var whaleCacheClean;
GetCacheCleanInstance();

var gracePeriod = 120;

var sessionDelta = 60000;
var sessionTimeout = 300000 - sessionDelta;
var scheduledLogoff = 3600;
var bMonitorDomain = false;
var bForceBrowser = false;
var bUseAuth = -1;
var NAPStatus = -1;
var whlClientMode = 0;
//to prevent NAN params
try
{
	sessionDelta = jsNotificationTimeout;
	sessionTimeout = jsSessionTimeout - sessionDelta;
	scheduledLogoff = jsScheduledLogoffTimer;
	bMonitorDomain = jsbMonitorDomain;
	bForceBrowser = jsbForceBrowser;
	bUseAuth = jsbUseAuth;
	NAPStatus = jsNAPStatus;
	whlClientMode = jsWhlClientMode;
}
catch(e)
{}

if (typeof(isUAGportal) == 'undefined')
	isUAGportal = false;
var bHandleScheduledLogoff = true
if (bUseAuth != -1 || scheduledLogoff == 0)
	bHandleScheduledLogoff = false;

var refreshSessionTimeStamp = 0;

var schedRunning = false;
var theCounter;

var expiredDate = new Date("1/1/1980")
var expiredDateGMT = expiredDate.toGMTString()

var sessionTimeoutURL = jsOwnURL  + "SessionTimeout.asp";
var scheduledLogoffURL = jsOwnURL  + "ScheduledLogoff.asp";

var bHandleSessionTimeoutCalled = false;
var bSessionTimeoutAlert = false;
var bScheduledLogoffAlert = false;

//for popup blockers
var popupOpened = false;

//Periodic Detection parameters
var refreshRate = 5;	// Periodic detection polling (seconds)
var dwTimestamp = 0;
var oldTimestamp = 0;
var bFirstLoad = true;
var dwLastDetectionTimestamp = 0;

var getNonce = "";
var addCustomDetectionScripts = "";
var getNumbersDecimalSymbol = "";

//get NLSession cookie value for the case of working with multiple sessions
var sSecure = "S";
if (secure != 1)
	sSecure = "";
var origCookie = getCookie("NLSession" + sSecure + siteName);

if (getCookie("dwLastDetectionTimestamp") == null)
{
	var d = new Date();
	//set session start time as first detection time
	sLastDetectionTimeStamp = d.getFullYear() + "," + d.getMonth() + "," + d.getDate() + "," + d.getHours() + "," + d.getMinutes() + "," + d.getSeconds() + ",0";	
	document.cookie = "dwLastDetectionTimestamp=" + sLastDetectionTimeStamp + "; path=/;";
}

var whaleEndpointDetectorClient = null;
//For adding detection.js dynamically
detectionScriptLoaded = 0;

//saving original window title in a cookie to re-set it after session timeout / scheduled logoff
if (getCookie("WhlWinTitle") == null)
{
	try
	{
		document.cookie = "WhlWinTitle=" + escape(window.top.document.title) + "; path=/;";
	}
	catch(e)
	{
		document.cookie = "WhlWinTitle=" + escape(window.parent.document.title) + "; path=/;";
	}
}
else
{
	try
	{
		window.top.document.title = getCookie("WhlWinTitle");
	}
	catch(e)
	{
		window.parent.document.title = getCookie("WhlWinTitle");
	}
}

function preSchedCountdown()
{	
	try
	{
		theCounter = document.getElementById("timer");
		schedCountdown();
	}
	catch(e)
	{
		scheduledLogoff -= 1;
		window.setTimeout("preSchedCountdown()", 1000);
	}
}

function schedCountdown()
{	
	if(scheduledLogoff <= 0)
	{
		theCounter.innerHTML = "00:00:00";
		try
		{
			schedLogoff();
		}
		catch(e)
		{
		}
	}
	else
	{
		var t_time = scheduledLogoff;
		var hours_left = Math.floor(scheduledLogoff/3600);
		t_time -= hours_left*3600;
		var minutes_left = Math.floor(t_time/60);
		t_time -= minutes_left*60;
		var seconds_left = Math.floor(t_time);

		if(seconds_left < 10)
		   seconds_left = "0" + seconds_left;

		if(minutes_left < 10)
		   minutes_left = "0" + minutes_left;

		if(hours_left < 10)
		   hours_left = "0" + hours_left;

		strMessage = hours_left + ":" + minutes_left + ":" + seconds_left;
		if (!(isNaN(hours_left) || isNaN(minutes_left) || isNaN(seconds_left)))
		{
			theCounter.innerHTML = strMessage;
		}
		else
		{
			handleScheduledLogoff();
		}
		
		scheduledLogoff -= 1;
		window.setTimeout("schedCountdown()", 1000);
	}
}

