﻿// Name:        Thallo.Web.UI.WebControls.DialogFrames.scripts.DialogFrame.debug.js
// Assembly:    Thallo.Web
// Version:     1.0.0.0
// FileVersion: 1.0.0.0
/// <reference name="MicrosoftAjax.debug.js"/>
/// <reference path="../../scripts/jquery-1.3.2-vsdoc2.js" />

/// Comment version: 1.0.0

Type.registerNamespace("DialogFrame");

DialogFrame.PanelBase = function(element) {
    ///	<summary locid = "M:J#DialogFrame.PanelBase.#ctor">封装给定的 DOM 元素使之可以定位</summary>
    ///	<param name="element" type="DOM">DOM 元素</param>
    ///	<returns type="DialogFrame.PanelBase" />
    DialogFrame.PanelBase.initializeBase(this, [element]);

    // Properties
    this._ZIndex = 0;
    this._Covered = true;
    this._Fixed = false;
    this._Eyeable = true;
    this._X = -1;
    this._Y = -1;

    // Variables
    this._jqground = null;
    this._jqelement = null;
    this._jqframe = null;
    this._showing = false;
    this._layoutHandler = null;
    this._saveTabIndexes = new Array();
    this._saveDesableSelect = new Array();
};

DialogFrame.PanelBase.prototype = {
    initialize: function() {
        /// <summary>初始化当前 DialogFrame.PanelBase 对象。</summary>
        DialogFrame.PanelBase.callBaseMethod(this, 'initialize');

        if (this._ZIndex == 0)
            this._ZIndex = this._validIndex();
        this._jqelement = $(this._element).css({ position: 'absolute', zIndex: this._ZIndex + 2, display: 'none' });
        this._jqground = $("<div />").insertBefore(this._jqelement).attr({ 'class': 'df-pb-cover' }).css({ display: 'none', position: 'absolute', zIndex: this._ZIndex, top: 0, left: 0 }).defaultcss({ opacity: 0.2, backgroundColor: 'white' });

        this._layoutHandler = Function.createDelegate(this, this._onLayout);

        if (this.isIE6()) {
            this._jqframe = this.create("iframe", this._jqelement.parent()).css({ position: 'absolute', zIndex: this._ZIndex + 1, display: 'none' });
            $(this._element).resize(Function.createDelegate(this, this._onResize));
        }
    },
    dispose: function() {
        /// <summary>从应用程序中移除当前 DialogFrame.PanelBase 对象。</summary>
        this._layoutHandler = null;
        if (this._jqground)
            this._jqground.remove();

        DialogFrame.PanelBase.callBaseMethod(this, 'dispose');
    },
    preShow: function() {
        this._jqelement.show();
        this._showing = true;
    },
    show: function(o) {
        /// <summary>呈现封装的 DOM 元素</summary>
        /// <param name="o" type="object">（可选）显示对象的位置的 JSON 对象。可用的属性为 x, y。</param>
        if (!this._showing && (this.isVisible() || this.dispatchEvent('showing')))
            return;
        this._ZIndex = this._validIndex();
        this._jqelement.css({ zIndex: this._ZIndex + 2 }).show();
        this._showing = false;
        this.setProperties(o);

        this.moveTo();
        this.set_Covered(this._Covered, true);
        this.set_Fixed(this._Fixed, true);
        this.set_Eyeable(this._Eyeable, true);
        if (this.isIE6()) {
            var os = this._jqelement.offset();
            this._jqframe.css({ zIndex: this._ZIndex + 1, display: 'block', left: os.left, top: os.top, width: this._jqelement.width(), height: this._jqelement.height() });
        }

        this.dispatchEvent('showed')
    },
    hide: function() {
        /// <summary>隐藏封装的 DOM 元素。</summary>
        if (!this.isVisible() || this.dispatchEvent('hiding'))
            return;

        if (this._Fixed) {
            if (this.isIE6())
                $removeHandler(window, 'scroll', this._layoutHandler);
            else
                this._jqelement.css('position', 'absolute');
        }
        if (this._Eyeable) {
            $removeHandler(window, 'resize', this._layoutHandler);
        }
        if (this._Covered) {
            this._restoreTab();
            this._jqground.hide();
        }
        this._jqelement.hide();
        if (this.isIE6())
            this._jqframe.css({ display: 'none' });

        this.dispatchEvent('hidden');
    },
    location: function() {
        /// <summary>布局封装的 DOM 元素使之符合设置。</summary>
        this._location();
    },
    moveTo: function(x, y) {
        /// <summary>移动封装的 DOM 元素至指定的坐标。</summary>
        /// <param name="x" type="int">（可选）显示对象的 x 坐标。</param>
        /// <param name="y" type="int">（可选）显示对象的 y 坐标。</param>
        var o = {};
        if (x != undefined)
            o.x = x;
        if (y != undefined)
            o.y = y;
        this.setProperties(o);
        this.location();
    },
    isVisible: function() {
        /// <summary>当前封装的 DOM 元素是否可见。</summary>
        return this.get_isInitialized() && this._jqelement.css("display") != "none";
    },
    _onResize: function() {
        this._jqframe.css({ width: this._jqelement.width(), height: this._jqelement.height() });
    },
    _onLayout: function() {
        this._location(true);
    },
    _location: function(fixed) {
        if (!this.isVisible())
            return;
        var e = this._jqelement, cb = this.getCB();
        if (this._X < 0 && this._Fixed && !this.isIE6())
            this._X = Math.round((cb.w - e.outerWidth()) / 2);
        else if (this._X < 0)
            this._X = Math.round(cb.x + (cb.w - e.outerWidth()) / 2);

        if (this._Y < 0 && this._Fixed && !this.isIE6())
            this._Y = Math.round((cb.h - e.outerHeight() - 100) / 2);
        else if (this._Y < 0)
            this._Y = Math.round(cb.y + (cb.h - e.outerHeight() - 100) / 2);


        var x = this._X;
        var y = this._Y;

        if (this._Fixed && fixed) {
            x = e.offset().left + cb.x - this.lastcb.x;
            y = e.offset().top + cb.y - this.lastcb.y;
        }

        if (this._Eyeable) {
            if (this._Fixed && !this.isIE6()) {
                x = Math.max(0, Math.min(cb.r - e.outerWidth(), x));
                y = Math.max(0, Math.min(cb.b - e.outerHeight(), y));
            }
            else {
                x = Math.max(cb.x, Math.min(cb.r - e.outerWidth(), x));
                y = Math.max(cb.y, Math.min(cb.b - e.outerHeight(), y));
            }
        }
        e.css({ left: x, top: y });

        this.lastcb = cb;
        if (this.isIE6())
            this._jqframe.css({ left: x, top: y, width: e.width(), height: e.height() });
    },
    _disableTab: function() {
        var i = 0, t = this;
        Array.clear(this._saveTabIndexes);

        $("a, area, button, input, object, select, textarea, iframe").each(function(i, e) {
            t._saveTabIndexes.push({ tag: e, index: e.tabIndex });
            e.tabIndex = -1;
        });

        i = 0;
        if (this.isIE6()) {
            $("SELECT").not($("SELECT", this._element)).each(function(i, e) {
                t._saveDesableSelect.push({ tag: e, visibility: e.style.visibility });
                e.style.visibility = 'hidden';
            });
        }
    },
    _restoreTab: function() {
        $.each(this._saveTabIndexes, function(i, o) {
            o.tag.tabIndex = o.index;
        });
        Array.clear(this._saveTabIndexes);

        if (this.isIE6()) {
            $.each(this._saveDesableSelect, function(i, o) {
                o.tag.style.visibility = o.visibility;
            });
        }
        Array.clear(this._saveDesableSelect);
    },
    _Global: { index: 1000000 },
    _validIndex: function(i) {
        if (typeof (i) == "number")
            this._Global.index = i;
        else
            i = this._Global.index;
        this._Global.index += 10;
        return i;
    },
    set_Fixed: function(v, i) {
        if (v !== this._Fixed || i) {
            this._Fixed = v;
            if (this.isVisible()) {
                if (this._Fixed) {
                    if (this.isIE6())
                        $addHandler(window, 'scroll', this._layoutHandler);
                    else
                        this._jqelement.css('position', 'fixed');
                }
                else if (!i) {
                    if (this.isIE6())
                        $removeHandler(window, 'scroll', this._layoutHandler);
                    else
                        this._jqelement.css('position', 'absolute');
                }
            }
        }
    },
    set_Eyeable: function(v, i) {
        if (v !== this._Eyeable || i) {
            this._Eyeable = v;
            if (this.isVisible()) {
                if (this._Eyeable)
                    $addHandler(window, 'resize', this._layoutHandler);
                else if (!i)
                    $removeHandler(window, 'resize', this._layoutHandler);
            }
        }
    },
    set_Covered: function(v, i) {
        if (v !== this._Covered || i) {
            this._Covered = v;
            if (this.isVisible()) {
                if (this._Covered) {
                    this._jqground.css({ zIndex: this._ZIndex, width: $(document).width(), height: $(document).height() }).show();
                    this._disableTab();
                }
                else if (!i) {
                    this._restoreTab();
                    this._jqground.hide();
                }
            }
        }
    },
    set_ZIndex: function(v) {
        if (v !== 0) {
            this._ZIndex = this._validIndex(v);
        }
    },
    set_X: function(v) {
        if (this._X != v) {
            this._X = v;
            if (this.isVisible())
                this.moveTo();
        }
    },
    set_Y: function(v) {
        if (this._Y != v) {
            this._Y = v;
            if (this.isVisible())
                this.moveTo();
        }
    }
};
DialogFrame.PanelBase.registerClass('DialogFrame.PanelBase', Sys.UI.Behavior);
DialogFrame.PanelBase.registerProperties([
    { name: 'Fixed', summary: '指定封装的 DOM 元素是否相对窗体进行定位。' },
    { name: 'Eyeable', summary: '指定封装的 DOM 元素是否保持在窗体区域可见。' },
    { name: 'Covered', summary: '指定是否显示覆盖背景。' },
    { name: 'ZIndex', summary: '指定显示的 zIndex 值。默认值为 10000。' },
    { name: 'X', summary: '指定显示的位置的横坐标。' },
    { name: 'Y', summary: '指定显示的位置的纵坐标。' }
    ]);
