﻿/*!
 * 主  题：《页面弹出窗口》
 * 说  明：用于子页面弹出时的窗口。
 * 功能描述：
 * 1、生成弹出窗口，窗口内包括iframe控件，用于加载实际控制页面；
 * 2、窗口弹出时，生成背景遮罩；
 * 3、窗口最小为宽高100，小于等于100时，宽高值默认为浏览器窗口的百分比；
 *
 *
 * 作  者：宋雷鸣 
 * 开发时间: 2012年12月28日
 */


//弹出窗口的主类
//title:窗口标题
//page:打开的页面
//width:窗口宽度
//height:窗口高度
function PageBox(title,page,width,height)
{
	this.Init(title,page,width,height);
}
//初始化参数
PageBox.prototype.Init=function(title,page,width,height)
{
	title= title!=null && title!="" ? title : "newWinBox";		
	//如果为空，则为浏览器窗口一半宽高
	width= width!=null && width!=0 && width!="" ? Number(width) : $("body").width()/2;	
	height= height!=null &&height!=0 && height!="" ? Number(height) : $("body").height()/2;
	//如果宽高小于100，则默认为浏览器窗口的百分比
	width= width>100 ? Number(width) : $("body").width()* Number(width)/100;	
	height= height>100 ? Number(height) : $("body").height() * Number(height)/100;
	//
	this.Title=title;
	this.Width=width;
	this.Height=height;
	this.Page=page;	
}
//创建窗口，并打开
PageBox.prototype.Open=function(title,page,width,height)
{
	title= title!=null && title!="" ? title : this.Title;
	width= width!=null && width!=0 && width!="" ? Number(width) : this.Width;	
	height= height!=null &&height!=0 && height!="" ? Number(height) : this.Height;
	page= page!=null && page!="" ? page : this.Page;
	this.Init(title,page,width,height);
	//
	this.Mask();
	this.BuildFrame();
	this.BuildTitle();
	this.BuildIFrame();
	//设置拖动
	$("#PageBox").easydrag();
	$("#PageBox").setHandler("PageBoxTitle");
	//完成后触发事件
	this.OnComplete();
}
//生成窗体外框
PageBox.prototype.BuildFrame=function()
{
	$("body").append("<div id=\"PageBox\"></div>");
	var PageBox=$("#PageBox");
	PageBox.css("position","absolute");
	PageBox.css("z-index","20000");
	PageBox.css("width",this.Width);
	PageBox.css("height",this.Height);
	var top=($("body").height()-this.Height)/2;;
	var left=($("body").width()-this.Width)/2;
	PageBox.css("top",top);
	PageBox.css("left",left);	
}
//生成标题栏
PageBox.prototype.BuildTitle=function()
{
	var PageBox=$("#PageBox");
	PageBox.append("<div id=\"PageBoxTitle\"></div>");
	var titbox=$("#PageBoxTitle");
	var tm="<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"";
    tm+="<tr>";
	tm+="<td width=\"25\" height=\"25\">&nbsp;</td>"
	tm+="<td><div id=\"PageBoxTitleTxt\">"+this.Title+"</div></td>";
	tm+="<td width=\"50\" align=\"center\">";
	tm+="<a id=\"PageBoxTitleClose\" href=\"#\">×</a></td>";
	tm+="</tr></table>"
	titbox.append(tm);
	$("#PageBoxTitleClose").click(
			function()
			{
				var t=new window.PageBox();
				t.Close();
				return false;
			}
		)
	
}
//生成页面frame区域
PageBox.prototype.BuildIFrame=function()
{
	var PageBox=$("#PageBox");
	var width=PageBox.width()*0.98;
	var height=PageBox.height()-$("#PageBoxTitle").height()-10;
	var frame="";
	frame+="<iframe src=\""+this.Page+"\" name=\"PageBoxIframe\" id=\"PageBoxIframe\" ";
	frame+="width=\""+width+"\"";
	frame+="height=\""+height+"\"";
	frame+="marginwidth=\"0\"  marginheight=\"0\" align=\"top\" scrolling=\"auto\"";
	frame+="frameborder=\"0\" allowtransparency=\"false\">";
	frame+="</iframe>";	
	PageBox.append(frame);
}
//关闭窗口
PageBox.prototype.Close=function()
{	//清除窗口
	$("#PageBox").remove();
	$("#screenMask").remove();
}
//关闭窗口并刷新当前打开的页面
PageBox.prototype.CloseAndRefresh=function()
{	//清除窗口
	$("#PageBox").remove();
	$("#screenMask").remove();
	//当前处于焦点的面板
	var focusId=new parent.PagePanel().focus();
	var frame=$("#consFame_"+focusId);
	//刷新界面
	var src=frame.attr("src");
	frame.attr("src",src);
}
//生成遮罩层
PageBox.prototype.Mask=function()
{	
	var mask=$("#screenMask");
	mask.remove();
	mask=null
	delete mask;
	var html="<div id=\"screenMask\"/>";
	$("body").append(html);
	mask=$("#screenMask");
	mask.css("position","absolute");
	mask.css("z-index","10000");
	mask.css("width",$("body").width());
	mask.css("height",$("body").height());	
	mask.css("top",0);
	mask.css("left",0);
	mask.css("background-color","#999999");
	mask.css("filter","Alpha(Opacity=60)");
	mask.css("display","block");
	mask.css("-moz-opacity",0.6);
	mask.css("opacity",0.6);
	mask.fadeIn("slow");
}
//当完成后，触发事件
PageBox.prototype.OnComplete=function()
{
	var num=50;
	var p=$("#PageBox");
	//谈入效果
	p.hide();
	p.fadeIn();
	/*由中心扩展效果
	var w=p.width();
	var h=p.height();
	var offset = p.offset();
	var l=offset.left;
	var t=offset.top;
	p.width(w-num);
	p.height(h-num);
	p.css("top",t+num/2);
	p.css("left",l+num/2);
	p.animate({
		width: w,						
		height:h,
		left: l,
		top:t
		},1000);
	*/
}
