﻿function updateTopNav () {
//get the Channel from Query String and select  
// the correct classes to add
//
   var qs = getQuerystring('Channel');
   
   if (qs=='Health') {
 // clear all selecteds 
  $('[id*=zz1_TopNavigationMenun]').find('table').removeClass('ms-topnavselected');
  $('[id*=zz1_TopNavigationMenun]').find('a').removeClass('ms-topnavselected');

// add to Health //
    $('#zz1_TopNavigationMenun1').find('table').addClass('ms-topnavselected');
    $('#zz1_TopNavigationMenun1').find('a').addClass('ms-topnavselected');
  
   if ($('[id*=list]').length>0) {
   // for the Guides/Forms Section
     $('[id*=list]').removeClass('guideListSelected');
     $('#listHealth').removeClass('guideList').addClass('guideListSelected');
   }
   
    if ($('[id*=news]').length>0) {
   // for the News Section
     $('[id*=news]').removeClass('newsListSelected');
     $('#newsHealth').removeClass('newsList').addClass('newsListSelected');
   }

  };
  
  if (qs=='Income Security' || qs=='Income%20Security') {
// clear all selecteds 
  $('[id*=zz1_TopNavigationMenun]').find('table').removeClass('ms-topnavselected');
  $('[id*=zz1_TopNavigationMenun]').find('a').removeClass('ms-topnavselected');

// add to Wealth //  
    $('#zz1_TopNavigationMenun2').find('table').addClass('ms-topnavselected');
    $('#zz1_TopNavigationMenun2').find('a').addClass('ms-topnavselected');

   if ($('[id*=list]').length>0) {
      // for the Guides/Forms Section
     $('[id*=list]').removeClass('guideListSelected');
     $('#listIncomeSecurity').removeClass('guideList').addClass('guideListSelected');
   }

    if ($('[id*=news]').length>0) {
   // for the News Section
     $('[id*=news]').removeClass('newsListSelected');
     $('#newsIncomeSecurity').removeClass('newsList').addClass('newsListSelected');
   }

  };
  
    if (qs=='Work/Life') {
// clear all selecteds 
  $('[id*=zz1_TopNavigationMenun]').find('table').removeClass('ms-topnavselected');
  $('[id*=zz1_TopNavigationMenun]').find('a').removeClass('ms-topnavselected');

// add to Wealth //  
    $('#zz1_TopNavigationMenun3').find('table').addClass('ms-topnavselected');
    $('#zz1_TopNavigationMenun3').find('a').addClass('ms-topnavselected');

   if ($('[id*=list]').length>0) {
      // for the Guides/Forms Section
     $('[id*=list]').removeClass('guideListSelected');
     $('#listWorkLife').removeClass('guideList').addClass('guideListSelected');
   }

    if ($('[id*=news]').length>0) {
   // for the News Section
     $('[id*=news]').removeClass('newsListSelected');
     $('#newsWorkLife').removeClass('newsList').addClass('newsListSelected');
   }

  };


  if (qs=='') {
 // clear all selecteds 
  $('[id*=zz1_TopNavigationMenun]').find('table').removeClass('ms-topnavselected');
  $('[id*=zz1_TopNavigationMenun]').find('a').removeClass('ms-topnavselected');

 // add to Home //
  $('#zz1_TopNavigationMenun0').find('table').addClass('ms-topnavselected');
  $('#zz1_TopNavigationMenun0').find('a').addClass('ms-topnavselected');

   if ($('[id*=list]').length>0) {
      // for the Guides/Forms Section
     $('[id*=list]').removeClass('guideListSelected');
     $('#listAll').removeClass('guideList').addClass('guideListSelected');
   }

  };

  if (qs=='Home') {
   // clear all selecteds 
  $('[id*=zz1_TopNavigationMenun]').find('table').removeClass('ms-topnavselected');
  $('[id*=zz1_TopNavigationMenun]').find('a').removeClass('ms-topnavselected');

 // add to Home //
  $('#zz1_TopNavigationMenun0').find('table').addClass('ms-topnavselected');
  $('#zz1_TopNavigationMenun0').find('a').addClass('ms-topnavselected');

    if ($('[id*=news]').length>0) {
   // for the News Section
     $('[id*=news]').removeClass('newsListSelected');
     $('#newsHome').removeClass('newsList').addClass('newsListSelected');
   }
  };
  
}  // end updateTopNav

//  determines Query String based on key //
function getQuerystring(key, default_)
{
  if (default_==null) default_=""; 
  key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
  var qs = regex.exec(window.location.href);
  if(qs == null)
    return default_;
  else
    return qs[1];
}

//  COOKIE CONTROL FUNCTIONS: ===================================================================================

function getExpDate(days, hours, minutes) {
    var expDate = new Date();
    if (typeof days == "number" && typeof hours == "number" && typeof hours == "number") {
        expDate.setDate(expDate.getDate() + parseInt(days));
        expDate.setHours(expDate.getHours() + parseInt(hours));
        expDate.setMinutes(expDate.getMinutes() + parseInt(minutes));
        return expDate.toGMTString();
    }
}

function setCookie(type,value,exphour){
   if (typeof exphour == 'undefined') 
   {
     var expString = getExpDate(366,1,1);
	 document.cookie = type+'=' + value + ';expires=' + expString + ';path=/'; 
   
   } else if (exphour == 'SESSION') {
      expString = ''
      document.cookie = type+'=' + value + ';path=/';
   
   } else {    
    var expString = getExpDate(0,exphour,0);
    document.cookie = type+'=' + value + ';expires=' + expString + ';path=/';
   }
     
   
}
   
