﻿/// <reference path="/Scripts/jquery-1.4.1.min-vsdoc.js" />

//vars
var html, finderBusinessCategoryId;

//methods
function setFinderBusinessCategoryId(id) {
    //finderBusinessCategoryId = id;
};

function getStatesByBusinessCategoryId() {
    $.ajax({
        type: "POST",
        url: "/webmethods/global.aspx/asynchfindstatesbybusinesscategoryid",
        dataType: 'json',
        contentType: 'application/json; charset=utf-8',
        data: "{'businessCategoryId' : '" + $("#finder select[id$='ddlSourceProfessional'] option:selected").val() + "'}",
        beforeSend: function () {
        },
        success: function (results) {
            $("#resource-finder-states").html('<option selected="selected" value="">Select a State</option>').attr("disabled", "");
            html += '<option value="0">All States</option>';
            $.each(results.d, function (i, state) {
                html += '<option value="' + state.StateCode + '">' + state.StateName + '</option>';
            });
            $("#resource-finder-states").append(html).change(function () {
                $("input[id$='BusinessCategoryId']").val($(this).val());
            });
        },
        failure: function (results) {
        }
    });
};

//event handlers
function ddlSourceProfessional_Change(sender) {
    //setFinderBusinessCategoryId();
    getStatesByBusinessCategoryId();
};

//DOM Ready
$(function () {
    //bind to change event
    $("#finder select[id$='ddlSourceProfessional']").change(function () {
        ddlSourceProfessional_Change($(this));
    });
    $("#resource-finder-states").attr("disabled", "disabled");
});
