$(function ()
{
    $('.MakeDropDownList').change(getYears);
    $('#YearDropDownList').attr('disabled', true);
    $('#ModelDropDownList').attr('disabled', true);
});

function getYears()
{
    $.ajax(
			{
			    type: "POST",
			    url: "CategoryWebService.asmx/GetSubCategoriesDesc",
			    contentType: "application/json; charset=utf-8",
			    data: "{parentCategoryId:'" + $('.MakeDropDownList').val() + "'}",
			    dataType: "json",
			    success: function (data)
			    {
			        $('#YearDropDownList').attr('disabled', false).hide().fadeIn('slow').change(getModels).removeOption(/./).addOption('', ' -- Select Year -- ');
			        $('#ModelDropDownList').attr('disabled', true).removeOption(/./);
			        $.each(data, function (index, value) { $('#YearDropDownList').addOption(value.CategoryId, value.Name, false) });
			    }
			});
}

function getModels()
{
    $.ajax(
			{
			    type: "POST",
			    url: "CategoryWebService.asmx/GetSubCategories",
			    contentType: "application/json; charset=utf-8",
			    data: "{parentCategoryId:'" + $('#YearDropDownList').val() + "'}",
			    dataType: "json",
			    success: function (data)
			    {
			        $('#ModelDropDownList').attr('disabled', false).hide().fadeIn('slow').change(getCategoryLink).removeOption(/./).addOption('', ' -- Select Model -- ');
			        $.each(data, function (index, value) { $('#ModelDropDownList').addOption(value.CategoryId, value.Name, false) });
			    }
			});
}

function getCategoryLink()
{
    $.ajax(
			{
			    type: "POST",
			    url: "CategoryWebService.asmx/GetCategoryLink",
			    contentType: "application/json; charset=utf-8",
			    data: "{categoryId:'" + $('#ModelDropDownList').val() + "'}",
			    dataType: "json",
			    success: function (data) { window.location = data.replace('~/', '') }
			});
}

