﻿var bgObj,msgObj,s; 
function alertWin(title, msg, w, h,bt) {
    s = document.getElementsByTagName("select"); //--------------把所有select标签捉住
    for (var j = 0; j < s.length; j++) { s[j].style.display = "none"; } //--------------设为不显示，再进行下面操作

    var scrtop, iHeight;
    if (window.innerHeight && window.scrollMaxY) {
        // Mozilla
        scrtop = window.pageYOffset;
    } else if (document.body.scrollHeight > document.body.offsetHeight) {
        // all but IE Mac
        scrtop = document.documentElement.scrollTop;
    } else if (document.body) { // IE Mac
        scrtop = document.documentElement.scrollTop;
    }
    iHeight = document.documentElement.scrollHeight;
    var iWidth = document.documentElement.clientWidth;
    bgObj = document.createElement("div");
    bgObj.className = "msgbgdiv";
    bgObj.style.cssText += "width:" + iWidth + "px;height:" + Math.max(document.body.clientHeight, iHeight) + "px;";
    bgObj.title = "单击背景可关闭窗口";
    document.body.appendChild(bgObj);
    msgObj = document.createElement("div");
    msgObj.className = "msgdiv";
    msgObj.style.cssText = "top:" + (document.documentElement.clientHeight - h + scrtop) / 2 + "px;left:" + (iWidth - w) / 2 + "px;width:" + w + "px;height:" + h + "px;";
    document.body.appendChild(msgObj);
    
    var divtitle = document.createElement("div");
    divtitle.className = "msgtitle";
    msgObj.appendChild(divtitle);
    var h3 = document.createElement("H3");
    h3.className = "msgH3";
    h3.innerHTML = title;
    divtitle.appendChild(h3);

    var closeBtn = document.createElement("span");
    closeBtn.className = "msgClose";
    closeBtn.innerHTML = "x";
    divtitle.appendChild(closeBtn);
    closeBtn.onclick = function() { clear(bgObj, msgObj, s); }
    
    var moveX = 0;
    var moveY = 0;
    var moveTop = 0;
    var moveLeft = 0;
    var moveable = false;
    var docMouseMoveEvent = document.onmousemove;
    var docMouseUpEvent = document.onmouseup;
    divtitle.onmousedown = function() {
        var evt = getEvent();
        moveable = true;
        moveX = evt.clientX;
        moveY = evt.clientY;
        moveTop = parseInt(msgObj.style.top);
        moveLeft = parseInt(msgObj.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 + w < iWidth) && y > 0 && (y + h < iHeight)) {
                    msgObj.style.left = x + "px";
                    msgObj.style.top = y + "px";
                }
            }
        };
        document.onmouseup = function() {
            if (moveable) {
                document.onmousemove = docMouseMoveEvent;
                document.onmouseup = docMouseUpEvent;
                moveable = false;
                moveX = moveY =moveTop =moveLeft = 0;
            }
        };
    }
    msgObj.appendChild(msg);

    bgObj.onclick = function() { clear(bgObj, msgObj, s); }
    if (bt != undefined) {ID$(bt).onclick = function() { if(onUploadImgChange())clear(bgObj, msgObj, s); } }
    // 获得事件Event对象，用于兼容IE和FireFox
    function getEvent() {
        return window.event || arguments.callee.caller.arguments[0];
    }
}

function clear(bgObj, msgObj, s) {
    for (var j = 0; j < s.length; j++) { s[j].style.display = "block"; } //--------------再给select显出来
    document.body.removeChild(bgObj);
    document.body.removeChild(msgObj);
}