function timerFunc()
{		
	if (!bSessionTimeoutAlert && !bScheduledLogoffAlert)
	{
		bSessionTimeoutAlert = true;
		SetTimeoutForCacheClean(sessionDelta/1000);
		window.focus();
		openDialogWin(sessionTimeoutURL);
	}
}

function schedLogoff()
{	
	if (!bSessionTimeoutAlert && !bScheduledLogoffAlert)
	{
		window.focus();
		//ADFS - upon scheduled logoff, instead of re-login, logoff.
		if (isADFS == "True" || isADFSv2 == "True")	
			endSession("SCHEDULED_LOGOFF");
		else
		{
			bScheduledLogoffAlert = true;	
			openDialogWin(scheduledLogoffURL);
		}
	}
}

try
{
	var hostName =  window.top.location.hostname;
}
catch(e)
{
	var hostName =  window.parent.location.hostname;
}

function oldTimerFunc()
{
	start = new Date();
	window.focus();
	var bOK = window.confirm(strSessionTimeoutConfirm1 + " \"" + hostName + "\" " + strSessionTimeoutConfirm2);
	end = new Date();
	end -= start;
	//enable re-alert session timeout
	bHandleSessionTimeoutCalled = false;
	if (end.valueOf() >= sessionDelta)
	{
		setReasonCookie("SESSION_TIMEOUT", 60*60*1000);
		ActivateCacheClean(jsLogoffMsg + "?site_name=" + siteName + "&secure=" + secure);
		return;
	}
	if (bOK)
		refreshSession();
	else
		endSession("SESSION_TIMEOUT");
}

function oldSchedLogoff()
{
	start = new Date();
	window.focus();
	clearTimeout(sessionTimeoutTimeout);
	var bOK = window.confirm(strSchedLogoffConfirm1 + " \"" + hostName + "\".\n" + strSchedLogoffConfirm2);
	end = new Date();
	end -= start;
	if (end.valueOf() >= sessionDelta)
	{
		setReasonCookie("SCHEDULED_LOGOFF", 60*60*1000);
		ActivateCacheClean(jsLogoffMsg + "?site_name=" + siteName + "&secure=" + secure);
		return;
	}
	if (bOK)
	{
		gotoRelogin();
	}
	else
		endSession("SCHEDULED_LOGOFF");
}

function getCookie(sName)
{	
	var aCookie = document.cookie.split("; ");
	for (var i=0; i < aCookie.length; i++)
	{
		var aCrumb = aCookie[i].split("=");
		if (sName == aCrumb[0])
			return unescape(aCrumb[1]);
	}
	return null;
}

function handleScheduledLogoff()
{
    //Nullify WhlLogoffReasonCookie
    setReasonCookie("", -60*60*1000);
    
    setOriginalWinTitle();
    
	if (bHandleScheduledLogoff)
	{
		var time = getCookie("WhlSL");
		if (time != null)
			scheduledLogoff = time / 1000;
		else //WhlSL cookie is null. call RefreshSession() to get it again.
		{
			refreshSession();
			return;
		}
		document.cookie = "WhlSL=" + "; expires=" + expiredDateGMT + "; path=/;";
		
		if (scheduledLogoff > 0)
		{
			SetTimeoutForCacheClean(scheduledLogoff + gracePeriod);
			//only on when there's a schedule countdown clock
			if(isUAGportal === true)
			{
				if (schedRunning == false)
				{
					schedRunning = true;
					preSchedCountdown();
				}
			}
			else
				window.setTimeout("schedLogoff()", scheduledLogoff*1000);
		}
	}	
	activateCompareTimeStamps();
}

