﻿var obj, cover;
var tmpAlpha=0.0, tmpAlphaN=0.5;

function show(id){    //弹出对话框
    var pageSize = GetPageSize(); 
	cover = document.body.appendChild(document.createElement("div"));
	obj = document.getElementById(id); 
	cover.id = 'cover';
	cover.onclick = DecOpacity;
	cover.style.width = pageSize.WinW+"px";
	if(document.all) cover.style.height = pageSize.WinH; else cover.style.height = "100%";
	cover.style.top = document.documentElement.scrollTop + "px";   
	cover.style.visibility="visible";
		
	obj.style.visibility="visible";
	obj.style.left = (pageSize.WinW - obj.clientWidth)/2 + "px"; 
	obj.style.top = (pageSize.WinH - obj.clientHeight)/2 + GetPageScroll().Y +"px";
	AddOpacity();
}
window.onscroll = function () {   
    if(cover) cover.style.top = document.documentElement.scrollTop + "px";   
} 

function AddOpacity(){
	if(!cover) return;
    obj.style.opacity=tmpAlpha;
    obj.style.filter="alpha(opacity="+tmpAlpha*100+")";
    cover.style.opacity=tmpAlpha;
    cover.style.filter="alpha(opacity="+tmpAlpha*60+")";
	tmpAlpha+=0.05;
	if(tmpAlpha>=0.5) cover.style.opacity = 0.5;		
	if(tmpAlpha>=1){
		obj.style.opacity = 1;
		return;
	}else setTimeout("AddOpacity()",20);
}

function DecOpacity(){    //隐藏对话框
	if(!cover) return;
    obj.style.opacity=tmpAlphaN;
    obj.style.filter="alpha(opacity="+tmpAlphaN*100+")";
    cover.style.opacity=tmpAlphaN;

    cover.style.filter="alpha(opacity="+tmpAlphaN*60+")";
	tmpAlphaN-=0.05;
	if(tmpAlphaN<=0){
	    obj.style.opacity = 0;
	    obj.style.visibility="hidden";
	    document.body.removeChild(cover); cover = null;
	    tmpAlpha=0.0;
	    tmpAlphaN=0.5;
	    try{ClosePop();}catch(e){} 
	    return;
	}
	else setTimeout("DecOpacity()",20);
	
	
}

/*************************/
function GetPageSize() {  //获取页面高度宽度
    var scrW, scrH;  
    if(window.innerHeight && window.scrollMaxY) {    // Mozilla    
        scrW = window.innerWidth + window.scrollMaxX;    
        scrH = window.innerHeight + window.scrollMaxY;  } 
    else if(document.body.scrollHeight > document.body.offsetHeight){      
        scrW = document.body.scrollWidth; scrH = document.body.scrollHeight; } 
    else if(document.body) { // IE Mac    
        scrW = document.body.offsetWidth;    
        scrH = document.body.offsetHeight; }    

    var winW, winH;  
    if(window.innerHeight) { // all except IE    
        winW = window.innerWidth;    winH = window.innerHeight;  } 
    else if (document.documentElement     && document.documentElement.clientHeight) {    // IE 6 Strict Mode    
        winW = document.documentElement.clientWidth;     winH = document.documentElement.clientHeight;  } 
    else if (document.body) { 
        winW = document.body.clientWidth;    
        winH = document.body.clientHeight;  
    }    // for small pages with total size less then the viewport  
    var pageW = (scrW<winW) ? winW : scrW;  var pageH = (scrH<winH) ? winH : scrH;    
    return {PageW:pageW, PageH:pageH, WinW:winW, WinH:winH };
}
//页面滚动高度
function GetPageScroll() {  
    var x, y;  
    if(window.pageYOffset) {    // all except IE    
        y = window.pageYOffset;    x = window.pageXOffset; } 
    else if(document.documentElement     && document.documentElement.scrollTop) {    // IE 6 Strict    
        y = document.documentElement.scrollTop;    x = document.documentElement.scrollLeft;  } 
    else if(document.body) {    // all other IE    
        y = document.body.scrollTop;  x = document.body.scrollLeft; }  
    return {X:x, Y:y};
}