/* Search Box functionality
----------------------------------------------- */
function searchFocus() { if(document.search.search.value=="Search CIGNA.com") {document.search.search.value="";return false;} }
function searchBlur() { if(document.search.search.value=="") {document.search.search.value="Search CIGNA.com";return false;} }
function searchSubmit() {
		if (document.search.search.value=="Search CIGNA.com") {document.search.search.value="";}
		document.search.submit();
}

/* Toggle for content page tabs
----------------------------------------------- */
function scrollPageToTopOfTab(obj,subtab) {
		var curleft = 0;
		curtop = 0;
		if (obj.offsetParent) {
			curleft = obj.offsetLeft;
			curtop = obj.offsetTop;
			while (obj = obj.offsetParent) {
				curleft += obj.offsetLeft;
				curtop += obj.offsetTop;
			}
		} else {
			curleft = obj.offsetLeft;
			curtop = obj.offsetTop;
		}
		if (subtab) {
			window.scroll(0,curtop - 124);
		} else {
			window.scroll(0,curtop - 50);
		}
}


function switchContentTabs (activeContainerId,tabArray) {
	//var contentTabsIDs = new Array('features', 'estimates', 'other', 'contact_cigna');
	
	if (activeContainerId == "" || tabArray == "") {
		// do nothing 
	}
	else { 
	
	var contentTabsIDs = tabArray;
	for (i = 0; i < contentTabsIDs.length; i++) {
 		document.getElementById(contentTabsIDs[i]).style.display = 'none';
		document.getElementById(contentTabsIDs[i]+"_tab").className = '';
		}
		document.getElementById(activeContainerId).style.display= 'block';
		document.getElementById(activeContainerId+"_tab").className = 'selected';
	
		// set page's tab state 
		document.cookie = document.location+"sessionActiveContainerId="+escape(activeContainerId);
		document.cookie = document.location+"sessionTabArray="+tabArray;
		document.cookie = document.location+"sessionTabbedPageType=basicTabs";
		
		scrollPageToTopOfTab(document.getElementById(activeContainerId+"_tab"), false);

	}

}


/* Toggle for content page sub tabs
----------------------------------------------- */
function switchContentSubTabs (activeContainerSubTabId,subTabArray) {
	
	if (activeContainerSubTabId == "" || subTabArray == "") {
		// do nothing 
	}
	else {	
	
	//var contentSubTabsIDs = new Array('subTab1', 'subTab2', 'subTab3', 'subTab4', 'subTab5');
	var contentSubTabsIDs = subTabArray; 
	for (i = 0; i < contentSubTabsIDs.length; i++) {
 		document.getElementById(contentSubTabsIDs[i]).style.display = 'none';
		document.getElementById(contentSubTabsIDs[i]+"_tab").style.fontWeight='normal';
		document.getElementById(contentSubTabsIDs[i]+"_tab").style.color = '#007DB5';
		}
		document.getElementById(activeContainerSubTabId).style.display= 'block';
		document.getElementById(activeContainerSubTabId+"_tab").style.color= '#4A601C';
  		document.getElementById(activeContainerSubTabId+"_tab").style.fontWeight='bold';
	
		// set page's tab state 
		document.cookie = document.location+"sessionActiveContainerSubTabID="+escape(activeContainerSubTabId);
		document.cookie = document.location+"sessionSubTabArray="+subTabArray;
		document.cookie = document.location+"sessionTabbedPageType=subTabs";
		
		scrollPageToTopOfTab(document.getElementById(activeContainerSubTabId+"_tab"), true);
	}
}


/* Toggle for content page sub tabs and tabs
----------------------------------------------- */
function switchContentTabsNSubTabs(activeContainerTabId,tabArray,subTabArray) {

	if (activeContainerTabId == "" || tabArray == "" || subTabArray == "") {
		// do nothing 
	}
	else {		

	var contentTabsIDs = tabArray;
	for (i = 0; i < contentTabsIDs.length; i++) {
		document.getElementById(contentTabsIDs[i]).style.display = 'none';
		document.getElementById(contentTabsIDs[i]+"_tab").className = '';
		}
		document.getElementById(activeContainerTabId).style.display= 'block';
		document.getElementById(activeContainerTabId+"_tab").className = 'selected';
	
	var contentSubTabsIDs = subTabArray; 
	
	for (i = 0; i < contentSubTabsIDs.length; i++) {
 	
 		document.getElementById(contentSubTabsIDs[i]).style.display = 'none';
		document.getElementById(contentSubTabsIDs[i]+"_tab").style.color = '#666666';
	  document.getElementById(contentSubTabsIDs[i]+"_tab").style.fontWeight='normal';
	 }      
	 	document.getElementById(contentSubTabsIDs[0]).style.display= 'block';   
	  document.getElementById(contentSubTabsIDs[0]+"_tab").style.color= '#4A601C';
    document.getElementById(contentSubTabsIDs[0]+"_tab").style.fontWeight='bold';	
		
		// set page's tab state
		document.cookie = document.location+"sessionActiveContainerId="+escape(activeContainerTabId);
		document.cookie = document.location+"sessionTabArray="+tabArray;
		document.cookie = document.location+"sessionSubTabArray="+subTabArray;
		document.cookie = document.location+"sessionTabbedPageType=LastToFirstTabs";

	}

}

