var sessiontimeout = 10000;
var box = document.getElementById('alertbox');
var agt      = navigator.userAgent.toLowerCase();
var is_ie    = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var is_ie5_5 = (is_ie && !(parseInt(navigator.appVersion) < 4) || (agt.indexOf("msie 4") >-1));
var seconds;
var box = document.getElementById('alertbox');
var countDownTimer;
var alertPosTimer;
var sessionredirect = "/Imd_SessionExpired.aspx";

function startTimer() {
	box.style.display = 'block';
	posAlert();
	seconds = 60;
	countDownTimer = window.setTimeout("countdown()",1);
}
function countdown() {
	countDownTimer = window.setTimeout("countdown()",1000);
	if (seconds > 0)
		seconds -= 1;
	else
		logoutsession();
	document.getElementById('timeouttime').innerHTML = seconds;
}
function posAlert() {
	var y = window.pageYOffset;
	if (!y) y = document.body.scrollTop;
	var h = window.innerHeight;
	if (!h) h = document.documentElement.clientHeight;
	if (!h) h = document.clientHeight;
	if (!h) h = document.documentElement.offsetHeight;
	box.style.top = (y + h/2) + 'px';
	
	alertPosTimer = window.setTimeout("posAlert()", 10);
}
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}
function continuesession() {
	clearTimeout(countDownTimer);
	clearTimeout(alertPosTimer);
	box.style.display = 'none';
	refreshLogin();
	startsessiontimer();
}
function startsessiontimer() {
	if (box)
	{
		if (is_ie5_5)
			document.getElementById('alertshadow').style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/Images/boxshadow.png', sizingMethod='crop')";
		if (!is_ie)
			document.getElementById('alertshadow').style.background = "url(/Images/boxshadow.png) top center no-repeat";
		window.setTimeout('startTimer()', sessiontimeout);
	}
}
function logoutsession() {
	location.href = sessionredirect;
}
function getXmlHttp() {
  var xmlHttp;
  try {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
  } catch (e) {
  // Internet Explorer
    try {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
  return xmlHttp;
}

var xmlHttpReq = getXmlHttp();
function refreshLogin()
{
	xmlHttpReq.open('GET', '/default.aspx', true);
	xmlHttpReq.send(null);
}
