/*
 * YUI Extensions 0.33 RC2
 * Copyright(c) 2006, Jack Slocum.
 */


YAHOO.ext.LayoutManager=function(container){YAHOO.ext.LayoutManager.superclass.constructor.call(this);this.el=getEl(container,true);this.id=this.el.id;this.el.addClass('ylayout-container');this.monitorWindowResize=true;this.regions={};this.events={'layout':new YAHOO.util.CustomEvent(),'regionresized':new YAHOO.util.CustomEvent(),'regioncollapsed':new YAHOO.util.CustomEvent(),'regionexpanded':new YAHOO.util.CustomEvent()};this.updating=false;YAHOO.ext.EventManager.onWindowResize(this.onWindowResize,this,true);};YAHOO.extendX(YAHOO.ext.LayoutManager,YAHOO.ext.util.Observable,{isUpdating:function(){return this.updating;},beginUpdate:function(){this.updating=true;},endUpdate:function(noLayout){this.updating=false;if(!noLayout){this.layout();}},layout:function(){},onRegionResized:function(region,newSize){this.fireEvent('regionresized',region,newSize);this.layout();},onRegionCollapsed:function(region){this.fireEvent('regioncollapsed',region);},onRegionExpanded:function(region){this.fireEvent('regionexpanded',region);},getViewSize:function(){var size;if(this.el.dom!=document.body){this.el.beginMeasure();size=this.el.getSize();this.el.endMeasure();}else{size={width:YAHOO.util.Dom.getViewportWidth(),height:YAHOO.util.Dom.getViewportHeight()};}
size.width-=this.el.getBorderWidth('lr')-this.el.getPadding('lr');size.height-=this.el.getBorderWidth('tb')-this.el.getPadding('tb');return size;},getEl:function(){return this.el;},getRegion:function(target){return this.regions[target];},onWindowResize:function(){if(this.monitorWindowResize){this.layout();}}});