/* get width of browser window's view port
----------------------------------------------- */
getViewportWidth = function() {
  var width = 0;
  if( document.documentElement && document.documentElement.clientWidth ) {
    width = document.documentElement.clientWidth;
  }
  else if( document.body && document.body.clientWidth ) {
    width = document.body.clientWidth;
  }
  else if( window.innerWidth ) {
    width = window.innerWidth - 18;
  }
  return width;
}


/* get fileName of current page
----------------------------------------------- */
getFileName = function() {
	var protocol = window.location.protocol;
	var path = window.location.pathname;
	// this is required because IE loading files locally uses "\" and not "/"
	var separator = (protocol == "file:" && path.indexOf("/", 1) == -1 ? "\\" : "/");
	var path = window.location.pathname;
	var fileName = path.substring(path.lastIndexOf(separator) + 1);
	return fileName;	
}

/* get Referrer page fileName of current page
----------------------------------------------- */
getReferrerFileName = function() {
	
	var path = document.referrer;
	var fileName = path.substring(path.lastIndexOf("/") + 1);
	return fileName;	
}

/* get parameters passed via URL of current page
----------------------------------------------- */
getURLParameters = function() {
	
	var path = location.href;
	var URLParameters = path.substring(path.lastIndexOf("?") + 1);
	return URLParameters;	
}

/* slide the home page header to make sure it is always visible and fixed to the right side of the home page
----------------------------------------------- */
slideheader = function() {
  // if browesr window is less than 984, slide the header to the right edge of the browser
	if ( getViewportWidth() < 984 ) { 
		document.getElementById('header').style.width = (getViewportWidth()-10)+'px'; 
	}
	else {
    // make sure the header is full size
		document.getElementById('header').style.width = '100%' ; 
	}
}



/* open an external CIGNA site from the footer's drop down menu
----------------------------------------------- */
openCIGNAsiteFromFooter = function() {	
	// set how the window should be opened
	wSettings = "width=900,height=700,resizable=yes,scrollbars=yes,location=yes,menubar=yes,toolbar=yes,status=yes,top=50,left=50";
	
	// get the selected drop down option
	whichSite = document.getElementById('footerSiteSelector').value;
	
	// open or focus the appropriate window
	switch (whichSite)
	{
	case (whichSite = "1"): 
		wHref = "http://my.cigna.com";
		wTarget = "mycigna";	
	break
	
	case (whichSite = "2"):
		wHref = "https://cignaaccess.cigna.com/";
		wTarget = "cignaaccess";	
	break
	
	case (whichSite = "3"):
		wHref = "http://www.cigna.com/cgi-bin/secure_link.pl?site=portalProvider&url=/";
		wTarget = "cignaforhcp";	
	break
	
	case (whichSite = "4"):
		wHref = "http://www.cignabehavioral.com/";
		wTarget = "cignabehavioral";	
	break
	
	case (whichSite = "5"):
		wHref = "http://www.cignaturerx.com";
		wTarget = "cignaturerx";	
	break
	
	case (whichSite = "6"):
		wHref = "http://ciebinq.intl.cigna.com/gateway.html";
		wTarget = "cignainternational";	
	break
	
	case (whichSite = "7"):
		wHref = "http://www.cignaseniorsaz-rx.com/";
		wTarget = "cignamapd";	
	break
	
	case (whichSite = "8"):
		wHref = "/cmgaz/cmgaz.html";
		wTarget = "cmgaz";	
	break
	
	default:
		// do nothing
	break
	} 	

  // open the window
	newWin = window.open(wHref, wTarget, wSettings);
	newWin.focus();
	return false;

}

