/****************************************************************************************

  ©°©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©´
  ©¦©°©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©´©À©¤©¤ Main Frame (DIV)
  ©¦©¦©°©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©´©¦©¦
  ©¦©¦©¦©°©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©´					 ©°©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©´©¦©À©à©¤©¤ Inner Border(DIV)
  ©¦©¦©¦©¦Caption(DIV)©¦					 ©¦Close Button(DIV)©¦©¦©¦©¦
  ©¦©¦©¦©¸©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¼					 ©¸©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¼©À©à©à©¤©¤ Titlebar(DIV) 
  ©¦©¦©¸©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¼©¦©¦
  ©¦©¦©°©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©´©¦©¦
  ©¦©¦©¦								  				  	©¦©¦©¦
  ©¦©¦©¦											  	  	©¦©¦©¦
  ©¦©¦©¦									 			  	©¦©¦©¦
  ©¦©¦©¦				  								  	©¦©¦©¦
  ©¦©¦©¦								  				  	©¦©¦©¦
  ©¦©¦©¦			Dialog View	(IFRAME Element)		    ©¦©¦©¦
  ©¦©¦©¦				  								  	©¦©¦©¦
  ©¦©¦©¦				  								  	©¦©¦©¦
  ©¦©¦©¦				  								  	©¦©¦©¦
  ©¦©¦©¦											  	  	©¦©¦©¦
  ©¦©¦©¦												    ©¦©¦©¦
  ©¦©¦©¸©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¼©¦©¦
  ©¦©¸©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¼©¦
  ©¸©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¤©¼
  
*****************************************************************************************/

