﻿/**************************************************************
*
* CLASSE JAVASCRIPT BUSCA RÁPIDA
*
* CRIADO POR: CRISTIANO TAVELLA
* DATA: 12/05/2011
* OBS:
* EDITADO POR: CRISTIANO TAVELLA
* DATA: 24/05/2011
* OBS:
*
*************************************************************/

function imprimir(consulta) {
    var v_this = this;

    if (typeof (consulta) != "undefined") {
        this.filtrosConsulta = consulta.slice(0);
    }

    //imprime o html na pagina
    var arr_filtros = this.filtros.split(";");
    for (var i = 0; i < arr_filtros.length; i++) {
        this.layout = this.layout.replace("[" + $.trim(arr_filtros[i]) + "]", this.setFiltros($.trim(arr_filtros[i])));
    }
    $(this.destino).html(this.layout);

    //Insere os combos
    for (var i = 0; i < arr_filtros.length; i++) {
        this.setCombo($.trim(arr_filtros[i]));
    }

    //busca dados vindo do BD
    this.setBDCombos();

    //insere o clique no botão pesquisar
    $(this.btnPesquisar).click(function () {
        v_this.Pesquisar();
    });

}


function setFiltros(filtro) {
    var script = "";

    switch (filtro) {
        case "pretensão": script = "<div id='" + this.destino.replace("#boxConteudo_", "") + "boxFiltro_pret'></div>"; break;
        case "pretensão2": script = "<div id='" + this.destino.replace("#boxConteudo_", "") + "boxFiltro_pret'></div>"; break;
        case "subtipo": script = "<div id='" + this.destino.replace("#boxConteudo_", "") + "boxFiltro_subtipo'></div>"; break;
        case "tipo": script = "<div id='" + this.destino.replace("#boxConteudo_", "") + "boxFiltro_tipo'></div>"; break;
        case "tipo2": script = "<div id='" + this.destino.replace("#boxConteudo_", "") + "boxFiltro_tipo'></div>"; break;
        case "uf": script = "<div id='" + this.destino.replace("#boxConteudo_", "") + "boxFiltro_uf'></div>"; break;
        case "cidade": script = "<div id='" + this.destino.replace("#boxConteudo_", "") + "boxFiltro_cidade'></div>"; break;
        case "bairro": script = "<div id='" + this.destino.replace("#boxConteudo_", "") + "boxFiltro_bairro'></div>"; break;
        case "valor": script = "<div id='" + this.destino.replace("#boxConteudo_", "") + "boxFiltro_valor'></div>"; break;
        case "valor2": script = "<div id='" + this.destino.replace("#boxConteudo_", "") + "boxFiltro_valor'></div>"; break;
        case "valor mínimo": script = "<div id='" + this.destino.replace("#boxConteudo_", "") + "boxFiltro_valmin'></div>"; break;
        case "valor máximo": script = "<div id='" + this.destino.replace("#boxConteudo_", "") + "boxFiltro_valmax'></div>"; break;
        case "dormitórios": script = "<div id='" + this.destino.replace("#boxConteudo_", "") + "boxFiltro_dorms'></div>"; break;
        case "condomínio": script = "<div id='" + this.destino.replace("#boxConteudo_", "") + "boxFiltro_cond'></div>"; break;
        case "suítes": script = "<div id='" + this.destino.replace("#boxConteudo_", "") + "boxFiltro_suites'></div>"; break;
        case "vagas": script = "<div id='" + this.destino.replace("#boxConteudo_", "") + "boxFiltro_vagas'></div>"; break;
        case "área": script = "<div id='" + this.destino.replace("#boxConteudo_", "") + "boxFiltro_area'></div>"; break;
        case "área mínima": script = "<div id='" + this.destino.replace("#boxConteudo_", "") + "boxFiltro_areamin'></div>"; break;
        case "área máxima": script = "<div id='" + this.destino.replace("#boxConteudo_", "") + "boxFiltro_areamax'></div>"; break;
        case "virtual tour": script = "<div id='" + this.destino.replace("#boxConteudo_", "") + "boxFiltro_tour'></div>"; break;
    }
    return script;
}

