﻿var _pop;
function ShowPop(url,w,h)
{
    _pop = (_pop==null) ? new PopDiv(w,h) : _pop;    //不用每次都初始化
    if(_pop.fixWidth!=w) {_pop.fixWidth=w;}
    if(_pop.fixHeight!=h) {_pop.fixHeight=h;}
    _pop.ResetPop();
    _pop.popFrame.src = url;
    _pop.Show();
}
function ClosePop()
{
    if(_pop!=null) _pop.Hide();
}

function PopFrameLoaded()
{
    if(_pop==null) {return;}
    _pop.popFrame.style.visibility="visible";
    _pop.title.innerHTML = _pop.popWeb.document.title;
	var subWebC_H =(document.all)? _pop.popWeb.document.body.scrollHeight : _pop.popWeb.document.documentElement.offsetHeight;
	var subWebC_W =(document.all)? _pop.popWeb.document.body.scrollWidth : _pop.popWeb.document.body.offsetWidth;
    var h =(_pop.fixHeight)?_pop.fixHeight : Math.max(100,subWebC_H)+45;//要加上滚动条 24px
    var w =(_pop.fixWidth)?_pop.fixWidth :  Math.max(400,subWebC_W)+28;
    _pop.bgHeight = Math.max(h,_pop.bgHeight);
    _pop.bgWidth = Math.max(w,_pop.bgWidth);
    _pop.bgPanel.style.height = (_pop.bgHeight+_pop.titleHeight)+"px";
    _pop.bgPanel.style.width = _pop.bgWidth+"px";
    if(document.all)
    {
        _pop.bgFrame.style.height = (_pop.bgHeight+_pop.titleHeight)+"px";
        _pop.bgFrame.style.width = _pop.bgWidth+"px";
    }
    _pop.popFrame.style.height = h+"px";
    _pop.popFrame.style.width = w+"px";
    _pop.msgBox.style.height = (h+_pop.titleHeight)+"px";
    _pop.msgBox.style.width = w+"px";
    _pop.header.style.width = w+"px";
    
    var topS = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
//    var t = (((_pop.bgHeight < h)? 0 :(_pop.bgHeight - h))/2);
//    var l =(((_pop.bgWidth < w)? 0 :(_pop.bgWidth - w))/2);
    var t = (((window.screen.availHeight < h)? 0 :(window.screen.availHeight - h))/2);
    var l =(((_pop.bgWidth < w)? 0 :(_pop.bgWidth - w))/2);
    _pop.msgBox.style.top = (t+topS) +"px";
    _pop.msgBox.style.left = l +"px";
}