//---------------------------------------------------------------------------------------
//YzDialog Core Class
//---------------------------------------------------------------------------------------
var YzDialog=function(url,caption,width,height,param,onReturn,win)
{
	Yz.instance.add(this);
	
	this.onReturn=onReturn;
	this.url=url;
	this.caption=caption;
	this.clientHeight=height;
	this.clientWidth=width;
	this.height=height+24;
	this.width=width+4;
	this.param=param;
	this.onReturn=onReturn;
	this.returnValue=null;
	this.window=win;
	
	this.titleBarId=this.handle+"_titleBar";
	this.iframeId=this.handle+"_iframe";
	this.closeButtonId=this.handle+"_closeButton";
	this.shadowId=this.handle+"_shadow";
	this.innerBoxId=this.handle+'_innerBox';
	this.loadingBarId=this.handle+'_loadingBar';
}
Yz.dialog=YzDialog;
Yz.dialog.prototype=
{
	getType : function(){return "YzDialog";},
	setSize : function(clientWidth,clientHeight)
	{
		this.clientHeight=clientHeight;
		this.clientWidth=clientWidth;
		this.width=clientWidth+4;
		this.height=clientHeight+24;//titlebar height:24px border height:4px
	},
	show : function()
	{
		var doc=this.window.document;
		//-----------------------------------------------------------------------------
		var frameDiv=doc.getElementById(this.handle);
			frameDiv.style.visibility="visible";
		//-----------------------------------------------------------------------------	
		var ifrm=doc.getElementById(this.iframeId);
			ifrm.src=this.url;
			ifrm.contentWindow.focus();	
		//-----------------------------------------------------------------------------
		//display cover and register Dragbox
			frameDiv.style.zIndex=2+YzDialogCover.show();
			YzDialogDragBox.addRef(this.handle);
		//-----------------------------------------------------------------------------
		//display shadow
		var shadow=doc.getElementById(this.shadowId);
			shadow.style.zIndex=frameDiv.style.zIndex-1;
			
			ifrm.contentWindow.focus();
			frameDiv=null; doc=null; shadow=null;
	},
	loadingComplete : function()
	{
		var dom=this.window.document.getElementById(this.loadingBarId);
			if(dom)
			{
				dom.style.display='none';
				Yz.util.removeNode(dom);
				this.loadingBarId=null;
			}
			
	},
	createLoadingBar : function()
	{
		if(this.hasLoadingBar!=true)return;
		
		var doc=this.window.document;
		var ch=doc.documentElement.clientHeight;
		var cw=doc.documentElement.clientWidth;
		
		var html='<table cellpadding="0" cellspacing="0" width="100%" height="100%"><tr><td align="center"><table><tr><td><div class="dialog_loading"><div class="dialog_loading_mid"><div class="dialog_loading_inner">Loading, please wait a moment ... ...</div></div></div></td></tr></table></td></tr></table>';
		
		var loadingDiv=this.window.document.createElement('DIV');
			loadingDiv.style.position="absolute";
			loadingDiv.style.zIndex=20000;
			loadingDiv.style.left='0';
			loadingDiv.style.top='0';
			loadingDiv.style.width=cw+'px';
			loadingDiv.style.height=ch+'px';
			loadingDiv.style.backgroundColor='';
			loadingDiv.innerHTML=html;
			loadingDiv.id=this.loadingBarId;
			this.window.document.body.appendChild(loadingDiv);
	},
	create : function()
	{		
		var doc=this.window.document;
		
		//1 create a div object as the dialog outer border
		var frameDiv=doc.createElement("div");
			frameDiv.style.left="-2000px";
			frameDiv.style.top="-2000px";
			frameDiv.style.width=this.width-2+"px";
			frameDiv.style.height=this.height-2+"px";
			frameDiv.style.visibility="hidden";
			frameDiv.style.zIndex=1000;
			frameDiv.className="YzDialog_outerBorder";
			frameDiv.id=this.handle;
		
		//2 inner border	
		var divInner=doc.createElement("div");	
			divInner.style.height=this.height-4+"px";
			divInner.style.width=this.width-4+"px";
			divInner.className="YzDialog_innerBorder";
			divInner.id=this.innerBoxId;
		
		//3 title bar
		var divTitlebar=doc.createElement("div");
			divTitlebar.style.width=this.width-4+"px";
			divTitlebar.className="YzDialog_titleBar";
			divTitlebar.id=this.titleBarId;
			
		//4 caption
		var divCaption=doc.createElement("div");
			divCaption.innerHTML=this.caption;
			divCaption.className="YzDialog_caption";
			divTitlebar.appendChild(divCaption);
			
		
		//5 close button
		var divCloseButton=doc.createElement("div");
			divCloseButton.className="YzDialog_closeButton_out";
			divCloseButton.onclick=YzDialog_onclose;
			divCloseButton.onmouseover=YzDialog_closebutton_onmouseover;
			divCloseButton.onmouseout=YzDialog_closebutton_onmouseout;
			divCloseButton.id=this.closeButtonId;
			
			divTitlebar.appendChild(divCloseButton);
			divInner.appendChild(divTitlebar);
				
		//6 a iframe object holder the dialog 		
		var ifrm=doc.createElement('IFRAME');
			ifrm.id				= this.iframeId;
			ifrm.frameBorder	= '0';
			ifrm.scrolling		= 'no' ;
			//ifrm.style.position	= 'absolute';
			ifrm.width 			= this.clientWidth+'px'; 
			ifrm.height 		= this.clientHeight+'px';
			//ifrm.src			= "javascript:'';";
			
			divInner.appendChild(ifrm);	
			frameDiv.appendChild(divInner);
			doc.body.appendChild(frameDiv);
			
			//IMPORTANT, as the outline CSS render delay will cause the scrollbar for top window
			frameDiv.style.position="absolute";
			
			ifrm.dialogHandle=this.handle;

		//7 shadow layer
		var sw=Yz.isIE ? 0 : 16;
		var shadow=doc.createElement("div");
			shadow.className=Yz.isIE ? "YzDialog_shadow" : "YzDialog_shadow_ff";
			shadow.style.display="none";
			shadow.style.width=this.width+sw+"px";
			shadow.style.height=this.height+sw+"px";
			shadow.style.top='-2000px';
			shadow.style.left='-2000px';
			shadow.id=this.shadowId;
			
			if(Yz.isIE==false)
			{
				shadow.innerHTML=''+
				'<div id="'+this.handle+'_FFsd_bl" class="dialog_shadow_bl"></div>'+
				'<div id="'+this.handle+'_FFsd_bc" class="dialog_shadow_bc" style="width:'+(this.width+2-32)+'px;"></div>'+
				'<div id="'+this.handle+'_FFsd_br" class="dialog_shadow_br"></div>'+
				'<div id="'+this.handle+'_FFsd_rc" class="dialog_shadow_rc" style="height:'+(this.height+16-44-49)+'px;"></div>'+
				'<div id="'+this.handle+'_FFsd_rt" class="dialog_shadow_rt"></div>'+
				'<div id="'+this.handle+'_FFsd_rb" class="dialog_shadow_rb"></div>';
			}
			
			doc.body.appendChild(shadow);
			
		//8	loading bar
			this.createLoadingBar();
			
			this.enableDrag();
			
			doc=null; frameDiv=null; divInner=null; divTitlebar=null;	
			divCaption=null; divCloseButton=null; ifrm=null; shadow=null; 
	},
	
	destory : function()
	{
		var doc=this.window.document;
		
		//1 destory iframe object 
		var ifrm=this.window.document.getElementById(this.iframeId);
			ifrm.onreadystatechange=null;
			Yz.util.removeNode(ifrm);
			ifrm=null;
			
		//2 detach close button event£¬and remove node
		var cb=doc.getElementById(this.closeButtonId);
			cb.onclick=null;
			cb.onmouseover=null;
			cb.onmouseout=null;
			Yz.util.removeNode(cb);
			cb=null;	
		
		//3 detach titlebar event and remove the node
		var titleBar=doc.getElementById(this.titleBarId);
			titleBar.onmousedown=null;
			titleBar.onmousemove=null;
			titleBar.onmouseup=null;
			Yz.util.removeNode(titleBar);
			titleBar=null;
			
		//4 remove dialog main div node
		var frameDiv=doc.getElementById(this.handle);	
			Yz.util.removeNode(frameDiv);
			frameDiv=null;
		
		//5 remove shadow layer dom node	
		var sd=doc.getElementById(this.shadowId);	
			Yz.util.removeNode(sd);
			sd=null;
		
		//6 remove loading bar dom object
			if(this.loadingBarId)
			{
				var lbar=doc.getElementById(this.loadingBarId);
					Yz.util.removeNode(lbar);	
					lbar=null;
			}
			
		//7 hide cover mask and unregister dragbox
			YzDialogCover.hide();
			YzDialogDragBox.release();
			
		//8 call dialog return function	
			if(this.onReturn)
			{
				this.onReturn(this.returnValue);
				this.onReturn=null;
			}
			
			Yz.instance.remove(this);
	},
	close : function()
	{
		//1 close dialog page and remove the iframe node
		//  if there is a  function named dispose in the page, will call it
		//  and will close dialog if the function returns true
		var ifrm=this.window.document.getElementById(this.iframeId);
			
			if(ifrm.contentWindow.dispose)
				if(!ifrm.contentWindow.dispose())
					return;
			if(Yz.isIE)
			{
				ifrm.onreadystatechange=onYzDialogIFRAMEUnloaded;
				ifrm.src="javascript:'';";
				//ifrm.src="about:blank";
				//this.destory();
			}
			else
			{
				ifrm.src="javascript: void(0);";
				this.destory();
			}
			ifrm=null;
	},
	getWindowRect : function()
	{
		var frameDiv=this.window.document.getElementById(this.handle);
		var l=frameDiv.style.left,t=frameDiv.style.top;
		var w=frameDiv.style.width,h=frameDiv.style.height;
		var z=frameDiv.style.zIndex;
			frameDiv=null;
			
		return {"left" : l, "top" : t, "width" : w, "height" : h, "zIndex" : z};	
	},
	getClientHeight : function()
	{
		return this.window.document.getElementById(this.iframeId).offsetHeight;
	},
	centerWindow : function()
	{
		var doc=this.window.document;
		var frameDiv=doc.getElementById(this.handle);
		var ch=doc.documentElement.clientHeight;
		var cw=doc.documentElement.clientWidth;
		var	x=(cw-this.width)/2;
		var	y=(ch-this.height)/2+doc.documentElement.scrollTop;
			//frameDiv.style.left=x+'px';
			//frameDiv.style.top =y+'px';
			
			this.moveTo(x,y);
	},
	moveTo : function(x,y)
	{
		x=parseInt(x); y=parseInt(y);
		var frameDiv=this.window.document.getElementById(this.handle);
			frameDiv.style.left=x+"px";
			frameDiv.style.top=y+"px";
			frameDiv=null;
		var sox=Yz.isIE ? -2 : -4;
		var soy=Yz.isIE ? -2 : -7;
		var shadow=this.window.document.getElementById(this.shadowId);
			shadow.style.left=x+sox+"px";
			shadow.style.top=y+soy+"px";
			shadow.style.display='';
			shadow=null;
	},
	resize : function(w,h)
	{
		this.setSize(w,h);

		var frameDiv=this.window.document.getElementById(this.handle);
			frameDiv.style.width=this.width-2+"px";
			frameDiv.style.height=this.height-2+"px";
			
		var ifrm=this.window.document.getElementById(this.iframeId);	
			ifrm.width 			= this.clientWidth+'px'; 
			ifrm.height 		= this.clientHeight+'px';
			
		var divInner=this.window.document.getElementById(this.innerBoxId);	
			divInner.style.height=this.height-4+"px";
			divInner.style.width=this.width-4+"px";
	
		var divTitlebar=this.window.document.getElementById(this.titleBarId);	
			divTitlebar.style.width=this.width-4+"px";
		
		var sw=Yz.isIE ? 0 : 16;
		var shadow=this.window.document.getElementById(this.shadowId);
			shadow.style.width=this.width+sw+"px";
			shadow.style.height=this.height+sw+"px";
			if(Yz.isIE==false)
			{
				shadow.childNodes[1].style.width=this.width+2-32+'px';
				shadow.childNodes[3].style.height=this.height+16-44-49+'px';
			}
			
		this.centerWindow();	
	},
	
	setReturnValue : function(val)
	{
		this.returnValue=val;
	},
	setCaption : function(txt,bAppend)
	{
		if(bAppend)
			this.window.document.getElementById(this.titleBarId).firstChild.innerHTML+=txt;
		else
			this.window.document.getElementById(this.titleBarId).firstChild.innerHTML=txt;
	},
	enableDrag : function()
	{
		var divTitlebar=document.getElementById(this.titleBarId);
		if(Yz.isIE)
			divTitlebar.onmousedown=YzDialog_startDragging;
		else
			enableDragFF(divTitlebar);
	},
	sendMessage : function(msg)
	{
		var ifrm=this.window.document.getElementById(this.iframeId);
		if(ifrm.contentWindow.onMessage)
		{
			ifrm.contentWindow.onMessage.call(this,msg);
		}
		return true;
	}
}
function onYzDialogIFRAMEUnloaded()
{
	if(this.readyState=="complete")
	{
		Yz.util.delay(realDestory,this.id);
	}
}
function realDestory(iframeId)
{
	Yz.dialog.fromHandle(iframeId).destory();
}
//---------------------------------------------------------------------------------------
// Dialog Display Cover
//---------------------------------------------------------------------------------------
var YzDialogCover=
{
	cover : null,
	reference : 0,
	create : function()
	{
		if(this.cover)return;
		var div=window.top.document.createElement("div");
		div.className="YzDialog_cover";
		div.id="YzDialogCover_"+Yz.util.newGuid();
		div.style.left="-2000px";
		div.style.top="-2000px";
		div.style.position='absolute';
		div.style.display='none';
		Yz.util.disableSelection(div);
		window.top.document.body.appendChild(div);
		this.cover=div;
		div=null;
		this.reference=0;
	},
	show : function()
	{
		if(!this.cover)this.create();
			this.reference++;
		
		var ow=window.top.document.body.clientWidth;
		var oh=Math.max(document.documentElement.scrollHeight,document.documentElement.clientHeight,document.documentElement.offsetHeight);
			this.cover.style.left="0";
			this.cover.style.top="0";
			this.cover.style.width=ow+"px";
			this.cover.style.height=oh+"px";
			this.cover.style.display="";
			this.setZIndex();
			
			return parseInt(this.cover.style.zIndex);
	},
	hide : function()
	{
		if(!this.cover)return;
		this.reference--;
		this.setZIndex();
		
		//if there is not any reference to the cover,remove the cover DOM node
		if(this.reference<=0)
		{
			Yz.util.removeNode(this.cover);
			this.cover=null;
			this.reference=0;
		}
	},
	setZIndex : function(zIndex){this.cover.style.zIndex=zIndex || this.reference*1000+1000;}
}