YAHOO.ext.LayoutRegion=function(mgr,config,pos){this.mgr=mgr;this.position=pos;var dh=YAHOO.ext.DomHelper;this.el=dh.append(mgr.el.dom,{tag:'div',cls:'ylayout-panel ylayout-panel-'+this.position},true);this.titleEl=dh.append(this.el.dom,{tag:'div',unselectable:'on',cls:'yunselectable ylayout-panel-hd ylayout-title-'+this.position,children:[{tag:'span',cls:'yunselectable ylayout-panel-hd-text',unselectable:'on',html:'&#160;'},{tag:'div',cls:'yunselectable ylayout-panel-hd-tools',unselectable:'on'}]},true);this.titleEl.enableDisplayMode();this.titleTextEl=this.titleEl.dom.firstChild;this.tools=getEl(this.titleEl.dom.childNodes[1],true);this.closeBtn=this.createTool(this.tools.dom,'ylayout-close');this.closeBtn.enableDisplayMode();this.closeBtn.on('click',this.closeClicked,this,true);this.closeBtn.hide();this.bodyEl=dh.append(this.el.dom,{tag:'div',cls:'ylayout-panel-body'},true);this.events={'invalidated':new YAHOO.util.CustomEvent('invalidated'),'visibilitychange':new YAHOO.util.CustomEvent('visibilitychange'),'paneladded':new YAHOO.util.CustomEvent('paneladded'),'panelremoved':new YAHOO.util.CustomEvent('panelremoved'),'collapsed':new YAHOO.util.CustomEvent('collapsed'),'expanded':new YAHOO.util.CustomEvent('expanded'),'panelactivated':new YAHOO.util.CustomEvent('panelactivated'),'resized':new YAHOO.util.CustomEvent('resized')};this.panels=new YAHOO.ext.util.MixedCollection();this.panels.getKey=this.getPanelId.createDelegate(this);this.box=null;this.visible=false;this.collapsed=false;this.hide();this.on('paneladded',this.validateVisibility,this,true);this.on('panelremoved',this.validateVisibility,this,true);this.activePanel=null;this.applyConfig(config);};YAHOO.extendX(YAHOO.ext.LayoutRegion,YAHOO.ext.util.Observable,{getPanelId:function(p){return p.getId();},applyConfig:function(config){if(config.collapsible&&this.position!='center'&&!this.collapsedEl){var dh=YAHOO.ext.DomHelper;this.collapseBtn=this.createTool(this.tools.dom,'ylayout-collapse-'+this.position);this.collapseBtn.mon('click',this.collapse,this,true);this.collapsedEl=dh.append(this.mgr.el.dom,{tag:'div',cls:'ylayout-collapsed ylayout-collapsed-'+this.position,children:[{tag:'div',cls:'ylayout-collapsed-tools'}]},true);if(config.floatable!==false){this.collapsedEl.addClassOnOver('ylayout-collapsed-over');this.collapsedEl.mon('click',this.collapseClick,this,true);}
this.expandBtn=this.createTool(this.collapsedEl.dom.firstChild,'ylayout-expand-'+this.position);this.expandBtn.mon('click',this.expand,this,true);}
if(this.collapseBtn){this.collapseBtn.setVisible(config.collapsible==true);}
this.cmargins=config.cmargins||this.cmargins||(this.position=='west'||this.position=='east'?{top:0,left:2,right:2,bottom:0}:{top:2,left:0,right:0,bottom:2});this.margins=config.margins||this.margins||{top:0,left:0,right:0,bottom:0};this.bottomTabs=config.tabPosition!='top';this.autoScroll=config.autoScroll||false;if(this.autoScroll){this.bodyEl.setStyle('overflow','auto');}else{this.bodyEl.setStyle('overflow','hidden');}
if((!config.titlebar&&!config.title)||config.titlebar===false){this.titleEl.hide();}else{this.titleEl.show();if(config.title){this.titleTextEl.innerHTML=config.title;}}
this.duration=config.duration||.30;this.slideDuration=config.slideDuration||.45;this.config=config;if(config.collapsed){this.collapse(true);}},resizeTo:function(newSize){switch(this.position){case'east':case'west':this.el.setWidth(newSize);this.fireEvent('resized',this,newSize);break;case'north':case'south':this.el.setHeight(newSize);this.fireEvent('resized',this,newSize);break;}},getBox:function(){var b;if(!this.collapsed){b=this.el.getBox(false,true);}else{b=this.collapsedEl.getBox(false,true);}
return b;},getMargins:function(){return this.collapsed?this.cmargins:this.margins;},highlight:function(){this.el.addClass('ylayout-panel-dragover');},unhighlight:function(){this.el.removeClass('ylayout-panel-dragover');},updateBox:function(box){this.box=box;if(!this.collapsed){this.el.dom.style.left=box.x+'px';this.el.dom.style.top=box.y+'px';this.el.setSize(box.width,box.height);var bodyHeight=this.config.titlebar?box.height-(this.titleEl.getHeight()||0):box.height;bodyHeight-=this.el.getBorderWidth('tb');bodyWidth=box.width-this.el.getBorderWidth('rl');this.bodyEl.setHeight(bodyHeight);this.bodyEl.setWidth(bodyWidth);var tabHeight=bodyHeight;if(this.tabs){tabHeight=this.tabs.syncHeight(bodyHeight);if(YAHOO.ext.util.Browser.isIE)this.tabs.el.repaint();}
this.panelSize={width:bodyWidth,height:tabHeight};if(this.activePanel){this.activePanel.setSize(bodyWidth,tabHeight);}}else{this.collapsedEl.dom.style.left=box.x+'px';this.collapsedEl.dom.style.top=box.y+'px';this.collapsedEl.setSize(box.width,box.height);}
if(this.tabs){this.tabs.autoSizeTabs();}},getEl:function(){return this.el;},hide:function(){if(!this.collapsed){this.el.dom.style.left='-2000px';this.el.hide();}else{this.collapsedEl.dom.style.left='-2000px';this.collapsedEl.hide();}
this.visible=false;this.fireEvent('visibilitychange',this,false);},show:function(){if(!this.collapsed){this.el.show();}else{this.collapsedEl.show();}
this.visible=true;this.fireEvent('visibilitychange',this,true);},isVisible:function(){return this.visible;},closeClicked:function(){if(this.activePanel){this.remove(this.activePanel);}},collapseClick:function(e){if(this.isSlid){e.stopPropagation();this.slideIn();}else{e.stopPropagation();this.slideOut();}},collapse:function(skipAnim){if(this.collapsed)return;this.collapsed=true;if(this.split){this.split.el.hide();}
if(this.config.animate&&skipAnim!==true){this.animateCollapse();}else{this.el.setLocation(-20000,-20000);this.el.hide();this.collapsedEl.show();this.fireEvent('collapsed',this);}
this.fireEvent('invalidated',this);},animateCollapse:function(){},expand:function(e,skipAnim){if(e)e.stopPropagation();if(!this.collapsed)return;if(this.isSlid){this.slideIn(this.expand.createDelegate(this));return;}
this.collapsed=false;this.el.show();if(this.config.animate&&skipAnim!==true){this.animateExpand();}else{if(this.split){this.split.el.show();}
this.collapsedEl.setLocation(-2000,-2000);this.collapsedEl.hide();this.fireEvent('invalidated',this);this.fireEvent('expanded',this);}},animateExpand:function(){},initTabs:function(){this.bodyEl.setStyle('overflow','hidden');var ts=new YAHOO.ext.TabPanel(this.bodyEl.dom,this.bottomTabs);this.tabs=ts;ts.resizeTabs=this.config.resizeTabs===true;ts.minTabWidth=this.config.minTabWidth||40;ts.maxTabWidth=this.config.maxTabWidth||250;ts.preferredTabWidth=this.config.preferredTabWidth||150;ts.monitorResize=false;ts.bodyEl.setStyle('overflow',this.config.autoScroll?'auto':'hidden');this.panels.each(this.initPanelAsTab,this);},initPanelAsTab:function(panel){var ti=this.tabs.addTab(panel.getEl().id,panel.getTitle(),null,this.config.closeOnTab&&panel.isClosable());ti.on('activate',function(){this.setActivePanel(panel);},this,true);if(this.config.closeOnTab){ti.on('beforeclose',function(t,e){e.cancel=true;this.remove(panel);},this,true);}
return ti;},updatePanelTitle:function(panel,title){if(this.activePanel==panel){this.updateTitle(title);}
if(this.tabs){this.tabs.getTab(panel.getEl().id).setText(title);}},updateTitle:function(title){if(this.titleTextEl&&!this.config.title){this.titleTextEl.innerHTML=(typeof title!='undefined'&&title.length>0?title:"&#160;");}},setActivePanel:function(panel){panel=this.getPanel(panel);if(this.activePanel&&this.activePanel!=panel){this.activePanel.setActiveState(false);}
this.activePanel=panel;panel.setActiveState(true);if(this.panelSize){panel.setSize(this.panelSize.width,this.panelSize.height);}
this.closeBtn.setVisible(!this.config.closeOnTab&&!this.isSlid&&panel.isClosable());this.updateTitle(panel.getTitle());this.fireEvent('panelactivated',this,panel);},showPanel:function(panel){if(panel=this.getPanel(panel)){if(this.tabs){this.tabs.activate(panel.getEl().id);}else{this.setActivePanel(panel);}}
return panel;},getActivePanel:function(){return this.activePanel;},validateVisibility:function(){if(this.panels.getCount()<1){this.updateTitle('&#160;');this.closeBtn.hide();this.hide();}else{if(!this.isVisible()){this.show();}}},add:function(panel){if(arguments.length>1){for(var i=0,len=arguments.length;i<len;i++){this.add(arguments[i]);}
return null;}
panel.setRegion(this);this.panels.add(panel);if(this.panels.getCount()==1&&!this.config.alwaysShowTabs){this.bodyEl.dom.appendChild(panel.getEl().dom);this.setActivePanel(panel);this.fireEvent('paneladded',this,panel);return panel;}
if(!this.tabs){this.initTabs();}else{this.initPanelAsTab(panel);}
this.tabs.activate(panel.getEl().id);this.fireEvent('paneladded',this,panel);return panel;},hasPanel:function(panel){if(typeof panel=='object'){panel=panel.getId();}
return this.getPanel(panel)?true:false;},hidePanel:function(panel){if(this.tabs&&(panel=this.getPanel(panel))){this.tabs.hideTab(panel.getEl().id);}},unhidePanel:function(panel){if(this.tabs&&(panel=this.getPanel(panel))){this.tabs.unhideTab(panel.getEl().id);}},remove:function(panel,preservePanel){panel=this.getPanel(panel);if(!panel){return null;}
preservePanel=(typeof preservePanel!='undefined'?preservePanel:this.config.preservePanels===true);var panelId=panel.getId();this.panels.removeKey(panelId);if(preservePanel){document.body.appendChild(panel.getEl().dom);}
if(this.tabs){this.tabs.removeTab(panel.getEl().id);}else if(!preservePanel){this.bodyEl.dom.removeChild(panel.getEl().dom);}
if(this.panels.getCount()==1&&this.tabs&&!this.config.alwaysShowTabs){var p=this.panels.first();var tempEl=document.createElement('span');tempEl.appendChild(p.getEl().dom);this.bodyEl.update('');this.bodyEl.dom.appendChild(p.getEl().dom);tempEl=null;this.updateTitle(p.getTitle());this.tabs=null;this.bodyEl.setStyle('overflow',this.config.autoScroll?'auto':'hidden');this.setActivePanel(p);}
panel.setRegion(null);if(this.activePanel==panel){this.activePanel=null;}
if(this.config.autoDestroy!==false&&preservePanel!==true){try{panel.destroy();}catch(e){}}
this.fireEvent('panelremoved',this,panel);return panel;},getTabs:function(){return this.tabs;},getPanel:function(id){if(typeof id=='object'){return id;}
return this.panels.get(id);},getPosition:function(){return this.position;},createTool:function(parentEl,className){var btn=YAHOO.ext.DomHelper.append(parentEl,{tag:'div',cls:'ylayout-tools-button',children:[{tag:'div',cls:'ylayout-tools-button-inner '+className,html:'&#160;'}]},true);btn.on('mouseover',btn.addClass.createDelegate(btn,['ylayout-tools-button-over']));btn.on('mouseout',btn.removeClass.createDelegate(btn,['ylayout-tools-button-over']));return btn;}});

