function more(productId) {
	var qty = document.getElementById('select_' + productId);
	if (qty.innerHTML == 'select quantity' || parseInt(qty.innerHTML) == 0) {
		qty.innerHTML = 1;
	}
	else {
		qty.innerHTML = parseInt(qty.innerHTML) + 1;
	}
	setQty(productId, parseInt(qty.innerHTML));
}

function moreFromCart(productId,productCartId) {
	var theField = document.getElementById('select_' + productId);
	if (theField.value == '' || theField.value == 0) {
		theField.value = 1;
	}
	else {
		theField.value = parseInt(theField.value) + 1;
	}
	setQtyFromCart(productId, parseInt(theField.value), productCartId);
}

function less(productId) {
	var qty = document.getElementById('select_' + productId);
	if (qty.innerHTML == 'select quantity' || parseInt(qty.innerHTML) == 0) {
		qty.innerHTML = 0;
	}
	else {
		qty.innerHTML = parseInt(qty.innerHTML) - 1;
	}
	setQty(productId, parseInt(qty.innerHTML));
}

function lessFromCart(productId,productCartId) {
	var theField = document.getElementById('select_' + productId);
	if (theField.value == '' || theField.value == 0) {
		theField.value = 0;
	}
	else {
		theField.value = parseInt(theField.value) - 1;
	}
	setQtyFromCart(productId, parseInt(theField.value), productCartId);
}

function setQty(theId,theQty) {
	var theField = document.getElementById('dom_qty_' + theId);
	theField.value = theQty;
}

function setQtyFromCart(theId,theQty,productCartId) {
	var theField = document.getElementById('dom_qty_' + theId);
	theField.value = theQty;
	var url = 'cart.php?action=update&productindexes[' + productCartId + ']=' + theQty;
	self.location = url;
}

function setQtyFromField(theId,productCartId) {
	var theField = document.getElementById('select_' + theId);
	var theQty = parseInt(theField.value);
	var url = 'cart.php?action=update&productindexes[' + productCartId + ']=' + theQty;
	self.location = url;
}

function submitAll() {
	var i;
	var theId;
	var theIds = "";
	var theQtys = "";
	var theForm = document.getElementById('add_products_form');
	for (var i=0;i<theForm.length;i++) {
		theName = theForm.elements[i].name;
		if (theName != null && theName != "") {
			if (theName.substring(0,3) == 'pid') {
				theIds =  theIds + theForm.elements[i].value + "|";
			} else if (theName.substring(0,3) == 'qty') {
				theQtys = theQtys + theForm.elements[i].value + "|";
			}
		}
	}
	theForm.productids.value = theIds;
	theForm.amounts.value = theQtys;
	theForm.submit();
}
