 //controla a fila de carregamento das solicitações
//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;
        }
    }
}

//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){//sem o carregando
    //Carregando...
    document.getElementById(id).innerHTML="&nbsp;"
    //Adiciona à fila
    fila[fila.length]=[id,url]
    //Se não há conexões pendentes, executa
    if((ifila+1)==fila.length)ajaxRun()
}
function ajaxHTMLBlank(id,url){//sem o carregando
    //Carregando...
    //document.getElementById(id).innerHTML="&nbsp;"
    //Adiciona à fila
    fila[fila.length]=[id,url]
    //Se não há conexões pendentes, executa
    if((ifila+1)==fila.length)ajaxRun()
}
function ajaxHTMLon(id,url){//sem o carregando
    //Carregando...
    document.getElementById(id).innerHTML="carregando..."
    //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)
}

//fim do controle de carregamento




function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}




function resolucao(){
	
	total = screen.width;
	if(total > 800){
		valor = Math.round(((100-(77000/total))/2));
		
		document.getElementById('tabDireita').style.width = valor + '%';
	}
	}
	



//VENDAS
function buscaCategorias(codCidade){
	ajaxHTML('divCategorias','index.php?secao=divCategoria&cidade='+codCidade);
	ajaxHTML('divBairros','index.php?secao=divBairroVenda&cidade='+codCidade);
	
	}




//LOCACAO
function buscaBairros(codCidade){
	ajaxHTML('divBairros','index.php?secao=divBairros&cidade='+codCidade);
	
	}
function buscaBairrosAvan(codCidade){
	ajaxHTMLon('divBairrosAvan','index.php?secao=divBairrosAvan&cidade='+codCidade);
	
	}
function buscaTipo(codOcu){
	ajaxHTML('divTipoImovel','index.php?secao=divTipoImovel&ocupacao='+codOcu);
	
	
	}
function buscaTipoAvan(codOcu){
	ajaxHTML('divTipoImovelAvan','index.php?secao=divTipoImovelAdv&ocupacao='+codOcu);
	//document.getElementById('qtDormitorios').disabled = true;
	
	}
	
function buscaVendaAvan(cidade){
	ajaxHTML('divCategoriaAdv','index.php?secao=divCategoriaAdv&cidade='+cidade);
	ajaxHTML('divBairroVendaAdv','index.php?secao=divBairroVendaAdv&cidade='+cidade);
	
	}	

function MarcaTodos(){ 
   for (i=0;i<document.formBuscaAvan.elements.length;i++) 
      if(document.formBuscaAvan.elements[i].type == "checkbox"){
	 if(document.formBuscaAvan.elements[i].id == 'bairro')
         document.formBuscaAvan.elements[i].checked=1 ;
		
}
}
function DesmarcaTodos(){ 
   for (i=0;i<document.formBuscaAvan.elements.length;i++) 
      if(document.formBuscaAvan.elements[i].type == "checkbox"){
	 	if(document.formBuscaAvan.elements[i].id == 'bairro')
         document.formBuscaAvan.elements[i].checked=0 ;
		 
	  }
		 
}
function MarcaTodosCat(){ 
   for (i=0;i<document.formBuscaAvan.elements.length;i++) 
      if(document.formBuscaAvan.elements[i].type == "checkbox"){
	 if(document.formBuscaAvan.elements[i].id == 'categoria')
         document.formBuscaAvan.elements[i].checked=1 ;
		
}
}
function DesmarcaTodosCat(){ 
   for (i=0;i<document.formBuscaAvan.elements.length;i++) 
      if(document.formBuscaAvan.elements[i].type == "checkbox"){
	 	if(document.formBuscaAvan.elements[i].id == 'categoria')
         document.formBuscaAvan.elements[i].checked=0 ;
		 
	  }
		 
}


function MarcaTodosTipo(){ 
   for (i=0;i<document.formBuscaAvan.elements.length;i++) 
      if(document.formBuscaAvan.elements[i].type == "checkbox"){
	 if(document.formBuscaAvan.elements[i].id == 'tipoImovel')
         document.formBuscaAvan.elements[i].checked=1 ;
		
}
}
function DesmarcaTodosTipo(){ 
   for (i=0;i<document.formBuscaAvan.elements.length;i++) 
      if(document.formBuscaAvan.elements[i].type == "checkbox"){
	 	if(document.formBuscaAvan.elements[i].id == 'tipoImovel')
         document.formBuscaAvan.elements[i].checked=0 ;
		 
	  }
		 
}


function CarregaServicos(login,senha){
	
	ajaxHTMLon('divServicos','clienteonline/prg/crLogin.php?LOGIN='+login+'&SENHA='+senha);
	
	}

function Dicas(id){
	var id;
	ajaxHTMLon('dicas_'+id,'index.php?secao=carregadica&id_duvida='+id);
	
	}
	
function enviaViaEmail(id){
	var id;
	ajaxHTML('divEmail','templates/emailPop.htm');
	
	}

function enviaEmailPop(){
	
	ajaxHTML('divEmail','acao.php?secao=popEmail&emailnome='+document.getElementById('emailnome').value+'&emailemail='+document.getElementById('emailemail').value+'&tipo='+document.getElementById('emailtipo').value+'&id='+document.getElementById('emailid').value);
	
	ajaxHTML('divEmail','templates/emailPopOk.htm');
	}
	
function loginPop(id){
	var id;
	ajaxHTML('divLoginPop','templates/loginPop.htm');
	
	}