function getCookie(nameE){
	var nameEQ = nameE + '=';
	var ca = document.cookie.split(';');
	for(var i=0; i< ca.length; i++){
		var c=ca[i];
		while(c.charAt(0)==' ') c=c.substring(1,c.length);
		if(c.indexOf(nameEQ)==0) return c.substring(nameEQ.length, c.length);
	}
	return '';						
}

function setPagesVisited(pageTitle, pageURL){
	//set, then return pages visited
	//Don't que the home page:
	var temp = pageTitle.substring(0,20);
	if(pageTitle.substring(0,20) == 'Publicis Home'){
		return "Publicis - Discard";
		}
	
	//if this page is a refresh of the last page, don't do anything:
 	if (pageURL == getCookie('Page1.URL')){
 		return "Same Refresh - Discard";
 	}
 	//Que this page:
 	var TempTitle = "s";	
	TempTitle = pageTitle;
	
//	var dashPos = 0;
//	dashPos = TempTitle.indexOf(" - ");
//	if(dashPos > 0){
//		TempTitle = TempTitle.substring(dashPos + 3);
//	}

	if( TempTitle.indexOf(" - ") > 0){
		TempTitle = TempTitle.substring(TempTitle.indexOf(" - ") + 3);
	    
	    if (TempTitle == 'GuideForm' || TempTitle == 'GuideFormSub') 
	    	{TempTitle='Guides/Forms'};
	    if (TempTitle == 'FAQ' || TempTitle == 'FAQSub' ) 
	    	{TempTitle='FAQs'};
	    if (TempTitle == 'IncomeSecurity') 
	    	{TempTitle='Income Security'};
	    if (TempTitle == 'WorkLife') 
	    	{TempTitle='Work/Life'};
	    	
    
	    var qs = getQuerystring('Channel');	
	    if (qs != '' && qs !='Home' ) {TempTitle = TempTitle + ' (' + qs + ')'};	
     
	} else {
	  var qs = getQuerystring('ContentTitle');	
//	  alert (qs);
	  if (qs != '' && qs !='Home' ) {TempTitle = qs};	
	}

	TempTitle = decode(TempTitle);	
	
	var expString = getExpDate(366,1,1);
 	document.cookie = "Page4.Title=" + getCookie('Page3.Title') + ";expires=" + expString + "; path=/";
 	document.cookie = "Page4.URL=" + getCookie('Page3.URL') + ";expires=" + expString + "; path=/";
 	document.cookie = "Page3.Title=" + getCookie('Page2.Title') + ";expires=" + expString + "; path=/";
 	document.cookie = "Page3.URL=" + getCookie('Page2.URL') + ";expires=" + expString + "; path=/";
 	document.cookie = "Page2.Title=" + getCookie('Page1.Title') + ";expires=" + expString + "; path=/";
 	document.cookie = "Page2.URL=" + getCookie('Page1.URL') + ";expires=" + expString + "; path=/";
 	document.cookie = "Page1.Title=" + TempTitle + ";expires=" + expString + "; path=/";
	document.cookie = "Page1.URL=" + pageURL + ";expires=" + expString + "; path=/";
	return("Cookie Set");
}
function clearAllCookies(){
	clearCookie("Page1.URL");
	clearCookie("Page1.Title");
	clearCookie("Page2.URL");
	clearCookie("Page2.Title");
	clearCookie("Page3.URL");
	clearCookie("Page3.Title");
	clearCookie("Page4.URL");
	clearCookie("Page4.Title");	
}

function clearCookie(name){
		document.cookie = name + "= ;path=/" + ";expires=Thu, 01-Jan-1970 00:00:01 GMT";

}

function formattedPagesVisited(){
	//~un-assigned are empty - or "".  
	var TmpURL = '';
	var TmpTitle = '';
	var ReturnString = '<ul class="zeropaddingUL">';
	for(var ixx=1; ixx<6; ixx++){
		TmpURL = 'Page' + ixx.toString() + '.URL';
		TmpURL = getCookie(TmpURL);
		TmpTitle = 'Page' + ixx.toString() + '.Title';
		TmpTitle = getCookie(TmpTitle);
		if(TmpURL == ""){ 
			ReturnString = ReturnString + '</ul>';
			return(ReturnString); 
		}
		
	var tmpClass = "nobulletlist Type2Detail"; 
 	
	ReturnString = ReturnString + "<li class='" + tmpClass + "'><a class='textlinks recentPages' href='" + TmpURL + "'>" + TmpTitle + "</a></li>";		
	}
	ReturnString = ReturnString + '</ul>';
	return(ReturnString); 
}

function decode(str) {
	return unescape(str.replace(/\+/g," "));
}

// image scroller functions //
	function setupScrollers(){
		setInterval('gallery()', 5000);		
	}

	function gallery(){
		//alert("Gallery");
		if(Running == "True"){
		if(Current == 3) {Current=1;}
			else {Current = Current+1;}
			document.getElementById(CurString).style.visibility = 'hidden';
			CurString = "TopDiv-" + Current.toString();
			document.getElementById(CurString).style.visibility = 'visible';
			}
		//alert(CurString);
		}
					
	function gallerySelect(imageID){
		//CurBottom 
    	document.getElementById(CurString).style.visibility = 'hidden';
		Running = "False";
		clearInterval('gallery()');
		CurString = "TopDiv-" + imageID.toString();
		document.getElementById(CurString).style.visibility = 'visible';
		}
					
	function pause(milliseconds) {
			var dt = new Date();
			while ((new Date()) - dt <= milliseconds) { /* Do nothing */ }
			}