YAHOO.ext.SplitLayoutRegion=function(mgr,config,pos,cursor){this.cursor=cursor;YAHOO.ext.SplitLayoutRegion.superclass.constructor.call(this,mgr,config,pos);if(config.split){this.hide();}};YAHOO.extendX(YAHOO.ext.SplitLayoutRegion,YAHOO.ext.LayoutRegion,{applyConfig:function(config){YAHOO.ext.SplitLayoutRegion.superclass.applyConfig.call(this,config);if(config.split){if(!this.split){var splitEl=YAHOO.ext.DomHelper.append(this.mgr.el.dom,{tag:'div',id:this.el.id+'-split',cls:'ylayout-split ylayout-split-'+this.position,html:'&#160;'});this.split=new YAHOO.ext.SplitBar(splitEl,this.el);this.split.onMoved.subscribe(this.onSplitMove,this,true);this.split.useShim=config.useShim===true;YAHOO.util.Dom.setStyle([this.split.el.dom,this.split.proxy],'cursor',this.cursor);this.split.getMaximumSize=this.getMaxSize.createDelegate(this);}
if(typeof config.minSize!='undefined'){this.split.minSize=config.minSize;}
if(typeof config.maxSize!='undefined'){this.split.maxSize=config.maxSize;}}},getMaxSize:function(){var cmax=this.config.maxSize||10000;var center=this.mgr.getRegion('center');return Math.min(cmax,(this.el.getWidth()+center.getEl().getWidth())-center.getMinWidth());},onSplitMove:function(split,newSize){this.fireEvent('resized',this,newSize);},getSplitBar:function(){return this.split;},hide:function(){if(this.split){this.split.el.setLocation(-2000,-2000);this.split.el.hide();}
YAHOO.ext.SplitLayoutRegion.superclass.hide.call(this);},show:function(){if(this.split){this.split.el.show();}
YAHOO.ext.SplitLayoutRegion.superclass.show.call(this);},beforeSlide:function(){if(YAHOO.ext.util.Browser.isGecko){this.bodyEl.clip();if(this.tabs)this.tabs.bodyEl.clip();if(this.activePanel){this.activePanel.getEl().clip();if(this.activePanel.beforeSlide){this.activePanel.beforeSlide();}}}},afterSlide:function(){if(YAHOO.ext.util.Browser.isGecko){this.bodyEl.unclip();if(this.tabs)this.tabs.bodyEl.unclip();if(this.activePanel){this.activePanel.getEl().unclip();if(this.activePanel.afterSlide){this.activePanel.afterSlide();}}}},slideOut:function(){if(!this.slideEl){this.slideEl=new YAHOO.ext.Actor(YAHOO.ext.DomHelper.append(this.mgr.el.dom,{tag:'div',cls:'ylayout-slider'}));if(this.config.autoHide!==false){var slideInTask=new YAHOO.ext.util.DelayedTask(this.slideIn,this);this.slideEl.mon('mouseout',function(e){var to=e.getRelatedTarget();if(to&&to!=this.slideEl.dom&&!YAHOO.util.Dom.isAncestor(this.slideEl.dom,to)){slideInTask.delay(500);}},this,true);this.slideEl.mon('mouseover',function(e){slideInTask.cancel();},this,true);}}
var sl=this.slideEl,c=this.collapsedEl,cm=this.cmargins;this.isSlid=true;this.snapshot={'left':this.el.getLeft(true),'top':this.el.getTop(true),'colbtn':this.collapseBtn.isVisible(),'closebtn':this.closeBtn.isVisible()};this.collapseBtn.hide();this.closeBtn.hide();this.el.show();this.el.setLeftTop(0,0);sl.startCapture(true);var size;switch(this.position){case'west':sl.setLeft(c.getRight(true));sl.setTop(c.getTop(true));size=this.el.getWidth();break;case'east':sl.setRight(this.mgr.getViewSize().width-c.getLeft(true));sl.setTop(c.getTop(true));size=this.el.getWidth();break;case'north':sl.setLeft(c.getLeft(true));sl.setTop(c.getBottom(true));size=this.el.getHeight();break;case'south':sl.setLeft(c.getLeft(true));sl.setBottom(this.mgr.getViewSize().height-c.getTop(true));size=this.el.getHeight();break;}
sl.dom.appendChild(this.el.dom);YAHOO.util.Event.on(document.body,'click',this.slideInIf,this,true);sl.setSize(this.el.getWidth(),this.el.getHeight());this.beforeSlide();if(this.activePanel){this.activePanel.setSize(this.bodyEl.getWidth(),this.bodyEl.getHeight());}
sl.slideShow(this.getAnchor(),size,this.slideDuration,null,false);sl.play(function(){this.afterSlide();}.createDelegate(this));},slideInIf:function(e){var t=YAHOO.util.Event.getTarget(e);if(!YAHOO.util.Dom.isAncestor(this.el.dom,t)){this.slideIn();}},slideIn:function(callback){if(this.isSlid&&!this.slideEl.playlist.isPlaying()){YAHOO.util.Event.removeListener(document.body,'click',this.slideInIf,this,true);this.slideEl.startCapture(true);this.slideEl.slideHide(this.getAnchor(),this.slideDuration,null);this.beforeSlide();this.slideEl.play(function(){this.isSlid=false;this.el.setPositioning(this.snapshot);this.collapseBtn.setVisible(this.snapshot.colbtn);this.closeBtn.setVisible(this.snapshot.closebtn);this.afterSlide();this.mgr.el.dom.appendChild(this.el.dom);if(typeof callback=='function'){callback();}}.createDelegate(this));}},animateExpand:function(){var em=this.margins,cm=this.cmargins;var c=this.collapsedEl,el=this.el;var direction,distance;switch(this.position){case'west':direction='right';el.setLeft(-(el.getWidth()+(em.right+em.left)));el.setTop(c.getTop(true)-cm.top+em.top);distance=el.getWidth()+(em.right+em.left);break;case'east':direction='left';el.setLeft(this.mgr.getViewSize().width+em.left);el.setTop(c.getTop(true)-cm.top+em.top);distance=el.getWidth()+(em.right+em.left);break;case'north':direction='down';el.setLeft(em.left);el.setTop(-(el.getHeight()+(em.top+em.bottom)));distance=el.getHeight()+(em.top+em.bottom);break;case'south':direction='up';el.setLeft(em.left);el.setTop(this.mgr.getViewSize().height+em.top);distance=el.getHeight()+(em.top+em.bottom);break;}
this.beforeSlide();el.setStyle('z-index','100');el.show();c.setLocation(-2000,-2000);c.hide();el.move(direction,distance,true,this.duration,function(){this.afterSlide();el.setStyle('z-index','');if(this.split){this.split.el.show();}
this.fireEvent('invalidated',this);this.fireEvent('expanded',this);}.createDelegate(this),this.config.easing||YAHOO.util.Easing.easeOut);},animateCollapse:function(){var em=this.margins,cm=this.cmargins;var c=this.collapsedEl,el=this.el;var direction,distance;switch(this.position){case'west':direction='left';distance=el.getWidth()+(em.right+em.left);break;case'east':direction='right';distance=el.getWidth()+(em.right+em.left);break;case'north':direction='up';distance=el.getHeight()+(em.top+em.bottom);break;case'south':direction='down';distance=el.getHeight()+(em.top+em.bottom);break;}
this.el.setStyle('z-index','100');this.beforeSlide();this.el.move(direction,distance,true,this.duration,function(){this.afterSlide();this.el.setStyle('z-index','');this.el.setLocation(-20000,-20000);this.el.hide();this.collapsedEl.show();this.fireEvent('collapsed',this);}.createDelegate(this),YAHOO.util.Easing.easeIn);},getAnchor:function(){switch(this.position){case'west':return'left';case'east':return'right';case'north':return'top';case'south':return'bottom';}}});