DialogFrame.PanelBase.registerEvents([
    { name: 'showing', summary: '封装的 DOM 元素正在呈现。' },
    { name: 'showed', summary: '封装的 DOM 元素已呈现' },
    { name: 'hiding', summary: '封装的 DOM 元素正准备隐藏。' },
    { name: 'hidden', summary: '封装的 DOM 元素已隐藏。' }
    ]);


DialogFrame.DialogBase = function(element) {
    ///	<summary>封装给定的 DOM 元素使之可以定位、移动和大小更改</summary>
    DialogFrame.DialogBase.initializeBase(this, [element]);

    this._XResizable = true;
    this._YResizable = true;
    this._Moveable = true;
    this._Limiting = true;
    this._Closeable = true;
    this._Caption = "Loading";
    this._Theme = "";
    this._CloseLabel = "";
    this._Width = -1;
    this._Height = -1;
    this._MinWidth = 100;
    this._MinHeight = 80;

    this._MaxWidth = Math.round(window.screen.width * 0.8);
    this._MaxHeight = Math.round(window.screen.height * 0.6);

    this._moving = false;
    this._panelBase = null;
    this._moveHandler = null;
};
DialogFrame.DialogBase.prototype = {
    initialize: function() {
        /// <summary>初始化当前 DialogFrame.DialogBase 对象。</summary>
        DialogFrame.DialogBase.callBaseMethod(this, 'initialize');

        var mc = this.mc = $("<span style='position: absolute;'><table cellSpacing='0' cellPadding='0'  class='df-db-wapper' style='*border-collapse:collapse;'>" +
            "<tr><td colspan='3'><div class='df-db-header'><div class='df-db-headerLeft' style='position:absolute; left: 0px; top: 0px;' /><div class='df-db-headerRight' style='position:absolute; right: 0px; top: 0px;' /><a href='javascript:;' class='df-db-close' style='position:absolute;' /><span class='df-db-title'>" + this._Caption + "</span></div></td></tr>" +
            "<tr><td class='df-db-mainLeft'></td><td><div class='df-db-main' style='overflow: auto;' /></td><td class='df-db-mainRight'></td></tr>" +
            "<tr><td colspan='3'><div class='df-db-bottom'><div class='df-db-bottomLeft' style='position:absolute; bottom: 0px; left: 0px;' /><div class='df-db-bottomRight' style='position:absolute; bottom: 0px; right: 0px;' /><div class='df-db-resize' style='position:absolute; bottom: 0px; right: 0px;' /></div></td></tr>" +
            "</table></span>").appendTo($("<span class='" + this._Theme + "' />").appendTo(document.forms[0]));

        this._moveHandler = Function.createDelegate(this, this._startMove);

        var o = this.grepProperties(DialogFrame.PanelBase.getProperties());
        this._panelBase = $create(DialogFrame.PanelBase, o, null, null, mc.get(0));
        if (this.isIE6())
            $('div,a', mc).css({ overflow: 'hidden' });

        $(this._element).css({ display: "block" }).appendTo($('.df-db-main', mc));
    },
    dispose: function() {
        /// <summary>从应用程序中移除当前 DialogFrame.DialogBase 对象。</summary>
        DialogFrame.DialogBase.callBaseMethod(this, 'dispose');
        if (this._panelBase) {
            this._panelBase.dispose();
            this.mc.parent().remove();
        }
    },
    isVisible: function() {
        /// <summary>当前封装的 DOM 元素是否可见。</summary>
        return this.get_isInitialized() && this._jqelement.css("display") != "none";
    },
    preShow: function() {
        this._panelBase.preShow();
    },
    show: function(o) {
        /// <summary>呈现封装的 DOM 元素</summary>
        /// <param name="s" type="object">（可选）显示对象的位置的 JSON 对象。可用的属性为 x, y, width, height, minwidth, minheight, maxwidth, maxheight。</param>
        if (!this._panelBase._showing && (this.isVisible() || this.dispatchEvent('showing')))
            return;
        this.preShow();
        this.setProperties(o);

        this.set_Theme(this._Theme, true);
        this.set_Caption(this._Caption, true);
        if (this._XResizable == this._YResizable) {
            this.set_Resizable(this._XResizable, true);
        }
        else {
            this.set_XResizable(this._XResizable, true);
            this.set_YResizable(this._YResizable, true);
        }
        this.set_Moveable(this._Moveable, true);
        this.set_Closeable(this._Closeable, true);
        this.set_CloseLabel(this._CloseLabel, true);

        this.resize();
        this._panelBase.show(o);
        //$(".df-db-main", this.mc).get(0).focus();

        this.dispatchEvent('showed');
    },
    hide: function() {
        /// <summary>隐藏封装的 DOM 元素。</summary>
        if (!this.isVisible() || this.dispatchEvent('hiding'))
            return;
        this._panelBase.hide();
        $(".df-db-main", this.mc).get(0).blur();
        this.dispatchEvent('hidden')
    },
    moveTo: function(x, y) {
        /// <summary>移动封装的 DOM 元素至指定的坐标。</summary>
        /// <param name="x" type="int">显示对象的 x 坐标。</param>
        /// <param name="y" type="int">显示对象的 y 坐标。</param>
        this._panelBase.moveTo(x, y);
    },
    resize: function(w, h) {
        /// <summary>调整封装的 DOM 元素的大小。</summary>
        /// <param name="w" type="int">调整的宽度值。</param>
        /// <param name="h" type="int">调整的高度值。</param>
        if (w != undefined)
            this._Width = w;
        if (w != undefined)
            this._Height = h;
        this._resize(this._Width, this._Height);
    },
    addButtons: function(buttons) {
        /// <summary>为窗体添加自定义按钮到。</summary>
        /// <param name="buttons" type="array">自定义按钮设置数组。按钮的设置使用 JSON 对象表示。可使用参数为：label, class, click。</param>
        var t = this;
        $.each(buttons, function(i, v) {
            var b = $("<a href='javascript:;' tabIndex='-1' />").css({ position: 'absolute' }).appendTo($(".df-db-header", t.mc));
            if (v['class'])
                b.addClass(v['class']);
            if (v.label)
                b.html(v.label);
            if (v.click)
                b.bind('click', function() { v.click(t, Sys.EventArgs.Empty); });
            b.bind('mousedown', function() { return false; });
            if (t.isIE6())
                b.css({ overflow: 'hidden' });
        });
    },
    getDialogElement: function() {
        /// <summary>获取模式窗体的 DOM 元素。</summary>
        return this.mc.get(0);
    },
    isVisible: function() {
        if (this._panelBase)
            return this._panelBase.isVisible();
    },
    _resize: function(w, h) {
        var e = $(this._element), f = w > 0 || h > 0;

        if (w <= 0 || isNaN(w))
            w = e.outerWidth(true);
        if (h <= 0 || isNaN(h))
            h = e.outerHeight(true);
        if (this._MaxWidth > 0)
            w = Math.min(w, this._MaxWidth);
        if (this._MaxHeight > 0)
            h = Math.min(h, this._MaxHeight);

        if (this._MinWidth > 0)
            w = Math.max(w, this._MinWidth);
        if (this._MinHeight > 0)
            h = Math.max(h, this._MinHeight);

        var m = $(".df-db-main", this.mc);
        if (w == this._MinWidth || w == this._MaxWidth || f)
            m.css({ width: w });
        else
            m.css({ width: "auto" });

        if (h == this._MinHeight || h == this._MaxHeight || f)
            m.css({ height: h });
        else
            m.css({ height: "auto" });
    },
    _close: function(evt) {
        this.dispatchEvent('close');
        return false;
    },
    _startMove: function(evt) {
        if (!this._moving) {
            this._moving = true;

            var mc = this.mc, mw = $(".df-db-main", mc), mcs = evt.data;
            var os = mc.offset(), cb = this.getCB();
            var z = this.get_ZIndex();
            var mo = this._moveObj = { x: evt.clientX + cb.x, y: evt.clientY + cb.y, w: mc.outerWidth(), h: mc.outerHeight(), ox: evt.clientX + cb.x - os.left, oy: evt.clientY + cb.y - os.top, cb: cb, os: os };
            this._limitObj = { osw: mo.w - mw.width(), osh: mo.h - mw.height() };
            $.extend(this._limitObj, { minw: this._MinWidth > 0 ? this._MinWidth + this._limitObj.osw : 0, minh: this._MinHeight > 0 ? this._MinHeight + this._limitObj.osh : this._MinHeight, maxw: this._MaxWidth > 0 ? this._MaxWidth + this._limitObj.osw : Number.MAX_VALUE, maxh: this._MaxHeight > 0 ? this._MaxHeight + this._limitObj.osh : Number.MAX_VALUE });

            var mh = Function.createDelegate(this, this._move);
            var me = Function.createDelegate(this, this._endMove);
            if (mc.get(0).setCapture) {
                mc.get(0).setCapture();
                $(document.documentElement).bind('mousemove', mcs, mh);
                $(document.documentElement).bind('mouseup', mcs, me);
            }
            else if (window.captureEvents) {
                window.captureEvents(Event.MOUSEMOVE | Event.MOUSEUP);
                $(window).bind('mousemove', mcs, mh);
                $(window).bind('mouseup', mcs, me);
            }

            if (typeof (this.mb) == "undefined")
                this.mb = $("<div style='position: absolute; backgroundColor: white;  z-index: " + (z + 5) + "; left: 0px; top: 0px; width: " + $(document).width() + "px; height:" + $(document).height() + "; cursor:" + (mcs == "m" ? "move" : mcs + "-resize") + ";' />").css('opacity', '0').insertAfter(mc);

            this.mm = $("<div class='df-db-mover' style='position:absolute; z-index:" + (z + 6) + "; cursor:" + (mcs == "m" ? "move" : mcs + "-resize") + ";' />").css('opacity', '0.5').insertAfter(mc);
            this.mm.css({ left: os.left, top: os.top, width: mo.w + this.mm.width() - this.mm.outerWidth(), height: mo.h + this.mm.height() - this.mm.outerHeight() });

            return false;
        }
    },
    _move: function(evt) {
        if (this._moving) {
            var mm = this.mm, mo = this._moveObj, lo = this._limitObj;
            var cb = mo.cb, ep = { x: evt.clientX + cb.x, y: evt.clientY + cb.y }, m = {}, l = this._Limiting, minw = lo.minw, minh = lo.minh, maxw = lo.maxw, maxh = lo.maxh;

            var mcs = evt.data;
            if (mcs == 'm') {
                if (l) {
                    ep.x = Math.max(cb.x + mo.ox, Math.min(ep.x, cb.r - mo.w + mo.ox));
                    ep.y = Math.max(cb.y + mo.oy, Math.min(ep.y, cb.b - mo.h + mo.oy));
                }
                else {
                    ep.x = Math.min(cb.r, Math.max(0, ep.x));
                    ep.y = Math.min(cb.b, Math.max(0, ep.y));
                }
                m.x = ep.x - mo.ox;
                m.y = ep.y - mo.oy;
            }
            if (mcs.substr(0, 1) == 'n') {
                ep.y = l ? Math.max(cb.y + mo.oy, ep.y) : Math.max(0, ep.y);

                m.h = mo.y - ep.y + mo.h;
                m.y = ep.y - mo.oy;
                if (m.h > maxh)
                    m.y -= maxh - m.h;
                if (m.h < minh)
                    m.y -= minh - m.h;
                window.status = m.y + "," + m.h + "," + minh;
            }
            if (mcs.substr(0, 1) == 's') {
                ep.y = l ? Math.min(ep.y, cb.b - mo.h + mo.oy) : Math.min(ep.y, cb.b);
                m.h = ep.y - mo.y + mo.h;
            }
            if (mcs.substr(0, 1) == 'w' || mcs.substr(1, 1) == 'w') {
                ep.x = l ? Math.max(cb.x + mo.ox, ep.x) : Math.max(0, ep.x);
                m.x = ep.x - mo.ox;
                m.w = mo.x - ep.x + mo.w;
                if (m.w > maxw)
                    m.x -= maxw - m.h;
                if (m.w < minw)
                    m.x -= minw - m.w;
            }
            if (mcs.substr(0, 1) == 'e' || mcs.substr(1, 1) == 'e') {
                ep.x = l ? Math.min(ep.x, cb.r - mo.w + mo.ox) : Math.min(ep.x, cb.r);
                m.w = ep.x - mo.x + mo.w;
            }

            if (typeof (m.x) != "undefined")
                mm.css({ left: m.x });
            if (typeof (m.y) != "undefined")
                mm.css({ top: m.y });
            if (typeof (m.w) != "undefined")
                mm.setOuterWidth(Math.max(Math.min(m.w, maxw), minw));
            if (typeof (m.h) != "undefined")
                mm.setOuterHeight(Math.max(Math.min(m.h, maxh), minh));

            return false;
        }
    },
    _endMove: function(evt) {
        if (this._moving) {
            this._moving = false;
            var mc = this.mc, mm = this.mm, lo = this._limitObj, os = mm.offset();
            if (mc.get(0).releaseCapture) {
                mc.get(0).releaseCapture();
                $(document.documentElement).unbind('mousemove');
                $(document.documentElement).unbind('mouseup');
            }
            else if (window.releaseEvents) {
                window.releaseEvents(Event.MOUSEMOVE | Event.MOUSEUP);
                $(window).unbind('mousemove');
                $(window).unbind('mouseup');
            }

            var mw = mm.outerWidth(), mh = mm.outerHeight();
            var w = mw - lo.osw, h = mh - lo.osh;
            if (evt.data != "m")
                this.resize(w, h);
            else {
                var x = os.left, y = os.top;
                if (this._panelBase._Fixed) {
                    var cb = this._moveObj.cb;
                    x = x - cb.x;
                    y = y - cb.y;
                }
                this.moveTo(x, y);
            }

            this.mb.hide();
            this.mm.remove();

            if (evt.data != "m" && (this._moveObj.w != mw || this._moveObj.h != mh))
                this.dispatchEvent('resize');
            if (evt.data == "m" && (this._moveObj.os.left != os.left || this._moveObj.os.top != os.top))
                this.dispatchEvent('move');

            return false;
        }
    },
    get_Caption: function() {
        /// <summary>模式框口的名称。</summary>
        if (this.get_isInitialized())
            return $('.df-db-title', this.mc).html();
        return this._Caption;
    },
    set_Caption: function(v, i) {
        if (this._Caption !== v || i) {
            this._Caption = v;
            if (this.get_isInitialized())
                $('.df-db-title', this.mc).html(v);
        }
    },
    set_Theme: function(v, i) {
        if (v && v.toLowerCase() != this._Theme.toLowerCase() || i) {
            this._Theme = v;
            if (this.get_isInitialized())
                this.mc.parent().removeClass().addClass(v);
        }
    },
    get_Resizable: function() {
        return this.get_XResizable() && this.get_YResizable();
    },
    set_Resizable: function(v, i) {
        if (v !== this._XResizable || v !== this._YResizable || i) {
            this._XResizable = v;
            this._YResizable = v;
            if (this.isVisible()) {
                var r = $('.df-db-resize', this.mc);
                if (v) {
                    r.css({ cursor: 'se-resize' }).bind('mousedown', 'se', this._moveHandler).show();
                }
                else {
                    r.hide();
                    if (!i)
                        r.unbind('mousedown');
                }
            }
        }
    },
    set_XResizable: function(v, i) {
        if (v !== this._XResizable || i) {
            this._XResizable = v;
            if (this.isVisible()) {
                var r = $('.df-db-resize', this.mc);
                if (v) {
                    if (this._YResizable) {
                        r.unbind('mousedown');
                        this.set_Resizable(true, i);
                    }
                    else {
                        r.css({ cursor: 'e-resize' }).bind('mousedown', 'e', this._moveHandler).show();
                    }
                }
                else if (!i) {
                    if (this._YResizable) {
                        r.unbind('mousedown');
                        this.set_YResizable(true, i);
                    }
                    else {
                        this.set_Resizable(false, true);
                    }
                }
            }
        }
    },
    set_YResizable: function(v, i) {
        if (v !== this._YResizable || i) {
            this._YResizable = v;
            if (this.isVisible()) {
                var r = $('.df-db-resize', this.mc);
                if (v) {
                    if (this._XResizable) {
                        r.unbind('mousedown');
                        this.set_Resizable(true, i);
                    }
                    else {
                        r.css({ cursor: 's-resize' }).bind('mousedown', 's', this._moveHandler).show();
                    }
                }
                else if (!i) {
                    if (this._XResizable) {
                        r.unbind('mousedown');
                        this.set_XResizable(true, i);
                    }
                    else {
                        this.set_Resizable(false, true);
                    }
                }
            }
        }
    },
    set_Moveable: function(v, i) {
        if (v !== this._Moveable || i) {
            this._Moveable = v;
            if (this.isVisible()) {
                var m = $('.df-db-header', this.mc), t = $('.df-db-title', this.mc);
                if (v) {
                    m.css({ cursor: 'move' }).bind('mousedown', 'm', this._moveHandler);
                    t.css({ cursor: 'move' });
                }
                else if (!i) {
                    m.css({ cursor: 'auto' }).unbind('mousedown');
                    t.css({ cursor: 'auto' });
                }
            }
        }
    },
    set_Closeable: function(v, i) {
        if (v !== this._Closeable || i) {
            this._Closeable = v;
            var c = $('.df-db-close', this.mc);
            if (v)
                c.show();
            else
                c.hide();
            if (this.isVisible()) {
                if (v) {
                    c.bind('mousedown', function() { return false; });
                    c.bind('click', Function.createDelegate(this, this._close));
                }
                else if (!i) {
                    c.unbind('click').unbind('mousedown');
                }
            }
        }
    },
    set_CloseLabel: function(v, i) {
        if (v !== this._CloseLabel || i) {
            this._CloseLabel = v;
            $('.df-db-close', this.mc).html(v);
        }
    },
    get_Width: function() {
        /// <summary>模式窗体的内部宽度。</summary>
        return $(".df-db-main", this.mc).width();
    },
    get_Height: function() {
        /// <summary>模式窗体的内部高度。</summary>
        return $(".df-db-main", this.mc).height();
    },
    get_ZIndex: function() {
        return this._panelBase.get_ZIndex();
    }
};
DialogFrame.DialogBase.registerClass('DialogFrame.DialogBase', Sys.UI.Behavior);