/* open a PDF from the Member's Forms page
----------------------------------------------- */
openPharamcyPDF = function() {	
	// set how the window should be opened
	wSettings = "width=900,height=700,resizable=yes,scrollbars=yes,location=yes,menubar=yes,toolbar=yes,status=yes,top=50,left=50";
	wTarget = "pdfWindow";
	
	// get the selected drop down option
	whichForm = document.getElementById('pdfFormSelector').value;
	
	// open or focus the appropriate window
	switch (whichForm)
	{
	case (whichForm = "0"): 
		return false;
	break	
			
	case (whichForm = "1"): 
		wHref = "/pdf/Pharmacy_antifungal.pdf";
	break
	
	case (whichForm = "2"):
		wHref = "/pdf/Pharmacy_coxII.pdf";
	break
	
	case (whichForm = "3"):
		wHref = "/pdf/Pharmacy_Proton_Pump_Inhib.pdf";
	break
	
	case (whichForm = "4"):
		wHref = "/pdf/Pharmacy_erectile_dysfunction.pdf";
	break
	
//	case (whichForm = "5"):
//		wHref = "/pdfs/xxx.pdf";
//	break
	
	case (whichForm = "6"):
		wHref = "/pdf/Pharmacy_dacon.pdf";
	break

	case (whichForm = "7"):
		wHref = "/pdf/Pharmacy_general_injectable.pdf";
	break
	
	case (whichForm = "8"):
		wHref = "/pdf/Pharmacy_blood_modifier.pdf";
	break

	case (whichForm = "9"):
		wHref = "/pdf/Pharmacy_chronic_plaque_psoriasis.pdf";
	break
	
	case (whichForm = "10"):
		wHref = "/pdf/Pharmacy_febrile_neutropenia.pdf";
	break
	
	case (whichForm = "11"):
		wHref = "/pdf/Pharmacy_fuzeon.pdf";
	break	

	case (whichForm = "12"):
		wHref = "/pdf/Pharmacy_growth_hormones.pdf";
	break	

	case (whichForm = "13"):
		wHref = "/pdf/Pharmacy_hemophilia_injectable.pdf";
	break	

	case (whichForm = "14"):
		wHref = "/pdf/Pharmacy_hepatitis_c.pdf";
	break	

	case (whichForm = "15"):
		wHref = "/pdf/Pharmacy_infertility.pdf";
	break	

	case (whichForm = "16"):
		wHref = "/pdf/Pharmacy_joint_degeneration.pdf";
	break	

	case (whichForm = "17"):
		wHref = "/pdf/Pharmacy_lovenox.pdf";
	break	
	
	case (whichForm = "18"):
		wHref = "/pdf/Pharmacy_lupron.pdf";
	break	

	case (whichForm = "19"):
		wHref = "/pdf/Pharmacy_multiple_sclerosis.pdf";
	break	

	case (whichForm = "20"):
		wHref = "/pdf/Pharmacy_oncology.pdf";
	break	

	case (whichForm = "21"):
		wHref = "/pdf/Pharmacy_remicade.pdf";
	break	

	case (whichForm = "22"):
		wHref = "/pdf/Pharmacy_rheumatoid_arthritis.pdf";
	break	

	case (whichForm = "23"):
		wHref = "/pdf/Pharmacy_synagis.pdf";
	break	

	case (whichForm = "24"):
		wHref = "/pdf/Pharmacy_xolair.pdf";
	break	

	case (whichForm = "25"):
		wHref = "/pdf/Pharmacy_high_risk_maternity.pdf";
	break	

	default:
		// do nothing
	break
	} 	

  // open the window
	newWin = window.open(wHref, wTarget, wSettings);
	newWin.focus();
	return false;

}


/* navigate to a Our Plans or Health&Money landing 2 page via dual drop down menu
----------------------------------------------- */
gotoLandingPage = function() {	
	
	// get the two selected drop down options
	whichView = document.getElementById('viewSelection').value;
	whichFor = document.getElementById('forSelection').value;

	//fix 'n/a' pages in "Our Plans" 
	if (whichView == "/our_plans/international/" && whichFor =="unions.html") { 
		document.location = "/our_plans/international/index.html"; 
		return false; }
		
	if (whichView == "/our_plans/vision/" && whichFor =="unions.html") { 
		document.location = "/our_plans/vision/index.html"; 
		return false; }
		
	if (whichView == "/our_plans/disability/" && whichFor =="unions.html") { 
		document.location = "/our_plans/disability/index.html"; 
		return false;	}
		
	if (whichView == "/our_plans/accident/" && whichFor =="unions.html") { 
		document.location = "/our_plans/accident/index.html"; 
		return false;	}		
		
	if (whichView == "/our_plans/life/" && whichFor =="unions.html") { 
		document.location = "/our_plans/life/universal/unions.html"; 
		return false;	}
		
	//fix 'n/a' pages in "Health & Money" 
	if (whichView == "/health_money/atoz/") { 
		document.location = "/healthinfo/atozlist/ht/index.html"; 
		return false; }	

  // naviagte to selected page
	document.location = whichView+whichFor;
				
	return false;

}