YAHOO.ext.BorderLayout=function(container,config){YAHOO.ext.BorderLayout.superclass.constructor.call(this,container);this.factory=config.factory||YAHOO.ext.BorderLayout.RegionFactory;this.hideOnLayout=config.hideOnLayout||false;for(var i=0,len=this.factory.validRegions.length;i<len;i++){var target=this.factory.validRegions[i];if(config[target]){this.addRegion(target,config[target]);}}};YAHOO.extendX(YAHOO.ext.BorderLayout,YAHOO.ext.LayoutManager,{addRegion:function(target,config){if(!this.regions[target]){var r=this.factory.create(target,this,config);this.regions[target]=r;r.on('visibilitychange',this.layout,this,true);r.on('paneladded',this.layout,this,true);r.on('panelremoved',this.layout,this,true);r.on('invalidated',this.layout,this,true);r.on('resized',this.onRegionResized,this,true);r.on('collapsed',this.onRegionCollapsed,this,true);r.on('expanded',this.onRegionExpanded,this,true);}
return this.regions[target];},layout:function(){if(this.updating)return;var size=this.getViewSize();var w=size.width,h=size.height;var centerW=w,centerH=h,centerY=0,centerX=0;var x=0,y=0;var rs=this.regions;var n=rs['north'],s=rs['south'],west=rs['west'],e=rs['east'],c=rs['center'];if(this.hideOnLayout){c.el.setStyle('display','none');}
if(n&&n.isVisible()){var b=n.getBox();var m=n.getMargins();b.width=w-(m.left+m.right);b.x=m.left;b.y=m.top;centerY=b.height+b.y+m.bottom;centerH-=centerY;n.updateBox(this.safeBox(b));}
if(s&&s.isVisible()){var b=s.getBox();var m=s.getMargins();b.width=w-(m.left+m.right);b.x=m.left;var totalHeight=(b.height+m.top+m.bottom);b.y=h-totalHeight+m.top;centerH-=totalHeight;s.updateBox(this.safeBox(b));}
if(west&&west.isVisible()){var b=west.getBox();var m=west.getMargins();b.height=centerH-(m.top+m.bottom);b.x=m.left;b.y=centerY+m.top;var totalWidth=(b.width+m.left+m.right);centerX+=totalWidth;centerW-=totalWidth;west.updateBox(this.safeBox(b));}
if(e&&e.isVisible()){var b=e.getBox();var m=e.getMargins();b.height=centerH-(m.top+m.bottom);var totalWidth=(b.width+m.left+m.right);b.x=w-totalWidth+m.left;b.y=centerY+m.top;centerW-=totalWidth;e.updateBox(this.safeBox(b));}
if(c){var m=c.getMargins();var centerBox={x:centerX+m.left,y:centerY+m.top,width:centerW-(m.left+m.right),height:centerH-(m.top+m.bottom)};if(this.hideOnLayout){c.el.setStyle('display','block');}
c.updateBox(this.safeBox(centerBox));}
this.el.repaint();this.fireEvent('layout',this);},safeBox:function(box){box.width=Math.max(0,box.width);box.height=Math.max(0,box.height);return box;},add:function(target,panel){target=target.toLowerCase();return this.regions[target].add(panel);},remove:function(target,panel){target=target.toLowerCase();return this.regions[target].remove(panel);},findPanel:function(panelId){var rs=this.regions;for(var target in rs){if(typeof rs[target]!='function'){var p=rs[target].getPanel(panelId);if(p){return p;}}}
return null;},showPanel:function(panelId){var rs=this.regions;for(var target in rs){var r=rs[target];if(typeof r!='function'){if(r.hasPanel(panelId)){return r.showPanel(panelId);}}}
return null;},restoreState:function(provider){if(!provider){provider=YAHOO.ext.state.Manager;}
var sm=new YAHOO.ext.LayoutStateManager();sm.init(this,provider);}});YAHOO.ext.BorderLayout.RegionFactory={};YAHOO.ext.BorderLayout.RegionFactory.validRegions=['north','south','east','west','center'];YAHOO.ext.BorderLayout.RegionFactory.create=function(target,mgr,config){target=target.toLowerCase();switch(target){case'north':return new YAHOO.ext.NorthLayoutRegion(mgr,config);case'south':return new YAHOO.ext.SouthLayoutRegion(mgr,config);case'east':return new YAHOO.ext.EastLayoutRegion(mgr,config);case'west':return new YAHOO.ext.WestLayoutRegion(mgr,config);case'center':return new YAHOO.ext.CenterLayoutRegion(mgr,config);}
throw'Layout region "'+target+'" not supported.';};

