/**
 * 
 */

    	
function Form1_Validator2(Form1)
{
    var submitcount=0; 
	var alertsay = "";
	var re10digit="0123456789"; //regular expression defining a 10 digit number
	
	if(Form1.userName)
	{
		if (Form1.userName.value == ""||Form1.userName.value.length <= 0)
		{
		alert("You must enter a \"User Name\".");
		Form1.userName.focus();
		return (false);
		}
	}
	
	if(Form1.password)
	{
		re = /^\w+$/;	
		if ((Form1.password.value.length <=6)||(Form1.password.value=="")||(!re.test(Form1.password.value)))
		{
		alert("You must enter a \"Password\" 7 to 12 characters; letters and numbers only.");
		Form1.password.focus();
		return (false);
		}
	}
		
	if(Form1.confirmpassword)
	{
		if (!((Form1.password.value)==(Form1.confirmpassword.value)))
		{
		alert("You must enter Password and Confirm Password be same.");
		Form1.confirmpassword.focus();
		return (false);
		}
	}
		
	//check if email available, if so valid
	if(Form1.email1)
	{	
		var at="@"
		var dot="."
		var lat=Form1.email1.value.indexOf(at)
		var lstr=Form1.email1.value.length
		var ldot=Form1.email1.value.indexOf(dot)
		
		if (Form1.email1.value.indexOf(at)==-1 || Form1.email1.value.indexOf(at)==0 || Form1.email1.value.indexOf(at)==lstr)
		{
		alert("Please enter a valid E-mail ID")
		Form1.email1.focus()
		return 
		}

		if (Form1.email1.value.indexOf(dot)==-1 || Form1.email1.value.indexOf(dot)==0 || Form1.email1.value.indexOf(dot)==lstr){
		alert("Please enter a valid E-mail ID")
		Form1.email1.focus()
		return (false);
		}

		if (Form1.email1.value.indexOf(at,(lat+1))!=-1){
		alert("Please enter a valid E-mail ID")
		Form1.email1.focus()
		return (false);
		}

		if (Form1.email1.value.substring(lat+1,lat+2)==dot){
		alert("Please enter a valid E-mail ID")
		Form1.email1.focus()
		return (false);
		}

		if (Form1.email1.value.indexOf(dot,(lat+2))==-1){
		alert("Please enter a valid E-mail ID")
		Form1.email1.focus()
		return (false);
		}
		
		if (Form1.email1.value.indexOf(" ")!=-1){
		alert("Please enter a valid E-mail ID")
		Form1.email1.focus()
		return (false);
		}
		
	}
		
	var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
	if(Form1.email2)
	{
		if (!((Form1.email1.value)==(Form1.email2.value)))
		{
		alert("You must enter Email and Re-Type Email be same.");
		Form1.email2.focus();
		return (false);
		}
	}

	if(Form1.firstName)
	{
		if (Form1.firstName.value == "")
		{
		alert("You must enter a \"First Name\".");
		Form1.firstName.focus();
		return (false);
		}
	
		if (Form1.firstName.value.length > 16)
		{
		alert("\"First Name\" must not exceed 16 characters.");
		Form1.firstName.focus();
		return (false);
		}
	}

	if(Form1.lastName)
	{
		if (Form1.lastName.value == "")
		{
		alert("You must enter a \"Last Name\".");
		Form1.lastName.focus();
		return (false);
		}
	
		if (Form1.lastName.value.length > 16)
		{
		alert("\"Last Name\" must not exceed 16 characters.");
		Form1.lastName.focus();
		return (false);
		}
	}
	
	if (Form1.address1.value == "")
	{
	alert("You must enter an \"Address\".");
				Form1.address1.focus();
				return (false);
			}
			if (Form1.address1.value.length > 35)
			{
				alert("\"Address 1\" must not exceed 35 characters.");
				Form1.address1.focus();
				return (false);
			}
	
			if (Form1.city.value == "")
			{
				alert("You must enter a \"City\".");
				Form1.city.focus();
				return (false);
			}

			if (Form1.city.value.length > 25)
			{
				alert("\"City \" must not exceed 25 characters.");
				Form1.city.focus();
				return (false);
			}  

		// check if no drop down or first drop down is selected, if so, invalid selection
			if (Form1.state.selectedIndex <= 0)
			{
				alert("You must select a \"State\".");
				Form1.state.focus();
			return (false);
			}

			if (Form1.zipcode.value == "")
			{
				alert("You must enter a \"Zip\".");
				Form1.zipcode.focus();
				return (false);
			}
	
				for(var i=0;i<Form1.zipcode.value.length;i++)
				{	
					if (re10digit.indexOf(Form1.zipcode.value.charAt(i))==-1) //if match failed
					{
						alert("\"Zip Code\" must be digits.");
							Form1.zipcode.focus();
							return (false);
					}
				}
		
		//Work
	
			if(Form1.workareacode)
			{
				// check if enough digits have been entered
				if (Form1.workareacode.value.length != 3)
				{
					alert("You must enter 3 digit \"Area Code\".");
					Form1.workareacode.focus();
					return (false);
				}else{
					
					if(!areacodevalidation(Form1.workareacode.value)) {
					
						alert("\"Area Code\" must be 3 digits. Omit country code, parentheses, spaces and hyphens (i.e. 800)");
						Form1.workareacode.focus();
						return (false);
					
					}
				}
			}
	
			if(Form1.workphonenumber)
			{
				if (Form1.workphonenumber.value.length != 7)
				{
					alert("You must enter 7 digit \"Phone Number\".");
					Form1.workphonenumber.focus();
					return (false);
				}else{

					if(!phonenumbervalidation(Form1.workphonenumber.value)) {
					
						alert("\"Phone Number\" must be 7 digits. Omit country code, area code, parentheses, spaces and hyphens (i.e. 5551212)");
						Form1.workphonenumber.focus();
						return (false);
					
					}
				}
			}
		
			if(Form1.workextension && Form1.workextension.value != "" )
			{
				if(!extensionvalidation(Form1.workextension.value))
				{
					
					alert("\"Extention\" must be digits.");
					Form1.workextension.focus();
					return (false);
					
				}
		
			}
			
			if(Form1.homeareacode && Form1.homeareacode.value != "" )
			{
				if(!areacodevalidation(Form1.homeareacode.value))
				{
					
					alert("\"Area Code\" must be 3 digits. Omit country code, parentheses, spaces and hyphens (i.e. 800)");
					Form1.homeareacode.focus();
					return (false);
					
				}
		
			}
			
			if(Form1.homephonenumber && Form1.homephonenumber.value != "" )
			{
				if(!phonenumbervalidation(Form1.homephonenumber.value))
				{
					
					alert("\"Phone Number\" must be 7 digits. Omit country code, area code, parentheses, spaces and hyphens (i.e. 5551212)");
					Form1.homephonenumber.focus();
					return (false);
					
				}
		
			}
			
			if(Form1.homeextension && Form1.homeextension.value != "" )
			{
				if(!extensionvalidation(Form1.homeextension.value))
				{
					
					alert("\"Extention\" must be digits.");
					Form1.homeextension.focus();
					return (false);
					
				}
		
			}
			
			if(Form1.faxareacode && Form1.faxareacode.value != "" )
			{
				if(!areacodevalidation(Form1.faxareacode.value))
				{
					
					alert("\"Area Code\" must be 3 digits. Omit country code, parentheses, spaces and hyphens (i.e. 800)");
					Form1.faxareacode.focus();
					return (false);
					
				}
		
			}
			
			if(Form1.faxphonenumber && Form1.faxphonenumber.value != "" )
			{
				if(!phonenumbervalidation(Form1.faxphonenumber.value))
				{
					
					alert("\"Fax Number\" must be 7 digits. Omit country code, area code, parentheses, spaces and hyphens (i.e. 5551212)");
					Form1.faxphonenumber.focus();
					return (false);
					
				}
		
			}
			
			if(Form1.faxextension && Form1.faxextension.value != "" )
			{
				if(!extensionvalidation(Form1.faxextension.value))
				{
					
					alert("\"Extention\" must be digits.");
					Form1.faxextension.focus();
					return (false);
					
				}
		
			}
			
			
			
	
		return true;
	
}	
  