$.each(['Width', 'Height', 'MinWidth', 'MinHeight', 'MaxWidth', 'MaxHeight'], function(i, n) {
    DialogFrame.DialogBase.prototype["set_" + n] = function(v) {
        if (v !== this["_" + n]) {
            this["_" + n] = v;
            if (this.isVisible())
                this.resize();
        }
    }
});

DialogFrame.DialogBase.registerProperties([
    { name: 'Theme', summary: '指定模式窗体使用的皮肤样式名称。' },
    { name: 'Resizable', summary: '指定是否可以调节模式窗体的大小。默认值为 True。' },
    { name: 'XResizable', summary: '指定是否可以调节模式窗体的宽度。默认值为 True。' },
    { name: 'YResizable', summary: '指定是否可以调节模式窗体的高度。默认值为 True。' },
    { name: 'Moveable', summary: '指定模式窗体是否可以移动。默认值为 True。' },
    { name: 'Limiting', summary: '指定模式窗体是否只能在窗口区域移动。默认值为 True。' },
    { name: 'Closeable', summary: '指定模式窗体是否显示关闭按钮。默认值为 True' },
    { name: 'CloseLabel', summary: '指定关闭按钮的文本内容。' },
    { name: 'MinWidth', summary: '模式窗体的内部最小宽度。' },
    { name: 'MinHeight', summary: '模式窗体的内部最小高度。' },
    { name: 'MaxWidth', summary: '模式窗体的内部最大宽度。' },
    { name: 'MaxHeight', summary: '模式窗体的内部最大高度。' }
    ]);
