﻿// Variables
	var total = 0;
	var shipping = 0;
	var subtotal = 0;		

	var cc_price = 15;		//Compulsory Cards
	var fc_price = 30;		//Flash Cards
	var oec_price = 10;		//Optional Event Cards
	var bi_price = 3;		//Bar Index
	var oc78_price = 12;		//Omni Card 78
	var oc910_price = 12;		//Omni Card 9-10
	var noc_price = 12;		//NCAA Omni Card
	var wc_price = 22;		//Wall Charts
	var cp_price = 88;		//Coaches Packet
	var jp_price = 62;		//Judges Packet
	var rp_tabs = 5;		// rules and policies chart	

// Shipping Variables

	var ship = new Array();
	ship[0] = 4;	//Shipping <= $10.00
	ship[1] = 6;	//$10.00 < Shipping <= $20.00
	ship[2] = 9;	//$20.00 < Shipping <= $40.00
	ship[3] = 10;	//$40.00 < Shipping <= $70.00
	ship[4] = 14;	//$70.00 < Shipping
	
function IsNumeric(sText)
{
	var ValidChars = "0123456789";
	var IsNumber=true;
	var Char;
	for (i = 0; i < sText.length && IsNumber == true; i++) 
	{ 
		Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) 
		{
			IsNumber = false;
		}
	}
	return IsNumber;
}

function calSubTotal() 
{
	subtotal = 0;
	jumpto= "";
	if (IsNumeric(document.getElementById("cc-quantity").value) == false)
	{
		alert("You must enter an Interger");
		document.getElementById("cc-quantity").value = "0";
		jumpto == "cc-quantity";
	}

	tmp = document.getElementById("cc-quantity").value * cc_price;
	subtotal += (tmp);
	document.getElementById("cc-total").innerHTML = "$ " + tmp + ".00";
	
	tmp = document.getElementById("fc-quantity").value * fc_price;
	subtotal += (tmp);
	document.getElementById("fc-total").innerHTML = "$ " + tmp + ".00";
	
	tmp = document.getElementById("oec-quantity").value * oec_price;
	subtotal += (tmp);
	document.getElementById("oec-total").innerHTML = "$ " + tmp + ".00";
	
	tmp = document.getElementById("bi-quantity").value * bi_price;
	subtotal += (tmp);
	document.getElementById("bi-total").innerHTML = "$ " + tmp + ".00";
	
	tmp = document.getElementById("oc78-quantity").value * oc78_price;
	subtotal += (tmp);
	document.getElementById("oc78-total").innerHTML = "$ " + tmp + ".00";
	
	tmp = document.getElementById("oc910-quantity").value * oc910_price;
	subtotal += (tmp);
	document.getElementById("oc910-total").innerHTML = "$ " + tmp + ".00";
	
	tmp = document.getElementById("noc-quantity").value * noc_price;
	subtotal += (tmp);
	document.getElementById("noc-total").innerHTML = "$ " + tmp + ".00";
	
	tmp = document.getElementById("wc-quantity").value * wc_price;
	subtotal += (tmp);
	document.getElementById("wc-total").innerHTML = "$ " + tmp + ".00";
	
	tmp = document.getElementById("rp-quantity").value * rp_tabs;
	subtotal += (tmp);
	document.getElementById("rp-total").innerHTML = "$ " + tmp + ".00";
	
	tmp = document.getElementById("cp-quantity").value * cp_price;
	subtotal += (tmp);
	document.getElementById("cp-total").innerHTML = "$ " + tmp + ".00";
	
	tmp = document.getElementById("jp-quantity").value * jp_price;
	subtotal += (tmp);
	document.getElementById("jp-total").innerHTML = "$ " + tmp + ".00";
	
	document.getElementById("s-total").innerHTML = "$ " + subtotal + ".00";
	document.getElementById("hst").value = subtotal;
	
//Shipping Calculation
	tmpsubtotal = subtotal;
	tmp = document.getElementById("cp-quantity").value * cp_price;
	tmpsubtotal -= tmp
	tmp = document.getElementById("jp-quantity").value * jp_price;
	tmpsubtotal -= tmp
	if (tmpsubtotal > 70)
	  {shipping = ship[4];}

	else if (tmpsubtotal > 40)
	  {shipping = ship[3];}

	else if (tmpsubtotal > 20)
	  {shipping = ship[2];}

	else if (tmpsubtotal > 10)
	  {shipping = ship[1];}

	else if (tmpsubtotal == 0) {shipping = 0;}
	else {shipping = ship[0];}

	document.getElementById("ship-total").innerHTML = "$ " + shipping + ".00";
	document.getElementById("hs").value = shipping;
	total = shipping + subtotal;
	document.getElementById("ht").value = total;
	document.getElementById("total").innerHTML ="$ " + total + ".00";
}





