function addToCart(id, quantity) {
	
	if(!quantity) {
		quantity = 1;
	}
	
	if((typeof quantity) == "string") {
		var quantityField = document.merchantForm[quantity];
		if(!quantityField || quantityField == "undefined") {
			alert("Field not found: " + quantity);
			return;
		}
		quantity = quantityField.value;
	}
	
	document.merchantForm.action = "/controlPanel/merchant/store/add.do";
	document.merchantForm.itemId.value = id;
	document.merchantForm.quantity.value = quantity;
	document.merchantForm.submit();
}

function addToCartAndGoTo(id, quantity, materiaId) {
	
	if(!quantity) {
		quantity = 1;
	}
	
	if((typeof quantity) == "string") {
		var quantityField = document.merchantForm[quantity];
		if(!quantityField || quantityField == "undefined") {
			alert("Field not found: " + quantity);
			return;
		}
		quantity = quantityField.value;
	}
	
	document.merchantForm.action = "/controlPanel/merchant/store/add.do";
	document.merchantForm.itemId.value = id;
	document.merchantForm.quantity.value = quantity;
	document.merchantForm.materiaId.value = materiaId;
	document.merchantForm.submit();
}

function removeFromCart(id) {
	document.merchantForm.action = "/controlPanel/merchant/store/remove.do";
	document.merchantForm.itemId.value = id;
	document.merchantForm.submit();
}

function clearCart(formName) {
	document.merchantForm.action = "/controlPanel/merchant/store/clear.do";
	document.merchantForm.submit();
}

function previousPage() {
	if(document.merchantForm.currentPage.value > 1) {
		document.merchantForm.currentPage.value = parseInt(document.merchantForm.currentPage.value) -1;
		document.merchantForm.action = "/" + document.merchantForm.materiaId.value;
		document.merchantForm.submit();
	}
}

function nextPage() {
	if(document.merchantForm.currentPage.value < document.merchantForm.totalPages.value) {
		document.merchantForm.currentPage.value = parseInt(document.merchantForm.currentPage.value) + 1;
		document.merchantForm.action = "/" + document.merchantForm.materiaId.value;
		document.merchantForm.submit();
	}
}

function goToPage(number) {
	if(document.merchantForm.currentPage.value != number && number > 0 && number <= document.merchantForm.totalPages.value) {
		document.merchantForm.currentPage.value = number;
		document.merchantForm.action = "/" + document.merchantForm.materiaId.value;
		document.merchantForm.submit();
	}
}

function changeItemsPerPage() {
	document.merchantForm.itemsPerPage.value = value;
	document.merchantForm.action = "/" + document.merchantForm.materiaId.value;
	document.merchantForm.submit();
}
