var preFunction=null;
var timeOutId=null;
function autoRefresh()
{
  var needReload;
  if(preFunction!=null && typeof(preFunction) == 'function' )
      needReload = preFunction();
  if(!needReload)
    window.location.reload();       
}
function timeOut(maxInactiveInterval)
{            
   timeOutId = setTimeout('autoRefresh()', (maxInactiveInterval-60)*1000);
}

function retrieveCookie( cookieName ) {
	var cookieJar = document.cookie.split( "; " );
	for( var x = 0; x < cookieJar.length; x++ ) {
		var oneCookie = cookieJar[x].split( "=" );
		if( oneCookie[0] == cookieName ) { return oneCookie[1] ? oneCookie[1] : ''; }
	}
	return null;
}
function setRefreshCookie( cookieName, cookieValue, lifeTime, path, domain, isSecure ) {
	if( !cookieName ) { return false; }
	if( lifeTime == "delete" ) { lifeTime = -10; }
	document.cookie = cookieName + "=" + cookieValue +
		( lifeTime ? ";expires=" + ( new Date( ( new Date() ).getTime() + ( 1000 * lifeTime ) ) ).toGMTString() : "" ) +
		( path ? ";path=" + path : "") + ( domain ? ";domain=" + domain : "") + 
		( isSecure ? ";secure" : "");
	if( lifeTime < 0 ) { if( typeof( retrieveCookie( cookieName ) ) == "string" ) { return false; } return true; }
	if( typeof( retrieveCookie( cookieName ) ) == "string" ) { return true; } return false;
}

function sessionRefresh(basePath, maxInactiveInterval)
{
    clearTimeout(timeOutId);
    var func = "sendRequest('" + basePath + "/ajaxRequest.do?p=t')";
    setInterval(func, (maxInactiveInterval-50)*1000);
}

function sendRequest(url) {
    url += "&rid=" + Math.random();
    var xmlHttp=GetXmlHttpObject();
    if( !xmlHttp ) return;
    if (xmlHttp.overrideMimeType) {
        xmlHttp.overrideMimeType('application/text');
    }

    //xmlHttp.onreadystatechange=function() { onStateChanged(xmlHttp,postProcess); };
    try {
        xmlHttp.open("GET",url,true);
        var req = xmlHttp.send(null);
    } catch(e) {
    }
}

function GetXmlHttpObject(){
    var xmlHttp=null;
    try{
        // Firefox, Opera 8.0+, Safari
        xmlHttp=new XMLHttpRequest();
    }catch (e){
    // Internet Explorer
    try{
        xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }catch (e){
    try{
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }catch (e){
    return null;
}
}
}
return xmlHttp;
}
