﻿var reflash = false,messageboxloadcomplete = false;
function SetMessageboxLoadComplete() {
    messageboxloadcomplete = true
}
if (document.all) window.attachEvent('onload', SetMessageboxLoadComplete);
else window.addEventListener('load', SetMessageboxLoadComplete, false);

var sctimer;
var tempwidth = 0, tempheight = 0, temppate = 1, speedrate = 24, interval_id = 0;
var newdiv = document.createElement("div");
var contentdiv = document.createElement("div");
var Globle_width = 0, Globle_height = 0, Globle_shadow = true, Globle_src = '', Globle_title = '', Globle_Str = '', Globle_width_p = 0, Globle_height_div1 = 0;

document.writeln('<style type="text/css">body{margin:0px!ipmortant;padding:0px!ipmortant;}#blackbg{position:fixed;_position:absolute;}');
document.writeln('#blackcontentOuter{zoom:1;position:fixed!important;position:absolute;left:50%;top:45%;_top:expression((document.documentElement.scrollTop || document.body.scrollTop) + Math.round(50 * (document.documentElement.offsetHeight || document.body.clientHeight) / 100));}</style>');
function GetCookieValue(name) {
    var arr = document.cookie.match(new RegExp(name + "=([^&;]+)"));
    if (arr != null) return decodeURI(arr[1]);
    return "";
}
//jsn: {close:show close button,title:dialog title,width:dialog width,height:dialog height,src:iframe src,lock:show shadow}
function showdialog(jsn) {
    var show = jsn.close;
    Globle_shadow = jsn.lock;
    if (!messageboxloadcomplete) {
        window.clearInterval(interval_id);
        interval_id = window.setInterval(function() { showdialog(jsn) }, 200);
        return;
    }
    ShowSelectAll(false, _tkMessageBox.HideIDs);
    window.clearInterval(interval_id);
    _tkMessageBox.InitMsgDivData();
    reflash = jsn.reflash;
    Globle_title = jsn.title;
    Globle_width = jsn.width;
    Globle_height = jsn.height;
    Globle_src = jsn.src;
    Globle_width_p = Globle_width - 20;
    Globle_height_div1 = Globle_height + 30;
    Globle_Str = '<div style="position:relative"><div id="messageboxframecontainer" style="display:none;width:' + Globle_width + 'px;height:38px;padding:8px;background:#000;filter:alpha(opacity=40);-moz-opacity:0.4;-kHTML-opacity:0.4;opacity:0.4;position:absolute;top:0;left:0;z-index:1"></div><div id="__messageboxback" style="width:' + Globle_width + 'px;position:absolute;top:8px;left:8px;background:#fff;z-index:1000;"><p id="messageboxclosebutton" style="display:none;background:url(/t/t-cn/images/dialog_bg.gif) repeat-x;width:' + Globle_width_p + 'px;height:30px;line-height:32px;padding:0 10px;border-bottom:none;font-size:14px;font-weight:bold;color:#fff;margin:0;">' + (show == true ? '<a style="display:block;width:12px;height:12px;background:url(/t/t-cn/images/dialog_close.gif) no-repeat;line-height:100px;overflow:hidden;margin-top:10px;float:right" href="javascript:closedialog()">[关闭]</a>' : '') + '<span id="dialogTitle">' + Globle_title + '</span></p><iframe id="_tkMessageBoxFrame" onload="_tkMessageBox.ResizeIframe()" scrolling="no" src="' + Globle_src + '" frameborder="0" height="0" width="' + Globle_width + '"></iframe></div></div>';

    _tkMessageBox.scroolMsgeffect();
}
function closedialog() {
    ShowSelectAll(true, _tkMessageBox.HideIDs);
    if (reflash == true) {
        window.location.reload()
    } else {
        contentdiv.style.width = '10px';
        contentdiv.style.height = '10px';
        contentdiv.innerHTML = "";
        Globle_width = 0, Globle_height = 0, Globle_src = '', Globle_title = '', Globle_Str = '';
        tempwidth = 0, tempheight = 0, temppate = 1, contentdiv.style.display = "none";
        newdiv.style.display = "none";
    }
}
var _tkMessageBox = {
    HideIDs: '',
    ResizeIframe: function() {
        try {
            var _frame = document.getElementById("_tkMessageBoxFrame");
            var height = 0,
                width = 0;
            var f = document.getElementById("messageboxframecontainer");
            var closebutton = document.getElementById("messageboxclosebutton");
            try {
                _frame.height = 0;
                width = Math.max(_frame.contentWindow.document.documentElement.scrollWidth, _frame.contentWindow.document.body.scrollWidth);
                height = Math.max(_frame.contentWindow.document.documentElement.scrollHeight, _frame.contentWindow.document.body.scrollHeight);
            } catch (e) { }
            if (height > 0) {
                Globle_height = height;
                Globle_height_div1 = Globle_height + 30;
                Globle_width = width;
                Globle_width_p = Globle_width - 20;
            }
            contentdiv.style.width = Globle_width + "px";
            contentdiv.style.height = Globle_height + "px";
            contentdiv.style.margin = "-" + Globle_height / 2 + "px 0px 0px -" + Globle_width / 2 + "px";
            _frame.width = Globle_width;
            _frame.height = Globle_height;
            closebutton.style.width = Globle_width_p + "px";
            closebutton.style.display = "inline-block";
            f.style.width = Globle_width + "px";
            f.style.height = _tkMessageBox.setheightauto(Globle_height_div1) + "px";
            f.style.display = "block";
            document.getElementById('__messageboxback').style.width = Globle_width + "px";
            document.getElementById("messageboxclosebutton").style.display = "inline-block";
        } catch (e1) { }
    },
    getMsgDivHeight: function() {
        var a = document.body.scrollHeight;
        var b = window.screen.height;
        return a > b ? a : b;
    },
    InitMsgDivData: function() {
        if (Globle_shadow) {
            newdiv.id = "blackbg";
            newdiv.style.display = "none";
            newdiv.style.zIndex = '99990';
            newdiv.style.backgroundColor = "#000000";
            newdiv.style.filter = "alpha(opacity=30)";
            newdiv.style.opacity = 0.3;
            newdiv.style.display = "block";
            newdiv.style.top = "0px";
            newdiv.style.left = "0px";
            newdiv.style.width = "100%";
            newdiv.style.height = _tkMessageBox.getMsgDivHeight() + "px";

            document.body.appendChild(newdiv);
        }

        contentdiv.id = "blackcontentOuter";
        contentdiv.style.display = "none";
        contentdiv.style.zIndex = '99991';
        contentdiv.style.width = '10px';
        contentdiv.style.height = '10px';
        contentdiv.style.margin = '-5px 0px 0px -5px';
        contentdiv.style.backgroundColor = "";

        document.body.appendChild(contentdiv);
    },
    scroolMsgeffect: function() {
        contentdiv.style.display = "block";
        _tkMessageBox.scroolMsgdiv();
    },
    getiecopy: function() {
        var bro = navigator.userAgent.toLowerCase();
        if (/msie/.test(bro)) return bro.match(/msie ([\d.]*);/)[1];
    },
    setheightauto: function(input) {
        if (document.all) {
            if (_tkMessageBox.getiecopy() < 7.0) return input + 3;
        }
        return input;
    },
    scroolMsgdiv: function() {
        tempwidth = Globle_width;
        tempheight = Globle_height;
        contentdiv.innerHTML = Globle_Str;
        contentdiv.style.width = tempwidth + "px";
        contentdiv.style.height = tempheight + "px";
        contentdiv.style.margin = "-" + tempheight / 2 + "px 0px 0px -" + tempwidth / 2 + "px";
        var _frame = document.getElementById("_tkMessageBoxFrame");
        _frame.src = Globle_src;
    }
};
function ShowSelectAll(show, sID) {
    var sList = document.getElementsByTagName("select");
    if (sID && sID != '') sID = "|" + sID + '|'
    if (sList && sList.length > 0) {
        for (var i = 0; i < sList.length; i++) {
            if (sID && sID != '') {
                if (sList[i].id && sList[i].id != '' && sID.indexOf('|' + sList[i].id + '|') >= 0) continue;                
            }
            if (show) sList[i].style.display = 'inline';
            else sList[i].style.display = 'none';
        }
    }
}
function setDialogTitle(msg) {
    var d_title = document.getElementById('dialogTitle');
    if (d_title) d_title.innerHTML = msg;
}
