﻿function showBox(id) {
    var isIE = (document.all) ? true : false;
    var isIE6 = isIE && ([/MSIE (\d)\.0/i.exec(navigator.userAgent)][0][1] == 6);
    if (isIE6) {
        showBoxForIE6(id);
    }
    else {
        //最外层;
        var screen = document.createElement("div");
        screen.id = "screentBox";
        //透明背景
        var filterBox = document.createElement("div");
        filterBox.className = "filterBox";
        //内容北景
        var contentBox = document.createElement("div");
        contentBox.className = "screenContentBox";

        screen.appendChild(filterBox);
        screen.appendChild(contentBox);
        var objDiv = document.getElementById(id);
        objDiv.style.display = "block";
        contentBox.appendChild(objDiv);
        var form = document.forms[0];
        form.appendChild(screen);
    }
}

function showBoxForIE6(id) {
    var content = document.getElementById(id);
    content.style.zIndex = "9999";
    content.style.display = "block";
    content.style.position = "absolute";
    content.style.top = "25%";
    content.style.left = "50%";
    content.style.marginTop = -content.offsetHeight / 2 + "px";
    content.style.marginLeft = -content.offsetWidth / 2 + "px";
    var screentBox = document.createElement("div");
    screentBox.id = "screentBox";
    screentBox.style.width = screentBox.style.height = "100%";
    screentBox.style.position = "absolute";
    screentBox.style.top = screentBox.style.left = 0;
    screentBox.style.backgroundColor = "#000";
    screentBox.style.zIndex = "9998";
    screentBox.style.opacity = "0.6";

    function layer_iestyle() {
        screentBox.style.width = Math.max(document.documentElement.scrollWidth, document.documentElement.clientWidth) + "px";
        screentBox.style.height = Math.max(document.documentElement.scrollHeight, document.documentElement.clientHeight) + "px";
    }
    function newbox_iestyle() {
        content.style.marginTop = document.documentElement.scrollTop - content.offsetHeight / 2 + "px";
        content.style.marginLeft = document.documentElement.scrollLeft - content.offsetWidth / 2 + "px";
    }
    screentBox.style.filter = "alpha(opacity=60)";
    layer_iestyle();
    newbox_iestyle();
    window.attachEvent("onscroll", function() { newbox_iestyle(); });
    window.attachEvent("onresize", layer_iestyle);

    var form = document.forms[0];
    form.appendChild(screentBox);
    hiddenSelect();
}

function closeScreen(id) {
    var content = document.getElementById(id);
    var screenBox = document.getElementById("screentBox");
    var form = document.forms[0];
    content.style.display = screenBox.style.display = "none";
    form.appendChild(content);
    form.removeChild(screenBox);
    showSelect();
}

function hiddenSelect() {
    var selects = document.getElementsByTagName("select");
    for (var i = 0; i < selects.length; i++) {
        selects.item(i).style.visibility = "hidden";
    }
}
function showSelect() {
    var selects = document.getElementsByTagName("select");
    for (var i = 0; i < selects.length; i++) {
        selects.item(i).style.visibility = "visible";
    }
}
