var IE = (document.all);
var NS6 = (document.getElementById&&!document.all);
var NS = (navigator.appName=="Netscape" && navigator.appVersion.charAt(0)=="4");
var PageStartTime= new Date;
PageStartTime.getTime();

//SET PAGE EVENTS
window.onload=window_onload;
window.onbeforeunload=window_onunload;

//HANDLE PAGE EVENTS
function window_onload() {
	SetScrollPosition();
	if (!IE) {
		try{
			calendarInit();
		}
		catch(exception){
			//did not have the calendar .js file on page
		}
	}	
	CalcPageLoadTime();
}

function window_onunload() {	
	setCookie("ScrollPos", document.body.scrollTop);	
}

//PRIVATE FUNCTIONS
function SetScrollPosition(){	
	var pos=0;
	if (myScrollPos == 0) //do not want to scroll if was a post back.  myScrollPos gets set in header's VB codebehind
		pos=getCookie("ScrollPos");
	if (pos > 0){
		document.body.scrollTop = pos;
	}
}	

function CalcPageLoadTime()
{
	var PageEndTime = new Date;
	var elm;
	PageEndTime = PageEndTime.getTime();
	var diff;
	diff = (PageEndTime-PageStartTime)/1000;	

	setCookie("PageLoadTime",diff)
	//document.forms[0].__PAGELOADTIME.value=diff;
	//alert(document.forms[0].__PAGELOADTIME.value);
	//window.status='Time took to load : ' + diff + ' second(s)';
}

function setCookie(cookieName, cookieValue, cookiePath, cookieExpires){
	cookieValue = escape(cookieValue);

	if (cookieExpires == null)
	{	
		nowDate = new Date();
		nowDate.setMonth(nowDate.getMonth() + 6);
		cookieExpires = nowDate.toGMTString();
	}
	if (cookiePath != null)
		cookiePath = ";Path=" + cookiePath;		
	else
		cookiePath = ""			
	//alert("Set Cookie [" + cookieName + "=" + cookieValue + ";expires=" + cookieExpires + cookiePath + "]");
	document.cookie = cookieName + "=" + cookieValue + ";expires=" + cookieExpires + cookiePath;			
}
function getCookie(cookieName){
	//alert("Whole Cookie [" + document.cookie + "]")
	var cookieValue = document.cookie;	
	var cookieStartsAt = cookieValue.indexOf(cookieName + "=");
	if (cookieStartsAt == -1)
	{
		cookieValue = null;
	}
	else
	{
		cookieStartsAt = cookieValue.indexOf("=", cookieStartsAt) + 1;
		var cookieEndsAt = cookieValue.indexOf(";", cookieStartsAt);
		if (cookieEndsAt == -1)
		{
			cookieEndsAt = cookieValue.length;
		}
		cookieValue = unescape(cookieValue.substring(cookieStartsAt, cookieEndsAt));					
	}
	//alert("Get Cookie [" + cookieName + "=" + cookieValue + "]")	
	return cookieValue;
}


