function cf_findAnAgentSubmit(findAnAgentForm)
{
	var keyCodeID = findAnAgentForm.keyCode.value;
	var webID = findAnAgentForm.MM_webID.value;

	// disable keyCode if not available
	if (keyCodeID == "") 
	{
		findAnAgentForm.keyCode.disabled = true;
	} 
	else 
	{
		findAnAgentForm.keyCode.disabled = false;
	}

	// disable MM_webID if not available
	if (webID == "") 
	{
		findAnAgentForm.MM_webID.disabled = true;
	} 
	else 
	{
		findAnAgentForm.MM_webID.disabled = false;
	}

	if (cf_validateZIPCode(findAnAgentForm.zip))
	{
		findAnAgentForm.action = rc.urlLookup ("FindAgentResults");
		findAnAgentForm.submit();
	}
}

function cf_findAnAgentEnter(findAnAgentForm)
{
	var keycode;
	
	if (window.event) 
	{
		keycode = window.event.keyCode;
	}

	if (keycode == 13)
	{
		cf_findAnAgentSubmit(findAnAgentForm);
	}
}

function cf_eServiceLoginSubmit(eServiceLoginForm) 
{
	var s=s_gi(OMNITURE_REPORT_SUITE_ID);
	s.linkTrackVars="events";
	s.linkTrackEvents="event7";
	s.events="event7";
	s.tl("button","o","Manage Your Policies login button");

	eServiceLoginForm.action = rc.urlLookup ("SelfServiceLoginAction");
	eServiceLoginForm.target.value = rc.urlLookup ("SelfServiceLoginTarget");
	eServiceLoginForm.submit();
}

function cf_getAQuoteSubmit(getAQuoteForm)
{
	var selectControl = getAQuoteForm.policyType.options;
	var index = getAQuoteForm.policyType.selectedIndex;
	var choice = selectControl[index].value;
	var keyCodeID = getAQuoteForm.keyCode.value;
	var webID = getAQuoteForm.MM_webID.value;

	// disable MM_webID if not available
	if (webID == "") 
	{
		getAQuoteForm.MM_webID.disabled = true;
	} 
	else 
	{
		getAQuoteForm.MM_webID.disabled = false;
	}

	// disable keyCode if not available
	if (keyCodeID == "") 
	{
		getAQuoteForm.keyCode.disabled = true;
	} 
	else 
	{
		getAQuoteForm.keyCode.disabled = false;
	}
	
	if (choice == "Life")
	{
		if (cf_validateZIPCode(getAQuoteForm.zipCode))
		{
			getAQuoteForm.MM_webID.disabled = true;
			getAQuoteForm.keyCode.disabled = true;
			getAQuoteForm.policyType.disabled = true;
	    	getAQuoteForm.action = rc.urlLookup ("LifeQuoteServiceStartQuote");
			getAQuoteForm.submit();
		}
    }
	else if (choice == "Auto" || choice == "H3" || choice == "H4" || choice == "H6")
	{
		if (cf_validateZIPCode(getAQuoteForm.zipCode))
		{
		    getAQuoteForm.action = rc.urlLookup ("QuoteServiceStartQuote");
			getAQuoteForm.submit();
		}
	}
}

function cf_getAQuoteEnter(getAQuoteForm)
{
	var keycode;
	
	if (window.event) 
	{
		keycode = window.event.keyCode;
	}

	if (keycode == 13)
	{
		cf_getAQuoteSubmit(getAQuoteForm);
	}
}