DialogFrame.DialogBase.registerProperties(DialogFrame.PanelBase, '_panelBase');
DialogFrame.DialogBase.registerEvents([
    { name: 'showing', summary: '封装的 DOM 元素正在呈现。' },
    { name: 'showed', summary: '封装的 DOM 元素已呈现' },
    { name: 'hiding', summary: '封装的 DOM 元素正准备隐藏。' },
    { name: 'hidden', summary: '封装的 DOM 元素已隐藏。' },
    { name: 'close', summary: '当模式窗体关闭时触发。' },
    { name: 'resize', summary: '封装的 DOM 元素大小发生变化时触发。' },
    { name: 'move', summary: '封装的 DOM 元素位置发生变化时触发。' }
    ]);


DialogFrame.PopupDialog = function(element) {
    /// <summary>封装一个 DOM 元素使之在点击时能弹出一个模式窗体。</summary>
    ///	<param name="element" type="DOM">DOM 元素</param>
    ///	<returns type="DialogFrame.PopupDialog" />
    DialogFrame.PopupDialog.initializeBase(this, [element]);

    this._globalClickHandler = null;
    this._popupClickHandler = null;
    this._dialogBase = null;
    this._PopupDialogID = null;
    this._PopupOffsetX = 0;
    this._PopupOffsetY = 0;
};

