// JavaScript Document
//exibir layer
var layer = {
	
	show : function(url,act){	
		//instancia a classe AJAX
		var ajax
		try{ 
			ajax = new XMLHttpRequest();
		}catch (e){ 
			try {
				ajax = new ActiveXObject("Msxml2.XMLHTTP");
			}	catch (e)	{ 
				ajax=new ActiveXObject("Microsoft.XMLHTTP");
			}
		}				
		
		//verifica o suporte a AJAX
		if (ajax==null){ alert("Seu navegador não da suporte a tecnologia AJAX!");return false; }
		
		//cria o overlayer em runtime
		overlayer = document.createElement("div");
		var sizesPage = getPageSize();
		with (overlayer){
			setAttribute('id','overlayer');
			setAttribute('name','overlayer');					
			className = "overlayer";
			style.height = sizesPage + 'px'; 
		}
		document.body.appendChild(overlayer);
		
		//cria o layer em runtime				
		layer = document.createElement('div');
		with(layer){
			setAttribute('id','layer');
			setAttribute('name','layer');					
			className = "layer";
		}
		document.body.appendChild(layer);
		
		//carrega o conteudo via AJAX dentro do layer criado				
		l = document.getElementById("layer");
		ovl = document.getElementById("overlayer");			
		
		//verifica o estado do objeto AJAX
		ajax.onreadystatechange = function(){
			//enquanto esta no estado de seleção....
			if (ajax.readyState==0){l.innerHTML="<p align='center'>Carregando...</p>"}
			if (ajax.readyState==4){l.innerHTML=ajax.responseText;}
		}
		
		//executa a consulta em formato GET
		ajax.open("GET",url,true);
		ajax.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
		ajax.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
		ajax.setRequestHeader("Pragma", "no-cache");
		ajax.send(null);
	
	},
	
	hide : function(){	//destrou os elementos criados
		document.body.removeChild(l);
		document.body.removeChild(ovl);					
	}	

}

function getPageSize(){
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}
	return pageHeight
}

