var submitted = false;

function copy_billing(form)
{

if (form.usebilling.checked == true)
{
	 form.Ecom_ShipTo_Postal_Company.value = form.Ecom_BillTo_Postal_Company.value;
	 form.Ecom_ShipTo_Postal_Name_First.value = form.Ecom_BillTo_Postal_Name_First.value;
	 form.Ecom_ShipTo_Postal_Name_Last.value = 	form.Ecom_BillTo_Postal_Name_Last.value;
	 form.Ecom_ShipTo_Postal_Street_Line1.value = form.Ecom_BillTo_Postal_Street_Line1.value; 
	 form.Ecom_ShipTo_Postal_City.value = 	form.Ecom_BillTo_Postal_City.value;
	 form.Ecom_ShipTo_Postal_StateProv.value = 	form.Ecom_BillTo_Postal_StateProv.value;
	 form.Ecom_ShipTo_Postal_PostalCode.value  = form.Ecom_BillTo_Postal_PostalCode.value ;
   form.Ecom_ShipTo_Postal_CountryCode.value  = form.Ecom_BillTo_Postal_CountryCode.value ;
}
else


{
	 form.Ecom_ShipTo_Postal_Company.value = "";
	 form.Ecom_ShipTo_Postal_Name_First.value = "";
	 form.Ecom_ShipTo_Postal_Name_Last.value = 	"";
	 form.Ecom_ShipTo_Postal_Street_Line1.value = ""; 
	 form.Ecom_ShipTo_Postal_City.value = 	"";
	 form.Ecom_ShipTo_Postal_StateProv.value = 	"";
	 form.Ecom_ShipTo_Postal_PostalCode.value  = "";
   form.Ecom_ShipTo_Postal_CountryCode.value  = "";
}






}