function setCombo(filtro) {

    var v_this = this;

    var v_sel = "";
    //verifica se existe valor oriundo de consulta
    for (var i = 0; i < this.filtrosConsulta.length; i++) {
        if (filtro == this.filtrosConsulta[i].filtro)
            v_sel = this.filtrosConsulta[i].value;
        else if (filtro == this.filtrosConsulta[i].filtro + "2")
            v_sel = this.filtrosConsulta[i].value;
    }

    switch (filtro) {
        case "pretensão":
            v_sel = v_sel.split(",");
            var sel_comprar = false;
            var sel_alugar = false;
            for (var i = 0; i < v_sel.length; i++) {
                if (v_sel[i] == "Comprar")
                    sel_comprar = true;
                if (v_sel[i] == "Alugar")
                    sel_alugar = true;

            }

            if (v_SEO.flag_finalidade == "1")
                var arr_pret = [{ label: "Comprar", value: "Comprar", selected: sel_comprar }];
            else if (v_SEO.flag_finalidade == "2")
                var arr_pret = [{ label: "Alugar", value: "Alugar", selected: sel_alugar}];
            else
                var arr_pret = [{ label: "Comprar", value: "Comprar", selected: sel_comprar }
                                , { label: "Alugar", value: "Alugar", selected: sel_alugar}];

            this.combos[this.combos.length] = new Combo({
                destino: '#' + this.destino.replace("#boxConteudo_", "") + 'boxFiltro_pret'
                , elem: this.destino.replace("#boxConteudo_", "") + ".combos[" + this.combos.length + "]"
                , tipo: "pretensão"
                , queryString: "pretensão"
                , atualizar: 'subtipo, tipo, uf, cidade, bairro, valor, valor mínimo, valor máximo'
                , checkbox: (this.tipoCombo == "2" ? true : false)
                , id: this.destino.replace("#boxConteudo_", "") + 'inf_finalidade'
                , options: arr_pret
                , consultaOnChange: this.consultaOnChange
            });
            break;
        case "pretensão2":
            v_sel = v_sel.split(",");
            var sel_comprar = false;
            var sel_alugar = false;
            for (var i = 0; i < v_sel.length; i++) {
                if (v_sel[i] == "Comprar")
                    sel_comprar = true;
                if (v_sel[i] == "Alugar")
                    sel_alugar = true;

            }

            if (v_SEO.flag_finalidade == "1")
                var arr_pret = [{ label: "Comprar", value: "Comprar", selected: sel_comprar}];
            else if (v_SEO.flag_finalidade == "2")
                var arr_pret = [{ label: "Alugar", value: "Alugar", selected: sel_alugar}];
            else
                var arr_pret = [{ label: "Comprar", value: "Comprar", selected: sel_comprar }
                                , { label: "Alugar", value: "Alugar", selected: sel_alugar}];

            this.combos[this.combos.length] = new Combo({
                destino: '#' + this.destino.replace("#boxConteudo_", "") + 'boxFiltro_pret'
                , elem: this.destino.replace("#boxConteudo_", "") + ".combos[" + this.combos.length + "]"
                , tipo: "pretensão"
                , queryString: "pretensão"
                , radio: true
                , atualizar: 'tipo, uf, cidade, bairro, valor, valor mínimo, valor máximo'
                , id: this.destino.replace("#boxConteudo_", "") + 'inf_finalidade'
                , options: arr_pret
                , consultaOnChange: this.consultaOnChange 
            });
            break;
        case "subtipo":
            this.combos[this.combos.length] = new Combo({
                destino: '#' + this.destino.replace("#boxConteudo_", "") + 'boxFiltro_subtipo'
                    , elem: this.destino.replace("#boxConteudo_", "") + ".combos[" + this.combos.length + "]"
                    , tipo: "subtipo"
                    , queryString: "subtipo"
                    , atualizar: 'tipo, uf, cidade, bairro'
                    , checkbox: (this.tipoCombo == "2" ? true : false)
                    , id: this.destino.replace("#boxConteudo_", "") + 'inf_subtipo'
                    , options: [{ label: "Carregando...", value: ""}]
                    , consultaOnChange: this.consultaOnChange
            });
            break;
        case "tipo":
            this.combos[this.combos.length] = new Combo({
                destino: '#' + this.destino.replace("#boxConteudo_", "") + 'boxFiltro_tipo'
                    , elem: this.destino.replace("#boxConteudo_", "") + ".combos[" + this.combos.length + "]"
                    , tipo: "tipo"
                    , queryString: "tipo"
                    , atualizar: 'uf, cidade, bairro'
                    , checkbox: (this.tipoCombo == "2" ? true : false)
                    , id: this.destino.replace("#boxConteudo_", "") + 'inf_tipo'
                    , options: [{ label: "Carregando...", value: ""}]
                    , consultaOnChange: this.consultaOnChange 
            });
            break;
        case "tipo2":
            this.combos[this.combos.length] = new Combo({
                destino: '#' + this.destino.replace("#boxConteudo_", "") + 'boxFiltro_tipo'
                    , elem: this.destino.replace("#boxConteudo_", "") + ".combos[" + this.combos.length + "]"
                    , tipo: "tipo2"
                    , queryString: "tipo"
                    , atualizar: 'uf, cidade, bairro'
                    , lista: true
                    , id: this.destino.replace("#boxConteudo_", "") + 'inf_tipo'
                    , options: [{ label: "Carregando...", value: ""}]
                    , consultaOnChange: this.consultaOnChange
            });
            break;
        case "uf":
            this.combos[this.combos.length] = new Combo({
                destino: '#' + this.destino.replace("#boxConteudo_", "") + 'boxFiltro_uf'
                , elem: this.destino.replace("#boxConteudo_", "") + ".combos[" + this.combos.length + "]"
                , tipo: "uf"
                , queryString: "uf"
                , atualizar: 'cidade, bairro'
                , checkbox: (this.tipoCombo == "2" ? true : false)
                , id: this.destino.replace("#boxConteudo_", "") + 'inf_uf'
                , options: [{ label: "Carregando...", value: ""}]
                , consultaOnChange: this.consultaOnChange 
            });
            break;
        case "cidade":
            this.combos[this.combos.length] = new Combo({
                destino: '#' + this.destino.replace("#boxConteudo_", "") + 'boxFiltro_cidade'
                , elem: this.destino.replace("#boxConteudo_", "") + ".combos[" + this.combos.length + "]"
                , tipo: "cidade"
                , queryString: "cidade"
                , atualizar: 'bairro'
                , checkbox: (this.tipoCombo == "2" ? true : false)
                , id: this.destino.replace("#boxConteudo_", "") + 'inf_cidade'
                , options: [{ label: "Carregando...", value: ""}]
                , consultaOnChange: this.consultaOnChange 
            });
            break;
        case "bairro":
            this.combos[this.combos.length] = new Combo({
                destino: '#' + this.destino.replace("#boxConteudo_", "") + 'boxFiltro_bairro'
                , elem: this.destino.replace("#boxConteudo_", "") + ".combos[" + this.combos.length + "]"
                , tipo: "bairro"
                , queryString: "bairro"
                , checkbox: true
                , id: this.destino.replace("#boxConteudo_", "") + 'inf_bairro'
                , options: [{ label: "Carregando...", value: ""}]
                , consultaOnChange: this.consultaOnChange 
            });
            break;
        case "valor":
            if ($("#" + this.destino.replace("#boxConteudo_", "") + "inf_finalidade").val() == "Alugar" || $("input[name='" + this.destino.replace("#boxConteudo_", "") + "inf_finalidade']:checked").val() == "Alugar")
                var arr_valor = [{ label: 'Indiferente', value: '' }
                , { label: 'até 300', value: '0_300', selected: (v_sel == "0_300" ? true : false) }
                , { label: 'de 300 à 400', value: '300_400', selected: (v_sel == "300_400" ? true : false) }
                , { label: 'de 400 à 500', value: '400_500', selected: (v_sel == "400_500" ? true : false) }
                , { label: 'de 500 à 750', value: '500_750', selected: (v_sel == "500_750" ? true : false) }
                , { label: 'de 750 à 1.000', value: '750_1000', selected: (v_sel == "750_1000" ? true : false) }
                , { label: 'de 1.000 à 1.250', value: '1000_1250', selected: (v_sel == "1000_1250" ? true : false) }
                , { label: 'de 1.250 à 1.500', value: '1250_1500', selected: (v_sel == "1250_1500" ? true : false) }
                , { label: 'de 1.500 à 2.000', value: '1500_2000', selected: (v_sel == "1500_2000" ? true : false) }
                , { label: 'de 2.000 à 3.000', value: '2000_3000', selected: (v_sel == "2000_3000" ? true : false) }
                , { label: 'de 3.000 à 5.000', value: '3000_5000', selected: (v_sel == "3000_5000" ? true : false) }
                , { label: 'de 5.000 à 7.500', value: '7000_7500', selected: (v_sel == "5000_7500" ? true : false) }
                , { label: 'de 7.500 à 10.000', value: '7500_10000', selected: (v_sel == "7500_10000" ? true : false) }
                , { label: 'de 10.000 à 12.500', value: '10000_12500', selected: (v_sel == "10000_12500" ? true : false) }
                , { label: 'de 12.500 à 15.000', value: '12500_15000', selected: (v_sel == "12500_15000" ? true : false) }
                , { label: 'de 15.000 à 30.000', value: '15000_30000', selected: (v_sel == "15000_30000" ? true : false) }
                , { label: 'acima de 30.000', value: '30000_0', selected: (v_sel == "30000_0" ? true : false)}];
            else
                var arr_valor = [{ label: "Indiferente", value: "" }
                , { label: "até 100 mil", value: "0_100000", selected: (v_sel == "0_100000" ? true : false) }
                , { label: "de 100 mil à 150 mil", value: "100000_150000", selected: (v_sel == "100000_150000" ? true : false) }
                , { label: "de 150 mil à 200 mil", value: "150000_200000", selected: (v_sel == "150000_200000" ? true : false) }
                , { label: "de 200 mil à 300 mil", value: "200000_300000", selected: (v_sel == "200000_300000" ? true : false) }
                , { label: "de 300 mil à 400 mil", value: "300000_400000", selected: (v_sel == "300000_400000" ? true : false) }
                , { label: "de 400 mil à 500 mil", value: "400000_500000", selected: (v_sel == "400000_500000" ? true : false) }
                , { label: "de 500 mil à 1 milhão", value: "500000_1000000", selected: (v_sel == "500000_1000000" ? true : false) }
                , { label: "de 1 milhão à 3 milhões", value: "1000000_3000000", selected: (v_sel == "1000000_3000000" ? true : false) }
                , { label: "acima 3 milhões", value: "3000000_0", selected: (v_sel == "3000000_0" ? true : false)}];

            this.combos[this.combos.length] = new Combo({
                destino: '#' + this.destino.replace("#boxConteudo_", "") + 'boxFiltro_valor'
                , elem: this.destino.replace("#boxConteudo_", "") + ".combos[" + this.combos.length + "]"
                , tipo: "valor"
                , queryString: "valor"
                , id: this.destino.replace("#boxConteudo_", "") + 'inf_valor'
                 , options: arr_valor
                 , consultaOnChange: this.consultaOnChange 
            });
            break;
        case "valor2":
            var arr_sel = v_sel.split("_");
            if ($("#" + this.destino.replace("#boxConteudo_", "") + "inf_finalidade").val() == "Alugar" || $("input[name='" + this.destino.replace("#boxConteudo_", "") + "inf_finalidade']:checked").val() == "Alugar")
                var arr_valor = [{ label: '0', value: '0' }
                , { label: (v_sel == ""? '0' : arr_sel[0]), value: (v_sel == ""? '0' : arr_sel[0]) }
                , { label: (v_sel == ""? '2100' : arr_sel[1]), value: (v_sel == ""? '2100' : arr_sel[1]) }
                , { label: '2100', value: '2100'}];
            else
                var arr_valor = [{ label: "0", value: "0" }
                , { label: (v_sel == "" ? '0' : arr_sel[0]), value: (v_sel == "" ? '0' : arr_sel[0]) }
                , { label: (v_sel == ""? '1300000' : arr_sel[1]), value: (v_sel == ""? '1300000' : arr_sel[1]) }
                , { label: '1300000', value: '1300000'}];

            this.combos[this.combos.length] = new Combo({
                destino: '#' + this.destino.replace("#boxConteudo_", "") + 'boxFiltro_valor'
                , elem: this.destino.replace("#boxConteudo_", "") + ".combos[" + this.combos.length + "]"
                , tipo: "valor"
                , queryString: "valor"
                , slider: true
                , id: this.destino.replace("#boxConteudo_", "") + 'inf_valor'
                 , options: arr_valor
                 , consultaOnChange: this.consultaOnChange 
            });
            break;
        case "valor mínimo":
            if ($("#" + this.destino.replace("#boxConteudo_", "") + "inf_finalidade").val() == "Alugar" || $("input[name='" + this.destino.replace("#boxConteudo_", "") + "inf_finalidade']:checked").val() == "Alugar")
                var arr_valor = [{ label: 'Indiferente', value: '' }
                , { label: '300', value: '300', selected: (v_sel == "300" ? true : false) }
                , { label: '400', value: '400', selected: (v_sel == "400" ? true : false) }
                , { label: '500', value: '500', selected: (v_sel == "500" ? true : false) }
                , { label: '750', value: '750', selected: (v_sel == "750" ? true : false) }
                , { label: '1.000', value: '1000', selected: (v_sel == "1000" ? true : false) }
                , { label: '1.250', value: '1250', selected: (v_sel == "1250" ? true : false) }
                , { label: '1.500', value: '1500', selected: (v_sel == "1500" ? true : false) }
                , { label: '2.000', value: '2000', selected: (v_sel == "2000" ? true : false) }
                , { label: '5.000', value: '5000', selected: (v_sel == "5000" ? true : false) }
                , { label: '8.000', value: '8000', selected: (v_sel == "8000" ? true : false) }
                , { label: '12.000', value: '12000', selected: (v_sel == "12000" ? true : false) }
                , { label: '15.000', value: '15000', selected: (v_sel == "15000" ? true : false) }
                , { label: '30.000', value: '30000', selected: (v_sel == "30000" ? true : false)}];
            else
                var arr_valor = [{ label: "Indiferente", value: "" }
                , { label: "100 mil", value: "100000", selected: (v_sel == "100000" ? true : false) }
                , { label: "150 mil", value: "150000", selected: (v_sel == "150000" ? true : false) }
                , { label: "200 mil", value: "200000", selected: (v_sel == "200000" ? true : false) }
                , { label: "300 mil", value: "300000", selected: (v_sel == "300000" ? true : false) }
                , { label: "400 mil", value: "400000", selected: (v_sel == "400000" ? true : false) }
                , { label: "500 mil", value: "500000", selected: (v_sel == "500000" ? true : false) }
                , { label: "1 milhão", value: "1000000", selected: (v_sel == "1000000" ? true : false) }
                , { label: "3 milhões", value: "3000000", selected: (v_sel == "3000000" ? true : false)}];

            this.combos[this.combos.length] = new Combo({
                destino: '#' + this.destino.replace("#boxConteudo_", "") + 'boxFiltro_valmin'
                , elem: this.destino.replace("#boxConteudo_", "") + ".combos[" + this.combos.length + "]"
                , tipo: "valor mínimo"
                , queryString: "valor mínimo"
                , id: this.destino.replace("#boxConteudo_", "") + 'inf_valmin'
                 , options: arr_valor
                 , consultaOnChange: this.consultaOnChange 
            });
            break;
        case "valor máximo":
            if ($("#" + this.destino.replace("#boxConteudo_", "") + "inf_finalidade").val() == "Alugar" || $("input[name='" + this.destino.replace("#boxConteudo_", "") + "inf_finalidade']:checked").val() == "Alugar")
                var arr_valor = [{ label: 'Indiferente', value: '' }
                , { label: '300', value: '300', selected: (v_sel == "300" ? true : false) }
                , { label: '400', value: '400', selected: (v_sel == "400" ? true : false) }
                , { label: '500', value: '500', selected: (v_sel == "500" ? true : false) }
                , { label: '750', value: '750', selected: (v_sel == "750" ? true : false) }
                , { label: '1.000', value: '1000', selected: (v_sel == "1000" ? true : false) }
                , { label: '1.250', value: '1250', selected: (v_sel == "1250" ? true : false) }
                , { label: '1.500', value: '1500', selected: (v_sel == "1500" ? true : false) }
                , { label: '2.000', value: '2000', selected: (v_sel == "2000" ? true : false) }
                , { label: '5.000', value: '5000', selected: (v_sel == "5000" ? true : false) }
                , { label: '8.000', value: '8000', selected: (v_sel == "8000" ? true : false) }
                , { label: '12.000', value: '12000', selected: (v_sel == "12000" ? true : false) }
                , { label: '15.000', value: '15000', selected: (v_sel == "15000" ? true : false) }
                , { label: '30.000', value: '30000', selected: (v_sel == "30000" ? true : false)}];
            else
                var arr_valor = [{ label: "Indiferente", value: "" }
                , { label: "100 mil", value: "100000", selected: (v_sel == "100000" ? true : false) }
                , { label: "150 mil", value: "150000", selected: (v_sel == "150000" ? true : false) }
                , { label: "200 mil", value: "200000", selected: (v_sel == "200000" ? true : false) }
                , { label: "300 mil", value: "300000", selected: (v_sel == "300000" ? true : false) }
                , { label: "400 mil", value: "400000", selected: (v_sel == "400000" ? true : false) }
                , { label: "500 mil", value: "500000", selected: (v_sel == "500000" ? true : false) }
                , { label: "1 milhão", value: "1000000", selected: (v_sel == "1000000" ? true : false) }
                , { label: "3 milhões", value: "3000000", selected: (v_sel == "3000000" ? true : false)}];

            this.combos[this.combos.length] = new Combo({
                destino: '#' + this.destino.replace("#boxConteudo_", "") + 'boxFiltro_valmax'
                , elem: this.destino.replace("#boxConteudo_", "") + ".combos[" + this.combos.length + "]"
                , tipo: "valor máximo"
                , queryString: "valor máximo"
                , id: this.destino.replace("#boxConteudo_", "") + 'inf_valmax'
                , options: arr_valor
                , consultaOnChange: this.consultaOnChange 
            });
            break;
        case "dormitórios":
            this.combos[this.combos.length] = new Combo({
                destino: '#' + this.destino.replace("#boxConteudo_", "") + 'boxFiltro_dorms'
                , elem: this.destino.replace("#boxConteudo_", "") + ".combos[" + this.combos.length + "]"
                , tipo: "dormitórios"
                , queryString: "dormitórios"
                , id: this.destino.replace("#boxConteudo_", "") + 'det_dormitorios'
                , options: [{ label: "Indiferente", value: "" }
                , { label: "1 dorm.", value: "1", selected: (v_sel == "1" ? true : false) }
                , { label: "2 dorms.", value: "2", selected: (v_sel == "2" ? true : false) }
                , { label: "3 dorms.", value: "3", selected: (v_sel == "3" ? true : false) }
                , { label: "4 dorms.", value: "4", selected: (v_sel == "4" ? true : false) }
                , { label: "5 dorms. ou mais", value: "5", selected: (v_sel == "5" ? true : false)}]
                , consultaOnChange: this.consultaOnChange 
            });
            break;
        case "condomínio":
            this.combos[this.combos.length] = new Combo({
                destino: '#' + this.destino.replace("#boxConteudo_", "") + 'boxFiltro_cond'
                , elem: this.destino.replace("#boxConteudo_", "") + ".combos[" + this.combos.length + "]"
                , tipo: "condomínio"
                , queryString: "condomínio"
                , id: this.destino.replace("#boxConteudo_", "") + 'inf_condominio'
                , options: [{ label: "Indiferente", value: "" }
                , { label: "Sim", value: "Sim", selected: (v_sel == "Sim" ? true : false) }
                , { label: "Não", value: "Não", selected: (v_sel == "Não" ? true : false)}]
                , consultaOnChange: this.consultaOnChange 
            });
            break;
        case "suítes":
            this.combos[this.combos.length] = new Combo({
                destino: '#' + this.destino.replace("#boxConteudo_", "") + 'boxFiltro_suites'
                , elem: this.destino.replace("#boxConteudo_", "") + ".combos[" + this.combos.length + "]"
                , tipo: "suítes"
                , queryString: "suítes"
                , id: this.destino.replace("#boxConteudo_", "") + 'inf_suites'
                , options: [{ label: "Indiferente", value: "" }
                , { label: "1 suíte", value: "1", selected: (v_sel == "1" ? true : false) }
                , { label: "2 suítes", value: "2", selected: (v_sel == "2" ? true : false) }
                , { label: "3 suítes", value: "3", selected: (v_sel == "3" ? true : false) }
                , { label: "4 suítes", value: "4", selected: (v_sel == "4" ? true : false) }
                , { label: "5 suítes ou mais", value: "5", selected: (v_sel == "5" ? true : false)}]
                , consultaOnChange: this.consultaOnChange 
            });
            break;
        case "vagas":
            this.combos[this.combos.length] = new Combo({
                destino: '#' + this.destino.replace("#boxConteudo_", "") + 'boxFiltro_vagas'
                , elem: this.destino.replace("#boxConteudo_", "") + ".combos[" + this.combos.length + "]"
                , tipo: "vagas"
                , queryString: "vagas"
                , id: this.destino.replace("#boxConteudo_", "") + 'det_garagens'
                , options: [{ label: "Indiferente", value: "" }
                , { label: "1 vaga", value: "1", selected: (v_sel == "1" ? true : false) }
                , { label: "2 vagas", value: "2", selected: (v_sel == "2" ? true : false) }
                , { label: "3 vagas", value: "3", selected: (v_sel == "3" ? true : false) }
                , { label: "4 vagas", value: "4", selected: (v_sel == "4" ? true : false) }
                , { label: "5 vagas ou mais", value: "5", selected: (v_sel == "5" ? true : false)}]
                , consultaOnChange: this.consultaOnChange 
            });
            break;
        case "área":
            this.combos[this.combos.length] = new Combo({
                destino: '#' + this.destino.replace("#boxConteudo_", "") + 'boxFiltro_area'
                , elem: this.destino.replace("#boxConteudo_", "") + ".combos[" + this.combos.length + "]"
                , tipo: "área"
                , queryString: "área"
                , id: this.destino.replace("#boxConteudo_", "") + 'inf_area'
                , options: [{ label: "Indiferente", value: "" }
                , { label: "até 60", value: "0_60", selected: (v_sel == "0_60" ? true : false) }
                , { label: "de 60 à 90", value: "60_90", selected: (v_sel == "60_90" ? true : false) }
                , { label: "de 90 à 120", value: "90_120", selected: (v_sel == "90_120" ? true : false) }
                , { label: "de 120 à 150", value: "120_150", selected: (v_sel == "120_150" ? true : false) }
                , { label: "de 150 à 200", value: "150_200", selected: (v_sel == "150_200" ? true : false) }
                , { label: "de 200 à 250", value: "200_250", selected: (v_sel == "200_250" ? true : false) }
                , { label: "de 250 à 500", value: "250_500", selected: (v_sel == "250_500" ? true : false) }
                , { label: "de 500 à 1.000", value: "500_1000", selected: (v_sel == "500_1000" ? true : false) }
                , { label: "de 1.000 à 2.000", value: "1000_2000", selected: (v_sel == "1000_2000" ? true : false) }
                , { label: "de 2.000 à 4.000", value: "2000_4000", selected: (v_sel == "2000_4000" ? true : false) }
                , { label: "acima de 4.000", value: "4000_0", selected: (v_sel == "4000_0" ? true : false)}]
                , consultaOnChange: this.consultaOnChange 
            });
            break;
        case "área mínima":
            this.combos[this.combos.length] = new Combo({
                destino: '#' + this.destino.replace("#boxConteudo_", "") + 'boxFiltro_areamin'
                , elem: this.destino.replace("#boxConteudo_", "") + ".combos[" + this.combos.length + "]"
                , tipo: "área mínima"
                , queryString: "área mínima"
                , id: this.destino.replace("#boxConteudo_", "") + 'inf_areamin'
                , options: [{ label: "Indiferente", value: "" }
                , { label: "5", value: "5", selected: (v_sel == "5" ? true : false) }
                , { label: "30", value: "30", selected: (v_sel == "30" ? true : false) }
                , { label: "60", value: "60", selected: (v_sel == "60" ? true : false) }
                , { label: "90", value: "90", selected: (v_sel == "90" ? true : false) }
                , { label: "120", value: "120", selected: (v_sel == "120" ? true : false) }
                , { label: "150", value: "150", selected: (v_sel == "150" ? true : false) }
                , { label: "180", value: "180", selected: (v_sel == "180" ? true : false) }
                , { label: "210", value: "210", selected: (v_sel == "210" ? true : false) }
                , { label: "240", value: "240", selected: (v_sel == "240" ? true : false) }
                , { label: "270", value: "270", selected: (v_sel == "270" ? true : false) }
                , { label: "300", value: "300", selected: (v_sel == "300" ? true : false) }
                , { label: "500", value: "500", selected: (v_sel == "500" ? true : false) }
                , { label: "1.000", value: "1000", selected: (v_sel == "1000" ? true : false) }
                , { label: "1.500", value: "1500", selected: (v_sel == "1500" ? true : false) }
                , { label: "2.000", value: "2000", selected: (v_sel == "2000" ? true : false) }
                , { label: "4.000", value: "4000", selected: (v_sel == "4000" ? true : false)}]
                , consultaOnChange: this.consultaOnChange 
            });
            break;
        case "área máxima":
            this.combos[this.combos.length] = new Combo({
                destino: '#' + this.destino.replace("#boxConteudo_", "") + 'boxFiltro_areamax'
                , elem: this.destino.replace("#boxConteudo_", "") + ".combos[" + this.combos.length + "]"
                , tipo: "área máxima"
                , queryString: "área máxima"
                , id: this.destino.replace("#boxConteudo_", "") + 'inf_areamax'
                , options: [{ label: "Indiferente", value: "" }
                , { label: "5", value: "5", selected: (v_sel == "5" ? true : false) }
                , { label: "30", value: "30", selected: (v_sel == "30" ? true : false) }
                , { label: "60", value: "60", selected: (v_sel == "60" ? true : false) }
                , { label: "90", value: "90", selected: (v_sel == "90" ? true : false) }
                , { label: "120", value: "120", selected: (v_sel == "120" ? true : false) }
                , { label: "150", value: "150", selected: (v_sel == "150" ? true : false) }
                , { label: "180", value: "180", selected: (v_sel == "180" ? true : false) }
                , { label: "210", value: "210", selected: (v_sel == "210" ? true : false) }
                , { label: "240", value: "240", selected: (v_sel == "240" ? true : false) }
                , { label: "270", value: "270", selected: (v_sel == "270" ? true : false) }
                , { label: "300", value: "300", selected: (v_sel == "300" ? true : false) }
                , { label: "500", value: "500", selected: (v_sel == "500" ? true : false) }
                , { label: "1.000", value: "1000", selected: (v_sel == "1000" ? true : false) }
                , { label: "1.500", value: "1500", selected: (v_sel == "1500" ? true : false) }
                , { label: "2.000", value: "2000", selected: (v_sel == "2000" ? true : false) }
                , { label: "4.000", value: "4000", selected: (v_sel == "4000" ? true : false)}]
                , consultaOnChange: this.consultaOnChange 
            });
            break;
        case "virtual tour":
            this.combos[this.combos.length] = new Combo({
                destino: '#' + this.destino.replace("#boxConteudo_", "") + 'boxFiltro_tour'
                , elem: this.destino.replace("#boxConteudo_", "") + ".combos[" + this.combos.length + "]"
                , tipo: "virtual tour"
                , queryString: "virtual tour"
                , id: this.destino.replace("#boxConteudo_", "") + 'inf_tour'
                , options: [{ label: "Indiferente", value: "" }
                , { label: "Sim", value: "Sim", selected: (v_sel == "Sim" ? true : false) }
                , { label: "Não", value: "Não", selected: (v_sel == "Não" ? true : false)}]
                , consultaOnChange: this.consultaOnChange 
            });
            break;
    }
}

