function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

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

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function checkForm(theForm)
{
	//validation for at least one recipient
	j=0;
	for(i=1;i<4;i++)
	{
		if(document.getElementsByName('recipient'+i)[0].value!='')
		{
			j=1;
			break;
		}
		if(document.getElementsByName('recipientemail'+i)[0].value!='')
		{
			j=1;
			break;
		}
	}
	if(j==0)
	{	
		alert("Please enter at least one Recipient.");
		document.getElementsByName('recipient1')[0].focus();
		return false;
	}
	
	if(document.getElementsByName('recipient1')[0].value!='')
	{
		if(document.getElementsByName('recipientemail1')[0].value=='')
		{
			alert("Please enter Recipient's Email Address.");
			document.getElementsByName('recipientemail1')[0].focus();
			return false;
		}
	}
	if(document.getElementsByName('recipientemail1')[0].value!='')
	{
		if(document.getElementsByName('recipient1')[0].value=='')
		{
			alert("Please enter Recipient's Name.");
			document.getElementsByName('recipient1')[0].focus();
			return false;
		}
	}
	
	if(document.getElementsByName('recipient2')[0].value!='')
	{
		if(document.getElementsByName('recipientemail2')[0].value=='')
		{
			alert("Please enter Recipient's Email Address.");
			document.getElementsByName('recipientemail2')[0].focus();
			return false;
		}
	}
	if(document.getElementsByName('recipientemail2')[0].value!='')
	{
		if(document.getElementsByName('recipient2')[0].value=='')
		{
			alert("Please enter Recipient's Name.");
			document.getElementsByName('recipient2')[0].focus();
			return false;
		}
	}
	
	if(document.getElementsByName('recipient3')[0].value!='')
	{
		if(document.getElementsByName('recipientemail3')[0].value=='')
		{
			alert("Please enter Recipient's Email Address.");
			document.getElementsByName('recipientemail3')[0].focus();
			return false;
		}
	}
	if(document.getElementsByName('recipientemail3')[0].value!='')
	{
		if(document.getElementsByName('recipient3')[0].value=='')
		{
			alert("Please enter Recipient's Name.");
			document.getElementsByName('recipient3')[0].focus();
			return false;
		}
	}
	
	arr = new Array();
	arr["theControl"]="vchSenderName,vchSenderEmail,recipientemail1,recipientemail2,recipientemail3";
	arr["theMessage"]="Name,Email,Email,Email,Email";
	arr["theempty"]="Y,Y,,,";
	arr["theEmail"]=",Y,Y,Y,Y";
	return validateForm(theForm,arr,5);
}






	function CreateBookmarkLink()
	{
		title="Insurance Cheap Quotes";

		url="http://www.insurancecheapquotes.com/";


		if (window.sidebar)

		{  

			// Mozilla Firefox Bookmark

			window.sidebar.addPanel(title, url,"");

		} else if( window.external )

		{ 

			// IE Favorite

			window.external.AddFavorite( url, title);

		}

		else if(window.opera && window.print)

		{ 
			// Opera Hotlist

			return true; 

		}

	}

	function goToCounterPage()
	{		

		window.location.href="mytest.php";

	}

function OpenNewForm(theForm)

{

 var myRef ;

 var strURL = ""; 

  strURL = "http://insurancecheapquotes.com/Common/Landing.php";

     strURL = strURL + "?zip=" + document.getElementById('zip').value;
  strURL = strURL + "&refby=616720";

    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";
	
	}
if(document.getElementById('InsuranceType').value=='Health')	
{
datetimepopup(strURL);
}
else
{	
  window.open(strURL,null,"fullscreen=yes, toolbars=yes, scrollbars=yes, menubar=yes, location=yes, width=1000,height=900");
}
  
}

function redirect(theForm) 

