﻿$(function () {

    $('#name-list').css('width', '320px');
    $("#CategoryID").combobox();
    $("#VehicleMakeID").combobox({ selected: function (event, ui) { $(this).trigger("change"); } });
    $("#VehicleModelID").combobox();
    $("#RegionID").combobox({ selected: function (event, ui) { $(this).trigger("change"); } });
    $("#AuctioneerID").combobox();
    $("#VehicleFuelTypeID").combobox();
    $("#KilometerID").combobox();
    $("#ColorID").combobox();
    $("#YearMinID").combobox();
    $("#YearMaxID").combobox();
    $("#VehiclePowerSearchID").combobox();

    $("#VehicleMakeID").change(function () {
        $.getJSON("/Search/GetMakeModels/", { vehiclemakeId: $(this).val() }, function (data) {
            //Clear the Model list
            $("#VehicleModelID").empty();
            //Foreach Model in the list, add a model option from the data returned
            $.each(data, function (index, optionData) {
                $("#VehicleModelID").append("<option value='" + optionData.Value + "'>" + optionData.Text + "</option>");
            });
            $("#VehicleModelID").val(0);
            $("#VehicleModelID").next().val($("#VehicleModelID" + " :selected").text());
        });
    });

    $("#RegionID").change(function () {
        $.getJSON("/Search/GetRegionAuctioneers/", { regionId: $(this).val() }, function (data) {
            //Clear the Model list
            $("#AuctioneerID").empty();
            //Foreach Model in the list, add a model option from the data returned
            $.each(data, function (index, optionData) {
                $("#AuctioneerID").append("<option value='" + optionData.Value + "'>" + optionData.Text + "</option>");
            });
            //var count = data.length;
            //alert(count);
            $("#AuctioneerID").val(0);
            $("#AuctioneerID").next().val($("#AuctioneerID" + " :selected").text());
        });
    });

});

$(document).ready(function () {
    $("#maincolumn").css("min-height", function () { return $("#sidecolumn").height() + 25 });
});

function SelectRegionA(region) {
    $("#RegionID").val(region);
    $("#RegionID").next().val($("#RegionID" + " :selected").text());
    $("#RegionID").trigger("change");
}
