function adicionaEvento(obj, funcao, evento){
	if (window.addEventListener)
		obj.addEventListener(evento, funcao, true);
	else if (window.attachEvent)
		obj.attachEvent("on" + evento, funcao);
}

adicionaEvento(window, executarChamadaServidor, "load");

var xmlHttpGenericoJs = null; // O nome é extenso para não conflitar com outros códigos.
var tempoTimeOut = 0;
function executarChamadaServidor(){
	
	xmlHttpGenericoJs = GetXmlHttpObject();



	if (xmlHttpGenericoJs==null)
		return;
	
	
	
    var path = "";
    
    if(window.location.href.lastIndexOf(".aspx")!=-1)
        path = window.location.href.substring(0,window.location.href.lastIndexOf(".aspx"));	
    else
        path = window.location.href.substring(0,window.location.href.lastIndexOf("/"));	
	
	//path = path.substring(0,path.lastIndexOf("/"));
	
	var url = path.substring(0,path.lastIndexOf("/")) + "/NaoExpiraPagina.aspx";
	


	
	xmlHttpGenericoJs.onreadystatechange = stateChanged;	
	xmlHttpGenericoJs.open("GET", url, true)
	xmlHttpGenericoJs.send(null)	
}

function stateChanged(){ 
	if (xmlHttpGenericoJs.readyState == 4 || xmlHttpGenericoJs.readyState == "complete")
	{
		
		tempoTimeOut = xmlHttpGenericoJs.responseText.replace('\r', '').replace('\n', '');
		
		var tempo = Number(tempoTimeOut);
		
		if (tempo < 3)
			tempo -= 0.5;
		else if (tempo < 10)
			tempo -= 1;
		else
			tempo -= 2;

		
		//setTimeout('executarChamadaServidor()', tempo * 1000);// * 60);
		
		if(isNaN(tempo))return;
		setTimeout('executarChamadaServidor()', tempo * 60000);// * 60);
	}
} 

function GetXmlHttpObject(){
 
	var objXMLHttp = null
	if (window.XMLHttpRequest)
		objXMLHttp = new XMLHttpRequest();
	else if (window.ActiveXObject)
		objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP");

	return objXMLHttp;
}