YAHOO.ext.CenterLayoutRegion=function(mgr,config){YAHOO.ext.CenterLayoutRegion.superclass.constructor.call(this,mgr,config,'center');this.visible=true;this.minWidth=config.minWidth||20;this.minHeight=config.minHeight||20;};YAHOO.extendX(YAHOO.ext.CenterLayoutRegion,YAHOO.ext.LayoutRegion,{hide:function(){},show:function(){},getMinWidth:function(){return this.minWidth;},getMinHeight:function(){return this.minHeight;}});YAHOO.ext.NorthLayoutRegion=function(mgr,config){YAHOO.ext.NorthLayoutRegion.superclass.constructor.call(this,mgr,config,'north','n-resize');if(this.split){this.split.placement=YAHOO.ext.SplitBar.TOP;this.split.orientation=YAHOO.ext.SplitBar.VERTICAL;this.split.el.addClass('ylayout-split-v');}
if(typeof config.initialSize!='undefined'){this.el.setHeight(config.initialSize);}};YAHOO.extendX(YAHOO.ext.NorthLayoutRegion,YAHOO.ext.SplitLayoutRegion,{getBox:function(){if(this.collapsed){return this.collapsedEl.getBox();}
var box=this.el.getBox();if(this.split){box.height+=this.split.el.getHeight();}
return box;},updateBox:function(box){if(this.split&&!this.collapsed){box.height-=this.split.el.getHeight();this.split.el.setLeft(box.x);this.split.el.setTop(box.y+box.height);this.split.el.setWidth(box.width);}
if(this.collapsed){this.el.setWidth(box.width);var bodyWidth=box.width-this.el.getBorderWidth('rl');this.bodyEl.setWidth(bodyWidth);if(this.activePanel&&this.panelSize){this.activePanel.setSize(bodyWidth,this.panelSize.height);}}
YAHOO.ext.NorthLayoutRegion.superclass.updateBox.call(this,box);}});YAHOO.ext.SouthLayoutRegion=function(mgr,config){YAHOO.ext.SouthLayoutRegion.superclass.constructor.call(this,mgr,config,'south','s-resize');if(this.split){this.split.placement=YAHOO.ext.SplitBar.BOTTOM;this.split.orientation=YAHOO.ext.SplitBar.VERTICAL;this.split.el.addClass('ylayout-split-v');}
if(typeof config.initialSize!='undefined'){this.el.setHeight(config.initialSize);}};YAHOO.extendX(YAHOO.ext.SouthLayoutRegion,YAHOO.ext.SplitLayoutRegion,{getBox:function(){if(this.collapsed){return this.collapsedEl.getBox();}
var box=this.el.getBox();if(this.split){var sh=this.split.el.getHeight();box.height+=sh;box.y-=sh;}
return box;},updateBox:function(box){if(this.split&&!this.collapsed){var sh=this.split.el.getHeight();box.height-=sh;box.y+=sh;this.split.el.setLeft(box.x);this.split.el.setTop(box.y-sh);this.split.el.setWidth(box.width);}
if(this.collapsed){this.el.setWidth(box.width);var bodyWidth=box.width-this.el.getBorderWidth('rl');this.bodyEl.setWidth(bodyWidth);if(this.activePanel&&this.panelSize){this.activePanel.setSize(bodyWidth,this.panelSize.height);}}
YAHOO.ext.SouthLayoutRegion.superclass.updateBox.call(this,box);}});YAHOO.ext.EastLayoutRegion=function(mgr,config){YAHOO.ext.EastLayoutRegion.superclass.constructor.call(this,mgr,config,'east','e-resize');if(this.split){this.split.placement=YAHOO.ext.SplitBar.RIGHT;this.split.orientation=YAHOO.ext.SplitBar.HORIZONTAL;this.split.el.addClass('ylayout-split-h');}
if(typeof config.initialSize!='undefined'){this.el.setWidth(config.initialSize);}};YAHOO.extendX(YAHOO.ext.EastLayoutRegion,YAHOO.ext.SplitLayoutRegion,{getBox:function(){if(this.collapsed){return this.collapsedEl.getBox();}
var box=this.el.getBox();if(this.split){var sw=this.split.el.getWidth();box.width+=sw;box.x-=sw;}
return box;},updateBox:function(box){if(this.split&&!this.collapsed){var sw=this.split.el.getWidth();box.width-=sw;this.split.el.setLeft(box.x);this.split.el.setTop(box.y);this.split.el.setHeight(box.height);box.x+=sw;}
if(this.collapsed){this.el.setHeight(box.height);var bodyHeight=this.config.titlebar?box.height-(this.titleEl.getHeight()||0):box.height;bodyHeight-=this.el.getBorderWidth('tb');this.bodyEl.setHeight(bodyHeight);if(this.activePanel&&this.panelSize){this.activePanel.setSize(this.panelSize.width,bodyHeight);}}
YAHOO.ext.EastLayoutRegion.superclass.updateBox.call(this,box);}});YAHOO.ext.WestLayoutRegion=function(mgr,config){YAHOO.ext.WestLayoutRegion.superclass.constructor.call(this,mgr,config,'west','w-resize');if(this.split){this.split.placement=YAHOO.ext.SplitBar.LEFT;this.split.orientation=YAHOO.ext.SplitBar.HORIZONTAL;this.split.el.addClass('ylayout-split-h');}
if(typeof config.initialSize!='undefined'){this.el.setWidth(config.initialSize);}};YAHOO.extendX(YAHOO.ext.WestLayoutRegion,YAHOO.ext.SplitLayoutRegion,{getBox:function(){if(this.collapsed){return this.collapsedEl.getBox();}
var box=this.el.getBox();if(this.split){box.width+=this.split.el.getWidth();}
return box;},updateBox:function(box){if(this.split&&!this.collapsed){var sw=this.split.el.getWidth();box.width-=sw;this.split.el.setLeft(box.x+box.width);this.split.el.setTop(box.y);this.split.el.setHeight(box.height);}
if(this.collapsed){this.el.setHeight(box.height);var bodyHeight=this.config.titlebar?box.height-(this.titleEl.getHeight()||0):box.height;bodyHeight-=this.el.getBorderWidth('tb');this.bodyEl.setHeight(bodyHeight);if(this.activePanel&&this.panelSize){this.activePanel.setSize(this.panelSize.width,bodyHeight);}}
YAHOO.ext.WestLayoutRegion.superclass.updateBox.call(this,box);}});

