﻿//javascript
function atendimentoOnline() {
    window.open('http://187.61.53.195/adm/Atendimento/questoesIniciais.aspx?agencia=1&pergunta=0&idImovel=0&origem=5', 'atendimento', 'width=490,height=410');
}

function loadBanner(caminho, largura, altura) {
    //1003, 230
    var t = '';

        if (caminho == "home") {
    
        t='<div class="banner_area">'
	    t+='    <div class="banner_horizontal">'
        t+='    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="668" height="230">'
        t+='        <param name="movie" value="swf/banner.swf">'
        t+='        <param name="quality" value="high">'
        t+='        <embed src="swf/banner.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="668" height="230"></embed>'
        t+='    </object>'
	    t+='    </div>'
	    t+='<div class="banner_vertical">'
        t+='    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="325" height="230">'
        t+='    <param name="movie" value="swf/banner_vertical.swf">'
        t+='    <param name="quality" value="high">'
        t+='    <embed src="swf/banner_vertical.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="325" height="230"></embed>'
        t+='    </object>'
	    t+='</div>'
	    t+= '</div>'	
    }
    else {
        t = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=3,0,0,0" width="1003" height="308"><param name=movie value="' + caminho + '"><param name=quality value=autohigh><param name=menu value=false><param name=bgcolor><param name=wmode value=transparent><embed wmode="transparent" src="' + caminho + '" quality=autohigh width="1003" height="308" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></embed></object>';                        
    }
    
    document.write(t);
}

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]; } 
    }
}

