
try{
    xmlhttp = new XMLHttpRequest();
}catch(ee){
    try{
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }catch(e){
        try{
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }catch(E){
            xmlhttp = false;
        }
    }
}


atual=0

function itensCategria(ct){
    xmlhttp.open("GET", 'ajaxItensCategoria.php?ct='+ct,true);
    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4){

            var texto=xmlhttp.responseText
            texto=unescape(texto)

            if(texto!='erro')
            {
                if(texto.length > 0)
                {
                    var texto = texto.split("|#|");

                    if(texto[1].length > 0)
                    {
                        var opcoes = texto[1].split("|");
                        if(opcoes.length > 0){
                            for (i=0;i<=opcoes.length-1;i++)
                                setDisplay("div_"+opcoes[i]+"",'none')
                        }
                    }
                    if(texto[0].length > 0)
                    {
                        var opcoes = texto[0].split("|");
                        for (i=0;i<=opcoes.length-1;i++)
                            setDisplay("div_"+opcoes[i]+"",'block')
                    }
                }
                subtipos = $('imoveis_subtipo');
                imoveis_tipo = $('imoveis_tipo');

                if( subtipos.options[subtipos.selectedIndex].value == '3'
                && imoveis_tipo.options[imoveis_tipo.selectedIndex].value == '2'){
                    setDisplay("div_imoveis_dt_fim_valor_1","block");
                    setDisplay("div_imoveis_dt_fim_valor_2","block");
                    setDisplay("div_imoveis_valor_iptu","none");

                    el = $("div_imoveis_valor_condominio");
                    el.childNodes[1].innerHTML = "Valor:";
                }else{
                    setDisplay("div_imoveis_dt_fim_valor_1","none");
                    setDisplay("div_imoveis_dt_fim_valor_2","none");
                    setDisplay("div_imoveis_valor_iptu","block");

                    el = $("div_imoveis_valor_condominio");
                    el.childNodes[1].innerHTML = "Valor do Condomínio:";
                }
pessoa();

            }
            else
            {
                return null;
            }
        }
    }
    xmlhttp.send(null)
}

function categorias(ct,pk){
    xmlhttp.open("GET", 'ajaxImoveisSubcat.php?ct='+ct+'&pk='+pk,true);
    xmlhttp.onreadystatechange=function() {

        if (xmlhttp.readyState==4){

            var texto=xmlhttp.responseText
            texto=unescape(texto)

            if(texto!='erro')
            {
                if(texto.length > 0)
                {
                    opcoes = texto.split("][");
                    categ = $('imoveis_categoria');
                    i=categ.options.length;
                    while(i > 1){
                        categ.removeChild(categ.options[i-1]);
                        i--;
                    }

                    for (i=0;i<=opcoes.length-1;i++)
                    {
                        var item = opcoes[i].split("|");
                        categ.options[i+1] = new Option(item[1],item[0]);
                    }

            		//tipo = $("imoveis_tipo");/*2*/
pessoa();

                }
            }
            else
            {
                return null;
            }
        }
    }
    xmlhttp.send(null)
}


function climatempo(uf,div)
{
    //acessa o php comparamtro estado q retornara cidades
    xmlhttp.open("GET", 'ajaxClimatempo.php?uf='+uf+'&div='+div+' ',true);
    xmlhttp.onreadystatechange=function()
    {
        if (xmlhttp.readyState==4)
        {
            var texto=xmlhttp.responseText
            texto=unescape(texto)

            //verifica se retornou erro
            if(texto!='erro')
            {
                if(texto.length > 0)
                {
                    //preenche cidades
                    $('div_'+div).innerHTML=texto;
                }
            }
            else
            {
                return null;
            }
        }
    }
    xmlhttp.send(null)
}


function verifica_cep(CEP){
    if(CEP.length == 8 ){preencheformulario( 'ajaxCeps.php?cep='+CEP );}else{
    $("msg_form").innerHTML='Para fazer busca pelo CEP é nescessario preencher os 8 digitos do CEP';
    $("msg_form").style.color='red';
    }
}
function verifica_cepImoveis(CEP){
    if(CEP.length == 8 ){preencheformularioImoveis( 'ajaxCepsImoveis.php?cep='+CEP );}else{
    $("msg_form").innerHTML='Para fazer busca pelo CEP é nescessario preencher os 8 digitos do CEP';
    $("msg_form").style.color='red';
    }
}
function preencheformularioImoveis(file){

    //Guarda a página escolhida na variável atual
    atual=file
    $("msg_form").innerHTML='Carregando dados do CEP! Aguarde...<img src="imagens/carregando.gif" alt=""carregando">';
    $("msg_form").style.color='blue';
    //Abre a url
    xmlhttp.open("GET", file,true);

    //Executada quando o navegador obtiver o código
    xmlhttp.onreadystatechange=function() {

        if (xmlhttp.readyState==4){

            //Lê o texto
            var texto=xmlhttp.responseText

            //Desfaz o urlencode
            //texto=texto.replace(/\+/g," ")
            texto=unescape(texto)
            /*
            cidade=
            estado=
            bairro=
            logradouro=
            */
            if(texto!='erro')
            {
                //alert(texto);
                separados   = texto.split("&!&");
                estado      = separados[0]
                bairro      = separados[1]
                logradouroTipo  = separados[2]
                logradouro  = separados[3]
                cidade      = separados[4];


                if(bairro!='undefined')
                    $("imoveis_bairro").value=bairro;

                if(logradouro!='undefined')
                    $("imoveis_logradouro").value=logradouro;

                $("imoveis_logradourotipo").value='';
                if(logradouroTipo!='undefined')
                    $("imoveis_logradourotipo").value=logradouroTipo;
//alert(logradouroTipo);
                if(estado!='undefined')
                    $("imoveis_estado").value=estado;

                if(cidade!='undefined')
                    $("div_cidade").innerHTML=unescape(cidade);

                $("msg_form").innerHTML='CEP encontrado! Caso nescess&aacute;rio altere os campos abaixo!';
                $("msg_form").style.color='green';

            }
            else
            {
                    $("msg_form").innerHTML='CEP n&atilde;o encontrado! Preencha os campos abaixo!';
                    $("cada_cidade").value = '';
                    $("cada_estado").value = '';
                    $("cada_logradouro").value = '';
                    $("cada_bairro").value = '';
                    $("msg_form").style.color='red';
            }
        }
    }
    xmlhttp.send(null)
}

