﻿$(document).ready(function() {
    editComboInit();
});

function editComboInit() {
    $("input.editcombo").each(function() {
        var hidden = $(this);
        var id = hidden.attr("id");
        var select = $("#" + id + "_editcombo_select")
        var edit = $("#" + id + "_editcombo_edit")

        if (select.val() === "__editcomboother__") {
            edit.show();
            hidden.val(edit.val());
        } else {
            edit.hide().val("");
            hidden.val(select.val());
        }

        // Function to handle changing the select box from a value to "other"
        select.bind("change", function() {
            if (select.val() === "__editcomboother__") {
                edit.show();
                hidden.val(edit.val());
            } else {
                edit.hide();
                hidden.val(select.val());
            }
            validate(hidden);
        });

        // Function to handle value changes in the edit portion of this control
        edit.bind("keyup blur", function() {
            hidden.val(edit.val());
            validate(hidden);
        });
    });
};
