(function ($) {
    var modaldialog = {}; function showDialog(msg, options) {
        if (!$.inArray(options.type, modaldialog.DialogTypes)) { options.type = modaldialog.DialogTypes[0]; }; var settings = $.extend({ title: modaldialog.DialogTitles[options.type] }, modaldialog.defaults, options); settings.timeout = (typeof (settings.timeout) == "undefined") ? 0 : settings.timeout; settings.showClose = ((typeof (settings.showClose) == "undefined") | !settings.timeout) ? true : !!settings.showClose; if (!document.getElementById('dialog')) { dialog = document.createElement('div'); dialog.id = 'dialog'; $(dialog).html("<div id='dialog-header'>" + "<div id='dialog-title'></div>" + "<div id='dialog-close'></div>" + "</div>" + "<div id='dialog-content'>" + "<div id='dialog-content-inner' />" + "<div id='dialog-button-container'>" + "<input type='button' id='dialog-button' value='Close'>" + "</div>" + "</div>"); dialogmask = document.createElement('div'); dialogmask.id = 'dialog-mask'; $(dialogmask).hide(); $(dialog).hide(); document.body.appendChild(dialogmask); document.body.appendChild(dialog); $("#dialog-close").click(modaldialog.hide); $("#dialog-button").click(modaldialog.hide); }
        var dl = $('#dialog'); var dlh = $('#dialog-header'); var dlc = $('#dialog-content'); var dlb = $('#dialog-button'); $('#dialog-title').html(settings.title); $('#dialog-content-inner').html(msg); dl.css('width', settings.width); var dialogTop = Math.abs($(window).height() - dl.height()) / 2; dl.css('left', ($(window).width() - dl.width()) / 2); dl.css('top', (dialogTop >= 25) ? dialogTop : 25); $.each(modaldialog.DialogTypes, function () { dlh.removeClass(this + "header") }); dlh.addClass(settings.type + "header")
        $.each(modaldialog.DialogTypes, function () { dlc.removeClass(this) }); dlc.addClass(settings.type); $.each(modaldialog.DialogTypes, function () { dlb.removeClass(this + "button") }); dlb.addClass(settings.type + "button")
        if (!settings.showClose) { $('#dialog-close').hide(); $('#dialog-button-container').hide(); } else { $('#dialog-close').show(); $('#dialog-button-container').show(); }
        if (settings.timeout) { window.setTimeout("$('#dialog').fadeOut('slow', 0); $('#dialog-mask').fadeOut('normal', 0);", (settings.timeout * 1000)); }
        dl.fadeIn("slow"); $('#dialog-mask').fadeIn("normal");
    }; modaldialog.error = function $$modaldialog$error(msg, options) {
        if (typeof (options) == "undefined") { options = {}; }
        options['type'] = "error"; return (showDialog(msg, options));
    }
    modaldialog.warning = function $$modaldialog$error(msg, options) {
        if (typeof (options) == "undefined") { options = {}; }
        options['type'] = "warning"; return (showDialog(msg, options));
    }
    modaldialog.success = function $$modaldialog$error(msg, options) {
        if (typeof (options) == "undefined") { options = {}; }
        options['type'] = "success"; return (showDialog(msg, options));
    }
    modaldialog.prompt = function $$modaldialog$error(msg, options) {
        if (typeof (options) == "undefined") { options = {}; }
        options['type'] = "prompt"; return (showDialog(msg, options));
    }
    modaldialog.hide = function $$modaldialog$hide() { $('#dialog').fadeOut("slow", function () { $(this).hide(0); }); $('#dialog-mask').fadeOut("normal", function () { $(this).hide(0); }); }; modaldialog.DialogTypes = new Array("error", "warning", "success", "prompt"); modaldialog.DialogTitles = { "error": "!! Error !!", "warning": "Warning!", "success": "Success", "prompt": "Please Choose" }; modaldialog.defaults = { timeout: 0, showClose: true, width: 525 }; $.extend({ modaldialog: modaldialog });
})(jQuery);
