// any changes, set changes_flag = 1
function setChangesFlag()
{
	var tab_active = $(FIND_TAB_ACTIVE).find("a").attr("href"); // id tab active
	//var id = $('#id', $(tab_active)).val();
	$(tab_active+"_change").val('1');
}

/**
 * Initializes the given input dialog.
 * @param {string | jQuery} dlg  the dialog selector or jQuery object 
 * @param {object} options       dialog options [ optional ]
 */
function initInputDialog(dlg, options) {
    var defaultOpts = {
        modal: true,
        autoOpen: false,
        width: 500,
        close: function () {
            $(this).find("input[type=text]").val(""); // clear all fields
            $(this).find("input").removeAttr("checked");
            $(this).find("select").val("0").attr("selected","selected");
            $(this).find("textarea").val("");
            $(this).find("input").removeAttr("disabled"); // enable all fields
            $(this).find("input").removeAttr("disabled");
            $(this).find("select").removeAttr("disabled");
            $(this).find("textarea").removeAttr("disabled");
			$(this).find("input").removeClass("disabled_style"); // remove style all fields
            $(this).find("input").removeClass("disabled_style");
            $(this).find("select").removeClass("disabled_style");
            $(this).find("textarea").removeClass("disabled_style");
        }
    };
    var opts = $.extend(defaultOpts, options);
    $obj(dlg).dialog(opts);
}

/**
 * Sets input dialog options.
 * @param {string | jQuery} dlg  the dialog selector or jQuery object 
 * @param {string} title         the dialog title
 * @param {string} actionName    the action button label
 * @param {function} fnAction    the function to run when the action button is
 *                               activated
 */
function setInputDialogOptions(dlg, title, actionName, fnAction) {
    var $dlg = $obj(dlg);
    var buttons = Object();	
    buttons[actionName] = function () {
        if (fnAction(this) != false)
        $(this).dialog('close');
    };
    buttons['Cancel'] = function () {
        $(this).dialog('close');
    };	
    $dlg.dialog('option', 'title', title);
    $dlg.dialog('option', 'buttons', buttons);
}

/**
 * Opens the given dialog.
 * If the dialog is already loaded into the DOM, it will be shown.
 * If it is not yet loaded, it will be dynamically loaded and then shown.
 * @param {string} dialogId        a unique dialog ID
 * @param {function} fnBeforeOpen  this function will be called before the 
 *                                 dialog is shown [ optional ]
 */
function openDialog(dialogId, fnBeforeOpen) {
    var _fnOpenDialog = function () {
        var $dlg = $('#'+dialogId);
        if (fnBeforeOpen) fnBeforeOpen($dlg);
        $dlg.dialog('open');
        //$('input:first', $dlg).focus().select();
    };
    if ($('#'+dialogId).length > 0) {
        _fnOpenDialog();
    }
    else {
        // Load if not yet loaded
        $('#dialog-container').load(ROOTPATH+'modules/dialog/'+dialogId+'.php', '', _fnOpenDialog);
    }
}

