//////////////////////////////////////////////////////////////
// psStore Shopping Cart page functions
// v1.00 (Budd Wright)
//
// Description:
//////////////////////////////////////////////////////////////
// Contains various psStore shopping cart functions
//////////////////////////////////////////////////////////////
//
// Usage:
//////////////////////////////////////////////////////////////
// <script language="javascript" src="js/psStore_product.js"></script>
//////////////////////////////////////////////////////////////
//
// v1.00 Notes
// -----------
//
// Known Issues
// ------------
// 
//////////////////////////////////////////////////////////////



/* ValidateCartValues function */
// Validates cart quantity entries before submitting form
function ValidateCartValues()
{
	// References
	var formElement = document.getElementById("cartForm");
	var quantityFields = document.getElementsByName("quantity");

	// Verify each quantity
	for( var x = 0; x < quantityFields.length; x++ )
	{
		// Treat blank values as zeros
		if( quantityFields[x].value.length == 0 )
			quantityFields[x].value = 0;

		// Must be numeric
		if( isNaN( quantityFields[x].value ) )
		{
			alert("One of your quantities is not numeric. Please enter the quantity you want and try again.");
			quantityFields[x].value = "";
			quantityFields[x].focus();
			return;
		}

		// Must be positive value
		if( quantityFields[x].value < 0 )
		{
			alert("Quantities must be a positive number. If you want to remove a product from your cart, enter 0 for its quantity. Please enter the quantity you want and try again.");
			quantityFields[x].value = "0";
			quantityFields[x].focus();
			return;
		}

		// Must be an integer
		if( quantityFields[x].value != parseInt( quantityFields[x].value, 10 ) )
		{
			alert("Quantities cannot be fractional. Please enter the quantity you want and try again.");
			quantityFields[x].value = parseInt( quantityFields[x].value, 10 );
			quantityFields[x].focus();
			return;
		}
	}


	// Submit form
	formElement.submit();
}