function validate(theform)
{
    //Login Validation

  
		
		
		if(theform.Ecom_BillTo_Online_Email.value == "")
		{
		window.alert ("Please enter email");
		theform.Ecom_BillTo_Online_Email.focus();
		return (false);
		}
		
		 if (isEmail(theform.Ecom_BillTo_Online_Email.value) == false)
	  {	
	  window.alert ("The e-mail address you have entered is not correct");
	  theform.Ecom_BillTo_Online_Email.focus();
	  return (false);
	}
		
		
    if(theform.Ecom_BillTo_Online_Email_Confirm.value == "")
		{
		window.alert ("Please enter your email address again");
		theform.Ecom_BillTo_Online_Email_Confirm.focus();
		return (false);
		}
		
			 if (isEmail(theform.Ecom_BillTo_Online_Email_Confirm.value) == false)
	  {	
	  window.alert ("The e-mail address you have entered is not correct");
	  theform.Ecom_BillTo_Online_Email_Confirm.focus();
	  return (false);
	  }
		
		
		
		
		
		if ((theform.Ecom_BillTo_Online_Email_Confirm.value) !== (theform.Ecom_BillTo_Online_Email.value)  )
	  {	
	  window.alert ("Email addresses do not match");
	  theform.Ecom_BillTo_Online_Email_Confirm.focus();
	  return (false);
	  }
		
		
		
		
		
		 if(theform.Ecom_User_Password.value == "")
		{
		window.alert ("Please enter password");
		theform.Ecom_User_Password.focus();
		return (false);
		}
		
		
			
		 if(theform.Ecom_User_Password.value.length < 6)
		{
		window.alert ("The password should be minimum 6 chararcter in length");
		theform.Ecom_User_Password.focus();
		return (false);
		}
		
		
		 if(theform.Ecom_User_Password_Confirm.value == "")
		{
		window.alert ("Please confirm your password");
		theform.Ecom_User_Password_Confirm.focus();
		return (false);
		}
		
		
		
		
		
		if ((theform.Ecom_User_Password.value) !== (theform.Ecom_User_Password_Confirm.value)  )
	  {	
	  window.alert ("Passwords do not match");
	  theform.Ecom_User_Password_Confirm.focus();
	  return (false);
	  }
		
		if(theform.question.value == "None")
		{
		window.alert ("Please select a secret question");
		theform.question.focus();
		return (false);
		}
	
		if(theform.answer.value == "")
		{
		window.alert ("Please enter the answer to question");
		theform.answer.focus();
		return (false);
		}
	
		
		//Billing Validation
		if(theform.Ecom_BillTo_Postal_Name_First.value == "")
		{
		window.alert ("Please enter your First Name");
		theform.Ecom_BillTo_Postal_Name_First.focus();
		return (false);
		}
    if(theform.Ecom_BillTo_Postal_Name_Last.value == "")
		{
		window.alert ("Please enter your Last Name");
		theform.Ecom_BillTo_Postal_Name_Last.focus();
		return (false);
		}
    if(theform.Ecom_BillTo_Postal_Street_Line1.value == "")
		{
		window.alert ("Please enter billing address");
		theform.Ecom_BillTo_Postal_Street_Line1.focus();
		return (false);
		}
    if(theform.Ecom_BillTo_Postal_City.value == "")
		{
		window.alert ("Please enter billing city");
		theform.Ecom_BillTo_Postal_City.focus();
		return (false);
		}
    if(theform.Ecom_BillTo_Postal_StateProv.value == "")
		{
		window.alert ("Please enter province");
		theform.Ecom_BillTo_Postal_StateProv.focus();
		return (false);
		}
		if(isProvince(theform.Ecom_BillTo_Postal_StateProv.value)== false)
		{
		window.alert ("Please select billing province");
		theform.Ecom_BillTo_Postal_StateProv.focus();
		return (false);
		}
    if(theform.Ecom_BillTo_Postal_PostalCode.value == "")
		{
		window.alert ("Please enter the postal code");
		theform.Ecom_BillTo_Postal_PostalCode.focus();
		return (false);
		}
    if(theform.Ecom_BillTo_Postal_CountryCode.value == "NONE")
		{
		window.alert ("Please select billing country");
		theform.Ecom_BillTo_Postal_CountryCode.focus();
		return (false);
		}
		 if(theform.Ecom_BillTo_Telecom_Phone_Number.value == "")
		{
		window.alert ("Please enter phone number");
		theform.Ecom_BillTo_Telecom_Phone_Number.focus();
		return (false);
		}
		
		
		 //Shipping Validation
		if(theform.Ecom_ShipTo_Postal_Name_First.value == "")
		{
		window.alert ("Please enter your First Name");
		theform.Ecom_ShipTo_Postal_Name_First.focus();
		return (false);
		}
    if(theform.Ecom_ShipTo_Postal_Name_Last.value == "")
		{
		window.alert ("Please enter your Last Name");
		theform.Ecom_ShipTo_Postal_Name_Last.focus();
		return (false);
		}
    if(theform.Ecom_ShipTo_Postal_Street_Line1.value == "")
		{
		window.alert ("Please enter Shipping address");
		theform.Ecom_ShipTo_Postal_Street_Line1.focus();
		return (false);
		}
    if(theform.Ecom_ShipTo_Postal_City.value == "")
		{
		window.alert ("Please enter Shipping city");
		theform.Ecom_ShipTo_Postal_City.focus();
		return (false);
		}
    if(theform.Ecom_ShipTo_Postal_StateProv.value == "")
		{
		window.alert ("Please enter province");
		theform.Ecom_ShipTo_Postal_StateProv.focus();
		return (false);
		}
		if(isProvince(theform.Ecom_ShipTo_Postal_StateProv.value)== false)
		{
		window.alert ("Please select Shipping province");
		theform.Ecom_ShipTo_Postal_StateProv.focus();
		return (false);
		}
    if(theform.Ecom_ShipTo_Postal_PostalCode.value == "")
		{
		window.alert ("Please enter the postal code");
		theform.Ecom_ShipTo_Postal_PostalCode.focus();
		return (false);
		}
    if(theform.Ecom_ShipTo_Postal_CountryCode.value == "NONE")
		{
		window.alert ("Please select Shipping country");
		theform.Ecom_ShipTo_Postal_CountryCode.focus();
		return (false);
		}


//if IE 4+ or NS 6+
if (document.all||document.getElementById){
//screen thru every element in the form, and hunt down "submit" and "reset"
for (i=0;i<theform.length;i++){
var tempobj=theform.elements[i]
if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset")
//disable em
tempobj.disabled=true
}
}




}












