//global vars
var EsuranceWebServerName = "www.esurance.com";

var eSuranceQuoteID;
var eSuranceSessionID;

EsuranceWebServerName = "http://" + EsuranceWebServerName;

function DeleteCookie()
{
	window.location.href = EsuranceWebServerName+"/?sessionstatus=abandon";
}

function ValidateMaritalStatus() {
    var maritalStatus = document.getElementById('ddMaritalStatus');
    if (maritalStatus != null) {
        if (maritalStatus.value == null || maritalStatus.value == "")
            if (!maritalStatus.disabled) {
                alert("Please select your marital status.");
                return false;
            }
    }
    return true;
}

function setSessionId(sessionId) {
    if (document.getElementById(sessionId) != null)
        eSuranceSessionID = document.getElementById(sessionId).value;
}

function setQuoteId(quoteId) {

    if (document.getElementById(quoteId) != null)
        eSuranceQuoteID = document.getElementById(quoteId).value;
}

function openWindowAboutAllState(url, trackInfo) {
    var url = EsuranceWebServerName + url;
//    AllStateMessageTracking(trackInfo);
    window.open(url, 'Allstate', 'scrollbars=yes,resizable=yes,toolbar=yes,menubar=yes,location=yes,height=480,width=800');
}


function isZip() 
{
     // Check for correct zip code
	if(document.landingform.txtEnterKey != null)
	{
	
		if(document.landingform.txtEnterKey.value != "1")
		{
			var s="";
			if(document.landingform.txtZipCode!=null)
			{
				s = document.landingform.txtZipCode.value;
			}
			else if(document.landingform.zip1_txtZipCode!=null)
			{
				s = document.landingform.zip1_txtZipCode.value;
			}
			else if(document.landingform.V1A_txtZipCode!=null)
			{
				s = document.landingform.V1A_txtZipCode.value;
			}
			else if(document.landingform.V1B_txtZipCode!=null)
			{
				s = document.landingform.V1B_txtZipCode.value;
			}
			else if(document.landingform.V2A_txtZipCode!=null)
			{
				s = document.landingform.V2A_txtZipCode.value;
			}
			else if(document.landingform.V2B_txtZipCode!=null)
			{
				s = document.landingform.V2B_txtZipCode.value;
			}
			else if(document.landingform.V3A_txtZipCode!=null)
			{
				s = document.landingform.V3A_txtZipCode.value;
			}
			else if(document.landingform.V3B_txtZipCode!=null)
			{
				s = document.landingform.V3B_txtZipCode.value;
			}
            reZip = new RegExp(/(^\d{5}$)|(^\d{5}-\d{4}$)/);
            if (!reZip.test(s)) {
                alert("Please enter a 5-digit numeric ZIP Code.");
                if (document.landingform.txtZipCode != null) {
                    document.landingform.txtZipCode.value = "";
                }
                else if (document.landingform.zip1_txtZipCode != null) {
                    document.landingform.zip1_txtZipCode.value = "";
                }
                if ($.browser.msie) 
                    window.location.href(EsuranceWebServerName);
                return false;
            }
		}
	}
	else
	{
			var s="";
			if(document.landingform.txtZipCode!=null)
			{
				s = document.landingform.txtZipCode.value;
			}
			else if(document.landingform.zip1_txtZipCode!=null)
			{
				s = document.landingform.zip1_txtZipCode.value;
			}
			else if(document.landingform.V1A_txtZipCode!=null)
			{
				s = document.landingform.V1A_txtZipCode.value;
			}
			else if(document.landingform.V1B_txtZipCode!=null)
			{
				s = document.landingform.V1B_txtZipCode.value;
			}
			else if(document.landingform.V2A_txtZipCode!=null)
			{
				s = document.landingform.V2A_txtZipCode.value;
			}
			else if(document.landingform.V2B_txtZipCode!=null)
			{
				s = document.landingform.V2B_txtZipCode.value;
			}
			else if(document.landingform.V3A_txtZipCode!=null)
			{
				s = document.landingform.V3A_txtZipCode.value;
			}
			else if(document.landingform.V3B_txtZipCode!=null)
			{
				s = document.landingform.V3B_txtZipCode.value;
			}
			
			reZip = new RegExp(/(^\d{5}$)|(^\d{5}-\d{4}$)/);
			if (!reZip.test(s)) 
			{
				alert("Please enter a 5-digit numeric ZIP Code.");
				return false;
			}
			else
			{
				return true;
			}
	}
}
function validateFieldsOnEnter(e)	
{
	var keynum;
	var keychar;
	var numcheck;
	if(window.event) // IE
	{
		keynum = e.keyCode;
	}
	else if(e.which) // Netscape/Firefox/Opera
	{
		keynum = e.which;
	}
	if(keynum == 13) 
	{
		var strZipCode ="";
		var prefix = "";
		if(document.landingform.txtZipCode!=null)
			{
				strZipCode = document.landingform.txtZipCode.value;
				prefix="";
			}
			else if(document.landingform.V1A_txtZipCode!=null)
			{
				strZipCode = document.landingform.V1A_txtZipCode.value;
				prefix= "V1A_";
			}
			else if(document.landingform.V1B_txtZipCode!=null)
			{
				strZipCode = document.landingform.V1B_txtZipCode.value;
				prefix = "V1B_";
			}
			else if(document.landingform.V2A_txtZipCode!=null)
			{
				strZipCode = document.landingform.V2A_txtZipCode.value;
				prefix = "V2A_";
			}
			else if(document.landingform.V2B_txtZipCode!=null)
			{
				strZipCode = document.landingform.V2B_txtZipCode.value;
				prefix = "V2B_";
			}
			else if(document.landingform.V3A_txtZipCode!=null)
			{
				strZipCode = document.landingform.V3A_txtZipCode.value;
				prefix = "V3A_";
			}
			else if(document.landingform.V3B_txtZipCode!=null)
			{
				strZipCode = document.landingform.V3B_txtZipCode.value;
				prefix = "V3B_";
			}

		if(document.getElementById(prefix + "txtAcctPwd").value == "" && strZipCode == "")
		{
			document.getElementById("txtEnterKey").value = "2";
		}
		else
			document.getElementById("txtEnterKey").value = "1";
		if(document.getElementById(prefix + "txtAcctPwd").value != "" && strZipCode != "")
		{
			document.getElementById("txtEnterKey").value = "1";
		}
		return validateFields('Validate');
    }
}

