function carga(tipo,elemento){

	if ( typeof tipo == 'undefined' ) {
		tipo = 'false'; }
		
	if (document.getElementById("carga"))
		{
		if (tipo=='true') { 
			 //alert(document.getElementById("carga").style.display);
			 if (document.getElementById("carga").style.display=="none")
    			document.getElementById("carga").style.display=""
			 else document.getElementById("carga").style.display="none";
			 }
		else {	
			if ( typeof elemento == 'undefined' ) 
				 {//document.getElementById("carga").style.display="none";
				 }
			else { 
				 //if (elemento.style.display=="none")
				// 	  {
				 	  elemento.innerHTML="<center><img border='0' src='http://www.abracors.org.br/images/loading.gif' hspace=4>carregando...</center>";		
			 		  elemento.style.display="";
				 //	  }
				 //else {//elemento.style.display="none";
				 //	  }
				 }	
			 }
		}
}



function fechardiv(elemt){
	document.getElementById(elemt).style.display='none';
}


function proc_http(asp,elemento,tcarga, fecha)
{ 

	if ( typeof tcarga == 'undefined' ) {tcarga = 'false';}		
	if ( typeof fecha == 'undefined' )  { fecha  = 'false'; }

    var XMLHttp=null
    if (window.XMLHttpRequest)
        {XMLHttp=new XMLHttpRequest()}
    else if (window.ActiveXObject)
        {XMLHttp=new ActiveXObject("Microsoft.XMLHTTP")}
    if (XMLHttp==null) {
        alert ("Browser does not support HTTP Request")
        return } 
    elmt=document.getElementById(elemento);	
	carga(tcarga,elmt);
    XMLHttp.open("POST",asp,false)
    XMLHttp.send(asp) 
    if (elmt!=null)
       { 
	    elmt.innerHTML=XMLHttp.responseText;
		if (fecha=='true'){
		
			setTimeout("fechardiv('"+elemento+"')",500);
			}
		else 	     
		   if (elmt.innerHTML!='')
	   	   	  {
				var vTxt = elmt.innerHTML;
				if (vTxt.indexOf("#login#")==0) 
					location.href='login.asp?T=LE';
				else 		
					elmt.style.display='';	   
			  }
	   } 

	if (tcarga=='true')
		setTimeout("carga('true')",300);
	else setTimeout("carga('false')",300);

}

function buildPOST(theFormName) 
{ 
    theForm = document.forms[theFormName]; 
    var qs = '' 
    for (e=0;e<theForm.elements.length;e++) { 
        if ((theForm.elements[e].name!='')&&(theForm.elements[e].type!=null)) {
	        if ((theForm.elements[e].type.toLowerCase()=='checkbox')||(theForm.elements[e].type.toLowerCase()=='radio')) {
				if (theForm.elements[e].checked) {
    	        	var name = theForm.elements[e].name;
        	    	qs+=(qs=='')?'':'&'
            		qs+= name+'='+escape(theForm.elements[e].value);
				}
			} else {
    	        var name = theForm.elements[e].name;
        	    qs+=(qs=='')?'':'&'
            	qs+= name+'='+escape(theForm.elements[e].value);
			}
        }
    }
    qs+="\n";
    return qs 
}

function proc_form(asp,elemento,form)
{ 
    var xmlMessage = buildPOST(form); 
    var XMLHttp=null
    if (window.XMLHttpRequest)
        {XMLHttp=new XMLHttpRequest()}
    else if (window.ActiveXObject)
        {XMLHttp=new ActiveXObject("Microsoft.XMLHTTP")}
    if (XMLHttp==null) {
        alert ("Browser does not support HTTP Request")
        return } 
    elmt=document.getElementById(elemento)
	elmt.innerHTML="<center><br><br><br><img border='0' alt='' src='images/indicator.gif'></center>";	
	elmt.style.display='';	
	
    XMLHttp.open("POST",asp,false)
    XMLHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    XMLHttp.send(xmlMessage)
    if (elmt!=null) 
		{ 	
		elmt.innerHTML=XMLHttp.responseText; 
		if (elmt.innerHTML!='')
			elmt.style.display='';			
		}
}

function proc_http_param(asp,elemento,param)
{ 
    var XMLHttp=null
    if (window.XMLHttpRequest)
        {XMLHttp=new XMLHttpRequest()}
    else if (window.ActiveXObject)
        {XMLHttp=new ActiveXObject("Microsoft.XMLHTTP")}
    if (XMLHttp==null) {
        alert ("Browser does not support HTTP Request")
        return } 
    XMLHttp.onreadystatechange=function() { if (XMLHttp.readyState == 4||XMLHttp.readyState=="Complete")
                                                { proc_http_dados(asp,elemento,XMLHttp.responseText) } } 
    XMLHttp.open("POST",param,true)
    XMLHttp.send(param) //null
}

function proc_http_dados(asp,elemento,param,fecha)
{ 
	if ( typeof fecha == 'undefined' )  { fecha  = 'false'; }

	carga();
    var XMLHttp=null
    if (window.XMLHttpRequest)
        {XMLHttp=new XMLHttpRequest()}
    else if (window.ActiveXObject)
        {XMLHttp=new ActiveXObject("Microsoft.XMLHTTP")}
    if (XMLHttp==null) {
        alert ("Browser does not support HTTP Request")
        return } 
		
    elmt=document.getElementById(elemento);
    if (elmt==null) {
        alert ("Elemento não encontrado")
        return } 
		
	elmt.innerHTML="<center><br><br><br><img border='0' alt='' src='../images/indicator.gif'></center>";
	elmt.style.display='';		
		
//    param='?'+param
    XMLHttp.open("POST",asp,false)
//    XMLHttp.setRequestHeader('encoding','ISO-8859-1');     
    XMLHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 
//    XMLHttp.setRequestHeader("Content-length", param.length);
//    XMLHttp.setRequestHeader("Connection", "close");
   	XMLHttp.send(param) //param
   	elmt.innerHTML=XMLHttp.responseText;
	
	if (fecha=='true'){
		elmt.style.display='none';
		}	
	else 
		if (elmt.innerHTML!='')
			elmt.style.display='';
	setTimeout("carga()",300);		
}