function setBDCombos() {
    //busca os dados no BD
    var campos = new Array();
    var pretensao = "";

    //busca pretensao
    for (var j = 0; j < this.filtrosConsulta.length; j++) {
        if (this.filtrosConsulta[j].filtro == "pretensão")
            pretensao = this.filtrosConsulta[j].value;
    }   

    for (var i = 0; i < this.combos.length; i++) {
        var v_sel = "";
        //verifica se existe valor oriundo de consulta
        for (var j = 0; j < this.filtrosConsulta.length; j++) {
            if (this.combos[i].queryString == this.filtrosConsulta[j].filtro)
                v_sel = this.filtrosConsulta[j].value;
          
        }

        switch (this.combos[i].tipo) {
            case "subtipo": campos[campos.length] = { tipo: this.combos[i].tipo, i: i, action: "PesquisarSubTipo", v_sel: v_sel }; break;
            case "tipo": v_sel = (v_sel == "" ? (pretensao == "Comprar" ? v_SEO.tipo_padrao_venda : (pretensao == "Alugar" ? v_SEO.tipo_padrao_locacao : (v_SEO.flag_busca_tipo == "1" ? "" : (v_SEO.busca_tipo == "" || v_SEO.busca_tipo == "PADRAO" ? "-" : v_SEO.busca_tipo)))) : v_sel); campos[campos.length] = { tipo: this.combos[i].tipo, i: i, action: "PesquisarTipo", v_sel: v_sel }; break;
            case "tipo2": v_sel = (v_sel == "" ? (pretensao == "Comprar" ? v_SEO.tipo_padrao_venda : (pretensao == "Alugar" ? v_SEO.tipo_padrao_locacao : (v_SEO.flag_busca_tipo == "1" ? "" : (v_SEO.busca_tipo == "" || v_SEO.busca_tipo == "PADRAO" ? "-" : v_SEO.busca_tipo)))) : v_sel); campos[campos.length] = { tipo: this.combos[i].tipo, i: i, action: "PesquisarTipo2", v_sel: v_sel }; break;
            case "uf": campos[campos.length] = { tipo: this.combos[i].tipo, i: i, action: "PesquisarUf", v_sel: v_sel }; break;
            case "cidade": v_sel = (v_sel == "" ? (v_SEO.flag_busca_cidade == "1" ? "" : (v_SEO.busca_cidade == "" || v_SEO.busca_cidade == "PADRAO" ? "-" : v_SEO.busca_cidade)) : v_sel); campos[campos.length] = { tipo: this.combos[i].tipo, i: i, action: "PesquisarCidade", v_sel: v_sel }; break;
            case "bairro": campos[campos.length] = { tipo: this.combos[i].tipo, i: i, action: "PesquisarBairro", v_sel: v_sel }; break;
        }
    }

    var v_eval = "";

    for (var i = 0; i < campos.length; i++) {
        v_eval += "ajax({ action: \"" + campos[i].action + "\", v_where: " + this.destino.replace("#boxConteudo_", "") + ".setWhere(), v_sel: \"" + campos[i].v_sel + "\", busca: \"" + this.tipoBusca + "\" }, function (retorno) {";
        v_eval += "eval(retorno);";
        v_eval += this.destino.replace("#boxConteudo_", "") + ".combos[" + campos[i].i + "].setOptions(dados);";
    }

    for (var i = 0; i < campos.length; i++) {
        v_eval += "  }); ";
    }
    eval(v_eval);
}