function handleSessionTimeout()
{	
	var sslVpnStatus = 0;
	try 
	{
		Control = new ActiveXObject("WhlClnt3.LocalProxy.2");
		try
		{
			Control.MonitorDomainParams(document.location.href,GetBrowserExePath(),bMonitorDomain,GetBrowserPID(),sessionDelta/1000,bForceBrowser);
		}
		catch(e)
		{
		}
		sslVpnStatus = Control.ConnectionStatus(document.location.href);
	}
	catch(e)
	{
		sslVpnStatus = 0;
	}

	//Check Java applet on windows
	if (navigator.userAgent.indexOf("Win") > -1)
	{
		if (isJavaApplet())
		{
			var windowName = siteName + secure + "SSLVPNApplet";
			//making sure the refrence to the appletWindow exists (in case not, create it)
			if((appletWindow == null) || appletWindow.closed)
				appletWindow = window.open("", windowName);	
			
			//appletWindow can still be null due to popup blocker
			try
			{
				sslVpnStatus = appletWindow.getConnectionStatus(document.location.href);
			}
			catch(e)
			{
				//if java applet is running, but couldn't create the reference to the window set status =1
				sslVpnStatus = 1;
			}
		}
	}

	if (sslVpnStatus == 0) //Disconnected
	{		
		var time = getCookie("WhlST");
		if (time != null)
			sessionTimeout = time - sessionDelta;
		
		document.cookie = "WhlST=" + "; expires=" + expiredDateGMT + "; path=/;";

		if (sessionTimeout <= 0)
			timerFunc();
		else
		{
			if (scheduledLogoff <= 0)
				SetTimeoutForCacheClean(sessionTimeout/1000 + gracePeriod);
			sessionTimeoutTimeout = window.setTimeout("getWhlCookie('WhlST')", sessionTimeout);
		}
	}
	else if (sslVpnStatus == 1) //Connected
	{		
		if (scheduledLogoff <= 0)
			SetTimeoutForCacheClean(sessionTimeout/1000 + gracePeriod);
		window.setTimeout("handleSessionTimeout()", 5000);
	}
	else if(sslVpnStatus == -1) //Timed out
	{
		SetTimeoutForCacheClean(0)
		endSession("SESSION_TIMEOUT");
	}	
}

