﻿function PopupDiv(id, OkEvent, OkEventArgs) {
    $("#"+id+"_content").show();            
    $("#"+id+"_result").hide();
    
    var pop = $("#"+id);
    var windowWidth = $(document).width();
    var windowHeight = $(document).height();
    var popupHeight = pop.height();
    var popupWidth = pop.width();
    
    //添加并显示遮罩层
    if($("#mask").length > 0) $("#mask").remove();
    var bgIframe = null;
    if (ie6() == true) {
        bgIframe = document.createElement("iframe");
        bgIframe.setAttribute("src", "");
        bgIframe.style.cssText = "position:absolute;top:0px;left:0px;width:100%;height:100%; filter: alpha(opacity=0); opacity: 0; z-index:-1;";
    }
    $("<div id='mask'></div>").append(bgIframe).appendTo("body").show();
    
    //显示弹出层                                            
    pop.css({"left":(windowWidth - popupWidth) / 2 + 'px', 
             "top":(document.documentElement.clientHeight - popupHeight) / 2 + document.documentElement.scrollTop + 'px'})
       .show();
    
    //注册关闭按钮的点击事件
    pop.find(".Popup_ok")
        .unbind("click")
        .one("click", function(e) {OkEvent(OkEventArgs,id);})
        .css({"cursor":"pointer"});
                                                    
    //注册关闭按钮的点击事件
    pop.find(".Popup_cancel")
        .unbind("click")
        .one("click", function(e) {hideDiv(id);})
        .css({"cursor":"pointer"});
}  
 
function hideDiv(id) {
    $("#mask").hide();
    $("#" + id).hide();
}

function showDiv(id, Event, EventArgs) {
    var div = $("#"+id);
    var windowWidth = $(document).width();
    var windowHeight = $(document).height();
    var popupHeight = div.height();
    var popupWidth = div.width();
    
    div.css({"position":"absolute", 
             "z-index": "999",
             "left":(windowWidth - popupWidth) / 2, 
             "top":(document.documentElement.clientHeight - popupHeight) / 2 + document.documentElement.scrollTop + 'px'})
        .show();
                                                    
    //注册关闭按钮的点击事件
    div.find(".Popup_cancel")
        .unbind("click")
        .one("click", function(e) {div.hide(); if(Event!=null) Event(EventArgs);})
        .css({"cursor":"pointer"});
}

function ajaxLoading(id) {
    var loading = $("#"+id);
    var windowWidth = $(document).width();
    var windowHeight = $(document).height();
    var popupHeight = loading.height();
    var popupWidth = loading.width();
                                           
    loading.css({"position":"absolute", 
             "z-index": "999",
             "left":(windowWidth - popupWidth) / 2 + 'px', 
             "top":(document.documentElement.clientHeight - popupHeight) / 2 + document.documentElement.scrollTop + 'px'})
           .toggle();
}

 function GetUserID() {
    var uid = "";
    $.post("/Personal/IDSet/idset.ashx", 
            {action:"userid"},
            function(result) {
                uid = result;
            }
    );
    return uid;
}

function ie6() {
    var b = new Browser();
    if (b.isIE == true && b.version == "6")
        return true;
    else
        return false;
}

function Browser() {

    var ua, s, i;

    this.isIE = false;   // Internet Explorer
    this.isNS = false;   // Netscape
    this.version = null;

    ua = navigator.userAgent;

    s = "MSIE";
    if ((i = ua.indexOf(s)) >= 0) {
        this.isIE = true;
        this.version = parseFloat(ua.substr(i + s.length));
        return;
    }

    s = "Netscape6/";
    if ((i = ua.indexOf(s)) >= 0) {
        this.isNS = true;
        this.version = parseFloat(ua.substr(i + s.length));
        return;
    }

    // Treat any other "Gecko" browser as NS 6.1.

    s = "Gecko";
    if ((i = ua.indexOf(s)) >= 0) {
        this.isNS = true;
        this.version = 6.1;
        return;
    }
}