function atualizarBDCombos(atualizar) {

    atualizar = atualizar.split(",");
    
    //busca os dados no BD
    var campos = new Array();

    for (var i = 0; i < this.combos.length; i++) {
        for (var j = 0; j < atualizar.length; j++) {
            if (this.combos[i].tipo == $.trim(atualizar[j])) {
                
                var v_sel = "";

                switch (this.combos[i].tipo) {
                    case "valor":
                        if ($("#" + this.destino.replace("#boxConteudo_", "") + "inf_finalidade").val() == "Comprar" || $("input[name='" + this.destino.replace("#boxConteudo_", "") + "inf_finalidade']:checked").val() == "Comprar") {
                            if (this.combos[i].slider)
                                eval(this.destino.replace("#boxConteudo_", "") + ".combos[" + i + "].setOptions(" +
                                    "[{ label: '0', value: '0' }" +
                                    ", { label: '0', value: '0' }" +
                                    ", { label: '1300000', value: '1300000' }" +
                                    ", { label: '1300000', value: '1300000'}]" +
                                ");");
                            else
                                eval(this.destino.replace("#boxConteudo_", "") + ".combos[" + i + "].setOptions("+
                                    "[{ label: 'Indiferente', value: '' }"+
                                    ", { label: 'até 100 mil', value: '0_100000' }"+
                                    ", { label: 'de 100 mil à 150 mil', value: '100000_150000' }"+
                                    ", { label: 'de 150 mil à 200 mil', value: '150000_200000' }"+
                                    ", { label: 'de 200 mil à 300 mil', value: '200000_300000' }"+
                                    ", { label: 'de 300 mil à 400 mil', value: '300000_400000' }"+
                                    ", { label: 'de 400 mil à 500 mil', value: '400000_500000' }"+
                                    ", { label: 'de 500 mil à 1 milhão', value: '500000_1000000' }"+
                                    ", { label: 'de 1 milhão à 3 milhões', value: '1000000_3000000' }"+
                                    ", { label: 'acima 3 milhões', value: '3000000_0'}]" +
                                ");");
                        }
                        else if ($("#" + this.destino.replace("#boxConteudo_", "") + "inf_finalidade").val() == "Alugar" || $("input[name='" + this.destino.replace("#boxConteudo_", "") + "inf_finalidade']:checked").val() == "Alugar") {
                            if (this.combos[i].slider)
                                eval(this.destino.replace("#boxConteudo_", "") + ".combos[" + i + "].setOptions(" +
                                    "[{ label: '0', value: '0' }" +
                                    ", { label: '0', value: '0' }" +
                                    ", { label: '2100', value: '2100' }" +
                                    ", { label: '2100', value: '2100'}]" +
                                ");");
                            else
                                eval(this.destino.replace("#boxConteudo_", "") + ".combos[" + i + "].setOptions(" +
                                    "[{ label: 'Indiferente', value: '' }" +
                                    ",{ label: 'até 300', value: '0_300' }" +
                                    ",{ label: 'de 300 à 400', value: '300_400' }" +
                                    ",{ label: 'de 400 à 500', value: '400_500' }" +
                                    ",{ label: 'de 500 à 750', value: '500_750' }" +
                                    ",{ label: 'de 750 à 1.000', value: '750_1000' }" +
                                    ",{ label: 'de 1.000 à 1.250', value: '1000_1250' }" +
                                    ",{ label: 'de 1.250 à 1.500', value: '1250_1500' }" +
                                    ",{ label: 'de 1.500 à 2.000', value: '1500_2000' }" +
                                    ",{ label: 'de 2.000 à 3.000', value: '2000_3000' }" +
                                    ",{ label: 'de 3.000 à 5.000', value: '3000_5000' }" +
                                    ",{ label: 'de 5.000 à 7.500', value: '5000_7500' }" +
                                    ",{ label: 'de 7.500 à 10.000', value: '7500_10000' }" +
                                    ",{ label: 'de 10.000 à 12.500', value: '10000_12500' }" +
                                    ",{ label: 'de 12.500 à 15.000', value: '12500_15000' }" +
                                    ",{ label: 'de 15.000 à 30.000', value: '15000_30000' }" +
                                    ",{ label: 'acima de 30.000', value: '30000_0' }]" +
                                ");");
                        }
                    break;
                    case "valor mínimo":
                        if ($("#" + this.destino.replace("#boxConteudo_", "") + "inf_finalidade").val() == "Comprar" || $("input[name='" + this.destino.replace("#boxConteudo_", "") + "inf_finalidade']:checked").val() == "Comprar") {
                            eval(this.destino.replace("#boxConteudo_", "") + ".combos[" + i + "].setOptions("+
                                "[{ label: 'Indiferente', value: '' }" +
                                ",{ label: '100 mil', value: '100000' }" +
                                ",{ label: '150 mil', value: '150000' }" +
                                ",{ label: '200 mil', value: '200000' }" +
                                ",{ label: '300 mil', value: '300000' }" +
                                ",{ label: '400 mil', value: '400000' }" +
                                ",{ label: '500 mil', value: '500000' }" +
                                ",{ label: '1 milhão', value: '1000000' }" +
                                ",{ label: '3 milhões', value: '3000000' }]" +
                            ");");
                        }
                        else if ($("#" + this.destino.replace("#boxConteudo_", "") + "inf_finalidade").val() == "Alugar" || $("input[name='" + this.destino.replace("#boxConteudo_", "") + "inf_finalidade']:checked").val() == "Alugar") {
                            eval(this.destino.replace("#boxConteudo_", "") + ".combos[" + i + "].setOptions(" +
                                "[{ label: 'Indiferente', value: '' }" +
                                ",{ label: '300', value: '300' }" +
                                ",{ label: '400', value: '400' }" +
                                ",{ label: '500', value: '500' }" +
                                ",{ label: '750', value: '750' }" +
                                ",{ label: '1.000', value: '1000' }" +
                                ",{ label: '1.250', value: '1250' }" +
                                ",{ label: '1.500', value: '1500' }" +
                                ",{ label: '2.000', value: '2000' }" +
                                ",{ label: '5.000', value: '5000' }" +
                                ",{ label: '8.000', value: '8000' }" +
                                ",{ label: '12.000', value: '12000' }" +
                                ",{ label: '15.000', value: '15000' }" +
                                ",{ label: '30.000', value: '30000' }]" +
                            ");");
                        }
                        
                    break;
                    case "valor máximo":
                        if ($("#" + this.destino.replace("#boxConteudo_", "") + "inf_finalidade").val() == "Comprar" || $("input[name='" + this.destino.replace("#boxConteudo_", "") + "inf_finalidade']:checked").val() == "Comprar") {
                            eval(this.destino.replace("#boxConteudo_", "") + ".combos[" + i + "].setOptions(" +
                                "[{ label: 'Indiferente', value: '' }" +
                                ",{ label: '100 mil', value: '100000' }" +
                                ",{ label: '150 mil', value: '150000' }" +
                                ",{ label: '200 mil', value: '200000' }" +
                                ",{ label: '300 mil', value: '300000' }" +
                                ",{ label: '400 mil', value: '400000' }" +
                                ",{ label: '500 mil', value: '500000' }" +
                                ",{ label: '1 milhão', value: '1000000' }" +
                                ",{ label: '3 milhões', value: '3000000' }]" +
                            ");");
                        }
                        else if ($("#" + this.destino.replace("#boxConteudo_", "") + "inf_finalidade").val() == "Alugar" || $("input[name='" + this.destino.replace("#boxConteudo_", "") + "inf_finalidade']:checked").val() == "Alugar") {
                            eval(this.destino.replace("#boxConteudo_", "") + ".combos[" + i + "].setOptions(" +
                                "[{ label: 'Indiferente', value: '' }" +
                                ",{ label: '300', value: '300' }" +
                                ",{ label: '400', value: '400' }" +
                                ",{ label: '500', value: '500' }" +
                                ",{ label: '750', value: '750' }" +
                                ",{ label: '1.000', value: '1000' }" +
                                ",{ label: '1.250', value: '1250' }" +
                                ",{ label: '1.500', value: '1500' }" +
                                ",{ label: '2.000', value: '2000' }" +
                                ",{ label: '5.000', value: '5000' }" +
                                ",{ label: '8.000', value: '8000' }" +
                                ",{ label: '12.000', value: '12000' }" +
                                ",{ label: '15.000', value: '15000' }" +
                                ",{ label: '30.000', value: '30000' }]" +
                            ");");
                        }
                        break;
                case "subtipo": campos[campos.length] = { tipo: this.combos[i].tipo, i: i, action: "PesquisarSubTipo", v_sel: v_sel }; $("#" + this.combos[i].id).val("Carregando..."); this.combos[i].val = ""; break;
                case "tipo": campos[campos.length] = { tipo: this.combos[i].tipo, i: i, action: "PesquisarTipo", v_sel: v_sel }; $("#" + this.combos[i].id).val("Carregando..."); this.combos[i].val = ""; break;
                case "uf": campos[campos.length] = { tipo: this.combos[i].tipo, i: i, action: "PesquisarUf", v_sel: v_sel }; $("#" + this.combos[i].id).val("Carregando..."); this.combos[i].val = ""; break;
                case "cidade": campos[campos.length] = { tipo: this.combos[i].tipo, i: i, action: "PesquisarCidade", v_sel: v_sel }; $("#" + this.combos[i].id).val("Carregando..."); this.combos[i].val = ""; break;
                case "bairro": campos[campos.length] = { tipo: this.combos[i].tipo, i: i, action: "PesquisarBairro", v_sel: v_sel }; $("#" + this.combos[i].id).val("Carregando..."); this.combos[i].val = ""; break;
                }
            }
            
        }
        
    }

    var v_eval = "";

    for (var i = 0; i < campos.length; i++) {
        v_eval += "ajax({ action: \"" + campos[i].action + "\", v_where: " + this.destino.replace("#boxConteudo_", "") + ".setWhere(), v_sel: \"" + campos[i].v_sel + "\", busca: \"" + this.tipoBusca + "\" }, function (retorno) {";
        v_eval += "eval(retorno);";
        v_eval += this.destino.replace("#boxConteudo_", "") + ".combos[" + campos[i].i + "].setOptions(dados);";
    }

    for (var i = 0; i < campos.length; i++) {
        v_eval += "  }); ";
    }
    eval(v_eval);
}

