// Validate Discount
function validateDiscount()
{
	trimFields();
	if(obj.coupon_code.value == "")
	{
		alert("Please enter a Coupon Code for Discount.");
		obj.coupon_code.focus();
		return;
	}
	obj.action = "shopping_cart.php?opt=discount";
	obj.submit();
}

//Update shopping cart
function updateCart()
{
	isValid = true;
	for(var i = 0; i < obj.elements.length; i++)
	{
		if(obj.elements[i].type == "text" && obj.elements[i].name.substring(0,9) == "quantity_")
		{
			if(obj.elements[i].value == '' || isNaN(obj.elements[i].value) || (!isNaN(obj.elements[i].value) && obj.elements[i].value < 0))
			{
				isValid = false;
				break;
			}
		}
	}
	if(!isValid)
	{
		alert("Please enter a valid quantity.");
		obj.elements[i].focus();
		obj.elements[i].select();
		return;
	}
	obj.action = 'shopping_cart.php?opt=update';
	obj.submit();
}

//Removes item from shopping cart
function deleteItem()
{
	flag = false;
	for(var i = 0; i < obj.elements.length; i++)
	{
		if(obj.elements[i].type == "checkbox" && obj.elements[i].name.substring(0,11) == "delete_item")
		{
			if(obj.elements[i].checked)
				flag = true;
		}
	}
	if(flag == false)
	{
		alert("Please check the Products you want to delete.");
		return;
	}
	else
	{
		if(confirm("Are you sure you want to remove the selected Item?"))
		{
			obj.action = 'shopping_cart.php?opt=delete';
			obj.submit();
		}
	}
}

function confirmPickup()
{
	if(obj.local_pickup.checked)
	{
		if(confirm("Are you sure you want to pick up this order from the Store?"))
		{
			self.location = 'shopping_cart.php?opt=pickup&local_pickup=Y';
		}
	}
	else
	{
		if(confirm("Are you sure you want the order to be shipped to you?"))
		{
			self.location = 'shopping_cart.php?opt=pickup&local_pickup=N';
		}
	}
}

