function OpenNewForm(theForm)
{
 var myRef ;
 var strURL = ""; 
var strInsChecked ="";	
 
  strURL = "http://getinsurancequotes.org/Common/Landing.php";
  strURL = strURL + "?zip=" + document.getElementById('zip').value;
/*if (document.getElementById('Type').value == 'Auto')
{
	strInsChecked="&noinsurance=no";	
}*/	

  strURL = strURL + strInsChecked;
  strURL = strURL + "&refby=616019";
  strURL = strURL + "&type=" + document.getElementById('Type').value;
  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");
}
  
}



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://getinsurancequotes.org/auto_results.html";
   		strURL = strURL + "?zipcode=" + document.getElementById('zip').value;
   		strURL = strURL + "&refby=616019";
	} else {
		strURL= "http://getinsurancequotes.org/Common/Landing.php";
   		strURL = strURL + "?zip=" + document.getElementById('zip').value;
		strURL = strURL + "&refby=616019";
		strURL = strURL + "&type=" + document.getElementById('InsuranceType').value;
		strURL = strURL + "&noinsurance=yes";
	}
	window.location= strURL;
	return false;	
}


function OpenNewFormAuto(theForm){
	
 	var myRef ;
 	var strURL = "";
  	var strInsChecked = "";
  	//var strInsChecked = "&noinsurance=no";
 
  	strURL= "http://getinsurancequotes.org/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=616019";
		strURL = strURL + "&type=" + document.getElementById('Type').value;
		
		//window.location=strURL;
		window.open(strURL,null,"fullscreen=yes, toolbars=yes, scrollbars=yes, menubar=yes, location=yes");
		window.location="auto_bw.html?zipcode=" + document.getElementById('zip').value; 	

}





function redirect(theForm) 
{
	var strErr = "";
	if(document.getElementById('zip').value=="")
	{
		strErr = strErr + "Please enter zip code.\n";
		theForm.Zip.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_bw.html?zipcode=" + document.getElementById('zip').value;
            }
                if(document.getElementById('Type').value =="Home" || document.getElementById('Type').value =="Renter")
        	{
			    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()
			//window.location='health_results.html?zipcode='+document.getElementById('zip').value
            	}		
		if(document.getElementById('Type').value =="Life")
        	{
			window.location="life_results.html?zipcode=" + document.getElementById('zip').value;
            }		
			
     }


}
function ValidateForm(theForm)
{
	
	var strErr = "";
	if(document.getElementById('Type').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('Type').value == 'Auto'){ // For Auto 
        	OpenNewFormAuto(theForm);
        } else {	// For Others
     		 preserveRefby();
        	OpenNewForm(theForm);
		}
     }
}	


 
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.location=strURL;
		//window.open(strURL,null,"fullscreen=yes, toolbars=yes, scrollbars=yes, menubar=yes, location=yes, width=1000,height=900");
	}
}


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 trim(str){



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



}


       

function SetErrorImage(strFieldName, blnIsError)

{

	if (blnIsError) {

		eval("document.getQuoteForm."+strFieldName+"_ErrImg.src = \"http://www.insureme.com/images/alert.gif\"");

	}

	else {

		eval("document.getQuoteForm."+strFieldName+"_ErrImg.src = \"http://www.insureme.com/images/trans.gif\"");

	}

}
