
//ARQ STUFF

if (window.addEventListener) { //DOM method for binding an event
	window.addEventListener("load", checkError, false);
	window.addEventListener("unload", resetFld, false);
}
else if (window.attachEvent) { //IE exclusive method for binding an event
	window.attachEvent("onload", checkError);
	window.attachEvent("onunload", resetFld);
}
else if (document.getElementById) {//support older modern browsers
	window.onload=checkError;
	window.onunload=resetFld;

}

function checkError() {
	var errFlag = "";
	
	if (errFlag == "true") {

		if (document.getElementById("errMsgCnt").value == "") {
			document.getElementById("errMsgCnt").value = "true";
			document.getElementById("rateQuoteZipErrorMsg").style.display = "block";
		}
		//else {
			//document.getElementById("rateQuoteZipErrorMsg").style.display = "none";
			//hrefStr = window.location.href;
			//var listAry = hrefStr.split("?");
			
			//window.location.href=listAry[0];
		//}

	}
}

function resetFld() {
	document.getElementById("rateQuoteZipErrorMsg").style.display = "none";
}

function trackQuoteForm() {
        var wtQuoteFormSelect = document.getElementById('sType');
        var wtQuoteFormSelectedIndex = wtQuoteFormSelect.selectedIndex;
        var wtQuoteFormType = wtQuoteFormSelect.options[wtQuoteFormSelectedIndex].text;
        var wtQuoteFormZip = document.getElementById('sZip').value;
        var quoteFormURI = '/HP_QForm/';
        var quoteFormQuery ='?quoteZip='+wtQuoteFormZip+'&quoteType='+wtQuoteFormType;
        dcsMultiTrack('DCS.dcsuri', quoteFormURI,'DCSext.dcsqry', quoteFormQuery,'WT.ti','Quote Form Submission');
}

function isValidateZip()
{
	
	var zipVal = document.getElementById("getRateQuoteForm").instate.value;
	
	var RegExpUS = /(^\d{5}$)/;
	//var RegExpCA = /^([ABCEGHJKLMNPRSTVXY][0-9][ABCEGHJKLMNPRSTVWXYZ])\s*([0-9][ABCEGHJKLMNPRSTVWXYZ][0-9])$/;
	var RegExpCA = /^([abceghjklmnprstvxyABCEGHJKLMNPRSTVXY][0-9][abceghjklmnprstvwxyzABCEGHJKLMNPRSTVWXYZ])\s*([0-9][abceghjklmnprstvwxyzABCEGHJKLMNPRSTVWXYZ][0-9])$/;

	var matchUS, matchCA;
	zipVal = Ltrim(zipVal);
	zipVal = Rtrim(zipVal);
	document.getElementById("getRateQuoteForm").instate.value = zipVal;
	matchUS = RegExpUS.test(zipVal);
	matchCA = RegExpCA.test(zipVal);
	
	if(matchUS || matchCA)
	{
		if (matchCA)
		{
			zipVal = zipVal.toUpperCase();
			zipVal = zipVal.replace(/\s+/g,'');
			document.getElementById("getRateQuoteForm").instate.value = zipVal;
			
		}	
		return true
	}
	else
	{
		document.getElementById("rateQuoteZipErrorMsg").style.display = "block";
		document.getElementById("rateQuoteZipErrorMsg").innerText = "Please enter a valid Zip/Postal Code";
		document.getElementById("rateQuoteZipErrorMsg").style.position = "absolute";
		var curleft, curtop;
		curleft = document.getElementById("getRateQuoteForm").instate.offsetLeft;
		curtop = document.getElementById("getRateQuoteForm").instate.offsetTop;
		
		//document.getElementById("rateQuoteZipErrorMsg").style.top = -(curleft/4);
		//document.getElementById("rateQuoteZipErrorMsg").style.left = curleft - curtop + (curleft/10);
		return false;
	}
	
	
}

function Ltrim (objVal)
{
	return objVal.replace( /^\s*/,'');
}