DialogFrame.PopupDialog.prototype = {
    initialize: function() {
        /// <summary>初始化当前 DialogFrame.PopupDialog 对象。</summary>
        DialogFrame.PopupDialog.callBaseMethod(this, 'initialize');

        var p = this.grepProperties(DialogFrame.DialogBase.getProperties());
        $.extend(p, { Covered: false });

        this._dialogBase = $create(DialogFrame.DialogBase, p, { close: Function.createDelegate(this, this.hide) }, null, $get(this._PopupPanelID));
        this._dialogBase.tag = this;

        $addHandler(this._element, 'click', Function.createDelegate(this, this.popup));

        this._globalClickHandler = Function.createDelegate(this, this._globalClick);
        this._popupClickHandler = Function.createDelegate(this, this._popupClick);
    },
    dispose: function() {
        /// <summary>从应用程序中移除当前 DialogFrame.PopupDialog 对象。</summary>
        DialogFrame.PopupDialog.callBaseMethod(this, 'dispose');
        if (this._dialogBase)
            this._dialogBase.dispose();
    },
    popup: function() {
        /// <summary>显示模式窗体。</summary>
        if (this._dialogBase.isVisible()) {
            this.hide();
            return;
        }
        if (this.dispatchEvent('popup'))
            return;
        var e = $(this._element);
        var os = e.offset();
        var s = { x: os.left + this._PopupOffsetX, y: os.top + e.outerHeight() + this._PopupOffsetY };
        this._dialogBase.show(s);
        $addHandler(window.document, 'click', this._globalClickHandler);
        $addHandler(this._dialogBase.getDialogElement(), 'click', this._popupClickHandler);
        this.dispatchEvent('popuped')
    },
    hide: function() {
        /// <summary>隐藏模式窗体。</summary>
        if (!this._dialogBase.isVisible() || this.dispatchEvent('hiding'))
            return;
        $removeHandler(window.document, 'click', this._globalClickHandler);
        $removeHandler(this._dialogBase.getDialogElement(), 'click', this._popupClickHandler);
        this._dialogBase.hide();
        this.dispatchEvent('hidden');
    },
    stopCapture: function() {
        if (this._dialogBase.isVisible()) {
            $removeHandler(window.document, 'click', this._globalClickHandler);
            $removeHandler(this._dialogBase.getDialogElement(), 'click', this._popupClickHandler);
        }
    },
    resumeCapture: function() {
        if (this._dialogBase.isVisible()) {
            $addHandler(window.document, 'click', this._globalClickHandler);
            $addHandler(this._dialogBase.getDialogElement(), 'click', this._popupClickHandler);
        }
    },
    get_DialogBase: function() {
        /// <summary>获取模式窗体对象。</summary>
        return this._dialogBase;
    },
    _globalClick: function(evt) {
        if (this._dialogBase.isVisible()) {
            var p = evt.target;
            while (p && p != this._element && p.tagName != 'HTML') {
                p = p.parentNode;
            }
            if (p != this._element && p.tagName == 'HTML')
                this.hide();
        }
    },
    _popupClick: function(evt) {
        evt.stopPropagation();
    }
};