function setWhere() {
    var v_where = "";
    //verifica combos anteriores

    for (var i = 0; i < this.combos.length; i++) {
        switch (this.combos[i].tipo) {
            case "pretensão":
                if (this.combos[i].val != "") {
                    if (this.combos[i].checkbox) {
                        var arr_dados = this.combos[i].val.split(',');
                        var dados = "";
                        for (var j = 0; j < arr_dados.length; j++) {
                            if (arr_dados[j] == "Comprar")
                                dados += (dados == "" ? "" : "or") + " inf_venda = 1  ";
                            else if (arr_dados[j] == "Alugar")
                                dados += (dados == "" ? "" : "or") + " inf_locacao = 1  ";
                        }
                        v_where += " and  (" + dados + ") ";
                    }
                    else {
                        if (this.combos[i].val == "Comprar")
                            v_where += " and inf_venda = 1 ";
                        else if (this.combos[i].val == "Alugar")
                            v_where += " and inf_locacao = 1 ";
                    }
                }
                break;
            case "subtipo":
                if (this.combos[i].val != "")
                    if (this.combos[i].checkbox) {
                        var arr_dados = this.combos[i].val.split(',');
                        var dados = "";
                        for (var j = 0; j < arr_dados.length; j++) {
                            dados += (dados == "" ? "" : "or") + " inf_subtipo = ''" + arr_dados[j] + "'' ";
                        }
                        v_where += " and  (" + dados + ") ";
                    }
                    else
                        v_where += " and inf_subtipo = ''" + this.combos[i].val + "'' ";
                break;
            case "tipo":
                if (this.combos[i].val != "")
                    if (this.combos[i].checkbox) {
                        var arr_dados = this.combos[i].val.split(',');
                        var dados = "";
                        for (var j = 0; j < arr_dados.length; j++) {
                            dados += (dados == "" ? "" : "or") + " inf_tipo = ''" + arr_dados[j] + "'' ";
                        }
                        v_where += " and  (" + dados + ") ";
                    }
                    else
                        v_where += " and inf_tipo = ''" + this.combos[i].val + "'' ";
                break;
            case "uf":
                if (this.combos[i].val != "")
                    if (this.combos[i].checkbox) {
                        var arr_dados = this.combos[i].val.split(',');
                        var dados = "";
                        for (var j = 0; j < arr_dados.length; j++) {
                            dados += (dados == "" ? "" : "or") + " inf_uf = ''" + arr_dados[j] + "'' ";
                        }
                        v_where += " and (" + dados + ") ";
                    }
                    else
                        v_where += " and inf_uf = ''" + this.combos[i].val + "'' ";
                break;
            case "cidade":
                if (this.combos[i].val != "") {
                    if (this.combos[i].checkbox) {
                        var arr_dados = this.combos[i].val.split(',');
                        var dados = "";
                        for (var j = 0; j < arr_dados.length; j++) {
                            dados += (dados == "" ? "" : "or") + " inf_cidade = ''" + arr_dados[j] + "'' ";
                        }
                        v_where += " and ("+dados+") ";
                    }
                    else
                        v_where += " and inf_cidade = ''" + this.combos[i].val + "'' ";
                }
                break;
        }
    }

    return v_where;
}


