var onloadEval="";
window.onload=ftnWindowLoaded;
var IE = false;
var popupsAllowed = false;
var timeoutTimer;

if (navigator.appName.indexOf("Microsoft") !=-1) IE=true;

function CanCreatePopUp()
{
	if (popupsAllowed == false)
	{
		var win = window.open('','CanCreatePopUp','width=10,height=10,left=2500,top=2500');
		if (win != null)
		{
			popupsAllowed = true;
			win.close();
			this.focus();
		}
		else
		{
			alert('The system has detected that you have a pop-up blocker turned on. In order for the site to function correctly you need to set the pop-up blocker to allow pop-ups for this site. If you have any questions about how to do this, please contact the Help Desk.');
		}
	}
	
    return popupsAllowed;
}
   
function ftnWindowLoaded() {
    subSetTimeout();
    eval(onloadEval);
}

function subSetTimeout() 
{
    timeoutTimer = setTimeout(subSetTimeoutMessage, GetSessionTimeoutNotice());
}

function GetSessionTimeoutNotice() {
    var minutes = '20';
    try {
        if (parseFloat(sessionTimeOutMinutes) == 0) {
            sessionTimeOutMinutes = '20';
        }
        minutes = sessionTimeOutMinutes;
    } catch (err) {
        minutes = '20';
    }

    //warning 1 1/2 minutes before timeout
    return String(((parseFloat(minutes) - 1.5) * 60) * 1000);
}

function subReSetTimeout()
{
    clearTimeout(timeoutTimer);
    subSetTimeout();
}

function subClearTimeout()
{
    clearTimeout(timeoutTimer);
}

function subSetTimeoutMessage()
{
	var canpop = CanCreatePopUp();
	if (canpop)
	{
		if (IE)
		{
			ftnShowModal('/Library/Aspx/KeepAlive.aspx',339,225);
		}
		else
		{
			ftnShowWindow('/Library/Aspx/KeepAlive.aspx',339,225);
		}
	}
	else
	{
		alert("Your session is about to time out. Please save your work.");
	}
}

function ftnTimedOut()
{
    if (openwindow) openwindow.close();
	window.parent.location = '/Login/Login.aspx';
}

//TODO - make this work cross browser - copied from old skool partners
function ftnGetObjectString(strObjectId)
{
	return "document.getElementById('" + strObjectId + "')";
}

function ftnRefresh(objID)
{
	document.location.href = document.location.href;
	// Changed this to a redirect to itself rather than a refresh to get away from  the resubmit data warning.
	//location.reload(true);
}

function ftnFlashViewer(strSwfID, strWidth, strHeight, blnFullscreen)
{
	var canpop = CanCreatePopUp();
	if (canpop == true)
	{
		var strFullscreen = 'fullscreen=No,';
		if (blnFullscreen == true)
		{
			strFullscreen = 'fullscreen=Yes,';	
		}
		ftnShowWindow('/Library/Aspx/FlashViewer.aspx?swf='+strSwfID, strWidth, strHeight, strFullscreen+'toolbar=No,location=No,status=No,menubar=No,scrollbars=No,resizable=No');
	}
}

function ftnGetObject(strObjectID, blnParent)
{
	if (blnParent) 
		{
		if (IE) 
		{	
			return window.parent.document.getElementById(strObjectID);
		}
		else
		{
			return window.parent.document.getElementById(strObjectID);
		}
	}
	else
	{
		if (IE)
		{	
			return document.getElementById(strObjectID);
		}
		else
		{
			return document.getElementById(strObjectID);
		}
	}
}

//gets relative URL of current page
function ftnGetRelativeURL(strURL)
{
	return escape(strURL.substr(strURL.indexOf('/', 8)));
}

// Checks if the given flash movie is completely loaded. Returns true if yes, false if no.
function ftnMovieIsLoaded(objMovie)
{
	if (typeof(objMovie) != "undefined")
		return objMovie.PercentLoaded() == 100;
	else
		return false;
}

function PageEditRedirect(){
	var querystring = (document.location.href.indexOf("?") > -1)? document.location.href.slice(document.location.href.indexOf("?")) : "";
	document.location.href = "PageEditRedirectHandler.axd?u=" + document.location.pathname + querystring;
}