function nopassworderror()
{
	var strVal = "The email address you entered is not valid.";
	strVal = strVal + "\n\nPlease reenter and try again.";
	alert(strVal);
}

function submitForm() {
		var strZipCode
		if(document.landingform.txtZipCode!=null)
			{
				strZipCode = document.landingform.txtZipCode.value;
			}
			else if(document.landingform.V1A_txtZipCode!=null)
			{
				strZipCode = document.landingform.V1A_txtZipCode.value;
			}
			else if(document.landingform.V1B_txtZipCode!=null)
			{
				strZipCode = document.landingform.V1B_txtZipCode.value;
			}
			else if(document.landingform.V2A_txtZipCode!=null)
			{
				strZipCode = document.landingform.V2A_txtZipCode.value;
			}
			else if(document.landingform.V2B_txtZipCode!=null)
			{
				strZipCode = document.landingform.V2B_txtZipCode.value;
			}
			else if(document.landingform.V3A_txtZipCode!=null)
			{
				strZipCode = document.landingform.V3A_txtZipCode.value;
			}
			else if(document.landingform.V3B_txtZipCode!=null)
			{
				strZipCode = document.landingform.V3B_txtZipCode.value;
			}

                                        
        if ((strZipCode == "") || (isNaN(strZipCode)) || (strZipCode < 0 || strZipCode.length != 5) || (strZipCode.indexOf(".") != -1)) {
            window.location = "/";
        }
        else {
            document.landingform.submit();  
        }
}



function ClickEnter(btnName)
{      
	
	var evt = window.event;
	if (evt != null)
	{
		if (evt.keyCode==13)
		{ 		
			var btn;
			if(btnName != null)
			{
				if(document.getElementById(btnName)!=null)
				{
					btn = document.getElementById(btnName);
				}
				else if(document.getElementById("V1A_" + btnName)!=null)
				{
					btn= document.getElementById("V1A_" + btnName);
				}
				else if(document.getElementById("V1B_" + btnName)!=null)
				{
					btn = document.getElementById("V1B_" + btnName)
				}
				else if(document.getElementById("V2A_" + btnName)!=null)
				{
					btn = document.getElementById("V2A_" + btnName)
				}
				else if(document.getElementById("V2B_" + btnName)!=null)
				{
					btn = document.getElementById("V2B_" + btnName)
				}
				else if(document.getElementById("V3A_" + btnName)!=null)
				{
					btn = document.getElementById("V3A_" + btnName)
				}
				else if(document.getElementById("V3B_" + btnName)!=null)
				{
					btn = document.getElementById("V3B_" + btnName)
				}
		}
			else
			{
				if(document.getElementById(btnGoZip)!=null)
				{
					btn = document.getElementById(btnGoZip);
				}
				else if(document.getElementById("V1A_btnGoZip")!=null)
				{
					btn= document.getElementById("V1A_btnGoZip");
				}
				else if(document.getElementById("V1B_btnGoZip")!=null)
				{
					btn = document.getElementById("V1B_btnGoZip")
				}
				else if(document.getElementById("V2A_btnGoZip")!=null)
				{
					btn = document.getElementById("V2A_btnGoZip")
				}
				else if(document.getElementById("V2B_btnGoZip")!=null)
				{
					btn = document.getElementById("V2B_btnGoZip")
				}
				else if(document.getElementById("V3A_btnGoZip")!=null)
				{
					btn = document.getElementById("V3A_btnGoZip")
				}
				else if(document.getElementById("V3B_btnGoZip")!=null)
				{
					btn = document.getElementById("V3B_btnGoZip")
				}
			}				
			if (btn != null)
			{ 
				btn.click(); 
				return false; 
			} 
		}
	} 
}