function Rtrim(objVal)
{
	return objVal.replace( /\s*$/,'');
}

function doSubmit() {
	
	if (location.href.indexOf("index") > 0) { // on homepage, for web trends
		if (document.getElementById("divB").style.display == "none") {
			dcsMultiTrack('DCS.dcsuri', '/HP_Quote.clk', 'WT.ti', 'Home Page Quote Click');
		}
	}
	
	if((document.getElementById("getRateQuoteForm").instate.value == "ZIP/Postal Code") || (document.getElementById("getRateQuoteForm").instate.value == "")) 
	{

		switch(document.getElementById("getRateQuoteForm").quotetype.value) 
		{
			case "ARQ":
				document.getElementById("rateQuoteZipErrorMsg").style.display = "inline";
				document.getElementById("rateQuoteZipErrorMsg").innerText = "Please enter your Zip/Postal Code";
				document.getElementById("rateQuoteZipErrorMsg").style.position = "absolute";
				return false;
				//document.getElementById("getRateQuoteForm").action = "http://www.statefarm.com/insurance/auto_insurance/auto_insurance.asp";
				break;
			case "HOW":
				document.getElementById("rateQuoteZipErrorMsg").style.display = "inline";
				document.getElementById("rateQuoteZipErrorMsg").innerText = "Please enter your Zip/Postal Code";
				document.getElementById("rateQuoteZipErrorMsg").style.position = "absolute";
				return false;
				//document.getElementById("getRateQuoteForm").action = "http://www.statefarm.com/insurance/quote/homeowners.asp";
				break;
			case "CRQ":
				document.getElementById("rateQuoteZipErrorMsg").style.display = "inline";
				document.getElementById("rateQuoteZipErrorMsg").innerText = "Please enter your Zip/Postal Code";
				document.getElementById("rateQuoteZipErrorMsg").style.position = "absolute";
				return false;
				//document.getElementById("getRateQuoteForm").action = "http://www.statefarm.com/insurance/quote/condo.asp";
				break;
			case "RRQ":
				document.getElementById("rateQuoteZipErrorMsg").style.display = "inline";
				document.getElementById("rateQuoteZipErrorMsg").innerText = "Please enter your Zip/Postal Code";
				document.getElementById("rateQuoteZipErrorMsg").style.position = "absolute";
				return false;
				//document.getElementById("getRateQuoteForm").action = "http://www.statefarm.com/insurance/quote/renters/renters.asp";
				break;
			case "LRQ":
				document.getElementById("getRateQuoteForm").action = "http://www.statefarm.com/quote/life.htm";
				break;
			case "HRQ":
				document.getElementById("getRateQuoteForm").action = "http://www.statefarm.com/apps/hrq_health/health_welcome.asp";
				break;
			case "DSB":
				document.getElementById("getRateQuoteForm").action = "http://www.statefarm.com/insurance/disability/disability.asp";
				break;
			case "LTCRQ":
				document.getElementById("getRateQuoteForm").action = "http://www.statefarm.com/apps/hrq/welcomeltc_01.asp";
				break;
			case "BURQ":
				document.getElementById("getRateQuoteForm").action = "http://www.statefarm.com/insurance/business/business.asp";
				break;
			case "BRQ":
				document.getElementById("getRateQuoteForm").action = "http://www.statefarm.com/insurance/boat/boat.asp";
				break;
			case "other":
				document.getElementById("getRateQuoteForm").action = "http://www.statefarm.com/insurance/other/other.asp";
				break;
			default:
				document.getElementById("getRateQuoteForm").action = "http://www.statefarm.com/insurance/other/other.asp";
				break;
		}

	}
	else {
		
		switch(document.getElementById("getRateQuoteForm").quotetype.value) {
			case "ARQ":
					if(!(isValidateZip()))			
					{
						return false;
					}
					else
					{
					document.getElementById("getRateQuoteForm").action="http://www.statefarm.com/apps/InsuranceApp/S1AppSelector.asp?appname=ARQ";
					document.getElementById("getRateQuoteForm").method="POST";
					document.getElementById("getRateQuoteForm").submit();
					}
					break;
			case "HOW":
					if(!(isValidateZip()))			
					{
						return false;
					}
					else
					{
					document.getElementById("getRateQuoteForm").action="http://www.statefarm.com/apps/InsuranceApp/S1AppSelector.asp?appname=HOW";
					document.getElementById("getRateQuoteForm").method="POST";
					document.getElementById("getRateQuoteForm").submit();
					}
					break;
			case "CRQ":
					if(!(isValidateZip()))			
					{
						return false;
					}
					else
					{
					document.getElementById("getRateQuoteForm").action="http://www.statefarm.com/apps/InsuranceApp/S1AppSelector.asp?appname=CRQ";
					document.getElementById("getRateQuoteForm").method="POST";
					document.getElementById("getRateQuoteForm").submit();
					}	
					break;
			case "RRQ":
					if(!(isValidateZip()))			
					{
						return false;
					}
					else
					{
					document.getElementById("getRateQuoteForm").action="http://www.statefarm.com/apps/InsuranceApp/S1AppSelector.asp?appname=RRQ";
					document.getElementById("getRateQuoteForm").method="POST";
					document.getElementById("getRateQuoteForm").submit();
					}
					break;
			case "LRQ":
				document.getElementById("getRateQuoteForm").action="https://online.statefarm.com/apps/lrq3/lrq.asp";
				break;
			case "HRQ":
				document.getElementById("getRateQuoteForm").action="http://www.statefarm.com/apps/hrq_health/health_welcome.asp";
				break;
			case "DSB": 
				document.getElementById("getRateQuoteForm").action="http://www.statefarm.com/insurance/disability/disability.asp";
				break;
			case "LTCRQ":
				document.getElementById("getRateQuoteForm").action="http://www.statefarm.com/apps/hrq/welcomeltc_01.asp";
				break;
			case "BURQ":
				document.getElementById("getRateQuoteForm").action="http://www.statefarm.com/insurance/business/business.asp";
				break;
			case "BRQ":
				document.getElementById("getRateQuoteForm").action="http://www.statefarm.com/insurance/boat/boat.asp";
				break;
			case "other":
				document.getElementById("getRateQuoteForm").action="http://www.statefarm.com/insurance/other/other.asp";
				break;
			default:
				document.getElementById("getRateQuoteForm").action="http://www.statefarm.com/insurance/other/other.asp";
				break;
	
		}	
	}
}

