
//RZ Plugins INIT
$(document).ready(function(){
     $('#sAgentZip').inputHint();
     $('#userID2').inputHint();
     $('#password2').inputHint();
     //Checkboxes
     $('input:checkbox').razorCheckBox(
                     {
						 styledCheckboxClass: 'styledCheckBox',
						 checkedClass: 'on',
						 disabledClass: 'disabled',
						 hideClass: "hidden",
						 focusClass: "focus"
                     }
     );
     /// Radio
     $('input:radio').razorRadioButton(
            {
                defaultClass: 'styledRadioButton',
                checkedClass: 'on',
                disabledClass: 'disabled',
                hideClass: 'hidden',
                labelFocusClass: 'focus'
            }
        );
     /// Online Security Modal
     $("#onlineSecurity").click(function(e){
                     e.preventDefault();
                     $('#modalOnlineSecurity').modal({close:false,focus:false, persist: true});
                     $('#onlineSecurityHdr').attr({'tabIndex':'0'}).focus();           
     });
     ////
});

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



//****************************************************/
//**************  Validate Claims ********************/
//****************************************************/
function submitClaimForm(){
	var ccState = document.getElementById('sState'); 
	var ccErr = document.getElementById('claimZoneErr'); 
	if (ccState.value == "") {
		ccErr.style.display = 'block';
		return false;
	}
	return true;
}
//************** End Validate Claims ****************//




//****************************************************/
//************ Claims Center Radio Buttons ***********/
//****************************************************/
	$(document).ready(function() { setupControls(); });		
	function setupControls() {
		$('input:radio').addClass("radio");
		$('input:radio').wrap("<div class=\"radio\"></div>");
		$('input:radio').change(updateControls);	
		updateControls();
	}
	function updateControls() {
		$('input:radio').parent().removeClass("checked");
		$('input:radio:checked').parent().addClass("checked");
	}
//************ END Claims Center Radio Buttons ***********/




//****************************************************/
//****** State Validation for Life Product ***********/
//****************************************************/
function stateValidation(state){
		if(state == "Select a State"){
			return false;
		}
		return true;
}
//****************************************************/




//****************************************************/
// ************* GET A RATE QUOTE BOX ***************//
//****************************************************/
$(document).ready(function(){		
	$("#applicationName option[value='Auto']").attr('selected', 'selected');
	$(".appSelectAuto").show();
	$(".appSelectLife").hide();
	
	$(document).click(function(){ $(".errorMsg").hide(); });
	$("#postalCode").click(function(){ $("#postalCode").val(''); });
	
	$("#applicationName").change(function(){ 
		$(".appSelect").hide();
		$(".appSelect" + $("#applicationName").val()).show();
		
		if( ($("#applicationName").val() == "HRQ") || ($("#applicationName").val() == "LTCRQ") ){
			$("#getRateQuoteGo").css("left","135px");
		}
		else {
			$("#getRateQuoteGo").css("left","267px");
		}
	});
	
	$("#getRateQuoteForm").submit(function(){
		$("#currentUrl").val("" + document.location.href +"");	
		switch($("#applicationName").val()) {
			case "Life":	
				if(!stateValidation($("#states").val())){
					showErrorMessage("Please select a state from dropdown");
					return false;
				}
				else {
					quoteURL = $("#appSelector_servlet").val() + "?applicationName=Life&state="+ $("#states").val();							
					break;
			}
		case "HRQ":
				quoteURL = "/apps/hrq_health/health_welcome.asp";
				break;
			case "LTCRQ":
				quoteURL = "/apps/hrq/welcomeltc_01.asp";	
				break;
			default:
				if(!simpleValidation($("#postalCode").val())){
					showErrorMessage("Please enter a Zip/Postal Code");
					return false;
				}
				else {
					var request = $("#appSelector_rest").val() + "?applicationName=" + $("#applicationName").val() + "&postalCode=" + $("#postalCode").val() + "&callback=?";
					jQuery.getJSON(request, zipResponse);
					errorTimer = setTimeout("showErrorMessage('Please try again later')", 4000);	
					return false;
				}
		}
		submitForm(quoteURL);
		return false;
	});
});
 	
	function zipResponse(data){
		clearTimeout(errorTimer);
		if ( (data != null ) && (data.result == "true")) {
			var quoteUrl = $("#path2online2").val() + "" + data.redirect;
			submitForm(quoteUrl);
		}
		else {
			showErrorMessage("Please enter a valid ZIP/Postal Code");
		}
	}
	function submitForm(quoteUrl){
		$("#getRateQuoteForm").unbind('submit');
		$("#getRateQuoteForm").attr("action",quoteUrl);								
		if (dcsMultiTrack !=  null) trackQuoteForm();
		$("#getRateQuoteForm").submit();
	}
	function simpleValidation(postalCode){
		if(postalCode == ""){
			return false;
		}
		return true;
	}
	var errorTimer;
	function showErrorMessage(msg){
		clearTimeout(errorTimer);
		$("#rateQuoteZipErrorMsg").html(msg); 
		$("#rateQuoteZipErrorMsg").show(); 
	}
	function trackQuoteForm(quoteUrl) {
		var wtQuoteFormType = $("#applicationName").val();
		var wtQuoteFormZip = $("#postalCode").val();
		var quoteFormQuery ='?quoteZip='+wtQuoteFormZip+'&amp;appName='+wtQuoteFormType + "&amp;currentUrl="+document.location.href;
		dcsMultiTrack('DCS.dcsuri', quoteUrl,'DCSext.dcsqry', quoteFormQuery,'WT.ti','Quote Form Submission');
	}
// ************* END GET A RATE QUOTE BOX ***************//




function checkError() {
	var errFlag = "";
	
	if (errFlag == "true") {

		if (document.getElementById("errMsgCnt").value == "") {
			document.getElementById("errMsgCnt").value = "true";
			document.getElementById("rateQuoteZipErrorMsg").style.display = "block";
		}
	}
}

function resetFld() {
	document.getElementById("rateQuoteZipErrorMsg").style.display = "none";
}


//// 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(){ 


//// SEARCHBOX FOCUS
	
//// 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');
	
	
		//---------------------------------------------------------------------------//
		// 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 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("LoginForm").pm_fp.value = add_deviceprint();
        
        if ( document.getElementById("LoginForm").chkrememberMe.checked == true) {            setCookie("W0082393.UserId",  document.getElementById("LoginForm").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;
	}





