//------------- Cookie Functions-------------------//
function readCookie(name) 
{
	var nameEQ=name+"=";
	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 null;
}

function setCookie(name,value,expires,path,domain,secure) {
    document.cookie = name + "=" +escape(value) +
        ( (expires) ? ";expires=" + expires.toGMTString() : "") +
        ( (path) ? ";path=" + path : "") +
        ( (domain) ? ";domain=" + domain : "") +
        ( (secure) ? ";secure" : "");

}

function setiscCookie(name,value,expires,path,domain,secure) {
	var expdate = new Date();
		expdate.setTime(expdate.getTime() + expires *24*60*60*1000);


    document.cookie = name + "=" +escape(value) +
        ( (expires) ? ";expires=" + expdate.toGMTString() : "") +
        ( (path) ? ";path=" + path : "") +
        ( (domain) ? ";domain=" + domain : "") +
        ( (secure) ? ";secure" : "");
}

//------------- Cookie Functions-------------------//

//------------- Global Nav Functions-------------------//
function isLoggedIn()
{
	var type = readCookie("LCTSessionCookie");
	return (type!=null);
}

function loginRedirect(redirectURL) {
	layer="contentBody";
	var viewAs = readCookie("VIEW_AS");

	url = "https://"+location.host+"/LincolnPageServer?KPage_PageID=VIEW_LOGIN&KPage_Action=DISPLAY&LFGPage=/lfg/" + viewAs + "/secure.html";

	if (null != redirectURL)
	{
		url += "&redirectURL=" + redirectURL;
	}

	location.href = url;
}

function login(lfgPage) {
	var viewAs = readCookie("VIEW_AS");

	if(lfgPage == null) lfgPage = "/lfg/" + viewAs + "/secure.html";
	url = "https://"+location.host+"/LincolnPageServer?KPage_PageID=VIEW_LOGIN&KPage_Action=DISPLAY&LFGPage="+lfgPage;
	location.href = url;
}

function logout(lfgPage) {
	setCookie("acct", "null","","/","","");
	var viewAs = readCookie("VIEW_AS");
	if(lfgPage == null) lfgPage = "/lfg/" + viewAs + "/secure.html";

	url = "https://"+location.host+"/LincolnPageServer?KPage_PageID=VIEW_LOGIN&KPage_Action=LOGOUT&LFGPage="+lfgPage;
	location.href = url;
}

function editProfile(lfgPage) {
	var viewAs = readCookie("VIEW_AS");
	if(lfgPage == null) lfgPage = "/lfg/" + viewAs + "/secure.html";

	url = "https://"+location.host+"/LincolnPageServer?KPage_PageID=VIEW_EDIT_PROFILE&KPage_Action=DISPLAY&LFGPage="+lfgPage;
	location.href = url;
}

function register(lfgPage) {
	var viewAs = readCookie("VIEW_AS");
	if(lfgPage == null) lfgPage = "/lfg/" + viewAs + "/secure.html";

	url = "https://"+location.host+"/LincolnPageServer?KPage_PageID=VIEW_REGISTRATION&KPage_Action=DISPLAY&LFGPage="+lfgPage;
	location.href = url;
}

function contact() {
	contactUs(Contact_XML);
}

function contactUs(url, lfgPage) {
	if(lfgPage == null) lfgPage = "/lfg/" + viewAs + "/blank.html";
	var pageURL = "/LincolnPageServer?LFGPage="+lfgPage+"&KURL="+url+"&ARG_ARRAY="+url;

	location.href=pageURL;
}
function findAnAdvisor(){
	var viewAs = readCookie("VIEW_AS");
	var loc="/lfg/"+viewAs+"/cus/reqinfo/index.html";
	//url="/LincolnPageServer?KURL=/lfg/uni/cus/frm/content.xml&ARG_ARRAY=/lfg/uni/cus/frm/content.xml&LFGPage=/lfg/"+viewAs+"/global/blank/index.html";
	//if(viewAs=="ipc"||viewAs=="lfgclient"||viewAs=="ind")
	//	url = "/LincolnPageServer?LFGPage=/lfg/"+viewAs+"/cus/req/index.html";
	location.href = loc;
}
function openExternalWindow(url) {
	var height="540";
	var width="675";

	if(viewAs=="ipc"||viewAs=="ind"||viewAs=="lfgclient"||viewAs=="emrp"){
		height="480";
		width="640";
	}
	if (url) {
		openExtWindow('/lfg/'+ viewAs +'/bum/redirect.html?URL='+escape(url),'newWin','outerWidth='+ width + ',outerHeight=' + height + ',height='+height+' width=' + width);
	}
}

