try {
	xmlhttp = new XMLHttpRequest();
} catch(ee) {
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch(e) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch(E) {
			xmlhttp = false;
		}
	}
} 

function obj(id)
{
	return document.getElementById(id);
}

function toogle(objt)
{
	if(objt.style.display=='')	
		objt.style.display='none';
	else
		objt.style.display='';
}

var resultados;
function iniciaAjax(linksql, vars, div, acaoPosterior,semCarregando){
	var args = iniciaAjax.arguments.length;
	xmlhttp.open("POST", linksql, true);
	xmlhttp.onreadystatechange = function(){
		if (xmlhttp.readyState==4)
		{
			t = xmlhttp.responseText			
			resultados=t;		
			if (args >= 3) 
			{
				document.getElementById(div).innerHTML=unescape(resultados);	
			}
			if(acaoPosterior)
				setTimeout(acaoPosterior,1);
		}
	}
	if(!semCarregando)
		document.getElementById(div).innerHTML = "<img src='../images/carregando1.gif?1'/>";//peq
	xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlhttp.send(vars);
}

function iniciaAcao(linksql, vars){
	xmlhttp.open("POST", linksql, true);
	xmlhttp.onreadystatechange = function()
	{
		if (xmlhttp.readyState==4)
		{
			setTimeout(unescape(xmlhttp.responseText),1);
		}		
	}
	xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlhttp.send(vars);
}

function alerta(texto, titulo, naomostrarefeito)
{
	if(!naomostrarefeito)
		exibeEfeito();
	if(!titulo)
		titulo="";
	iniciaAjax('../page/_boxAlerta.asp','mensagem='+escape(texto.replace('\n','<BR>'))+'&titulo='+escape(titulo), 'divResultado');
}
function informar(texto, titulo, naomostrarefeito)
{
	if(!naomostrarefeito)
		exibeEfeito();
	if(!titulo)
		titulo="";
	iniciaAjax('../page/_boxInformacao.asp','mensagem='+escape(texto)+'&titulo='+escape(titulo), 'divResultado');
}

function iniciaPost(linksql,div,form,acaoPosterior)
{	
	try
	{				
		var vars="";
		for(var i = 0; i < form.elements.length; i++) 
		{
			if (form.elements[i].type == "checkbox"|| form.elements[i].type=="radio")
			{
				if(form.elements[i].checked)
					vars=vars + form.elements[i].name + "=" + escape(form.elements[i].value) + "&";
			}
			else
			{			
				vars=vars + form.elements[i].name + "=" + escape(form.elements[i].value) + "&";
				if (form.elements[i].type == "text") 
					form.elements[i].value = "";
			}			
		}
		while(vars.indexOf(" ")>=0)
		{
			vars=vars.replace(" ","%20");
		}			
		xmlhttp.open("POST", linksql, true);		
		xmlhttp.onreadystatechange = function()
		{
			if (xmlhttp.readyState==4)		
			{
				if(div)
				{
					var t = xmlhttp.responseText;
					t = unescape(t);
					document.getElementById(div).innerHTML=t;
				}
				if(acaoPosterior)
				{
					setTimeout(acaoPosterior,1);
				}
			}
		}
		xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xmlhttp.send(vars);		
		if(div)
			document.getElementById(div).innerHTML = strCarregando;
	}
	catch(e)
	{
	}
}

var divResultado;
var strCarregando='<table width="252" height="100" border="0" align="center"><tr><td width="252" height="100" align="center" valign="middle" class="texto_preto"><img src="../images/carregando_linhas1.gif?1"></td></tr></table>';
function exibeEfeito(valor,texto){
	var div, div2;	
	
	var tudo=document.getElementsByTagName("body")[0];
	tudo.scroll="no";		
	div2=document.createElement("div");
 	div2.id=("divJanela");
	tudo.appendChild(div2);	
	div=document.createElement("div");
 	div.id=("divResultado");	
	if(valor)
		div.style.marginLeft=valor;
	//div.innerHTML="<img src='../images/carregando1.gif?1'>"
	
 	tudo.appendChild(div);
	tudo.scrollTop=0;
	document.onkeydown=function(event){tecla(event)};
	divResultado=document.getElementById("divResultado");
	
	if(document.all)
		tudo.style.marginRight='17px';
	document.getElementById("divResultado").focus();
	document.getElementById("divResultado").innerHTML=strCarregando;
	
}
 
function apagaEfeito(){
	var tudo=document.getElementsByTagName("body")[0]
  	var div1 = document.getElementById("divResultado");
	var div2 = document.getElementById("divJanela");	
	div1.innerHTML="";
  	tudo.removeChild(div1);
	tudo.removeChild(div2);
	document.getElementsByTagName("html")[0].style.overflow="";
	if(document.all)
		tudo.style.marginRight='';
  	tudo.scroll="yes";	
	document.onkeydown='';
}  

function tecla(e){
	if (!e) 
		e = window.event;	

	if (e.keyCode==27)// || e.keyCode==13
	{
		apagaEfeito();
		document.onkeydown='';
	}
}
