

function ValidateForm(frm)
{
	//callServer();
	//message = "Please fill in following fields:-\n";
	message = "In order to guarantee the lowest price quote, your CONTACT information must be VALID.\n";
	message += "Please correct the following:\n";
	message2 = "Following fields must match with each other:-\n";

	valid = true;
	match = true;
	focused = false;
	
	

	if(frm.Name_last.value=="" || frm.Name_last.value.length<2) // first and last names are reversed ;)
	{
		message += "- First Name\n";
		if( ! focused )
		{
			frm.Name_last.focus();
			focused = true;
		}
		valid = false;
	}
	if(frm.Name_first.value=="" || frm.Name_first.value.length<2) // first and last names are reversed ;)
	{
		message += "- Last Name\n";
		if( ! focused )
		{
			frm.Name_first.focus();
			focused = true;
		}
		valid = false;
	}
	
	if(document.getElementById("ValidName").value=="false")
	{
		message += "- First / Last Name!\n";
		if( ! focused )
		{
			frm.Name_first.focus();
			focused = true;
		}
		valid = false;
	}
	
	if(frm.Address.value=="" || frm.Address.value.length<2)
	{
		message += "- Address\n";
		if( ! focused )
		{
			frm.Address.focus();
			focused = true;
		}
		valid = false;
	}
	/*if(frm.City.value=="")
	{
		message += "- City\n";
		if( ! focused )
		{
			frm.City.focus();
			focused = true;
		}
		valid = false;
	}*/
	// state being name of combo box
	/*
	if(frm.State.value=="-")
	{
		message += "- State\n";
		if( ! focused )
		{
			frm.State.focus();
			focused = true;
		}
		valid = false;
	}
	*/
	/*
	if(frm.Zipcode.value=="" || frm.Zipcode.value.length<5)
	{
		message += "- Zip Code\n";
		if( ! focused )
		{
			frm.Zipcode.focus();
			focused = true;
		}
		valid = false;
	}
	*/
/*	alert(frm.Home_Phone_area_ch.value.charCodeAt(0));
	alert(frm.Home_Phone_area_ch.value.charCodeAt(1));
	alert(frm.Home_Phone_area_ch.value.charCodeAt(2));
	return false;
*/
	if(frm.Home_Phone_area_ch.value=="" || frm.Home_Phone_prefix_ch.value == "" || frm.Home_Phone_ch.value == "" ||
	   isNaN(frm.Home_Phone_area_ch.value) || isNaN(frm.Home_Phone_prefix_ch.value) || isNaN(frm.Home_Phone_ch.value) ||
	   frm.Home_Phone_area_ch.value.length!=3 || frm.Home_Phone_prefix_ch.value.length != 3 || frm.Home_Phone_ch.value.length != 4 ||
	   (frm.Home_Phone_area_ch.value.charCodeAt(0) == frm.Home_Phone_area_ch.value.charCodeAt(1) && frm.Home_Phone_area_ch.value.charCodeAt(1) == frm.Home_Phone_area_ch.value.charCodeAt(2)) )
	{
		message += "- Phone Number\n";
		if( ! focused )
		{
			if(frm.Home_Phone_area_ch.value=="" || isNaN(frm.Home_Phone_area_ch.value) || frm.Home_Phone_area_ch.value.length!=3 || (frm.Home_Phone_area_ch.value.charCodeAt(0) == frm.Home_Phone_area_ch.value.charCodeAt(1) && frm.Home_Phone_area_ch.value.charCodeAt(1) == frm.Home_Phone_area_ch.value.charCodeAt(2)))
				frm.Home_Phone_area_ch.focus();
			else
			if(frm.Home_Phone_prefix_ch.value == "" || isNaN(frm.Home_Phone_prefix_ch.value) || frm.Home_Phone_prefix_ch.value.length != 3)
				frm.Home_Phone_prefix_ch.focus();
			else
				frm.Home_Phone_ch.focus();
			focused = true;
		}
		valid = false;
	}
	if(frm.Email.value=="" || !(frm.Email.value.indexOf("@")>1 && frm.Email.value.lastIndexOf(".") > frm.Email.value.indexOf("@")+1) )
	{
		message += "- Email\n";
		if( ! focused )
		{
			frm.Email.focus();
			focused = true;
		}
		valid = false;
	}
	if(frm.Email.value.indexOf(" ")!=-1 && frm.Email.value.indexOf(" ")!=0 && frm.Email.value.indexOf(" ")!= frm.Email.value.length-1)
	{
		
		message += "- Email: Spaces are not Allowed\n";
		if( ! focused )
		{
			frm.Email.focus();
			focused = true;
		}
		valid = false;
	}
	
	if(frm.Email.value.indexOf("www.")!=-1 || frm.Email.value.indexOf("WWW.")!=-1)
	{
		message += "-Email: (www) not Allowed\n";
		if( ! focused )
		{
			frm.Email.focus();
			focused = true;
		}
		valid = false;
	}

	if(!checkMail(frm.Email.value))
	{
		message += " Please check your email - We can only accept United States Based emails.\n";
		if( ! focused )
		{
			frm.Email.focus();
			focused = true;
		}
		valid = false;
	}
	
	//->Any phones with the following area codes:  900, 911, 411, 456, 500, 555, 222, 333, 444, invalid ones.
	if(frm.Home_Phone_area_ch.value=="900" || frm.Home_Phone_area_ch.value=="911" || frm.Home_Phone_area_ch.value=="441" || frm.Home_Phone_area_ch.value=="456" || frm.Home_Phone_area_ch.value=="500")
	{
		message += "- Invalid Phone Area\n";
		valid=false;
	}
	
	//->Any area code with the first digit of 0 or 1 is an invalid phone number.
	if(frm.Home_Phone_area_ch.value.charAt(0)=="1" || frm.Home_Phone_area_ch.value.charAt(0)=="0")
	{
		message += "- Invalid Phone Area\n";
		valid=false;
	}
	 

     //->800, 888, 877, or 876 (toll free numbers) are considered valid phone numbers.
    if(frm.Home_Phone_area_ch.value=="800" || frm.Home_Phone_area_ch.value=="888" || frm.Home_Phone_area_ch.value=="877" || frm.Home_Phone_area_ch.value=="876")
	{
		//message += "- Invalid Phone Area\n";
		valid=true;
	}
	
	 //-> Any exchange that starts with a 0 or 1 is considered an invalid phone number.
	 
	 if(frm.Home_Phone_prefix_ch.value.charAt(0)=="0" || frm.Home_Phone_prefix_ch.value.charAt(0)=="1")
	 {
		message += "- Invalid Phone Prefix\n";
		valid=false;
	 }
	 
     //-> 411, 555, 611, 911 is considered an invalid phone number.
     
     if(frm.Home_Phone_prefix_ch.value=="411" || frm.Home_Phone_prefix_ch.value=="555" ||  frm.Home_Phone_prefix_ch.value=="611" ||  frm.Home_Phone_prefix_ch.value=="911" )
	 {
		message += "- Invalid Phone Prefix\n";
		valid=false;
	 }
     
    //->  Phone numbers with repeating sequences of 10 digits are considered invalid phone numbers. 
    //-> For example, 305-777-7777 would be considered valid:
    
    if(document.getElementById("ValidPhone").value=="false")
	{
		message += "- Invalid Area Code / Prefix Combination!\n";
		if( ! focused )
		{
			frm.Home_Phone_area_ch.focus();
			focused = true;
		}
		valid = false;
	}



	
	/*
	if(frm.ConfirmEmail.value=="")
	{
		message += "- Confirm Email\n";
		if( ! focused )
		{
			frm.ConfirmEmail.focus();
			focused = true;
		}
		valid = false;
	}
	if(frm.Color.value=="no preference")
	{
		message += "- Color Of Vehicle\n";
		if( ! focused )
		{
			frm.Color.focus();
			focused = true;
		}
		valid = false;
	}
*/
	if(! valid)
	{
		alert(message);
		return false;
	}

	/*
	if(frm.Email.value != frm.ConfirmEmail.value)
	{
		message2 += "- Email and Confirm Email\n";
		if ( match )
			frm.ConfirmEmail.focus();
		match = false;
	}
	*/

	if(! match)
	{
		alert(message2);
		ena(form1.Submit);
		return false;
	}

	// Disable Submit button to disallow redundant requests
	submitonce(frm);
		
	return true;
	
}

function checkMail(e_mail)
{
	return true;
	var domains=".ac|.ca|.com|.edu|.firm|.gov|.int|.mil|.nato|.net|.nom|.org|.store|.us|.web|.cc|.biz|.info|.tv|.name|.jobs";
	var arr=domains.split("|");
	true_=false;
	for(i=0; i<arr.length; i++)
	{
		if(e_mail.indexOf(arr[i])==(e_mail.length-arr[i].length))
			true_=true;
	}	
	return true_;
}

function submitonce(theform)
{
	//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 MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}


function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') {
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (val<min || max<val) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}