/// ARQ STUFF


/// HIDE/SHOW ZIPCODE ELMENT IN RATE QUOTE MODULES
/// HIDE/SHOW ZIPCODE ELMENT IN RATE QUOTE MODULES
/// HIDE/SHOW ZIPCODE ELMENT IN RATE QUOTE MODULES

// id1 = ID for the first div which is typically visible
// 'sZip' = ID for the second div which is typically hidden
// field = the ID for the field of the select box

function showhide(field){
	if ((document.getElementById(field)[document.getElementById(field).selectedIndex].value)== "other") {
		document.getElementById('sZip').style.display = "none";
	} 
	else if ((document.getElementById(field)[document.getElementById(field).selectedIndex].value)== "LRQ") {
		document.getElementById('sZip').style.display = "none";
	}
	else if ((document.getElementById(field)[document.getElementById(field).selectedIndex].value)== "HRQ") {
		document.getElementById('sZip').style.display = "none";
	}
	else if ((document.getElementById(field)[document.getElementById(field).selectedIndex].value)== "LTCRQ") {
		document.getElementById('sZip').style.display = "none";
	}
	else {
		document.getElementById('sZip').style.display = "inline"; 
	}
}
/// HIDE/SHOW ZIPCODE ELMENT IN RATE QUOTE MODULES
/// HIDE/SHOW ZIPCODE ELMENT IN RATE QUOTE MODULES
/// HIDE/SHOW ZIPCODE ELMENT IN RATE QUOTE MODULES



