
//*****************************************************************
//THIS CODE IS USED TO EXTEND YOUR SESSION
//*****************************************************************

function handleResponse(msg) {
  if (msg == 'SUCCESS'){
	resettimer();
  }else{
	alert('There was an error trying to extend your session.');
  }
}

function extendSession(url) {callToServer(url);};

function callToServer(url) {
  if (!document.createElement) {return true};
  var IFrameDoc;
  var URL = url;
  if (!IFrameObj && document.createElement) {
    // create the IFrame and assign a reference to the
    // object to our global variable IFrameObj.
    // this will only happen the first time 
    // callToServer() is called
   try {
      var tempIFrame=document.createElement('iframe');
      tempIFrame.setAttribute('id','RSIFrame');
      tempIFrame.style.border='0px';
      tempIFrame.style.width='0px';
      tempIFrame.style.height='0px';
      IFrameObj = document.body.appendChild(tempIFrame);
      
      if (document.frames) {
        // this is for IE5 Mac, because it will only
        // allow access to the document object
        // of the IFrame if we access it through
        // the document.frames array
        IFrameObj = document.frames['RSIFrame'];
      }
    } catch(exception) {
      // This is for IE5 PC, which does not allow dynamic creation
      // and manipulation of an iframe object. Instead, we'll fake
      // it up by creating our own objects.
      iframeHTML='\<iframe id="RSIFrame" style="';
      iframeHTML+='border:0px;';
      iframeHTML+='width:500px;';
      iframeHTML+='height:500px;';
      iframeHTML+='"><\/iframe>';
      document.body.innerHTML+=iframeHTML;
      IFrameObj = new Object();
      IFrameObj.document = new Object();
      IFrameObj.document.location = new Object();
      IFrameObj.document.location.iframe = document.getElementById('RSIFrame');
      IFrameObj.document.location.replace = function(URL) {
        this.iframe.src = URL;
      }
    }
  }

  if (navigator.userAgent.indexOf('Gecko') !=-1 && !IFrameObj.contentDocument) {
    // we have to give NS6 a fraction of a second
    // to recognize the new IFrame
    setTimeout('callToServer('+url+')',100);
    return false;
  }
  
  if (IFrameObj.contentDocument) {
    // For NS6
    IFrameDoc = IFrameObj.contentDocument; 
  } else if (IFrameObj.contentWindow) {
    // For IE5.5 and IE6
    IFrameDoc = IFrameObj.contentWindow.document;
  } else if (IFrameObj.document) {
    // For IE5
    IFrameDoc = IFrameObj.document;
  } else {
    return true;
  }
  
  IFrameDoc.location.replace(URL);
  return false;
  
}

function countdown(remain,messages, reset){
	if (reset == true){clearInterval(timer);document.getElementById("notifier").innerHTML = '';}
	var
		notifier = document.getElementById("notifier"),
		countdown = document.getElementById("notifier_countdown")
		timer = setInterval( function () {
			countdown.innerHTML = Math.floor(remain/60) + ":" + (remain%60 < 10 ? "0": "") + remain %60;
			if (messages[remain]) { notifier.innerHTML = messages[remain]; }
			if (--remain < 0 ) { clearInterval(timer); alert("Your session has expired. \n \n Please log back into the system.");window.location='http://moveitshipit.com/login.asp?logout=true';}
		},1000);
};
	
function resettimer(){
	countdown(3600,
		{ 
			600: "expires in 10 min",
			300: "expires in 5 min",
			60: "expires in 1 min", 
			10: "expiring",
			0: "expired"
		},true
	);
}