function validateFields(TargetPage)	
{
	//	
	
	errorField = "";
	strValidationMsg = "";
	var strAcctEmail="";
	var acctEmail;
	var strAcctPwd="";
	var acctPwd;
			if(document.landingform.txtAcctEmail!=null)
			{
				strAcctEmail = document.landingform.txtAcctEmail.value;
				acctEmail = document.landingform.txtAcctEmail;
			}
			else if(document.landingform.V1A_txtAcctEmail!=null)
			{
				strAcctEmail = document.landingform.V1A_txtAcctEmail.value;
				acctEmail = document.landingform.V1A_txtAcctEmail;
			}
			else if(document.landingform.V1B_txtAcctEmail!=null)
			{
				strAcctEmail = document.landingform.V1B_txtAcctEmail.value;
				acctEmail = document.landingform.V1B_txtAcctEmail;
			}
			else if(document.landingform.V2A_txtAcctEmail!=null)
			{
				strAcctEmail = document.landingform.V2A_txtAcctEmail.value;
				acctEmail = document.landingform.V2A_txtAcctEmail;
			}
			else if(document.landingform.V2B_txtAcctEmail!=null)
			{
				strAcctEmail = document.landingform.V2B_txtAcctEmail.value;
				acctEmail = document.landingform.V2B_txtAcctEmail;
			}
			else if(document.landingform.V3A_txtAcctEmail!=null)
			{
				strAcctEmail = document.landingform.V3A_txtAcctEmail.value;
				acctEmail = document.landingform.V3A_txtAcctEmail;
			}
			else if(document.landingform.V3B_txtAcctEmail!=null)
			{
				strAcctEmail = document.landingform.V3B_txtAcctEmail.value;
				acctEmail = document.landingform.V3B_txtAcctEmail;
			}
	
			if(document.landingform.txtAcctPwd!=null)
			{
				strAcctPwd = document.landingform.txtAcctPwd.value;
				acctPwd = document.landingform.txtAcctPwd;
			}
			else if(document.landingform.V1A_txtAcctPwd!=null)
			{
				strAcctPwd = document.landingform.V1A_txtAcctPwd.value;
				acctPwd = document.landingform.V1A_txtAcctPwd;
			}
			else if(document.landingform.V1B_txtAcctPwd!=null)
			{
				strAcctPwd = document.landingform.V1B_txtAcctPwd.value;
				acctPwd = document.landingform.V1B_txtAcctPwd;
			}
			else if(document.landingform.V2A_txtAcctPwd!=null)
			{
				strAcctPwd = document.landingform.V2A_txtAcctPwd.value;
				acctPwd = document.landingform.V2A_txtAcctPwd;
			}
			else if(document.landingform.V2B_txtAcctPwd!=null)
			{
				strAcctPwd = document.landingform.V2B_txtAcctPwd.value;
				acctPwd = document.landingform.V2B_txtAcctPwd;
			}
			else if(document.landingform.V3A_txtAcctPwd!=null)
			{
				strAcctPwd = document.landingform.V3A_txtAcctPwd.value;
				acctPwd = document.landingform.V3A_txtAcctPwd;
			}
			else if(document.landingform.V3B_txtAcctPwd!=null)
			{
				strAcctPwd = document.landingform.V3B_txtAcctPwd.value;
				acctPwd = document.landingform.V3B_txtAcctPwd;
			}
	strAcctEmail = TrimString(strAcctEmail);
	
	if (TargetPage == "Validate") 
	{
		document.landingform.hdnTargetPage.value = "Validate";
		if(acctEmail!=null)
		{
			if(strAcctEmail!="" || strAcctEmail!="")
			{
				if (strAcctEmail == "")
				{
					strValidationMsg = strValidationMsg + "Please enter your email address and password. Then click \"Login.\"\n";
					errorField = acctEmail;
				}
				else 
				{	
					if (! isEmail(strAcctEmail))
					{
						if (document.landingform.AccountCreation) {
							strValidationMsg = strValidationMsg + "If you are creating a new account, please verify your password. If you already have an account, please check your email address to make sure that it is correct.";
						}
						else {
							strValidationMsg = strValidationMsg + "We don\'t have the email address you entered on file. Please double-check the address and try again.\n";
						}
							if (errorField == "") 
							{
								errorField = acctEmail;						
							}
					}
					else 
					{

						if (strAcctPwd == "")
						{
							strValidationMsg = strValidationMsg + "Please enter your password and click \"Login.\"\n";
							errorField = acctPwd;
						}
						else
						{
							/*if (document.landingform.txtAcctPwd.value.length < 4)
							{
								strValidationMsg = strValidationMsg + "The password you entered does not match the email address on file. Please re-enter it and try again.\n If you\'ve forgotten your password, click \"Forgot your password?\" and we\'ll send it to you right away.";
								errorField = document.landingform.txtAcctPwd;
							}*/
						}

					}
				}
			}
			else
			{
				if (strAcctEmail == "")
				{
					strValidationMsg = strValidationMsg + "Please enter your email address and password. Then click \"Login.\"\n";
					errorField = acctEmail;
				}
				else 
				{	
					if (! isEmail(strAcctEmail))
					{
						if (document.landingform.AccountCreation) {
							strValidationMsg = strValidationMsg + "If you are creating a new account, please verify your password. If you already have an account, please check your email address to make sure that it is correct.";
						}
						else {
							strValidationMsg = strValidationMsg + "We don\'t have the email address you entered on file. Please double-check the address and try again.\n";
						}
							if (errorField == "") 
							{
								errorField = acctEmail;						
							}
					}
					else 
					{

						if (strAcctPwd == "")
						{
							strValidationMsg = strValidationMsg + "Please enter your password and click \"Login.\"\n";
							errorField = acctPwd;
						}
						else
						{
							/*if (document.landingform.txtAcctPwd.value.length < 4)
							{
								strValidationMsg = strValidationMsg + "The password you entered does not match the email address on file. Please re-enter it and try again.\n If you\'ve forgotten your password, click \"Forgot your password?\" and we\'ll send it to you right away.";
								errorField = document.landingform.txtAcctPwd;
							}*/
						}

					}
				}
			}
		}	
	}

	if (TargetPage == "ForgetPass")
	{
	    document.landingform.hdnTargetPage.value = "ForgetPass";
	    if (strAcctEmail == "") {
	        strValidationMsg = "ForgotEmailPassword";
	        str = window.location.host;
	        if (str.toUpperCase() == "LOCALHOST") {
	            strServer = "http://localhost/";
	        }
	        else {
	            strServer = "http://" + str;
	        }
	        window.open(strServer + "/account/login-hint-forgot-password", "_self");

	    }
	    else {
	        if (!isEmail(strAcctEmail)) {
	            strValidationMsg = strValidationMsg + "We don\'t have the email address you entered on file. Please double-check the address and try again.\n";
	            if (errorField == "") {
	                errorField = acctEmail;
	            }
	        }
	    }
	}		
	
	if (strValidationMsg == "")
	{
		if (TargetPage == "ForgetPass") 
		{ 
			str = window.location.host;
			if (str.toUpperCase() == "LOCALHOST")
			{
				strServer = "http://localhost/09-REL-05";
			}
			else
			{
				strServer = "http://"+str;
			}
			window.open(strServer + "/account/login-hint?Email=" + strAcctEmail + "&SessnId=" + document.landingform.LCC1_SessionId.value, "_self");
		}
		
	} 
	else 
	{
	    if (strValidationMsg != "ForgotEmailPassword") {
	        alert(strValidationMsg);
	    }
	    if (TargetPage != 'ForgetPass')
	        return false;
	}			
}	