function openHTMLSiteMapWindow(audience, popUp)
{
	lfgPage = "/lfg/uni/smp/smp.html";
	url = "/LincolnPageServer?LFGPage="+lfgPage+"&audience=" + audience;
	if(popUp == false)
		location.href=url;
	else
		openExtWindow(url, "sitemap", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=740,height=650");
}

function openSluxSiteMapWindow(audience, popUp)
{
   /* removed the open window functionality, SLUX-708 */
	lfgPage = "/lfg/"+audience+"/sitemap.html";
	url = "/LincolnPageServer?LFGPage="+lfgPage+"&audience=" + audience;
   location.href=url;
}
function openHTMLSiteMap(audience, lfgPage){
	if(lfgPage == null) lfgPage = "/lfg/" + audience + "/blank.html";
	location.href="/LincolnPageServer?LFGPage=" + lfgPage + "&audience=" + audience + "&url=/lfg/uni/smp/&LFGComponentID=sitemap";
}

function openNewCompaniesWindow(){


var lfgpage = "";
	if(viewAs=="ipc" || viewAs=="ind" || viewAs=="lfgclient" || viewAs=="emrp")
		lfgpage = "/lfg/uni/slux/blank.html";
	else lfgpage="/lfg/uni/gls/index.html";
var link ="/LincolnPageServer?LFGPage="+lfgpage+"&KURL=/lfg/lfgclient/mis/exp/content.xml&ARG_ARRAY=/lfg/lfgclient/mis/exp/content.xml"
	openExtWindow(link, "companies", "height=650 width=740,screenX=10,screenY=5,top=10,left=5,toolbar=no,menubar=no,scrollbars=yes,resizable=yes")
}

function openNewSiteMapWindow(){


	openExtWindow("/lfg/uni/smp/who/index.html", "companies", "height=650 width=740,screenX=10,screenY=5,top=10,left=5,toolbar=no,scrollbars=yes,resizable=yes")
}

function openFAQsWindow(){
	openExtWindow('/lfg/llc/uni/faq/index.html','faqs','scrollbars=yes,width=700,height=550, resizable=yes');
}

function openGlossaryWindow(){
	openExtWindow('/lfg/llc/uni/glo/index.html','glossary','scrollbars=yes,width=700,height=550, resizable=yes');
}

function saveFavoriteDoc(title, url, replace) {
	var lfgpage = "";
	if( viewAs=="ind" || viewAs=="lfgclient")
		lfgpage = "/lfg/lfgclient/favorites/blank.html";
	else lfgpage="/lfg/uni/favorites/index.html";

    var link = "/LincolnPageServer?LFGPage="+lfgpage+"&LFGComponentID=xwork&xworkNamespace=favorites&dataKey=favoriteDocs&"+
                "xworkAction=view-add-favorites&isPopup=true&linkTitle="+escape(title)+"&url="+escape(url);
    if (replace != null) {
        link=link+"&replace="+replace
    }
    openExtWindow(link, 'favorites', 'scrollbars=yes,width=500,height=300, resizable=no');
    return false;
}
function saveFavoritePage(title, url, replace) {
    if(url.indexOf("content.xml")!=-1){
    	url = url.replace("content.xml", "index.html");

    }

    if( viewAs=="ind" || viewAs=="lfgclient" || viewAs=="emrp")
		lfgpage = "/lfg/lfgclient/favorites/slux/blank.html";
	else lfgpage="/lfg/uni/favorites/index.html";


    var link = "/LincolnPageServer?LFGPage="+lfgpage+"&LFGComponentID=xwork&xworkNamespace=favorites&dataKey=favoriteDocs&"+
                "xworkAction=view-add-favorites&isPopup=false&viewAs=" + viewAs + "&linkTitle="+escape(title)+"&url="+escape(url);
    if (replace != null) {
        link=link+"&replace="+replace
    }
    openExtWindow(link, 'favorites', 'scrollbars=yes,width=450,height=300, resizable=no');
    return false;
}
function openFavoriteDoc(favorite) {

    var url = favorite.options[favorite.selectedIndex].value;
    if (url) {
        openExtWindow(url, 'doc', 'scrollbars=yes,width=700,height=550, resizable=yes');
    }
    return false;
}

function manageFavorites(navPage) {
	if(navPage == null) navPage = "/lfg/" + viewAs + "/blank.html";

	url = "https://"+location.host+"/LincolnPageServer?LFGComponentID=xwork&xworkNamespace=favorites&"+
	        "xworkAction=view-favorites&dataKey=favoriteDocs&LFGPage="+navPage;
	location.href = url;
}

//------------- Global Nav Functions-------------------//

//------------- Image Functions-------------------//
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//------------- Image Functions-------------------//

//------------- Layer Functions-------------------//
var prevL1Lyr, prevL1OverLyr, prevL2OverLyr = null;
function layerOverHandler(n, lyrL1, lyrL1Over, lyrL2Over)
{
	if (is.ns4)
	{
		x = lyrL1.getRelativeX() - lyrParentDiv.getRelativeX();
	}
	else
	{
		x = 0;
		if (n > 1)
		{
			for(i=1; i<n; i++)
			{
				if (is.ie)
					isLyr = (document.all["lyr" + i] != null);
				else
					isLyr = (document.getElementById("lyr" + i) != null);

				if(isLyr){
					tempLyr = eval("lyr" + i + "Div" )
					x = x + tempLyr.w;
				}
			}
		}
	}
	if (lyrL1Over != null) lyrL1Over.moveTo(x, 0);
	if (lyrL2Over != null) lyrL2Over.moveTo(171, 65);

	hideLyr();
	showLyr(lyrL1, lyrL1Over, lyrL2Over);
}

function layerOutHandler()
{
	hideLyr();
}

function showLyr(lyrL1, lyrL1Over, lyrL2Over)
{

	if (prevL2OverLyr != null) prevL2OverLyr.hide();
	if (prevL1OverLyr != null) prevL1OverLyr.hide();
	if (prevL1Lyr != null) prevL1Lyr.show();

	prevL1Lyr	= lyrL1;
	prevL1OverLyr	= lyrL1Over;
	prevL2OverLyr	= lyrL2Over;

	if (prevL1Lyr != null) prevL1Lyr.hide();
	if (prevL1OverLyr != null) prevL1OverLyr.show();
	if (prevL2OverLyr != null) prevL2OverLyr.show();
}

function hideLyr()
{

	if (prevL1Lyr != null) prevL1Lyr.show();
	if (prevL1OverLyr != null) prevL1OverLyr.hide();
	if (prevL2OverLyr != null) prevL2OverLyr.hide();

	prevL1Lyr	= null;
	prevL1OverLyr	= null;
	prevL2OverLyr	= null;
}



function checkLyr(bln, timeout, func)
{
	eval(timeout + " = window.setTimeout('if(" + bln + "==false){" + func + ";window.clearTimeout(" + bln + ");}', 800)");
	eval(timeout + " = 0;")
}

function showMouseOverText(e, text, size, bordercolor, bgcolor, styleClass, position) {
	var txtBoxLayer = new DynLayer("MouseOverTxtBox");
    if(is.ns4) {
    	x  = e.pageX;
        y  = e.pageY;
    } else {
    	x  = document.body.scrollLeft + e.clientX;
        y  = document.body.scrollTop + e.clientY;
    }

    if(size == null || size == "") size = "300";
    if(bordercolor == null || bordercolor == "") bordercolor = "#000000";
    if(bgcolor == null || bgcolor == "") bgcolor = "#FFFFDD";
    if(styleClass == null || styleClass == "") styleClass = "tableText";

    text = '<table width="'+size+'" border="0" bgcolor="'+bordercolor+'" cellpadding="1" cellspacing="0"><tr><td><table width="100%" border="0" bgcolor="'+bgcolor+'" cellpadding="3" cellspacing="0"><tr><td class="'+styleClass+'">' + text + '</td></tr></table></td></tr></table>';
    txtBoxLayer.write(text);

    x = x + 5;
    if(position != null){
    	if(position == "bottom"){
    		txtBoxLayer = new DynLayer("MouseOverTxtBox");
    		y = y - txtBoxLayer.h - 2;
    	} else {
    		y = y + 2;
    	}
    }

    txtBoxLayer.moveTo(x, y);
    txtBoxLayer.show();

}
function hideMouseOverText() {
	var txtBoxLayer = new DynLayer("MouseOverTxtBox");
    txtBoxLayer.hide();
}

//------------- Layer Functions-------------------//

//------------- Other Functions-------------------//
function openTimeZoneWindow()
{
	var url = "/LincolnPageServer?KURL=/lfg/uni/tim/content.xml&ARG_ARRAY=/lfg/uni/tim/content.xml&LFGPage=/lfg/uni/slux/blank.html";

	window.open(url,'','height=560, width=450, scrollbars=yes, resizable=no, menubar=no, toolbar=no');
}


var messageMaxCount = 10;
function messageAlert(msg,id)
{
	var client = "/";
	if(viewAs!=null && (viewAs=="leg"||viewAs=="adv"))
		client += "leg/";
	var val = readCookie(id);
	var count = readCookie(id+"Count");
	if(count == null)
		count = 0;
	else
		count = parseInt(count);

	msg = escape(msg);
	if((val == null || val == "yes")&&(count<=messageMaxCount))
		openExtWindow('/lfg/admin/msg'+client+'messagealert.html?msg='+msg+'&id='+id,id,'width=350,height=400,resizable=yes');
}

function openExtWindow(url,name,features){
	var extWin = window.open(url,name,features);
	//extWin.focus();
}
function printerFriendlySplash(){
	var url = location.href;


	var newurl = "LFGPage=/lfg/uni/prt/slux/PrinterFriendlyWrapper.html";
	var fragment = url.indexOf("LFGPage");
	var temp = url.substring(0,fragment);
	var lfgpage = url.substring(fragment,url.lastIndexOf("index.html"));
	lfgpageInd = lfgpage.lastIndexOf("=");
	lfgpage = lfgpage.substring(lfgpageInd,lfgpage.lastIndexOf("/"));
	var testurl = temp + newurl + "&KURL" + lfgpage + "/content.xml";
	openExtWindow(testurl,'printer','height=600 width=740, screenX=10,screenY=5, top=10,left=5, menubar=yes, toolbar=yes, scrollbars=yes, resizable=yes');
}

function printerFriendly()
{
	var url = location.href;
	var printerURL = url;


	actInd = url.indexOf("KPage_Action");
	alreadyPrinterFriendly = url.indexOf("PRINTER_FRIENDLY");
	
	if (alreadyPrinterFriendly == -1)
	{
		fragment = url.lastIndexOf("#"); 
		if (fragment != -1) 
		{ 
			url = url.substring(0,fragment);
		}
		 
		if (actInd != -1)
		{
		  endInd = url.indexOf("&", actInd);
		  if (endInd == -1)
		      endInd = url.length();
		  printerURL = url.substring(0,actInd) + "KPage_Action=PRINTER_FRIENDLY"
		          + url.substring(endInd);
		}
		else
		{
			qInd = url.indexOf("?");
			if (qInd < 0 )
				printerURL = url + "?KPage_Action=PRINTER_FRIENDLY";
			else
				printerURL = url + "&KPage_Action=PRINTER_FRIENDLY";
		}
	  
		openExtWindow(printerURL,  'printer', 'height=600 width=740, screenX=10,screenY=5, top=10,left=5, menubar=yes, toolbar=yes, scrollbars=yes, resizable=yes');
	}
}

function go()
{

	level1 = document.audienceForm.views.options[document.audienceForm.views.selectedIndex].value;
	window.parent.location.href = "/LincolnPageServer?LFGPage=/lfg/" + level1 + "/index.html";
}

var errorTitles = new Array(1);
errorTitles[0] = "An error was encountered processing your request";

var errorMsgs = new Array(1);
errorMsgs[0] = "Please click <a href=\"javascript:history.back()\">here</a> to return to the previous page.";
	
function getErrorTitle(index){
	if(index < errorTitles.length)
		return errorTitles[index];
	else
		return 0		
}

function getErrorMsg(index){
	if(index < errorMsgs.length)
		return errorMsgs[index];
	else
		return 0		
}

var useWrapperPage = "";
function emailDocToFriend(url,lfgPage){	
	url = "/LincolnPageServer?LFGComponentID=xwork&xworkNamespace=emaildoc&xworkAction=view-email-doc-form&url="+url;
	
	if(useWrapperPage != ""){
		lfgPage = useWrapperPage;	
	}
	if(lfgPage != ""){
		url = url + "&LFGPage=" + lfgPage;		
	}
	location.href=url;		
}

//------------- Other Functions-------------------//


var warningTime;
var timeout;
var timeMsg = "30";

function prepareAutoLoggoff(audience) {
    if(("who" != audience) && ("lfdbd" != audience) && ("lfgclient" != audience)) {

        warningTime = 1680000; //28 minutes in milliseconds

        if ("lfns" == audience) {
            warningTime = 3480000; //58 minutes
            timeMsg = "60";
        }

        timeout = warningTime + 120000;  // plus 2 minutes

        if (isLoggedIn && !hasAutoCookie())
        {
            logoffWindowId = window.setTimeout("showLogoffPopup()", warningTime);   //28 minutes
            logoffActionId = window.setTimeout("logout()", timeout);            //30 minutes
        }

   	}
}

function showLogoffPopup()
{
	var msg = "Your current session is about to expire.  For your security, sessions automatically end after " + timeMsg + " minutes of inactivity.  This helps prevent possible breaches of security if you forgot to log out.\n\n";
	msg = msg + "Your current session will expire in 2 minutes.\n\n";
	msg = msg + "If you would like to continue your session, please select OK\n\n";
	msg = msg + "If you would like to log off now, please select the Cancel button.";

	var startTime = new Date().getTime();

	if (confirm(msg))
	{
		var endTime = new Date().getTime();
	    if ( endTime - startTime > 120000) { // the 2 minutes have expired so call logout
	        logout();
	    } else {
            window.clearTimeout(logoffActionId);
            logoffWindowId = window.setTimeout("showLogoffPopup()", warningTime);
            logoffActionId = window.setTimeout("logout()", timeout);
   		}
	}
	else
	{
		logout();
	}
}

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

function hasAutoCookie() {
	var type = readCookie("AL");
	return (type!=null);
}

