
function OpenNewForm(theForm)
{
	var myRef ;
	var strURL = ""; 
	
	strURL = "http://autoinsuranceequotes.com/Common/Landing.php";
	strURL = strURL + "?zip=" + document.getElementById('zip').value;
	strURL = strURL + "&refby=616721";
	var strInsChecked='';	
	strURL = strURL + strInsChecked;    	

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

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

	if(document.getElementById('zip').value=="")
	{
		strErr = strErr + "Please enter zip code.\n";
		theForm.ZipCode.focus();
	}

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

		if(document.getElementById('InsuranceType').value =="Auto")
        	{
			 // window.location.href="auto_bw.htm?zipcode=" + document.getElementById('zip').value;
			 // window.location.href="auto.php?zipcode=" + document.getElementById('zip').value;
	        }
		if(document.getElementById('InsuranceType').value =="Health")
        	{
			     /// 3rd Step
			datetimeredirection();
			//window.location.href="health_results.html?zipcode=" + document.getElementById('zip').value;	
	        }
		if((document.getElementById('InsuranceType').value =="Home") || (document.getElementById('InsuranceType').value =="Renter")) 
        	{
			   window.location.href="home_results.htm?zipcode=" + document.getElementById('zip').value;
		}
		if(document.getElementById('InsuranceType').value =="Life")
        	{
			  //  window.location.href="life_results.htm?zipcode=" + document.getElementById('zip').value;
            	}	
        //window.location="auto_results.html?zipcode=" + document.getElementById('zip').value;	
     }
}

function ValidateForm(theForm)
{
	var strErr = "";
	if(document.getElementById('InsuranceType').value=="none")
	{
		strErr = strErr + "Please select insurance type.\n";
	}
	if(document.getElementById('zip').value=="")
	{
		strErr = strErr + "Please enter zip code.\n";
		document.getElementById('zip').focus();
	}
	else
        {
           if(document.getElementById('zip').value.length!=5)
         	{
           		strErr = strErr + "Please enter valid zip code.\n";
			document.getElementById('zip').focus();
         	}
        }
     if (strErr != "")
     {
           alert(strErr);
           return false;
     }
     else{
     	
	if(document.getElementById('InsuranceType').value == "Auto"){ // For Auto 
        	OpenNewFormAuto(theForm);
        } else {	// For Others*/
     		preserveRefby();
        	OpenNewForm(theForm);
		}
     }
}	

function AutoRedirect(theForm) 
{
	var myRef ;
 	var strURL = "";
  	var strInsChecked = "";
	var strInsChecked = "&noinsurance=no";
	//alert(document.getElementById('rblInsurance').checked);
	if (document.getElementById('rblInsurance').checked==false)
	{
		strURL= "http://autoinsuranceequotes.com/auto_results.htm";
   		strURL = strURL + "?zipcode=" + document.getElementById('zip').value;
   		strURL = strURL + "&refby=616721";
	} else {
		strURL= "http://autoinsuranceequotes.com/Common/Landing.php";
   		strURL = strURL + "?zip=" + document.getElementById('zip').value;
		strURL = strURL + "&refby=616721";
		strURL = strURL + "&type=" + document.getElementById('InsuranceType').value;
		strURL = strURL + "&noinsurance=yes";
	}
	window.location= strURL;
	//window.open(strURL,null,"fullscreen=yes, toolbars=yes, scrollbars=yes, menubar=yes, location=yes")
	return false;	
}

function OpenNewFormAuto(theForm){
	
 	var myRef ;
 	var strURL = "";
  	var strInsChecked = "";
  	//var strInsChecked = "&noinsurance=no";
 
  	strURL= "http://autoinsuranceequotes.com/auto.php";    
   	strURL = strURL + "?zip=" + document.getElementById('zip').value;
 	//alert(strURL);
	  /*if (document.getElementById('rblInsurance').checked)
	   {
	          strInsChecked = "&noinsurance=yes";
	   } */
		
		//strURL = strURL + strInsChecked;
		//alert(strURL);
		strURL = strURL + "&refby=616721";
		strURL = strURL + "&type=" + document.getElementById('InsuranceType').value;
		
			//window.location=strURL;
		window.open(strURL,null,"fullscreen=yes, toolbars=yes, scrollbars=yes, menubar=yes, location=yes");
		window.location="auto_bw.htm?zipcode=" + document.getElementById('zip').value; 	

}

function preserveRefby()

      {

          var queryStringRefby = "";

          var queryString = location.search.substring(1).toLowerCase();

          var firstchar = queryString.indexOf("refby=",0);

          if(firstchar >= 0)

	var secondchar = queryString.indexOf("&",firstchar+6);

          else

	var secondchar = -1;	 	

          if(secondchar > 0)

          {

                queryStringRefby = queryString.substring(firstchar+6, secondchar);

          }

          else if(firstchar >= 0){

                queryStringRefby = queryString.substring(firstchar+6, queryString.length);

          }

          if(queryStringRefby.length > 0)

          {

	document.getElementById("Refby").value = queryStringRefby;

          }			 

   }
   
   



function datetimeredirection()
{
	var now = new Date();
	var hr= eval(now.getHours());
	var dday= eval(now.getDay());
	//Condition for 7AM to 6PM and Monday to Friday- LeadCo
	if ((hr>=7 && hr<18) && (dday>=1 && dday<=5))	 
	window.location='health-popup.php?zip='+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>=7 && hr<18) && (dday>=1 && dday<=5))	//Condition for 7AM to 6PM 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 statewise_forms(strURL,zip)
{
	var strURLNew;
	if ((zip>=90000 && zip<=96699) || (zip>=80000 && zip<=81999) || (zip>=06000 && zip<=06999) || (zip>=30000 && zip<=31999) || (zip>=46000 && zip<=47999) || (zip>=40000 && zip<=42999)  || (zip>=03900 && zip<=04999)  || (zip>=63000 && zip<=65999) || (zip>=88900 && zip<=89999) || (zip>=03000 && zip<=03899) || (zip>=10000 && zip<=14999) || (zip>=43000 && zip<=45999) || (zip>=22000 && zip<=24699) || (zip>=53000 && zip<=54999))
	{
		strURLNew = 'health-popup.php?zip_code='+document.getElementById('zip').value;
		
	} else {
		strURLNew =strURL;
	}
	window.open(strURLNew,null,"fullscreen=yes, toolbars=yes, scrollbars=yes, menubar=yes, location=yes, width=1000,height=900");
}



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];}}
}