function Pesquisar() {
    var urla = "";

    for (var i = 0; i < this.combos.length; i++) {
        $("#" + this.combos[i].id).attr("disabled", true);
        $("#boxOptions_" + this.combos[i].id).attr("disabled", true);
    }
    $(this.btnPesquisar).hide();
    $(this.boxAguarde).show();

    var script = "";

    for (var i = 0; i < this.combos.length; i++) {
        if (this.combos[i].val != "" && this.combos[i].val != null) {
            script += (script == "" ? "" : ";") + $.trim(this.combos[i].queryString) + "-" + this.combos[i].val;
            urla += (urla == "" ? "" : "-") + getFiltro($.trim(this.combos[i].queryString), this.combos[i].val);
        }
    }

    if (typeof ($("#inf_ordem_hidden").val()) != "undefined" && ($("#inf_ordem_hidden").val() != "valor") || ($("#inf_ordem_hidden").val() == "valor" && (typeof ($("#inf_asc_hidden").val()) != "undefined" && $("#inf_asc_hidden").val() != "asc")))
        script += (script == "" ? "" : ";") + "ordem-" + $("#inf_ordem_hidden").val() + ((typeof ($("#inf_asc_hidden").val()) != "undefined" && $("#inf_asc_hidden").val() != "asc") ? " desc" : "");

    if (typeof ($("#inf_qtd_hidden").val()) != "undefined" && $("#inf_qtd_hidden").val() != "10")
        script += (script == "" ? "" : ";") + "qtd-" + $("#inf_qtd_hidden").val();

    if (typeof (this.tipoBusca) != "undefined" && this.tipoBusca != "")
        script += (script == "" ? "" : ";") + "busca-" + this.tipoBusca;

    //grava a consulta
    ajax({ action: "gravarConsulta", query: script }, function (retorno) {
        window.open(v_path + url(urla) + "/C" + retorno, "_self");
    });
    //window.open(v_path + url(urla) + "/-/" + script, "_self");
    //window.open(v_path + "Resultado/" + script, "_self");
}