function validateFieldsOriginal(TargetPage)	
{
	errorField = "";
	strValidationMsg = "";
	var strAcctEmail="";
	var acctEmail;
	var strAcctPwd="";
	var acctPwd;
			if(document.landingform.txtAcctEmail!=null)
			{
				strAcctEmail = document.landingform.txtAcctEmail.value;
				acctEmail = document.landingform.txtAcctEmail;
			}
			else if(document.landingform.V1A_txtAcctEmail!=null)
			{
				strAcctEmail = document.landingform.V1A_txtAcctEmail.value;
				acctEmail = document.landingform.V1A_txtAcctEmail;
			}
			else if(document.landingform.V1B_txtAcctEmail!=null)
			{
				strAcctEmail = document.landingform.V1B_txtAcctEmail.value;
				acctEmail = document.landingform.V1B_txtAcctEmail;
			}
			else if(document.landingform.V2A_txtAcctEmail!=null)
			{
				strAcctEmail = document.landingform.V2A_txtAcctEmail.value;
				acctEmail = document.landingform.V2A_txtAcctEmail;
			}
			else if(document.landingform.V2B_txtAcctEmail!=null)
			{
				strAcctEmail = document.landingform.V2B_txtAcctEmail.value;
				acctEmail = document.landingform.V2B_txtAcctEmail;
			}
			else if(document.landingform.V3A_txtAcctEmail!=null)
			{
				strAcctEmail = document.landingform.V3A_txtAcctEmail.value;
				acctEmail = document.landingform.V3A_txtAcctEmail;
			}
			else if(document.landingform.V3B_txtAcctEmail!=null)
			{
				strAcctEmail = document.landingform.V3B_txtAcctEmail.value;
				acctEmail = document.landingform.V3B_txtAcctEmail;
			}
	
			if(document.landingform.txtAcctPwd!=null)
			{
				strAcctPwd = document.landingform.txtAcctPwd.value;
				acctPwd = document.landingform.txtAcctPwd;
			}
			else if(document.landingform.V1A_txtAcctPwd!=null)
			{
				strAcctPwd = document.landingform.V1A_txtAcctPwd.value;
				acctPwd = document.landingform.V1A_txtAcctPwd;
			}
			else if(document.landingform.V1B_txtAcctPwd!=null)
			{
				strAcctPwd = document.landingform.V1B_txtAcctPwd.value;
				acctPwd = document.landingform.V1B_txtAcctPwd;
			}
			else if(document.landingform.V2A_txtAcctPwd!=null)
			{
				strAcctPwd = document.landingform.V2A_txtAcctPwd.value;
				acctPwd = document.landingform.V2A_txtAcctPwd;
			}
			else if(document.landingform.V2B_txtAcctPwd!=null)
			{
				strAcctPwd = document.landingform.V2B_txtAcctPwd.value;
				acctPwd = document.landingform.V2B_txtAcctPwd;
			}
			else if(document.landingform.V3A_txtAcctPwd!=null)
			{
				strAcctPwd = document.landingform.V3A_txtAcctPwd.value;
				acctPwd = document.landingform.V3A_txtAcctPwd;
			}
			else if(document.landingform.V3B_txtAcctPwd!=null)
			{
				strAcctPwd = document.landingform.V3B_txtAcctPwd.value;
				acctPwd = document.landingform.V3B_txtAcctPwd;
			}
											
	if (TargetPage == "Validate") {
		document.landingform.hdnTargetPage.value = "Validate";
	}
	else {
		document.landingform.hdnTargetPage.value = "ForgetPass";
	}
	if (strAcctEmail == ""){
		strValidationMsg = strValidationMsg + "Please enter your email address.\n";
		errorField = acctEmail;
	}
	else {	
		if (! isEmail(strAcctEmail)){
			strValidationMsg = strValidationMsg + "Your email address was not valid; please try again.\n";
				if (errorField == "") {
					errorField = acctEmail;						
				}
		}
		else {
			if (TargetPage != "ForgetPass") {
				if ((strAcctPwd == "")||(strAcctPwd.length < 4)){
					strValidationMsg = strValidationMsg + "Please enter a valid password that is at least 4 characters long.\n";
					errorField = acctPwd;
				}
			}
		}
	}			
	
	if (strValidationMsg == ""){
		document.landingform.submit();
	} 
	else {
		alert(strValidationMsg);
		errorField.focus();
	}			
}	
function isEmail(strData) {
	// Email address must be of form a@b.c -- in other words:
	// * there must be at least one character before the @
	// * there must be at least one character before and after the .
	// * the characters @ and . are both required
	var	iCtr,
		jCtr,
		sLength,
		atPos,
		cs,
		cTemp;
				
	if (isEmpty(strData))
		if (isEmail.arguments.length == 1)
			return false;
		else
			return (isEmail.arguments[1] == true);
		   
    if (isWhitespace(strData))
		return false;
		    
    iCtr = 1;
    sLength = strData.length;

    iCtr = strData.indexOf("@");
    atPos = iCtr;
		    
    if ( iCtr < 0 )
		return false;
	else 
		iCtr+=2;
			
	iCtr = strData.lastIndexOf(".");
    if ( iCtr < 0 )
		return false;
	else 
		iCtr++;			
			    
    if (iCtr > sLength)
		return false;
		    
    if(! isAlphanumeric(strData.substring( iCtr, strData.length)))
		return false;
			
	cTemp	= "";
	cs		= "";
	for(jCtr = atPos+1; jCtr < strData.length; jCtr++) {
		cTemp =  strData.charAt(jCtr);
		if( (cTemp != ".") && (cTemp != "-") )
			cs += cTemp;
	}
			
	if(! isAlphanumeric(cs))
		return false;
				
	return true;
}	

function isEmpty(strData) {
	return ((strData == null) || (strData.length == 0));
}

var whitespace = " \t\n\r";		
function isWhitespace(strData) {
	var iCtr,
		cTemp;

    if (isEmpty(strData))
		return true;

    for (iCtr = 0; iCtr < strData.length; iCtr++) {   
        var cTemp = strData.charAt(iCtr);
		if (whitespace.indexOf(cTemp) == -1)
			return false;
    }

    return true;
}