function Limpa(id){
	var id;
	ajaxHTMLBlank(id,'templates/blank.htm');
	
	}
function buscaPersonalizada(){
	
	ajaxHTML('divBuscaPersonalizada','templates/popBuscaPersonalizada.htm');
	
	}

function enviaBuscaPersonalizada(){
	ajaxHTML('divBuscaPersonalizada','acao.php?secao=popBuscaPersonalizada&buscanome='+document.getElementById('buscanome').value+'&buscaemail='+document.getElementById('buscaemail').value+'&buscatelefone='+document.getElementById('buscatelefone').value+'&buscamensagem='+document.getElementById('buscamensagem').value);
	
	
	ajaxHTML('divBuscaPersonalizada','templates/popBuscaPersonalizadaOk.htm');
	
	}

function AbrePop(){
	
		window.open('','popCompara','scrollbars=yes,resizable=yes,width=750,height=650');
	}
	
	
function AbreDetalhes(id){
	
		window.open('index.php?secao=locacoes&modulo=detalhes&codigo='+id,'popCompara','scrollbars=yes,resizable=no,width=750,height=650');
	}
	
function enviaComparacao(){
	document.getElementById('fCompara').submit();
	
	}
<!-- Início da Funçao FormataReais -->

function FormataReais(fld, milSep, decSep, e) {

var sep = 0;

var key = '';

var i = j = 0;

var len = len2 = 0;

var strCheck = '0123456789';

var aux = aux2 = '';

var whichCode = (window.Event) ? e.which : e.keyCode;

if (whichCode == 13) return true;

key = String.fromCharCode(whichCode);// Valor para o código da Chave

if (strCheck.indexOf(key) == -1) return false; // Chave inválida

len = fld.value.length;

for(i = 0; i < len; i++)

if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;

aux = '';

for(; i < len; i++)

if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);

aux += key;

len = aux.length;

if (len == 0) fld.value = '';

if (len == 1) fld.value = '0'+ decSep + '0' + aux;

if (len == 2) fld.value = '0'+ decSep + aux;

if (len > 2) {

aux2 = '';

for (j = 0, i = len - 3; i >= 0; i--) {

if (j == 3) {

aux2 += milSep;

j = 0;

}

aux2 += aux.charAt(i);

j++;

}

fld.value = '';

len2 = aux2.length;

for (i = len2 - 1; i >= 0; i--)

fld.value += aux2.charAt(i);

fld.value += decSep + aux.substr(len - 2, len);

}

return false;

}

function txtBoxFormat(objForm, strField, sMask, evtKeyPress) {
var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;

if(document.all) { // Internet Explorer
nTecla = evtKeyPress.keyCode; }
else if(document.layers) { // Nestcape
nTecla = evtKeyPress.which;
} else if(document.getElementById) { // FireFox
nTecla = evtKeyPress.which;
}

sValue = objForm[strField].value;

// Limpa todos os caracteres de formataçao que
// já estiverem no campo.
sValue = sValue.toString().replace( "-", "" );
sValue = sValue.toString().replace( "-", "" );
sValue = sValue.toString().replace( ".", "" );
sValue = sValue.toString().replace( ".", "" );
sValue = sValue.toString().replace( "/", "" );
sValue = sValue.toString().replace( "/", "" );
sValue = sValue.toString().replace( "(", "" );
sValue = sValue.toString().replace( "(", "" );
sValue = sValue.toString().replace( ")", "" );
sValue = sValue.toString().replace( ")", "" );
sValue = sValue.toString().replace( " ", "" );
sValue = sValue.toString().replace( " ", "" );
fldLen = sValue.length;
mskLen = sMask.length;

i = 0;
nCount = 0;
sCod = "";
mskLen = fldLen;

while (i <= mskLen) {
bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/"))
bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))

if (bolMask) {
sCod += sMask.charAt(i);
mskLen++; }
else {
sCod += sValue.charAt(nCount);
nCount++;
}

i++;
}

objForm[strField].value = sCod;

if (nTecla != 8) { // backspace
if (sMask.charAt(i-1) == "9") { // apenas números...
return ((nTecla > 47) && (nTecla < 58)); } // números de 0 a 9
else { // qualquer caracter...
return true;
} }
else {
return true;
}
}


function Seleciona(id){
	var id;
	
	document.getElementById(id).style.background = '#8D882E';
	document.getElementById(id).style.color = '#FFFFFF';
	
	}
function DesSeleciona(id){
	var id;
	
	document.getElementById(id).style.background = '#F1F1F1';
	document.getElementById(id).style.color = '#006699';
	}

function limpaBox(id){
	document.getElementById(id).value = '';
	
	}

function abrePesquisa(){
	MM_openBrWindow('index.php?secao=pesquisaSatisfacao','','scrollbars=yes,resizable=no,width=690,height=500')
	
	}

function abreNoticia(id){
	MM_openBrWindow('index.php?secao=noticias&id_noticia='+id,'','scrollbars=yes,resizable=no,width=690,height=500')
	
	}

function carlosgomes(){
	
	MM_openBrWindow('destaques/carlosgomes/','','scrollbars=no,resizable=no,width=630,height=675')
	
	}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_nbGroup(event, grpName) { //v6.0
var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])?args[i+1] : img.MM_up);
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) { img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    nbArr = document[grpName];
    if (nbArr) for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
      nbArr[nbArr.length] = img;
  } }
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