function filtrarResultado(elem) {
    var script = "";
    var existe = false;
    var urla = "";

    for (var i = 0; i < this.filtrosConsulta.length; i++) {
        if (this.filtrosConsulta[i].filtro != elem.queryString && this.filtrosConsulta[i].filtro != "pagina") {
            script += (script == "" ? "" : ";") + this.filtrosConsulta[i].filtro + "-" + this.filtrosConsulta[i].value;
            urla += (urla == "" ? "" : "-") + getFiltro(this.filtrosConsulta[i].filtro, this.filtrosConsulta[i].value);
        }
        else {
            if (elem.val != "") {
                script += (script == "" ? "" : ";") + elem.queryString + "-" + elem.val;
                urla += (urla == "" ? "" : "-") + getFiltro(elem.queryString, elem.val);
            }
            existe = true;
        }
    }

    if (!existe) {
        script += (script == "" ? "" : ";") + elem.queryString + "-" + elem.val;
        urla += (urla == "" ? "" : "-") + getFiltro(elem.queryString, elem.val);
    }

    if (elem.val != null) {
        if (script == "")
            window.open(v_path + "Resultado", "_self");
        else {
            //grava a consulta
            ajax({ action: "gravarConsulta", query: script }, function (retorno) {
                window.open(v_path + url(urla) + "/C" + retorno, "_self");
            });
            //window.open(v_path + url(urla) + "/-/" + script, "_self");
        }
        //window.open(v_path + "Resultado/" + script, "_self");
    }
}

