var sessionTimeout = 55; //55; //length of time until logged out (minutes)
var warningTime = 2; //2; //length of time popup stays up for (minutes)
var howLong = 120; //120; //how long to keep window open for (seconds)

//popup opens sessionTimeout minus warningTime minutes after the page is opened
var thisTimer = null; //stop/start session timer
var thisWarningTimer = null; //stop/start warning timer
var thisDialogTimer = null;  //stop/start dialog timer
//var sDure=1*60*1000;

function startTimeoutTimer()
{
    thisTimer = setTimeout("closeSession()", sessionTimeout * 60000+3000);
    thisWarningTimer = setTimeout("popupAsk()", (sessionTimeout - warningTime) * 60000);
}

function refreshSession()
{
    //ping server in iframe to restart session
    //refreshMe.document.location.href = "http://xyz.org/intranet/refreshsession.aspx";

    //restart timers
    clearTimeout(thisTimer);
    clearTimeout(thisWarningTimer);
    clearTimeout(thisDialogTimer);
    startTimeoutTimer();
    keepSession();
}

function closeSession()
{
    //redirect to login page with logged out message
 //   document.location.href="/osc/setupElogNewExpire.do";
      window.location=logout_url;
}

var reqSession = null;

function keepSessionByReload()
{
	location.reload(true);
}

function keepSession()
{
   var url = reqContextPath+"/keepsession.jsp"; //"/osc/keepsession.jsp" //this file renew session

      
      if ( window.XMLHttpRequest ) 
      {
            reqSession = new XMLHttpRequest();
      } 
      else if ( window.ActiveXObject ) 
      {
            reqSession = new ActiveXObject("Microsoft.XMLHTTP");
      }
      
      reqSession.open("GET", url, true);
      reqSession.onreadystatechange = keepSessionCallback;
      reqSession.send(null);
       // setTimeout("keepSession();", keepSessionTimeout );
}

function keepSessionCallback()
{
      if (reqSession.readyState == 4) 
      {
       
        if (reqSession.status == 200) 
            {
                  //the page request was a success
				 //alert("It worked!");
				 // refreshSession();

            }
      }
}


function tick()
{
    //subtract one second
    howLong -= 1;

    var timeLeft = howLong //- second;

    if (timeLeft==0)
    {
     tooLate();
    }
    
}

function stillHere()
{
 	refreshSession();
    hideDialog();
}

function orig_stillHere()
{
    //resets timer on parent page and closes this window
    window.opener.refreshSession();
 window.close();
}

function goAway()
{
    closeSession();
}

function tooLate()
{
    closeSession();
    hideDialog();
    clearTimeout(thisDialogTimer);
}

function cancelpressed()
{
    closeSession();
    hideDialog();
}
