//******************************
//* Global Variables/constants *
//******************************

//This function returns true if the string passed into is a whole number 1 to infinity--otherwise false
function isStringNumber(InString)
{
	if (InString.length == 0) return (false);

	var RefString="1234567890";

	for (Count=0; Count < InString.length; Count++)
	{
		TempChar = InString.substring (Count, Count+1);
		if (RefString.indexOf(TempChar, 0) == -1) return (false);
	}

	return (true);	
}

//This function will verify that required fields have been filled in before submitting the form
//If not, focus will be set in the first required field that is not filled in
function verifyRequiredFields()
{
	var strFirstName = document.OrderForm.txtFirstName.value;
	var strLastName = document.OrderForm.txtLastName.value;
	var strPrimaryPhone = document.OrderForm.txtPhone1.value;

	if (strFirstName == "") 
	{
		document.OrderForm.txtFirstName.focus();
		alert("*First Name is a required field.");
	} 
	else
	{ 	
		if (strLastName == "") 
		{
			document.OrderForm.txtLastName.focus();
			alert("*Last Name is a required field.");
		}
		else
		{
			if (strPrimaryPhone == "") 
			{
				document.OrderForm.txtPhone1.focus();
				alert("*Primary Phone is a required field. Please enter 10 to 15 numbers only and no spaces.");
			}
			else
			{
				if (isStringNumber(strPrimaryPhone) == false)
				{
					document.OrderForm.txtPhone1.focus();
					alert("*Primary Phone must contain numbers only and no spaces.  Please enter 10 to 15 numbers.");							
				}
				else
				{
					if(strPrimaryPhone.length < 10)
					{
						document.OrderForm.txtPhone1.focus();
						alert("*Primary Phone must contain from 10 to 15 numbers and no spaces."); 
					}
					else
					{
						if (submitOrderForm())
						{
							document.OrderForm.submit();
						}
						else
						{
							document.OrderForm.btnSubmit.focus();
						}
					}
				}
			}
		}
	} 
	
}

//This function will confirm the Order Form submission
function submitOrderForm()
{
	var strOrderDetails = document.OrderForm.txtSeashellArtCraftsOrderDetails.value;

	//Logic to control the submitting of the form
	if (strOrderDetails == "")
	{
		alert("Please describe the item(s) you are interested in purchasing in the Order Details box.");
		return false;
	}
	else
	{
		if (window.confirm("Submit this Order?"))
		{
			alert("Your Order is complete!  A Sales Representative will attempt to contact with you within 1 to 3 business days.");
			location = "DEFAULT.htm";
			return true;
		}
		else
		{
			return false;
		}
	}
}