DialogFrame.PopupDialog.registerClass('DialogFrame.PopupDialog', Sys.UI.Control);
DialogFrame.PopupDialog.registerProperties([
    { name: 'PopupPanelID', summary: '指定弹出模式窗体封装的 DOM 元素的 ID。' },
    { name: 'PopupOffsetX', summary: '指定弹出模式窗体封装的 DOM 元素的 ID。' },
    { name: 'PopupOffsetY', summary: '指定弹出模式窗体封装的 DOM 元素的 ID。' }
    ]);
DialogFrame.PopupDialog.registerProperties(DialogFrame.DialogBase, '_dialogBase');
DialogFrame.PopupDialog.registerEvents([
    { name: 'popup', summary: '当窗体弹出时触发。' },
    { name: 'popuped', summary: '当窗体弹出后触发。' },
    { name: 'hiding', summary: '当窗体隐藏时触发。' },
    { name: 'hidden', summary: '当窗体隐藏后触发。' }
    ]);

DialogFrame.MessageBoxIcon = function() {
    /// <summary>定义消息框的图标形式。</summary>
    if (arguments.length !== 0) throw Error.parameterCount();
    throw Error.notImplemented();
};

DialogFrame.MessageBoxIcon.prototype = {
    None: 0,
    Information: 1,
    Alert: 2,
    Stop: 3,
    Question: 4,
    Success: 5
};
DialogFrame.MessageBoxIcon.registerEnum("DialogFrame.MessageBoxIcon");

DialogFrame.MessageBoxButtons = function() {
    /// <summary>定义消息框的按钮形式。</summary>
    if (arguments.length !== 0) throw Error.parameterCount();
    throw Error.notImplemented();
};
DialogFrame.MessageBoxButtons.prototype = {
    None: 0,
    OK: 1,
    Yes: 2,
    No: 4,
    Abort: 8,
    Retry: 16,
    Cancel: 32,
    Ignore: 64,
    Close: 128,
    Timer: 256,
    OKCancel: 33,
    RetryCancel: 48,
    YesNo: 6,
    YesNoCancel: 38,
    AbortRetryIgnore: 86
};
DialogFrame.MessageBoxButtons.registerEnum("DialogFrame.MessageBoxButtons");

DialogFrame.DialogResult = function() {
    /// <summary>定义消息框的返回值。</summary>
    if (arguments.length !== 0) throw Error.parameterCount();
    throw Error.notImplemented();
};
DialogFrame.DialogResult.prototype = {
    None: 0,
    OK: 1,
    Cancel: 2,
    Yes: 3,
    No: 4,
    Abort: 5,
    Retry: 6,
    Ignore: 7
};
DialogFrame.DialogResult.registerEnum("DialogFrame.DialogResult");

DialogFrame.MessageBox = function() {
    /// <summary>显示可包含文本、按钮和符号（通知并指示用户）的消息框。</summary>
    DialogFrame.MessageBox.initializeBase(this);
    this._TimerSpan = 3000;
    this._Icon = DialogFrame.MessageBoxIcon.None;
    this._Buttons = DialogFrame.MessageBoxButtons.None;
    this._jqelement = null;
    this._resultHandler = null;
    this._timerHandler = null;
    this._timerInterval = 0;
    this._timerCounter = 0;

    var t = this;
    $.each({ OK: '确定', Yes: '是', No: '否', Abort: '放弃', Retry: '重试', Cancel: '取消', Ignore: '忽略', Close: '关闭' }, function(i, v) {
        t['_Label_' + i] = v;
    });
};