//---------------------------------------------------------------------------------------
// Dialog DragBox
//---------------------------------------------------------------------------------------
var YzDialogDragBox=
{
	referer : [],
	box : null,
	addRef : function(dialogHandle){this.referer.push(dialogHandle);},
	release : function()
	{
		this.referer.pop();
		if(this.referer.length==0 && this.box)
		{
			Yz.util.removeNode(this.box);
			this.box=null;
		}
	},
	create : function()
	{
		if(this.box)return;
		var div=document.createElement("div");
			div.id="YzDialogDragBox_"+Yz.util.newGuid();
			div.className="YzDialog_dragBox";
			document.body.appendChild(div);
			this.box=div;
			div=null;
	},
	show : function(x,y)
	{
		if(!this.box)this.create();
		var dlgInst=Yz.dialog.fromHandle(this.referer[this.referer.length-1]);
		var rect=dlgInst.getWindowRect();
		dlgInst=null;
		
		this.box.style.left=rect.left;
		this.box.style.top=rect.top;
		this.box.style.width=rect.width;
		this.box.style.height=rect.height;
		this.box.style.zIndex=rect.zIndex+1000;
		this.box.style.display="";
		
		YzDialogCover.setZIndex(rect.zIndex+5);
		
		this.startLeft=parseInt(rect.left);
		this.startTop=parseInt(rect.top);
		this.startX=x; this.startY=y;
		
		rect=null;
	},
	hide : function()
	{
		this.box.style.display="none";	
		var	dlgInst=Yz.dialog.fromHandle(this.referer[this.referer.length-1]);
			dlgInst.moveTo(this.box.style.left,this.box.style.top);
			dlgInst=null;
			
			YzDialogCover.setZIndex();
			
	},
	moveTo : function(x,y)
	{
		this.box.style.left=this.startLeft+x-this.startX+"px";
		this.box.style.top=this.startTop+y-this.startY+"px";
	}
}

