
if(!PopupBox||typeof(PopupBox)!=="object")
{
	var PopupBox={};
	PopupBox.PreEvenX=null;
	PopupBox.PreEvenY=null;
	PopupBox.AlertBoxHTML=Ajax().SynchronousGet(Site.GetRootPath()+'Component/LightBox/Html/AlertBox.html?AjaxTime='+((new Date()).valueOf())).Text;	
	PopupBox.WaitingBoxHTML=Ajax().SynchronousGet(Site.GetRootPath()+'Component/LightBox/Html/WaitingBox.html?AjaxTime='+((new Date()).valueOf())).Text;	
	PopupBox.TopBoxs=[];
	PopupBox.AutoCoverBox=[];
	PopupBox.ShowBottom=function()
	{
		var BottomBox=$F("BottomPopupBox");
		if(!BottomBox)
		{
			var Node = document.createElement( "div" ); 
				Node.id="BottomPopupBox";
				Node.Position="FitExplorer";
				Node.style.cssText='position:absolute;width:100%;height:100%;top:0px;left:0px;z-index:1999;background:url(/OnlineOffice/Images/Background/Alpha20.png)';
				document.body.appendChild(Node);
				return;
		}
		BottomBox.style.width=Math.max(document.body.scrollWidth,GetViewportInfo().W)-30+"px";
		BottomBox.style.height=Math.max(document.body.scrollHeight,GetViewportInfo().H)+"px";
		BottomBox.style.visibility="visible";
		BottomBox.style.display="";
		return;
		
	}
	
	PopupBox.HidBottom=function()
	{
		 var BottomBox=$F("BottomPopupBox");
		 if(!BottomBox){return false;}
		 BottomBox.style.visibility="hidden";
		 BottomBox.style.display="none";
	}
	
	PopupBox.CreatePopup=function(BoxId)//建立顶层显示层(DIV)
	{
		if(BoxId=="BottomPopupBox"){return false;}
		if($F(BoxId)){return $F(BoxId)}
		var Node = document.createElement( "div" ); 
			Node.id=BoxId;
			Node.BoxName="PopupBox";
			Node.FitExPlorer=true;
			Node.style.cssText='position:absolute;z-index:2000;left:0px;top:0px;visibility:\
			hidden;border-style:outset;border-width:1px;'
			document.body.appendChild(Node);	
			return Node;
	}
	
	PopupBox.SetInnerHTML=function(BoxId,HTML)//设置Box内容
	{
		
		if(BoxId=="BottomPopupBox"){return false;}
		if(BoxId!=="WaitingBox"&&BoxId!=="AlertBox")
		{
			if($F("WaitingBox")||$F("AlertBox"))
			{
				return false;
			}
		}
		var Box=$F(BoxId)
		if(!Box){return false}
		Box.innerHTML=HTML;
		PopupBox.SetRang(BoxId,Box.Position);
		return true;
		
	}
	
	PopupBox.Show=function(BoxId)
	{
		if(BoxId=="BottomPopupBox")
		{
			PopupBox.ShowBottom();
			return;
		}
		if(BoxId!=="WaitingBox"&&BoxId!=="AlertBox")
		{
			if($F("WaitingBox")||$F("AlertBox"))
			{
				return false;
			}
		}
		var Box=PopupBox.CreatePopup(BoxId);
		var Width=arguments[1]||"auto";
		var Position =arguments[2]||"FitExplorer";
		Box.Position=Position;
		//alert(PopupBox.TopBoxs.length);
		if(PopupBox.TopBoxs.length>0&&PopupBox.TopBoxs[PopupBox.TopBoxs.length-1]!==BoxId)
				 {
					 Box.style.zIndex=$F(PopupBox.TopBoxs[PopupBox.TopBoxs.length-1]).style.zIndex+1;
				 }
		Box.style.width=(Width+"px").replace("autopx",parseInt(window.screen.availWidth*0.7)+"px");
		
		Box.style.height="auto";
		Box.style.overflow="hidden";
		Box.style.visibility="visible"
		Box.style.display="";
		PopupBox.SetRang(BoxId,Position)
		for(var i in PopupBox.TopBoxs)
		{
			if(PopupBox.TopBoxs[i]==BoxId){return false;}
		
		}
		PopupBox.TopBoxs[PopupBox.TopBoxs.length]=BoxId+"";
		Box.focus();
		return Box;
	}
	
	PopupBox.CreateCoverBox=function(ParentBoxId)
	{
		
		var ParentBox=$F(ParentBoxId);
		if($F(ParentBox.Child))
			{
				
				$F(ParentBox.Child).style.visibility="visible";
				$F(ParentBox.Child).style.display="";
				return $F(ParentBox.Child);
			}
		Node = document.createElement( "div" ); 
		Node.id=ParentBox.id+"_Child";	
		Node.Position=ParentBox.Position;
		Node.Parent=ParentBox.id+"";
		ParentBox.Child=Node.id+"";
		Node.style.cssText='position:absolute;background-color:#000000;visibility:visible;filter:alpha(opacity=40);-moz-opacity:0.40; opacity:0.40;'
		Node.innerHTML='<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0"><tr><td align="center" valign="middle"></td></tr></table>';
		document.body.appendChild(Node);	
		Node.style.left=ParentBox.style.left;
		Node.style.top=ParentBox.style.top;
		Node.style.width=ParentBox.offsetWidth+"px";
		Node.style.height=ParentBox.offsetHeight+"px";
		Node.style.zIndex=ParentBox.style.zIndex;
		Node.FitExPlorer=ParentBox.FitExPlorer;
		return Node;
	}
	
	PopupBox.CreateChildPopup=function(ParentBoxId,BoxId)
	{
		
		var ParentBox=$F(ParentBoxId);
		if(!ParentBox||ParentBoxId==BoxId||BoxId=="BottomPopupBox"||ParentBoxId=="BottomPopupBox"){return false;}
		var Box=PopupBox.CreatePopup(BoxId);
			Box.Parent=PopupBox.CreateCoverBox(ParentBoxId).id+"";
			
	}
	
	PopupBox.Remove=function(BoxId)//删除
	{
		var Box=$F(BoxId);
		if(!Box){return false;}
		if($F(Box.Parent))
			{
				if(PopupBox.AutoCoverBox.toString().indexOf($F(Box.Parent).id)==-1)
				{
					$F($F(Box.Parent).Parent).Child="";;
					$F(Box.Parent).parentNode.removeChild($F(Box.Parent));
				}
			}
		for(var A in PopupBox.TopBoxs)
			{
				
				if(PopupBox.TopBoxs[A]==BoxId)
				{
					PopupBox.TopBoxs.splice(A,1);
					
				}
			}
		Box.parentNode.removeChild(Box);
		if(PopupBox.TopBoxs.length==0){PopupBox.HidBottom();}
		if(BoxId=="WaitingBox"||BoxId=="AlertBox"){PopupBox.RemoveAutoCoverBox();}
		return true;
	}


	PopupBox.Move=function(BoxId,Left,Top)//移动
	{
		var Box=$F(BoxId)
		if(!Box){return false;}
			Box.style.left=Left+"px";
			Box.style.top=Top+"px";
	}
	
	PopupBox.Hid=function(BoxId)//隐藏
	{
		var Box=$F(BoxId)
		if(!Box){return false;}
		Box.style.visibility="hidden";
		Box.style.display="none";
		if($F(Box.Parent))
			{
				$F($F(Box.Parent).Parent).Child="";
				$F(Box.Parent).parentNode.removeChild($F(Box.Parent))
			}
		for(var A in PopupBox.TopBoxs)
			{
				if(PopupBox.TopBoxs[A]==BoxId)
				{
					PopupBox.TopBoxs.splice(A,1);
				}
			}
		//if(Box.Parent){$F(Box.Parent).style.visibility="hidden";}
		if(PopupBox.TopBoxs.length==0){PopupBox.HidBottom();}
		return true;
	}

	PopupBox.SetRang=function(BoxId,Position)//设置TopBox窗口位置
	{
		var Box=$F(BoxId);
		if(!Box){return false;}
		var BWidth=Box.offsetWidth;
		var BHeight=Box.offsetHeight;
		if(BHeight>GetViewportInfo().H||BWidth>GetViewportInfo().W)
		{
			Box.style.height=parseInt(GetViewportInfo().H*0.8)+"px";
			
			BHeight=parseInt(GetViewportInfo().H*0.8);
			//BWidth=parseInt(GetViewportInfo().W*0.8);
			//alert(parseInt(GetViewportInfo().H*0.8))

		}
		else
		{
			Box.style.height="auto"
			BHeight=Box.offsetHeight;
			//BWidth=Box.offsetWidth;
			
		}
		switch (Position)
		{
			case "Center":
			Box.style.left=document.body.scrollLeft+(GetViewportInfo().W-BWidth)/2+"px";
			Box.style.top=document.body.scrollTop+(GetViewportInfo().H-BHeight)/2+"px";
			
			//Box.style.marginLeft="-"+document.body.scrollLeft+(GetViewportInfo().W-BWidth)/2+"px";
			//Box.style.marginTop=document.body.scrollTop+(GetViewportInfo().H-BHeight)/2+"px";
			//document.body.scrollTop+(GetViewportInfo().H-BHeight)/2
			break;
			case "LeftTop":
			Box.style.left=document.body.scrollLeft+"px";
			Box.style.top=document.body.scrollTop+"px";
			break;
			case "LeftBottom":
			Box.style.left=document.body.scrollLeft+"px";
			Box.style.top=document.body.scrollTop+GetViewportInfo().H-BHeight-4+"px";
			break;
			case "RightTop":
			//alert(document.body.scrollLeft);
			Box.style.left=GetViewportInfo().W-BWidth-4+"px";
			Box.style.top=document.body.scrollTop+"px";
			break;
			case "RightBottom":
			Box.style.left=document.body.scrollLeft+GetViewportInfo().W-BWidth-36+"px";
			Box.style.top=document.body.scrollTop+GetViewportInfo().H-BHeight-30+"px";
			break;
			case "FitExplorer":
			Box.style.left="30px";
			Box.style.top="30px";
			Box.style.width=Math.max(document.body.scrollWidth,GetViewportInfo().W)-60+"px";
			Box.style.height=Math.max(document.body.scrollHeight,GetViewportInfo().H)-60+"px";
			//Box.style.width=document.body.scrollWidth+"px";
			//Box.style.height=GetViewportInfo().H+"px";
			//alert(GetViewportInfo().H)
			break;
			default:
			if(/\d+,{1}\d+/g.test(Position))
			{
				var Left=Position.split(",")[0];
				var Top=Position.split(",")[1];
				Box.style.left=Left+"px";
				Box.style.top=Top+"px";
			}
			break;
		}
		return true;
	}


		
	PopupBox.Alert=function(Width,Content,CallBackFun)
	{
		PopupBox.CreateAutoCoverBox();
		if(PopupBox.AlertBoxHTML==""||PopupBox.AlertBoxHTML==undefined)
			{
				
				RemoveAutoCoverBox();
				alert(Content);
				eval(CallBackFun);
				return false;
			}
		PopupBox.CreatePopup("AlertBox");
		PopupBox.SetInnerHTML("AlertBox",PopupBox.AlertBoxHTML);
		PopupBox.ShowBottom();
		PopupBox.Show("AlertBox",Width,"Center");
		$F("AlertBoxContent").innerHTML=Content;
		$F("AlertBoxOK").onclick=new Function("PopupBox.Remove('AlertBox');"+CallBackFun)
		$F("AlertBoxOK").onKeyup=new Function("if(event.keyCode==13){PopupBox.Remove('AlertBox');"+CallBackFun+"}")
		$F("AlertBoxOK").focus();
		
		
	}
	
	function OnAlertBoxMbokBlur()	
	{
		var Box=$F("AlertBox");
		if(!Box){return false;}
		else
		{
			Box.style.visibility="visible"
			$F("AlertBoxOK").focus();
		}
			
	}
	
	PopupBox.Wait=function(Width,Caption)
	{
		
		
		if(PopupBox.WaitingBoxHTML==""||PopupBox.WaitingBoxHTML==undefined)
			{
				WaitingBoxHTML='<div style="padding:4px;" id="WaitingBoxCaption">请稍后…</div>'
			}
		PopupBox.CreateAutoCoverBox();
		PopupBox.CreatePopup("WaitingBox");
		PopupBox.SetInnerHTML("WaitingBox",PopupBox.WaitingBoxHTML);
		PopupBox.ShowBottom();
		PopupBox.Show("WaitingBox",Width,"Center");
		$F("WaitingBoxCaption").innerHTML=Caption;
		
		
	}
	PopupBox.UnWait=function()
	{
		PopupBox.Remove('WaitingBox');
	}
	PopupBox.CreateAutoCoverBox=function()
	{
		for(A in PopupBox.TopBoxs)
		{
			if(!$F(PopupBox.TopBoxs[A])){return false;}
			
			if(!$F(PopupBox.TopBoxs[A]).Child&&PopupBox.TopBoxs[A]!=="WaitingBox"&&PopupBox.TopBoxs[A]!=="AlertBox")
			{
				
				//if(!$F(PopupBox.TopBoxs[A]).Child||$F($F(PopupBox.TopBoxs[A]).Child).style.display=="none")
				//{
					PopupBox.AutoCoverBox[PopupBox.AutoCoverBox.length]=PopupBox.CreateCoverBox(PopupBox.TopBoxs[A]).id+"";
				//}
				
			}
		}
		
	}
	
	PopupBox.RemoveAutoCoverBox=function()
	{
		while(PopupBox.AutoCoverBox.length>0)
		{
			$F($F(PopupBox.AutoCoverBox[PopupBox.AutoCoverBox.length-1]).Parent).Child=null;
			$F(PopupBox.AutoCoverBox[PopupBox.AutoCoverBox.length-1]).parentNode.removeChild($F(PopupBox.AutoCoverBox[PopupBox.AutoCoverBox.length-1]));
			PopupBox.AutoCoverBox.splice(PopupBox.AutoCoverBox.length-1,1);
			
		}
		
	}

	PopupBox.OnExploreStatusChange=function()
	{
		var BottomBox=$F("BottomPopupBox");
		if(BottomBox&&BottomBox.style.visibility=="visible")
		{
		BottomBox.style.width=Math.max(document.body.scrollWidth,GetViewportInfo().W)-30+"px";
		BottomBox.style.height=Math.max(document.body.scrollHeight,GetViewportInfo().H)+"px";
		}
		try{
		for(var i in PopupBox.TopBoxs)
		{
			//alert($F(PopupBox.TopBoxs[i]).Position);
			if($F(PopupBox.TopBoxs[i]).FitExPlorer+""=="true")
			{
				PopupBox.SetRang(PopupBox.TopBoxs[i],$F(PopupBox.TopBoxs[i]).Position);
				if($F(PopupBox.TopBoxs[i]).Child)
				{
					//alert('hello');
					PopupBox.SetRang($F(PopupBox.TopBoxs[i].Child),$F(PopupBox.TopBoxs[i]).Position);
				}
			}
		}
		
		}
		catch(e)
		{
		}
	}
	
	PopupBox.RemoveAll=function()
	{

		for(A in PopupBox.TopBoxs)
		{
			PopupBox.Remove(PopupBox.TopBoxs[A]);
		}
		return ;
	}
	window.onscroll=new Function("PopupBox.OnExploreStatusChange();")
	window.onresize=new Function("PopupBox.OnExploreStatusChange();")
//PopupBox 定义结束
}