/**
 * @author HQL
 */
function dialog(){
    /*begin*/
    //var _sId ='';
    /*End*/
    var titile = '';
    var width = 491;
    var height = 311;
    var src = "";
    var path = hostpath + "images/";
    var impath = hostpath + "images/";
    var sFunc = '<input id="dialogOk" type="button" style="{width:62px;height:22px;border:0;background:url(\'' + impath + 'smb_btn_bg.gif\');line-height:20px;" value="确认" onclick="new dialog().reset();" /> <input id="dialogCancel" type="button" style="{width:62px;height:22px;border:0;background:url(\'' + impath + 'smb_btn_bg.gif\');line-height:20px;" value="取消" onclick="new dialog().reset();" />';
    var sClose = '<a id="dialogBoxClose" href="javascript:;" onclick="new dialog().reset();" style="cursor:hand;"> <img src="'+hostpath+'images/hy_tc1.gif" alt="关闭" /></a>';
    var sBody = '\
		<table id="dialogBodyBox" border="0" align="center" cellpadding="0" cellspacing="0">\
			<tr height="10"><td colspan="4"></td></tr>\
			<tr>\
				<td width="10"></td>\
				<td id="dialogMsg" style="font-size:12px;"></td>\
				<td width="10"></td>\
			</tr>\
			<tr height="10"><td colspan="4" align="center"></td></tr>\
			<tr><td id="dialogFunc" colspan="4" align="center">' +
    sFunc +
    '</td></tr>\
			<tr height="10"><td colspan="4" align="center"></td></tr>\
		</table>\
	';
    var sBox = '\
        <div id="dialogBox" alt="dialog" border="0" align="center" cellpadding="0" cellspacing="0" style=" width:491px; height:311px; background:url(\'' + hostpath + 'images/hy_tc.gif\');background-color:#838383;display:none;z-index:10;">\
			<div style="width:100px; height:12px; margin:10px 10px 0px 378px">\
						<span align="left"  id="dialogBoxTitle" onMouseUp="new dialog().moveStart().end" onMouseDown="new dialog().moveStart(event, \'dialogBox\')" style="color:#fff;cursor:move;font-size:12px;font-weight:bold;">&nbsp;</span>\
						<span id=dialogClose onMouseUp="new dialog().moveStart().end" onMouseDown="new dialog().moveStart(event, \'dialogBox\')" style="color:#fff;cursor:move;font-size:12px;font-weight:bold;">' +
    sClose+
    '</span>\
			 </div>\
			<div style="width:350px; margin-top:80px; margin-left:80px; text-align:left;">\
				<table width="100%" border="0" cellspacing="0" cellpadding="0" style="-moz-user-select:none;">\
					<tr id="dialogHeight" style="height:' +
    height +
    ';">\
						<td id="dialogBody" valign="top" style="padding-left:20px;font-size:14px; font-weight:bold;">' +
    sBody +
    '</td>\
					</tr>\
				</table>\
			</div>\
		</div>\
		<iframe id="dialogBoxIframe" width="' +
    width +
    '" style="position:absolute;display:none;" frameborder="0"></iframe>\
		<div id="dialogBoxShadow" style="display:none;z-index:9;"></div>\
	';
    var sBG = "<div id='dialogBoxBG' style='position:absolute;visibility:inherit;top:0px;left:0px;width:100%;height:"+ (parent.document.body.scrollHeight) + "px;FILTER: alpha(opacity=60);background-color:#323232;'></div>";

    this.show = function(){
        this.middle('dialogBox');
        this.shadow();
        //$("dialogBoxBG").style.width = document.body.scrollWidth;
        //$("dialogBoxBG").style.height = document.body.scrollHeight;
    }
    this.reset = function(){
        fwinbgclos();
        $('dialogBox').style.display = 'none';
        $('dialogBoxBG').style.display = 'none';
        $('dialogBoxShadow').style.display = "none";
        $('dialogBoxIframe').style.display = "none";
        $('dialogBody').innerHTML = sBody;
    }
    this.html = function(_sHtml){
        $("dialogBody").innerHTML = _sHtml;
        this.show();
    }
    this.init = function(){
        $('dialogCase') ? $('dialogCase').parentNode.removeChild($('dialogCase')) : function(){
        };
        var oDiv = document.createElement('span');
        oDiv.id = "dialogCase";
        oDiv.innerHTML = sBG + sBox;
        document.body.appendChild(oDiv);
        //$('dialogBoxBG').style.height = document.body.scrollHeight;
    }
    this.button = function(_sId, _sFuc){
        if ($(_sId)) {
            $(_sId).style.display = '';
            if ($(_sId).addEventListener) {
                if ($(_sId).act) {
                    $(_sId).removeEventListener('click', function(){
                        eval($(_sId).act)
                    }, false);
                }
                $(_sId).act = _sFuc;
                $(_sId).addEventListener('click', function(){
                    eval(_sFuc)
                }, false);
            }
            else {
                if ($(_sId).act) {
                    $(_sId).detachEvent('onclick', function(){
                        eval($(_sId).act)
                    });
                }
                $(_sId).act = _sFuc;
                $(_sId).attachEvent('onclick', function(){
                    eval(_sFuc)
                });
            }
        }
    }
    this.shadow = function(){
        var oShadow = $('dialogBoxShadow');
        var oDialog = $('dialogBox');
        var oIframe = $('dialogBoxIframe');
        oShadow['style']['position'] = "absolute";
        oIframe['style']['position'] = "absolute";
        oShadow['style']['background'] = "#838383"; //影子为蓝色,呵呵.
        oShadow['style']['display'] = "";
        oIframe['style']['display'] = "";
        oShadow['style']['opacity'] = "0.2";
        oShadow['style']['filter'] = "alpha(opacity=20)";
        oShadow['style']['top'] = oDialog.offsetTop + 6;
        oShadow['style']['left'] = oDialog.offsetLeft + 6;
        oShadow['style']['width'] = oDialog.offsetWidth;
        oShadow['style']['height'] = oDialog.offsetHeight;
        oIframe['style']['top'] = oDialog.offsetTop;
        oIframe['style']['left'] = oDialog.offsetLeft;
        oIframe['style']['width'] = oDialog.offsetWidth;
        oIframe['style']['height'] = oDialog.offsetHeight;
    }
    this.open = function(_sUrl, _sMode){
        this.show();
        this.ifmiddle('dialogBox');
        if (!_sMode || _sMode == "no" || _sMode == "yes" || _sMode == "auto") {
            $("dialogBody").innerHTML = "<iframe width='100%' height='100%' frameborder='0' scrolling='" + _sMode + "' id='dialogBodyframeEle'></iframe>";
            $('dialogBodyframeEle').src = _sUrl;
        }
    }
    this.showWindow = function(_sUrl, _iWidth, _iHeight, _sMode, _sTitle){
        var oWindow;
        var sLeft = (screen.width) ? (screen.width - _iWidth) / 2 : 0;
        var iTop = -80 + (screen.height - _iHeight) / 2;
        iTop = iTop > 0 ? iTop : (screen.height - _iHeight) / 2;
        var sTop = (screen.height) ? iTop : 0;
        if (window.showModalDialog && _sMode == "m") {
            oWindow = window.showModalDialog(_sUrl, _sTitle, "dialogWidth:" + _iWidth + "px;dialogheight:" + _iHeight + "px");
        }
        else {
            oWindow = window.open(_sUrl, _sTitle, 'height=' + _iHeight + ', width=' + _iWidth + ', top=' + sTop + ', left=' + sLeft + ', toolbar=no, menubar=no, scrollbars=' + _sMode + ', resizable=no,location=no, status=no');
            this.reset();
        }
    }
    this.event = function(_sMsg, _sOk, _sCancel, _sClose){
        $('dialogFunc').innerHTML = sFunc;
        $('dialogClose').innerHTML = sClose;
        $('dialogBodyBox') == null ? $('dialogBody').innerHTML = sBody : function(){
        };
        $('dialogMsg') ? $('dialogMsg').innerHTML = _sMsg : function(){
        };
        _sOk && _sOk != "" ? this.button('dialogOk', _sOk) | $('dialogOk').focus() : $('dialogOk').style.display = 'none';
        _sCancel && _sCancel != "" ? this.button('dialogCancel', _sCancel) : $('dialogCancel').style.display = 'none';
        //_sOk ? this.button('dialogOk', _sOk) : _sOk == "" ? function(){} : $('dialogCancel').style.display = 'none';
        //_sCancel ? this.button('dialogCancel', _sCancel) : _sCancel == "" ? function(){} : $('dialogCancel').style.display = 'none';
        _sClose && _sClose != "" ? this.button('dialogBoxClose', _sClose) : $('dialogBoxClose').style.display = 'none';
        //_sClose && _sClose != "" ? this.button('dialogBoxClose', _sClose) : function(){};
        this.show();
        this.middle('dialogBox');
    }
    this.set = function(_oAttr, _sVal){
        var oShadow = $('dialogBoxShadow');
        var oDialog = $('dialogBox');//dialogBody
        var oDialogBody = $('dialogBody');
        var oHeight = $('dialogHeight');
        var oIframe = $('dialogBoxIframe');
        if (_sVal != '') {
            switch (_oAttr) {
                case 'title':
                    $('dialogBoxTitle').innerHTML = _sVal;
                    title = _sVal;
                    break;
                case 'width':
                    oDialog['style']['width'] = _sVal;
                    width = _sVal;
                    oDialog.width = _sVal;
                    break;
                case 'height':
                    oHeight['style']['height'] = _sVal;
                    height = _sVal;
                    oDialogBody.height = _sVal;
                    break;
                case 'src':
                    if (parseInt(_sVal) > 0) {
                        $('dialogBoxFace') ? $('dialogBoxFace').src = path + _sVal + '.gif' : function(){
                        };
                    }
                    else {
                        $('dialogBoxFace') ? $('dialogBoxFace').src = _sVal : function(){
                        };
                    }
                    src = _sVal;
                    break;
            }
        }
        this.middle('dialogBox');
        oShadow['style']['top'] = oDialog.offsetTop + 6;
        oShadow['style']['left'] = oDialog.offsetLeft + 6;
        oShadow['style']['width'] = oDialog.offsetWidth;
        oShadow['style']['height'] = oDialog.offsetHeight;
        oIframe['style']['top'] = oDialog.offsetTop;
        oIframe['style']['left'] = oDialog.offsetLeft;
        oIframe['style']['width'] = oDialog.offsetWidth;
        oIframe['style']['height'] = oDialog.offsetHeight;
    }
    this.moveStart = function(e, _sId){
        function fixE(e){
            if (typeof e == 'undefined') 
                e = window.event;
            if (typeof e.layerX == 'undefined') 
                e.layerX = e.offsetX;
            if (typeof e.layerY == 'undefined') 
                e.layerY = e.offsetY;
            return e;
        }
        function getX(e){
            return fixE(e).clientX;
        };
        function getY(e){
            return fixE(e).clientY;
        };
        function drag(e){
            if (document.getElementById(_sId))
            {
            v = document.getElementById(_sId);
            var nX = getX(e);
            var nY = getY(e);
            var ll = v.rL + nX - v.oX;
            var tt = v.rT + nY - v.oY;
            v.style.left = ll + 'px';
            v.style.top = tt + 'px';
            $('dialogBoxShadow').style.left = ll + 6 + 'px';
            $('dialogBoxShadow').style.top = tt + 6 + 'px';
            $('dialogBoxIframe').style.left = ll + 'px';
            $('dialogBoxIframe').style.top = tt + 'px';
            }
            return false;
        }
        function end(){
            document.onmousemove = null;
            document.onmouseup = null;
        }
        if ( $(_sId))
        {
        v = $(_sId);
        v.oX = getX(e);
        v.oY = getY(e);
        v.rL = parseInt(v.style.left ? v.style.left : 0);
        v.rT = parseInt(v.style.top ? v.style.top : 0);
        }
        document.onmousemove = drag;
        document.onmouseup = end;
        return false;
    }
    this.hideModule = function(_sType, _sDisplay){
        var aIframe = parent.document.getElementsByTagName("iframe");
        aIframe = 0;
        var aType = document.getElementsByTagName(_sType);
        var iChildObj, iChildLen;
        for (var i = 0; i < aType.length; i++) {
            aType[i].style.display = _sDisplay;
        }
        for (var j = 0; j < aIframe.length; j++) {
            iChildObj = document.frames ? document.frames[j] : aIframe[j].contentWindow;
            iChildLen = iChildObj.document.body.getElementsByTagName(_sType).length;
            for (var k = 0; k < iChildLen; k++) {
                iChildObj.document.body.getElementsByTagName(_sType)[k].style.display = _sDisplay;
            }
        }
    }
    this.middle = function(_sId){
        var obj = document.getElementById(_sId);
        var sClientWidth = getWinSize().width;
        var sClientHeight = parent ? getWinSize(parent).height - 200 : getWinSize().height;
        var sScrollTop;
        if (typeof parent.window.pageYOffset != 'undefined') {
            sScrollTop = parent.window.pageYOffset;
        }
        else 
            if (typeof window.pageYOffset != 'undefined') {
                sScrollTop = window.pageYOffset;
            }
            else 
                if (typeof parent.document.compatMode != 'undefined' &&
                parent.document.compatMode != 'BackCompat') {
                    sScrollTop = parent.document.documentElement.scrollTop;
                }
                else 
                    if (typeof document.compatMode != 'undefined' &&
                    document.compatMode != 'BackCompat') {
                        sScrollTop = document.documentElement.scrollTop;
                    }
                    else 
                        if (typeof parent.document.body != 'undefined') {
                            sScrollTop = parent.document.body.scrollTop;
                        }
                        else 
                            if (typeof document.body != 'undefined') {
                                sScrollTop = document.body.scrollTop;
                            }
        //var sScrollTop = parent ? parent.document.body.scrollTop : document.body.scrollTop;
        obj.style.display = "";
        obj.style.position = "absolute";
        obj.style.left = (sClientWidth - obj.offsetWidth) / 2 + 'px';
        var styletop = (sClientHeight - obj.offsetHeight) / 2 + sScrollTop;
        obj.style.top = styletop < 0 ? 0 + 'px' : styletop + 'px';
    }
    this.ifmiddle = function(_sId){
        var obj = document.getElementById(_sId);
        var sClientWidth = getWinSize().width;
        var sClientHeight = parent ? getWinSize(parent).height - 200 : getWinSize().height;
        var sScrollTop;
        if (typeof window.pageYOffset != 'undefined') {
            sScrollTop = window.pageYOffset;
        }
        else 
            if (typeof document.compatMode != 'undefined' &&
            document.compatMode != 'BackCompat') {
                sScrollTop = document.documentElement.scrollTop;
            }
            else 
                if (typeof document.body != 'undefined') {
                    sScrollTop = document.body.scrollTop;
                }
        //var sScrollTop = parent ? parent.document.body.scrollTop : document.body.scrollTop;
        obj.style.display = "";
        obj.style.position = "absolute";
        obj.style.left = (sClientWidth - obj.offsetWidth) / 2 + 'px';
        var styletop = (sClientHeight - obj.offsetHeight) / 2 + sScrollTop;
        obj.style.top = styletop < 0 ? 0 + 'px' : styletop + 'px';
    }
}