function MM_swapImgRestore() { //v3.0
    var i, x, a = document.MM_sr; for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
}

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_swapImage() { //v3.0   

    var i, j = 0, x, a = MM_swapImage.arguments; document.MM_sr = new Array; for (i = 0; i < (a.length - 2); i += 3)
        if ((x = MM_findObj(a[i])) != null) { document.MM_sr[j++] = x; if (!x.oSrc) x.oSrc = x.src; x.src = a[i + 2]; }
    }
        
    function load() {
        loadBairros();
        if(document.getElementById('hdBusca').value!="1") zerandoBuscaRapida();
    }
   
    function loadBairros() {
        var response = MasterPage.loadBairros();
        document.getElementById('bairros').innerHTML = response.value;
    }

    function mudarAba(obj, finalidade) {
        //finalidade 2 e 3
             
        if (finalidade == 2) {
            document.getElementById('MComprar').style.height = "24";
            document.getElementById('MAlugar').style.height = "21";
        }
        else {
            document.getElementById('MComprar').style.height = "21";
            document.getElementById('MAlugar').style.height = "24";
        }

        document.getElementById('MComprar').className = "aba_out";
        document.getElementById('MAlugar').className = "aba_out";

        document.getElementById(obj).className = "aba_in";
        
        document.getElementById('hdFinalidade').value = finalidade;
        document.getElementById('hdFinalidadeCompleta').value = finalidade;
        
        //faixas de preço
        loadFaixaBCompleta(finalidade);
    }

    function zerarFaixa() {
        document.getElementById('hdFaixaIn').value = "";
        document.getElementById('hdFaixaOut').value = "";
        document.getElementById('hdTipoBusca').value = "R";
        document.getElementById('hdBairroBR').value = "";
        document.getElementById('hdPerfil').value = "";
        document.getElementById('hdDorm').value = "";
        document.getElementById('hdVagas').value = "";
        document.getElementById('hdAUIn').value = "";
        document.getElementById('hdAUOut').value = "";
    }

    function setFaixa(numFaixaIn, numFaixaOut) {
        zerandoBuscaRapida();
        document.getElementById('hdFaixaIn').value = numFaixaIn;
        document.getElementById('hdFaixaOut').value = numFaixaOut;        
        document.getElementById('hdTipoBusca').value = "R";
        loadResultado();
    }

    function setBairro(codBairro) {
        zerandoBuscaRapida();
        document.getElementById('hdBairroBR').value = codBairro;
        document.getElementById('hdTipoBusca').value = "R";
        loadResultado();
    }

    function setPerfil(codPerfil) {
        zerandoBuscaRapida();
        document.getElementById('hdPerfil').value = codPerfil;
        document.getElementById('hdTipoBusca').value = "R";
        loadResultado();
    }

    function setDorm(numDorm) {
        zerandoBuscaRapida();
        document.getElementById('hdDorm').value = numDorm;
        document.getElementById('hdTipoBusca').value = "R";
        loadResultado();
    }

    function setVagas(numVagas) {
        zerandoBuscaRapida();
        document.getElementById('hdVagas').value = numVagas;
        document.getElementById('hdTipoBusca').value = "R";
        loadResultado();
    }

    function setAU(numAUIn, numAUOut) {
        zerandoBuscaRapida();
        document.getElementById('hdAUIn').value = numAUIn;
        document.getElementById('hdAUOut').value = numAUOut;
        document.getElementById('hdTipoBusca').value = "R";
        loadResultado();
    }      

    //=================================busca completa====================================
    function loadPerfilBCompleta(RC) {
        limpandoSelect(document.getElementById('sltPerfilImovel'));
        response = MasterPage.getPerfilDT(RC);
        setarSelect(response, 'sltPerfilImovel', "valor", "ds_valor", "PERFIL DO IMÓVEL", ""); //falta listar apenas os imóveis de acordo com o perfil
        document.getElementById('hdRCCompleta').value = RC;        
    }

    //utizado ao trocar a finalidade
    function loadFaixaBCompleta(id_finalidade) {
        var response = MasterPage.loadFaixaPrecos(id_finalidade);
        limpandoSelect(document.getElementById('sltValorMinimo'));
        setarSelect(response, "sltValorMinimo", "faixaIn", "ds_valorIn", "VALOR MINIMO", "INDEFINIDO");

        limpandoSelect(document.getElementById('sltValorMaximo'));
        setarSelect(response, "sltValorMaximo", "faixaIn", "ds_valorIn", "VALOR MAXIMO", "INDEFINIDO");
    }

    //===============================final da busca completa=============================

    function zerandoBuscaRapida() {
        if (document.getElementById('hdTipoBusca').value == 'C') {
            document.getElementById('hdPagina').value = 0
            document.getElementById('hdFinalidade').value = 2;
            document.getElementById('hdRC').value = "R"
            document.getElementById('hdPerfil').value = "";
            document.getElementById('hdBairroBR').value = "";
            document.getElementById('hdFaixaIn').value = "";
            document.getElementById('hdFaixaOut').value = "";
            document.getElementById('hdCidades').value = "";
            document.getElementById('hdDorm').value = 0;
            document.getElementById('hdSuites').value = 0;
            document.getElementById('hdVagas').value = 0;
            document.getElementById('hdAUIn').value = 0;
            document.getElementById('hdAUOut').value = 0;
            document.getElementById('hdTipoBusca').value = "R";
        }
    }

    function setBuscaCompleta()
    {   
        var finalidade=document.getElementById('hdFinalidadeCompleta').value;
        var perfil=document.getElementById('sltPerfilImovel').value;
        var faixaIn=document.getElementById('sltValorMinimo').value;
        var faixaOut = document.getElementById('sltValorMaximo').value;
        var dorm=document.getElementById('sltDorm').value;
        var suites = document.getElementById('sltSuites').value;
        var vagas = document.getElementById('sltVagas').value;
        var id_bairro = document.getElementById('hdBairroBC').value;
        var RC = document.getElementById('hdRCCompleta').value;
        var auIn = document.getElementById('hdAUIn').value;
        var auOut = document.getElementById('hdAUOut').value;
        var cidades = document.getElementById('hdCidades').value;
        var tipoBusca = "C";

        var url = 'imoveis.aspx?RC='+ RC +'&id_cidades='+ cidades +'&id_bairro=' + id_bairro + '&finalidade=' + finalidade + '&perfil=' + perfil + '&valorMinimo=' + faixaIn + '&valorMaximo=' + faixaOut;
        url += '&dormitorios=' + dorm + '&suites=' + suites + '&vagas=' + vagas + '&auIn=' + auIn + '&auOut=' + auOut + '&tipoBusca=' + tipoBusca;
        window.location = url;
    }
    
    function detalhes(id_imovel)
    {
        var imovel = document.getElementById('hdImovel' + id_imovel).value;

        if (id_imovel != "") {
            var url = "imovel.aspx?Imovel=" + imovel + "&id=" + id_imovel;            
            window.location = url;
        }
        else
            alert('Insira a referência');
    }

    //setResultado()
    function loadResultado() {
    
        var id_imovel=document.getElementById('hdReferencia').value;
    
        var pagina = document.getElementById('hdPagina').value;
                
        var id_finalidade = document.getElementById('hdFinalidade').value;
        var RC = document.getElementById('hdRC').value;
        var perfil = document.getElementById('hdPerfil').value;

        var id_bairro = "";
        if (document.getElementById('hdTipoBusca').value == 'R')
            id_bairro = document.getElementById('hdBairroBR').value;
        else{
            id_bairro = document.getElementById('hdBairroBC').value;
            RC=document.getElementById('hdRCCompleta').value;
        }
                
        var id_cidade = document.getElementById('hdCidades').value;

        if (document.getElementById('hdTipoBusca').value == 'R' && id_bairro == "")
            id_bairro = "1126, 1033, 1035, 1330, 1331, 1303, 1460, 1486, 1337, 1378, 1045, 1353, 1078, 1063, 1095, 1161, 1159, 1238, 1199, 1295, 1299, 1465, 1474, 1384";
        
        var faixaIn = document.getElementById('hdFaixaIn').value;
        var faixaOut = document.getElementById('hdFaixaOut').value;
        var dorm = document.getElementById('hdDorm').value;
        var suites = document.getElementById('hdSuites').value;
        var vagas = document.getElementById('hdVagas').value;
        var AUIn = document.getElementById('hdAUIn').value;
        var AUOut = document.getElementById('hdAUOut').value;    
                
        document.getElementById('hdBusca').value = 1;

        var response;
        if (id_imovel == '') {
            //var url = 'imoveis.aspx?pagina=' + pagina + '&RC=' + RC + '&id_bairro=' + id_bairro + '&finalidade=' + id_finalidade + '&perfil=' + perfil + '&valorMinimo=' + faixaIn + '&valorMaximo=' + faixaOut;
            var url = 'imoveis.aspx?RC='+ RC +'&id_bairro=' + id_bairro + '&finalidade=' + id_finalidade + '&perfil=' + perfil + '&valorMinimo=' + faixaIn + '&valorMaximo=' + faixaOut;
            url += '&dormitorios=' + dorm + '&suites=' + suites + '&vagas=' + vagas + '&auIn=' + AUIn + '&auOut=' + AUOut + '&tipoBusca=R';
            window.location = url;    
        }
        else {
            //busca por referencia
            response = MasterPage.loadResultado('', '', '', '', '', 0, 0, 0, 0, 0, 0, 0, pagina, id_imovel);
            document.getElementById('conteudo').innerHTML = response.value;
        }       
    }

    function adicionarCidades(obj, codCidade) {
        var cidades = document.getElementById('hdCidades').value;

        if (obj.checked == true)
            cidades = cidades + ',' + codCidade;
        else 
            cidades = cidades.replace(',' + codCidade, '');

        document.getElementById('hdCidades').value = cidades;
    }
    
    //bairros busca completa
    function adicionarBairros(obj, codBairro) {

        document.getElementById('hdTipoBusca').value = "C";
        
        var bairros = document.getElementById('hdBairroBC').value;

        if (obj.checked == true)
            bairros = bairros + ',' + codBairro;
        else
            bairros = bairros.replace(',' + codBairro, '');

        document.getElementById('hdBairroBC').value = bairros;
    }

    function openBairros() {
        y = eval(screen.width) / 3;
        x = eval(screen.height) / 3;
        var bairros = window.document.getElementById('hdBairros').value;

        window.open('bairros.aspx?bairros=' + bairros, 'Bairros', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,left=' + y + ',top=' + x + ';resizable=no,copyhistory=yes,width=645,height=242');
    } 