/* for tabbed pages, sve state when displaying a tab, then later check cookies to see if state needs to be updated. session only.
----------------------------------------------- */
function checkPageState() 
{
	
	// first check if cookie for this page even exists, if not, exit
	if (document.cookie.indexOf(document.location) == -1 ) {
		return false;	
	}
	
	var sessionTabbedPageTypeValue="";
	var sessionActiveContainerSubTabIDValue="";
	var sessionActiveContainerIDValue=""; 
	var sessionTabArrayValue="";
	var sessionSubTabArrayValue="";
		
	// first get any page states from document cookie, one by one
	allCookies = document.cookie;
	allCookies = allCookies.substring(allCookies.indexOf(document.location),allCookies.length);
	pos = allCookies.indexOf("sessionTabbedPageType=")
  if (pos != -1){
		start = pos + 22;  // start of cookie value
		end = allCookies.indexOf(";", start);  // end of cookie value
		if (end == -1) end = allCookies.length;
		sessionTabbedPageTypeValue = allCookies.substring(start,end); // extract the value
		sessionTabbedPageTypeValue = unescape(sessionTabbedPageTypeValue);
	}
	
	pos = allCookies.indexOf("sessionActiveContainerSubTabID=")
  if (pos != -1){
		start = pos + 31;  // start of cookie value
		end = allCookies.indexOf(";", start);  // end of cookie value
		if (end == -1) end = allCookies.length;
		sessionActiveContainerSubTabIDValue = allCookies.substring(start,end); // extract the value
		sessionActiveContainerSubTabIDValue = unescape(sessionActiveContainerSubTabIDValue);
	}
		
	pos = allCookies.indexOf("sessionActiveContainerId=")
  if (pos != -1){
		start = pos + 25;  // start of cookie value
		end = allCookies.indexOf(";", start);  // end of cookie value
		if (end == -1) end = allCookies.length;
		sessionActiveContainerIDValue = allCookies.substring(start,end); // extract the value
		sessionActiveContainerIDValue = unescape(sessionActiveContainerIDValue);
	}

	pos = allCookies.indexOf("sessionTabArray=")
  if (pos != -1){
		start = pos + 16;  // start of cookie value
		end = allCookies.indexOf(";", start);  // end of cookie value
		if (end == -1) end = allCookies.length;
		sessionTabArrayValue = allCookies.substring(start,end); // extract the value
		sessionTabArrayValue = unescape(sessionTabArrayValue);
	}
	
	pos = allCookies.indexOf("sessionSubTabArray=")
  if (pos != -1){
		start = pos + 19;  // start of cookie value
		end = allCookies.indexOf(";", start);  // end of cookie value
		if (end == -1) end = allCookies.length;
		sessionSubTabArrayValue = allCookies.substring(start,end); // extract the value
		sessionSubTabArrayValue = unescape(sessionSubTabArrayValue);
	}	
	
	
	// now that we have the cookies, see if we need to reset the tab state
  if (sessionTabbedPageTypeValue != "") { 

		// basic tab page
		 if (sessionTabbedPageTypeValue == "basicTabs") {
			 if (sessionActiveContainerIDValue != "" && sessionTabArrayValue != "") {
					activeContainerId = sessionActiveContainerIDValue;
					tabArray = sessionTabArrayValue;
					//update the page
					switchContentTabs(activeContainerId,tabArray.split(','));
					}
			 }
			
		else if (sessionTabbedPageTypeValue == "subTabs") {
			if (sessionActiveContainerIDValue != "" && sessionTabArrayValue != "" && sessionActiveContainerSubTabIDValue != "" && sessionSubTabArrayValue != "") { 
				  // first go to the right tab
				  activeContainerId = sessionActiveContainerIDValue;
					tabArray = sessionTabArrayValue;
					subTabArray = sessionSubTabArrayValue;
					//update the page
					switchContentTabsNSubTabs(activeContainerId,tabArray.split(','),subTabArray.split(','));
					
					// then set the right sub tab			
					activeContainerSubTabId = sessionActiveContainerSubTabIDValue;
					subTabArray = sessionSubTabArrayValue; 	
					//update the page
					switchContentSubTabs(activeContainerSubTabId,subTabArray.split(','));					
					}
			 }
			
		else if (sessionTabbedPageTypeValue == "LastToFirstTabs") {		
			if (sessionActiveContainerIDValue != "" && sessionTabArrayValue != "" && sessionActiveContainerSubTabIDValue != "" && sessionSubTabArrayValue != "") {
				  // first go to the right tab
				  activeContainerId = sessionActiveContainerIDValue;
					tabArray = sessionTabArrayValue;
					subTabArray = sessionSubTabArrayValue;
					//update the page
					switchContentTabsNSubTabs(activeContainerId,tabArray.split(','),subTabArray.split(','));
					
					// then set the right sub tab			
					activeContainerSubTabId = sessionActiveContainerSubTabIDValue;
					subTabArray = sessionSubTabArrayValue; 
					//update the page
					switchContentSubTabs(activeContainerSubTabId,subTabArray.split(','));
				  }
			  }
	    }
		else {
			return false;
		}
}

