/*

InsureMe Embedded Quote Box

Note: If a visitor arrives at your site with a Refby
from Google, Yahoo or any other search engine, 
the quote box will pass it through to InsureMe. If 
a visitor comes to your site without a Refby via a 
natural search result, the quote box will attach the 
Refby number you indicated when you selected the 
quotebox. This functionality will allow you to 
track your traffic from various search engines 
pointed to the same page and measure revenue 
from your SEO efforts.

If you Improperly modify the code, you may not 
receive credits for your leads.
INSUREME IS NOT RESPONSIBLE FOR LOST 
REVENUE DUE TO THE IMPROPER MODIFICATION 
OF THE EMBEDDED QUOTE BOX CODE.

** InsureMe Embedded Quote Box Terms of Use **

Use of this code implies your acceptance of the
InsureMe Affiliate Agreement.

ANY MODIFICATION TO THIS CODE MAY CAUSE THE 
EMBEDDED QUOTE BOX TO OPERATE IMPROPERLY.
InsureMe is not responsible for revenue lost due to
quote box modification.
		
InsureMe requires that the embedded quote box
includes links to the InsureMe Terms and
Conditions and Privacy Policy. 

END OF QUOTE BOX INSTRUCTIONS

Begin InsureMe.com Embedded Affiliate Quote Box
Code Copyright 2008, InsureMe.  All rights reserved.
*/

function ValidateForm()
{
	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;
	}
	preserveRefby();	
	return true;
}

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\"");
	}
}


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

  document.getElementById("insureme").href = document.getElementById("insureme").href + "?Refby=" + document.getElementById("Refby").value;