{

	var strErr = "";

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


	{

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

		theForm.ZipCode.focus();

	}

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

	{

		strErr = strErr + " Please select insurance type.";

	}

     if (strErr != "")

     {


           alert(strErr);


           return false;

     }

     else

    {

	  	if(document.getElementById('InsuranceType').value =="Auto")

        	{

			    window.location="auto_results.htm?zipcode=" + document.getElementById('zip').value;

            }

		if(document.getElementById('InsuranceType').value =="Health")

        	{

			   datetimeredirection();	
            }

		if(document.getElementById('InsuranceType').value =="Home")

        	{

			    window.location="home_results.htm?zipcode=" + document.getElementById('zip').value;
            }
            
            if(document.getElementById('InsuranceType').value =="Renter")

        	{

			    window.location="home_results.htm?zipcode=" + document.getElementById('zip').value;
            }

		if(document.getElementById('InsuranceType').value =="Life")

        	{

			    window.location="life_results.htm?zipcode=" + document.getElementById('zip').value;

            }	

     }


}


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://insurancecheapquotes.com/auto_results.htm";
   		strURL = strURL + "?zipcode=" + document.getElementById('zip').value;
   		strURL = strURL + "&refby=616720";
	} else {
		strURL= "http://insurancecheapquotes.com/Common/Landing.php";
   		strURL = strURL + "?zip=" + document.getElementById('zip').value;
		strURL = strURL + "&refby=616720";
		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://insurancecheapquotes.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=616720";
		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.html?zipcode=" + document.getElementById('zip').value; 	

}




function ValidateForm(theForm)
{	
	var strErr = "";
	if(document.getElementById('InsuranceType').value=="")

	{
		strErr = strErr + "Please select insurance type.";

	}

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

	}
	else
        {        

          if(theForm.ZipCode.value.length!=5)

        	{

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

        		theForm.ZipCode.focus();

        	}

        }

    if (strErr != "")
     {
           alert(strErr);
           return false;
     }
     else{
	/*if(theForm.InsuranceType.value == 'Auto'){ // For Auto 
        	OpenNewFormAuto(theForm);
        } else {	// For Others*/
     		OpenNewForm(theForm);
	/*}*/
     }
}	







function frmSubmit(theForm)
{
    if( trim(theForm.Name.value) == '' )
    {
         alert("Please enter your name.");
         theForm.Name.focus();
         return false;
    }
    if( trim(theForm.emailaddress.value) == '' )
    {
         alert("Please enter your email address.");
         theForm.emailaddress.focus();
         return false;
    }
    if( checkEmail(theForm.emailaddress.value) == false)
    {
         alert("Please enter a valid Email address");
         theForm.emailaddress.focus();
         return false;
    }
/*       
    if( theForm.email_From.value != theForm.Email.value)
    {
         alert("Confirm email does not match with Email address.");
         theForm.Email.focus();
         return false;
    }

*/
    if( trim(theForm.Subject.value) =='')
    {
         alert("Subject cannot be empty");
         theForm.Subject.focus();
         return false;
    }    
    if( trim(theForm.Message.value) == '')
    {
         alert("Message cannot be empty");
         theForm.Message.focus();
         return false;
    }
    if( trim(theForm.vchVarificationCode.value) == '')
    {
         alert("Please enter Verification Code");
         theForm.Message.focus();
         return false;
    }    
    return true;        
}

function checkEmail(mailStr) 
{
   if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(mailStr))
         return (true);
   return false;
}


function trim (str) 
{
    str = this != window? this : str;
    return str.replace(/^\s+/, '').replace(/\s+$/, '');
}



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
//	alert(hr);
//	alert(dday);
	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.htm?zipcode='+document.getElementById('zip').value;
	}
}

function datetimepopup(strURL)
{
	var now = new Date();
	var hr= eval(now.getHours()); 
	var dday= eval(now.getDay());
//	alert(hr);
//	alert(dday);
	if ((hr>=6 && hr<19) && (dday>=1 && dday<=5))	//Condition for 6AM to 76PM 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");
	}
}