//Phone Validation



	function elimChars(theString)

	{

		var newString = new String("");

		for (var i = 0; i < theString.length; i++)

		{

			if (theString.charAt(i) >= "0" && theString.charAt(i) <= "9")

				newString = newString + theString.charAt(i);

			else if (theString.charAt(i) == "(" || theString.charAt(i) == ") " || theString.charAt(i) == "-" || theString.charAt(i) == " ")

			{

				

			}

			else 

			{

				return ("");

			}

		}

		return(newString);

	}

	function checkValidPhone(control)

	{

		var temp = elimChars(control.value);

		if (temp.length != 10)

		{

			alert("Invalid Phone Number \n Please Enter a Valid Phone Number");

			control.focus();

			control.select();

		}

		else

		{

			control.value = "(" + temp.charAt(0) + temp.charAt(1) + temp.charAt(2) + ")" + temp.charAt(3) +temp.charAt(4) +temp.charAt(5) + "-" + temp.charAt(6) + temp.charAt(7) + temp.charAt(8) + temp.charAt(9); 

		}

	}



//Form Validation



function checksubmit()



	{



	 if (document.dem_orderform.f_name.value == "")



		{	alert("Please enter your First Name."); document.dem_orderform.f_name.focus(); return false;	}



	 if (document.dem_orderform.l_name.value == "")



		{	alert("Please enter your Last Name."); document.dem_orderform.l_name.focus(); return false; }



	 if (document.dem_orderform.s_address.value == "")



		{	alert("Please enter your Shipping Address."); document.dem_orderform.s_address.focus(); return false; }



	 if (document.dem_orderform.city.value == "")



		{	alert("Please enter your City."); document.dem_orderform.city.focus(); return false; }



	 if (document.dem_orderform.state.value == "")



		{	alert("Please select your State"); document.dem_orderform.state.focus(); return false; }

		

	 if (document.dem_orderform.zip.value.length != 5 || IsNumeric(document.dem_orderform.zip.value) != true)

		{	alert("Please enter your 5 Digit Postal Code"); document.dem_orderform.state.focus(); return false; }



	 if (document.dem_orderform.phone.value == "")



		{	alert("Please enter your phone number."); document.dem_contact.phone.focus(); return false; }



	

	 if (document.dem_orderform.email.value == "")



		{	alert("Please enter your Email Address.");	document.dem_orderform.email.focus(); return false;	}



		else 



			{



			 tmp = new String(document.dem_orderform.email.value);



			 tmp2 = tmp.split("@")



			 if (tmp2.length != 2)



				{	alert("Not a valid email address!"); document.dem_orderform.email.focus(); return false;}



			 if (tmp2[0] == '')



				{	alert("Not a valid email address!"); document.dem_orderform.email.focus(); return false;}



				tmp3 = tmp2[1].split('.')



				if (tmp3.length < 2)



					{	alert("Not a valid email address!"); document.dem_orderform.email.focus(); return false;}



				i = tmp3.length



				  for (j = 0; j<i ;j++)



					{



				 	 if (tmp3[j] =="")



				 	 {	alert("Not a valid email address!"); document.dem_orderform.email.focus(); return false;}



			}



				 



		 }



	 if (document.dem_orderform.confirm_email.value != document.dem_orderform.email.value)



		{	alert("Your email address does not match.");	document.dem_orderform.email.focus(); return false;	}



	 document.dem_orderform.submit();



	}

