/*
 * Copyright (c) 2006 Sébastien Gruhier (http://xilinus.com, http://itseb.com)
 * 
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 * 
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 * VERSION 0.99
 */
var Window=Class.create();Window.keepMultiModalWindow=false;Window.prototype={initialize:function(id){this.hasEffectLib=String.prototype.parseColor!=null;this.options=Object.extend({className:"dialog",minWidth:100,minHeight:20,resizable:true,closable:true,minimizable:true,maximizable:true,draggable:true,userData:null,showEffect:(this.hasEffectLib?Effect.Appear:Element.show),hideEffect:(this.hasEffectLib?Effect.Fade:Element.hide),showEffectOptions:{},hideEffectOptions:{},effectOptions:null,parent:document.getElementsByTagName("body").item(0),title:"&nbsp;",url:null,onload:Prototype.emptyFunction,width:200,height:300,opacity:1,recenterAuto:true,wiredDrag:false},arguments[1]||{});if(this.options.effectOptions){Object.extend(this.options.hideEffectOptions,this.options.effectOptions);Object.extend(this.options.showEffectOptions,this.options.effectOptions);}if(this.options.hideEffect==Element.hide){this.options.hideEffect=function(){Element.hide(this.element);if(this.destroyOnClose){this.destroy();}}.bind(this);}this.element=this._createWindow(id);this.eventMouseDown=this._initDrag.bindAsEventListener(this);this.eventMouseUp=this._endDrag.bindAsEventListener(this);this.eventMouseMove=this._updateDrag.bindAsEventListener(this);this.eventOnLoad=this._getWindowBorderSize.bindAsEventListener(this);this.eventMouseDownContent=this.toFront.bindAsEventListener(this);this.eventResize=this._recenter.bindAsEventListener(this);this.topbar=$(this.element.id+"_top");this.bottombar=$(this.element.id+"_bottom");this.content=$(this.element.id+"_content");Event.observe(this.topbar,"mousedown",this.eventMouseDown);Event.observe(this.bottombar,"mousedown",this.eventMouseDown);Event.observe(this.content,"mousedown",this.eventMouseDownContent);Event.observe(window,"load",this.eventOnLoad);Event.observe(window,"resize",this.eventResize);Event.observe(window,"scroll",this.eventResize);if(this.options.draggable){this.bottombar.addClassName("bottom_draggable");this.topbar.addClassName("top_draggable");}if(this.options.resizable){this.sizer=$(this.element.id+"_sizer");Event.observe(this.sizer,"mousedown",this.eventMouseDown);}this.useLeft=null;this.useTop=null;if(arguments[1].left!=null){this.element.setStyle({left:parseFloat(arguments[1].left)+'px'});this.useLeft=true;}if(arguments[1].right!=null){this.element.setStyle({right:parseFloat(arguments[1].right)+'px'});this.useLeft=false;}if(this.useLeft==null){this.element.setStyle({left:"0px"});this.useLeft=true;}if(arguments[1].top!=null){this.element.setStyle({top:parseFloat(arguments[1].top)+'px'});this.useTop=true;}if(arguments[1].bottom!=null){this.element.setStyle({bottom:parseFloat(arguments[1].bottom)+'px'});this.useTop=false;}if(this.useTop==null){this.element.setStyle({top:"0px"});this.useTop=true;}this.storedLocation=null;this.setOpacity(this.options.opacity);if(this.options.zIndex){this.setZIndex(this.options.zIndex);}this.destroyOnClose=false;this._getWindowBorderSize();this.width=this.options.width;this.height=this.options.height;this.visible=false;if(this.width&&this.height){this.setSize(this.options.width,this.options.height);}this.setTitle(this.options.title);Windows.register(this);},destroy:function(){Windows.notify("onDestroy",this);Event.stopObserving(this.topbar,"mousedown",this.eventMouseDown);Event.stopObserving(this.bottombar,"mousedown",this.eventMouseDown);Event.stopObserving(this.content,"mousedown",this.eventMouseDownContent);Event.stopObserving(window,"load",this.eventOnLoad);Event.stopObserving(window,"resize",this.eventResize);Event.stopObserving(window,"scroll",this.eventResize);Event.stopObserving(this.content,"load",this.options.onload);if(this._oldParent){var content=this.getContent();var originalContent=null;for(var i=0;i<content.childNodes.length;i++){originalContent=content.childNodes[i];if(originalContent.nodeType==1){break;}originalContent=null;}if(originalContent){this._oldParent.appendChild(originalContent);}this._oldParent=null;}if(this.sizer){Event.stopObserving(this.sizer,"mousedown",this.eventMouseDown);}if(this.options.url){this.content.src=null;}if(this.iefix){Element.remove(this.iefix);}Element.remove(this.element);Windows.unregister(this);},setDelegate:function(delegate){this.delegate=delegate;},getDelegate:function(){return this.delegate;},getContent:function(){return this.content;},setContent:function(id,autoresize,autoposition){var element=$(id);if(null==element){throw"Unable to find element '"+id+"' in DOM";}this._oldParent=element.parentNode;var d=null;var p=null;if(autoresize){d=Element.getDimensions(element);}if(autoposition){p=Position.cumulativeOffset(element);}var content=this.getContent();content.appendChild(element);element.show();if(autoresize){this.setSize(d.width,d.height);}if(autoposition){this.setLocation(p[1]-this.heightN,p[0]-this.widthW);}},setAjaxContent:function(url,options,showCentered,showModal){this.showFunction=showCentered?"showCenter":"show";this.showModal=showModal||false;if(options==null){options={};}this.onComplete=options.onComplete;options.onComplete=this._setAjaxContent.bind(this);new Ajax.Request(url,options);},_setAjaxContent:function(originalRequest){Element.update(this.getContent(),originalRequest.responseText);if(this.onComplete){this.onComplete(originalRequest);}this[this.showFunction](this.showModal);},setCookie:function(name,expires,path,domain,secure){name=name||this.element.id;this.cookie=[name,expires,path,domain,secure];var value=WindowUtilities.getCookie(name);if(value){var values=value.split(',');var x=values[0].split(':');var y=values[1].split(':');var w=parseFloat(values[2]),h=parseFloat(values[3]);var mini=values[4];var maxi=values[5];this.setSize(w,h);if(mini=="true"){this.doMinimize=true;}else if(maxi=="true"){this.doMaximize=true;}this.useLeft=x[0]=="l";this.useTop=y[0]=="t";this.element.setStyle(this.useLeft?{left:x[1]}:{right:x[1]});this.element.setStyle(this.useTop?{top:y[1]}:{bottom:y[1]});}},getId:function(){return this.element.id;},setDestroyOnClose:function(){var destroyFunc=this.destroy.bind(this);if(this.options.hideEffectOptions.afterFinish){var func=this.options.hideEffectOptions.afterFinish;this.options.hideEffectOptions.afterFinish=function(){func();destroyFunc();};}else{this.options.hideEffectOptions.afterFinish=function(){destroyFunc();};}this.destroyOnClose=true;},_initDrag:function(event){this.pointer=[Event.pointerX(event),Event.pointerY(event)];if(this.options.wiredDrag){this.currentDrag=this._createWiredElement();}else{this.currentDrag=this.element;}if(Event.element(event)==this.sizer){this.doResize=true;this.widthOrg=this.width;this.heightOrg=this.height;this.bottomOrg=parseFloat(this.element.getStyle('bottom'));this.rightOrg=parseFloat(this.element.getStyle('right'));Windows.notify("onStartResize",this);}else{this.doResize=false;var closeButton=$(this.getId()+'_close');if(closeButton&&Position.within(closeButton,this.pointer[0],this.pointer[1])){this.currentDrag=null;return;}this.toFront();if(!this.options.draggable){return;}Windows.notify("onStartMove",this);}Event.observe(document,"mouseup",this.eventMouseUp,false);Event.observe(document,"mousemove",this.eventMouseMove,false);WindowUtilities.disableScreen('__invisible__','__invisible__');document.body.ondrag=function(){return false;};document.body.onselectstart=function(){return false;};this.currentDrag.show();Event.stop(event);},_updateDrag:function(event){var pointer=[Event.pointerX(event),Event.pointerY(event)];var dx=pointer[0]-this.pointer[0];var dy=pointer[1]-this.pointer[1];if(this.doResize){this.setSize(this.widthOrg+dx,this.heightOrg+dy);dx=this.width-this.widthOrg;dy=this.height-this.heightOrg;if(!this.useLeft){this.currentDrag.setStyle({right:(this.rightOrg-dx)+'px'});}if(!this.useTop){this.currentDrag.setStyle({bottom:(this.bottomOrg-dy)+'px'});}}else{this.pointer=pointer;if(this.useLeft){this.currentDrag.setStyle({left:parseFloat(this.currentDrag.getStyle('left'))+dx+'px'});}else{this.currentDrag.setStyle({right:parseFloat(this.currentDrag.getStyle('right'))-dx+'px'});}if(this.useTop){this.currentDrag.setStyle({top:parseFloat(this.currentDrag.getStyle('top'))+dy+'px'});}else{this.currentDrag.setStyle({bottom:parseFloat(this.currentDrag.getStyle('bottom'))-dy+'px'});}}if(this.iefix){this._fixIEOverlapping();}this._removeStoreLocation();Event.stop(event);},_endDrag:function(event){WindowUtilities.enableScreen('__invisible__');if(this.doResize){Windows.notify("onEndResize",this);}else{Windows.notify("onEndMove",this);}Event.stopObserving(document,"mouseup",this.eventMouseUp,false);Event.stopObserving(document,"mousemove",this.eventMouseMove,false);Event.stop(event);this._hideWiredElement();this._saveCookie();document.body.ondrag=null;document.body.onselectstart=null;},_createWindow:function(id){var className=this.options.className;var win=document.createElement("div");win.setAttribute('id',id);win.className="dialog";var content;if(this.options.url){content="<iframe frameborder=\"0\" name=\""+id+"_content\"	id=\""+id+"_content\" src=\""+this.options.url+"\"> </iframe>";}else{content="<div id=\""+id+"_content\" class=\""+className+"_content\"> </div>";}var closeDiv=this.options.closable?"<div class='"+className+"_close' id='"+id+"_close' onclick='Windows.close(\""+id+"\", event)'> </div>":"";var minDiv=this.options.minimizable?"<div class='"+className+"_minimize' id='"+id+"_minimize' onclick='Windows.minimize(\""+id+"\", event)'> </div>":"";var maxDiv=this.options.maximizable?"<div class='"+className+"_maximize' id='"+id+"_maximize' onclick='Windows.maximize(\""+id+"\", event)'> </div>":"";var seAttributes=this.options.resizable?"class='"+className+"_sizer' id='"+id+"_sizer'":"class='"+className+"_se'";win.innerHTML=closeDiv+minDiv+maxDiv+""+"<table id='"+id+"_row1' class=\"top table_window\">"+"<tr>"+"<td class='"+className+"_nw'>&nbsp;</td>"+"<td class='"+className+"_n'>"+"<div id='"+id+"_top' class='"+className+"_title title_window'>"+this.options.title+"</div></td>"+"<td class='"+className+"_ne'>&nbsp;</td>"+"</tr>"+"</table>"+"<table id='"+id+"_row2' class=\"mid table_window\">"+"<tr>"+"<td class='"+className+"_w'></td>"+"<td id='"+id+"_table_content' class='"+className+"_content' valign='top'>"+content+"</td>"+"<td class='"+className+"_e'></td>"+"</tr>"+"</table>"+"<table id='"+id+"_row3' class=\"bot table_window\">"+"<tr>"+"<td class='"+className+"_sw'>&nbsp;</td>"+"<td class='"+className+"_s'><div id='"+id+"_bottom' class='status_bar'>&nbsp;</div></td>"+"<td "+seAttributes+">&nbsp;</td>"+"</tr>"+"</table>";Element.hide(win);this.options.parent.insertBefore(win,this.options.parent.firstChild);Event.observe($(id+"_content"),"load",this.options.onload);return win;},setLocation:function(top,left){if(top<0){top=0;}if(left<0){left=0;}this.element.setStyle({top:top+'px'});this.element.setStyle({left:left+'px'});this.useLeft=true;this.useTop=true;},getLocation:function(){var location={};if(this.useTop){location=Object.extend(location,{top:this.element.getStyle("top")});}else{location=Object.extend(location,{bottom:this.element.getStyle("bottom")});}if(this.useLeft){location=Object.extend(location,{left:this.element.getStyle("left")});}else{location=Object.extend(location,{right:this.element.getStyle("right")});}return location;},getSize:function(){return{width:this.width,height:this.height};},setSize:function(width,height){width=parseFloat(width);height=parseFloat(height);if(width<this.options.minWidth){width=this.options.minWidth;}if(height<this.options.minHeight){height=this.options.minHeight;}if(this.options.maxHeight&&height>this.options.maxHeight){height=this.options.maxHeight;}if(this.options.maxWidth&&width>this.options.maxWidth){width=this.options.maxWidth;}this.width=width;this.height=height;var e=this.currentDrag?this.currentDrag:this.element;e.setStyle({width:width+this.widthW+this.widthE+"px"});e.setStyle({height:height+this.heightN+this.heightS+"px"});if(!this.currentDrag||this.currentDrag==this.element){var content=$(this.element.id+'_content');content.setStyle({height:height+'px'});content.setStyle({width:width+'px'});}},updateHeight:function(){this.setSize(this.width,this.content.scrollHeight);},updateWidth:function(){this.setSize(this.content.scrollWidth,this.height);},toFront:function(){if(Windows.focusedWindow==this){return;}this.setZIndex(Windows.maxZIndex+20);Windows.notify("onFocus",this);},show:function(modal){if(modal){Windows.addModalWindow(this);this.modal=true;this.setZIndex(Windows.maxZIndex+20);Windows.unsetOverflow(this);}if(this.oldStyle){this.getContent().setStyle({overflow:this.oldStyle});}if(!this.width||!this.height){var size=WindowUtilities._computeSize(this.content.innerHTML,this.content.id,this.width,this.height,0);if(this.height){this.width=size+5;}else{this.height=size+5;}}this.setSize(this.width,this.height);if(this.centered){this._center(this.centerTop,this.centerLeft);}if(this.options.showEffect!=Element.show&&this.options.showEffectOptions){this.options.showEffect(this.element,this.options.showEffectOptions);}else{this.options.showEffect(this.element);}this._checkIEOverlapping();this.visible=true;WindowUtilities.focusedWindow=this;Windows.notify("onShow",this);},showCenter:function(modal,top,left){this.centered=true;this.centerTop=top;this.centerLeft=left;this.show(modal);},isVisible:function(){return this.visible;},_center:function(top,left){var windowScroll=WindowUtilities.getWindowScroll();var pageSize=WindowUtilities.getPageSize();if(!top){top=(pageSize.windowHeight-(this.height+this.heightN+this.heightS))/2;}top+=windowScroll.top;if(!left){left=(pageSize.windowWidth-(this.width+this.widthW+this.widthE))/2;}left+=windowScroll.left;this.setLocation(top,left);this.toFront();},_recenter:function(event){if(this.modal&&this.centered){var pageSize=WindowUtilities.getPageSize();if(this.pageSize&&this.pageSize.pageWidth==pageSize.windowWidth&&this.pageSize.pageHeight==pageSize.windowHeight){return;}this.pageSize=pageSize;if($('overlay_modal')){$('overlay_modal').style.height=(pageSize.pageHeight+'px');$('overlay_modal').style.width=(pageSize.pageWidth+'px');}if(this.options.recenterAuto){this._center(this.centerTop,this.centerLeft);}}},hide:function(){this.visible=false;if(this.modal){Windows.removeModalWindow(this);Windows.resetOverflow();}this.oldStyle=this.getContent().getStyle('overflow')||"auto";this.getContent().setStyle({overflow:"hidden"});this.options.hideEffect(this.element,this.options.hideEffectOptions);if(this.iefix){this.iefix.hide();}Windows.notify("onHide",this);},minimize:function(){var r2=$(this.getId()+"_row2");var dh=r2.getDimensions().height;if(r2.visible()){var h=this.element.getHeight()-dh;r2.hide();this.element.setStyle({height:h+"px"});if(!this.useTop){var bottom=parseFloat(this.element.getStyle('bottom'));this.element.setStyle({bottom:(bottom+dh)+'px'});}}else{var h=this.element.getHeight()+dh;this.element.setStyle({height:h+"px"});if(!this.useTop){var bottom=parseFloat(this.element.getStyle('bottom'));this.element.setStyle({bottom:(bottom-dh)+'px'});}r2.show();this.toFront();}Windows.notify("onMinimize",this);this._saveCookie();},maximize:function(){if(this.storedLocation!=null){this._restoreLocation();if(this.iefix){this.iefix.hide();}}else{this._storeLocation();Windows.unsetOverflow(this);var windowScroll=WindowUtilities.getWindowScroll();var pageSize=WindowUtilities.getPageSize();this.element.setStyle(this.useLeft?{left:windowScroll.left}:{right:windowScroll.left});this.element.setStyle(this.useTop?{top:windowScroll.top}:{bottom:windowScroll.top});this.setSize(pageSize.windowWidth-this.widthW-this.widthE,pageSize.windowHeight-this.heightN-this.heightS);this.toFront();if(this.iefix){this._fixIEOverlapping();}}Windows.notify("onMaximize",this);this._saveCookie();},isMinimized:function(){var r2=$(this.getId()+"_row2");return!r2.visible();},isMaximized:function(){return(this.storedLocation!=null);},setOpacity:function(opacity){if(Element.setOpacity){Element.setOpacity(this.element,opacity);}},setZIndex:function(zindex){this.element.setStyle({zIndex:zindex});Windows.updateZindex(zindex,this);},setTitle:function(newTitle){if(!newTitle||newTitle==""){newTitle="&nbsp;";}Element.update(this.element.id+'_top',newTitle);},setStatusBar:function(element){var statusBar=$(this.getId()+"_bottom");if(typeof(element)=="object"){if(this.bottombar.firstChild){this.bottombar.replaceChild(element,this.bottombar.firstChild);}else{this.bottombar.appendChild(element);}}else{this.bottombar.innerHTML=element;}},_checkIEOverlapping:function(){if(!this.iefix&&(navigator.appVersion.indexOf('MSIE')>0)&&(navigator.userAgent.indexOf('Opera')<0)&&(this.element.getStyle('position')=='absolute')){new Insertion.After(this.element.id,'<iframe id="'+this.element.id+'_iefix" '+'style="display:none;position:absolute;filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0);" '+'src="javascript:false;" frameborder="0" scrolling="no"></iframe>');this.iefix=$(this.element.id+'_iefix');}if(this.iefix){setTimeout(this._fixIEOverlapping.bind(this),50);}},_fixIEOverlapping:function(){Position.clone(this.element,this.iefix);this.iefix.style.zIndex=this.element.style.zIndex-1;this.iefix.show();},_getWindowBorderSize:function(event){var div=this._createHiddenDiv(this.options.className+"_n");this.heightN=Element.getDimensions(div).height;div.parentNode.removeChild(div);var div=this._createHiddenDiv(this.options.className+"_s");this.heightS=Element.getDimensions(div).height;div.parentNode.removeChild(div);var div=this._createHiddenDiv(this.options.className+"_e");this.widthE=Element.getDimensions(div).width;div.parentNode.removeChild(div);var div=this._createHiddenDiv(this.options.className+"_w");this.widthW=Element.getDimensions(div).width;div.parentNode.removeChild(div);if(isIE){this.heightS=$(this.getId()+"_row3").getDimensions().height;this.heightN=$(this.getId()+"_row1").getDimensions().height;}if(!BrowserInfo.isWebKit){if(/Konqueror|Safari|KHTML/.test(navigator.userAgent)){this.setSize(this.width,this.height);}if(this.doMaximize){this.maximize();}if(this.doMinimize){this.minimize();}}},_createHiddenDiv:function(className){var objBody=document.getElementsByTagName("body").item(0);var win=document.createElement("div");win.setAttribute('id',this.element.id+"_tmp");win.className=className;win.style.display='none';win.innerHTML='';objBody.insertBefore(win,objBody.firstChild);return win;},_storeLocation:function(){if(this.storedLocation==null){this.storedLocation={useTop:this.useTop,useLeft:this.useLeft,top:this.element.getStyle('top'),bottom:this.element.getStyle('bottom'),left:this.element.getStyle('left'),right:this.element.getStyle('right'),width:this.width,height:this.height};}},_restoreLocation:function(){if(this.storedLocation!=null){this.useLeft=this.storedLocation.useLeft;this.useTop=this.storedLocation.useTop;this.element.setStyle(this.useLeft?{left:this.storedLocation.left}:{right:this.storedLocation.right});this.element.setStyle(this.useTop?{top:this.storedLocation.top}:{bottom:this.storedLocation.bottom});this.setSize(this.storedLocation.width,this.storedLocation.height);Windows.resetOverflow();this._removeStoreLocation();}},_removeStoreLocation:function(){this.storedLocation=null;},_saveCookie:function(){if(this.cookie){var value="";if(this.useLeft){value+="l:"+(this.storedLocation?this.storedLocation.left:this.element.getStyle('left'));}else{value+="r:"+(this.storedLocation?this.storedLocation.right:this.element.getStyle('right'));}if(this.useTop){value+=",t:"+(this.storedLocation?this.storedLocation.top:this.element.getStyle('top'));}else{value+=",b:"+(this.storedLocation?this.storedLocation.bottom:this.element.getStyle('bottom'));}value+=","+(this.storedLocation?this.storedLocation.width:this.width);value+=","+(this.storedLocation?this.storedLocation.height:this.height);value+=","+this.isMinimized();value+=","+this.isMaximized();WindowUtilities.setCookie(value,this.cookie);}},_createWiredElement:function(){if(!this.wiredElement){if(isIE){this._getWindowBorderSize();}var div=document.createElement("div");div.className="wired_frame "+this.options.className+"_wired_frame";div.style.position='absolute';document.body.insertBefore(div,document.body.firstChild);div=$(div);var dim=this.element.getDimensions();div.setStyle({width:dim.width+"px",height:dim.height+"px"});if(this.useLeft){div.setStyle({left:this.element.getStyle('left')});}else{div.setStyle({right:this.element.getStyle('right')});}if(this.useTop){div.setStyle({top:this.element.getStyle('top')});}else{div.setStyle({bottom:this.element.getStyle('bottom')});}this.wiredElement=div;}this.wiredElement.setStyle({zIndex:Windows.maxZIndex+30});return this.wiredElement;},_hideWiredElement:function(){if(this.currentDrag==this.element){this.currentDrag=null;}else{if(this.useLeft){this.element.setStyle({left:this.currentDrag.getStyle('left')});}else{this.element.setStyle({right:this.currentDrag.getStyle('right')});}if(this.useTop){this.element.setStyle({top:this.currentDrag.getStyle('top')});}else{this.element.setStyle({bottom:this.currentDrag.getStyle('bottom')});}this.currentDrag.hide();this.currentDrag=null;this.setSize(this.width,this.height);}}};var Windows={windows:[],modalWindows:[],observers:[],focusedWindow:null,maxZIndex:0,addObserver:function(observer){this.removeObserver(observer);this.observers.push(observer);},removeObserver:function(observer){this.observers=this.observers.reject(function(o){return o==observer;});},notify:function(eventName,win){this.observers.each(function(o){if(o[eventName]){o[eventName](eventName,win);}});},getWindow:function(id){return this.windows.detect(function(d){return d.getId()==id;});},getFocusedWindow:function(){return this.focusedWindow;},register:function(win){this.windows.push(win);},addModalWindow:function(win){if(this.modalWindows.length==0){WindowUtilities.disableScreen(win.options.className,'overlay_modal',win.getId());}else{if(Window.keepMultiModalWindow){$('overlay_modal').style.zIndex=Windows.maxZIndex+20;Windows.maxZIndex+=20;WindowUtilities._hideSelect(this.modalWindows.last().getId());}else{this.modalWindows.last().element.hide();}WindowUtilities._showSelect(win.getId());}this.modalWindows.push(win);},removeModalWindow:function(win){this.modalWindows.pop();if(this.modalWindows.length==0){WindowUtilities.enableScreen();}else{if(Window.keepMultiModalWindow){this.modalWindows.last().toFront();WindowUtilities._showSelect(this.modalWindows.last().getId());}else{this.modalWindows.last().element.show();}}},register:function(win){this.windows.push(win);},unregister:function(win){this.windows=this.windows.reject(function(d){return d==win;});},close:function(id,event){var win=this.getWindow(id);if(win&&win.visible){if(win.getDelegate()&&!win.getDelegate().canClose(win)){return;}this.focusedWindow=this.windows.length>=2?this.windows[this.windows.length-2]:null;this.notify("onClose",win);win.hide();}if(event){Event.stop(event);}},closeAll:function(){this.windows.each(function(w){Windows.close(w.getId());});},closeAllModalWindows:function(){WindowUtilities.enableScreen();this.modalWindows.each(function(win){win.hide();});},minimize:function(id,event){var win=this.getWindow(id);if(win&&win.visible){win.minimize();}Event.stop(event);},maximize:function(id,event){var win=this.getWindow(id);if(win&&win.visible){win.maximize();}Event.stop(event);},unsetOverflow:function(except){this.windows.each(function(d){d.oldOverflow=d.getContent().getStyle("overflow")||"auto";d.getContent().setStyle({overflow:"hidden"});});if(except&&except.oldOverflow){except.getContent().setStyle({overflow:except.oldOverflow});}},resetOverflow:function(){this.windows.each(function(d){if(d.oldOverflow){d.getContent().setStyle({overflow:d.oldOverflow});}});},updateZindex:function(zindex,win){if(zindex>this.maxZIndex){this.maxZIndex=zindex;}this.focusedWindow=win;}};var isIE=navigator.appVersion.match(/MSIE/)=="MSIE";var WindowUtilities={getWindowScroll:function(){var w=window;var T,L,W,H;with(w.document){if(w.document.documentElement&&documentElement.scrollTop){T=documentElement.scrollTop;L=documentElement.scrollLeft;}else if(w.document.body){T=body.scrollTop;L=body.scrollLeft;}if(w.innerWidth){W=w.innerWidth;H=w.innerHeight;}else if(w.document.documentElement&&documentElement.clientWidth){W=documentElement.clientWidth;H=documentElement.clientHeight;}else{W=body.offsetWidth;H=body.offsetHeight;}}return{top:T,left:L,width:W,height:H};},getPageSize:function(){var xScroll,yScroll;if(window.innerHeight&&window.scrollMaxY){xScroll=document.body.scrollWidth;yScroll=window.innerHeight+window.scrollMaxY;}else if(document.body.scrollHeight>document.body.offsetHeight){xScroll=document.body.scrollWidth;yScroll=document.body.scrollHeight;}else{xScroll=document.body.offsetWidth;yScroll=document.body.offsetHeight;}var windowWidth,windowHeight;if(self.innerHeight){windowWidth=self.innerWidth;windowHeight=self.innerHeight;}else if(document.documentElement&&document.documentElement.clientHeight){windowWidth=document.documentElement.clientWidth;windowHeight=document.documentElement.clientHeight;}else if(document.body){windowWidth=document.body.clientWidth;windowHeight=document.body.clientHeight;}var pageHeight,pageWidth;if(yScroll<windowHeight){pageHeight=windowHeight;}else{pageHeight=yScroll;}if(xScroll<windowWidth){pageWidth=windowWidth;}else{pageWidth=xScroll;}return{pageWidth:pageWidth,pageHeight:pageHeight,windowWidth:windowWidth,windowHeight:windowHeight};},disableScreen:function(className,overlayId,contentId){WindowUtilities.initLightbox(overlayId,className);var objBody=document.getElementsByTagName("body").item(0);var objOverlay=$(overlayId);var pageSize=WindowUtilities.getPageSize();objOverlay.style.height=(pageSize.pageHeight+'px');objOverlay.style.width=(pageSize.windowWidth+'px');objOverlay.style.display='block';},enableScreen:function(id){id=id||'overlay_modal';var objOverlay=$(id);if(objOverlay){objOverlay.style.display='none';if(id!="__invisible__"){WindowUtilities._showSelect();}objOverlay.parentNode.removeChild(objOverlay);}},_hideSelect:function(id){if(isIE){id=id==null?"":"#"+id+" ";$$(id+'select').each(function(element){if(!WindowUtilities.isDefined(element.oldVisibility)){element.oldVisibility=element.style.visibility?element.style.visibility:"visible";element.style.visibility="hidden";}});}},_showSelect:function(id){if(isIE){id=id==null?"":"#"+id+" ";$$(id+'select').each(function(element){if(WindowUtilities.isDefined(element.oldVisibility)){try{element.style.visibility=element.oldVisibility;}catch(e){element.style.visibility="visible";}element.oldVisibility=null;}else{if(element.style.visibility){element.style.visibility="visible";}}});}},isDefined:function(object){return typeof(object)!="undefined"&&object!=null;},initLightbox:function(id,className){if($(id)){Element.setStyle(id,{zIndex:Windows.maxZIndex+10});}else{var objBody=document.getElementsByTagName("body").item(0);var objOverlay=document.createElement("div");objOverlay.setAttribute('id',id);objOverlay.className="overlay_"+className;objOverlay.style.display='none';objOverlay.style.position='absolute';objOverlay.style.top='0';objOverlay.style.left='0';objOverlay.style.zIndex=Windows.maxZIndex+10;objOverlay.style.width='100%';objBody.insertBefore(objOverlay,objBody.firstChild);}},setCookie:function(value,parameters){document.cookie=parameters[0]+"="+escape(value)+((parameters[1])?"; expires="+parameters[1].toGMTString():"")+((parameters[2])?"; path="+parameters[2]:"")+((parameters[3])?"; domain="+parameters[3]:"")+((parameters[4])?"; secure":"");},getCookie:function(name){var dc=document.cookie;var prefix=name+"=";var begin=dc.indexOf("; "+prefix);if(begin==-1){begin=dc.indexOf(prefix);if(begin!=0){return null;}}else{begin+=2;}var end=document.cookie.indexOf(";",begin);if(end==-1){end=dc.length;}return unescape(dc.substring(begin+prefix.length,end));},_computeSize:function(content,id,width,height,margin){if(margin==null){margin=5;}var objBody=document.getElementsByTagName("body").item(0);var tmpObj=document.createElement("div");tmpObj.setAttribute('id',id);if(height){tmpObj.style.height=height+"px";}else{tmpObj.style.width=width+"px";}tmpObj.style.position='absolute';tmpObj.style.top='0';tmpObj.style.left='0';tmpObj.style.display='none';tmpObj.innerHTML=content;objBody.insertBefore(tmpObj,objBody.firstChild);var size;if(height){size=$(id).getDimensions().width+margin;}else{size=$(id).getDimensions().height+margin;}objBody.removeChild(tmpObj);return size;}};