DialogFrame.MessageBox.prototype = {
    initialize: function() {
        /// <summary>初始化当前 DialogFrame.MessageBox 对象。</summary>
        DialogFrame.MessageBox.callBaseMethod(this, 'initialize');

        this._resultHandler = Function.createDelegate(this, this._close);
        this._timerHandler = Function.createDelegate(this, this._doTimer);

        var mb = this.mb = $("<table class='df-mb-box' cellSpacing='0' cellPadding='0'><tr><td class='df-mb-icon'><div /></td><td valign='top' class='df-mb-message' /></tr><tr><td colspan='2' class='df-mb-buttons' ><div /></td></tr></table>");

        var p = this.grepProperties(DialogFrame.DialogBase.getProperties());
        p = $.extend({ Resizable: false, XResizable: false, YResizable: false, Fixed: true }, p);
        $(".df-mb-buttons div", mb).bind("click", Function.createDelegate(this, this._buttonClick));

        this._dialogBase = $create(DialogFrame.DialogBase, p, { close: Function.createDelegate(this, this._close) }, null, mb.get(0));
        this._dialogBase.tag = this;
    },
    dispose: function() {
        /// <summary>从应用程序中移除当前 DialogFrame.MessageBox 对象。</summary>
        DialogFrame.MessageBox.callBaseMethod(this, 'dispose');
        if (this._dialogBase)
            this._dialogBase.dispose();
        this._clearTimer();
    },
    show: function(o) {
        /// <summary>显示消息框。</summary>
        /// <param name="s" type="object">关于的消息框设置的 JSON 对象。可用的属性为 title, message, icon, buttons, x, y, width, height, mwidth, mheight。</param>
        if (this._dialogBase.isVisible())
            return;
        this._dialogBase.preShow();
        var ni = __Util.getPropertyName(o, 'icon', true);
        if (ni && typeof (o[ni]) == 'string')
            o[ni] = __Util.getEnumValue(DialogFrame.MessageBoxIcon, o[ni]);
        var nb = __Util.getPropertyName(o, 'buttons', true);
        if (nb && typeof (o[nb]) == 'string')
            o[nb] = __Util.getEnumValue(DialogFrame.MessageBoxButtons, o[nb]);

        this.setProperties(o);

        this.set_Message(this._Message, true);
        this.set_Icon(this._Icon, true);
        this.set_Buttons(this._Buttons, true);
        this._dialogBase.show(o);
    },
    close: function() {
        /// <summary>关闭消息框。</summary>
        this._DialogResult = DialogFrame.DialogResult.Cancel;
        this._close();
    },
    get_DialogBase: function() {
        /// <summary>获取模式窗体对象。</summary>
        return this._dialogBase;
    },
    _close: function(evt) {
        this._clearTimer();
        this._dialogBase.hide();
        this.dispatchEvent('result');
    },
    _doTimer: function(i) {
        if (i) {
            this._innerCaption = this.get_Caption();
            this.set_Caption(this._innerCaption + " (" + Math.round(this._timerCounter / 1000) + ")");
        }
        else {
            this._timerCounter -= 1000;
            this.set_Caption(this._innerCaption + " (" + Math.round(this._timerCounter / 1000) + ")");
            if (this._timerCounter <= 0) {
                this._close();
                this._clearTimer();
            }
        }
    },
    _clearTimer: function() {
        if (this._timerInterval != 0) {
            window.clearInterval(this._timerInterval);
            this._timerInterval = 0;
        }
    },
    _buttonClick: function(evt) {
        if (evt.target.tagName == 'A') {
            var r = evt.target.getAttribute("result");
            this._DialogResult = __Util.getEnumValue(DialogFrame.DialogResult, r);
            this._close();
        }
    },
    get_DialogResult: function() {
        /// <summary>获取消息框的返回值。</summary>
        return this._DialogResult;
    },
    set_Message: function(v, i) {
        if (this._Message !== v || i) {
            this._Message = v;
            if (this.get_isInitialized()) {
                $(".df-mb-message", this.mb).html(v);
            }
        }
    },
    set_Icon: function(v, i) {
        if (typeof (v) == 'string')
            v = __Util.getEnumValue(DialogFrame.MessageBoxIcon, v);
        if (this._Icon !== v || i) {
            this._Icon = v;
            if (this.get_isInitialized()) {
                $(this._dialogBase.getDialogElement()).removeClass().addClass("df-mb-" + __Util.getEnumName(DialogFrame.MessageBoxIcon, v).toLowerCase());
                $(".df-mb-icon", this.mb).css({ display: v == DialogFrame.MessageBoxIcon.None ? 'none' : '' });
            }
        }
    },
    set_Buttons: function(v, i) {
        if (typeof (v) == 'string')
            v = __Util.getEnumValue(DialogFrame.MessageBoxButtons, v);
        if (this._Buttons !== v || i) {
            this._Buttons = v;
            if (this.get_isInitialized()) {
                var mbbs = $(".df-mb-buttons div", this.mb);
                mbbs.clearNodes();
                mbbs.css({ display: v == 0 || v == 256 ? 'none' : '' });
                var t = this;
                $.each([1, 2, 4, 8, 16, 32, 64, 128], function(i, iv) {
                    if ((v & iv) == iv) {
                        var n = __Util.getEnumName(DialogFrame.MessageBoxButtons, iv);
                        var mi = $("<a result='" + n + "' href='javascript:;' class='df-mb-button'>" + t['_Label_' + n] + "</a>").appendTo(mbbs);
                    }
                });
                if ((v & 256) == 256) {
                    this._clearTimer();
                    this._timerCounter = this._TimerSpan;
                    this._doTimer(true);
                    this._timerInterval = window.setInterval(this._timerHandler, 1000);
                }
            }
        }
    }
};

DialogFrame.MessageBox.registerClass('DialogFrame.MessageBox', Sys.Component);
DialogFrame.MessageBox.registerProperties([
    { name: 'Label_OK', summary: '按钮 OK 的文本。' },
    { name: 'Label_Yes', summary: '按钮 Yes 的文本。' },
    { name: 'Label_No', summary: '按钮 No 的文本。' },
    { name: 'Label_Abort', summary: '按钮 Abort 的文本。' },
    { name: 'Label_Retry', summary: '按钮 Retry 的文本。' },
    { name: 'Label_Cancel', summary: '按钮 Cancel 的文本。' },
    { name: 'Label_Ignore', summary: '按钮 Ignore 的文本。' },
    { name: 'Message', summary: '消息的 HTML 内容。' },
    { name: 'Icon', summary: '消息对话框显示的图标。' },
    { name: 'Buttons', summary: '消息对话框显示的按钮。' },
    { name: 'TimerSpan', summary: '使用自动关闭的时间间隔，默认3000毫秒。' }
]);
DialogFrame.MessageBox.registerProperties(DialogFrame.DialogBase, '_dialogBase');
DialogFrame.MessageBox.registerEvents([{ name: 'result', summary: '当消息框关闭时触发。'}]);

