//// 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){
	myVar = data;
	/// BUTTONS
	if (myVar == 'pacifierBtn'){
		dcsMultiTrack('DCS.dcsuri', '/HP_Flash/Pacifier.btn', 'WT.ti', 'Pacifier Flash Button Click ');
		//alert('pacifierBtn')
	}
	if (myVar == 'coffeeBtn'){
		dcsMultiTrack('DCS.dcsuri', '/HP_Flash/Coffee.btn', 'WT.ti', 'Coffee Flash Button Click');
		//alert('coffeeBtn')
	}
	if (myVar == 'bikeBtn'){
		dcsMultiTrack('DCS.dcsuri', '/HP_Flash/Bike.btn', 'WT.ti', 'Bike Flash Button Click');
		//alert('bikeBtn')
	}
	/// ANIMATIONS
	if (myVar == 'pacifierAnim'){
		dcsMultiTrack('DCS.dcsuri', '/HP_Flash/Pacifier/', 'WT.ti', 'Pacifier Flash Button View');
		//alert('pacifierAnim')
	}
	if (myVar == 'coffeeAnim'){
		dcsMultiTrack('DCS.dcsuri', '/HP_Flash/Coffee/', 'WT.ti', 'Coffee Flash Button View');
		//alert('coffeeAnim')
	}
	if (myVar == 'bikeAnim'){
		dcsMultiTrack('DCS.dcsuri', '/HP_Flash/Bike/', 'WT.ti', 'Bike Flash Button View');
		//alert('bikeAnim')
	}
}

function resetTopNav() {
  var myRegisterDHTML = document.getElementById('accountLogin');
	var myQuickLogin = document.getElementById('quickLogin');
	var myLanguageSelect = document.getElementById('languageSelect');
	var myLanguageSelectMenu = document.getElementById('languageSelectMenu');
	
	myQuickLogin.className = "hidden";
	myLanguageSelectMenu.className = "hidden";
	myRegisterDHTML.className = "accountLogin";
	myLanguageSelect.className = "languageSelect";
}

/// WAIT FOR THE PAGE TO LOAD.
window.onload = function(){ 

	//// CUSTOM DROP DOWNS FOR HOME PAGE
	//DUE to ACCESSIBILITY, WE DISABLE CUSTOM STYLES IF USER USES KEYBOARD ONLY AND ONLY IF THEY TAB TO SEARCH BOX
	//Large Get A Rate Quote
	
	//Small Select State/Provice
//	var osState = new SFX_Dropdown_Controller("sState", true, "Select your state/province", "_images/customselect/", 'sAgentZip');
	var osState = new SFX_Dropdown_Controller("sState", true, "State/Province", "../../_images/customselect/", "searchInput");

	
	var osType = new SFX_Dropdown_Controller("sType",true, "Auto", "_images/customselect/", 'searchBox');  

//// CALL AUTO SPIFF FEATURE
	spiffAutoScroll();
	
//// 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. 
	};
	}
	

/// REGISTER HIDDEN ZONE
	var myRegisterDHTML = document.getElementById('accountLogin');
	var myQuickLogin = document.getElementById('quickLogin');
	var myLanguageSelect = document.getElementById('languageSelect');
	var myLanguageSelectMenu = document.getElementById('languageSelectMenu');
	
	myRegisterDHTML.onclick = function() {

		if (myRegisterDHTML.className == 'accountLogin') {
		  resetTopNav();
			this.className = "accountLoginActive"
			myQuickLogin.className = ""
			dcsMultiTrack('DCS.dcsuri', '/login_form/', 'WT.ti', 'Login form');	// WebTrends Account Center Functionality Tagging Exposing the Login Form 
			return false; // This disables the redirect of the live link if javascript is enabled.
			} else {
			this.className = "accountLogin"
			myQuickLogin.className = "hidden"
			dcsMultiTrack('DCS.dcsuri', 'homepage.html', 'WT.ti', 'Home Page');// WebTrends Account Center Functionality Tagging Hidding the Login Form
			return false; // This disables the redirect of the live link if javascript is enabled.
		}
	};
	
	myLanguageSelect.onclick = function() {

		if (myLanguageSelect.className == 'languageSelect') {
		  resetTopNav();
			this.className = "languageSelectActive"
			myLanguageSelectMenu.className = ""
			dcsMultiTrack('DCS.dcsuri', '/language_form/', 'WT.ti', 'Login form');	// WebTrends Account Center Functionality Tagging Exposing the Login Form 
			return false; // This disables the redirect of the live link if javascript is enabled.
			} else {
			this.className = "languageSelect"
			myLanguageSelectMenu.className = "hidden"
			dcsMultiTrack('DCS.dcsuri', 'homepage.html', 'WT.ti', 'Home Page');// WebTrends Account Center Functionality Tagging Hidding the Login Form
			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('zoneAgentGo');
			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) {
			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;
	}