YAHOO.ext.ContentPanel=function(el,config,content){YAHOO.ext.ContentPanel.superclass.constructor.call(this);this.el=getEl(el,true);if(!this.el&&config&&config.autoCreate){if(typeof config.autoCreate=='object'){if(!config.autoCreate.id){config.autoCreate.id=el;}
this.el=YAHOO.ext.DomHelper.append(document.body,config.autoCreate,true);}else{this.el=YAHOO.ext.DomHelper.append(document.body,{tag:'div',cls:'ylayout-inactive-content',id:el},true);}}
this.closable=false;this.loaded=false;this.active=false;if(typeof config=='string'){this.title=config;}else{YAHOO.ext.util.Config.apply(this,config);}
if(this.resizeEl){this.resizeEl=getEl(this.resizeEl,true);}else{this.resizeEl=this.el;}
this.events={'activate':new YAHOO.util.CustomEvent('activate'),'deactivate':new YAHOO.util.CustomEvent('deactivate')};if(content){this.setContent(content);}};YAHOO.extendX(YAHOO.ext.ContentPanel,YAHOO.ext.util.Observable,{setRegion:function(region){this.region=region;if(region){this.el.replaceClass('ylayout-inactive-content','ylayout-active-content');}else{this.el.replaceClass('ylayout-active-content','ylayout-inactive-content');}},getToolbar:function(){return this.toolbar;},setActiveState:function(active){this.active=active;if(!active){this.fireEvent('deactivate',this);}else{this.fireEvent('activate',this);}},setContent:function(content,loadScripts){this.el.update(content,loadScripts);},getUpdateManager:function(){return this.el.getUpdateManager();},setUrl:function(url,params,loadOnce){if(this.refreshDelegate){this.removeListener('activate',this.refreshDelegate);}
this.refreshDelegate=this._handleRefresh.createDelegate(this,[url,params,loadOnce]);this.on('activate',this._handleRefresh.createDelegate(this,[url,params,loadOnce]));return this.el.getUpdateManager();},_handleRefresh:function(url,params,loadOnce){if(!loadOnce||!this.loaded){var updater=this.el.getUpdateManager();updater.update(url,params,this._setLoaded.createDelegate(this));}},_setLoaded:function(){this.loaded=true;},getId:function(){return this.el.id;},getEl:function(){return this.el;},adjustForComponents:function(width,height){if(this.toolbar){height-=this.toolbar.getEl().getHeight();}
return{'width':width,'height':height};},setSize:function(width,height){if(this.fitToFrame){var size=this.adjustForComponents(width,height);this.resizeEl.setSize(size.width,size.height);}},getTitle:function(){return this.title;},setTitle:function(title){this.title=title;if(this.region){this.region.updatePanelTitle(this,title);}},isClosable:function(){return this.closable;},beforeSlide:function(){this.el.clip();this.resizeEl.clip();},afterSlide:function(){this.el.unclip();this.resizeEl.unclip();},destroy:function(){this.el.removeAllListeners();var tempEl=document.createElement('span');tempEl.appendChild(this.el.dom);tempEl.innerHTML='';this.el=null;}});YAHOO.ext.GridPanel=function(grid,config){this.wrapper=YAHOO.ext.DomHelper.append(document.body,{tag:'div',cls:'ylayout-grid-wrapper ylayout-inactive-content'},true);this.wrapper.dom.appendChild(grid.container.dom);YAHOO.ext.GridPanel.superclass.constructor.call(this,this.wrapper,config);if(this.toolbar){this.toolbar.el.insertBefore(this.wrapper.dom.firstChild);}
grid.monitorWindowResize=false;grid.autoHeight=false;grid.autoWidth=false;this.grid=grid;this.grid.container.replaceClass('ylayout-inactive-content','ylayout-component-panel');};YAHOO.extendX(YAHOO.ext.GridPanel,YAHOO.ext.ContentPanel,{getId:function(){return this.grid.id;},getGrid:function(){return this.grid;},setSize:function(width,height){var grid=this.grid;var size=this.adjustForComponents(width,height);grid.container.setSize(size.width,size.height);grid.autoSize();},beforeSlide:function(){this.grid.getView().wrapEl.clip();},afterSlide:function(){this.grid.getView().wrapEl.unclip();},destroy:function(){this.grid.getView().unplugDataModel(this.grid.getDataModel());this.grid.container.removeAllListeners();YAHOO.ext.GridPanel.superclass.destroy.call(this);}});YAHOO.ext.NestedLayoutPanel=function(layout,config){YAHOO.ext.NestedLayoutPanel.superclass.constructor.call(this,layout.getEl(),config);layout.monitorWindowResize=false;this.layout=layout;this.layout.getEl().addClass('ylayout-nested-layout');};YAHOO.extendX(YAHOO.ext.NestedLayoutPanel,YAHOO.ext.ContentPanel,{setSize:function(width,height){var size=this.adjustForComponents(width,height);this.layout.getEl().setSize(size.width,size.height);this.layout.layout();},getLayout:function(){return this.layout;}});

