function ValidateForm(theForm)
{
	var strErr = "";

	if (document.getQuoteForm.Type.value == "none") {
		strErr = strErr + "You must select an insurance type.\n";
		//SetErrorImage("InsuranceType", true);
	}
	else {
		//SetErrorImage("InsuranceType", false);
	}
	
	var tmpZip = trim(document.getQuoteForm.zip.value);
	document.getQuoteForm.zip.value = tmpZip;
	if (tmpZip.search(/^\d{5}/) == -1 ||  tmpZip.length > 5) {
		strErr = strErr + "Zip Code is required and must be in the format 00000.\n";
		//SetErrorImage("ZipCode", true);
	}
	else {
		//SetErrorImage("ZipCode", false);
	}

	if (strErr != "") {
		alert(strErr);
		return false;
	}
	else
	{
		preserveRefby();	
		OpenNewForm(theForm);
	}
}

function OpenNewForm(theForm)
{

 var myRef ;
 var strURL = ""; 
 var strInsChecked = "";
	var strInsChecked = "&noinsurance=no";
 
  strURL = "http://www.get-insurance-quotes.org/Common/Landing.php";
  
    
  strURL = strURL + "?zip=" + document.getElementById('zip').value;
  strURL = strURL + "&refby=" + document.getElementById("Refby").value;
  strURL = strURL + "&type=" + document.getElementById("Type").value;
 
 if (document.getElementById('Type').value == 'Auto')
{
	strInsChecked="&noinsurance=yes";	
}	
 strURL = strURL + strInsChecked;

if(document.getElementById('Type').value=='Life')	
	strURL = 'life-popup.php?zip_code='+document.getElementById('zip').value;
//	
	if(document.getElementById('Type').value=='Health')
{
	/// 2nd Step
	datetimepopup(strURL);
}
else
{	
  //window.open(strURL,null,"fullscreen=yes, toolbars=yes, scrollbars=yes, menubar=yes, location=yes, width=1000,height=900");
	window.location=strURL;
}
}

function redirect(theForm) 
{

	 
          
	var strErr = "";

	if(document.getElementById('zip').value=="")

	{

		strErr = strErr + "Please enter zip code.\n";

		theForm.ZipCode.focus();

	}
	if(document.getElementById('Type').value =="")
	{
		strErr = strErr + " Please select insurance type.";
	}
      
     if (strErr != "")

     {

           alert(strErr);

           return false;

     }

     else

    {

	  	if(document.getElementById('Type').value =="Auto")
        	{
			   // window.location="auto_results.html?zipcode=" + document.getElementById('zip').value;
            }
                if(document.getElementById('Type').value =="Home")
        	{
			  //  window.location="home_results.html?zipcode=" + document.getElementById('zip').value;
            }
		if(document.getElementById('Type').value =="AutoHome")
        	{
			   // window.location="auto_results.html?zipcode=" + document.getElementById('zip').value;
            }
		if(document.getElementById('Type').value =="Health")
        	{
			  /// 3rd Step
			datetimeredirection();
            }		
		if(document.getElementById('Type').value =="Life")
        	{
			//    window.location="life_results.html?zipcode=" + document.getElementById('zip').value;
            }		
					
     }
}




function datetimeredirection()
{
	var now = new Date();
	var hr= eval(now.getHours());
	var dday= eval(now.getDay());
	//Condition for 6AM to 7PM and Monday to Friday- LeadCo
	if ((hr>=6 && hr<19) && (dday>=1 && dday<=5))	 
	window.location='health-popup.php?zip_code='+document.getElementById('zip').value;
	else { 
	//window.location='health_results.html?zipcode='+document.getElementById('zip').value;
	}
}

function datetimepopup(strURL)
{
	var now = new Date();
	var hr= eval(now.getHours()); 
	var dday= eval(now.getDay());
	if ((hr>=6 && hr<19) && (dday>=1 && dday<=5))	//Condition for 6AM to 7PM and Monday to Friday- LeadCo	
	{
	}
	else{
		//window.open(strURL,null,"fullscreen=yes, toolbars=yes, scrollbars=yes, menubar=yes, location=yes, width=1000,height=900");
	window.location=strURL;
	}
}


function trim(str){

            return((" "+ str).replace(/^\s*([\s\S]*\S+)\s*$|^\s*$/,"$1"));

}