function isEmail(str) {
  // are regular expressions supported?
  var supported = 0;
if (window.RegExp) {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
  }
  if (!supported) 
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  return (!r1.test(str) && r2.test(str));
}


function isPostalCode(str)
{
if (str.length != 6 ) return false;
	if(! (isLetter(str.charAt(0))))	return false;
	if(! (isNumber(str.charAt(1)))) return false;
	if(! (isLetter(str.charAt(2)))) return false;
	if(! isNumber(str.charAt(3))) return false;
	if(! isLetter(str.charAt(4))) return false;
	if(! isNumber(str.charAt(5))) return false;
}

function isProvince(str)
{
if (str.length != 2 ) return false;
}




function isNumber(s)
{
	var i = 0;

for (i = 0; i < s.length; i++) {
		l = s.charAt(i);
		if (l < '0' || l > '9') return false;
	}
	

return(true);
}



function isLetter(s)
{
	var i = 0;
	var l = '';

	for (i = 0; i < s.length; i++) {
		l = s.charAt(i);
		l = l.toLowerCase();
		
		if (l < 'a' || l > 'z') return false;
	}

return(true);
}




function ValidateCC(ccNumber){
  var bOdd = true;
  var sum = new Number(0);
  var num = new Number(0);
  // check for a valid length
  if (ccNumber.length <13 || ccNumber.length> 16) {
      return ""; // Invalid Credit Card Number";
  }
  // beginning with the rightmost digit, 
  // multiply the number by 1 if
  // the position is odd, or 2 if the position is even.
  // if the product is greater than 9, the units and tens 
  // position are added together. 
  // if the final answer is divisble by 10, it's good...
  // otherwise the card is invalid.
  for (var i = ccNumber.length - 1; i >= 0; i--){ 
    num = Number(ccNumber.substr(i,1));
    if ( bOdd ) { 
      sum = sum + (num * 1);
    }else{
      num = (num * 2);
      var tString = String(num);
      var n = (tString.length -1);
      for (n; n>=0; n--){
        sum = sum + Number(tString.substr(n,1));
      }
    }
    bOdd = !bOdd;
  }
  if ((sum % 10) != 0) return ""; 
  // once we know the number is good, loop the card types
  // for unmatched numbers, return a blank 
  // for valid cards, return the card name 
  
 
  if (Number(ccNumber.length) == 16 && 
    ccNumber.substring(0,2)>="51" && 
    ccNumber.substring(0,2)<="55") 
	return "MASTERCARD";
  if (Number(ccNumber.length) == 16 && 
    ccNumber.substring(0,1)=="4") 
    return "VISA";
  if (Number(ccNumber.length) == 13 && 
    (ccNumber.substring(0,1)=="4")) 
    return "VISA";
  if (Number(ccNumber.length) == 16 && 
    ccNumber.substring(0,4)=="6011") 
	{
window.alert ("Sorry, We do not accept DISCOVER Cards")
	return "";
  }
  
  if  (Number(ccNumber.length) == 15 && 
    (ccNumber.substring(0,2)=="34" || 
    ccNumber.substring(0,2)=="37")) 
    { 
    return "AMEX";
    }
  
  if (Number(ccNumber.length) == 14 && 
    (ccNumber.substring(0,2)=="36" || 
    ccNumber.substring(0,2)=="30" || 
    ccNumber.substring(0,2)=="38")) 
   {
    window.alert ("Sorry, We do not accept DINERSCLUB Cards")
    return "";
   } 
 
 
  return ""; // unknown credit card type 
}