function getSTCookie(cookieName)
{     
	bHandleSessionTimeoutCalled = false;
	var url = jsOwnURL + '?' + cookieName
	try 
	{
		xmlhttp1 = new ActiveXObject("Msxml2.XMLHTTP");
	} 
	catch(e)
	{
		try
		{
			xmlhttp1 = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch (E)
		{
			xmlhttp1 = false;
		}
	}
	try
	{
		if (!xmlhttp1 && typeof XMLHttpRequest!='undefined') 
		{
			xmlhttp1 = new XMLHttpRequest();
		}
		
		if (xmlhttp1)
		{	
			xmlhttp1.onreadystatechange = function()
			{
				if (xmlhttp1.readyState != 4)
					return;
			        
				try
				{  	
					if (xmlhttp1.status == "200" && xmlhttp1.responseText == "<Status>StatusMessage</Status>")
					{	    	        
						if ((cookieName == "WhlST" && !bHandleSessionTimeoutCalled) || cookieName == "WhlSTUpdate")
							handleSessionTimeout();
					}
				}
				catch(e)
				{
				}
			}
			xmlhttp1.open("GET", url, true);
			xmlhttp1.send("");
		}	
	}
	catch (E)
	{}
}

function getWhlCookie(cookieName)
{
	if (cookieName!="WhlSL") 
	{
		// this call is required since we use a global var for xmlhttp.
		// If 2 threads will call getWhlCookie concurretly they will fail.
		// getSTCookie duplicates much of getWhlCookie.
		// Please update both if you make a change.
		getSTCookie(cookieName);
		return;
	}
    
	bHandleSessionTimeoutCalled = false;
	var url = jsOwnURL + '?' + cookieName
	try 
	{
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} 
	catch(e)
	{
		try
		{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch (E)
		{
			xmlhttp = false;
		}
	}
	try
	{
		if (!xmlhttp && typeof XMLHttpRequest!='undefined') 
		{
			xmlhttp = new XMLHttpRequest();
		}
		
		if (xmlhttp)
		{	
			xmlhttp.onreadystatechange = function()
			{
			    if (xmlhttp.readyState != 4)
			        return;
			        
				try
				{
					if (xmlhttp.status == "200" && xmlhttp.responseText == "<Status>StatusMessage</Status>")
					{
							handleScheduledLogoff();
					}
				}
				catch(e)
				{
				}
			}
			xmlhttp.open("GET", url, true);
			xmlhttp.send("");
		}
	} 
	catch (E)
	{}
}

function IgnoreEvents(e)
{
	HandleFocus();
	return false;
}

function openDialogWin(strURL)
{
	if(isUAGportal === true)
	{
	    	if(strURL.indexOf("SessionTimeout.asp") != -1)
        	    	window.startSessionTimeout();       
	    	else
        	    	window.startScheduleLogoffCountDown();       
    	}
	else if (window.showModalDialog && navigator.appName.indexOf("Internet Explorer") > 0)
	{
		try
		{
			var sFeatures = "dialogWidth=400px;dialogHeight=";
			//on XP SP2, Win2003 on IE, status bar cannot be hidden -> enlarge window height
			navigator.userAgent.toLowerCase().indexOf("sv1") > -1 ? sFeatures += "266" : sFeatures += "250";
			sFeatures += "px;status=no";
			window.showModalDialog(strURL, window, sFeatures);
		}
		catch(e)
		{}
		//for popup blockers
		window.setTimeout("isModalOpen('" + strURL + "')", 2000);
	}
	else
	{
		var curAvailWidth = screen.availWidth;
		var curAvailHeight = screen.availHeight; 
		var iWidth = 402;
		var iHeight = 252;
		var sFeatures = "";

		sFeatures += 'width=' + iWidth;
		sFeatures += ',height=' + iHeight;
		sFeatures += ',top=' + (curAvailHeight-iHeight)/2;
		sFeatures += ',left=' + (curAvailWidth-iWidth)/2;

		sFeatures += ',status=no,dependent=yes';

		try
		{
			window.top.captureEvents(Event.MOUSEDOWN|Event.FOCUS);
			window.top.onclick = IgnoreEvents;
			window.top.oncontextmenu = IgnoreEvents;
			window.top.onfocus = HandleFocus;
			window.top.addEventListener('click', IgnoreEvents, false);
			window.top.addEventListener('focus', HandleFocus, false);
		}
		catch(e)
		{
			window.parent.captureEvents(Event.MOUSEDOWN|Event.FOCUS);
			window.parent.onclick = IgnoreEvents;
			window.parent.oncontextmenu = IgnoreEvents;
			window.parent.onfocus = HandleFocus;
			window.parent.addEventListener('click', IgnoreEvents, false);
			window.parent.addEventListener('focus', HandleFocus, false);
		}

		window.captureEvents(Event.MOUSEDOWN|Event.FOCUS);
		window.onclick=IgnoreEvents;
		window.oncontextmenu=IgnoreEvents;
		window.onfocus=HandleFocus;
		window.addEventListener('click', IgnoreEvents, false);
		window.addEventListener('focus', HandleFocus, false);

		winModalWindow = window.open(strURL, "ModalChild", sFeatures);

		//for popup blockers
		window.setTimeout("isSchedLogoffOpen('" + strURL + "')", 2000);	
	}
}

function isSchedLogoffOpen(strURL)
{
	if (winModalWindow && !winModalWindow.closed)
		winModalWindow.focus();
	isModalOpen(strURL)
}

function isModalOpen(strURL)
{
	if (popupOpened == false)
	{
		//back to the old solution where we use alerts
		if (strURL == sessionTimeoutURL)
			oldTimerFunc();
		else if (strURL == scheduledLogoffURL)
			oldSchedLogoff();
		else
			endSession()
	}		
	popupOpened = false;
}

function HandleFocus()
{
	if (typeof(winModalWindow) != "undefined" && winModalWindow)
	{
		if (!winModalWindow.closed)
		{
			winModalWindow.focus();
		}
		else
		{
			try
			{
				window.top.releaseEvents(Event.MOUSEDOWN|Event.FOCUS);
				window.top.onclick = "";
				window.top.oncontextmenu = "";
				window.top.addEventListener('click',IgnoreEvents,true);
				window.top.addEventListener('focus',HandleFocus,true);
			}
			catch(e)
			{
				window.parent.releaseEvents(Event.MOUSEDOWN|Event.FOCUS);
				window.parent.onclick= "";
				window.parent.oncontextmenu = "";
				window.parent.addEventListener('click',IgnoreEvents,true);
				window.parent.addEventListener('focus',HandleFocus,true);
			}

			window.releaseEvents(Event.MOUSEDOWN|Event.FOCUS);
			window.onclick="";
			window.oncontextmenu="";
			window.addEventListener('click',IgnoreEvents,true);
			window.addEventListener('focus',HandleFocus,true);
		}
	}
	return false;
}

function refreshSession()
{
	var bTerminateRefresh = true;
	if (refreshSessionTimeStamp == 0)
		bTerminateRefresh = false;
	else
	{
		var currentTimeStamp = new Date();
		lastRefresh = currentTimeStamp - refreshSessionTimeStamp;
		if (lastRefresh > 5000)
			bTerminateRefresh = false;
	}
	if (bTerminateRefresh)
	{
		return;
	}

	refreshSessionTimeStamp = new Date();

	if (document.images)
	{
		if (scheduledLogoff != 0)
		{
			SetTimeoutForCacheClean(scheduledLogoff + gracePeriod);	
			//checking scheduled logoff only on authenticated trunks
			if (bHandleScheduledLogoff)
				window.setTimeout("getWhlCookie('WhlSL')", 1);
		}
		else
			SetTimeoutForCacheClean(sessionTimeout/1000 + gracePeriod);

		bSessionTimeoutAlert = false;
		window.setTimeout("getWhlCookie('WhlSTUpdate')", 1000);

		if (bHandleScheduledLogoff)
		{
			if (scheduledLogoff <= 0)
			{
				try
				{
					schedLogoff();
				}
				catch(e)
				{}
			}
		}
	}
	setOriginalWinTitle();
}

function endSession(sReason)
{		
	if(sReason)
		setReasonCookie(sReason, 60*60*1000);

	whlLogoffEvent = true;
	bAskForClosingApplet = false;

	try
	{
		//stop monitoring this domain tunnel lifetime
		Control = new ActiveXObject("WhlClnt3.LocalProxy.2");
		Control.MonitorDomain(document.location.href,false);
	}
	catch(e)
	{
	}

	var urlForCachClean = "";
	
	try
	{
		var curURL = window.top.location.href;
	}
	catch(e)
	{
		var curURL = window.parent.location.href;
	}

	urlForCachClean = curURL + jsLogoffURL;
	
	urlForCachClean = removeHashKey(urlForCachClean);
	urlForCachClean = removeDuplicateSlash(urlForCachClean);
	ActivateCacheClean(urlForCachClean, true);
}

function gotoRelogin()
{
	try
	{
		//stop monitoring this domain tunnel lifetime
		Control = new ActiveXObject("WhlClnt3.LocalProxy.2");
		Control.MonitorDomain(document.location.href,false);
	}
	catch(e)
	{}

	var strURL = window.top.frames[0].location.pathname + "WhlSchedLogoff";

	if(isUAGportal === true) 
	{
		parent.document.getElementById("portal_frameset").rows = "100%, 0px";
		parent.frames[0].location.replace(strURL);
  	}
	else
		window.top.location.replace(strURL);
}

function setOriginalWinTitle()
{
	try
	{
		window.top.document.title = getCookie("WhlWinTitle");
	}
	catch(e)
	{
		window.parent.document.title = getCookie("WhlWinTitle");
	}
	window.document.title = getCookie("WhlWinTitle");
}
function removeHashKey(url)
{	
	return ReplaceAll(url, "#", "");

}

function removeDuplicateSlash(url)
{
	urlFirstPart = url.substring(0, 10);
	urlSecondPart = url.substring(10, url.length);
	newUrl = ReplaceAll(urlSecondPart, "//", "/");

	return(urlFirstPart + newUrl);
}

function ReplaceAll(str, find, replace)
{
	var a;
	var b = new Array();

	if (str == null)
		return null;

	str = str.toString();
	a = str.split(find);
	b[0] = a[0];

	for (var i=1 ; i < a.length ; i++)
	{
		b[i] = replace + a[i];
	}

	str = '';
	for (i=0 ; i < a.length ; i++)
	{
		str = str+b[i];
	}

	return str;
}

function GetBrowserPID()
{
	var browserPID = 0;
	try
	{
		var CompMgrObj = new ActiveXObject("ComponentManager.Installer.2");
		browserPID=CompMgrObj.BrowserPID;
	}
	catch(e)
	{
	}

	return browserPID;
}

function GetBrowserExePath()
{
	var browserExePath="";
	try
	{
		var CompMgrObj = new ActiveXObject("ComponentManager.Installer.2");
		browserExePath=CompMgrObj.BrowserExePath;
	}
	catch(e)
	{
	}

	return browserExePath;
}

function isJavaApplet()
{
	//check if java applet is running:
	var isAppletWin = getCookie("WhlApplet");
	if (isAppletWin == "True")
		return true;
	else
		return false;
}

//Periodic Detection functionality
if (NAPStatus == 0)
{
	try
	{
		whaleEndpointDetectorClient = new ActiveXObject("EndpointCompliance.Detector.2");
	}
	catch(e)
	{
		//failed creating detection object - no periodic detection
		whaleEndpointDetectorClient = null;
	}
}

function activateCompareTimeStamps()
{		
	if (whaleEndpointDetectorClient || whlClientMode == 1)
		compareTimeStamps();
}

function compareTimeStamps()
{
	oldTimestamp = dwTimestamp;
	bHaveAccess = true;
	state = 2;
	try
	{
		var results;
		var resultsArr;
		if (whlClientMode == 1) // applet
		{			
			if (getCookie("WhlInstall") != "False")	
			{
				var siteInfoResult = "";
				var oApplet = document.getElementById("RemoteAccessAgent");
				if (!oApplet)
				{
					if (document.getElementById("appletSpan") == null)
					{
						var newSpan = document.createElement('span');
						newSpan.setAttribute('id',"appletSpan");
						document.body.appendChild(newSpan);
					}
						
					DrawAWApplet("getsiteinfo",100,-1,siteName,secure);
				}
				
				oApplet = document.getElementById("RemoteAccessAgent");
				getSiteInfoResults = oApplet.GetSiteInfo(); 
				
				if(getSiteInfoResults.indexOf(",") >= 0)
				{					
					resultsArr = getSiteInfoResults.split(",");
					if (resultsArr.length != 3)
						throw("Invalid return value from applet's GetSiteInfo");
				}
				else								
					throw("Invalid return value or no results yet from applet's GetSiteInfo");
			}
		}
		else // activex
		{
			results = new VBArray(whaleEndpointDetectorClient.GetSiteInfo(CanonicalizeLocation()));	
			resultsArr = results.toArray();
		}
		dwTimestamp = resultsArr[0];			//Portal Refresh Timestamp
		//setting the new time to the cookie only if it's not "0,0,0,0,0,0,0"
		if (dwTimestamp.substr(0,1) != "0")
			document.cookie = "dwLastDetectionTimestamp=" + dwTimestamp + "; path=/;";
		bHaveAccess = resultsArr[1];			//Session Access
		state = resultsArr[2];				//Periodic Detection State - if 0 - should be restarted

		if (bFirstLoad)
		{
			oldTimestamp = dwTimestamp;
			bFirstLoad = false;
		}
	}
	catch(e)
	{}	
	
	//Checking if detection should be restarted
	if (state == 0)
	{
		launchDetection();
	}
	else// detection is currently running
	{
		//Checking site access
		if (!bHaveAccess)
			endSession("NO_SITE_ACCESS");
		
		//Checking if view should be refreshed
		if (oldTimestamp != dwTimestamp)
		{
			//Checking if a new session wasn't created
			if (origCookie == getCookie("NLSession" + sSecure + siteName))
			{				
				if(isUAGportal === true)
				{
					//update application list on mainframe.aspx if it exist
					//find if MainFrame exist (iterating all available frames and iframes from top)
					oWin = null;
					findFrame(window.top, 'mainframe.aspx');
					if(oWin)
						oWin.resetApplicationList();
					else
					{
						findFrame(window.top, 'contentframe.aspx');
						if(oWin)
							oWin.resetApplicationList(true);
					}	
				}
				else
				{
					//No toolbar, but application list might exist (SharePoint)
					oWin = null;
					findFrame(window.top, 'contentframe.aspx');
					if(oWin)
						oWin.resetApplicationList(true);
				}
			}
		}
	}	
	window.setTimeout("compareTimeStamps()", refreshRate*1000);
}


var getSiteInfoResults = "";
function onGetSiteInfo(retValue)
{
	//launched by java applet in order to receive GetSiteInfo values
	getSiteInfoResults = retValue;
	
}

function setReasonCookie(reason, delay)
{
	var today = new Date();
	var expiredDate = new Date(today.getTime() + delay);
	var expiredDateGMT = expiredDate.toGMTString();
	//set value of WhlLogoffReason
	document.cookie = "WhlLogoffReason=" + reason + "; expires=" + expiredDateGMT + ";path=/";
}

var oWin = null;

function findFrame(win, frameName)
{
    //find mainFrame on Iframes/frames
    var framesCollection = win.frames;
    for (var i=0 ; i < framesCollection.length ; i++)
    {
        //permission denied can be thrown on 'location.href' if frames are from different domain.
        //in that case we keep searching the frame
        try{
            if (framesCollection[i].location.href.toLowerCase().indexOf(frameName) > 0)
            {
                oWin = framesCollection[i];
                return;
            }
            else
            {
                findFrame(framesCollection[i], frameName);
            }
        }
        catch(e){
            try{
                findFrame(framesCollection[i], frameName);
            }
            catch(e){
            }
        }
    }           
}

function CanonicalizeLocation()
{
	var loc = document.location.href;
	var i = loc.indexOf("://"), j;
	if(i < 0)
	{
		loc = "http://" + loc;
		i = 4;
	}
	
	j = loc.indexOf("/",i+3);
	if(j < 0)
	{
		j = loc.length;
		loc += "/";
	}
	
	loc = loc.substr(0, j);
	return loc;
}

function launchDetection()
{
	try 
	{
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} 
	catch (e) 
	{
		try 
		{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch (E) 
		{
			xmlhttp = false;
		}
	}
	try
	{
		if (!xmlhttp && typeof XMLHttpRequest!='undefined') 
		{
			xmlhttp = new XMLHttpRequest();
		}
		
		if (xmlhttp)
		{	
			xmlhttp.onreadystatechange = function()
			{
				if (xmlhttp.readyState==4)
				{
					addDetectionScript(xmlhttp.responseXML);
				}
			}
			
			xmlhttp.open("GET", "/InternalSite/LaunchDetection.asp?site_name=" + siteName + "&secure=" + secure, true);
			xmlhttp.send("");
		}
	} 
	catch (E)
	{}
}

function addDetectionScript(xmlObj)
{
	getNonce = xmlObj.getElementsByTagName("GetNonce")[0].text;
	addCustomDetectionScripts = xmlObj.getElementsByTagName("AddCustomDetectionScripts")[0].text;
	getNumbersDecimalSymbol = xmlObj.getElementsByTagName("GetNumbersDecimalSymbol")[0].text;
	
	loadScript("/InternalSite/scripts/detection.js");
	
	callDetection();
}

function callDetection()
{	
	if (detectionScriptLoaded == 1)
		WhlDetect(getNonce, siteName, NLcookie, secure, addCustomDetectionScripts, getNumbersDecimalSymbol, true, false, null);
	else
		window.setTimeout("callDetection()", 100);
}

function loadScript(file)
{
	// Create script DOM element
	var scriptObj = document.createElement('script');
	scriptObj.type = 'text/javascript';
	scriptObj.src = file;

	// Alert when the script is loaded
	if (typeof(scriptObj.onreadystatechange) == 'undefined') // W3C
		scriptObj.onload = function()
		{ 
			this.onload = null;
		};
	else // IE
		scriptObj.onreadystatechange = function()
		{ 
			if (this.readyState != 'loaded' && this.readyState != 'complete') 
				return; 
			this.onreadystatechange = null;
		}; // Unset onreadystatechange, leaks mem in IE

	// Add script DOM element to document tree
	document.getElementsByTagName('head')[0].appendChild(scriptObj);
}

var oldonload = window.onload;
if (typeof window.onload != 'function')
{
	window.onload = new function() 
	{
		window.setTimeout("getWhlCookie('WhlST');",10);
		window.setTimeout("getWhlCookie('WhlSL');",10);
	}
} 
else
{
	window.onload = function()
	{
	    oldonload();
	    window.setTimeout("getWhlCookie('WhlST');",10);
	    window.setTimeout("getWhlCookie('WhlSL');",10);
	}
}