function isAlphanumeric(strData) {
	var iCtr,
		cTemp;

    if (isEmpty(strData)) 
		if (isAlphanumeric.arguments.length == 1)
			return false;
		else
			return (isAlphanumeric.arguments[1] == true);

	for (iCtr = 0; iCtr < strData.length; iCtr++) {
        cTemp = strData.charAt(iCtr);
        if (! (isLetter(cTemp) || isDigit(cTemp)))
			return false;
    }

    return true;
}

function isLetter(strData) {
	for (iCtr = 0; iCtr < strData.length; iCtr++) {
		cDigit = strData.charAt(iCtr);
	    if (! (((cDigit >= "a") && (cDigit <= "z")) || ((cDigit >= "A") && (cDigit <= "Z"))))
			return false;
	}
	return true;
}

function isDigit(strData) {
	if (strData==null) return false;
	for (iCtr = 0; iCtr < strData.length; iCtr++) {
		cDigit = strData.charAt(iCtr);
	    if ((cDigit < "0") || (cDigit > "9"))
			return false;
	}
	return true;
}
		
function oneClick()
	{
		if(document.getElementById) {
			document.getElementById('erin').style.backgroundColor = '#FFFFFF';
			document.getElementById('erin').style.width = '240px';
			document.getElementById('erin').style.left = '515px';
			document.getElementById('erin').style.top = '160px';
			document.getElementById('erin').style.border = '2px solid #FF3399';
			document.getElementById('erin').style.padding = '8px';
			document.getElementById('erin').style.visibility = 'visible';
		}
		else {
			window.open(strServer + '/','esurance','width=200,height=300,directories=no,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=yes,screenX=50,screenY=500,top=50,left=500');
			}
	}

function award()
	{
		if(document.getElementById) {
			document.getElementById('award').style.backgroundColor = '#DCEDFF';
			document.getElementById('award').style.width = '500px';
			document.getElementById('award').style.left = '181px';
			document.getElementById('award').style.top = '448px';
			document.getElementById('award').style.border = '2px solid #003399';
			document.getElementById('award').style.padding = '8px';
			document.getElementById('award').style.visibility = 'visible';
		}
		else {
			window.open(strServer + '/','esurance','width=500,height=325,directories=no,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=yes,screenX=0,screenY=0,top=0,left=0');
			}
	}
	
function shutit()
	{		
		if (document.getElementById) {
			document.getElementById('erin').style.visibility = 'hidden';
		}
	}     
	
function shutit_award()
	{		
		if (document.getElementById) {
			document.getElementById('award').style.visibility = 'hidden';
		}
	}    
	
function secure(){
	window.name = "main";
	window.open(EsuranceWebServerName + '/views/home/aboutus/about_secure.aspx', 'secure', 'width=500,height=500,directories=no,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=yes,screenX=0,screenY=0,top=0,left=0');
	
}

function checkEnterLogin(e)
{ 
	//e is event object passed from function invocation
	var characterCode //literal character code will be stored in this variable

	if(e && e.which){ //if which property of event object is supported (NN4)
		e = e
		characterCode = e.which //character code is contained in NN4's which property
	}
	else{
		e = event
		characterCode = e.keyCode //character code is contained in IE's keyCode property
	}

	if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
	//document.forms[0].submit() //submit the form
		validateFields('Validate')
		return false 
	}
	else{
		return true 
	}
}

function checkEnterZipCode(e)
{ 
	//e is event object passed from function invocation
	var characterCode //literal character code will be stored in this variable

	if(e && e.which){ //if which property of event object is supported (NN4)
		e = e
		characterCode = e.which //character code is contained in NN4's which property
	}
	else{
		e = event
		characterCode = e.keyCode //character code is contained in IE's keyCode property
	}

	if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
	//document.forms[0].submit() //submit the form
		 
		submitForm()
		//document.menuForm.ZipCode.focus();
		 
		return false 
	}
	else{
		 
		return true  
	}
}

function TrimString(str) 
{
	str = str.replace(/^[ ]+(.*)$/, '$1'); // Trims leading spaces
	str = str.replace(/^(.*)[ ]+$/, '$1'); // Trims trailing spaces
	return str;
}

function openNewWindow(theURL,winName,features) 
{
   theURL = EsuranceWebServerName + theURL;
  window.open(theURL,winName,features);
}

function openSecureLoginWindow()
	{
	  var freshurl= EsuranceWebServerName + '/CommonContent/content/ResourceCenter/SecureInfo.aspx?pagetype=p';
	    SmallWin = window.open(freshurl, 'footerwindow','scrollbars=yes,resizable=yes,toolbar=no,height=450,width=471');

		if( ! isIE4() )
		{
            if (window.focus) {
                SmallWin.focus();
            }
		}

	    if (SmallWin.opener == null) SmallWin.opener = window;
            SmallWin.opener.name = "PUMain";
	}
   function openWindow(freshurl)
	{
		freshurl = EsuranceWebServerName + freshurl;
	    SmallWin = window.open(freshurl, 'HelpWindow','scrollbars=yes,resizable=yes,toolbar=no,height=480,width=471');

		if( ! isIE4() )
		{
            if (window.focus) {
                SmallWin.focus();
            }
		}

	    if (SmallWin.opener == null) SmallWin.opener = window;
            SmallWin.opener.name = "PUMain";
	}
	
   function openSizedWindow(freshurl, theWidth, theHeight, theLeft, theTop)
	{
	freshurl = EsuranceWebServerName + freshurl;
	    SmallWin = window.open(freshurl, 'HelpWindow','scrollbars=yes,resizable=yes,toolbar=no,height=' + theHeight + ' width=' + theWidth + ' left=' + theLeft + ' top=' + theTop);

		if( ! isIE4() )
		{
            if (window.focus) {
                SmallWin.focus();
            }
		}

	    if (SmallWin.opener == null) SmallWin.opener = window;
            SmallWin.opener.name = "PUMain";
	}
   
   function isIE4()
	{
		return( navigator.appName.indexOf("Microsoft") != -1 && (navigator.appVersion.charAt(0)=='4') );
	}
	
	   

