﻿document.write('<style type="text/css">\
                <!--\
                #dialog {position:absolute;border:2px solid #666666;z-index:200;padding:1px;background:#ffffff;}\
                #dialog-header {display:block;position:relative;height:46px;line-height:46px;font-size:14px;font-weight:bold;color:#FFFFFF;background:#333333;border-bottom:1px solid #ffffff;}\
                #dialog-title {float:left;height:46px;width:auto;padding-left:55px;}\
                #dialog-close {float:right;cursor:pointer;height:46px;width:50px;background:url(/images/dialog/close.gif) no-repeat}\
                #dialog-content {display:block;border-top:1px solid #cccccc;color:#333333;font-size:14px;font-weight:bold;text-align:center;}\
                #mycontent {background:url(/images/dialog/confirm.gif) no-repeat bottom;cursor:pointer;padding-top:30px;}\
                .error {background:url(/images/dialog/error.gif) no-repeat left;}\
                .warning {background:url(/images/dialog/warning.gif) no-repeat left;}\
                .success {background:url(/images/dialog/success.gif) no-repeat left;}\
                .prompt {background:url(/images/dialog/prompt.gif) no-repeat left;}\
                -->\
                </style>');
function pageWidth() {
    return window.innerWidth != null ? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
}
function pageHeight() {
    return window.innerHeight != null ? window.innerHeight : document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body != null ? document.body.clientHeight : null;
}
function topPosition() {
    return typeof window.pageYOffset != 'undefined' ? window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;
}
function leftPosition() {
    return typeof window.pageXOffset != 'undefined' ? window.pageXOffset : document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;
}
function getEvent() {
    return window.event || arguments.callee.caller.arguments[0];
}
function showDialog(title, message, type, uwidth, uheight, hiddenconfirm, autohide) {
    if (!type) {
        type = 'error';
    }
    var dialog;
    var dialogheader;
    var dialogclose;
    var dialogtitle;
    var dialogcontent;
    if (!document.getElementById('dialog')) {
        dialog = document.createElement('div');
        dialog.id = 'dialog';
        dialogheader = document.createElement('div');
        dialogheader.id = 'dialog-header';
        dialogtitle = document.createElement('div');
        dialogtitle.id = 'dialog-title';
        dialogclose = document.createElement('div');
        dialogclose.id = 'dialog-close'
        dialogcontent = document.createElement('div');
        dialogcontent.id = 'dialog-content';
        document.body.appendChild(dialog);
        dialog.appendChild(dialogheader);
        dialogheader.appendChild(dialogtitle);
        dialogheader.appendChild(dialogclose);
        dialog.appendChild(dialogcontent); ;
        dialogclose.setAttribute('onclick', 'hideDialog()');
        dialogclose.onclick = hideDialog;
    } else {
        dialog = document.getElementById('dialog');
        dialogheader = document.getElementById('dialog-header');
        dialogtitle = document.getElementById('dialog-title');
        dialogclose = document.getElementById('dialog-close');
        dialogcontent = document.getElementById('dialog-content');
        dialog.style.visibility = "visible";
    }
    dialog.style.width = uwidth + "px";
    dialogheader.style.width = uwidth + "px";
    dialogcontent.style.height = uheight + "px";
    var width = pageWidth();
    var height = pageHeight();
    var left = leftPosition();
    var top = topPosition();
    var dialogwidth = dialog.offsetWidth;
    var dialogheight = dialog.offsetHeight;
    var topposition = top + (height / 3) - (dialogheight / 2);
    var leftposition = left + (width / 2) - (dialogwidth / 2);
    dialog.style.top = topposition + "px";
    dialog.style.left = leftposition + "px";
    dialogtitle.className = type;
    dialogtitle.innerHTML = title;
    if (hiddenconfirm) {
        dialogcontent.innerHTML = message;
    } else {
        dialogcontent.innerHTML = "";
        var mycontent;
        if (!document.getElementById('mycontent')) {
            mycontent = document.createElement('div');
            mycontent.id = 'mycontent';
            mycontent.setAttribute('onclick', 'hideDialog()');
            mycontent.onclick = hideDialog;
            dialogcontent.appendChild(mycontent);
        } else {
            mycontent = document.getElementById('mycontent');
        }
        mycontent.style.height = (uheight - 60) + "px";
        mycontent.innerHTML = message;
    }
    if (autohide) {
        dialogclose.style.visibility = "hidden";
        window.setTimeout("hideDialog()", (autohide * 1000));
    }
    var iWidth = document.documentElement.clientWidth;
    var iHeight = document.documentElement.clientHeight;
    var docMouseMoveEvent = document.onmousemove;
    var docMouseUpEvent = document.onmouseup;
    dialogheader.style.cursor = "move";
    dialogheader.onmousedown = function() {
        var evt = getEvent();
        moveable = true;
        moveX = evt.clientX;
        moveY = evt.clientY;
        moveTop = parseInt(dialog.style.top);
        moveLeft = parseInt(dialog.style.left);
        document.onmousemove = function() {
            if (moveable) {
                var evt = getEvent();
                var x = moveLeft + evt.clientX - moveX;
                var y = moveTop + evt.clientY - moveY;
                if (x > 0 && (x + uwidth + 20 < iWidth) && y > 0 && (y + uheight + 55 < iHeight)) {
                    dialog.style.left = x + "px";
                    dialog.style.top = y + "px";
                }
            }
        };
        document.onmouseup = function() {
            if (moveable) {
                document.onmousemove = docMouseMoveEvent;
                document.onmouseup = docMouseUpEvent;
                moveable = false;
                moveX = 0;
                moveY = 0;
                moveTop = 0;
                moveLeft = 0;
            }
        };
    }
}
function hideDialog() {
    fadeDialog(0);
}
function fadeDialog(flag) {
    if (flag == null) {
        flag = 1;
    }
    var dialog = document.getElementById('dialog');
    if (dialog) {
        if (flag == 1) {
            dialog.style.visibility = "visible";
        } else if (flag == 0) {
            dialog.style.visibility = "hidden";
        } 
    }
}
function showMessageDialog(title, message, type, autohide) {
    showDialog(title, message, type, 400, 150, false, autohide);
}
function showIframeDialog(title, iframe, uwidth, uheight) {
    showDialog(title, iframe, 'prompt', uwidth, uheight, true);
}
function showPrompt(title, message, dosome) {
    var divcontent = "<div style=\"width:400px;\"><div style=\"float:left;height:60px;width:400px;padding-top:30px;line-height:30px;\">" + message + "</div><div style=\"float:left;height:70px;width:400px;\"><img src=\"/images/dialog/confirm.gif\" alt=\"确定\" onclick=\"" + dosome + ";this.disabled=true;\" style=\"cursor:pointer;\"/>&nbsp;&nbsp;<img src=\"/images/dialog/cancel.gif\" alt=\"取消\" onclick=\"hideDialog()\" style=\"cursor:pointer;\" /></div></div>";
    showIframeDialog(title, divcontent, 400, 160);
}