﻿// 弹出遮罩层
// 修改记录：
var isIE = (document.all) ? true : false;
var isIE6 = isIE && ([/MSIE (\d)\.0/i.exec(navigator.userAgent)][0][1] == 6);

// 打开遮罩
function FY_Popup(url, w, h) {
    $("<div id='popBg'></div>").prependTo("body");
    $("#popBg").css("height", Math.max(document.documentElement.scrollHeight, document.documentElement.clientHeight) + "px"); // 重置背景层高度
    $("#popBg").fadeTo("slow", 0.9);
    $("<div id='popHighLight' class='FY_PopupHighLight'></div").prependTo("body");
    $("#popHighLight").css("width", w + "px");
    $("#popHighLight").css("height", h + "px");
    $("#popHighLight").css("margin-left", "-" + w / 2 + "px");

    if (isIE6) {
        $("#popHighLight").css("position", "absolute");
        $("#popHighLight").css("margin-top", document.documentElement.scrollTop + (document.documentElement.clientHeight - $("#popHighLight").innerHeight()) / 2 + "px");
    } else {
        $("#popHighLight").css("position", "fixed");
        $("#popHighLight").css("top", "50%");
        $("#popHighLight").css("margin-top", "-" + $("#popHighLight").innerHeight() / 2 + "px");
    }

    $("<a href='javascript://void(0);' target='_top' class='FY_PopupCloser' onclick='FY_PopupClose();'>关闭</a>").appendTo($("#popHighLight")); // 插入关闭按钮
    $("<iframe src='" + url + "' width='100%' height='100%' scrolling='no' frameborder='0'></iframe>").appendTo($("#popHighLight")); // 插入子节点

    if (isIE6) {
        window.onscroll = function() {
            $("#popHighLight").css("margin-top", document.documentElement.scrollTop + (document.documentElement.clientHeight - $("#popHighLight").innerHeight()) / 2 + "px");
        }
    }
}

// 关闭遮罩
function FY_PopupClose() {
    if (typeof (FY_PopupCloseSelf) == "function") {
        FY_PopupCloseSelf();

        return false;
    }
    else {
        $("#popHighLight").empty(); // 清除遮罩背景层中的所有子节点
        $("#popHighLight").remove(); // 隐藏遮罩背景层
        $("#popBg").remove(); // 隐藏遮罩背景层

        return false;
    }
}