function preencheformulario(file){

    //Guarda a página escolhida na variável atual
    atual=file
    $("msg_form").innerHTML='Carregando dados do CEP! Aguarde...<img src="imagens/carregando.gif" alt=""carregando">';
    $("msg_form").style.color='blue';
    //Abre a url
    xmlhttp.open("GET", file,true);

    //Executada quando o navegador obtiver o código
    xmlhttp.onreadystatechange=function() {

        if (xmlhttp.readyState==4){

            //Lê o texto
            var texto=xmlhttp.responseText

            //Desfaz o urlencode
            //texto=texto.replace(/\+/g," ")
            texto=unescape(texto)
            /*
            cidade=
            estado=
            bairro=
            logradouro=
            */
            if(texto!='erro')
            {
                //alert(texto);
                separados   = texto.split("&!&");
                estado      = separados[0]
                bairro      = separados[1]
                logradouroTipo  = separados[2]
                logradouro  = separados[3]
                cidade      = separados[4];


                if(bairro!='undefined')
                    $("cada_bairro").value=bairro;

                if(logradouro!='undefined')
                    $("cada_logradouro").value=logradouro;

                $("cada_logradourotipo").value='';
                if(logradouroTipo!='undefined')
                    $("cada_logradourotipo").value=logradouroTipo;
//alert(logradouroTipo);
                if(estado!='undefined')
                    $("cada_estado").value=estado;

                if(cidade!='undefined')
                    $("div_cidade").innerHTML=unescape(cidade);

                $("msg_form").innerHTML='CEP encontrado! Caso nescess&aacute;rio altere os campos abaixo!';
                $("msg_form").style.color='green';

            }
            else
            {
                    $("msg_form").innerHTML='CEP n&atilde;o encontrado! Preencha os campos abaixo!';
                    $("cada_cidade").value = '';
                    $("cada_estado").value = '';
                    $("cada_logradouro").value = '';
                    $("cada_bairro").value = '';
                    $("msg_form").style.color='red';
            }
        }
    }
    xmlhttp.send(null)
}

function carregaNoReplace(file,div)
{

    //Exibe o texto carregando no div conteúdo
    var conteudo=document.getElementById(div)

    conteudo.innerHTML='<div class="carregando">carregando...</div>';
    conteudo.value='<div class="carregando">carregando...</div>';
    //Guarda a página escolhida na variável atual
    atual=file

    //Abre a url
    xmlhttp.open("GET", /*"funcoes.php?n="+*/file,true);

    //Executada quando o navegador obtiver o código
    xmlhttp.onreadystatechange=function() {

        if (xmlhttp.readyState==4){

            //Lê o texto
            var texto=xmlhttp.responseText

            //Desfaz o urlencode
            //texto=texto.replace(/\+/g," ")
            //texto=unescape(texto)
            //Exibe o texto no div conteúdo
            var conteudo=document.getElementById(div)
            conteudo.innerHTML=texto;
            //texto = texto.replace('/r',' ')
            //texto = texto.replace('/n',' ')
            conteudo.value=texto;
        }
    }
    xmlhttp.send(null)
}


function carrega(file,div){

    //Exibe o texto carregando no div conteúdo
    var conteudo=document.getElementById(div)

    conteudo.innerHTML='<div class="carregando">carregando...</div>';
    conteudo.value='<div class="carregando">carregando...</div>';


    //Guarda a página escolhida na variável atual
    atual=file

    //Abre a url
    xmlhttp.open("GET", /*"funcoes.php?n="+*/file,true);

    //Executada quando o navegador obtiver o código
    xmlhttp.onreadystatechange=function() {

        if (xmlhttp.readyState==4){

            //Lê o texto
            var texto=xmlhttp.responseText

            //Desfaz o urlencode
            texto=texto.replace(/\+/g," ")
            texto=unescape(texto)
            //Exibe o texto no div conteúdo
            var conteudo=document.getElementById(div)
            conteudo.innerHTML=texto;
            texto = texto.replace('/r',' ')
            texto = texto.replace('/n',' ')
            conteudo.value=texto;
        }
    }
    xmlhttp.send(null)
}





function init(){
    //Atribui o evento
}

if(xmlhttp)window.onload=init