function openWindowLarge(theURL,winName) 
		{ 
	//theURL = "http://www.esurance.com" + theURL;
  window.open(theURL,winName,'scrollbars=yes,resizable=yes,toolbar=yes,menubar=yes,location=yes,height=480,width=800');

		}

function openFooterWindow(theURL,winName) 
{ 
	theURL = EsuranceWebServer + theURL;
	window.open(theURL,winName,'scrollbars=yes,resizable=yes,toolbar=yes,menubar=yes,location=yes,height=480,width=800');

}
  
   function HelpInfo(DefNo) { 
     var strASPPage;
     
     	//strASPPage=EsuranceWebServerName + "/Content/HelpInfo/HelpInfo.asp?DefNo=" + DefNo;
     strASPPage = "/Views/Home/HelpInfo.aspx?DefNo=" + DefNo;
	    newWindow3 = window.open(strASPPage, 'newwindowWin3', 'toolbar=no,resizable=yes,location=no ,left=400,scrollbars=yes,width=375,height=400,alwaysRaised=yes') ;
	
     }

   function HelpInfo2() { 
     var strASPPage;
     
     	strASPPage=EsuranceWebServerName + "/QuoteBuilder/comparePop.asp";
	    newWindow3 = window.open(strASPPage, 'newwindowWin3', 'toolbar=no,resizable=yes,location=no ,left=400,scrollbars=yes,width=350,height=275,alwaysRaised=yes') ;
	
     }     

   function HelpInfo3(DefNo) { 
     var strASPPage;
     
     	strASPPage=EsuranceWebServerName + "/Content/HelpInfo/HelpInfo.asp?DefNo=" + DefNo;

	    newWindow3 = window.open(strASPPage, 'newwindowWin3', 'toolbar=no,resizable=yes,location=no ,left=300,scrollbars=yes,width=800,height=570,alwaysRaised=yes') ;
	
     }
     
   function ClaimsPopup(No) { 
     var strASPPage;

     strASPPage = EsuranceWebServerName + "/Views/Home/content/ClaimsPopup/ClaimsPopup.aspx?No=" + No;

	    newWindow3 = window.open(strASPPage, 'newwindowWin3', 'toolbar=no,resizable=yes,location=no ,left=400,scrollbars=yes,width=400,height=450,alwaysRaised=yes') ;
	
     }
      function TreesPopup(Name) { 
     var strASPPage;
     
     	strASPPage=EsuranceWebServerName + "/Views/Home/Home/TreesPopup.aspx?Name=" + Name;

	    newWindow3 = window.open(strASPPage, 'newwindowWin3', 'toolbar=no,resizable=yes,location=no ,left=400,scrollbars=yes,width=400,height=480,alwaysRaised=yes') ;
	
     }
	function TreePopup(Name) { 
     var strASPPage;
     
     	strASPPage=EsuranceWebServerName + "/Content/TreesPopup/TreesPopup.asp?Name=" + Name;

	    newWindow3 = window.open(strASPPage, 'newwindowWin3', 'toolbar=no,resizable=yes,location=no ,left=400,scrollbars=yes,width=400,height=355,alwaysRaised=yes') ;
	
     }
     
   function RaceSchedulePopup(No) { 
     var strASPPage;
     
     	strASPPage=EsuranceWebServerName + "/Content/RaceSchedulePopup/RaceSchedulePopup.asp?No=" + No;

	    newWindow3 = window.open(strASPPage, 'newwindowWin3', 'toolbar=no,resizable=yes,location=no ,top=400,scrollbars=yes,width=400,height=480,alwaysRaised=yes') ;
		
     }
     
    function SpecialDealsPopup(No) { 
     var strASPPage;
     
     	strASPPage=EsuranceWebServerName + "/Content/SpecialDealsPopup/SpecialDealsPopup.asp?No=" + No;

	    newWindow3 = window.open(strASPPage, 'newwindowWin3', 'toolbar=no,resizable=yes,location=no ,left=400,scrollbars=yes,width=400,height=480,alwaysRaised=yes') ;
	
     }
   function MonolithRadio() { 
     var strASPPage;
     
     	strASPPage=EsuranceWebServerName +"/Monolith/radio.asp?";

	    newWindow3 = window.open(strASPPage, 'newwindowWin3', 'toolbar=no,resizable=yes,location=no ,left=400,scrollbars=yes,width=425,height=415,alwaysRaised=yes') ;
	
     }
     
   function HomeownersPopup(DefNo) { 
     var strASPPage;
     
     	strASPPage=EsuranceWebServerName + "/Content/HomeownersPopup/HomeownersPopup.asp?DefNo=" + DefNo;

	    newWindow3 = window.open(strASPPage, 'newwindowWin3', 'toolbar=no,resizable=yes,location=no ,left=400,scrollbars=yes,width=400,height=480,alwaysRaised=yes') ;
		
     }

	function HomepagePopup(DefNo) { 
     var strASPPage;
     
     	strASPPage=EsuranceWebServerName + "/Content/HomepagePopup/HomepagePopup.asp?DefNo=" + DefNo;

	    newWindow3 = window.open(strASPPage, 'newwindowWin3', 'toolbar=no,resizable=yes,location=no ,left=400,scrollbars=yes,width=400,height=480,alwaysRaised=yes') ;
		
     }
  
   function AvailableStatesPopup(DefNo) { 
     var strASPPage;
     
     	strASPPage=EsuranceWebServerName + "/Views/home/aboutus/AvailableStatesPopup/AvailableStatesPopup.aspx?DefNo=" + DefNo;
		
	    newWindow3 = window.open(strASPPage, 'newwindowWin3', 'toolbar=no,resizable=yes,location=no ,left=400,scrollbars=yes,width=550,height=480,alwaysRaised=yes') ;
	
     }
     
     function validateAccountChanges() 
			{
				strValidationMsg = "";
				errorField = "";
				sData = "";
				
				//validate email format
				if (document.frmChngAcctInf.accountEmail.value == "") 
				{	strValidationMsg = strValidationMsg + "Please enter an email address.\n";
					if (errorField == "")
						errorField = document.frmChngAcctInf.accountEmail;
				}
				else 
				{	if (! isEmail(document.frmChngAcctInf.accountEmail.value)) 
					{	strValidationMsg = strValidationMsg + "Your email address was not valid; please try again.\n";
						if (errorField == "")
							errorField = document.frmChngAcctInf.accountEmail;		

				
					}
				}
				
				//validate  old password
				if ((document.frmChngAcctInf.txtPwordOld.value != "")&&(document.frmChngAcctInf.txtPwordOld.value.length < 4)) 
				{	strValidationMsg = strValidationMsg + "Please enter your current password that is at least 4 characters long.\n";
					if (errorField == "")
					errorField = document.frmChngAcctInf.txtPwordOld;
				}
				else {
					
						if (document.frmChngAcctInf.txtPwordOld.value == ""){
							strValidationMsg = strValidationMsg + "Please enter your current password.\n";
							if (errorField == "")
							errorField = document.frmChngAcctInf.txtPwordOld;
						}				
					
				}
				//validate  password length
				if ((document.frmChngAcctInf.txtPword1.value != "")&&(document.frmChngAcctInf.txtPword1.value.length < 4)) 
				{	strValidationMsg = strValidationMsg + "Your password was too short; please use 4 or more characters and/or numbers.\n";
					if (errorField == "")
						errorField = document.frmChngAcctInf.txtPword1;
				}
				
				//check if password entered has both digits and letters
				sData = document.frmChngAcctInf.txtPword1.value
				if (sData != "")
				{
					if ((document.frmChngAcctInf.txtPword2.value != "")&&(document.frmChngAcctInf.txtPword2.value.length < 4)) 
					{
						strValidationMsg = strValidationMsg + "Please re-enter the password for verification.\n";
						if (errorField == "")
							errorField = document.frmChngAcctInf.txtPword2;
					}
					else 
					{	
						if (document.frmChngAcctInf.txtPword1.value != document.frmChngAcctInf.txtPword2.value) 
						{	
							strValidationMsg = strValidationMsg + "Your password entries did not match; please try again.\n";	 
							if (errorField == "")
								errorField = document.frmChngAcctInf.txtPword1;
						}
					}
				}
					
				//if error return message
				if (strValidationMsg == "")
				{	
					//document.frmChngAcctInf.submit();
					//alert("passed validate fields")
					return true; // true;
				}
				else 
				{	alert(strValidationMsg);
					if (errorField != "")
					errorField.focus();
					return false;
					
				}											

	
			
			}
			
			
		function submitForm1() 
			{
		
		var flg=false;
        var strZipCode
		if(document.landingform.txtZipCode!=null)
			{
				strZipCode = document.landingform.txtZipCode.value;
			}
			else if(document.landingform.V1A_txtZipCode!=null)
			{
				strZipCode = document.landingform.V1A_txtZipCode.value;
			}
			else if(document.landingform.V1B_txtZipCode!=null)
			{
				strZipCode = document.landingform.V1B_txtZipCode.value;
			}
			else if(document.landingform.V2A_txtZipCode!=null)
			{
				strZipCode = document.landingform.V2A_txtZipCode.value;
			}
			else if(document.landingform.V2B_txtZipCode!=null)
			{
				strZipCode = document.landingform.V2B_txtZipCode.value;
			}
			else if(document.landingform.V3A_txtZipCode!=null)
			{
				strZipCode = document.landingform.V3A_txtZipCode.value;
			}
			else if(document.landingform.V3B_txtZipCode!=null)
			{
				strZipCode = document.landingform.V3B_txtZipCode.value;
			}
                                        
        if ((strZipCode == "") || (isNaN(strZipCode)) || (strZipCode < 0 || strZipCode.length != 5) || (strZipCode.indexOf(".") != -1))
         {
			alert('Please enter valid zip code');
			var strZipCode
		if(document.landingform.txtZipCode!=null)
			{
				document.landingform.txtZipCode.select();
				document.landingform.txtZipCode.focus();
			}
			else if(document.landingform.V1A_txtZipCode!=null)
			{
				document.landingform.V1A_txtZipCode.select();
				document.landingform.V1A_txtZipCode.focus();
			}
			else if(document.landingform.V1B_txtZipCode!=null)
			{
				document.landingform.V1B_txtZipCode.select();
				document.landingform.V1B_txtZipCode.focus();
			}
			else if(document.landingform.V2A_txtZipCode!=null)
			{
				document.landingform.V2A_txtZipCode.select();
				document.landingform.V2A_txtZipCode.focus();
			}
			else if(document.landingform.V2B_txtZipCode!=null)
			{
				document.landingform.V2B_txtZipCode.select();
				document.landingform.V2B_txtZipCode.focus();
			}
			else if(document.landingform.V3A_txtZipCode!=null)
			{
				document.landingform.V3A_txtZipCode.select();
				document.landingform.V3A_txtZipCode.focus();
			}
			else if(document.landingform.V3B_txtZipCode!=null)
			{
				document.landingform.V3B_txtZipCode.select();
				document.landingform.V3B_txtZipCode.focus();
			}

            flg=false;
        }
 
        else {
            flg=true;
        }
        return flg;
}

