

function clear_shipping()
{
	shipping=document.getElementById("shipping");
	document.getElementById("shipping").options.length = 0;
	
}

function set_shipping()
{

	clear_shipping();
	
	ship_country=document.getElementById("ship_country");
	if(ship_country.value == "United States")
	{
		ship_state=document.getElementById("ship_stateUS");
		if(ship_state.value == "HI" || ship_state.value=="AA" || ship_state.value=="AE" || ship_state.value=="AP" || ship_state.value=="FM" || ship_state.value=="MH" || ship_state.value=="MP" || ship_state.value=="VI" || ship_state.value=="AS" || ship_state.value=="PR")
		{
			document.getElementById("shipping").options.length = 1;
			document.getElementById("shipping").options[0].text="US Standard Territory or Island Shipping";
			document.getElementById("shipping").options[0].value="4";
		}
		else
		{
			document.getElementById("shipping").options.length = 4;
			document.getElementById("shipping").options[0].text="Standard Delivery";
			document.getElementById("shipping").options[0].value="0";
			document.getElementById("shipping").options[1].text="3rd Business Day Express Delivery";
			document.getElementById("shipping").options[1].value="1";
			document.getElementById("shipping").options[2].text="2nd Business Day Express Delivery";
			document.getElementById("shipping").options[2].value="2";
			document.getElementById("shipping").options[3].text="Next Business Day Express Delivery";
			document.getElementById("shipping").options[3].value="3";
		}
	}
	else if(ship_country.value == "Canada")
	{
		//document.getElementById("shipping").options=null;
		document.getElementById("shipping").options.length = 1;
		document.getElementById("shipping").options[0].text="Canadian Standard Delivery";
		document.getElementById("shipping").options[0].value="10";
		
	}
	else
	{
		//document.getElementById("shipping").options=null;
		document.getElementById("shipping").options.length = 1;
		document.getElementById("shipping").options[0].text="Worldwide Standard Delivery";
		document.getElementById("shipping").options[0].value="20";
	}
	
}

function order_state(type)
{
		country = document.getElementById(type+"_country").value;
		if(country!="United States")
		{
			document.getElementById(type+"_stateUS").readOnly=true;
			document.getElementById(type+"_stateUS").className="order_input_disabled";
			document.getElementById(type+"_stateUS").value="";
			document.getElementById(type+"_stateOther").readOnly=false;
			document.getElementById(type+"_stateOther").className="order_input";
			
			
			if(type=="ship")
			{
				set_shipping();
			}
		}
		else
		{
			document.getElementById(type+"_stateUS").readOnly=false;
			document.getElementById(type+"_stateUS").className="order_input";
			document.getElementById(type+"_stateOther").readOnly=true;
			document.getElementById(type+"_stateOther").className="order_input_disabled";
			document.getElementById(type+"_stateOther").value="";
			
			if(type=="ship")
			{
				set_shipping();
			}
		}
}

function verify()
{
	if(document.getElementById("agree").checked==true)
	{
		document.getElementById("checkout").action="index.php?page=checkout&option=order";
		document.getElementById("checkout").submit();
	}
	else
	{
		alert("You must accept our terms to proceed with your order");
	}
}