//---------------------------------------------------------------------------------------
// events
//---------------------------------------------------------------------------------------
//{{{drag and drop
function YzDialog_startDragging()
{
	if(event.srcElement.id.indexOf("_closeButton")>0)return;
	YzDialogDragBox.show(event.x,event.y);
	this.onmousemove=YzDialog_dragging;
	this.onmouseup=YzDialog_stopDragging;
	Yz.util.delay(function(ttb){ttb.setCapture();},this);
}
function YzDialog_dragging(){YzDialogDragBox.moveTo(event.x,event.y);}
function YzDialog_stopDragging()
{
	this.releaseCapture(); 
	this.onmousemove=null;
	this.onmouseup=null;
	YzDialogDragBox.hide();
}
//drag functions in firefox
function enableDragFF(dragHandleElt)
{
	dragHandleElt.onmousedown=function(e)
	{
		//disable drag on close button
		if(e.target.id.indexOf("_closeButton")>0)return;
		window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
		YzDialogDragBox.show(e.screenX,e.screenY);	
		
		window.onmousemove=function(ev)
		{
			YzDialogDragBox.moveTo(ev.screenX,ev.screenY);
		}
		
		window.onmouseup=function()
		{
			window.releaseEvents(Event.MOUSEMOVE|Event.MOUSEUP);
			
			window.onmousemove=null;
			window.onmouseup=null;
			YzDialogDragBox.hide();
		}
	}
}
//}}}
//---------------------------------------------------------------------------------------
function YzDialog_onclose()
{
	var inst=Yz.dialog.fromHandle(this.id);
		if(inst)inst.close();
		inst=null;
}
function YzDialog_closebutton_onmouseover(){this.className=this.className.replace("out","over");}
function YzDialog_closebutton_onmouseout(){this.className=this.className.replace("over","out");}
//---------------------------------------------------------------------------------------