function getFiltro(filtro, value) {
    var v_filtro_value = "", arr_valor = "";

    switch (filtro) {
        case "valor":
            v_valor = value.split("_");
            if (v_valor[0] == "0")
                v_filtro_value = "ate-" + formata_moeda(v_valor[1]);
            else if (v_valor[1] == "0")
                v_filtro_value = "a-partir-" + formata_moeda(v_valor[0]);
            else
                v_filtro_value = "de-" + formata_moeda(v_valor[0]) + "-ate-" + formata_moeda(v_valor[1]);
            break;
        case "valor2":
            v_valor = value.split("_");
            if (v_valor[0] == "0")
                v_filtro_value = "ate-" + formata_moeda(v_valor[1]);
            else if (v_valor[1] == "0")
                v_filtro_value = "a-partir-" + formata_moeda(v_valor[0]);
            else
                v_filtro_value = "de-" + formata_moeda(v_valor[0]) + "-ate-" + formata_moeda(v_valor[1]);
            break;
        case "valor mínimo": v_filtro_value = "a-partir-" + formata_moeda(value); break;
        case "valor máximo": v_filtro_value = "ate-" + formata_moeda(value); break;
        case "dormitórios": v_filtro_value = value + "-" + (value == "1" ? "dormitorio" : "dormitorios"); break;
        case "condomínio": v_filtro_value = (value == "Sim" ? "em-condominio" : "fora-de-codominio"); break;
        case "suítes": v_filtro_value = value + "-" + (value == "1" ? "suite" : "suites"); break;
        case "vagas": v_filtro_value = value + "-" + (value == "1" ? "vaga" : "vagas"); break;
        case "virtual tour": v_filtro_value = (value == "Sim" ? "virtual-tour" : "sem-virtual-tour"); break;
        case "área": v_filtro_value = ""; break;
        case "área mínima": v_filtro_value = ""; break;
        case "área máxima": v_filtro_value = ""; break;
        case "codigo": v_filtro_value = ""; break;
        case "pretensão": v_filtro_value = value; break;    
        case "pretensão2": v_filtro_value = value; break;    
        case "subtipo": v_filtro_value = value; break;    
        case "tipo": v_filtro_value = value; break;    
        case "tipo2": v_filtro_value = value; break;    
        case "cidade": v_filtro_value = value; break;    
        case "bairro": v_filtro_value = value; break;
        case "uf": v_filtro_value = value; break;
        case "corretor": v_filtro_value = "imoveis-"+value; break;    
    }

    return v_filtro_value;
}


function buscaRapida(parametros) {
    // Código fkempresa
    this.fkempresa = parametros.fkempresa;
    //Id de destino 
    this.destino = parametros.destino;
    //Layout
    this.layout = parametros.layout;
    //Filtros da pesquisa
    this.filtros = parametros.filtros;
    //Where adicional a pesquisa
    this.where = parametros.where;
    //elemento do botão pesquisar
    this.btnPesquisar = parametros.btnPesquisar;
    //box aguarde
    this.boxAguarde = parametros.boxAguarde;
    //combos da pesquisa
    this.combos = new Array();
    //Variavel q recebe os filtros consultados
    this.filtrosConsulta = new Array();
    //variavel que diz se a consulta vai se dar ao trocar o valor
    this.consultaOnChange = parametros.consultaOnChange;
    //variavel que define o tipo da busca
    this.tipoBusca = parametros.tipoBusca;
    //variavel que recebe o tipo de combo
    this.tipoCombo = parametros.tipoCombo;

    //Métodos
    this.imprimir = imprimir;
    this.setFiltros = setFiltros;
    this.setCombo = setCombo;
    this.Pesquisar = Pesquisar;
    this.setWhere = setWhere;
    this.setBDCombos = setBDCombos;
    this.atualizarBDCombos = atualizarBDCombos;
    this.filtrarResultado = filtrarResultado;
}

function formata_moeda(valor) {

    var preco = valor + "";
    var tam = preco.length;

    if (tam == 4)
        preco = preco.substr(0, 1) + '.' + preco.substr(1, 3);
    else if (tam == 5)
        preco = preco.substr(0, 2) + '.' + preco.substr(2, 3);
    else if (tam == 6)
        preco = preco.substr(0, 3) + '.' + preco.substr(3, 3);
    else if (tam == 7)
        preco = preco.substr(0, 1) + '.' + preco.substr(1, 3) + '.' + preco.substr(4, 3);
    else if (tam == 8)
        preco = preco.substr(0, 2) + '.' + preco.substr(2, 3) + '.' + preco.substr(5, 3);
    else if (tam == 9)
        preco = preco.substr(0, 3) + '.' + preco.substr(3, 3) + '.' + preco.substr(6, 3);

    return preco + ",00";
}
