var WJAeroplane=Class.create({initialize:function(){this.menu=null;this.contextmenu=null;this.spinErrorHandlers={};this.windowmanager=new WJWindowManager();this.unloadmanager=new WJUnloadManager(this.allowUnload.bind(this));this.topbarId="aeroplane_topbar";this.contentId="aeroplane_main";this.contentClass="aeroplane_sitemaincontent";this.contentBlockContainers={};this.dbtables={};this.layers=[];},aeroplaneSpinError:function(response,lastSpin){for(code in this.spinErrorHandlers){if(code==response.status&&typeof(this.spinErrorHandlers[code])=="function"){this.spinErrorHandlers[code](response,lastSpin);return;}}
var reload=function(){this.unloadmanager.suspend();document.location.reload();}.bind(this);WJWindow.alert("Er heeft zich een fout voorgedaan, Windmill CMS zal automatisch worden herladen. Neem contact op met Connectholland wanneer dit probleem zich blijft voordoen.",reload);},registerSpinErrorHandler:function(code,callback){this.spinErrorHandlers[code]=callback;},addMainMenuItem:function(id,menu){if(this.menu==null){this.menu=new WJMenu("main",-1);}
this.menu.addItem(id,menu);},addMenuItem:function(mainid,id,menu){this.menu.getItem(mainid).addItem(id,menu);},openApplication:function(application){var applicationInterface=window["WJ"+application+"Interface"].construct(arguments);this.windowmanager.startApplication(applicationInterface);return applicationInterface;},createTopBar:function(){var bodyChildren=Element.extend(document.body).childElements();var topbarDiv=document.body.appendChild(new Element("div",{id:this.topbarId}));var mainDiv=document.body.appendChild(new Element("div",{"class":this.contentClass,id:this.contentId}));for(i=0;i<bodyChildren.length;i++){if(bodyChildren[i].tagName!="script"){mainDiv.appendChild(bodyChildren[i]);}}},printPage:function(){window.print();},showTopBar:function(temporaryid){document.body.setStyle({"overflow":"hidden"});Element.extend(document.documentElement).setStyle({"overflow":"hidden"});var tempTop=document.getElementById(temporaryid);var topbar=document.getElementById(this.topbarId);topbar.innerHTML=tempTop.innerHTML;topbar.className=tempTop.className;tempTop.parentNode.removeChild(tempTop);var fixMainDivHeight=function(mainDiv,topbar){$(mainDiv).setStyle({"height":($(document).viewport.getHeight()-$(topbar).getHeight())+"px"});}.bind(window,this.getContentElement(),this.getTopbar());Event.observe(window,"resize",fixMainDivHeight);fixMainDivHeight();},getContentElement:function(){return document.getElementById(this.contentId);},getTopbar:function(){return document.getElementById(this.topbarId);},registerContentBlock:function(id,cbcid,identifier,module,basemodule,properties){var properties=properties||{};var cblock=new WJContentBlock(id,module,properties);cblock.setIdentifier(identifier);this.contentBlockContainers[cbcid].registerContentBlock(cblock);},registerDBTable:function(htmlid,module,collection){this.dbtables[htmlid]=new WJDBTable(htmlid,module,collection);},registerContentBlockContainer:function(id,identifier,module,basemodule,properties){var properties=properties||{};var cbc=new WJContentBlockContainer(id,identifier,module,properties);this.contentBlockContainers[identifier]=cbc;},editContentBlock:function(cbcid,blockid){WJDebugger.log(WJDebugger.NOTICE,"Edit content block",cbcid,blockid);var contentBlock=this.getContentBlock(cbcid,blockid);if(contentBlock){var application=this.openApplication(contentBlock.getApplicationName(),contentBlock.getModule(),contentBlock.getIdentifier(),contentBlock.getProperties());this.contentBlockContainers[cbcid].registerUpdate(blockid);application.setCBC(this.contentBlockContainers[cbcid]);application.setReloadCallback(this.contentBlockContainers[cbcid].callUpdateCallbacks.bind(this.contentBlockContainers[cbcid]));}},getCBCs:function(module){var cbcs=new Array();for(var key in this.contentBlockContainers){if(this.contentBlockContainers[key].getModule()==module){cbcs.push(this.contentBlockContainers[key]);}}
return cbcs;},getContentBlock:function(cbcid,blockid){return(this.contentBlockContainers[cbcid])?this.contentBlockContainers[cbcid].getContentBlock(blockid):false;},isContentBlock:function(cbcid,blockid){return(this.contentBlockContainers[cbcid]&&this.contentBlockContainers[cbcid].getContentBlock(blockid));},contextMenu:function(cbcid,blockid,action){if(blockid=="dbtable"){switch(action){case"update":this.dbtables[cbcid].openContentEditor();break;case"delete":this.dbtables[cbcid].deleteRecord();break;}}
else{switch(action){case"update":this.editContentBlock(cbcid,blockid);break;case"delete":this.deleteContentBlock(cbcid,blockid);break;case"online":this.setContentBlockOnline(true,cbcid,blockid);break;case"offline":this.setContentBlockOnline(false,cbcid,blockid);break;case"moveUp":case"moveDown":this.contentBlockFunction(action,cbcid,blockid);break;}}},contentBlockFunction:function(action,cbcid,blockid){var spin=new WJSpin();var contentBlock=this.getContentBlock(cbcid,blockid);var contentBlockContainer=this.contentBlockContainers[cbcid];spin.update(new WJUrl({"ct":"wmdynamic","module":"Wmcb","collections":contentBlock.properties.collection}),"Wmcb",action,{objid:contentBlock.getIdentifier()},[contentBlock.postActionHandler.bind(contentBlock,action),contentBlockContainer.postActionHandler.bind(contentBlockContainer,contentBlock,action)]);},deleteContentBlock:function(cbcid,blockid){WJWindow.booleanConfirm("Weet je zeker dat je dit contentblok wilt verwijderen?",function(cbcid,blockid,window,e,confirm){if(!confirm){return;}
var spin=new WJSpin();var contentBlock=this.getContentBlock(cbcid,blockid);var cbcon=this.contentBlockContainers[cbcid];spin.update(new WJUrl({"ct":"wmdynamic","module":"Wmcb","collections":contentBlock.properties.collection}),"Wmcb","delete",{objid:contentBlock.getIdentifier()},[contentBlock.removeContextMenu.bind(contentBlock),contentBlock.getElement().remove.bind(contentBlock.getElement()),cbcon.refreshContextMenuButtons.bind(cbcon)]);}.bind(this,cbcid,blockid));},setContentBlockOnline:function(online,cbcid,blockid){var spin=new WJSpin();var contentBlock=this.getContentBlock(cbcid,blockid);var func=online?"online":"offline";var message=online?"Het contentblock staat nu online":"Het contentblock staat nu offline";var updateClassname=online?function(){this.removeClassName("offline");}.bind(contentBlock.getElement()):function(){this.addClassName("offline");}.bind(contentBlock.getElement());spin.update(new WJUrl({"ct":"wmdynamic","module":"Wmcb","collections":contentBlock.properties.collection}),"Wmcb",func,{objid:contentBlock.getIdentifier()},[WJWindow.notice.bind(WJWindow,message),updateClassname]);},registerContextMenu:function(menuid,cbcid,blockid){if(!this.contextmenu){this.contextmenu=new WJContextMenu();}
this.contextmenu.register(menuid,cbcid,blockid);},registerDBTableContextMenu:function(menuid,htmlid,id){if(!this.contextmenu){this.contextmenu=new WJContextMenu();}
this.contextmenu.registerDBTable(menuid,htmlid,id);},hideAllContextMenus:function(){this.contextmenu.hideAll();},logout:function(logouturl){if(logouturl==null){document.location.href="/?useraction=logout";}
else{document.location.href=logouturl;}},loadingCursor:function(loading,wjwindow,callback){var wjwindow=wjwindow||false;var callback=callback||false;if(wjwindow){wjwindow.setLoading(loading,callback);}
if(loading){this.layers.push(new WJModalLayer());$(document.body).setStyle({"cursor":"wait"});$$(".aeroplane_button").each(function(s){$(s).setStyle({"cursor":"wait"});});$$(".dijitTab").each(function(s){$(s).setStyle({"cursor":"wait"});});}
else{this.layers.each(function(l){l.destroy();});this.layers=[];$(document.body).setStyle({"cursor":"auto"});$$(".aeroplane_button").each(function(s){$(s).setStyle({"cursor":"default"});});$$(".dijitTab").each(function(s){$(s).setStyle({"cursor":"pointer"});});}},respinMain:function(callback){var callback=Object.isFunction(callback)?callback:function(){};var baseUrl=document.location.href.replace("#","");var url=(baseUrl.indexOf("?")==-1)?baseUrl+"?wmtrigger[]=requestufts&wmtrigger[]=spin":baseUrl+"&wmtrigger[]=requestufts&wmtrigger[]=spin";url=(url.indexOf("dt=")==-1)?url+"&dt=default":url;var spin=new WJSpin();if(!$("aeroplane_main")){aeroplane.loadingCursor(false);return;}
spin.content(new WJUrl({},url),[function(response){var newcontent=response.documentElement.getElementsByTagName("body")[0];if(document.importNode){var stub=new Element("div");stub.appendChild($("aeroplane_main").ownerDocument.importNode(newcontent,true));stub.innerHTML+="";var newdoc=stub.firstDescendant();var origdoc=$("aeroplane_main");for(var i=0;i<origdoc.childNodes.length;i++){if((origdoc.childNodes[i].nodeName==newdoc.nodeName)&&(origdoc.childNodes[i].className==newdoc.className)){$(origdoc.childNodes[i]).update(newdoc);}}}
else{var origdoc=$("aeroplane_main");for(var i=0;i<origdoc.childNodes.length;i++){if((origdoc.childNodes[i].nodeName==newcontent.nodeName)&&(origdoc.childNodes[i].className==newcontent.className)){$(origdoc.childNodes[i]).update(newcontent);}}
origdoc.innerHTML=origdoc.innerHTML;}
aeroplane.loadingCursor(false);},callback]);},allowUnload:function(){var apps=this.windowmanager.getRunningApplication();for(var i=0;i<apps.length;i++){if(!apps[i].readonly){return false;}}
return true;}});var WJWindowManager=Class.create({initialize:function(){this.applications=new Array();this.windows={};this.applicationRunner.bind(this).repeat(0.25);this.applicationRun=false;this.pid=0;dojo.require("dojo.parser");},getMaxZIndex:function(){var nodes=$$(".");var lenght=nodes.lenght;var z=0;for(var i=0;i<lenght;i++){z=Math.max(z,nodes[i].getStyle("z-index"));}
return z;},startApplication:function(application){this.pid++;application.setPid(this.pid);var pid=application.getPid();this.windows["application"+pid]={};this.applications.push(application);application.wakeUp();},applicationRunner:function(){if(!this.applicationRun){this.applicationRun=true;for(var i=0;i<this.applications.length;i++){this.applications[i].wakeUp();}
for(var i=0;i<this.applications.length;i++){if(this.applications[i].closed()){this.closeApplication(this.applications[i],i);}}
this.cleanUpDijitWidgets();this.applicationRun=false;}},getRunningApplication:function(){return this.applications;},cleanUpDijitWidgets:function(){dijit.registry.forEach(function(widget){if(!$(widget.domNode).descendantOf(widget.domNode.ownerDocument.documentElement)){WJDebugger.log(WJDebugger.INFO,"Destroying dijit widget",widget);widget.destroyRecursive(false);}});},closeApplication:function(application,index){var wjwindow=this.getMainWindow(application);wjwindow.hide();this.applications.splice(index,1);},destroyMainWindow:function(application){WJDebugger.log(WJDebugger.INFO,"Destroy main window",this);this.getMainWindow(application).destroy();},getMainWindow:function(application){return this.getWindow(application,"main");},applicationResponse:function(application,wjwindow,event){WJDebugger.log(WJDebugger.NOTICE,"Application response",application,wjwindow,event);switch(event.eventName){case"wjgui:save":application.save();break;case"wjgui:close":case"wjgui:false":case"wjgui:cancel":application.close();break;default:var eventName=event.eventName.sub("wjgui:","");application.handleWindowEvent(eventName);break;}},getWindow:function(application,type){var pid=application.getPid();if(this.windows["application"+pid]){if(this.windows["application"+pid][type]){return this.windows["application"+pid][type];}}
if(type=="main"){this.windows["application"+pid][type]=application.createMainWindow();}
else{this.windows["application"+pid][type]=application.createWindow(type);}
return this.windows["application"+pid][type];},getMainWindowWidth:function(){return(document.viewport.getWidth()-(this.getMainWindowLeft()+this.getMainWindowRight()));},getMainWindowHeight:function(){return(document.viewport.getHeight()-(this.getMainWindowTop()+this.getMainWindowBottom()));},getMainWindowTop:function(){if(aeroplane.menu){return 42;}
else{return 2;}},getMainWindowBottom:function(){return 2;},getMainWindowLeft:function(){return 5;},getMainWindowRight:function(){return 5;},maximize:function(window){window.maximize(this.getMainWindowTop(),this.getMainWindowRight(),this.getMainWindowBottom(),this.getMainWindowLeft());}});var WJApplicationInterface=Class.create({initialize:function(appname){this.spin=new WJSpin();this.url=new WJUrl({},"/index.php");this.url.setCt("wmdynamic");this.url.addParameter("application",appname);this.appname=appname;this.state="starting";this.pid=null;this.readonly=false;},handleDatacollector:function(datacollector){var factory=new WJDatacollectorFactory();this.datacollector=factory.importDatacollector(datacollector);if(this.datacollector.fields.aeroplaneprofile){this.aeroplaneprofile=new WJAeroplaneprofile(this.datacollector.fields.aeroplaneprofile.getValue(),this);}
WJDebugger.log(WJDebugger.INFO,"Imported datacollector",this.datacollector);if(!this.gui){this.gui=this.buildGui();}
this._loadDatacollectorGui();},_loadDatacollectorGui:function(){this.gui.setDatacollector(this.datacollector);this.gui.addButtons(aeroplane.windowmanager.getMainWindow(this));WJDebugger.log(WJDebugger.DEBUG,"Load content into",this.currentComponent);this.currentComponent.update("");aeroplane.windowmanager.cleanUpDijitWidgets();this.gui.show(aeroplane.windowmanager.getMainWindow(this),this.currentComponent,this.spin,this.contentUpdated.bind(this));},setReloadCallback:function(callback){this.reloadCallback=callback;},buildGui:function(){return new WJGui(this);},fillDatacollector:function(){WJDebugger.log(WJDebugger.INFO,"Fill datacollector",this,this.gui,this.datacollector);this.gui.fillDatacollector(this.datacollector);if(!this.datacollector.valid()){}},closed:function(){return(this.state=="closed");},wakeUp:function(){WJDebugger.log(WJDebugger.DEBUG,"Application wakeup",this,this.state);switch(this.state){case"starting":this.startApplication();break;case"running":this.pingApplication();break;case"waiting":this.testTimeout();break;case"busy":this.handleBusy();break;case"crashed":this.reportCrash();break;case"closing":WJDebugger.log(WJDebugger.DEBUG,"Go cleanup application",this);this.cleanUp();break;case"closed":break;}},setPid:function(pid){this.pid=pid;},getPid:function(){return this.pid;},createMainWindow:function(){var window=new WJWindow(aeroplane.windowmanager.applicationResponse.bind(aeroplane.windowmanager,this));window.getWindowElement().addClassName("aeroplane_window_applicationwindow").addClassName("aeroplane_window_applicationwindow_"+this.appname.toLowerCase());window.setTitle(this.getWindowTitle());aeroplane.windowmanager.maximize(window);window.hide();return window;},getWindowTitle:function(){return"";},close:function(){WJDebugger.log(WJDebugger.NOTICE,"Requesting application close",this);this.wakeUp();this.state="closing";},startApplication:function(){if(this.pid==null){throw"Trying to start an application without a pid";}
this.currentComponent=aeroplane.windowmanager.getMainWindow(this).getContentElement("main");this.updateContent();},createWindow:function(type){var wjwindow=new WJWindow();wjwindow.setWidth(aeroplane.windowmanager.getMainWindowWidth());wjwindow.setHeight(aeroplane.windowmanager.getMainWindowHeight());wjwindow.setX(aeroplane.windowmanager.getMainWindowLeft());wjwindow.setY(aeroplane.windowmanager.getMainWindowTop());return wjwindow;},updateContent:function(){this.url.addParameter("state",this.state);this.url.addParameter("type","json");this.url.addParameter("mode","datacollector");this.spin.content(this.url,[this.handleDatacollector.bind(this)]);this.url.deleteParameter("type");this.url.deleteParameter("mode");this.state="waiting";},contentUpdated:function(){WJDebugger.log(WJDebugger.DEBUG,"Content updated",this);this.state="running";var loaderWnd=aeroplane.windowmanager.getWindow(this,"Loader");loaderWnd.destroy.bind(loaderWnd).delay(2.1);aeroplane.windowmanager.getMainWindow(this).evalContentElement("main");},pingApplication:function(){},testTimeout:function(){},handleBusy:function(){},reportCrash:function(){},cleanUp:function(){WJDebugger.log(WJDebugger.NOTICE,"Cleaning up application",this);aeroplane.windowmanager.destroyMainWindow(this);aeroplane.loadingCursor(false);this.state="closed";},handleWindowEvent:function(eventName){}});var WJGui=Class.create({initialize:function(application){WJDebugger.log(WJDebugger.INFO,"create gui for datacollector");this.application=application;this._initComponentMap();this.loadingCallback=false;WJDebugger.log(WJDebugger.INFO,"finished creating gui",this);},setDatacollector:function(datacollector){this.components=this.createComponents(datacollector);this.postProcesComponents();WJDebugger.log(WJDebugger.INFO,"finished creating components",this);},_initComponentMap:function(){this.componentMap={WMAddress:window["WJText"],WMArray:window["WJCheckbox"],WMBoolean:window["WJRadio"],WMConstant:window["WJComponent"],WMDate:window["WJDate"],WMEnumeration:window["WJSelect"],WMEmailAddress:window["WJText"],WMFile:window["WJFile"],WMFloat:window["WJText"],WMImage:window["WJImage"],WMFlash:window["WJFlash"],WMFlashVideo:window["WJFlashVideo"],WMInteger:window["WJText"],WMPassword:window["WJPassword"],WMPostalCode:window["WJText"],WMString:window["WJText"],WMRichString:window["WJRichtext"],WMPhonenumber:window["WJText"],WMTime:window["WJTime"],WMCompositeDatatype:window["WJGroup"],WMList:window["WJList"],WMPointer:window["WJTab"],WMContentblockPointer:window["WJHtml"],WMTagCloud:window["WJTagCloud"]};},postProcesComponents:function(){},groupComponents:function(groupName,groupLabel,fieldNames,fieldTypes,components,group,region){WJDebugger.log(WJDebugger.INFO,"grouping",arguments);var fieldNames=fieldNames||[];var fieldTypes=fieldTypes||[];var newComponents=new Array();var length=components.components.length;for(var i=0;i<length;i++){var grouped=false;if(fieldNames.indexOf(components.components[i].id)!=-1||fieldTypes.indexOf(components.components[i].componentType)!=-1){if(group==null){WJDebugger.log(WJDebugger.NOTICE,"Creating group",groupName);group=new WJGroup(groupName);var label=new WJLabel(groupName+"_label",groupLabel);group.setLabel(label);if(region){group.setRegion(region);}
newComponents.push(group);}
WJDebugger.log(WJDebugger.NOTICE,"Adding component to group",group,components.components[i],fieldNames);group.addComponent(components.components[i]);grouped=true;}
else if(components.components[i].components){group=this.groupComponents(groupName,groupLabel,fieldNames,fieldTypes,components.components[i],group,region);}
if(!grouped){newComponents.push(components.components[i]);}}
components.components=newComponents;return group;},getOrderedFields:function(datacollector){return $H(datacollector.fields).keys();},createComponents:function(datacollector){var comp=this.getComponent(datacollector);var fieldNames=this.getOrderedFields(datacollector).without("aeroplaneprofile");for(var i=0;i<fieldNames.length;i++){if(!Object.isArray(comp.components)){comp.components=new Array();}
comp.components.push(this.createComponents(datacollector.fields[fieldNames[i]]));}
WJDebugger.log(WJDebugger.INFO,"Completed component",datacollector,comp,comp.components);return comp;},fillDatacollector:function(datacollector){if(datacollector.getName){var component=this.getComponentForField(datacollector.getName());if(component){datacollector.setValue(component.getValue());}}
if(datacollector.fields){for(var key in datacollector.fields){this.fillDatacollector(datacollector.fields[key]);}}},getComponentForField:function(name,component){var component=component||this.components;for(var cmp in component){if(cmp=="id"){if(component[cmp]==name){return component;}
else if(component[cmp]==name.substr(0,(name.length-("_"+this.application.pid).length))){return component;}}
if(cmp=="component"){WJDebugger.log(WJDebugger.INFO,"Recurse into component",name,component,cmp)
if(component[cmp]){var comp=this.getComponentForField(name,component[cmp]);if(comp){return comp;}}}
if(cmp=="components"){for(var i=0;i<$A(component[cmp]).length;i++){WJDebugger.log(WJDebugger.INFO,"Recurse into components",name,component,cmp,component[cmp][i]);if(component[cmp][i]){var comp=this.getComponentForField(name,component[cmp][i]);if(comp){return comp;}}}}}},createComponent:function(datacollector){if(this.componentMap[datacollector.getDatatype()]){return new this.componentMap[datacollector.getDatatype()](datacollector.getName());}
else{WJDebugger.log(WJDebugger.WARNING,"No component defined for "+datacollector.getDatatype()+", falling back on WJComponent");return new WJComponent(datacollector.getName());}},getComponent:function(datacollector){var component={};if(datacollector.getDatatype){var component=this.createComponent(datacollector);component.initComponent(datacollector,this);var label=new WJLabel(datacollector.getName()+"_label");label.text=datacollector.getUfName();component.setLabel(label);}
return component;},show:function(wjwindow,elem,spin,finished,url){if(!url){var url=new WJUrl({},"/index.php");url.setCt(this.getCt());url.setDt(this.getDt());url.addParameter("mode","gui");url.addParameter("uft[]",this.getUfts());url.addParameter("wmtrigger[]",["requestufts"]);url.addParameter("components",$H(this.components).toJSON());url.addParameter("pid",this.application.getPid());WJDebugger.log(WJDebugger.DEBUG,"GUI Component JSON",$H(this.components).toJSON());}
wjwindow.show();spin.content(url,[elem,this.coupleComponents.bind(this,this.components),finished,aeroplane.windowmanager.cleanUpDijitWidgets.bind(aeroplane.windowmanager),this.parseGUI.bind(this,elem,wjwindow)]);},preCleanUp:function(wjwindow){var tinyMCELoaded=(typeof(tinyMCE)!="undefined")?true:false;if(tinyMCELoaded){$H(tinyMCE.editors).keys().each(function(id){if(!$(id)||$(id).descendantOf(this.getWindowElement())){WJDebugger.log(WJDebugger.NOTICE,"Removing tinyMCE editor: ",id);tinymce.EditorManager.execCommand("mceRemoveControl",false,id)}}.bind(wjwindow));}},parseGUI:function(context,wjwindow){WJDebugger.log(WJDebugger.DEBUG,"Parse GUI",context,wjwindow);if(dojo&&dojo.parser){WJDebugger.log(WJDebugger.DEBUG,"Ready to parse GUI");this._parseGUI(context,wjwindow);}
else{arguments.callee.bind(this,context,wjwindow).delay(0.5);}},_parseGUI:function(context,wjwindow){WJDebugger.log(WJDebugger.INFO,"Dojo parsing new Gui",context,wjwindow);aeroplane.windowmanager.cleanUpDijitWidgets();try{var widgets=dojo.parser.parse(context);}
catch(e){WJDebugger.log(WJDebugger.ERROR,"Dojo parsing new Gui failed",e);WJWindow.alert("De grafische gebruikersinterface kon niet correct worden opgebouwd."+"\n"+"Neem contact op met Connectholland."+"\n"+"De applicatie zal worden gesloten.",this.application.close.bind(this.application));}
this._handleGUILoad(context,wjwindow);return widgets;},_handleGUILoad:function(context,wjwindow){this.focusElement(context);aeroplane.loadingCursor(false,wjwindow,this.loadingCallback);},focusElement:function(context){if(!context){return;}
var element=context.select("input").first();if(Object.isElement(element)){try{element.focus();}
catch(err){}}},getCt:function(){return"wmgui";},getDt:function(){return"gui";},getUfts:function(){return["gui"];},addButtons:function(window){},getComponentId:function(id){if($(id+"_"+this.application.pid)){return id+"_"+this.application.pid;}
else{return id;}},coupleComponents:function(component){WJDebugger.log(WJDebugger.INFO,"coupling",component);for(var cmp in component){if(cmp=="id"){if($(this.getComponentId(component[cmp]))){component.setHtmlelement($(this.getComponentId(component[cmp])));}
else{var possibles=document.getElementsByName(component[cmp]);$A(possibles).each(component.setHtmlelement.bind(component));}}
if(cmp=="component"){this.coupleComponents(component[cmp]);}
if(cmp=="components"){if(component[cmp].each){$A(component[cmp]).each(this.coupleComponents.bind(this));}}}}});WJLoginInterface=Class.create(WJApplicationInterface,{initialize:function($super,appname,module){$super(appname);this.module=module;this.url.addParameter("module",this.module);this.readonly=true;},buildGui:function(){return new WJLoginGui(this);},handleWindowEvent:function(eventName){if(eventName=="true"){this.login();}
else{aeroplane.windowmanager.getMainWindow(this).hide();}},login:function(){var wjwindow=aeroplane.windowmanager.getMainWindow(this);aeroplane.loadingCursor(true);this.fillDatacollector();if(this.datacollector.valid()){this.url.addParameter("username",this.datacollector.getValue("username"));this.url.addParameter("password",this.datacollector.getValue("password"));this.spin.content(this.url,[this.loginCorrect.bind(this)],{"401":this.loginIncorrect.bind(this),"403":this.accessDenied.bind(this)});this.url.deleteParameter("username");this.datacollector.setValue("username","");this.url.deleteParameter("password");this.datacollector.setValue("password","");}},loginCorrect:function(response){if(typeof(this.loginCorrectHandler)=="function"){this.loginCorrectHandler(response);aeroplane.windowmanager.destroyMainWindow(this);}
else if(false){this._forward();}
else{this._reload();}},setLoginCorrectHandler:function(callback){this.loginCorrectHandler=callback;},_forward:function(url){document.location.href=url;},_reload:function(){var loc=document.location;if(loc.href.indexOf("useraction=logout")!=-1){var url=loc.href.replace("useraction=logout&","");url=url.replace("useraction=logout","");if(url.endsWith("?")){url=url.replace("?","");}
this._forward(url);}
else{document.location.reload();}},loginIncorrect:function(response){aeroplane.loadingCursor(false);WJWindow.alert("De door u opgegeven gebruikersnaam/wachtwoord combinatie is onbekend",this.showWindow.bind(this));},showWindow:function(){var win=aeroplane.windowmanager.getMainWindow(this);win.show();},accessDenied:function(response){var win=aeroplane.windowmanager.getMainWindow(this);aeroplane.loadingCursor(false);WJWindow.alert("U heeft geen toegang tot dit deel van het systeem, maar bent wel succesvol aangemeld.",this._reload.bind(this));}});var WJLoginGui=Class.create(WJGui,{show:function($super,wjwindow,spin,finished){$super(wjwindow,spin,finished);wjwindow.getWindowElement().addClassName("aeroplane_reset");wjwindow.insertWindowRowBefore("main","intro");wjwindow.setWidth(400);wjwindow.setHeight(528);wjwindow.setZ(1000);wjwindow.center();wjwindow.keepCentered();},addButtons:function(wjwindow){wjwindow.addButton("Aanmelden","true",true);},postProcesComponents:function($super){$super();this.groupComponents("optimizedtext","",["text"],null,this.components,null,"top");this.groupComponents("loginfields","Inloggen",["username","password"],null,this.components);},_parseGUI:function($super,context,wjwindow){var widgets=$super(context,wjwindow);wjwindow.getContentElement("intro").appendChild(wjwindow.getContentElement("main").down(".aeroplane_wjhtml"));return widgets;}});var WJDatacollectorFactory=Class.create({initialize:function(){},importDatacollector:function(datacollector){datacollector.getValue=function(key){return this.fields[key].getValue();};datacollector.setValue=function(key,value){this.fields[key].setValue(value);};datacollector.valid=function(){for(field in this.fields){if(!this.fields[field].valid()){return false;}}
return true;};this.rootDatacollector=datacollector;var fields={};if(datacollector.fields){for(var i=0;i<datacollector.fields.length;i++){fields[datacollector.fields[i].name]=this.importField(datacollector.fields[i]);}}
datacollector.fields=fields;return datacollector;},importField:function(datacollector){datacollector.valid=function(){if(!this.value.validate()){return false;}
for(field in this.fields){if(!this.fields[field].valid()){return false;}}
return true;};datacollector.setValue=function(value){this.value.setValue(value);};datacollector.getValue=function(){return this.value.getValue();};datacollector.getName=function(){return this.name;};datacollector.getUfName=function(){return this.ufname;};datacollector.getDatatype=function(){return this.value.datatype;};var fields={};if(datacollector.fields){for(var i=0;i<datacollector.fields.length;i++){fields[datacollector.fields[i].name]=this.importField(datacollector.fields[i]);}}
datacollector.fields=fields;var value={};value.value=datacollector.value;value=this.importDatatype(value,datacollector.datatype,datacollector.validateTree);datacollector.value=value;return datacollector;},importDatatype:function(value,datatype,validateTree){value.datatype=datatype;value.getValue=function(){return this.value;};value.setValue=function(value){this.value=value;};value.validateTree=this.importValidateTree(validateTree,value);value.validate=function(){return this.validateTree.valid();};if(value.datatype=="WMCompositeDatatype"){value.composite=new Array();for(var key in value.value){var compdatacol={name:key,ufname:key,value:value.value[key].value,datatype:value.value[key].datatype};value.composite.push(this.importField(compdatacol));}}
return value;},importValidateTree:function(validateTree,value){if(validateTree){var factory=new WJValidationTreeFactory();return factory.importTree(validateTree,value,this.rootDatacollector);}
else{return new WJValidationTree(new WJTrueTestClause(),value.getValue.bind(value));}}});var WJUnloadManager=Class.create({initialize:function(checker){this._checker=checker||function(){return false;};this.suspend(false);this._asking=false;Event.observe(window,"keydown",this.handleKeyUnload.bindAsEventListener(this));Event.observe(window,"beforeunload",this.handleUnload.bindAsEventListener(this));},handleUnload:function(event){if(!this._checker()&&!this.isSuspended()){event.returnValue=this._getMessage(true);}},handleKeyUnload:function(event){var modKs=(event.altKey?1:0)+(event.shiftKey?2:0)+(event.ctrlKey?4:0);var key=event.keyCode;if(!this._checker()&&!this.isSuspended()){if((modKs==4||modKs==6)&&key==82){this._showMessage(this.doReload.bind(this));}
if(modKs==1&&(key==Event.KEY_LEFT||key==Event.KEY_RIGHT)){this._showMessage(this.doHistory.bind(this,((key==Event.KEY_LEFT)?-1:+1)));}
if((modKs==0||modKs==4)&&key==116){this._showMessage(this.doReload.bind(this));}
}
if(this._asking){return this._stop(event);}},_stop:function(event){if(event.stopPropagation){event.stopPropagation();}
event.stop();event.returnValue=false;return false;},doReload:function(wjwindow,event,doReload){if(doReload){this.suspend();document.location.reload();}
else{this._asking=false;}},doHistory:function(direction,wjwindow,event,doHistory){if(doHistory){this.suspend();window.history.go(direction);}
else{this._asking=false;}},suspend:function(doSuspend){var doSuspend=(doSuspend!=false);this._suspended=doSuspend;},isSuspended:function(){return this._suspended;},_showMessage:function(callback){if(!this._asking){WJWindow.booleanConfirm(this._getMessage(false,true),callback);this._asking=true;}},_getMessage:function(useBrowserLang,full){var useBrowserLang=(useBrowserLang===true);var full=(full===true);if(useBrowserLang){var lang=this._getBrowserLanguage();if(full){return this._messages.body[lang]+"\n\n"+this._messages.question[lang];}
else{return this._messages.body[lang];}}
else{if(full){return"Mogelijk zijn er nog niet opgeslagen gegevens."+"\n\n"+"Weet je zeker dat u deze pagina wilt verlaten?";}
else{return"Mogelijk zijn er nog niet opgeslagen gegevens.";}
return;}},_getBrowserLanguage:function(){var lang=window.navigator["language"]||window.navigator["browserLanguage"];switch(lang){case"nl":case"nl-NL":case"nl_NL":case"nl-be":case"nl-BE":case"nl_BE":return"nl_NL";default:return"default";}},_messages:{body:{nl_NL:"Mogelijk zijn er nog niet opgeslagen gegevens.","default":"There might be unsaved data."},question:{nl_NL:"Weet u zeker dat u deze pagina wilt verlaten?","default":"Are you sure you want to navigate away?"}}});var WJComponent=Class.create({initialize:function(id){this.id=id;this.value=null;this.disabled=false;this.readonly=false;this.focusEvent="wj:focus";this.blurEvent="wj:blur";this.changeEvent="wj:change";this.componentType="WJComponent";this.htmlelement=null;this.label=null;this.group=false;},setHtmlelement:function(element){this.htmlelement=element;},setLabel:function(label){this.label=label;},fireEvent:function(eventName,e){this.htmlelement.fire(eventName,e);},initComponent:function(datacollector){this.value=datacollector.getValue();},getValue:function(){var usesDijit=(typeof(dijit)!="undefined")?true:false;if(this.htmlelement&&usesDijit&&dijit.byId(this.htmlelement.id)&&dijit.byId(this.htmlelement.id).getValue){this.value=dijit.byId(this.htmlelement.id).attr("value");}
else if(this.htmlelement&&this.htmlelement.value){this.value=this.htmlelement.value;}
return this.value;},setValue:function(value){var usesDijit=(typeof(dijit)!="undefined")?true:false;this.value=value;if(this.htmlelement&&usesDijit&&dijit.byId(this.htmlelement.id)&&dijit.byId(this.htmlelement.id).setValue){dijit.byId(this.htmlelement.id).setValue(this.value);}
else if(this.htmlelement&&this.htmlelement.value){this.htmlelement.value=this.value;}},getId:function(){return this.id;}});var WJText=Class.create(WJComponent,{initialize:function($super,id){$super(id);this.componentType="WJText";}});var WJPassword=Class.create(WJText,{initialize:function($super,id){$super(id);this.componentType="WJPassword";}});WJLabel=Class.create(WJComponent,{initialize:function($super,id,text,image){$super(id);this.componentType="WJLabel",this.text=text;this.image=image;}});WJGroup=Class.create(WJComponent,{initialize:function($super,id){$super(id);this.componentType="WJGroup";this.components=new Array();this.region="center";this.hasGroups=false;this.group=true;},setRegion:function(region){this.region=region;},addComponent:function(comp){WJDebugger.log(WJDebugger.DEBUG,"Adding component to WJGroup "+this.id,comp);this.components.push(comp);},getComponents:function(){return this.components;},initComponent:function($super,datacollector,gui){$super(datacollector,gui);WJDebugger.log(WJDebugger.DEBUG,"Initing a "+this.id+" WJGroup",datacollector,gui);if(datacollector.value.composite){for(var i=0;i<datacollector.value.composite.length;i++){if(typeof(datacollector.value.composite[i])=="object"){this.addComponent(gui.createComponents(datacollector.value.composite[i]));}}}}});var WJHtml=Class.create(WJGroup,{initialize:function($super,id){$super(id);this.componentType="WJHtml";this.group=0;}});var WJValidationTree=Class.create();WJValidationTree.prototype={initialize:function(test,inputCallback,additionalCallback){this.test=test;this.inputCallback=inputCallback;if(additionalCallback!=null){this.additionalCallback=additionalCallback;}
this.trueTree=null;this.falseTree=null;this.className="WJValidationTree";},setTrueTree:function(tree){this.trueTree=tree;return this.trueTree;},setFalseTree:function(tree){this.falseTree=tree;return this.falseTree;},valid:function(){var additional=null;if(typeof(this.additionalCallback)=="function"){additional=this.additionalCallback();}
if(typeof(this.inputCallback)!="function"){throw"Callback for input must be a function, it is a "+typeof(this.inputCallback);}
var input=this.inputCallback();var result=this.test.test(input,additional);if(result){if(this.trueTree){return this.trueTree.valid();}
else{return true;}}
else{if(this.falseTree){return this.falseTree.valid();}
else{return false;}}}}
var WJValidationTreeFactory=Class.create();WJValidationTreeFactory.prototype={initialize:function(){},importTree:function(tree,value,datacollector){var factory=new WJTestClauseFactory();var validateTree=new WJValidationTree(factory.importTest(tree.test),this.importCallback(tree.input,datacollector,value),this.importCallback(tree.additional,datacollector,value));if(tree.trueTree){validateTree.setTrueTree(this.importTree(tree.trueTree,value,datacollector));}
if(tree.falseTree){validateTree.setFalseTree(this.importTree(tree.falseTree,value,datacollector));}
return validateTree;},importCallback:function(callback,datacollector,value){if(typeof(callback)=="object"){if((callback.className=="WMRequest")&&(callback.method=="getVariable")){return datacollector.getValue.bind(datacollector,callback.args);}
if(callback.method=="getValue"){return value.getValue.bind(value);}}}}
var WJTestClause=Class.create();WJTestClause.prototype={initialize:function(){this.className="WJTestClause";}}
var WJTestClauseFactory=Class.create();WJTestClauseFactory.prototype={initialize:function(){this.className="WJTestClauseFactory";},importTest:function(test){var testClass=test.test.replace("WM","WJ");var resultTest=new window[testClass]();for(field in test){if(field!="test"){resultTest[field]=test[field];}}
return resultTest;}}
var WJTrueTestClause=Class.create(WJTestClause,{initialize:function($super){$super();this.className="WJTrueTestClause";},test:function(input,additional){return true;}});var WJScalarTestClause=Class.create(WJTestClause,{initialize:function(){this.className="WJScalarTestClause";},test:function(input,additional){var datatype=typeof(input);return((datatype=="number")||(datatype=="string")||(datatype=="boolean"));}});var WJWindow=Class.create({DEFAULT_PARENT:document.body,initialize:function(callback,parent){this._loading=false;this._basetitle=this._title="";this._theme="default";this._parent=parent||WJWindow.DEFAULT_PARENT||document.body;this._createWindow();this._listeners=new Hash();this._addDefaultListeners();this._addCloseButton();this.setCallback(callback);this.setBaseTitle(WJGuiSettings.windowBaseTitle);},_createWindow:function(){var classname=this._getBaseClassname();this._windowElement=new Element("div",{"class":classname});this._windowElement.setStyle({"display":"none"});this._createWindowRows(["title","main","buttons","bottom"],classname);this._windowElementId=this._windowElement.identify();this._parent.insert(this._windowElement);this._absolutizeTopLeft();this.hide();this._outerElement=this._windowElement;this.setTheme();},insertWindowRowBefore:function(rowname,newrowname){if(rowname==="title"){return;}
var classname=this._getBaseClassname();var row=this._windowElement.select("."+classname+"_"+rowname)
row=row.first();var newrowhtml=this._createRow(newrowname,classname," "+classname+"_body");var div=new Element("div");div.update(newrowhtml);var toprow=row.parentNode;var newrow=toprow.insertBefore(div.firstChild,row);newrow=Element.extend(newrow);newrow=newrow.select("."+classname+"_content");this._contentElements[newrowname]=newrow.first();return newrow;},replaceWindowRow:function(oldrow,newrow){var inserted=this.insertWindowRowBefore(oldrow,newrow);var toremove=this.getContentElement(oldrow);this._contentElements[oldrow]=this._contentElements[newrow];return toremove.remove();},_addCloseButton:function(){var title=this.getContentElement("title");title.appendChild(new Element("div",{"class":this._getBaseClassname()+"_closebutton","onclick":"this.parentNode.getWJWindowObject().fireClose(this)","title":"Venster sluiten"}));},fireClose:function(element){element=$(element);var func=function(){this.destroy();Event.stopObserving(document,"wjgui:close",arguments.callee.observerFunction);}
var bound=func.bindAsEventListener(this);func.observerFunction=bound;Event.observe(document,"wjgui:close",bound);element.fire("wjgui:close");Event.stopObserving.defer(document,"wjgui:close",bound);},_addDefaultListeners:function(element){this.addListener("true",this.windowResult.bindAsEventListener(this,true));this.addListener("false",this.windowResult.bindAsEventListener(this,false));this.addListener("close",this.windowResult.bindAsEventListener(this,false));this.addListener("save",this.windowResult.bindAsEventListener(this));this.addListener("delete",this.windowResult.bindAsEventListener(this));this.addListener("cancel",this.windowResult.bindAsEventListener(this));this._addDefaultKeyListener();},_addDefaultKeyListener:function(){var element=element||this._windowElement;Event.observe(element,"keydown",this.keyHandle.bindAsEventListener(this));},keyHandle:function(event){var element=event.element();if(Object.isElement(element.up(".wjgui_window"))){switch(event.keyCode){case Event.KEY_RETURN:if(this.isVisible()){element.fire("wjgui:true");}
break;case Event.KEY_ESC:if(this.isVisible()){element.fire("wjgui:close");}
break;default:return;}}},addListener:function(eventName,callback,element){WJDebugger.log(WJDebugger.INFO,"Adding listener in WJWindow",eventName,callback);var callback=callback||this.windowResult.bindAsEventListener(this);var element=element||this._windowElement;Event.observe(element,"wjgui:"+eventName,callback);this._setListener(eventName,{"element":element,"callback":callback});return this;},_setListener:function(key,elementAndCallback){this._listeners.set(key,elementAndCallback);},removeListener:function(key){var listener=this.getListener(key);Event.stopObserving(listener.element,"wjgui:"+key,listener.callback);this._listeners.unset(key);return this;},removeListeners:function(){this._listeners.each(function(info){this.removeListener(info.key);}.bind(this));return this;},windowResult:function(event){this._callback.apply(this,arguments);},getListeners:function(){return this._listeners;},getListener:function(key){return this._listeners.get(key);},_getBaseClassname:function(){return"wjgui_window";},_getWindowRowTemplate:function(){return new Template("<div class='#{classprefix}_#{rowname} #{classprefix}_row#{body}'><div class='#{classprefix}_left #{classprefix}_column'><div class='#{classprefix}_right #{classprefix}_column'><div class='#{classprefix}_center #{classprefix}_column'><div class='#{classprefix}_content'>&#160;</div></div></div></div></div>");},_createWindowRows:function(rows,classprefix,windowElement){var windowElement=windowElement||this._windowElement;rows.each(function(windowElement,classprefix,rowname,index){var body=" "+classprefix+"_body";if(index==0||index==(rows.length-1)){body="";}
windowElement.innerHTML+=this._createRow(rowname,classprefix,body);}.bind(this,windowElement,classprefix));this._saveRows(rows,classprefix,windowElement);this._addWindowObjectGetters();},_addWindowObjectGetters:function(){var test=[$H(this._contentElements).values(),this._windowElement].flatten();test.each(function(el){el.getWJWindowObject=function(){return this;}.bind(this);},this);return test;},_saveRows:function(rows,classprefix,windowElement){var windowElement=windowElement||this._windowElement;this._contentElements={};rows.each(function(windowElements,rowname,index){this._contentElements[rowname]=windowElements[index];}.bind(this,windowElement.select("."+classprefix+"_content")));return this;},_createRow:function(rowname,classprefix,body){var row=this._getWindowRowTemplate();return row.evaluate({"rowname":rowname,"classprefix":classprefix,"body":body});},getContentElement:function(rowname){return this._contentElements[rowname];},evalContentElement:function(rowname){var element=this.getContentElement(rowname);element.innerHTML.evalScripts();return this;},_absolutizeTopLeft:function(element){var element=element||this._windowElement;element.absolutize();element.setStyle({height:"",width:""});this.setX(0,element);this.setY(0,element);},_checkMaxHeight:function(element){var element=element||this.getContentElement("main");if(this.getY()+this.getHeight()>document.viewport.getHeight()){this.setHeight(document.viewport.getHeight()-this.getY(),element,false);}
else{element.setStyle({"maxHeight":""});}},show:function(element){var element=element||this._outerElement||this._windowElement;element.style.display="block";try{element.focus()}catch(e){}
return this;},hide:function(element){var element=element||this._outerElement||this._windowElement;element.style.display="none";return this;},destroy:function(element){var element=element||this._outerElement||this._windowElement;if(element.parentNode){element.remove();}
return this;},_callback:function(){if(Object.isFunction(this._callbackFunction)){var args=$A(arguments);args.unshift(this);return this._callbackFunction.apply(this._callbackFunction,args);}},_close:function(event){this.hide();},setBaseTitle:function(title){this._basetitle=title;this.setTitle(this.getTitle());return this;},setTitle:function(title){this._title=title;var headers=this.getContentElement("title").getElementsByTagName("h1");if(headers.length<1){this.getContentElement("title").innerHTML="<h1>&#160;</h1>"+this.getContentElement("title").innerHTML;return this.setTitle(this._title);}
headers[0].innerHTML=this._getComposedTitle();return this;},_getComposedTitle:function(){return this._title+((this._basetitle!=""&&this._basetitle!=this._title)?((this._title!="")?" - ":"")+this._basetitle:"");},setContent:function(content){if(Object.isString(content)){this.getContentElement("main").innerHTML=content;}
if(Object.isElement(content)){this.getContentElement("main").appendChild(content);}
this._content=content;return this;},addButton:function(caption,eventHandler,defaultButton){WJDebugger.log(WJDebugger.INFO,"Adding button to window",caption,eventHandler,this);var button=WJButton.create(caption,eventHandler,defaultButton,this.getContentElement("buttons"));this._checkMaxHeight();return button;},addStatusbar:function(){WJDebugger.log(WJDebugger.INFO,"Adding statusbar to window",this);this._statusbar=new Element("div",{"class":"wjgui_statusbar"});this.getContentElement("buttons").insert(this._statusbar);this._checkMaxHeight();},setStatusbar:function(content,fade){var fade=fade||-1;if(this._statusbar){this._statusbar.update(content);if(fade>0){this.hideStatusbar.bind(this).delay(fade);}}},hideStatusbar:function(){Effect.Fade(this._statusbar,{duration:3.0});this.clearAndShowStatusbar.bind(this).delay(3.5);},clearAndShowStatusbar:function(){this._statusbar.update("");this._statusbar.show();},setCallback:function(callback){if(Object.isFunction(callback)){this._callbackFunction=callback;}
return this;},setX:function(x,element){this._x=x||0;var element=element||this._windowElement;element.style.left=x+"px";return this;},setY:function(y,element){this._y=y||0;var element=element||this._windowElement;element.style.top=y+"px";this._checkMaxHeight(element);return this;},setZ:function(z,element){this._z=z||10000;var element=element||this._windowElement;element.style.zIndex=z;return this;},setWidth:function(width,element){this._width=width;var element=element||this._windowElement;element.setStyle({"width":width+"px"});element.fire("wjgui:resize");return this;},setHeight:function(height,element,checkHeight){this._height=height;var element=element||this.getContentElement("main");var wasVisible=this.isVisible();var origX=this.getX();var origY=this.getY();if(!wasVisible){this.setX(-10000);this.setY(-10000);this.show();}
var otherRowsHeight=0;for(var key in this._contentElements){if(key!="main"){otherRowsHeight+=this._contentElements[key].getHeight();}}
var height=(Object.isNumber(height)==false)?height:(height-otherRowsHeight)+"px";element.setStyle({"height":height});if(!wasVisible){this.hide();this.setX(origX);this.setY(origY);}
if(checkHeight!=false){this._checkMaxHeight(element);}
if(!checkHeight){element.fire("wjgui:resize");}
return this;},getBaseTitle:function(){return this._basetitle;},getTitle:function(){return this._title;},getType:function(){return this._type;},getContent:function(){return this._content;},getContenttype:function(){},getCallback:function(){return this._callbackFunction;},isVisible:function(){var xInLow=(this.getX()<0&&(this.getX()+this.getWidth())>0);var xInHigh=(this.getX()>=0&&this.getX()<document.viewport.getWidth());var yInLow=(this.getY()<0&&(this.getY()+this.getHeight())>0);var yInHigh=(this.getY()>=0&&this.getY()<document.viewport.getHeight());if((xInLow||xInHigh)&&(yInLow||yInHigh)&&this._windowElement.visible()){return true;}
return false;},getX:function(element){var element=element||this._windowElement;return parseInt(element.style.left);},getY:function(element){var element=element||this._windowElement;return parseInt(element.style.top);},getZ:function(){var element=element||this._windowElement;return element.style.zIndex;},getWidth:function(element){var element=element||this._windowElement;return element.getWidth();},getHeight:function(element){var element=element||this._windowElement;return element.getHeight();},getContentHeight:function(){return this.getContentElement("main").getHeight();},getContentWidth:function(){return this.getContentElement("main").getWidth();},getWindowElement:function(){return this._windowElement;},center:function(element){var element=element||this._windowElement;var remainsX=document.viewport.getWidth()-this.getWidth(element);var remainsY=document.viewport.getHeight()-this.getHeight(element);this.setX(remainsX/2,element).setY(remainsY/2,element);return this;},keepCentered:function(element){if(!this._centerObserver){var element=element||this._windowElement;this._centerObserver=this.center.bind(this,element);Event.observe(window,"resize",this._centerObserver);}},stopCentered:function(){Event.stopObserving(window,"resize",this._centerObserver);this._centerObserver=null;},maximize:function(paddingTop,paddingRight,paddingBottom,paddingLeft,noScroll){var paddingTop=paddingTop||0;var paddingRight=paddingRight||paddingTop;var paddingBottom=paddingBottom||paddingTop;var paddingLeft=paddingLeft||paddingTop;var noScroll=noScroll||false;this.setX(paddingLeft).setY(paddingTop);if(noScroll){this.setWidth(0).setHeight(0);}
this.setWidth(document.viewport.getWidth()-(paddingLeft+paddingRight)).setHeight(document.viewport.getHeight()-(paddingTop+paddingBottom));return this;},keepMaximized:function(){if(!this._maximizedObserver){var paddingTop=this.getY();var paddingLeft=this.getX();var paddingRight=document.viewport.getWidth()-this.getWidth()-paddingLeft;var paddingBottom=document.viewport.getHeight()-this.getHeight()-paddingTop;this._maximizedObserver=this.maximize.bind(this,paddingTop,paddingRight,paddingBottom,paddingLeft,true);Event.observe(window,"resize",this._maximizedObserver);}},stopMaximized:function(){Event.stopObserving(window,"resize",this._maximizedObserver);this._maximizedObserver=null;},setLoading:function(loading,loadCallback){var loadCallback=loadCallback||false;if(loading&&!this.getLoading()){this.getWindowElement().addClassName("wjgui_window_loading");if(!loadCallback){this.getContentElement("main").setStyle({"visibility":"hidden"});}
else{loadCallback(this,loading);}}
else if(!loading&&this.getLoading()){this.getWindowElement().removeClassName("wjgui_window_loading");if(!loadCallback){this.getContentElement("main").setStyle({"visibility":"visible"});}
else{loadCallback(this,loading);}}
this._loading=loading;return this;},getLoading:function(){return this._loading;},setTheme:function(theme){if(theme==this.getTheme()){return;}
this._removeOldTheme();this._setTheme(theme);this._addNewTheme();},_setTheme:function(theme){this._theme=theme||"default";},_removeOldTheme:function(){this.getWindowElement().removeClassName(this._getBaseClassname()+"theme_"+this.getTheme());},_addNewTheme:function(){this.getWindowElement().addClassName(this._getBaseClassname()+"theme_"+this.getTheme());},getTheme:function(){return this._theme;}});WJWindow._messagedialog=function(type,message,callback,show){var win=new WJWindow(callback);var mwin=new window[type](win);mwin.setMessage(message);if(show){mwin.show();}
return mwin;}
WJWindow.alert=function(message,callback){return WJWindow._messagedialog("WJWindowAlert",message,callback,true);}
WJWindow.notice=function(message,callback){return WJWindow._messagedialog("WJWindowNotice",message,callback,true);}
WJWindow.confirm=function(message,callback){return WJWindow._messagedialog("WJWindowConfirm",message,callback,true);}
WJWindow.booleanConfirm=function(message,callback){return WJWindow._messagedialog("WJWindowBooleanConfirm",message,callback,true);}
WJWindow.prompt=function(message,callback){return WJWindow._messagedialog("WJWindowPrompt",message,callback,true);}
var WJWindowModal=Class.create({initialize:function(toDecorate){this._decorate(toDecorate);this._createModalLayer();this._maxblink=6;this._addBlinkListener();this._rebindListeners();this._rebindWindowObjectGetters();this.setZ(2147483647);this.show();},_decorate:function(toDecorate){this._decorated=toDecorate;for(property in this._decorated){if(!Object.isFunction(this[property])){this[property]=this._decorated[property];}}},_rebindListeners:function(){this.removeListeners();this._addDefaultListeners();},_createModalLayer:function(){var windowElement=this._decorated.getWindowElement();this._modalLayer=new WJModalLayer();this._modalLayer.getLayer().insert(windowElement);this._outerElement=this._modalLayer.getLayer();},show:function(element){var element=element||this._outerElement||this._modalLayer.getLayer();element.style.display="block";this._setBodyOverflow("hidden");this._decorated.show();},hide:function(element){var element=element||this._outerElement||this._modalLayer.getLayer();element.style.display="none";this._setBodyOverflow();this._decorated.hide();},_setBodyOverflow:function(value){var value=value||"";$(document.body).setStyle({overflow:value});$(document.getElementsByTagName("html")[0]).setStyle({overflow:value});},_addBlinkListener:function(){Event.observe(this._modalLayer.getLayer(),"click",this.blink.bindAsEventListener(this));},blink:function(event,doBlink,count){var count=count||0;if(Event.element(event).className==this._getBaseClassname()+"_modality"){if(doBlink){this.getWindowElement().addClassName(this._getBaseClassname()+"_blink");doBlink=false;}
else{this.getWindowElement().removeClassName(this._getBaseClassname()+"_blink");doBlink=true;}
if(count<this._maxblink){count++
this.blink.bind(this,event,doBlink,count).delay(0.05);}}},_rebindWindowObjectGetters:function(){var els=this._decorated._addWindowObjectGetters();els.each(function(el){el.getWJWindowObject=el.getWJWindowObject.bind(this);},this);return els;}});var WJModalLayer=Class.create({initialize:function(parent,modalLayer){var parent=parent||document.body;this._modalLayer=(modalLayer||new Element("div"));Element.extend(this._modalLayer).addClassName("wjgui_window_modality");parent.appendChild(this._modalLayer);this._removed=false;this._absolutizeTopLeft();this._fillViewport();Event.observe(window,"resize",this._fillViewport.bind(this,this._modalLayer));},_absolutizeTopLeft:function(element){var element=this._modalLayer;element.absolutize();element.setStyle({left:0,top:0,zIndex:2147483647});},_fillViewport:function(){var element=$(this._modalLayer);if($(element.parentNode)&&$(element.parentNode).getHeight){element.setStyle({width:$(element.parentNode).getWidth()+"px",height:$(element.parentNode).getHeight()+"px"});}
else{element.setStyle({width:document.viewport.getWidth()+"px",height:document.viewport.getHeight()+"px"});}},getLayer:function(){return this._modalLayer;},destroy:function(){if(!this._removed){this._modalLayer.remove();this._removed=true;}}});var WJWindowMessageDialog=Class.create(WJWindowModal,{initialize:function($super,toDecorate){$super(toDecorate);this.center();this.keepCentered();this._drawDefaultContent();this._buttons=null;this._addButtons();},_drawDefaultContent:function(){var content=this.getContentElement("main");var replaces=this._getTemplateValues();var template=this._getTemplate();content.innerHTML=template.evaluate(replaces);this._contentElements["message"]=content.down("."+replaces.classprefix+"_message");},_getTemplateValues:function(){return{"classprefix":this._getBaseClassname(),"windowtype":this._type};},_addButtons:function(){if(this._buttons==null){this._buttons=new Hash();this._buttons.set("ok",WJButton.create("OK","true",true,this.getContentElement("buttons"))).focus();}
return this._buttons;},_getTemplate:function(){return new Template("<div class='#{classprefix}_messageicon #{classprefix}_messageicon_#{windowtype}'>&#160;</div><div class='#{classprefix}_message'>&#160;</div>");},setMessage:function(message){this.message=message.stripTags().stripScripts().split("\n").join("<br/>");this.getContentElement("message").innerHTML=this.message;},_callback:function(){this.hide();return this._decorated._callback.apply(this._decorated,$A(arguments));}});var WJWindowAlert=Class.create(WJWindowMessageDialog,{initialize:function($super,toDecorate){if(!this._type){this._type="alert";}
$super(toDecorate);this.getListener("close").callback.setArgument(0,true);this.removeListener("false");this.removeListener("save");this.removeListener("cancel");}});var WJWindowNotice=Class.create(WJWindowAlert,{initialize:function($super,toDecorate){this._type="notice";$super(toDecorate);}});var WJButton=Class.create({initialize:function(caption,eventHandler,defaultButton,parentElement){WJDebugger.log(WJDebugger.INFO,"Create new button",caption,eventHandler,defaultButton,parentElement);this._caption=caption;this._eventHandler=eventHandler;this._defaultButton=(defaultButton===true)?true:false;this._parentElement=$(parentElement);this._buildEventHandler();this._createButton();this._addButtonMethods();this._addObserver();if(Object.isElement(this._parentElement)){this._parentElement.appendChild(this.getButton());}
this.updateCaption(this._caption);},_addButtonMethods:function(){this.getButton().updateCaption=this.updateCaption.bind(this);this.getButton().setCaption=this.getButton().updateCaption;this.getButton().getCaption=this.getCaption.bind(this);this.getButton().enable=this.enable.bind(this);this.getButton().disable=this.disable.bind(this);},updateCaption:function(caption){this._caption=caption.stripTags().stripScripts();return this._setCaption.bind(this).defer();},setCaption:function(caption){this.updateCaption(caption);},_setCaption:function(){var contentElement=this.getContentElement();contentElement.update(this._caption);this.setWidth(this._getNewButtonWidth(this._caption,contentElement));return this.getButton();},enable:function(){this.getButton().removeAttribute("disabled");this.getButton().removeClassName("wjgui_button_disabled");return this;},disable:function(){this.getButton().disabled="disabled";this.getButton().addClassName("wjgui_button_disabled");return this;},getContentElement:function(){return this.getButton().down("."+this._getBaseClassName()+"_content");},_getNewButtonWidth:function(text,element){var fontfamily=element.getStyle("fontFamily");var fontsize=element.getStyle("fontSize");var fontweight=element.getStyle("fontWeight");WJButton.measureElement.setStyle({"fontFamily":fontfamily,"fontSize":fontsize,"fontWeight":fontweight}).update(text);var width=document.body.appendChild(WJButton.measureElement).getWidth();WJButton.measureElement.remove();width+=this.getWidth()-element.getWidth();return(width>100)?width:100;},getWidth:function(){return this.getButton().getWidth();},setWidth:function(width){this.getButton().setStyle({"width":width+"px"});},_buildEventHandler:function(){if(!Object.isFunction(this._eventHandler)){if(this._eventHandler.indexOf(":")==-1){this._eventHandler=this._getEventPrefix()+":"+this._eventHandler;WJDebugger.log(WJDebugger.INFO,"Build event handler for this, create event "+this._eventHandler);var func=function(event,eventHandler){WJDebugger.log(WJDebugger.INFO,"Fire event in WJButton",event,eventHandler);Event.element(event).fire(eventHandler);}.bindAsEventListener(this.getButton(),this._eventHandler);this._eventHandler=func;}}},_getEventPrefix:function(){return"wjgui";},_createButton:function(){this._buttonElement=new Element("button");var template=this._getTemplate();var replaces={};replaces.classprefix=this._getBaseClassName();this._buttonElement.className=replaces.classprefix+" "+replaces.classprefix+"_"+((this._defaultButton)?"":"no")+"default";this._buttonElement.innerHTML=template.evaluate(replaces);},_getBaseClassName:function(){return"wjgui_button";},_getTemplate:function(){return new Template("<div class='#{classprefix}_left #{classprefix}_column'><div class='#{classprefix}_right #{classprefix}_column'><div class='#{classprefix}_center #{classprefix}_column'><div class='#{classprefix}_content'>&#160;</div></div></div></div>");},getButton:function(){return this._buttonElement;},_addObserver:function(){WJDebugger.log(WJDebugger.INFO,"_addObserver in WJButton",this._eventHandler);WJDebugger.log(WJDebugger.DEBUG,"WJButton observer code",this._eventHandler.toString());Event.observe(this.getButton(),"click",this._eventHandler);},setObserver:function(eventHandler){Event.stopObserving(this.getButton(),"click",this._eventHandler);this._eventHandler=eventHandler;this._addObserver();},getCaption:function(){return this._caption;},recalculateWidth:function(){this.updateCaption(this.getCaption());}});WJButton.measureElement=new Element("div",{"style":"position: absolute; left: -1000px;"});WJButton.create=function(caption,eventHandler,defaultButton,parentElement){var button=new WJButton(caption,eventHandler,defaultButton,parentElement);return button.getButton();}
WJButton.toWJButtonStyle=function(element,defaultButton){if(element.tagName.toLowerCase()=="button"){var element=$(element);var caption=element.getTextContent();var template=WJButton.prototype._getTemplate();var replaces={classprefix:WJButton.prototype._getBaseClassName()};element.className=replaces.classprefix+" "+replaces.classprefix+"_"+((defaultButton)?"":"no")+"default";element.update(template.evaluate(replaces));element.down("."+replaces.classprefix+"_content").update(caption);}
return element;}
var WJGuiSettings=Object.extend({windowBaseTitle:"Windmill CMS"},WJGuiSettings||{});var WJLogin=Class.create({initialize:function(module,loggedIn){this.module=module;this.spinQueue=[];if(!loggedIn){this._startObservers();}},_startObservers:function(){Event.observe(document,"keydown",this.observeKey.bindAsEventListener(this));},observeKey:function(event){if(event.keyCode==76){if(event.ctrlKey){Event.stop(event);if(event.preventDefault){event.preventDefault();}
this.startLogin();}}},startLogin:function(){this.application=aeroplane.openApplication("Login",this.module);},registerLoginHandler:function(){aeroplane.registerSpinErrorHandler(403,this.handleAccessDenied.bind(this));},handleAccessDenied:function(response,spinCall){if(typeof(spinCall)=="function"){this.spinQueue.push(spinCall);}
this.application=aeroplane.openApplication("Login",this.module);this.application.setLoginCorrectHandler(this.invokeSpinQueue.bind(this));},invokeSpinQueue:function(response){if(typeof(this.spinQueue[0])=="function"){this.spinQueue[0]();delete this.spinQueue[0];this.invokeSpinQueue(response);}}});