/*FOR ADS:: checkout Address :BEGIN*/
		function CheckAddressInfo(form1){
			var msg='Missing Information: ';

	/* this is to check that the address fields are enetered before it hits the button */
	
		if (form1.firstName)
		{
			if (form1.firstName.value == '')
			{
			msg+="Bill-To First Name";
			alert(msg);
			form1.firstName.focus();
			return false;
			}
		}
		if (form1.lastName)
		{
			if (form1.lastName.value == '')
			{
			
			msg+="Bill-To Last Name";
			alert(msg);
			form1.lastName.focus();
			
			return false;
		}
		} 
		
		
		if (form1.address1)
		{
			if (form1.address1.value == '')
			{
			
			msg+="Bill-To Street";
			alert(msg);
			form1.address1.focus();
			
			return false;
		}
		}
		if (form1.city)
		{
			if (form1.city.value == '')
			{
			
			msg+="Bill-To City";
			alert(msg);
			form1.city.focus();
			return false;
		}
		}
		if (form1.billto_state)
		{
			if (form1.billto_state.value == 'XX')
			{
			
			msg+="Bill-To State";
			alert(msg);
			form1.billto_state.focus();
		
			return false;
			}
			else if (form1.billto_state.value == '')
			{
			
			msg+="Bill-To State";
			alert(msg);
			form1.billto_state.focus();
		
			return false;
			}
		}
		if (form1.zipcodeBillTo)
		{
			if (form1.zipcodeBillTo.value == '')
			{
			
			msg+="Bill-To Zip Code";
			alert(msg);
			form1.zipcodeBillTo.focus();
			
			return false;
		}
		}
		
		if (form1.phone_number_exch)
		{
			if (form1.phone_number_exch.value =='')
			{
				msg+="Area Code";
				alert(msg);
				form1.phone_number_exch.focus();
				return false;
				
			}else{
			
				if (!areacodevalidation(form1.phone_number_exch.value)) {
				
					alert("\"Area Code\" must be 3 digits. Omit country code, parentheses, spaces and hyphens (i.e. 800)");
					form1.phone_number_exch.focus();
					return false;
				
				}
			}
		}
	
		
		if(form1.workphonenumber)
			{
				if (form1.workphonenumber.value.length != 7)
				{
					alert("You must enter 7 digit \"Phone Number\".");
					Form1.workphonenumber.focus();
					return (false);
				}else{

					if(!phonenumbervalidation(form1.workphonenumber.value)) {
					
						alert("\"Phone Number\" must be 7 digits. Omit country code, area code, parentheses, spaces and hyphens (i.e. 5551212)");
						form1.workphonenumber.focus();
						return (false);
					
					}
				}
			}
		
		
		
		
		
		if(form1.workextension) {
		
			if(form1.workextension.value.length > 0 || form1.workextension.value != '' )
		  	{
			
				if(!extensionvalidation(form1.workextension.value))
				{
					alert("\"Extention\" must be digits.");
					form1.workextension.focus();
				}
          		
			}
		}	
	
		if (form1.email)
		{
			if(!emailvalidation(form1.email.value)) {
				msg+="Please enter Valid Email Address";
				alert(msg);
				form1.email.focus();
				return false; 
			}
		}
		
			if (form1.shipto_firstname)
			{if (form1.shipto_firstname.value == '')
			{
				
				msg+="Ship-To First Name";
				alert(msg);
				form1.shipto_firstname.focus();
			
				return false;
			}}
			if (form1.shipto_lastname)
			{if (form1.shipto_lastname.value == '')
			{
				
				msg+="Ship-To Last Name";
				alert(msg);
				form1.shipto_lastname.focus();
			
				return false;
			}}
			
			if (form1.shipaddress1)
			{if (form1.shipaddress1.value == '')
			{
				
				msg+="Ship-To Street";
				alert(msg);
				form1.shipaddress1.focus();
			
				return false;
			}}
			if (form1.shipto_city)
			{if (form1.shipto_city.value == '')
			{
				
				msg+="Ship-To City";
				alert(msg);
				form1.shipto_city.focus();
			
				return false;
			}}
			if (form1.shipto_state)
			{
				if (form1.shipto_state.value == 'XX')
				{
				
				msg+="Ship-To State";
				alert(msg);
				form1.shipto_state.focus();
			
				return false;
				}
				else if (form1.shipto_state.value == '')
				{
				
				msg+="Ship-To State";
				alert(msg);
				form1.shipto_state.focus();
			
				return false;
				}
			}
			if (form1.shipto_postalcode)
			{if (form1.shipto_postalcode.value == '')
			{
				
				msg+="Ship-To Zip Code";
				alert(msg);
				form1.shipto_postalcode.focus();
				
				return false;
			}}
		
		
		
		
			return true;
		
	}
	
	function emailvalidation(email) {
		var validemail = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+[\.]{1}[a-zA-Z]{2,4}$/;
			
		if(email.search(validemail)==-1) {
        	return false;	
          	}
		return true;
	}
	
	function areacodevalidation(areacode) {
		var re3digit=/^\d{3}$/;
		
		if(areacode.search(re3digit)==-1) {
        	return false;	
          	}
		return true;
	}
	
	function phonenumbervalidation(phonenumber) {
		var re7digit=/^\d{7}$/;
		
		if(phonenumber.search(re7digit)==-1) {
        	return false;
          	}
		return true;	
	}
	
	function extensionvalidation(extension) {
		var re10digit="0123456789";
		
		for(var i=0;i<extension.length;i++)
		{
			if (re10digit.indexOf(extension.charAt(i))==-1) //if match failed
			{
				return false;
			}
		}
		return true;
	}
	
	
