/*
	This javascript file is intended to contain a list of
	functions within runLoadFunc, that are to be run on the
	load of any page.
	
	startSessionTimeOut - A timeout function that will show an
	                      alert box when a timeout occurs

*/
var SESSION_DURATION = 1800000; // Session duration in milliseconds
var WARNING_TIME     = 1800000; // Length of time after which we warn 

/*
   Add functions in this function that are to be loaded
	on a onLoad event in the BODY tag of any page in the system
*/
function runLoadFunc() {

	startSessionTimeOut();

}


/*
   Starts a timeout event to occur once after the lenght of 
	time described by WARNING_TIME
*/
function startSessionTimeOut() {

	setTimeout("sessionCallBack()",WARNING_TIME);
}


/*
   The Callback function for startSessionTimeOut.
	This displays the time at which the session will expire.
	If the time at which the user clicks the ok on the alert
   box is after the session expires, we call the reload(true)
	method of the location class, which will reload the page, thus
	displaying the login function. 

	This was done because the location
	of this page in relative terms to the page calling this function
	changes depending on which aplication is being run. The
   reload will force the page to load the login function, and thus
   the location remains page specific.
*/
function sessionCallBack() {

	var sesTime = SESSION_DURATION  - WARNING_TIME;  // This is used to
                                                    // determine the proper
	                                                 // experation time  
	var sesDate = new Date();       // The Date object for the 
	var curDate = new Date();		  // The current date, before the alert box.
	var ampm="";

	sesDate.setTime(curDate.getTime() + sesTime);
	hours = sesDate.getHours();

	if (hours > 12) {
		hours = hours - 12;
		ampm="PM";
	} else {
		ampm="AM";
	}
	
	alert ("Your Session Has Expired");

	// the alert box is modal, so we have to check how long they left that up
	var newDate = new Date();

	if (newDate > sesDate) { 
		// the session has expired.
		location.reload(true);
	}

}