//---------------------------------------------------------------------------------------
// YzDialog Public Interface Static class
//---------------------------------------------------------------------------------------
Yz.dialog.styleAdded=false;
Yz.dialog.fromHandle = function(handle)
{
	handle=handle.replace("_iframe","").replace("_closeButton","");
	return Yz.instance.get(handle);
}
Yz.dialog.show=function(url,caption,onReturn,param)
{
	if(Yz.dialog.styleAdded==false)
	{
		Yz.util.importStyleSheet(document,"__YzDialog.css");
		YzDialog.styleAdded=true;
	}
	
	var dlgInst=new Yz.dialog(url,caption,380,180,param,onReturn,window);
		dlgInst.hasLoadingBar=true;
		dlgInst.create();
		dlgInst.show();
		//dlgInst.centerWindow();
	var handle=dlgInst.handle;	
		dlgInst=null;
	
		return handle;	
}
Yz.dialog.showMessageDialog=function(url,caption,width,height,param,onReturn)
{
	//window object is always the top window,as the YzDialog.js only can be loaded 
	//one time in the top window,other IFRAME window always use the top window's Yz.dialog object
	
	//load css file into the top window
	//-----------------------------------------------------------------------------
	if(Yz.dialog.styleAdded==false)
	{
		Yz.util.importStyleSheet(document,"__YzDialog.css");
		YzDialog.styleAdded=true;
	}
	
	var dlgInst=new Yz.dialog(url,caption,width,height,param,onReturn,window);
		dlgInst.hasLoadingBar=false;
		dlgInst.create();
		dlgInst.show();
	var handle=dlgInst.handle;	
		dlgInst=null;
	
		return handle;	
}
Yz.dialog.close=function(handle){Yz.dialog.fromHandle(handle).close();}
Yz.dialog.setReturnValue=function(handle,val){Yz.dialog.fromHandle(handle).setReturnValue(val);}
Yz.dialog.setCaption=function(handle,txt){Yz.dialog.fromHandle(handle).setCaption(txt);}
Yz.dialog.appendCaption=function(handle,txt){Yz.dialog.fromHandle(handle).setCaption(txt,true);}
Yz.dialog.getClientHeight=function(handle){return Yz.dialog.fromHandle(handle).getClientHeight();}
Yz.dialog.getWindowRect=function(handle){return Yz.dialog.fromHandle(handle).getWindowRect();}
Yz.dialog.moveTo=function(handle,x,y){return Yz.dialog.fromHandle(handle).moveTo(x,y);}
Yz.dialog.centerWindow=function(handle){return Yz.dialog.fromHandle(handle).centerWindow();}
Yz.dialog.resize=function(handle,w,h){return Yz.dialog.fromHandle(handle).resize(w,h);}
Yz.dialog.loadingComplete=function(handle){Yz.dialog.fromHandle(handle).loadingComplete();}