DialogFrame.WindowDialog = function() {
    /// <summary>在模式窗体中打开指定的 URL。</summary>
    ///	<returns type="DialogFrame.WindowDialog" />
    DialogFrame.WindowDialog.initializeBase(this);
    this._dialogBase = null;
    this._modalFrame = null;

    this._WindowCache = false;
    this._Url = null;

    this._loaded = false;
    this._contentWindow = null;
    this._currentWindow = null;
};

DialogFrame.WindowDialog.prototype = {
    initialize: function() {
        /// <summary>初始化当前 DialogFrame.WindowDialog 对象。</summary>
        DialogFrame.WindowDialog.callBaseMethod(this, 'initialize');
        var ef = this._modalFrame = $("<iframe frameBorder='no' />").css({ width: '100%', height: '100%' }).bind('load', Function.createDelegate(this, this._load));
        var p = this.grepProperties(DialogFrame.DialogBase.getProperties());
        this._dialogBase = $create(DialogFrame.DialogBase, p, { close: Function.createDelegate(this, this._close) }, null, ef.get(0));
        this._dialogBase.tag = this;
        this._currentWindow = window;

        this._dialogLoadHandler = null;
        this._dialogCloseHandler = null;
        if (this._Url)
            this.show(this._Url, null, true);
    },
    dispose: function() {
        /// <summary>从应用程序中移除当前 DialogFrame.WindowDialog 对象。</summary>
        DialogFrame.WindowDialog.callBaseMethod(this, 'dispose');
        if (this._dialogBase) {
            if (this._loaded) {
                var ow = this._contentWindow;
                ow.$close = null;
                ow.$hide = null;
                ow.$dialogObject = null;

                //                if (typeof (ow.dialogLoad) == "function")
                //                    this.remove_loaded(ow.dialogLoad);
                //                if (typeof (ow.dialogClose) == "function")
                //                    this.remove_closing(ow.dialogClose);

                if (this._rng) {
                    this._currentWindow.focus();
                    this._rng.select();
                }
            }
            this._dialogBase.dispose();
        }
    },
    show: function(url, o, init) {
        /// <summary>在模式窗口中打开 URL。</summary>
        /// <param name="url" type="string">打开的 URL。</param>
        /// <param name="s" type="object">（可选）显示对象的位置的 JSON 对象。可用的属性为 x, y, width, height, mwidth, mheight。</param>
        if (typeof (url) == "string" && this._Url != url && !init) {
            this._Url = url;
            this._loaded = false;
        }
        if (!this._loaded) {
            if (this.dispatchEvent('loading'))
                return;
            this._modalFrame.attr('src', this._getUrl(this._Url));
        }
        if (this._loaded && this.dispatchEvent('showing'))
            return;
        if ($.browser.msie) {
            this._rng = document.selection.createRange();
        }
        this._dialogBase.show(o);
        if (this._loaded)
            this.dispatchEvent('showed')
    },
    hide: function() {
        this._dialogBase.hide();
        window.focus();
        this.set_X(-1);
        this.set_Y(-1);
    },
    close: function() {
        /// <summary>关闭打开的模式窗口。</summary>
        this._close();
    },
    get_DialogBase: function() {
        /// <summary>获取模式窗体对象。</summary>
        return this._dialogBase;
    },
    _close: function() {
        if (this.dispatchEvent('closing'))
            return;
        this.hide();
        this.dispatchEvent('closed');
        var t = this;
        if (!this._WindowCache)
            this.dispose();
    },
    _load: function(evt) {
        this._loaded = true;
        var ow = evt.target.contentWindow;
        this._contentWindow = ow;
        this._dialogBase.set_Caption(ow.document.title);
        ow.$close = Function.createDelegate(this, this._close);
        ow.$hide = Function.createDelegate(this, this.hide);
        ow.$dialogObject = this;

        if (typeof (ow.dialogLoad) == "function") {
            this.add_loaded(this.createDelegate(ow.dialogLoad));
        }
        if (typeof (ow.dialogClose) == "function")
            this.add_closing(this.createDelegate(ow.dialogClose));

        this.dispatchEvent('loaded');
        //ow.focus();
        this.dispatchEvent('showed')
    },
    _getUrl: function(v) {
        var url = v;
        if (url.indexOf("?") == -1)
            url += "?";
        url += "&__pr=" + Math.round((Math.random() * 10000000)).toString();
        return url;
    }
};

DialogFrame.WindowDialog.registerClass('DialogFrame.WindowDialog', Sys.Component);
DialogFrame.WindowDialog.registerProperties([{ name: 'Url', summary: '打开的网址。' }, { name: 'DataChanged', summary: '返回数据是否更改。' }, { name: 'WindowCache', summary: '当窗体关闭时是否进行缓存以备下次使用。'}]);
DialogFrame.WindowDialog.registerProperties(DialogFrame.DialogBase, '_dialogBase');
DialogFrame.WindowDialog.registerEvents([
    { name: 'closing', summary: '当模式窗体正在关闭时触发。' },
    { name: 'closed', summary: '当模式窗体关闭后时触发。' },
    { name: 'showing', summary: '当模式窗体显示后时触发。' },
    { name: 'showed', summary: '当模式窗体显示后时触发。' },
    { name: 'loading', summary: '当模式窗体正在加载时触发。' },
    { name: 'loaded', summary: '当模式窗体加载完毕后触发。' }
]);

$showDialog = function(options, events) {
    if (window.parent && window.parent != window && window.parent.$showDialog) {
        window.parent.$showDialog(options, events);
        return;
    }
    return $create(DialogFrame.WindowDialog, __Util.grepObject(options, DialogFrame.WindowDialog.getProperties()), events);
};

$showMessage = function(options, events) {
    if (typeof (window.$__MessageBox) == "undefined")
        window.$__MessageBox = $create(DialogFrame.MessageBox);

    var mbObj = window.$__MessageBox;
    Sys$Component$_setProperties(mbObj, __Util.grepObject(options, DialogFrame.MessageBox.getProperties()));
    mbObj.get_events()._list = {};
    if (events) {
        for (var name in events) {
            if (!(mbObj["add_" + name] instanceof Function)) throw new Error.invalidOperation(String.format(Sys.Res.undefinedEvent, name));
            if (!(events[name] instanceof Function)) throw new Error.invalidOperation(Sys.Res.eventHandlerNotFunction);
            mbObj["add_" + name](events[name]);
        }
    }
    mbObj.show(options);
    return mbObj;
};

if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();


if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();