//// VARIABLES AND FUNCTION FOR AUTO SPIFF FEATURE
var running = true;
var interval = 4000; // 1000 = 1 sec
var nextViewIndex = -1;	
	
	function spiffAutoScroll(){
	
	if (running){
	
	var hotAutoTabs = document.getElementById('hotSpiffTabs');
	var autoLinks = hotAutoTabs.getElementsByTagName('a');
		for (var y=0;y < autoLinks.length;y++){
				if(nextViewIndex >= 0)
				{	
					if(nextViewIndex == y)
					{
						//set viewable
						var autoCurrentTab = autoLinks[y].id;
						//set icons
						autoLinks[y].className = "active";
						//swap tab for zone to get id
						var autoTempZone = autoCurrentTab.replace("tab","zone");
						//set background
						document.getElementById(autoTempZone).className = "visible"
		
					} else {
						//set viewable
						var autoCurrentTab = autoLinks[y].id;
						//set icons
						autoLinks[y].className = "non-active";
						//swap tab for zone to get id
						var autoTempZone = autoCurrentTab.replace("tab","zone");
						//set background
						document.getElementById(autoTempZone).className = "hidden"
					}
				} 
				
				if (nextViewIndex == -1 && ((autoLinks.length - 1) == y))
				{
					nextViewIndex = 0;
				}

		}
			nextViewIndex++;
			if (nextViewIndex > (autoLinks.length - 1))
			{
				nextViewIndex = 0;
			}  	 	
		
	setTimeout("spiffAutoScroll();",interval)
	}
	
}

//// *  FLASH TRACKING FUNCTIONS *//////

function flashTagCall(data){
	//alert(data);
	myVar = data;
	/// BUTTONS
	if (myVar == 'Service'){
		dcsMultiTrack('DCS.dcsuri', '/HP_Flash/Service/', 'WT.ti', 'Service Flash View');
		//alert('Service')
	}
	if (myVar == 'Convenience'){
		dcsMultiTrack('DCS.dcsuri', '/HP_Flash/Convenience/', 'WT.ti', 'Convenience Flash View');
		//alert('Convenience')
	}
	if (myVar == 'Savings'){
		dcsMultiTrack('DCS.dcsuri', '/HP_Flash/Savings/', 'WT.ti', 'Savings Flash View');
		//alert('Savings')
	}
	/// ANIMATIONS
	if (myVar == 'Relationships'){
		dcsMultiTrack('DCS.dcsuri', '/HP_Flash/Relationships/', 'WT.ti', 'Relationships Flash View');
		//alert('Relationships')
	}
}