//10-mkt-040 begins

function validateEmail(field) {
    var strString = document.getElementById(field).value;
    if (!(strString = "")) {
        return true;
    }
    else {
        return false;
    }
}


function Hityear(field) {

    if (!(field == "")) {
        if (document.getElementById(field).value != '') {
            document.getElementById(field).value = '';
            document.getElementById(field).style.color = "Black";
        }
    }


}

function chkDigit(field)
//  check for valid numeric strings
{
    var browserName = navigator.appName;
    var blnResult = true;
    var strString = document.getElementById(field).value;

    var strValidChars = "0123456789";
    var strChar;
    objectName = field;
    var strCount = 0;
    var strCommaCount = 0;

    //loops through the string
    for (i = 0; i < strString.length; i++) {
        strChar = strString.charAt(i);
        // count occurance of '0'
        if (strValidChars.indexOf(strChar) == -1) {
            blnResult = false;

            document.getElementById(field).value = document.getElementById(field).value.replace(strChar, "");
            document.getElementById(field).focus();

        }

    }

    if (blnResult == false && browserName == "Netscape" && e.type == "blur") {
        window.setTimeout("document.getElementById(objectName).focus()", 100);

    }
}


function validateLastName(field)
//  check for valid numeric strings
{
    var browserName = navigator.appName;
    var blnResult = true;
    var strString = document.getElementById(field).value;

    //var strValidChars = "abcdefghijklmnopqrstuvwxyz";
    var strChar;
    //objectName = document.landingform.txtLastname.value;
    var strCount = 0;
    var strCommaCount = 0;

    //loops through the string
    for (i = 0; i < strString.length; i++) {
        strChar = strString.charAt(i);
        // count occurance of '0'
        if (!(((strChar >= "a") && (strChar <= "z")) || ((strChar >= "A") && (strChar <= "Z")))) {
            blnResult = false;

            document.getElementById(field).value = document.getElementById(field).value.replace(strChar, "");
            document.getElementById(field).focus();

        }

    }

    if (blnResult == false && browserName == "Netscape" && e.type == "blur") {
        // window.setTimeout("document.landingform.txtLastname.focus()", 100);

    }
}