function getWinSize(_target){
    var windowWidth, windowHeight;
    if (_target) 
        target = _target.document;
    else 
        target = document;
    if (self.innerHeight) { // all except Explorer
        if (_target) 
            target = _target.self;
        else 
            target = self;
        windowWidth = target.innerWidth;
        windowHeight = target.innerHeight;
    }
    else 
        if (target.documentElement && target.documentElement.clientHeight) { // Explorer 6 Strict Mode
            windowWidth = target.documentElement.clientWidth;
            windowHeight = target.documentElement.clientHeight;
        }
        else 
            if (target.body) { // other Explorers
                windowWidth = target.body.clientWidth;
                windowHeight = target.body.clientHeight;
            }
            else {
                windowWidth = top.body.clientWidth;
                windowHeight = top.body.clientHeight;
            }
    return {
        width: parseInt(windowWidth),
        height: parseInt(windowHeight)
    };
}

function _confirm_msg_show(msg, title, click_ok, click_no, on_clos){
    title = title ? title : '系统提示信息';
    dg = new dialog();
    dg.init();
    dg.set('title', title);
    dg.set('width', 491);
    dg.set('height', 111);
    dg.event(msg, click_ok, click_no, on_clos);
}

function fshowwindows(urlID, ftitle, width, height, optbg){
    if (optbg == 1) 
        fwinbgopen();
    dialogs = new dialog();
    dialogs.init();
    dialogs.set('src', '2');
    dialogs.set('width', width > 0 ? width : 500);
    dialogs.set('height', height > 0 ? height : 0);
    dialogs.set('title', ftitle);
    
    dialogs.html("<img src='" + hostpath + "images/wait2.gif'>等待");
    //实例化Ajax对象
    url = urlID != '' ? urlID : "error.aspx?error=404";
    
    var ajax = InitAjax();
    ajax.open("GET", url, true);
    ajax.setRequestHeader("Content-Length", url.length);
    ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    ajax.setRequestHeader("Charset","gb2312");
    //获取执行状态
    ajax.onreadystatechange = function(){
        //如果执行是状态正常，那么就把返回的内容赋值给上面指定的层
        if (ajax.readyState == 0) 
            dialogs.html("<img src='" + hostpath + "images/wait2.gif'>请求初始化");
        
        if (ajax.readyState == 1) 
            dialogs.html("<img src='" + hostpath + "images/wait2.gif'>请求已发送，正在处理");
        
        if (ajax.readyState == 2) 
            dialogs.html("<img src='" + hostpath + "images/wait2.gif'>请求已发送，正在处理");
        
        if (ajax.readyState == 3) 
            dialogs.html("<img src='" + hostpath + "images/wait2.gif'>请求处理中");
        
        if (ajax.readyState == 4) {
            if (ajax.status == 404) 
                dialogs.html("<img src='" + hostpath + "images/warning.gif'>没有找到资源！");
            else 
                if (ajax.status == 403) 
                    dialogs.html("<img src='" + hostpath + "images/warning.gif'>资源不可用！");
                else 
                    if (ajax.status == 401) 
                        dialogs.html("<img src='" + hostpath + "images/warning.gif'>没有受权访问！");
                    else 
                        if (ajax.status == 200) {
                            //dialogs.html(ajax.responseText);
                            //小何修改 by 2008-9-26
                            var resText=ajax.responseText;
                            var reg = /<script[^>]*>((.|\n)+)<\/script>/;
                            var match=resText.match(reg);
                            var MyScript="";
                            if(match!=null) //有脚本返回
                            { 
                               MyScript=match[1];
                               eval(MyScript);//执行脚本
                            }
                            var Html=resText.replace(reg,"");//获取不包含脚本的其他内容
                            dialogs.html(Html);
                        }
        }
    }
    ajax.send(null);
}