function cf_getAQuoteNoSelectSubmit(getAQuoteForm)
{
	if (cf_validateZIPCode(getAQuoteForm.zipCode))
	{
		var keyCodeID = getAQuoteForm.keyCode.value;
		var webID = getAQuoteForm.MM_webID.value;

		// disable MM_webID if not available
		if (webID == "") 
		{
			getAQuoteForm.MM_webID.disabled = true;
		} 
		else 
		{
			getAQuoteForm.MM_webID.disabled = false;
		}

		// disable keyCode if not available
		if (keyCodeID == "") 
		{
			getAQuoteForm.keyCode.disabled = true;
		} 
		else 
		{
			getAQuoteForm.keyCode.disabled = false;
		}

		getAQuoteForm.action = rc.urlLookup ("QuoteServiceStartQuote");
		getAQuoteForm.submit();
	}
}

function cf_getAQuoteNoSelectEnter(getAQuoteForm)
{
	var keycode;
	
	if (window.event) 
	{
		keycode = window.event.keyCode;
	}

	if (keycode == 13)
	{
		cf_getAQuoteNoSelectSubmit(getAQuoteForm);
	}
}

function cf_policyTypeChange(getAQuoteForm, choice)
{
	if (choice == "Auto" || choice == "H3" || choice == "H4" || choice == "H6")
	{
	    if (choice == "Auto")
	    {
		    getAQuoteForm.lob.value = "Auto";
		    getAQuoteForm.product.value = "AutoSimple";
	    }
	    else if (choice == "H3" || choice == "H4" || choice == "H6")
	    {
		    getAQuoteForm.lob.value = "Property";
		    getAQuoteForm.product.value = "PropSimple";
	    }

		// auto/home quote hidden form variables
	    getAQuoteForm.product.disabled = false;
		getAQuoteForm.lob.disabled = false;
		getAQuoteForm.landingPage.disabled = false;
		getAQuoteForm.event.disabled = false;
		getAQuoteForm.MM_webID.disabled = false;
		getAQuoteForm.keyCode.disabled = false;
    }
    else if (choice == "Life")
    {
		// auto and home quote hidden form variables
		// if it is life quote, disable auto/home hidden form variables so that they are
		// not part of the query string
	    getAQuoteForm.product.disabled = true;
		getAQuoteForm.lob.disabled = true;
		getAQuoteForm.landingPage.disabled = true;
		getAQuoteForm.event.disabled = true;
		getAQuoteForm.MM_webID.disabled = true;
		getAQuoteForm.keyCode.disabled = true;
    }
}

regExpZIPCodeFormat = /^\d{5}$/

function cf_validateZIPCode(zipCodeElement)
{
    var isValid = (regExpZIPCodeFormat.exec(zipCodeElement.value) == null)? false: true;

    if (isValid == false)
    {
		alert ("The ZIP code entered is invalid!  Please enter a valid ZIP code.");
        zipCodeElement.focus();
    }

    return (isValid);
}

function cf_processURLZIPValidation(getAQuoteForm)
{
    var qs = new PMQueryString ();
	var webId = qs.get ("MM_webID");
	var zipValid = qs.get ("zipValid");
	var zip = qs.get ("zip");

	if (zip != null)
	{
		getAQuoteForm.zipCode.value = zip;
	}
	if (zipValid != null)
	{
		alert ("The ZIP code entered is invalid!  Please enter a valid ZIP code.");
	}
	
	//alert("WebId: "+webId+"\nZipValid: "+zipValid);
	if (webId != null)
    {
		getAQuoteForm.MM_webID.value = webId;
    }
}	

function cf_processURLZIPValidationMessage(getAQuoteForm, message)
{
    var qs = new PMQueryString ();
	var webId = qs.get ("MM_webID");
	var zipValid = qs.get ("zipValid");
	var zip = qs.get ("zip");

	if (zip != null)
	{
		getAQuoteForm.zipCode.value = zip;
	}
	if (zipValid != null)
	{
		if (message != null)
		{
			alert (message);
		}
		else
		{
			alert ("The ZIP code entered is invalid!  Please enter a valid ZIP code.");
		}
	}
	
	//alert("WebId: "+webId+"\nZipValid: "+zipValid);
	if (webId != null)
    {
		getAQuoteForm.MM_webID.value = webId;
    }
}	