function AutoAdvanceTabNumeric(flagcheck, e, currentElement, maxChars, advanceToElement) {
    objectName = currentElement;
    var keycode;
    var fldVal = currentElement.value;
    var flag;
    var browserName = navigator.appName;
    currentElement.style.color = "Black";


    flag = CheckNumeric(currentElement)


    if (flag == false && browserName == "Netscape" && e.type == "blur") {    //alert("inside");
        window.setTimeout("objectName.focus()", 1);

    }

    if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) {

        if (flagcheck == "True") {
            currentElement.maxLength = 2;
        }
        else {
            currentElement.maxLength = 4;
        }
        autoTab(currentElement, currentElement.maxLength, e);
    }
    else {
        //if year skip the autotab functionality
        if (flagcheck == "True") {
            if (flag == true) {
                if (e.which) {
                    keycode = e.which;
                }
                else if (window.event) {
                    keycode = window.event.keyCode;
                }

                if (advanceToElement != null && advanceToElement.style.display != 'none' && currentElement.value.length >= maxChars && keycode != 9 && keycode != 16) {	//alert("inside the if loop"+ maxChars);
                    if (currentElement.value.length == 3) {  //alert("inside the max char");
                        var charpos3 = fldVal.charAt(2);
                        currentElement.value = fldVal.substring(0, fldVal.length - 1);
                        advanceToElement.focus();
                        advanceToElement.style.color = "Black";
                        advanceToElement.value = charpos3;

                    }
                }
            } // If loop end for flag
        } // If loop end for flagcheck
    }
} //end of function

var isNN = (navigator.appName.indexOf("Netscape") != -1);

function autoTab(input, len, e) {
    var keyCode = (isNN) ? e.which : e.keyCode;
    var filter = (isNN) ? [0, 8, 9] : [0, 8, 9, 16, 17, 18, 37, 38, 39, 40, 46];
    if (input.value.length >= len && !containsElement(filter, keyCode)) {
        input.value = input.value.slice(0, len);
        input.form[(getIndex(input) + 1) % input.form.length].focus();
    }

    function containsElement(arr, ele) {
        var found = false, index = 0;
        while (!found && index < arr.length)
            if (arr[index] == ele)
            found = true;
        else
            index++;
        return found;
    }

    function getIndex(input) {
        var index = -1, i = 0, found = false;
        while (i < input.form.length && index == -1)
            if (input.form[i] == input) index = i;
        else i++;
        return index;
    }
    return true;
}

function CheckNumeric(ob)
//  check for valid numeric strings 
{//alert("function check numeric start:");
    var strString = ob.value;
    //alert("strstring:"+strString);
    var strValidChars = "0123456789";
    var strChar;
    var blnResult = true;
    //if (strString.length == 0) return false;
    //  test strString consists of valid characters listed above
    for (i = 0; i < strString.length; i++) {
        //alert("inside the for loop" +strString.length);
        strChar = strString.charAt(i);
        if (strValidChars.indexOf(strChar) == -1) {
            blnResult = false;
            //alert("Invalid characters.");
            ob.value = ob.value.replace(strChar, "");
            ob.focus();


        }
    }


    return blnResult;
}

function googleevalkeypress(e) {
    var key = window.event ? e.keyCode : e.which;
    if (key == 13) {
        submitGoogleSearch();
    }
}
function submitGoogleSearch() {
    document.forms[0].action = "/search-results/";
    document.forms[0].method = "GET";
    //disable all the input tags that don't belong to the google search
    $('form input, form select').each(function() {
        if (this.name != 'q' && this.name != 'cx' && this.name != 'cof'
			&& this.name != 'ie' && this.name != 'googlesearchbutton') {
            $(this).attr('disabled', 'disabled');
        }
    });
    document.forms[0].submit(); // Submit the page
    return true;
}
function googleevalkeypress2(e) {
    var key = window.event ? e.keyCode : e.which;
    if (key == 13) {
        submitGoogleSearch2();
    }
}
function submitGoogleSearch2() {
    document.forms[0].action = "/search-results/";
    document.forms[0].method = "GET";
    //disable all the input tags that don't belong to the google search
    $('form input, form select').each(function() {
        if (this.name != 'q2' && this.name != 'cx' && this.name != 'cof'
			&& this.name != 'ie' && this.name != 'googlesearchbutton') {
            $(this).attr('disabled', 'disabled');
        }
    });
    document.forms[0].submit(); // Submit the page
    return true;
}

