try{
	xmlhttp = new XMLHttpRequest();
}catch(ee){
	try{
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	}catch(e){
		try{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}catch(E){
			xmlhttp = false;
		}
	}
}

fila=[];
ifila=0;


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='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(url, destino){
	if(destino!=Object){
		destino = document.getElementById(destino);
	}
		destino.innerHTML="<center><img border='0' alt='' src='images/loading.gif'></center>";
	fila[fila.length]=[url,destino];
	if((ifila+1)==fila.length)ajaxRun();
}

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 = valor; 
	}
}

function ajaxRun(){
	url = fila[ifila][0];
	destino = fila[ifila][1];
	xmlhttp.open("GET", url, 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)setTimeout("ajaxRun()",30);
		}
	}
	xmlhttp.send(url);
}

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/loading.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/loading.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,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;

//	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 validaemail(email1) {
		var email  = /^[A-Za-z]([\w\.\-]*)@([A-Za-z0-9\.\-]*)\.(([A-Za-z]{3}\.[A-Za-z]{2}$)|([A-Za-z]{3}$)|([a-z]{2}$))/i ;
		return email.test(email1);
}

function EnviaNews(form)
	{
	var e="N";
	if ((form.email.value == "") && (e == "N"))
        {
	     e="S";
         alert("Preencha seu Email!");
         form.email.focus();
        }
	if ((validaemail(form.email.value)==false) && (e == "N"))
		{
	     e="S";
         alert("O Email fornecido não é válido");
         form.email.focus();		
		}

	if (e=="N")
		{
		 form.submit();	 	 
		 }
}