﻿/// <reference name="MicrosoftAjax.js"/>

Type.registerNamespace("DicksonCounty.Site.js");

DicksonCounty.Site.js.AjaxPopulatedDropDownList = function(element) {
    DicksonCounty.Site.js.AjaxPopulatedDropDownList.initializeBase(this, [element]);
}

DicksonCounty.Site.js.AjaxPopulatedDropDownList.prototype = {
    initialize: function() {
        DicksonCounty.Site.js.AjaxPopulatedDropDownList.callBaseMethod(this, 'initialize');

        this.load();

        // Add custom initialization here
    },
    dispose: function() {
        //Add custom dispose actions here
        DicksonCounty.Site.js.AjaxPopulatedDropDownList.callBaseMethod(this, 'dispose');
    },

    load: function() {
        jQuery.blockUI(
            {
                message: '<h1><img src="/js/aspnet/image/large-ajax-loader.gif" alt="Loading..." /> Loading...</h1>'
            });

        eval( this._functionName + '(this._onSuccess, this._onFailure, this)');
    },

    _onSuccess: function(result, context, methodName) {
        var dropDownList = context.get_element();

        jQuery(dropDownList).children("option:not([value=0])").remove();

        for (var i in result) {
            jQuery("<option value='" + result[i].ID + "'>" + result[i].Name + "</option>").appendTo(dropDownList);
        }

        jQuery.unblockUI();
        context._raiseEvent("dropdownlistLoaded", null);
    },

    _onFailure: function(error, context, methodName) {
        jQuery.unblockUI();
        jQuery("<div>An error has occured:<br />" + error.get_message() + "</div>").attr("title", "Error").dialog({
            buttons: {
                Ok: function() {
                    jQuery(this).dialog('close');
                }
            },
            modal: 'true'
        });
    }
}

DicksonCounty.Site.js.AjaxPopulatedDropDownList.createProperty("functionName");

DicksonCounty.Site.js.AjaxPopulatedDropDownList.createEvent("dropdownlistLoaded");

DicksonCounty.Site.js.AjaxPopulatedDropDownList.registerClass('DicksonCounty.Site.js.AjaxPopulatedDropDownList', Sys.UI.Control);

if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
