//Tenta criar o objeto xmlHTTP
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 ajaxInit() {
var req;

try {
 req = new ActiveXObject("Microsoft.XMLHTTP");
} catch(e) {
 try {
  req = new ActiveXObject("Msxml2.XMLHTTP");
 } catch(ex) {
  try {
   req = new XMLHttpRequest();
  } catch(exc) {
   alert("Esse browser não tem recursos para exibição deste sistema");
   req = null;
  }
 }
}

return req;
}
//Fila de conexões
fila=[]
ifila=0

//Carrega via XMLHTTP a url recebida e coloca seu valor
//no objeto com o id recebido
function ajaxHTML(id,url,msg){
    //Carregando...
    document.getElementById(id).innerHTML="<div class='carregando'><p class='porfavor'>"+msg+"</div>"
    //Adiciona à fila
    fila[fila.length]=[id,url]
    //Se não há conexões pendentes, executa
    if((ifila+1)==fila.length)ajaxRun()
}

//Executa a próxima conexão da fila
function ajaxRun(){
    //Abre a conexão
    xmlhttp.open("GET",fila[ifila][1],true);
    //Função para tratamento do retorno
    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4){
            //Mostra o HTML recebido
            retorno=unescape(xmlhttp.responseText.replace(/\+/g," "))
            document.getElementById(fila[ifila][0]).innerHTML=retorno
            //Roda o próximo
            ifila++
            if(ifila<fila.length)setTimeout("ajaxRun()",20)
        }
    }
    //Executa
    xmlhttp.send(null)
}

function cidRevendas(sel) {
	cid=sel.options[sel.selectedIndex].value;
	ajaxHTML('rev','revendas_cid_lst.php?cidade='+cid,'Aguarde enquanto as revendas são carregadas...');
}

function catClassificados(sel) {
	cat=sel.options[sel.selectedIndex].value;
	ajaxHTML('classi','classi_lista.php?classi_cat='+cat,'Aguarde enquanto os anúncios são carregadas...');
}

function catClassificados2(sel) {
	cat=sel.options[sel.selectedIndex].value;
	location.href='?pag=classi_anuncios.php&classi_cat='+cat;
}

function catGuia(sel) {
	cat=sel.options[sel.selectedIndex].value;
	ajaxHTML('guia','guia_lista.php?guia_cat='+cat,'Aguarde enquanto a categoria é carregada...');
}

function catGuia2(sel) {
	cat=sel.options[sel.selectedIndex].value;
	location.href='?pag=guia.php&guia_cat='+cat;
}

function validaBusca(cp) {
	if (cp=='') {
		alert('Campo de Busca não pode ser nulo!');
		return false;
	} else document.frm.submit();
}

function validaLogin(lg,ps) {
	if (lg=='') {
		alert('Campo Login não pode ser nulo!');
		document.frm.login.focus();
		return false;
	} else if (ps=='') {
		alert('Campo Senha não pode ser nulo!');
		document.frm.senha_form.focus();
		return false;
	} else document.frm.submit();
}