function order_same()
{
	bill_firstName=document.getElementById("bill_firstName");
	bill_lastName=document.getElementById("bill_lastName");
	bill_country=document.getElementById("bill_country");
	bill_address=document.getElementById("bill_address");
	bill_city=document.getElementById("bill_city");
	if(bill_country.value != "United States"){bill_state=document.getElementById("bill_stateOther");}
	else{bill_state=document.getElementById("bill_stateUS");}
	bill_zip=document.getElementById("bill_zip");
	
	ship_firstName=document.getElementById("ship_firstName");
	ship_lastName=document.getElementById("ship_lastName");
	ship_country=document.getElementById("ship_country");
	ship_address=document.getElementById("ship_address");
	ship_city=document.getElementById("ship_city");
	if(ship_country.value != "United States"){ship_state=document.getElementById("ship_stateOther");}
	else{ship_state=document.getElementById("ship_stateUS");}
	ship_zip=document.getElementById("ship_zip");
	
	if(document.getElementById("same").checked==true)
	{
	
		if(bill_firstName.value == "" || bill_lastName.value == "" || bill_country.value == "" || bill_address.value == "" || bill_city.value == "" || bill_state.value == "" || bill_zip.value == "")
		{alert("Your Billing Information has not been completed correctly\nPlease fill out all of your billing information and try again..."); document.getElementById("same").checked=false; return false;}
		
		ship_firstName.value=bill_firstName.value;	
		ship_lastName.value=bill_lastName.value;
		ship_country.value=bill_country.value;
		ship_address.value=bill_address.value;
		ship_city.value=bill_city.value;
		if(ship_country.value != "United States")
		{
			document.getElementById("ship_stateUS").value="";
			document.getElementById("bill_stateUS").value="";
			document.getElementById("ship_stateOther").value=document.getElementById("bill_stateOther").value;
		
		}
		else
		{
			document.getElementById("ship_stateOther").value="";
			document.getElementById("bill_stateOther").value="";
			document.getElementById("ship_stateUS").value=document.getElementById("bill_stateUS").value;
		}
		ship_zip.value=bill_zip.value;
		
		
		bill_firstName.readOnly=true;
		bill_lastName.readOnly=true;
		bill_country.readOnly=true;
		bill_address.readOnly=true;
		bill_city.readOnly=true;
		document.getElementById("bill_stateOther").readOnly=true;
		document.getElementById("bill_stateUS").readOnly=true;
		bill_zip.readOnly=true;
	
		ship_firstName.readOnly=true;
		ship_lastName.readOnly=true;
		ship_country.readOnly=true;
		ship_address.readOnly=true;
		ship_city.readOnly=true;
		document.getElementById("ship_stateOther").readOnly=true;
		document.getElementById("ship_stateUS").readOnly=true;
		ship_zip.readOnly=true;
		
		bill_firstName.className="order_input_disabled";
		bill_lastName.className="order_input_disabled";
		bill_country.className="order_input_disabled";
		bill_address.className="order_input_disabled";
		bill_city.className="order_input_disabled";
		document.getElementById("bill_stateOther").className="order_input_disabled";
		document.getElementById("bill_stateUS").className="order_input_disabled";
		bill_zip.className="order_input_disabled";
	
		ship_firstName.className="order_input_disabled";
		ship_lastName.className="order_input_disabled";
		ship_country.className="order_input_disabled";
		ship_address.className="order_input_disabled";
		ship_city.className="order_input_disabled";
		document.getElementById("ship_stateOther").className="order_input_disabled";
		document.getElementById("ship_stateUS").className="order_input_disabled";
		ship_zip.className="order_input_disabled";
		
		set_shipping();

			
	}
	else
	{
		bill_firstName.readOnly=false;
		bill_lastName.readOnly=false;
		bill_country.readOnly=false;
		bill_address.readOnly=false;
		bill_city.readOnly=false;
		
		if(bill_country.value != "United States"){document.getElementById("bill_stateOther").readOnly=false;}
		else{document.getElementById("bill_stateUS").readOnly=false;}	
		
		bill_zip.readOnly=false;
		ship_firstName.readOnly=false;
		ship_lastName.readOnly=false;
		ship_country.readOnly=false;
		ship_address.readOnly=false;
		ship_city.readOnly=false;
		
		if(ship_country.value != "United States"){document.getElementById("ship_stateOther").readOnly=false;}
		else{document.getElementById("ship_stateUS").readOnly=false;}
		
		ship_zip.readOnly=false;
		
		bill_firstName.className="order_input";
		bill_lastName.className="order_input";
		bill_country.className="order_input";
		bill_address.className="order_input";
		bill_city.className="order_input";
		
		if(ship_country.value != "United States"){document.getElementById("bill_stateOther").className="order_input";}
		else{document.getElementById("bill_stateUS").className="order_input";}
	
		bill_zip.className="order_input";
	
		ship_firstName.className="order_input";
		ship_lastName.className="order_input";
		ship_country.className="order_input";
		ship_address.className="order_input";
		ship_city.className="order_input";
		
		if(bill_country.value != "United States"){document.getElementById("ship_stateOther").className="order_input";}
		else{document.getElementById("ship_stateUS").className="order_input";}
		
		ship_zip.className="order_input";
		
		set_shipping();
	}
}
	
	function checkEmail(email)
	{
		var characters = /^[^@]+@[^@]+.[a-z]{2,}$/i;
		if (email.value.search(characters) == -1)
		{	
			return false;
		}
		return true;
	}
	
	function checkPhone(item, num)
	{
		size=item.value.length;
		if(isNaN(item.value) == true){return false;}
		if(size < num){return false;}
		return true;
	}

	function checkForm(item)
	{
		if(item.value == "" || item.value == null)
		{
			return false;
		}
		
		return true;
	}

	function checkAddress(address, state, zip, city, country)
	{	
		
		if(address.value.length == 0 || address.value == null){return -3;}
		if(city.value.length == 0 || city.value == null){return -4;}
		if(state.value.length < 2 || state.value == null){return -2;}
		if(isNaN(zip.value) == true){return -1;}
		if(zip.value.length < 5){return -1;}
		if(country.value == "" || country.value == null){return -5;}

		return 0;
	}
	
	function order_check()
	{
		
		bill_firstName=document.getElementById("bill_firstName");
		bill_lastName=document.getElementById("bill_lastName");
		bill_country=document.getElementById("bill_country");
		bill_address=document.getElementById("bill_address");
		bill_city=document.getElementById("bill_city");
		if(bill_country.value != "United States"){bill_state=document.getElementById("bill_stateOther");}
		else{bill_state=document.getElementById("bill_stateUS");}
		bill_zip=document.getElementById("bill_zip");
		
		ship_firstName=document.getElementById("ship_firstName");
		ship_lastName=document.getElementById("ship_lastName");
		ship_country=document.getElementById("ship_country");
		ship_address=document.getElementById("ship_address");
		ship_city=document.getElementById("ship_city");
		if(ship_country.value != "United States"){ship_state=document.getElementById("ship_stateOther");}
		else{ship_state=document.getElementById("ship_stateUS");}
		ship_zip=document.getElementById("ship_zip");
		
		bill_cardType=document.getElementById("bill_cardType");
		bill_expMonth=document.getElementById("bill_expMonth");
		bill_expYear=document.getElementById("bill_expYear");
		bill_cc=document.getElementById("bill_cc");
		bill_cvv=document.getElementById("bill_cvv");
		
		phone_code=document.getElementById("phone_code");
		phone_area=document.getElementById("phone_area");
		phone_access=document.getElementById("phone_access");
		phone_local=document.getElementById("phone_local");
		
		email=document.getElementById("email");
		
		/* Checking Form */
		
		if(checkForm(bill_firstName) == false){alert("Invalid Billing First Name"); bill_firstName.focus(); return false;}
		if(checkForm(bill_lastName) == false){alert("Invalid Billing Last Name"); bill_lastName.focus(); return false;}
		if(checkForm(bill_address) == false){alert("Invalid Billing Address"); bill_address.focus(); return false; }
		if(checkForm(bill_city) == false){alert("Invalid Billing City"); bill_city.focus(); return false;}
		if(checkForm(bill_state) == false){alert("Invalid Billing State");  bill_state.focus(); return false;}
		if(checkForm(bill_zip) == false){alert("Invalid Billing Zip"); bill_zip.focus(); return false;}
	
		if(checkForm(ship_firstName) == false){alert("Invalid Shipping First Name"); ship_firstName.focus(); return false;}
		if(checkForm(ship_lastName) == false){alert("Invalid Shipping Last Name"); ship_lastName.focus(); return false;}
		if(checkForm(ship_address) == false){alert("Invalid Shipping Address"); ship_address.focus(); return false; }
		if(checkForm(ship_city) == false){alert("Invalid Shipping City"); ship_city.focus(); return false;}
		if(checkForm(ship_zip) == false){alert("Invalid Shipping Postal Code"); ship_zip.focus(); return false;}
	
		if(checkEmail(email) == false){alert("Invalid E-Mail"); email.focus(); return false;}
		
		if(checkPhone(phone_area, 3) == false){alert("Invalid Area Code"); phone_area.focus(); return false;}
		if(checkPhone(phone_access, 3) == false){alert("Invalid Phone Number (Access Number)"); phone_access.focus(); return false;}
		if(checkPhone(phone_local, 4) == false){alert("Invalid Phone Number (Local Number)"); phone_local.focus(); return false;}
		
		document.getElementById("checkout").action="index.php?page=checkout&option=verify";
		document.getElementById("checkout").submit();
		
		
	}
	
	/*function contact()
	{
		
		first=document.getElementById("first");
		last=document.getElementById("last");
		
		phone_code=document.getElementById("phone_code");
		phone_area=document.getElementById("phone_area");
		phone_access=document.getElementById("phone_access");
		phone_local=document.getElementById("phone_local");
		
		if(checkForm(first) == false){alert("Invalid First Name"); ship_firstName.focus(); return false;}
		if(checkForm(last) == false){alert("Invalid Last Name"); ship_lastName.focus(); return false;}
		
		if(checkPhone(phone_area, 3) == false){alert("Invalid Area Code"); phone_area.focus(); return false;}
		if(checkPhone(phone_access, 3) == false){alert("Invalid Phone Number (Access Number)"); phone_access.focus(); return false;}
		if(checkPhone(phone_local, 4) == false){alert("Invalid Phone Number (Local Number)"); phone_local.focus(); return false;}
		
		document.getElementById("contact").action="index.php?argv=support&option=contact&directive=send";
		document.getElementById("contact").submit();
	}*/
	