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 criarXMLHttpRequest()
{
   try{ return new ActiveXObject("Msxml2.XMLHTTP"); }catch(e){}
   try{ return new ActiveXObject("Microsoft.XMLHTTP"); }catch(e){}
   try{ return new XMLHttpRequest(); }catch(e){}
   alert("XMLHttpRequest not supported");
   return null;
}
var XHR_criado = criarXMLHttpRequest();
var xmlhttp = criarXMLHttpRequest();

function pegaFormDados(form) {
get = document.getElementById(form);
count = get.length;
send = ""; 
for(i=0 ; i<=count-1;i++) {
	valor  = get.elements[i].value;
	campo  = get.elements[i].name;
	tipo   = get.elements[i].type;
	if (tipo=="checkbox"||tipo=="radio") {
	  if (tipo=="checkbox")  {
		valor = get.elements[i].checked;
	  }
	  if (tipo=="radio") {
		if (get.elements[i].checked==false) {
		   continue;
		}
	  }
	}

	if(i==count-1) {
	   send += campo+"="+valor;
	} else {
	  send += campo+"="+valor+"&";
	}
 }
 return send;
}

function mostrarDados(url,urlBack,nome_form) {
  send = pegaFormDados(nome_form);
  enviarDados(url,send,urlBack);
}
function enviarDados(url,send,urlBack)  {
    XHR_criado.open("post",url,true);
    XHR_criado.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    XHR_criado.setRequestHeader('Cache-Control', 'no-store, no-cache, must-revalidate');
    XHR_criado.onreadystatechange = SaidaHttpPOST;
    XHR_criado.send(send);
    function SaidaHttpPOST() {
      if(XHR_criado.readyState!=4) {
	    document.getElementById("conteudo").innerHTML= "<div><table border='0' width='100%' height='100%'><tr><td align='center' valign='middle'><img src='img/loading4.gif'></td></tr></table></div>";
	  }
	  if(XHR_criado.readyState==4) {
	    //document.getElementById("conteudo").innerHTML= XHR_criado.responseText;
		carrega(urlBack);		
	  }
    }
}

function mostrarDados_fica(url,urlBack,nome_form) {
  send = pegaFormDados(nome_form);
  enviarDados_fica(url,send,urlBack);
}
function enviarDados_fica(url,send,urlBack)  {
    XHR_criado.open("post",url,true);
    XHR_criado.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    XHR_criado.setRequestHeader('Cache-Control', 'no-store, no-cache, must-revalidate');
    XHR_criado.onreadystatechange = SaidaHttpPOST_fica;
    XHR_criado.send(send);
    function SaidaHttpPOST_fica() {
      if(XHR_criado.readyState!=4) {
	    document.getElementById("conteudo").innerHTML= "<div><br><br><br><table border='0' width='100%' height='100%'><tr><td align='center' valign='middle'><img src='img/loading4.gif'></td></tr></table></div>";
	  }
	  if(XHR_criado.readyState==4) {
	    document.getElementById("conteudo").innerHTML= XHR_criado.responseText;
		//carrega(urlBack);		
	  }
    }
}
function carrega(prog,id){ 
    
	 if(id==null) {
      var conteudo=document.getElementById("conteudo");
     } else {
      var conteudo=document.getElementById(id);
     } 
    
	conteudo.innerHTML="<div><br><br><br><table border='0' width='100%' height='100%'><tr><td align='center' valign='middle'><img src='img/loading4.gif'></td></tr></table></div>"
	
    xmlhttp.open("GET", prog,true);
    xmlhttp.setRequestHeader('Cache-Control', 'no-store, no-cache, must-revalidate');
    xmlhttp.setRequestHeader('Pragma', 'no-cache');
    xmlhttp.onreadystatechange=function() {
    if (xmlhttp.readyState==4) {
        var texto=xmlhttp.responseText
        texto=texto.replace(/\+/g," ")
        texto=unescape(texto)
		if(id==null) {
		  var conteudo=document.getElementById("conteudo");
		} else {
		  var conteudo=document.getElementById(id);
		} 
		conteudo.innerHTML=texto
        }
    }
    xmlhttp.send(null)
}

function carrega_menu(prog,id){ 


    carrega(prog);
}

function mOverLink(src){
  src.style.cursor = "pointer";
  src.style.textDecoration = "underline";
}
function mOutLink(src){
  src.style.cursor = "default";
  src.style.textDecoration = "none";
}
function valida_contato(url,urlBack,nome_form) {
	
	if (document.formulario.nome.value == "") {
	  alert ("Nome deve ser preenchido.");
	  return;
	}
	if (document.formulario.email.value == "") {
	  alert ("E-mail deve ser preenchido.");
	  return;
	}
	if (document.formulario.assunto.value == "") {
	  alert ("Assunto deve ser preenchido.");
	  return;
	}
	if (document.formulario.mensagem.value == "") {
	  alert ("Mensagem deve ser preenchido.");
	  return;
	}

	mostrarDados_fica(url,urlBack,nome_form)
}

function abreBusca(id) {
 if (document.getElementById(id).style.display=="block") {
   document.getElementById(id).style.display="none";
   document.getElementById("bs_a").style.backgroundColor = "";
   document.getElementById("bs_c").innerHTML = "<span class='style1'>b</span>uscar";
 } else {
   document.getElementById(id).style.display="block";
   document.getElementById("bs_a").style.backgroundColor = "#CCCCCC";
   document.getElementById("bs_c").innerHTML = "<span class='style1'>buscar</span>";
 }
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function vender() { //v3.0
  if (document.getElementById("selectopcao").value == "vender") {
	carrega("contato.asp");  
  }
}