function fopenwindows(urlID, ftitle, width, height, optbg){
    if (optbg == 1) 
        fwinbgopen();
    dialogs = new dialog();
    dialogs.init();
    dialogs.set('src', '2');
    dialogs.set('width', width > 0 ? width : 500);
    dialogs.set('height', height > 0 ? height : 0);
    dialogs.set('title', ftitle);
    
    url = urlID != '' ? urlID : "error.aspx?error=404";
    dialogs.showWindow(url, ftitle, width, height, optbg)
}

function fiframwindows(urlID, ftitle, width, height, optbg){
    if (optbg == 1) 
        fwinbgopen();
    dialogs = new dialog();
    dialogs.init();
    dialogs.set('src', '2');
    dialogs.set('width', width > 0 ? width : 500);
    dialogs.set('height', height > 0 ? height : 0);
    dialogs.set('title', ftitle);
    
    url = urlID != '' ? urlID : "error.aspx?error=404";
    dialogs.open(url, 'auto');
}

function fwinbgopen(){
    fwinbgclos('bgiframe');
    var showwindows = document.createElement("div");
    showwindows.id = 'bgiframe';
    showwindows.style.filter = 'Alpha(Opacity=60, FinishOpacity=100)';
    showwindows.style.position = 'absolute';
    showwindows.style.left = '0px';
    showwindows.style.top = '0px';
    showwindows.style.width = '100%';
    showwindows.style.height = parent.document.body.scrollHeight - 1;
    showwindows.style.background = 'Background'; 
    showwindows.style.overflow = 'auto';
    showwindows.innerHTML += "<iframe style='position:absolute;visibility:inherit;top:0px;left:0px;width:100%;height:" + (parent.document.body.scrollHeight - 1) + "px;z-index:-1;background-color:#323232;'></iframe>";
    document.body.appendChild(showwindows);
}

function fwinbgclos(idname){
    if ($(idname)) 
        $(idname).parentNode.removeChild($(idname));
    else 
        if ($('bgiframe')) 
            $('bgiframe').parentNode.removeChild($('bgiframe'));
}