YAHOO.ext.LayoutStateManager=function(layout){this.state={north:{},south:{},east:{},west:{}};};YAHOO.ext.LayoutStateManager.prototype={init:function(layout,provider){this.provider=provider;var state=provider.get(layout.id+'-layout-state');if(state){var wasUpdating=layout.isUpdating();if(!wasUpdating){layout.beginUpdate();}
for(var key in state){if(typeof state[key]!='function'){var rstate=state[key];var r=layout.getRegion(key);if(r&&rstate){if(rstate.size){r.resizeTo(rstate.size);}
if(rstate.collapsed==true){r.collapse(true);}else{r.expand(null,true);}}}}
if(!wasUpdating){layout.endUpdate();}
this.state=state;}
this.layout=layout;layout.on('regionresized',this.onRegionResized,this,true);layout.on('regioncollapsed',this.onRegionCollapsed,this,true);layout.on('regionexpanded',this.onRegionExpanded,this,true);},storeState:function(){this.provider.set(this.layout.id+'-layout-state',this.state);},onRegionResized:function(region,newSize){this.state[region.getPosition()].size=newSize;this.storeState();},onRegionCollapsed:function(region){this.state[region.getPosition()].collapsed=true;this.storeState();},onRegionExpanded:function(region){this.state[region.getPosition()].collapsed=false;this.storeState();}};
