﻿/*------------------------------------------------------------------------------
 * Project Name: TheIHS
 * Client Name: George Mason University
 * Component Name: Timeout.js
 * Purpose/Function: Warn users of impending timeout
 * Author: John Schrock
 * Version              Author              Date            Reason
 * 1.0              John Schrock     04/01/2010      timeout waringin needed 
 --------------------------------------------------------------------------------*/

// indexOf is case sensitive, returns -1 if string not found
/*
function goLogin()
{
	var SaveForLater = document.getElementById('<%=btnSaveForLater1 %>');
	if (SaveForLater != null)
	{
		SaveForLater.click();
		var LogOut = document.getElementByID('<%=lbtnLogOut %>');
	}
	else
	{
		window.location = "/MyIHS/Login.aspx"
	}
}
*/

function checkTimeout()
{
	if (document.URL.indexOf("ogin.aspx") < 0 & document.URL.indexOf("SignUp.aspx") < 0 & document.URL.indexOf("signup.aspx") < 0 & document.URL.indexOf("acultyProfile.aspx") < 0 & document.URL.indexOf("acultyprofile.aspx") < 0)
	{
	    setTimeout("sessionTimeoutWarning()", (14 * 60 * 1000)); // 14 minutes
		//setTimeout("goLogin()", 19 * 60 * 1000);
	}
}

function sessionTimeoutWarning()
{
	var w = window.open('', '', 'status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=0,scrollbars=0,width=300,height=100');
    w.document.write('<html><body style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10pt; color: #1b1a1a; padding: 0px; margin: 0px">');
    w.document.write('<p style="padding: 10px; margin: 0px"><b>Warning:</b>  Your session will time out in 5 minutes.  Please save any open forms.</p>');
    w.document.write('<div style="text-align: center; padding: 10px"><input type="button" value="Close" onclick="window.close();" /></div>');
    w.document.write('</body></html>');
    w.document.title = 'Session Timeout Warning - Institute for Humane Studies';
    w.document.close();

	setTimeout(function(){timeoutAutoSave(w)}, (5 * 60 * 1000)); // 5 minutes
}

function timeoutAutoSave(w)
{
    // call the 'autoSave()' function if it's defined on the page.
    if (typeof(autoSave) != 'undefined')
    {
        autoSave();
    }
    else
    {
        w.document.write('<html><body style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10pt; color: #1b1a1a; padding: 0px; margin: 0px">');
        w.document.write('<p style="padding: 10px; margin: 0px"><b>Warning:</b>  Your session has timed out.  This page has not been saved.</p>');
        w.document.write('<div style="text-align: center; padding: 10px"><input type="button" value="Close" onclick="window.close();" /></div>');
        w.document.write('</body></html>');
        w.document.title = 'Session Timeout Warning - Institute for Humane Studies';
        w.document.close();
    }
}

checkTimeout();


/*
var timerPROMPT = 0;
var timerCLOSE = 10 * 1000;

function EndApp()
{
	window.location = "/MyIHS/Login.aspx"
}
function StopTiming()
{

	if(timerPROMPT > 0)
		window.clearTimeout(timerPROMPT)

	if (confirm('Due to inactivity, your session is about to time out.  Please save any open forms.') == 1)
	{
		if(timerCLOSE > 0)
		window.clearTimeout(timerCLOSE)

		//timerPROMPT = window.setTimeout("StopTiming()",15 * 60* 1000);
		//timerCLOSE = window.setTimeout("EndApp()",20.5 * 60 * 1000);
		timerPROMPT = window.setTimeout("StopTiming()",1 * 5 * 1000);
		timerCLOSE = window.setTimeout("EndApp()",1 * 10 * 1000);
	}
	else
	{
		EndApp();
	}
}
function reset_timer() 
{
	if(timerPROMPT > 0)
		window.clearTimeout(timerPROMPT)
	if(timerCLOSE > 0)
		window.clearTimeout(timerCLOSE)

	//timerPROMPT = window.setTimeout("StopTiming()",15 * 10* 1000);
	//timerCLOSE = window.setTimeout("EndApp()",20.5 * 60 * 1000);
	timerPROMPT = window.setTimeout("StopTiming()",1 * 5 * 1000);
	timerCLOSE = window.setTimeout("EndApp()",1 * 10 * 1000);
}

*/

// Take user here after session timed out