function proc_http_le_dados(asp,elemento,param,tcarga,fecha)
{ 
	if ( typeof tcarga == 'undefined' ) { tcarga = 'false'; }
	if ( typeof fecha == 'undefined' )  { fecha  = 'false'; }

    var XMLHttp=null;
    if (window.XMLHttpRequest)
        {XMLHttp=new XMLHttpRequest();}
    else if (window.ActiveXObject)
        {XMLHttp=new ActiveXObject("Microsoft.XMLHTTP");}
    if (XMLHttp==null) {
        alert ("Browser does not support HTTP Request");
        return; } 
    elmt=document.getElementById(elemento);
    if (elmt==null) {
        alert ("Elemento não encontrado");
        return; } 
	carga(tcarga,elmt);		
//	elmt.innerHTML="<center><br><br><br><img border='0' alt='' src='images/indicator.gif'></center>";	
//	elmt.style.display='';		
    XMLHttp.open("POST",asp,false);
    XMLHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 
   	XMLHttp.send(asp);
	elmt.innerHTML=XMLHttp.responseText;


	if (fecha=='true'){
		elmt.style.display='none';
		}
	else 		
		if (elmt.innerHTML!='') 
			elmt.style.display='';
		
	if (tcarga=='true')   
		setTimeout("carga('true')",1600);
	else setTimeout("carga('false')",1600);
		
}

function proc_http_le_dados2(asp,elemento,param,tcarga,fecha)
{ 
	if ( typeof tcarga == 'undefined' ) { tcarga = 'false'; }
	if ( typeof fecha == 'undefined' )  { fecha  = 'false'; }

    var XMLHttp=null;
    if (window.XMLHttpRequest)
        {XMLHttp=new XMLHttpRequest();}
    else if (window.ActiveXObject)
        {XMLHttp=new ActiveXObject("Microsoft.XMLHTTP");}
    if (XMLHttp==null) {
        alert ("Browser does not support HTTP Request");
        return; } 
    elmt=document.getElementById(elemento);
    if (elmt==null) {
        alert ("Elemento não encontrado");
        return; } 
	carga(tcarga,elemento);		
//	elmt.innerHTML="<center><br><br><br><img border='0' alt='' src='images/indicator.gif'></center>";	
//	elmt.style.display='';		
    XMLHttp.open("POST",asp,false);
    XMLHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 
   	XMLHttp.send(asp);
	elmt.innerHTML=XMLHttp.responseText;

//	alert('-' + elmt.innerHTML +'-');
	
	if (fecha=='true'){
		elmt.style.display='none';
		}
	else 		
		if (elmt.innerHTML!='') 
			elmt.style.display='';
		else
			elmt.style.display='none';				
			
	if (tcarga=='true')   
		setTimeout("carga('true')",1600);
	else setTimeout("carga('false')",1600);
		
}

function proc_http_princ(asp,elemento){
	setTimeout("proc_http('"+asp+"','"+elemento+"');",100);
}


var fila=[];
var ifila=0;
var vatprevia="T";

function proc_http_p(url,destino,form)
{
	if(destino!=Object){
		destino = document.getElementById(destino);
	}
	carga();		
	fila[fila.length]=[url,destino];
	if((ifila+1)==fila.length) {
		setTimeout("ajaxRun()",1); 	}
	setTimeout("carga()",300);
}

function ajaxRun(){
	url = fila[ifila][0];
	destino = fila[ifila][1];
    var XMLHttp=null;  
	
	if (window.XMLHttpRequest)
        {XMLHttp=new XMLHttpRequest();}
    else if (window.ActiveXObject)
        {XMLHttp=new ActiveXObject("Microsoft.XMLHTTP");}
    if (XMLHttp==null) {
        alert ("Browser does not support HTTP Request");
        return; } 

    XMLHttp.open("POST",url,true);// padrao estava false (IE) mas Firefox requer true

	XMLHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=ISO-8859-1");
	XMLHttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
	XMLHttp.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
	XMLHttp.setRequestHeader("Pragma", "no-cache");


	XMLHttp.onreadystatechange=function() {
		if (XMLHttp.readyState==4){
			switch(XMLHttp.status){
				case 200: { 
					ajaxShow(XMLHttp.responseText,destino); 						
					break; }
				}
			ifila++;
			if(ifila<fila.length)ajaxRun();}
		} 		
	XMLHttp.send(url);//xmlMessage);//url);
	
}

function ajaxShow(valor,destino){
	if(destino.nodeName=="SELECT"){
		while(destino.options.length>0)destino.options[0]=null;
		if(valor.charAt(0)=="[" && valor.charAt(valor.length-1)=="]"){
			var destinoTmp=eval(valor);
			for(var i=0;i<destinoTmp.length;i++){
				destinoTmp[i][0]=unescape(destinoTmp[i][0]);
				destinoTmp[i][1]=unescape(destinoTmp[i][1]);
				destino.options[destino.options.length]=new Option(destinoTmp[i][1],destinoTmp[i][0]);
			}
		} else {
			destino.options[destino.options.length]=new Option(valor,valor);
		}
	} else {
		destino.innerHTML = unescape(valor.replace(/\+/g," ")); 
	}
}
/////////////////