﻿function getId(id) {
    return document.getElementById(id);
}

function validaBusca() {

}

$(document).ready(function() {
    $("#cmbCidade").change(function() {
        $("#cmbBairro").html("<option value='0' selected='selected'>Carregando...</option>");
        $.post("code/cmbBairro.ashx", { cod: $(this).val() }, function(data) {
            $("#cmbBairro").html(data);
        });
    });

    $("#txtCod").focus(function() { $("#txtCod").val(""); });

    $("#txtMax").maskMoney({ symbol: "", decimal: ".", thousands: " ", precision: 2 })
    $("#txtMin").maskMoney({ symbol: "", decimal: ".", thousands: " ", precision: 2 })

    $("#btnBuscar").click(function() {
        var tipo = $("#cmbTipo").val();
        var cidade = $("#cmbCidade").val();
        var bairro = $("#cmbBairro").val();
        var codigo = $("#txtCod").val();

        var chk = "";

        if (getId("rbAlugar").checked == true) {
            chk = "A";
        }
        if (getId("rbComprar").checked == true) {
            chk = "V";
        }

        var campos = "tp=" + tipo;
        campos += "&cd=" + cidade;
        campos += "&br=" + bairro;
        campos += "&chk=" + chk;

        if (($("#txtCod").val() == "Código") || ($("#txtCod").val() == "")) {
            campos += "&cod=0";
        } else {
            campos += "&cod=" + $("#txtCod").val();
        }

        if ($("#txtMin").val() != "") {
            campos += "&min=" + $("#txtMin").val();
        } else {
            campos += "&min=0";
        }
        if ($("#txtMax").val() != "") {
            campos += "&max=" + $("#txtMax").val();
        } else {
            campos += "&max=0";
        }

        campos += "&pg=0";

        window.location = "buscar.aspx?" + campos;

    });

    $(":text").focus(function() {
        $(this).addClass("textboxOn");
    });
    $(":text").blur(function() {
        $(this).removeClass("textboxOn");
    });

});
