//
//  File Name:  document.Checkout.js
//  Company:    Orbit Media
//  Author:     Kevin
//  Date:       10/6/02
//
	function cancelChechout()
	{
		document.Checkout._theAction.value="CANCELCO";
		return true;
	}
	function goSubmit()
	{
		document.Checkout._theAction.value="GOTOSUBMIT";
		return true;
	}
	
	
	function copyShippingInfo()
	{
		document.Checkout.firstName_fld.value = document.Checkout._inp_shipFirstName.value;
		document.Checkout.lastName_fld.value = document.Checkout._inp_shipFirstName.value;
		document.Checkout.companyName_fld.value = document.Checkout._inp_shipFirstName.value;
		document.Checkout.address1_fld.value = document.Checkout._inp_shipFirstName.value;
		document.Checkout.address2_fld.value = document.Checkout._inp_shipFirstName.value;
		document.Checkout.city_fld.value = document.Checkout._inp_shipFirstName.value;
		//document.Checkout.state_fld.selectedIndex = document.Checkout._inp_shipState.value;
		document.Checkout.zip_fld.value = document.Checkout._inp_shipFirstName.value;
		
		return false;
	}
	
	
	function copyBillingInfo()
	{
		document.Checkout.cc_first_name_fld.value = document.Checkout.firstName_fld.value;
		document.Checkout.cc_last_name_fld.value = document.Checkout.lastName_fld.value;
		document.Checkout.cc_address_fld.value = document.Checkout.address1_fld.value+" "+document.Checkout.address2_fld.value;
		document.Checkout.cc_city_fld.value = document.Checkout.city_fld.value;
		document.Checkout.cc_zip_fld.value = document.Checkout.zip_fld.value;
		document.Checkout.cc_state_fld.selectedIndex = document.Checkout.state_fld.selectedIndex;
		document.Checkout.cc_phArea_fld.value = document.Checkout.phArea_fld.value;
		document.Checkout.cc_phSuf_fld.value=document.Checkout.phSuf_fld.value;
		document.Checkout.cc_phPre_fld.value=document.Checkout.phPre_fld.value;
		
		return false;
	}
	
	function gotoVerify()
	{
		var strMsg = "";
		var	tmpPhone = document.Checkout.phArea_fld.value +document.Checkout.phPre_fld.value+document.Checkout.phSuf_fld.value + "";

		if (checkBlankText(document.Checkout.firstName_fld.value))
			strMsg = "- First name field is blank.\n";
		if (checkBlankText(document.Checkout.lastName_fld.value))
			strMsg += "- Last name field is blank.\n";
		if (checkBlankText(document.Checkout.address1_fld.value))
			strMsg += "- Address line field is blank.\n";
		if (checkBlankText(document.Checkout.city_fld.value))
			strMsg += "- City field is blank.\n";
		if (checkBlankText(document.Checkout.zip_fld.value))
			strMsg += "- Zip code field is blank.\n";
		else
		{
			if (!isNumber(document.Checkout.zip_fld.value))
				strMsg += "- Zip code field is not a number\n";
			else
				if(document.Checkout.zip_fld.value.length < 5)
				  strMsg += "- Zip code field is invalid\n";

		}
		if (checkBlankText(tmpPhone))
			strMsg += "- Daytime number field is blank.\n";
		else
		{
			if (!isNumber(tmpPhone))
				strMsg += "- Daytime number field is not a number\n";
			else
				if (tmpPhone.length != 10)
					strMsg += "- Daytime phone number field is invalid\n";
		}

		// Check form of payment
		//if (document.Checkout.pay_method_rbtn[0].checked) //Credit card selected
		//{
			var	tmpCCPhone = document.Checkout.cc_phArea_fld.value +document.Checkout.cc_phPre_fld.value+document.Checkout.cc_phSuf_fld.value + "";
			if (checkBlankText(document.Checkout.cc_first_name_fld.value))
				strMsg += "- Card holder first name field is blank.\n";
			if (checkBlankText(document.Checkout.cc_last_name_fld.value))
				strMsg += "- Card holder last name field is blank.\n";
			if (checkBlankText(document.Checkout.cc_address_fld.value))
				strMsg += "- Card holder address field is blank.\n";
			if (checkBlankText(document.Checkout.cc_city_fld.value))
				strMsg += "- Card holder city field is blank.\n";
			if (checkBlankText(document.Checkout.cc_zip_fld.value))
				strMsg += "- Zip code field is blank.\n";
			else
			{
				if (!isNumber(document.Checkout.cc_zip_fld.value))
					strMsg += "- Zip code field is not a number\n";
				else
					if(document.Checkout.cc_zip_fld.value.length < 5)
				  	strMsg += "- Zip code field is invalid\n";

			}	

			if (!isNumber(document.Checkout.cc_number_fld.value))
				strMsg += "- Card number field is not a number.\n";
			if (document.Checkout.cc_type_fld.value == "")
				strMsg += "- Card type has not been selected.\n";
			if (document.Checkout.cc_expMonth_fld.value == "")
				strMsg += "- Card expiration month not been selected.\n";
			if (document.Checkout.cc_expYear_fld.value == "")
				strMsg += "- Card expiration year has not been selected.\n";
			if (checkBlankText(tmpCCPhone))
				strMsg += "- Card holder phone number field is blank.\n";
			else
			{
				if (!isNumber(tmpCCPhone))
					strMsg += "- Card holder phone number field is not a number\n";
				else
					if (tmpCCPhone.length != 10)
						strMsg += "- Card holder phone number field is invalid\n";
			}
		/*}
		else
			if(document.Checkout.pay_method_rbtn[1].checked) // Check is selected
			{
				if(checkBlankText(document.Checkout.check_num_fld.value))
					strMsg += "- Check number field is blank.\n";
			}
		*/

		if (strMsg != "")
		{
			alert ("The Payment form has the following error(s)\n\n"+strMsg+"\n\nPlease correct the error(s) and resubmit");
			return false;
		}
		document.Checkout._theAction.value="GOTOVERIFY";
		return true;
	}
	
	

	function gotoShipping()
	{
		var strMsg = "";
		var	tmpHomePhone = document.Checkout._inp_HmPhArea.value +document.Checkout._inp_HmPhPre.value+document.Checkout._inp_HmPhSuf.value + "";
		var	tmpWorkPhone = document.Checkout._inp_WkPhArea.value +document.Checkout._inp_WkPhPre.value+document.Checkout._inp_WkPhSuf.value + "";

		if (checkBlankText(document.Checkout._inp_first_name.value))
			strMsg = "- First name field is blank.\n";
		if (checkBlankText(document.Checkout._inp_last_name.value))
			strMsg += "- Last name field is blank.\n";
		if (checkBlankText(document.Checkout._inp_address1.value))
			strMsg += "- Address line field is blank.\n";
		if (checkBlankText(document.Checkout._inp_city.value))
			strMsg += "- City field is blank.\n";
		if (checkBlankText(document.Checkout._inp_zip.value))
			strMsg += "- Zip code field is blank.\n";
		else
		{
			if (!isNumber(document.Checkout._inp_zip.value))
				strMsg += "- Zip code field is not a number\n";
			else
				if(document.Checkout._inp_zip.value.length < 5)
				  strMsg += "- Zip code field is invalid\n";
		}

		if (checkBlankText(tmpHomePhone))
			strMsg += "- Home number field is blank.\n";
		else
		{
			if (!isNumber(tmpHomePhone))
				strMsg += "- Home number field is not a number\n";
			else
				if (tmpHomePhone.length != 10)
					strMsg += "- Home phone number field is invalid\n";
		}

		if (checkBlankText(tmpWorkPhone))
			strMsg += "- Work number field is blank.\n";
		else
		{
			if (!isNumber(tmpWorkPhone))
				strMsg += "- Work number field is not a number\n";
			else
				if (tmpWorkPhone.length != 10)
					strMsg += "- Work phone number field is invalid\n";
		}

		if (strMsg != "")
		{
			alert ("The Customer form has the following error(s)\n\n"+strMsg+"\n\nPlease correct the error(s) and resubmit");
			return false;
		}
		document.Checkout._theAction.value="GOTOSHIPPING";
		return true;
	}
	
	

	function gotoPayment(bolRedoPage)
	{
		var strMsg = "";
		var	tmpPhone = document.Checkout.phArea_fld.value +document.Checkout.phPre_fld.value+document.Checkout.phSuf_fld.value + "";

		if (checkBlankText(document.Checkout.firstName_fld.value))
			strMsg = "- First name field is blank.\n";
		if (checkBlankText(document.Checkout.lastName_fld.value))
			strMsg += "- Last name field is blank.\n";
		if (checkBlankText(document.Checkout.address1_fld.value))
			strMsg += "- Address line field is blank.\n";
		if (checkBlankText(document.Checkout.city_fld.value))
			strMsg += "- City field is blank.\n";
		if (checkBlankText(document.Checkout.zip_fld.value))
			strMsg += "- Zip code field is blank.\n";
		else
		{
			if (!isNumber(document.Checkout.zip_fld.value))
				strMsg += "- Zip code field is not a number\n";
			else
				if(document.Checkout.zip_fld.value.length < 5)
				  strMsg += "- Zip code field is invalid\n";
		}

		if (checkBlankText(tmpPhone))
			strMsg += "- Daytime number field is blank.\n";
		else
		{
			if (!isNumber(tmpPhone))
				strMsg += "- Daytime number field is not a number\n";
			else
				if (tmpPhone.length != 10)
					strMsg += "- Daytime phone number field is invalid\n";
		}

		if (strMsg != "")
		{
			alert ("The Shipping form has the following error(s)\n\n"+strMsg+"\n\nPlease correct the error(s) and resubmit");
			return false;
		}
		if (bolRedoPage == 1)
			//document.Checkout._theAction.value="REDOPAYMENT";
			document.Checkout._theAction.value="GOTOPAYMENT";
		else
			document.Checkout._theAction.value="GOTOPAYMENT";
		return true;
	}
	
	
	function gotoBackPayment()
	{
		document.Checkout._theAction.value="GOBACKPAYMENT";
		return true;
	}
	
	
	function gotoBackShip()
	{
		document.Checkout._theAction.value="GOBACKSHIP";
		return true;
	}
	function lockField(objFld)
	{
		objFld.disabled		= true;
		objFld.className	= "lockedFld";
		objFld.value		= "";
	}
	
	function unlockField(objFld)
	{
		objFld.disabled		= false;
		objFld.className	= "defaultText";
	}

	// Lock the pickup field
	function lockPickup()
	{
		lockField(document.Checkout.ship_pickpup_fld);
	}
	// Unlock the customer pickup field
	function unlockPickup()
	{
		unlockField(document.Checkout.ship_pickpup_fld);
	}
	
	function setShipCosts(shipRate)
	{
		unlockField(document.Checkout.ship_costs_fld);
		document.Checkout.ship_costs_fld.value = shipRate;
	}

	function lockShipCosts()
	{
		lockField(document.Checkout.ship_costs_fld);
	}
	
	function disableCCard()
	{
		lockField(document.Checkout.cc_first_name_fld);
		lockField(document.Checkout.cc_last_name_fld);
		lockField(document.Checkout.cc_number_fld);
		lockField(document.Checkout.cc_address_fld);
		lockField(document.Checkout.cc_city_fld);
		lockField(document.Checkout.cc_zip_fld);
		lockField(document.Checkout.cc_number_fld);
		document.Checkout.cc_state_fld.disabled = true;
		document.Checkout.cc_type_fld.disabled = true;
		document.Checkout.cc_expMonth_fld.disabled = true;
		document.Checkout.cc_expYear_fld.disabled = true;
		lockField(document.Checkout.cc_phArea_fld);
		lockField(document.Checkout.cc_phPre_fld);
		lockField(document.Checkout.cc_phSuf_fld);
	}
	
	function disableCheck()
	{
		document.Checkout.check_type_rbtn[0].disabled = true;
		document.Checkout.check_type_rbtn[1].disabled = true;
		lockField(document.Checkout.check_num_fld);
	}

	function enableCCard()
	{
		disableCheck();
		unlockField(document.Checkout.cc_first_name_fld);
		unlockField(document.Checkout.cc_last_name_fld);
		unlockField(document.Checkout.cc_number_fld);
		unlockField(document.Checkout.cc_address_fld);
		unlockField(document.Checkout.cc_city_fld);
		unlockField(document.Checkout.cc_zip_fld);
		document.Checkout.cc_type_fld.disabled = false;
		document.Checkout.cc_state_fld.disabled = false;
		document.Checkout.cc_expMonth_fld.disabled = false;
		document.Checkout.cc_expYear_fld.disabled = false;
		document.Checkout.cc_type_fld.selectedIndex = 0;
		document.Checkout.cc_expMonth_fld.selectedIndex = 0;
		document.Checkout.cc_expYear_fld.selectedIndex = 0;
		unlockField(document.Checkout.cc_phArea_fld);
		unlockField(document.Checkout.cc_phPre_fld);
		unlockField(document.Checkout.cc_phSuf_fld);
	}
	
	function enableCheck()
	{
		disableCCard();
		document.Checkout.check_type_rbtn[0].disabled = false;
		document.Checkout.check_type_rbtn[1].disabled = false;
		unlockField(document.Checkout.check_num_fld);
	}

	function enableCODMO()
	{
		disableCCard();
		disableCheck();
	}
	
	function enableCash()
	{
		disableCCard();
		disableCheck();
	}