﻿/// <reference path="jquery-1.4.2.js" />

if (typeof NMA == "undefined") NMA = {};
if (typeof NMA.form == "undefined") NMA.form = {};

// Add options to drop down list
// id - id of drop down list
// options - object with options
if (typeof NMA.form.load_drop_down == "undefined") {
    NMA.form.load_drop_down = function(ddl, options, prompt_text, prompt_value) {
        var text = prompt_text;
        var value = prompt_value.length > 0 ? prompt_value : prompt_text;

        // add first item
        if (text.length > 0) {
            ddl.append($('<option></option>').val(value).html(text));
        }
        $.each(options.keys, function(index, value) {
            ddl.append($('<option></option>').val(value + "").html(options.text[index]));
        });

    };
}

if (typeof NMA.form.display_message == "undefined") {
    NMA.form.display_message = function(message_box_id, text, type) {

        var msg_box_id = "#" + message_box_id;

        var msg_box = $(msg_box_id);

        msg_box.text(text);
        msg_box.addClass(type);
        msg_box.show();
    };
}
if (typeof NMA.form.reset_fields == "undefined") {
    NMA.form.reset_fields = function(container_id, current_id, clear) {

        if (typeof clear == "undefined") {
            clear = false;
        }
        $("#" + container_id + " :input").not(":button, :submit, :reset").each(function() {

            var control = $(this);

            if (control.attr("id") != current_id) {

                switch (control.attr('type')) {
                    case "checkbox":
                        {
                            control.attr("checked", "");
                            break;
                        }
                    default:
                        {
                            control.val(clear ? "" : this.defaultValue);
                            break;
                        }
                }
            }
        });
    };

}