Yz.dialog.sendMessage=function(handle,msg)
{
	Yz.dialog.fromHandle(handle).sendMessage(msg);
}

Yz.dialog.getTextMetrics=function(str)
{
	var s=window.top.document.createElement("div");
		s.style.position="absolute";
		s.style.left="-5000px";
		s.innerHTML=str.replace(/\n/g,"<br/>");
		window.top.document.body.appendChild(s);
		
		w=s.offsetWidth+80;
		h=s.offsetHeight+100;
		
		s.parentNode.removeChild(s);
		s=null;
		
		return {width:w,height:h};
}

Yz.dialog.alert=function(msg,caption,retCallback,w,h)
{
	msg=msg || ""; if(!caption || caption.trim()=="")caption=" Infomation ";
	//w=w || 300; h=h || 150;
	var url="MessageBox.html?t=0";
	var m=Yz.dialog.getTextMetrics(msg);
		w=m.width; h=m.height-26;	
		if(w<250)w=250; if(h<100)h=100;
		
	Yz.dialog.showMessageDialog(url,caption,w,h,msg,retCallback);
};

Yz.dialog.confirm=function(msg,retCallback,caption,w,h)
{
	msg=msg || ""; if(!caption || caption.trim()=="")caption=" Infomation ";
	var url="MessageBox.html?t=1";
	var m=Yz.dialog.getTextMetrics(msg);
		w=m.width; h=m.height-26;	
		if(w<250)w=250; if(h<100)h=100;
		
	Yz.dialog.showMessageDialog(url,caption,w,h,msg,retCallback);
};

Yz.dialog.prompt=function(msg,caption,retCallback,w,h)
{
	msg=msg || ""; if(!caption || caption.trim()=="")caption=" Infomation ";
	w=w || 300; h=h || 150;
	var url="MessageBox.html?t=2";
	Yz.dialog.showMessageDialog(url,caption,w,h,["prompt",msg],retCallback);
};

/*function YzSetTimeout(fn,thisObject,milliseconds,paramArr,win)
{
	if(typeof fn=="function")
	{
		if(typeof milliseconds=="undefined")milliseconds=0;
		var win=arguments[4] || window;
		win.setTimeout(function(){
			if(paramArr)
				fn.apply(thisObject || win,[].concat(paramArr));
			else
				fn.apply(thisObject || win);	
			},
			milliseconds
		);
	}
}*/