
compono.window=new compono.Object("window");compono.window.currentActive={};compono.window.show=function(id,isModal,e,onShow){var base=this.getByID(id);if(onShow&&typeof(onShow)=="function"&&onShow.call(this,base,isModal,e)==false){return false;};this.appendClassName("window-openup",base);var button=this.getByClassName("input","action default",base)
if(button&&button.getAttribute("type")=="submit"){button.focus();}
this.setStorage(base);if(isModal){base.modal=this.setModal(null,null,base);}
this.Event.preventDefault(e);return true;}
compono.window.hide=function(id,e,onHide){var base=this.getByID(id);if(onHide&&typeof(onHide)=="function"&&onHide.call(this,base)==false){return false;};this.removeClassName("window-openup",base);this.setStorage(base);this.removeStorage(base);base.modal=base.modal||this.getByID("ComponoWindowModal");if(base.modal){this.setModal(false,base.modal,base);}
return true;}
compono.window.elementHide=function(node,e){this.hide(node.parentNode.parentNode.parentNode);this.Event.stopPropagation(e);}
compono.window.minimize=function(id,onMinimize){var base=this.getByID(id);if(onMinimize&&typeof(onMinimize)=="function"&&onMinimize.call(this,base)==false){return false;};this.toggleClassName("window-minimized",base);this.setStorage(base);return true;}
compono.window.elementMinimize=function(node,e){this.appendClassName("minimized",node,0);this.minimize(node.parentNode.parentNode.parentNode,e);this.Event.stopPropagation(e);}
compono.window.maximize=function(id,e,onMaximize){var base=this.getByID(id);if(onMaximize&&typeof(onMaximize)=="function"&&onMaximize.call(this,base)==false){return false;};this.removeClassName("window-minimized",base);this.setStorage(base);this.Event.stopPropagation(e);return true;}
compono.window.elementMaximize=function(node,e){this.appendClassName("maximized",node,0);this.maximize(node.parentNode.parentNode.parentNode);}
compono.window.startDrag=function(node,e,onStartDrag){var base=node.parentNode.parentNode;base.content=node.parentNode;if(onStartDrag&&typeof(onStartDrag)=="function"&&onStartDrag.call(this,base)==false){return false;};base.startLeft=(e.clientX)-base.offsetLeft;base.startTop=(e.clientY)-base.offsetTop;this.appendClassName("window-grabbing",base);this.appendClassName("window-grabbing",document.body);this.appendClassName("window-active",base);this.currentActive=base;this.updateDragGhost(base);this.Event.add("mousemove",this.documentDragMovement,document);this.Event.add("mouseup",this.documentStopDrag,document);document.onselectstart=new Function("return false");return true;}
compono.window.documentDragMovement=function(e){if(compono.window.currentActive){compono.window.currentActive.ghost.style.left=((e.clientX||e.pageX)-compono.window.currentActive.startLeft)+"px";compono.window.currentActive.ghost.style.top=((e.clientY||e.pageY)-compono.window.currentActive.startTop)+"px";}}
compono.window.documentStopDrag=function(node,e,onStopDrag){var w=compono.window;var c=w.currentActive;if(onStopDrag&&typeof(onStopDrag)=="function"&&onStopDrag.call(w,c)==false){return false;};c.style.left=(c.ghost.offsetLeft)+"px";c.style.top=(c.ghost.offsetTop<10?10:c.ghost.offsetTop)+"px";w.setStorage(c);w.removeClassName("window-grabbing",c);w.removeClassName("window-grabbing",document.body);w.removeClassName("window-active",c);w.removeClassName("window-ghost-openup",c.ghost);w.Event.remove("mousemove",compono.window.documentDragMovement,document);w.Event.remove("mouseup",compono.window.documentStopDrag,document);return true;}
compono.window.updateDragGhost=function(base){if(!base.ghost){var div=document.createElement("div");div.className="window-ghost";base.ghost=document.body.appendChild(div);}
this.appendClassName("window-ghost-openup",base.ghost);base.ghost.style.top=base.offsetTop+"px";base.ghost.style.left=base.offsetLeft+"px";base.ghost.style.width=base.content.offsetWidth+"px";base.ghost.style.height=base.content.offsetHeight+"px";}
compono.window.setStorage=function(base){if(!base.storage){if(base.getAttribute("persist")=="true"){base.storage=compono.Storage.Cookie.ID(base.id);}else{base.storage=compono.Storage.Hidden.ID(base.id+"_storage");}}
base.storage.set("x",base.offsetLeft);base.storage.set("y",base.offsetTop);base.storage.set("m",(this.hasClassName("window-minimized",base)?1:0));base.storage.set("o",(this.hasClassName("window-openup",base)?1:0));}
compono.window.removeStorage=function(base){if(!base.storage){if(base.getAttribute("persist")=="true"){base.storage=compono.Storage.Cookie.ID(base.id);}else{base.storage=compono.Storage.Hidden.ID(base.id+"_storage");}}
base.storage.remove("x");base.storage.remove("y");base.storage.remove("m");}
compono.window.setModal=function(open,id,base,onSetModal){if(typeof(base)=="string")base=this.getByID(base);var o=this.getByID("ComponoWindowModal")||this.getByID(id);var b=document.documentElement||document.body;if(!o){o=document.createElement("div");b.insertBefore(o,b.firstChild);o.id="WindowModal";o.className="window-modal";}
if(onSetModal&&typeof(onSetModal)=="function"&&onSetModal.call(this,o)==false){return false;};if(open!=false){this.appendClassName("window-modal-openup",o)
this.appendClassName("window-modal",document.body);this.appendClassName("window-modal",document.body.parentNode);b.WindowModalElement=o;this.setModalSize();this.Event.add("keydown",this.documentModalKeyPress,document);if(base){this.Event.add("keydown",this.windowModalKeyPress,base);}
return o;}else{this.removeClassName("window-modal-openup",o)
this.removeClassName("window-modal",document.body);this.removeClassName("window-modal",document.body.parentNode);this.Event.remove("keydown",this.documentModalKeyPress,document);if(base){this.Event.remove("keydown",this.windowModalKeyPress,base);}
return false;}}
compono.window.windowModalKeyPress=function(e){if(!e)e=window.event;compono.Event.stopPropagation(e);}
compono.window.documentModalKeyPress=function(e){if(!e)e=window.event;compono.Event.stopPropagation(e);compono.Event.preventDefault(e);}
compono.window.setModalSize=function(){var b=document.documentElement||document.body;if(b.WindowModalElement){b.WindowModalElement.style.width=(b.scrollWidth)+"px";b.WindowModalElement.style.height=(b.scrollHeight)+"px";}}
compono.window.startResize=function(anchor,e){var base=anchor.parentNode.parentNode;base.content=anchor.parentNode;base.resize=anchor;anchor.startLeft=(e.clientX)-anchor.offsetLeft;anchor.startTop=(e.clientY)-anchor.offsetTop;this.currentActive=base;compono.window.updateDragGhost(base);this.Event.add("mousemove",this.documentResizeMovement,document);this.Event.add("mouseup",this.documentStopResize,document);}
compono.window.documentResizeMovement=function(e){if(compono.window.currentActive){var c=compono.window.currentActive;c.resize.style.left=((e.clientX)-c.offsetLeft)+"px";c.resize.style.top=((e.clientY)-c.offsetTop)+"px";c.ghost.style.width=(c.resize.offsetLeft+c.resize.offsetWidth)+"px";c.ghost.style.height=(c.resize.offsetTop+c.resize.offsetHeight)+"px";}}
compono.window.documentStopResize=function(e){var w=compono.window;var c=compono.window.currentActive;c.content.style.width=(c.ghost.offsetWidth)+"px";c.content.style.height=(c.ghost.offsetHeight)+"px";w.removeClassName("window-ghost-openup",c.ghost);w.Event.remove("mousemove",compono.window.documentResizeMovement,document);w.Event.remove("mouseup",compono.window.documentStopResize,document);}