/// WAIT FOR THE PAGE TO LOAD.
window.onload = function(){ 


//// CALL AUTO SPIFF FEATURE
	spiffAutoScroll();

//// ANIMATE EMERGENCY SHADE
var emergencyShade = document.getElementById('emergencyShade');
var closeEmergency = document.getElementById('closeEmergency');
if (emergencyShade != null ){
closeEmergency.onclick = function(){
	emergencyShade.style.display = "none";
}

setTimeout("document.getElementById('emergencyShade').style.display='block';",2000)
}
	
//// MANUAL CLICK SPIFF FEATURE

	var hotSpiffTabs = document.getElementById('hotSpiffTabs');
	var spiffLinks = hotSpiffTabs.getElementsByTagName('a');
	var spiffCounter = spiffLinks.length;
   
	for (var i=0;i < spiffLinks.length;i++){
	
	spiffLinks[i].onclick = function() {
	/// Activate Tab
	
	/// STOP AUTO PLAY OF THE SPIFF's
	running = false;
	
	var currentSpiffTab = this.id;
	this.className = "active"
	
	/// Activate Zone /// SWAP OUT TAB FOR ZONE
	var newSpiffZone = currentSpiffTab.replace("tab","zone")
	document.getElementById(newSpiffZone).className = "visible"
	
	/// Loop through all links and disable enable the classes
	for (var y=0;y < spiffCounter;y++){
				
				/// If Not the clicked link	
				if(spiffLinks[y].id != currentSpiffTab){
				
				/// make sure all the non clicked tabs are off
				spiffLinks[y].className = "visible"
				
				/// make sure all the accociated zones are off
				var spiffCurrentTab = spiffLinks[y].id
				/// Swap out tab for zone
				var spiffNewZone = spiffCurrentTab.replace("tab","zone")
				document.getElementById(spiffNewZone).className = "hidden"
				
				}
				//alert(status);
					
	}  	 	
	return false; // This disables the redirect of the live link if javascript is enabled. 
	};
	}

//// MANUAL CLICK LEFT TAB FEATURE

	var hotTabs = document.getElementById('hotTabs');
	var links = hotTabs.getElementsByTagName('a');
	var counter = links.length;
   
	for (var i=0;i < links.length;i++){
	
	links[i].onclick = function() {
	/// Activate Tab
	var currentLink = this.id;
	this.className = "active"
	
	/// Activate Zone
	var newTab = currentLink.replace("tab","zone")
	document.getElementById(newTab).className = "null"
	
	/// Loop through all links and disable enable the classes
	for (var y=0;y < counter;y++){
				
				/// If Not the clicked link	
				if(links[y].id != currentLink){
				
				/// make sure all the non clicked tabs are off
				links[y].className = "null"
				
				/// make sure all the accociated zones are off
				var currentZone = links[y].id
				var newZone = currentZone.replace("tab","zone")
				document.getElementById(newZone).className = "hidden"
				
				}
				//alert(status);
					
	}  	 	
	return false; // This disables the redirect of the live link if javascript is enabled. 
	};
	}
	

function resetTopNav() {

	var myLanguageSelect = document.getElementById('languageSelect');
	var myLanguageSelectMenu = document.getElementById('languageSelectMenu');
	
	myLanguageSelectMenu.className = "hidden";
	myLanguageSelect.parentNode.className = "dropDown";
}
/// REGISTER HIDDEN ZONE

	var myLanguageSelect = document.getElementById('languageSelect');
	var myLanguageSelectMenu = document.getElementById('languageSelectMenu');
	
	
	myLanguageSelect.onclick = function() {
	
		if (myLanguageSelect.parentNode.className == 'dropDown') {
		  resetTopNav();
			this.parentNode.className = "dropDown open"
			myLanguageSelectMenu.className = ""
			return false; // This disables the redirect of the live link if javascript is enabled.
			} else {
			this.parentNode.className = "dropDown"
			myLanguageSelectMenu.className = "hidden"
			return false; // This disables the redirect of the live link if javascript is enabled.
		}
	};


		//---------------------------------------------------------------------------//
		// var sBtn contains the ID of the Search Box Button
		// var sInput contains the ID for the Search Box Input Field
		// var srFrom contains the ID for the Search Box Form Element
		//---------------------------------------------------------------------------//
			
		/// CAPTURE AND SUBMIT WEBTRENDS TRACK TAG FOR SEARCH BOX INPUT
		var sBtn = document.getElementById('searchBtn');
		
		if (sBtn != null){
			sBtn.onclick = function() {
				var sInput = document.getElementById('searchInput'); 
				var srForm = document.getElementById('searchBox');	
				dcsMultiTrack('WT.oss', sInput.value);
				srForm.submit();		
			};
		}
				
		//---------------------------------------------------------------------------//
		// var fBtn contains ID for Find An Agent Go Button
		// var fZipErr the Error message for Find An Agent Module
		// var fZipCode the ZipCode for Find An Agent Module
		// var fAgentForm the ID for the Form Element Find An Agent Module
		//---------------------------------------------------------------------------//
		
		/// TRACK TAG - Find An Agent MODULE: HOMPAGE DEFAULT VIEW
			var fBtn = document.getElementById('btnAgentSearch');
			var fZipErr = document.getElementById('fAgentZipError');
			var fZipCode = document.getElementById('sAgentZip'); 
			var fAgentForm = document.getElementById('findAgentForm');
					
			if(fBtn != null){
				fBtn.onclick = function() {
					if (fZipCode.value.length < 5 || fZipCode.value == "ZIP/Postal Code") {
						fZipErr.style.display = 'block';
						return false;
					} else {
						fZipErr.style.display = 'none';
						fAgentForm.submit();		
					}
				};
			}
		
		//---------------------------------------------------------------------------//
		// var ccGoBtn contains ID for Claim Center Report Button Homepage
		// var ccErr the Error message for Claim Center HomePage Module
		// var ccState the State for Claim Center HomePage Module
		// var ccForm the ID for the Form Element for Claim Center HomePage Module
		//---------------------------------------------------------------------------//
		
		// TRACK TAG - CLAIM CENTER MODULE: HOMEPAGE DEFAULT VIEW
			var ccGoBtn = document.getElementById('btnReport');
			var ccErr = document.getElementById('claimZoneErr');
			
			if(ccGoBtn != null){
				ccGoBtn.onclick = function() {
					var ccState = document.getElementById('sState'); 
					var ccForm = document.getElementById('ccForm');
					if (ccState.value == "") {
						ccErr.style.display = 'block';
						return false;
					} else {
						ccForm.action= "https://online2.statefarm.com/apps/sfappselector/RedirectorServlet?applicationName=IIC&stateProv="+document.getElementById('sState').value+"";
						ccForm.submit();	
					}
				};
			}	
		
		//---------------------------------------------------------------------------//
		// var ccModGoBtn contains ID for Claim Center Report Button Emergency Version
		// var ccModErr the Error message for Claim Center HomePage  Emergency Module
		// var ccStateEmergency the State for Claim Center HomePage Emergency Module
		// var ccModForm the ID for the Form Element for Claim Center HomePage Emergency Module
		//---------------------------------------------------------------------------//
		
		/// TRACK TAG - CLAIM CENTER MODULE: HOMEPAGE EMERGENY VIEW
			var ccModGoBtn = document.getElementById('btnReportSml');
			var ccModErr = document.getElementById('claimZoneErr');
			
			if(ccModGoBtn != null){
				ccModGoBtn.onclick = function() {
					var ccStateEmergency = document.getElementById('sState'); 
					var ccModForm = document.getElementById('ccEmergencyMod');
					if (ccStateEmergency.value == "") {
						ccModErr.style.display = 'block';
						return false;
					} else {
						ccModErr.style.display = 'none';
						ccModForm.submit();		
					}
				};
			}
		

}

//------------------------------------------------------------------
// for login
//------------------------------------------------------------------

	function CollectDeviceInfoAndRePostToLoginService() {
	
		document.getElementById("LoginScreen").pm_fp.value = add_deviceprint();
		
		// setCookie for RememberUserId to be used when LoginService.asp goes away
		//if (document.getElementById("LoginScreen").remCustID.checked == true) {
		if (false) {
			setCookie("W0082393.UserId", document.getElementById("LoginScreen").userID.value);
			//setCookie("W0082393.RememberUserId ", "True");
		}
		else {
			setCookie("W0082393.UserId", "");
			//setCookie("W0082393.RememberUserId ", "False");
		}		
	}
	
	function setCookie(name, value) {
	
		var cookie_date = new Date(); 
		cookie_date.setFullYear(2099); 

		var the_cookie_date = cookie_date.toGMTString(); 
		var cookie_name = name; 
		var the_cookie_data = value; 

		the_cookie = the_cookie_data + ';expires=' + the_cookie_date + ';path=/;domain=.statefarm.com';  
		document.cookie=cookie_name+"="+the_cookie;
	}

