﻿function show(mode) {
    if (mode == "grid") {
        $("#jsImoLista").attr("style", "display:none");
        $(".detalhada_div").attr("style", "display:none");
        $(".tabela").attr("style", "display:block");
        $(".show_list").removeClass("selecionado");
        $(".show_deta").removeClass("selecionado");
        $(".show_grid").addClass("selecionado");
    } else if (mode == "deta") {
        $("#jsImoLista").attr("style", "display:none");
        $(".detalhada_div").attr("style", "display:block");
        $(".tabela").attr("style", "display:none");
        $(".show_grid").removeClass("selecionado");
        $(".show_list").removeClass("selecionado");
        $(".show_deta").addClass("selecionado");
    } else {
        $("#jsImoLista").attr("style", "display:block");
        $(".detalhada_div").attr("style", "display:none");
        $(".tabela").attr("style", "display:none");
        $(".show_grid").removeClass("selecionado");
        $(".show_deta").removeClass("selecionado");
        $(".show_list").addClass("selecionado");
    }

    $('#Show').val(mode);

    $(".pages a").each(function() {
        var href = $(this).attr("href");

        href = href.replace("&&", "&");
        href = href.replace("Show=list", "");
        href = href.replace("Show=deta", "");
        href = href.replace("Show=grid", "");

        var posicao = href.indexOf("?");

        if (posicao > 0) {
            if (posicao == (href.length - 1)) {
                href += "Show=" + mode;
            } else {
                href += "&Show=" + mode;
            }
        } else {
            href += "?Show=" + mode;
        }
        $(this).attr("href", href);
    });
}

function price(Negocio) {
    var options = '';

    // Locação
    if (Negocio == 2 || Negocio == 3) {
        options += '<option value="0">Indiferente</option>';
        options += '<option value="0|300">Até 300</option>';
        options += '<option value="301|400">De 300 a 400</option>';
        options += '<option value="401|500">De 400 a 500</option>';
        options += '<option value="501|600">De 500 a 600</option>';
        options += '<option value="601|800">De 600 a 800</option>';
        options += '<option value="801|1000">De 800 a 1.000</option>';
        options += '<option value="1001|1500">De 1.000 a 1.500</option>';
        options += '<option value="1501|0">Acima de 1.500</option>';
    } else {
        options += '<option value="0">Indiferente</option>';
        options += '<option value="0|30000">Até 30 mil</option>';
        options += '<option value="30001|40000">De 30 a 40 mil</option>';
        options += '<option value="40001|70000">De 40 a 70 mil</option>';
        options += '<option value="70001|100000">De 70 a 100 mil</option>';
        options += '<option value="100001|200000">De 100 a 200 mil</option>';
        options += '<option value="200001|300000">De 200 a 300 mil</option>';
        options += '<option value="300001|500000">De 300 a 500 mil</option>';
        options += '<option value="500001|750000">De 500 a 750 mil</option>';
        options += '<option value="750001|0">Acima de 750 mil</option>';
    }
    $("select#Valor").html(options);
}

$(function() {
    show(Show);
    price(Negocio);

    $("select#Negocio").change(function() {
        price(this.value);
    });

    $("select#Negocio option").each(function() {
        if ($(this).val() > 0 && $(this).val() == Negocio) {
            select("Negocio", $(this));
        }
    });
    $("select#Tipo option").each(function() {
        if ($(this).val() != '0' && $(this).val() == Tipo) {
            select("Tipo", $(this));
        }
    });
    $("select#Cidade option").each(function() {
        if ($(this).val() != 10 && $(this).val() == Cidade) {
            select("Cidade", $(this));
        }
    });
    $("select#Valor option").each(function() {
        if ($(this).val() > 0 && $(this).val() == Valor) {
            select("Valor", $(this));
        }
    });

    $("select#Bairro option").each(function() {
        if ($(this).val() > 0 && $(this).val() == Bairro) {
            select("Bairro", $(this));
        }
    });

    $("select#Quartos option").each(function() {
        if ($(this).val() > 0 && $(this).val() == Quartos) {
            select("Quartos", $(this));
        }
    });

    $("select#Valor option").each(function() {
        if ($(this).val() != '0' && $(this).val() == Valor) {
            select("Valor", $(this));
        }
    });
})

function select(campo, opcao) {
    $('#' + campo).attr("style", "font-weight:bold; background-color:#E0E9EF");
    opcao.attr("selected", "selected");
}

/*mascara*/
jQuery(function($) {
    $("#data").mask("99/99/9999");
    $("#Telefone").mask("(99) 9999-9999");
    $("#cpf").mask("999.999.999-99");
    $("#cnpj").mask("99.999.999/9999-99");
    $("#cep").mask("99999-999");
    $("#placa").mask("aaa-9999");
    $("#real").maskMoney({ symbol: "R$", decimal: ",", thousands: "." })
});

function CountLista() {
    $("#CountLista").html($.cookie("CountLista"));
}