function PopDiv(w,h)
{
    this.bgWidth = Math.max(document.body.clientWidth,document.body.offsetWidth);
    this.bgHeight = Math.max(document.body.clientHeight,document.body.offsetHeight);
    this.borderColor="#336699";//提示窗口的边框颜色
    this.titleColor="#99CCFF";//提示窗口的标题颜色
    
    this.titleHeight = 25; //固定宽度
    this.fixWidth = w; //固定宽度
    this.fixHeight = h;//固定高度
    this.isVisibled = false;
    
	var htm = [];
	htm[htm.length] = '<div id="PopDivBgPanel" style="position: absolute;top:0px;left:0px;background-color:#ccc;'
	    +'filter:progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75);opacity:0.6;'
	    +'height:'+this.bgHeight+'px;width:'+this.bgWidth+'px;z-index:10000">';
    if(document.all)
    {  
       htm[htm.length] ='<iframe id="PopDivBgFrame" style="position:absolute;z-index:9000;width:'+this.bgHeight+'px;height:'+this.bgWidth+'px;left:0px;top:0px;'
		+ 'filter:progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=0);" scrolling="no" frameborder="no">';
       htm[htm.length] ='</iframe>';
	}
	htm[htm.length] = '</div>';//PopDivBgPanel 结束
	
	//PopDivMessageBox 开始
	htm[htm.length] = '<div id="PopDivMessageBox" align="center" ';
	htm[htm.length] = ' style="position: absolute;top:0px;left:0px;background-color:#fff;border:1px solid '+this.borderColor
	    +';font:16px Verdana, Geneva, Arial, Helvetica, sans-serif;text-algin:center;padding:0px;z-index:10001;">';
	
	//PopDivHeader 开始
	htm[htm.length] = '<div id="PopDivHeader"';
	htm[htm.length] = ' style="background-color:'+this.borderColor+';color:#fff;lineHeight:'+this.titleHeight+'px;height:'+this.titleHeight+'px;border:1px solid '+this.borderColor+';float:left;">';
	//PopDivTitle 开始
	htm[htm.length] =   '<div id="PopDivTitle" style="float:left;font:12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif;font-weight:bolder;padding:2px 2px 2px 20px;">';
	htm[htm.length] =   '&nbsp;</div>';//PopDivTitle 结束
    htm[htm.length] =   "<div style='border:1px solid white;width:20px;float:right;font-weight:bolder;cursor:pointer' align='center' onclick='ClosePop()'>×</div>";	
	htm[htm.length] = '</div>';//PopDivHeader 结束
	
	//PopDivFrame 开始
	htm[htm.length] =   '<iframe style="width:10%;margin:0px;height:10%;" frameborder="no" id="PopDivFrame" name="PopDivFrame" src="" scrolling="yes" onLoad="PopFrameLoaded()"></iframe>';
	
	htm[htm.length] = '</div>';//PopDivMessageBox 结束
	
	var div = document.createElement("div");
	div.innerHTML = htm.join("\r\n");
	div.id = "PopDivContainerPanel";
	div.style.display ="none";
	document.body.appendChild(div);
	
	//初始化对象
	this.popPanel = this.getObjectById("PopDivContainerPanel");
	this.bgPanel = this.getObjectById("PopDivBgPanel");
	if(document.all){this.bgFrame = this.getObjectById("PopDivBgFrame");}
	this.msgBox = this.getObjectById("PopDivMessageBox");
	this.header = this.getObjectById("PopDivHeader");
	this.title = this.getObjectById("PopDivTitle");
	this.popFrame = this.getObjectById("PopDivFrame");
	this.popWeb = PopDivFrame;
    
    window.objPopDiv = this; //方便其它页面访问
}

PopDiv.prototype.ResetPop = function()
{
    //复位
    this.bgWidth = Math.max(document.body.clientWidth,document.body.offsetWidth);
    this.bgHeight = Math.max(document.body.clientHeight,document.body.offsetHeight);
    
    this.popFrame.style.visibility="hidden";
    this.title.innerHTML = "正读取数据，请稍候……";
    var h =100;
    var w =300;
    this.bgPanel.style.height = (this.bgHeight+this.titleHeight)+"px";
    this.bgPanel.style.width = this.bgWidth+"px";
    if(document.all)
    {
        this.bgFrame.style.height = (this.bgHeight+this.titleHeight)+"px";
        this.bgFrame.style.width = this.bgWidth+"px";
    }
    this.popFrame.style.height = h+"px";
    this.popFrame.style.width = w+"px";
    this.msgBox.style.height = (h+this.titleHeight)+"px";
    this.msgBox.style.width = w+"px";
    this.header.style.width = w+"px";
    
    var topS = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
//    var t = (((this.bgHeight < h)? 0 :(this.bgHeight - h))/2);
//    var l =(((this.bgWidth < w)? 0 :(this.bgWidth - w))/2);
    var t = (((window.screen.availHeight < h)? 0 :(window.screen.availHeight - h))/2);
    var l =(((this.bgWidth < w)? 0 :(this.bgWidth - w))/2);
    this.msgBox.style.top = (t+topS) +"px";
    this.msgBox.style.left = l +"px";
}

PopDiv.prototype.Show = function()
{
    this.popPanel.style.display = "block";
    this.isVisibled = true;
}

PopDiv.prototype.Hide = function()
{
    this.popPanel.style.display = "none";
    this.popFrame.style.visibility="hidden";
    this.isVisibled = false;
}

PopDiv.prototype.getObjectById = function(id)
{
	if(document.all)
	{
		var obj = document.getElementById(id);
		if(obj.id == id){return obj;}
		obj = document.getElementsByName(id);
		for(var i=0;i< obj.length;i++)
		{
			if(obj[i].id == id){return obj[i];}
		}
	}
	if(document.getElementById) {return document.getElementById(id);}
    try {return eval(id);} catch(e){ return null;}
}