
function PtInRect(x,y,x0,y0,w0,h0)
{return(x>=x0&&x<=x0+w0&&y>=y0&&y<=y0+h0);}
function RectInRect(x,y,w,h,x0,y0,w0,h0)
{return(x>=x0&&x<=x0+w0&&y>=y0&&y<=y0+h0&&x+w>=x0&&x+w<=x0+w0&&y+h>=y0&&y+h<=y0+h0);}
var NMLAYOUT_MGR_HORIZONTAL=0x0000;var NMLAYOUT_MGR_VERTICAL=0x0010;var NMLAYOUT_MGR_AUTOHIDE=0x1000;var NMLAYOUT_ACTION_FREE=0;var NMLAYOUT_ACTION_MIN=1;var NMLAYOUT_ACTION_MAX=2;var NMLAYOUT_ACTION_TILE=3;var NMLAYOUT_ACTION_DEFAULT=NMLAYOUT_ACTION_TILE;function NMLayoutMgr(name,container,flags,related)
{this.name=name;this.container=container;this.flags=(typeof flags=='undefined')?0:flags;this.vertical=(this.flags&NMLAYOUT_MGR_VERTICAL)!=0;this.related=related;this.ids=new Array();this.comps=new Object();this.len=0;this.x0=0;this.y0=0;this.w0=0;this.h0=0;this.setBounds=function(x,y,w,h)
{this.x0=x;this.y0=y;this.w0=w;this.h0=h;}
this.test=function(obj)
{var ret=false;if(this.inside(obj))
{this.add(obj);ret=true;}
else
this.remove(obj);return ret;}
this.exist=function(obj)
{var ret=this.comps[obj.id];return typeof ret!='undefined';}
this.length=function()
{return this.len;}
this.add=function(obj,nolayout)
{if(!this.exist(obj))
{if(ObjIsHidden(obj))
{return;}
this.comps[obj.id]=obj;this.ids.push(obj.id);this.len++;}
if(!nolayout)
this.layout(obj);};this.remove=function(obj)
{if(this.exist(obj))
{delete this.comps[obj.id];this.ids=ArrayRemove(this.ids,obj.id);this.len--;}
this.layout();};this.allwidth=function()
{var allw=0;for(var i in this.comps)
{if((i in Object.prototype))continue;allw=allw+ObjGetW(this.comps[i]);}
return allw;}
this.allheight=function()
{var allh=0;for(var i in this.comps)
{if((i in Object.prototype))continue;allh=allh+ObjGetH(this.comps[i]);}
return allh;}
this.serialize=Serialize.attach(this,['ids','flags','x0','y0','w0','h0']);this.deserialize=function(strSource)
{Deserialize(this,strSource);for(var i=0;i<this.ids.length;i++)
{this.add(document.getElementById(this.ids[i]));}}
this.load=function()
{}
this.save=function()
{}}
NMLayoutMgr.prototype.getContainerBounds=function()
{if(this.container.boxObject)
{this.x0=this.container.boxObject.x;this.y0=this.container.boxObject.y;this.w0=this.container.boxObject.width;this.h0=this.container.boxObject.height;}else
{this.x0=ObjGetX(this.container);this.y0=ObjGetY(this.container);this.w0=ObjGetW(this.container);this.h0=ObjGetH(this.container);}}
NMLayoutMgr.prototype.inside=function(obj)
{var x=ObjGetX(obj);var y=ObjGetY(obj);var w=ObjGetW(obj);var h=ObjGetH(obj);if(!ObjIsHidden(this.container))
{this.getContainerBounds();}
else
{return false;}
if(PtInRect(x,y,this.x0,this.y0,this.w0,this.h0))
{return true;}
return false;}
NMLayoutMgr.prototype.show=function(isshow)
{if(!isshow)
{ObjDisplay(this.container,false);if(typeof this.related!="undefined")
for(var i in this.related)
{if((i in Object.prototype))continue;ObjDisplay(this.related[i],false);}}else
{ObjDisplay(this.container,true);if(typeof this.related!="undefined")
for(var i in this.related)
{if((i in Object.prototype))continue;ObjDisplay(this.related[i],true);}}}
NMLayoutMgr.prototype.layoutTileH=function(obj,x0,y0,w0,h0)
{var x2=x0;var w2=(w0)/(this.len-1);for(var i in this.comps)
{if((i in Object.prototype))continue;if(this.comps[i]!=obj)
{ObjMoveTo(this.comps[i],x2,y0);ObjResizeTo(this.comps[i],w2,h0);x2=x2+w2;}}}
NMLayoutMgr.prototype.layoutTileV=function(obj,x0,y0,w0,h0)
{var y2=y0;var h2=parseInt((h0)/(this.len-1));for(var i in this.comps)
{if((i in Object.prototype))continue;if(this.comps[i]!=obj)
{ObjMoveTo(this.comps[i],x0,y2);ObjResizeTo(this.comps[i],w0,h2);y2=y2+h2;}}}
NMLayoutMgr.prototype.layoutV=function(obj,action)
{this.getContainerBounds();var x0=this.x0;var y0=this.y0;var w0=this.w0;var h0=this.h0;if(action==NMLAYOUT_ACTION_FREE)
return;else
if(action==NMLAYOUT_ACTION_MAX)
h1=parseInt(h0*3/4);else
if(action==NMLAYOUT_ACTION_MIN)
h1=parseInt(h0*1/4);else
h1=parseInt(h0/this.len);ObjMoveTo(obj,x0,y0);ObjResizeTo(obj,w0,h1);this.layoutTileV(obj,x0,y0+h1,w0,h0-h1);}
NMLayoutMgr.prototype.layoutH=function(obj,action)
{this.getContainerBounds();var x0=this.x0;var y0=this.y0;var w0=this.w0;var h0=this.h0;if(action==NMLAYOUT_ACTION_FREE)
return;else
if(action==NMLAYOUT_ACTION_MAX)
w1=w0*3/4;else
if(action==NMLAYOUT_ACTION_MIN)
w1=w0*1/4;else
w1=w0/this.len;ObjMoveTo(obj,x0,y0);ObjResizeTo(obj,w1,h0);this.layoutTileH(obj,x0+w1,y0,w0-w1,h0);}
NMLayoutMgr.prototype.layout=function(obj,action)
{for(var i in this.comps)
{if((i in Object.prototype))continue;if(ObjIsHidden(this.comps[i]))
{this.remove(this.comps[i]);}}
if(this.len==0)
{if((this.flags&NMLAYOUT_MGR_AUTOHIDE)!=0)
{this.show(false);}
this.save();return;}
this.show(true);if(typeof(obj)=='undefined')
{for(var i in this.comps)
{if((i in Object.prototype))continue;obj=this.comps[i];break;}}
if(typeof(action)=='undefined')
action=NMLAYOUT_ACTION_DEFAULT;var x=ObjGetX(obj);var y=ObjGetY(obj);var w=ObjGetW(obj);var h=ObjGetH(obj);this.getContainerBounds();var x0=this.x0;var y0=this.y0;var w0=this.w0;var h0=this.h0;if(this.len==1)
{ObjMoveTo(obj,x0,y0);ObjResizeTo(obj,w0,h0);}
else if(this.len>1)
{if(this.vertical)
{this.layoutV(obj,action);}else
{this.layoutH(obj,action);}}
this.save();}
debug("layoutmgr.js 1140");