function SameAsBill() {
	var checkBox = document.getElementById("shiptosame");
	
	var shipFName = document.getElementById("shipto_firstname");
	var shipLName = document.getElementById("shipto_lastname");
	var shipCompany = document.getElementById("shipto_company");
	var shipStreet = document.getElementById("shipaddress1");
	var shipStreet2 = document.getElementById("shipaddress2");
	var shipZip = document.getElementById("shipto_postalcode");
	var shipCity = document.getElementById("shipto_city");
	var shipState = document.getElementById("shipto_state");
	
	if (document.getElementById("zipcodeBillTo").value !=""){
	
		if (checkBox.checked == true){
			
			shipFName.value = document.getElementById("firstName").value;
			shipLName.value = document.getElementById("lastName").value;
			shipCompany.value = document.getElementById("billto_company").value;
			shipStreet.value = document.getElementById("address1").value;
			shipStreet2.value = document.getElementById("address2").value;
			shipZip.value = document.getElementById("zipcodeBillTo").value;
			
			document.getElementById("shipTo_zipCodeButton").click();
			shipCity.value = document.getElementById("city").value;
			shipState.value = document.getElementById("billto_state").value;
			
		} else {
				shipFName.value = "";
					shipLName.value = "";
					
					shipCompany.value = "";
					shipStreet.value = "";
					shipStreet2.value = "";
					shipZip.value = "";
					shipCity.value = "";
					shipState.value = "";
		}
	} else {
		checkBox.checked = false;
		alert("Please Enter Bill-to Zip Code");
	}					
						
}


