NG.AJAX=function(b,a){this.responseHandlers={};this.url=b;if(arguments.length>1){this.setResponseHandler(a)}this.method="GET";this.requestHeaders={};this.async=true;this.lastState=null};NG.AJAX.UNITIALIZED=0;NG.AJAX.LOADING=1;NG.AJAX.LOADED=2;NG.AJAX.INTERACTIVE=3;NG.AJAX.COMPLETE=4;NG.AJAX.prototype.setRequestHeader=function(a,b){this.requestHeaders[a]=b};NG.AJAX.prototype.setResponseHandler=function(b,c,a){if(arguments.length<2){c=200}if(arguments.length<3){a=NG.AJAX.COMPLETE}if(!isDef(typeof this.responseHandlers[a])){this.responseHandlers[a]={}}this.responseHandlers[a][c]=b};NG.AJAX.prototype.send=function(f){if(arguments<1){f=""}var d=null;if(window.XMLHttpRequest){try{d=new XMLHttpRequest()}catch(g){d=null}}else{if(window.ActiveXObject){try{d=new ActiveXObject("Msxml2.XMLHTTP")}catch(g){try{d=new ActiveXObject("Microsoft.XMLHTTP")}catch(g){d=null}}}}if(d){this.req=d;var a=this;d.onreadystatechange=function(){if(d&&isFunc(isDef)){try{var i=d.readyState}catch(j){return}try{var c=d.status}catch(j){return}a.lastState=i;if(!isDef(typeof a.responseHandlers[i])&&isDef(typeof a.responseHandlers[""])){i=""}if(i==NG.AJAX.COMPLETE){NG.delClass(document.body,"ngcursor-progress")}if(isDef(typeof a.responseHandlers[i])){if(isDef(typeof a.responseHandlers[i][c])){a.responseHandlers[i][c](d)}else{if(isDef(typeof a.responseHandlers[i][""])){a.responseHandlers[i][""](d)}}}}};d.open(this.method,this.url,this.async);for(var b in this.requestHeaders){if(!isFunc(this.requestHeaders[b])){d.setRequestHeader(b,this.requestHeaders[b])}}NG.addClass(document.body,"ngcursor-progress");var h=f;setTimeout(function(){d.send(h)},0)}else{throw ("Could not create AJAX request")}};NG.AJAX.prototype.cancel=function(){if(this.req&&this.lastState!=NG.AJAX.COMPLETE){this.req.abort()}};NG.AJAX.send=function(b,a,c){new NG.AJAX(b,a).send(c)};NG._zdisregard=0;NG.hideZdisregard=function(){if(NG._zdisregard==0){var b=document.getElementsByTagName("embed");for(var a=0;a<b.length;a++){b[a].style.display="none"}var b=document.getElementsByTagName("object");for(var a=0;a<b.length;a++){b[a].style.visibility="hidden"}if(NG.ua.isEng("MSIE","6.0","<=")){var b=document.getElementsByTagName("select");for(var a=0;a<b.length;a++){b[a].style.visibility="hidden"}}}NG._zdisregard++};NG.showZdisregard=function(){if(NG._zdisregard>0){NG._zdisregard--}if(NG._zdisregard==0){var b=document.getElementsByTagName("embed");for(var a=0;a<b.length;a++){b[a].style.display="block"}var b=document.getElementsByTagName("object");for(var a=0;a<b.length;a++){b[a].style.visibility="visible"}if(NG.ua.isEng("MSIE","6.0","<=")){var b=document.getElementsByTagName("select");for(var a=0;a<b.length;a++){b[a].style.visibility="visible"}}}};NG.addClass=function(d,b){var e=(d.className+"").split(/ +/);for(var a=1;a<arguments.length;a++){if(e.search(arguments[a])==-1){d.className+=" "+arguments[a]}}};NG.delClass=function(e,d){var b,f=(e.className+"").split(/ +/);for(var a=1;a<arguments.length;a++){if(arguments[a].constructor==RegExp){for(var b=0;b<f.length;b++){if(d.test(f[b])){f.splice(b,1);break}}}else{if((b=f.search(arguments[a]))>=0){f.splice(b,1)}}}e.className=f.join(" ")};NG.replaceClass=function(e,b,a){var d,f=(e.className+"").split(/ +/);if(b.constructor==RegExp){for(var d=0;d<f.length;d++){if(b.test(f[d])){f.splice(d,1)}}}else{if((d=f.search(b))>=0){f.splice(d,1)}}if((d=f.search(a))<0){f.push(a)}e.className=f.join(" ")};NG.hasClass=function(e,d){if(e.nodeType!=1){return false}var b,f=(e.className+"").split(/ +/);for(var a=1;a<arguments.length;a++){if(arguments[a].constructor==RegExp){for(var b=0;b<f.length;b++){if(d.test(f[b])){return true}}}else{if((b=f.search(arguments[a]))>=0){return true}}}return false};NG.addStyleRule=function(a,e,f){if(document.styleSheets.length>0){var d=document.styleSheets[0];if(arguments.length<3){f=0}else{if(f<0){f=(isDef(typeof d.cssRules)?d.cssRules:d.rules).length+f+1}}if(isDef(typeof d.insertRule)){d.insertRule(a+" { "+e+" }",f)}else{if(isDef(typeof d.addRule)){var c=a.split(/, */);for(var b=0;b<c.length;b++){d.addRule(c[b],e,f)}}}}};NG.getComputedStyle=function(a){if(window.getComputedStyle){return window.getComputedStyle(a,"")}if(a.currentStyle){return a.currentStyle}return{}};NG.getComputedStylePx=function(c,d){var a,b=NG.getComputedStyle(c)[d];if(a=/^([0-9]+(\.[0-9]+)?)px$/.exec(b)){return parseInt(a[1])}return 0};NG.setNodeHeight=function(c,a){if(isNaN(a)){return}var b=a-NG.getComputedStylePx(c,"paddingTop")-NG.getComputedStylePx(c,"paddingBottom");b-=NG.getComputedStylePx(c,"borderTopWidth")+NG.getComputedStylePx(c,"borderBottomWidth");if(b>=0){c.style.height=b+"px"}};NG.drag=function(a){NG.drag.cancel();NG.drag.tentativeItem=a;NG.addEventListener(document,"mouseup",NG.drag.cancel);NG.addEventListener(document,"mousemove",NG.drag.begin)};NG.drag.cursorMap={"can-drop":"Drop here","move-drop":"Drop here to move","copy-drop":"Drop here to copy","link-drop":"Drop here to link","bad-drop":"Not permitted to drop here","no-drop":"Cannot drop here"};NG.drag.hasRunOnce=false;NG.drag.runOnce=function(){if(!NG.drag.hasRunOnce){NG.drag.hasRunOnce=true;NG.addStyleRule(".ng-drop","position:absolute; padding:2px; padding-left:4px; padding-right:4px; z-Index:100; color:white;");NG.addStyleRule(".ng-can-drop, .ng-move-drop, .ng-copy-drop, .ng-link-drop","background-color:#129301;");NG.addStyleRule(".ng-bad-drop","background-color:#d00000; padding:2px; z-Index:100; color:white;");NG.addStyleRule(".ng-no-drop","background-color:#dcdcdc;")}};NG.drag.curItem=NG.drag.curZone=NG.drag.tentativeItem=null;NG.drag.setCursor=function(a){NG.drag.runOnce();if(arguments.length==0){if(NG.drag.setCursor.node&&NG.drag.setCursor.node.parentNode){NG.drag.setCursor.node.parentNode.removeChild(NG.drag.setCursor.node)}NG.removeEventListener(document,"mousemove",NG.drag.updateCursor);return}if(!NG.drag.setCursor.node){NG.drag.setCursor.node=document.createElement("div");NG.drag.setCursor.node.appendChild(document.createTextNode(" "));NG.drag.setCursor.node.className="no-drop"}NG.drag.setCursor.node.firstChild.nodeValue=NG.drag.cursorMap[a];NG.drag.setCursor.node.className="ng-drop ng-"+a;if(!NG.drag.setCursor.node.offsetParent){document.body.appendChild(NG.drag.setCursor.node);NG.addEventListener(document,"mousemove",NG.drag.updateCursor)}};NG.drag.updateCursor=function(a){if(!a){a=window.event}if(NG.drag.setCursor.node){NG.drag.setCursor.node.style.top=(a.clientY+5)+"px";NG.drag.setCursor.node.style.left=(a.clientX+8)+"px"}};NG.drag.setCursor.node=null;NG.drag.begin=function(a){if(NG.drag.tentativeItem){NG.drag.curItem=NG.drag.tentativeItem;NG.drag.setCursor("no-drop");NG.drag.curItem.ondragstart(a)}if(document.selection){document.selection.empty()}NG.removeEventListener(document,"mousemove",NG.drag.begin)};NG.drag.enterZone=function(a,b){if(!NG.drag.curItem){return}if(!b){b=window.event}if(a.canDrop(b)){if(NG.drag.curZone&&a!=NG.drag.curZone){NG.drag.curZone.out(b)}NG.drag.setCursor("can-drop");NG.drag.curZone=a;NG.drag.overCurZone=function(c){a.over(c)};NG.addEventListener(document,"keydown",NG.drag.overCurZone);NG.addEventListener(document,"keyup",NG.drag.overCurZone);a.over(b)}else{NG.drag.setCursor("bad-drop")}NG.stopPropagation(b)};NG.drag.leaveZone=function(a,b){if(!NG.drag.curItem){return}if(NG.drag.curZone==a){if(!b){b=window.event}NG.removeEventListener(document,"keydown",NG.drag.overCurZone);NG.removeEventListener(document,"keyup",NG.drag.overCurZone);NG.drag.overCurZone=function(){};a.out(b);NG.drag.curZone=null;NG.drag.setCursor("no-drop")}};NG.drag.dropInZone=function(a,b){if(!b){b=window.event}if(NG.drag.curItem&&a.canDrop(b)){NG.drag.curZone=a;NG.drag.curZone.drop(b);NG.drag.curItem.ondrop(b)}NG.drag.cancel(b);NG.stopPropagation(b)};NG.drag.cancel=function(a){if(!a){a=window.event}if(NG.drag.curZone){NG.drag.curZone.out(a)}if(NG.drag.curItem){NG.drag.curItem.ondragend(a)}NG.removeEventListener(document,"mouseup",NG.drag.cancel);NG.removeEventListener(document,"mousemove",NG.drag.begin);NG.removeEventListener(document,"keydown",NG.drag.overCurZone);NG.removeEventListener(document,"keyup",NG.drag.overCurZone);NG.drag.setCursor();NG.drag.curItem=NG.drag.curZone=NG.drag.tentativeItem=null};NG.drag.item=function(a){this.type=a;this.ondragstart=function(b){};this.ondragend=function(b){};this.ondrop=function(b){}};NG.drag.zone=function(){};NG.drag.zone.prototype.canDrop=function(a){return false};NG.drag.zone.prototype.over=function(a){};NG.drag.zone.prototype.out=function(a){};NG.drag.zone.prototype.drop=function(a){};NG.drag.zone.prototype.attach=function(a){var b=this;NG.addEventListener(a,"mouseover",function(c){NG.drag.enterZone(b,c)});NG.addEventListener(a,"mouseout",function(c){NG.drag.leaveZone(b,c)});NG.addEventListener(a,"mouseup",function(c){NG.drag.dropInZone(b,c)})};NG.tree=function(){this.collections={};this.newCollections=this.instructions=this.canDropList=[];this.node=this.focusedItem=this.editingItem=null;this.layers=[NG.tree.layers.toggle,NG.tree.layers.label];this.hooks={};this.isEditable=this.isDraggable=this.canAppearMultipleTimesInParent=false;this.canCreate=this.isCopyable=this.isMoveable=this.isLinkable=this.canMultiFocus=false;this.linkOnNotCopyable=false;this.deepCopy=true;this.dragName="NG.tree.item";this.dataurl=null;this.saveurl=null;this.ajaxq=[];this.ajaxqp=false};NG.tree.prototype.qajax=function(a){if(this.saveurl===null){return}this.ajaxq.push(a);this.flush_ajaxq()};NG.tree.prototype.flush_ajaxq=function(){if(!this.ajaxqp&&this.ajaxq.length>0){this.ajaxqp=true;var h=["pk","apk","rpk","cpk"];var j=["pos","label"];var c=this.ajaxq[0];var d=new NGUrl(isDef(typeof c.url)?c.url:this.saveurl);for(var e=0;e<h.length;e++){if(isDef(typeof c[h[e]])){d.addArgument(h[e],ifnull(c[h[e]].pk,"\\N"))}}for(var e=0;e<j.length;e++){if(isDef(typeof c[j[e]])){d.addArgument(j[e],c[j[e]])}}var g=new NG.AJAX(d.toString());var b=this;g.setResponseHandler(function(a){b.flush_ajaxq_success(a)},200);g.setResponseHandler(function(a){b.flush_ajaxq_failure(a)},"");g.send()}};NG.tree.prototype.flush_ajaxq_success=function(c){var b=this.ajaxq.shift();if(isDef(typeof b.response)){b.response(c)}this.ajaxqp=false;this.flush_ajaxq()};NG.tree.prototype.flush_ajaxq_failure=function(c){this.ajaxq.shift();this.ajaxqp=false;this.reload();var b=[];if(c&&c.responseXML){var d=c.responseXML.getElementsByTagName("error");for(var a=0;a<d.length;a++){if(d[a].firstChild.nodeType==3){b.push(d[a].firstChild.nodeValue)}}}if(b.length==0){b.push("We were unable to update the server with your changes due to an unknown problem")}alert("- "+b.join("\n- "))};NG.tree.prototype.addCollection=function(e,d,b){var f=new NG.tree.collection(e,d,b);if(f.pk!==null){this.collections[e]=f}else{this.newCollections[(f.newOffset=this.newCollections.length)]=f}var a=this;f.getTree=function(){return a};return f};NG.tree.prototype.getRootItem=function(){if(!this.rootItem){var a=this;var b=new NG.tree.collection(null,null);b.isComplete=false;b.getTree=function(){return a};this.rootItem=new NG.tree.item(b);this.rootItem.getLayers=function(){return a.layers};this.rootItem.refresh=function(){a.refresh()};this.rootItem.expand=this.rootItem.collapse=this.rootItem.focus=this.rootItem.blur=function(){};this.rootItem.isVisible=function(){return true};this.rootItem.isExpanded=true}return this.rootItem};NG.tree.prototype.getNode=function(){if(!this.node){this.node=document.createElement("ul");for(var a=0;a<this.getRootItem().children.length;a++){this.node.appendChild(this.getRootItem().children[a].getNode())}this.node.onselectstart=function(){return false}}return this.node};NG.tree.prototype.addHook=function(b,a){if(!isDef(typeof this.hooks[b])){this.hooks[b]=[]}this.hooks[b].push(a)};NG.tree.prototype.applyHooks=function(d,c,a){if(isDef(typeof this.hooks[c])){for(var b=0;b<this.hooks[c].length;b++){this.hooks[c][b].apply(d,a)}}};NG.tree.prototype.refresh=function(){if(!this.node){return}var a=this.node.parentNode;a.removeChild(this.node);this.node=null;this.attach(a)};NG.tree.prototype.focusItem=function(a){if(this.focusedItem===a){return}if(this.editingItem){this.editingItem.stopEdit()}this.editingItem=null;if(this.focusedItem){this.focusedItem.blur()}if(a===this.getRootItem()){if(a.children.length==0){return}a=a.children[0]}a.focus();this.focusedItem=a;a.applyHooks("focus");NG.ContextMenu.closeAll()};NG.tree.prototype.editItem=function(a){if(this.editingItem){this.editingItem.stopEdit()}this.editingItem=a;if(a){a.startEdit()}};NG.tree.prototype.i=function(c,b,a){this.addCollection(c,b,a)};NG.tree.prototype.l=function(b){var c=this.getRootItem().getCollection();if(b!==null&&isDef(typeof this.collections[b])){c=this.collections[b]}for(var a=1;a<arguments.length;a++){if(isDef(typeof this.collections[arguments[a]])){c.linkChild(this.collections[arguments[a]])}}};NG.tree.prototype.addNew=function(){if(this.focusedItem&&this.focusedItem.isExpanded){return this.focusedItem.addNew()}if(this.focusedItem){return this.focusedItem.getParent().addNew(this.focusedItem.parentOffset+1)}return this.getRootItem().addNew()};NG.tree.prototype.add=function(c,b,a){return this.getRootItem().add(c,b,a)};NG.tree.prototype.attach=function(a){a.appendChild(this.getNode())};NG.tree.prototype.reattach=function(){if(NG.ua.isEng("MSIE")){var a=this.getNode();a.parentNode.appendChild(a.parentNode.removeChild(a))}};NG.tree.prototype.reload=function(){this.getRootItem().reload()};NG.tree.prototype.setAutoReload=function(a){this.getRootItem().setAutoReload(a)};NG.tree.collection=function(c,b,a){this.pk=c;this.newOffset=null;this.label=b;this.items=[];this.state=0;this.dataurl=null;this.autoReload=null;this.autoReloadSecs=null;this.options=(arguments.length>2&&isObj(a)?a:{});this.isComplete=(!isDef(typeof this.options.complete)||this.options.complete?true:false)};NG.tree.collection.prototype.getTree=function(){return null};NG.tree.collection.prototype.getDataUrl=function(){this.applyHooks("dataurl");var a=new NGUrl(this.dataurl===null?this.getTree().dataurl:this.dataurl);if(this.pk!==null){a.addArgument("pk",this.pk,true)}return a.toString()};NG.tree.collection.prototype.hasAncestor=function(b){if(this===b){return true}for(var a=0;a<this.items.length;a++){if(this.items[a].getParent()&&this.items[a].getParent().getCollection().hasAncestor(b)){return true}}return false};NG.tree.collection.prototype.copyChild=function(b,c,a){if(this.hasAncestor(b)){return false}if(arguments.length<3){var a="Copy of "}return this._copyChild(b,c,a)};NG.tree.collection.prototype._copyChild=function(d,f,b){if(this.items.length==0||d.items.length==0){return true}var e=this.getTree().addCollection(null,b+d.label);if(this.linkChild(e,f)){if(this.getTree().deepCopy){for(var a=0;a<d.items[0].children.length;a++){e.copyChild(d.items[0].children[a].getCollection(),a,"")}}else{for(var a=0;a<d.items[0].children.length;a++){e.linkChild(d.items[0].children[a].getCollection(),a)}}return true}return false};NG.tree.collection.prototype.linkChild=function(b,c){this.isComplete=true;if(this.items.length==0){return true}if(arguments.length<2){var c=this.items[0].children.length}if(this.hasAncestor(b)){return false}for(var a=0;a<this.items.length;a++){this.items[a].attachCollection(b,c)}return true};NG.tree.collection.prototype.removeChild=function(b){if(this.items.length==0){return}for(var a=0;a<this.items.length;a++){this.items[a].detachCollection(b)}};NG.tree.collection.prototype.startDrag=function(){for(var b=0;b<this.items.length;b++){NG.addClass(this.items[b].getNode(),"drag");if(this.items[b].isExpanded){for(var a=0;a<this.items[b].children.length;a++){this.items[b].children[a].getCollection().startDrag()}}}};NG.tree.collection.prototype.stopDrag=function(){for(var b=0;b<this.items.length;b++){NG.delClass(this.items[b].getNode(),"drag");if(this.items[b].isExpanded){for(var a=0;a<this.items[b].children.length;a++){this.items[b].children[a].getCollection().stopDrag()}}}};NG.tree.collection.prototype.refresh=function(){for(var a=0;a<this.items.length;a++){this.items[a].refresh()}};NG.tree.collection.prototype.select=function(b){if(arguments.length==0){b=(this.state+1)%2}for(var a=0;a<this.items.length;a++){this.items[a].select(b)}};NG.tree.collection.prototype.setLabel=function(a){if(a==this.label||a.length==0){return}this.label=a;this.refresh();this.getTree().qajax({pk:this,label:a});this.applyHooks("changed")};NG.tree.collection.prototype.applyHooks=function(b,a){if(arguments.length<2){var a=[]}this.getTree().applyHooks(this,b,a)};NG.tree.item=function(b){this.children=[];this.isExpanded=(isDef(typeof b.options.exp)?b.options.exp:false);var d=b;this.getCollection=function(){return d};this.getParent=function(){return null};this.node=this.parentOffset=this.last=this.editNode=this.loadNode=null;if(d.items.length>0){for(var a=0;a<d.items[0].children.length;a++){this.attachCollection(d.items[0].children[a].getCollection(),a)}}if(d){d.items.push(this)}this._isfound=false;this.focusTeam=[]};NG.tree.item.prototype.getValues=function(){var a=[this.getValue()];for(var b=0;b<this.focusTeam.length;b++){a.push({value:this.focusTeam[b].pk,label:this.focusTeam[b].label})}return a};NG.tree.item.prototype.getValue=function(){var a=this.getCollection();return{value:a.pk,label:a.label}};NG.tree.item.prototype.copyChild=function(a,b){if(arguments.length<2||b>this.children.length){var b=this.children.length}if(this.getCollection().copyChild(a.getCollection(),b)){return this.last}return false};NG.tree.item.prototype.linkChild=function(a,b){if(arguments.length<2||b>this.children.length){var b=this.children.length}if(this.getCollection().linkChild(a.getCollection(),b)){return this.last}return false};NG.tree.item.prototype.moveChild=function(a,b){if(arguments.length<2||b>this.children.length){var b=this.children.length}if(this.getCollection().linkChild(a.getCollection(),b)){a.getParent().detachCollection(a.getCollection(),this.last);return this.last}return false};NG.tree.item.prototype.removeChild=function(a){this.getCollection().removeChild(a.getCollection())};NG.tree.item.prototype.getLayers=function(){return(this.layers?this.layers:this.getParent().getLayers())};NG.tree.item.prototype.getTree=function(){return this.getCollection().getTree()};NG.tree.item.prototype.applyHooks=function(b,a){if(arguments.length<2){var a=[]}this.getTree().applyHooks(this,b,a)};NG.tree.item.prototype.attachCollection=function(c,d){for(var b=d;b<this.children.length;b++){this.children[b].parentOffset++}var a=this;this.last=new NG.tree.item(c);this.last.getParent=function(){return a};this.children.splice(d,0,this.last);this.last.parentOffset=d;if(!this.canAppearMultipleTimesInParent){this.detachCollection(c,this.last)}this.refresh();return this.last};NG.tree.item.prototype.detachCollection=function(d,a){for(var c=d.items.length-1;c>=0;c--){if(d.items[c].getParent()==this&&d.items[c]!==a){this.children.splice(d.items[c].parentOffset,1);for(var b=d.items[c].parentOffset;b<this.children.length;b++){this.children[b].parentOffset--}d.items.splice(c,1)}}this.refresh()};NG.tree.item.prototype.setAutoReload=function(b){if(this.getCollection().autoReload){clearInterval(this.getCollection().autoReload)}if(arguments.length>0&&b>0){var a=this;var c=function(){if(!a.getTree().ajaxqp&&a.isVisible()){a.reload()}};if(!this.getCollection().isComplete){setTimeout(c,0)}this.getCollection().autoReload=setInterval(c,b*1000)}};NG.tree.item.prototype.reload=function(){var h=this.getCollection().getDataUrl();if(h===null){return}var c=this;var b=new NG.AJAX(h);var e=function(d){var a=d.responseXML.getElementsByTagName("tree")[0];c.hideLoading();if(a){c.load(a)}if(c.getCollection().isComplete){c.expand()}if(c.getCollection().autoReloadSecs>0){c.setAutoReload(c.getCollection().autoReloadSecs);c.getCollection().autoReloadSecs=null}};b.setResponseHandler(e,200);b.setResponseHandler(function(){c.hideLoading()},null);this.hideLoading();if(!this.getCollection().isComplete){var g=(this.getTree().getRootItem()==this?this.getTree().getNode().parentNode:this.getNode());g.appendChild(this.loadNode=document.createElement("div"));g.lastChild.className="ngcms-tree-loading";g.lastChild.appendChild(document.createTextNode("Loading..."))}b.send()};NG.tree.item.prototype.hideLoading=function(){if(this.loadNode&&this.loadNode.parentNode){this.loadNode.parentNode.removeChild(this.loadNode)}this.loadNode=null};NG.tree.item.prototype.load=function(k){var m=this.getCollection();for(var g=0;g<this.children.length;g++){this.children[g]._isfound=false}for(var e,p,b=0,q,l,d,a,h=0;h<k.childNodes.length;h++){d=k.childNodes[h];if(d.nodeType==1&&d.nodeName=="item"){l=false;e=d.getAttribute("pk");p=d.getAttribute("label");a=[];if(d.getAttribute("theme")){a.theme=d.getAttribute("theme")}for(var g=0;l==false&&g<this.children.length;g++){if(this.children[g].getCollection().pk==e){if(p!=this.children[g].getCollection().label){this.children[g].getCollection().label=p;this.children[g].getCollection().refresh()}if(this.children[g].parentOffset!=b){this.linkChild(this.children[g],b)}l=true}}if(!l){if(!isDef(typeof this.getTree().collections[e])){this.getTree().addCollection(e,p,a)}this.getCollection().linkChild(this.getTree().collections[e],b);if(this.getTree().focusedItem==this){this.expand()}}if(d.getAttribute("focus")){this.getTree().focusItem(this.children[b])}this.children[b].load(d);this.children[b]._isfound=true;if(d.getAttribute("exp")){this.children[b].expand()}b++}}for(var g=0;g<this.children.length;g++){if(!this.children[g]._isfound){this.getCollection().removeChild(this.children[g].getCollection())}}m.isComplete=(k.getAttribute("complete")=="no"?false:true);if(isStr(k.getAttribute("src"))){m.dataurl=k.getAttribute("src")}if(k.getAttribute("interval")>0){m.autoReloadSecs=k.getAttribute("interval")}};NG.tree.item.prototype.add=function(d,b,a){var c=this.getTree();if(!isDef(typeof c.collections[d])){this.getTree().addCollection(d,b,a)}this.getCollection().linkChild(c.collections[d],this.children.length);return this.last};NG.tree.item.prototype.addNew=function(e){if(!this.getTree().canCreate){return}if(arguments.length==0){var e=this.children.length}var d=this.getTree().addCollection(null,"New item");this.getCollection().linkChild(d,e);var b=function(f){try{var c=f.responseXML.getElementsByTagName("pkalloc")[0].getAttribute("pk")}catch(g){return}d.pk=c;d.getTree().collections[c]=d};this.getTree().qajax({apk:this.getCollection(),pos:e,response:b});this.last.applyHooks("changed");this.getTree().focusItem(this.last);var a=d.label;d.label="";this.last.startEdit();d.label=a};NG.tree.item.prototype.getNode=function(){if(!this.node){this.node=document.createElement("li");var h=this.getCollection();var g,b=this.getLayers();this.node.appendChild(g=document.createElement("div"));for(var e=0;e<b.length;e++){g.appendChild(document.createElement("div"));g=g.lastChild;NG.addClass(g,"layer"+e);b[e].apply(this,[g])}if(this.children.length>0||!h.IsComplete){if(this.isExpanded){this.isExpanded=false;this.expand()}else{if(this.children.length>0){NG.addClass(this.node.firstChild,"collapsed")}}}NG.addClass(this.node.firstChild,"state"+h.state);if(isStr(h.options.theme)){NG.addClass(this.node.firstChild,"tree-theme-"+h.options.theme)}var a=this;var f=new NG.tree.dropZone();f.getItem=function(){return a};f.attach(this.node.firstChild);this.applyHooks("node")}return this.node};NG.tree.item.prototype.refresh=function(){if(!this.node||!this.node.parentNode){return}var b=this.getNode().parentNode;var a=this.getNode().nextSibling;b.removeChild(this.getNode());this.node=this.editNode=null;if(a){b.insertBefore(this.getNode(),a)}else{b.appendChild(this.getNode())}if(this.getTree().focusedItem===this){this.focus()}};NG.tree.item.prototype.expand=function(){if(this.isExpanded||(this.children.length==0&&this.getCollection().isComplete==true)){return}if(!this.getCollection().isComplete){return this.reload()}this.getNode().appendChild(document.createElement("ul"));for(var a=0;a<this.children.length;a++){this.getNode().lastChild.appendChild(this.children[a].getNode())}NG.replaceClass(this.getNode().firstChild,"collapsed","expanded");this.getTree().reattach();this.isExpanded=true;this.applyHooks("expand")};NG.tree.item.prototype.collapse=function(){if(!this.isExpanded||this.children.length==0){return}this.getNode().removeChild(this.getNode().lastChild);NG.replaceClass(this.getNode().firstChild,"expanded","collapsed");this.getTree().reattach();this.isExpanded=false;this.applyHooks("collapse")};NG.tree.item.prototype.toggle=function(){if(this.isExpanded){this.collapse()}else{this.expand()}};NG.tree.item.prototype.makeVisible=function(){this.getParent().makeVisible();this.getParent().expand()};NG.tree.item.prototype.isVisible=function(){return this.getParent().isExpanded&&this.getParent().isVisible()};NG.tree.item.prototype.focus=function(b){NG.addClass(this.getNode().firstChild,(b?"focused-ancestor":"focused"));if(!b){var d=this.getCollection();for(var a=0;a<d.items.length;a++){if(d.items[a]!==this){NG.addClass(d.items[a].getNode().firstChild,"focused-instance")}}}this.getParent().focus(true);this.getParent().expand()};NG.tree.item.prototype.onFocusTeam=function(b){var d=b.getCollection();for(var a=0;a<this.focusTeam.length;a++){if(d.pk==this.focusTeam[a].pk){return a}}return false};NG.tree.item.prototype.teamFocus=function(){var b=this.getTree().focusedItem;if(b){if(b.onFocusTeam(this)!==false){this.teamBlur();return false}else{var d=this.getCollection();NG.addClass(this.getNode().firstChild,"teamfocused");for(var a=0;a<d.items.length;a++){if(d.items[a]!==this){NG.addClass(d.items[a].getNode().firstChild,"teamfocused-instance")}}b.focusTeam.push(d)}}else{this.getTree().focusItem(this)}return true};NG.tree.item.prototype.teamBlur=function(){var d,b=this.getTree().focusedItem;if(b&&(d=b.onFocusTeam(this))!==false){var e=this.getCollection();for(var a=0;a<e.items.length;a++){NG.delClass(e.items[a].getNode().firstChild,"teamfocused","teamfocused-instance")}b.focusTeam.splice(d,1)}};NG.tree.item.prototype.blur=function(){NG.delClass(this.getNode().firstChild,"focused","focused-ancestor");var e=this.getCollection();for(var d=0;d<e.items.length;d++){if(e.items[d]!==this){NG.delClass(e.items[d].getNode().firstChild,"focused-instance")}for(var b=0;b<e.items[d].focusTeam.length;b++){for(var a=0;a<e.items[d].focusTeam[b].items.length;a++){NG.delClass(e.items[d].focusTeam[b].items[a].getNode().firstChild,"teamfocused","teamfocused-instance")}}e.items[d].focusTeam=[]}this.getParent().blur();this.applyHooks("blur")};NG.tree.item.prototype.select=function(b){this.getCollection().state=b;var c=this.getParent();var a=(c?this.getSiblingState():b);if(a==b&&c){this.getParent().select(b)}else{this.setState(b);if(a==0.5){while(c){NG.replaceClass(c.getNode().firstChild,/state[0-9]+/,"state1-ancestor");c.getCollection().state=0;c=c.getParent()}}else{while(c){c.getCollection().state=a;NG.replaceClass(c.getNode().firstChild,/state[0-9]+/,"state"+a);c=c.getParent()}}}};NG.tree.item.prototype.setState=function(b){this.getCollection().state=b;NG.replaceClass(this.getNode().firstChild,/state[0-9]+/,"state"+b);for(var a=0;a<this.children.length;a++){this.children[a].setState(b)}};NG.tree.item.prototype.getSiblingState=function(){var b=null;var c=this.getParent();for(var a=0;a<c.children.length;a++){if(b===null){b=c.children[a].getCollection().state}else{if(b!=c.children[a].getCollection().state){return 0.5}}}return b};NG.tree.item.prototype.getNextSibling=function(){if(this.parentOffset<this.getParent().children.length-1){return this.getParent().children[this.parentOffset+1]}return null};NG.tree.item.prototype.getPreviousSibling=function(){if(this.parentOffset>0){return this.getParent().children[this.parentOffset-1]}return null};NG.tree.item.prototype.startEdit=function(){if(this.editNode){return}var a=this;var e=this.getNode();var d=this.getCollection();while(e.firstChild&&e.firstChild.nodeType==1){e=e.firstChild}var b=document.createElement("span");b.innerHTML='<input type="text" class="edit" />';this.editNode=b.firstChild;this.editNode.value=d.label;NG.addEventListener(this.editNode,"blur",function(c){a.stopEdit();NG.stopPropagation(c)});NG.addEventListener(this.editNode,"keypress",function(c){if(!c){c=window.event}if(c.keyCode==13){a.stopEdit()}else{if(c.keyCode==27){a.cancelEdit()}}});this.getNode().appendChild(this.editNode);NG.addClass(this.getNode().firstChild,"editlabel");this.editNode.focus()};NG.tree.item.prototype.stopEdit=function(){if(this.editNode){this.getCollection().setLabel(this.editNode.value);this.cancelEdit()}};NG.tree.item.prototype.cancelEdit=function(){if(this.editNode){this.refresh();this.editNode=null}if(this.getTree().editingItem===this){this.getTree().editingItem=null}};NG.tree.layers={label:function(e){var a=this;var d=this.getTree();var f=this.getCollection();NG.addEventListener(e,"click",function(c){a.expand();NG.stopPropagation(c)});NG.addEventListener(e.parentNode,"mousedown",function(h){var c=null;if(d.canMultiFocus&&h.ctrlKey&&d.focusedItem){if(a.teamFocus()){c=d.focusedItem}}else{if(d.canMultiFocus&&d.focusedItem&&d.focusedItem!==a&&d.focusedItem.onFocusTeam(a)){c=d.focusedItem}else{d.focusItem(a);c=a}}if(c&&d.isDraggable&&d.editingItem!==c){var g=new NG.drag.item(d.dragName);g.item=c;g.ondragstart=function(){c.getCollection().startDrag();for(var i=0;i<c.focusTeam.length;i++){c.focusTeam[i].startDrag()}};g.ondragend=function(){c.getCollection().stopDrag();for(var i=0;i<c.focusTeam.length;i++){c.focusTeam[i].stopDrag()}};NG.drag(g)}NG.preventDefault(h);NG.stopPropagation(h)});e.appendChild(document.createTextNode(f.label));if(d.isEditable){NG.addEventListener(e.parentNode,"dblclick",function(c){d.editItem(a);NG.stopPropagation(c)});var b=[];if(isDef(typeof d.hooks.edit)){b.push({label:"Edit",func:function(){a.applyHooks("edit")}})}if(isDef(typeof d.hooks["delete"])){b.push({label:"Delete",func:function(){a.applyHooks("delete")}})}if(b.length>0){NG.ContextMenu.attach(e.parentNode,b)}}},icon:function(b){var a=this;NG.addEventListener(b,"click",function(c){a.expand();NG.stopPropagation(c)})},toggle:function(b){var a=this;NG.addEventListener(b,"click",function(c){a.toggle();NG.stopPropagation(c)})},select:function(b){var a=this.getCollection();NG.addEventListener(b,"click",function(c){a.select();NG.stopPropagation(c)})}};NG.tree.dropZone=function(){};NG.tree.dropZone.prototype=new NG.drag.zone();NG.tree.dropZone.prototype.direction="e";NG.tree.dropZone.prototype.isNativeDrop=function(){return(NG.drag.curItem.type==this.getItem().getTree().dragName&&NG.drag.curItem.item&&NG.drag.curItem.item.getTree&&NG.drag.curItem.item.getTree()==this.getItem().getTree())};NG.tree.dropZone.prototype.canDrop=function(b){if(this.isNativeDrop()){var a=this.getItem().getTree();if(NG.drag.curItem.item.focusTeam.length>1){return false}if(b.ctrlKey&&b.shiftKey&&!a.isLinkable){return false}else{if(b.ctrlKey&&!b.shiftKey&&!a.isCopyable&&(!a.linkOnNotCopyable||!a.isLinkable)){return false}else{if(!b.ctrlKey&&!b.shiftKey&&!a.isMoveable){return false}else{if(this.getItem().getCollection().hasAncestor(NG.drag.curItem.item.getCollection())){return false}}}}return true}else{return(this.getItem().getTree().canDropList.search(NG.drag.curItem.type)>-1)}};NG.tree.dropZone.prototype.over=function(d){this.out(d);var f=this.isNativeDrop();if(f){var j=this.getItem().getNode();var g=NG.getPagePos(j).y;var c=j.offsetHeight/4;if(d.clientY<g+c&&this.getItem().getPreviousSibling()!=NG.drag.curItem.item){this.direction="n"}else{if(d.clientY>g+(3*c)&&this.getItem().getNextSibling()!=NG.drag.curItem.item){this.direction="s"}else{this.direction="e";if(!this.getItem().getCollection().isComplete){this.getItem().reload()}if(this.getItem().children.length>0&&!this.getItem().isExpanded){var b=this.getItem();setTimeout(function(){if(/(^| )draghover\-e( |$)/.test(b.getNode().firstChild.className)){b.expand()}},1000)}}}}var a=this.getItem().getTree();if(d.ctrlKey&&d.shiftKey&&(!f||a.isLinkable)){NG.drag.setCursor("link-drop")}else{if(d.ctrlKey&&!d.shiftKey&&(!f||a.isCopyable||(a.linkOnNotCopyable&&a.isLinkable))){NG.drag.setCursor("copy-drop")}else{if(!d.ctrlKey&&!d.shiftKey&&(!f||a.isMoveable)){NG.drag.setCursor("move-drop")}else{NG.drag.setCursor("bad-drop")}}}NG.addClass(this.getItem().getNode().firstChild,"draghover-"+this.direction)};NG.tree.dropZone.prototype.out=function(a){NG.delClass(this.getItem().getNode().firstChild,/draghover\-[nse]/)};NG.tree.dropZone.prototype.drop=function(h){if(this.isNativeDrop()){switch(this.direction){case"n":var g=this.getItem().getParent();var i=this.getItem().parentOffset;break;case"s":var g=this.getItem().getParent();var i=this.getItem().parentOffset+1;break;case"e":var g=this.getItem();var i=this.getItem().children.length;break;default:return}var c=g.getTree();if(h.ctrlKey&&c.isLinkable&&(h.shiftKey||(c.linkOnNotCopyable&&!c.isCopyable))){var b=g.linkChild(NG.drag.curItem.item,i);c.qajax({pk:NG.drag.curItem.item.getCollection(),apk:g.getCollection(),pos:i})}else{if(h.ctrlKey&&!h.shiftKey&&c.isCopyable){var b=g.copyChild(NG.drag.curItem.item,i);var d=function(e){c.reload()};c.qajax({pk:NG.drag.curItem.item.getCollection(),cpk:g.getCollection(),pos:i,response:d})}else{if(!h.ctrlKey&&!h.shiftKey&&c.isMoveable){var a=NG.drag.curItem.item.getParent().getCollection();var b=g.moveChild(NG.drag.curItem.item,i);c.qajax({pk:NG.drag.curItem.item.getCollection(),rpk:a,apk:g.getCollection(),pos:i})}else{return}}}g.getCollection().refresh();if(b){b.getTree().focusItem(b)}}else{this.getItem().getCollection().applyHooks("external"+(h.ctrlKey?"copy":"move"),[this.getItem(),NG.drag.curItem])}};NG.tree.dropZone.prototype.attach=function(a){var b=this;NG.addEventListener(a,"mouseover",function(c){if(NG.drag.curZone==b){b.over(c)}});NG.drag.zone.prototype.attach.apply(this,[a])};NG.menu=function(){this.children=[];this.last=null;this.node=null;this.focusedItem=null;this.expandedItem=null;this.layers=[NG.menu.layers.select,NG.menu.layers.label];this.isRoot=false};NG.menu.prototype.add=function(c,b,a){return this.addItem(new NG.menu.item(c,b,a))};NG.menu.prototype.attach=function(a){this.isRoot=true;a.appendChild(this.getNode())};NG.menu.prototype.addItem=function(b){var a=this;b.getTree=function(){return a};b.parentOffset=this.children.length;this.children.push(b);this.last=this.children[this.children.length-1];return this.last};NG.menu.prototype.focusItem=function(a){if(this.focusedItem){this.focusedItem.blur()}a.focus();this.focusedItem=a};NG.menu.prototype.collapseItem=function(){if(this.expandedItem){this.expandedItem.collapse()}};NG.menu.prototype.collapseAll=function(){for(var a=0;a<this.children.length;a++){if(this.children[a].isExpanded){this.children[a].collapse()}}if(this.focusedItem){this.focusedItem.blur()}if(this._ca){NG.removeEventListener(document,"mouseover",this._ca);this._ca=false}};NG.menu.prototype.getNode=function(){if(!this.node){this.node=document.createElement("div");for(var a=0;a<this.children.length;a++){this.node.appendChild(this.children[a].getNode())}this.node.onselectstart=function(){return false};NG.addEventListener(this.node,"mouseover",NG.stopPropagation)}return this.node};NG.menu.prototype.refresh=function(){var a=this.getNode().parentNode;a.removeChild(this.node);this.node=null;this.attach(a)};NG.menu.prototype.getProp=function(a){return this[a]};NG.menu.layers={label:function(b){var a=this;NG.addEventListener(b,"mouseover",function(c){NG.ContextMenu.closeAll();if(a.getTree()){a.getTree().focusItem(a)}a.expand(c);NG.stopPropagation(c)});if(this.label){if(isStr(this.label)){b.appendChild(document.createTextNode(this.label))}else{b.appendChild(this.label)}}},select:function(b){var a=this;NG.addEventListener(b,"click",function(c){a.select();NG.stopPropagation(c)})}};NG.menu.item=function(c,b,a){this.pk=c;this.label=b;this.isCurrent=a;this.children=[];this.node=null;this.isExpanded=false;this.state=0;this.parentOffset=null};NG.menu.isCurrent=function(a){var b=new NGUrl(window.location);var a=new NGUrl(a);if(a.path==b.path){return true}else{return false}};NG.menu.item.prototype.getNode=function(){if(!this.node){this.node=document.createElement("div");var c,a=this.getProp("layers");c=this.node;for(var b=0;b<a.length;b++){c.appendChild(document.createElement("div"));c=c.lastChild;NG.addClass(c,"layer"+b);if(this.isCurrent==true){NG.addClass(c,"selected")}a[b].apply(this,[c])}if(this.children.length>0){if(this.getParent()){this.node.appendChild(ar=document.createElement("div"));NG.addClass(ar,"arrow");ar.appendChild(document.createTextNode("►"))}if(this.isExpanded){this.isExpanded=false;this.expand()}else{NG.addClass(this.node.firstChild,"collapsed")}}NG.addEventListener(this.node,"mouseover",NG.stopPropagation)}return this.node};NG.menu.item.prototype.getParent=function(){return null};NG.menu.item.prototype.getTree=function(){return null};NG.menu.item.prototype.getNextSibling=function(){var a=this.getParent();if(!a){a=this.getTree()}if(a&&this.parentOffset<a.children.length-1){return a.children[this.parentOffset+1]}return null};NG.menu.item.prototype.getPreviousSibling=function(){var a=this.getParent();if(!a){a=this.getTree()}if(a&&this.parentOffset>0){return a.children[this.parentOffset-1]}return null};NG.menu.item.prototype.refresh=function(){var b=this.getNode().parentNode;var a=this.getNode().nextSibling;b.removeChild(this.getNode());this.node=null;if(a){b.insertBefore(this.getNode(),a)}else{b.appendChild(this.getNode())}};NG.menu.item.prototype.expand=function(d){var b=this.getTree();if(!b._ca){b._ca=function(h){b.collapseAll(h)};NG.addEventListener(document,"mouseover",b._ca)}if(d&&b.expandedItem&&b.expandedItem!=this&&(!this.getParent()||(b.expandedItem&&this.getParent()==b.expandedItem.getParent()))){var c=b.expandedItem.getParent();b.collapseItem();if(c){b.expandedItem=c}}if(this.isExpanded||this.children.length==0){return}NG.hideZdisregard();var g=document.createElement("div");var f=this.getNode();NG.addClass(g,"children");f.appendChild(g);for(var a=0;a<this.children.length;a++){f.lastChild.appendChild(this.children[a].getNode())}NG.replaceClass(f.firstChild,"collapsed","expanded");this.isExpanded=true;if(b){b.expandedItem=this}};NG.menu.item.prototype.collapse=function(){if(!this.isExpanded||this.children.length==0){return}for(var b=0;b<this.children.length;b++){if(this.children[b].isExpanded){this.children[b].collapse()}}var a=this.getTree();var c=this.getNode();c.removeChild(c.lastChild);NG.replaceClass(c.firstChild,"expanded","collapsed");this.isExpanded=false;if(a){a.expandedItem=null}NG.showZdisregard()};NG.menu.item.prototype.toggle=function(){if(this.isExpanded){this.collapse()}else{this.expand()}};NG.menu.item.prototype.focus=function(a){NG.addClass(this.getNode().firstChild,(a?"focused-ancestor":"focused"));var b=this.getParent();if(b){b.focus(true);b.expand()}};NG.menu.item.prototype.blur=function(){NG.delClass(this.getNode().firstChild,/^focused(\-ancestor)?$/);if(this.getParent()){this.getParent().blur()}};NG.menu.item.prototype.select=function(){};NG.menu.item.prototype.addItem=function(b){var a=this;b.getParent=function(){return a};b.getTree=function(){return a.getTree()};b.parentOffset=this.children.length;this.children.push(b);this.last=this.children[this.children.length-1];if(b.isCurrent){this.setCurrent()}return this.last};NG.menu.item.prototype.setCurrent=function(){this.isCurrent=true;var a=this.getParent();if(a){a.setCurrent()}};NG.menu.item.prototype.getProp=function(a){if(isDef(typeof this[a])){return this[a]}if(this.getParent()){return this.getParent().getProp(a)}return this.getTree().getProp(a)};NG.menu.item.prototype.add=NG.menu.prototype.add;NG.ContextMenu=function(b){this.node=null;this.focusedItem=null;this.items=[];this.targetNode=null;var a=this;if(b){this.loadSpec(b)}this.attachFunc=function(c){if(!isObj(c)&&isObj(window.event)){var c=window.event}NG.ContextMenu.closeAll();a.show(c.clientX+document.documentElement.scrollLeft,c.clientY+document.documentElement.scrollTop);a.targetNode=this;NG.stopPropagation(c);NG.preventDefault(c);return false}};NG.ContextMenu.hasRunOnce=false;NG.ContextMenu.runOnce=function(){if(!NG.ContextMenu.hasRunOnce){NG.ContextMenu.hasRunOnce=true;NG.addStyleRule(".context-menu","position:absolute; background-color:#fefefe; border:1px outset; padding:2px; z-Index:100;");NG.addStyleRule(".context-menu-item","padding:1px; padding-left:19px; padding-right:19px; height:16px; line-height:16px; overflow:none; -moz-user-select:none; -khtml-user-select:none; cursor:default; background-repeat:no-repeat; position:relative; white-space:nowrap;");NG.addStyleRule(".context-menu-item-focused","background-color:#cccccc;");NG.addStyleRule(".context-menu-item-disabled","color:#c0c0c0;");NG.addStyleRule(".context-menu-item span","right:2px; font-size:7px; top:1px; position:absolute; line-height:16px;");NG.addStyleRule(".context-menu-item div","top:0px; left:0px; font-size:9px; position:absolute; line-height:16px; width:16px; text-align:center;");NG.addStyleRule(".context-menu-item-disabled img","display:none;");NG.addStyleRule(".context-menu-separator","border-top:1px solid #c0c0c0; line-height:0px; font-size:0px; height:0px; margin-top:3px; margin-bottom:3px;");NG.addEventListener(document,"mousedown",NG.ContextMenu.closeAll)}};NG.ContextMenu.curMenu=null;NG.ContextMenu.prototype.loadSpec=function(d){var b=false;if(this.node&&this.node.parentNode){var a=this.node.offsetLeft;var f=this.node.offsetTop;this.hide();b=true}this.node=null;this.items=[];var c=this;for(var e=0;e<d.length;e++){this.items[e]=new NG.ContextMenu.item(d[e]);this.items[e].offset=e;this.items[e].getMenu=function(){return c}}if(b){this.show(a,f)}};NG.ContextMenu.prototype.getRootMenu=function(){return this};NG.ContextMenu.prototype.getParentItem=function(){return null};NG.ContextMenu.prototype.getNode=function(){if(!this.node){this.node=document.createElement("div");if(NG.ua.isEng("MSIE","6.0")){this.node.style.width="0%"}this.node.className="context-menu";for(var a=0;a<this.items.length;a++){this.node.appendChild(this.items[a].getNode())}}return this.node};NG.ContextMenu.prototype.focusItem=function(b,a){if(this.focusedItem){this.focusedItem.blur(a)}if(b.isDisabled){this.focusedItem=null}else{this.focusedItem=b;this.focusedItem.focus(a)}};NG.ContextMenu.prototype.focusNextItem=function(c){var b=(this.focusedItem?this.focusedItem.offset+1:0);for(var a=b;a<this.items.length;a++){if(!this.items[a].isDisabled&&!this.items[a].isSeparator){return this.focusItem(this.items[a],c)}}};NG.ContextMenu.prototype.focusPrevItem=function(c){var b=(this.focusedItem?this.focusedItem.offset-1:this.items.length-1);for(var a=b;a>=0;a--){if(!this.items[a].isDisabled&&!this.items[a].isSeparator){return this.focusItem(this.items[a],c)}}};NG.ContextMenu.prototype.show=function(a,e,c,b){if(arguments.length<3){c=a}if(arguments.length<4){b=e}var d=this.getRootMenu();if(NG.ContextMenu.curMenu!=d){NG.ContextMenu.closeAll();NG.ContextMenu.curMenu=d}NG.ContextMenu.documentPosition(this.getNode(),a,e,c,b);if(NG.ua.isEng("MSIE")){this.getNode().style.width=this.getNode().offsetWidth+"px";document.body.appendChild(this.getNode())}NG.hideZdisregard()};NG.ContextMenu.documentPosition=function(b,j,h,g,f){if(arguments.length<4){g=j}if(arguments.length<5){f=h}var k=NG.getComputedStyle(b);var a=["offsetHeight","offsetWidth","clientHeight","clientWidth","scrollTop","scrollLeft"];var e={};for(var c=0;c<a.length;c++){e[a[c]]=parseInt(document.documentElement[a[c]])}b.style.left=j+"px";b.style.top=h+"px";document.body.appendChild(b);if(g-b.offsetWidth>e.scrollLeft&&j+b.offsetWidth>e.clientWidth+e.scrollLeft){b.style.left=(g-b.offsetWidth)+"px"}if(f-b.offsetHeight>e.scrollTop&&h+b.offsetHeight>e.clientHeight+e.scrollTop){b.style.top=(f-b.offsetHeight)+"px"}};NG.ContextMenu.prototype.hide=function(){if(this.focusedItem){this.focusedItem.blur();this.focusedItem=null}if(NG.ContextMenu.curMenu==this){NG.ContextMenu.curMenu=null}if(this.getNode().parentNode){this.getNode().parentNode.removeChild(this.getNode())}NG.showZdisregard()};NG.ContextMenu.addContextListener=function(b,a){if(NG.ua.isEng("OPERA")){NG.addEventListener(b,"click",a)}else{if(NG.ua.isApp("Konqueror")){NG.addEventListener(b,"click",a)}else{NG.addEventListener(b,"contextmenu",a)}}};NG.ContextMenu.removeContextListener=function(b,a){NG.removeEventListener(b,"click",a);NG.removeEventListener(b,"contextmenu",a)};NG.ContextMenu.prototype.attach=function(a){NG.ContextMenu.runOnce();NG.ContextMenu.addContextListener(a,this.attachFunc)};NG.ContextMenu.prototype.detach=function(a){NG.ContextMenu.removeContextListener(a,this.attachFunc)};NG.ContextMenu.attach=function(b,a){var d=new NG.ContextMenu(a);d.attach(b);return d};NG.ContextMenu.item=function(a){this.node=null;this.label=a.label;this.confirm=a.confirm;this.isCancel=(a.cancel?true:false);this.isDisabled=(a.disabled?true:false);this.isSeparator=(a.separator?true:false);this.isFlagged=(a.flag?true:false);this.func=a.func;if(a.url){this.url=a.url}this.iconSrc=a.iconsrc;if(a.children){this.childMenu=new NG.ContextMenu(a.children)}else{if(a.childmenu){this.childMenu=a.childmenu}else{this.childMenu=null}}if(this.childMenu){var b=this;this.childMenu.getParentItem=function(){return b};this.childMenu.getRootMenu=function(){return b.getMenu().getRootMenu()}}this.value=a.value;this.offset=null};NG.ContextMenu.item.prototype.getMenu=function(){return null};NG.ContextMenu.item.prototype.getNode=function(){if(!this.node){this.node=document.createElement("div");if(this.isSeparator){this.node.className="context-menu-separator"}else{this.node.className="context-menu-item";if(this.isDisabled){this.node.className+=" context-menu-item-disabled"}if(this.iconSrc){this.node.style.backgroundImage="url("+this.iconSrc+")"}this.node.appendChild(document.createTextNode(this.label));if(this.childMenu){this.node.appendChild(document.createElement("span"));this.node.lastChild.appendChild(document.createTextNode("►"))}if(this.isFlagged){this.isFlagged=false;this.flag(true)}var a=this;NG.addEventListener(this.node,"mousedown",function(b){NG.stopPropagation(b)});NG.addEventListener(this.node,"mouseup",function(b){a.select(b);return NG.preventDefault(b)});NG.addEventListener(this.node,"mouseover",function(b){a.getMenu().focusItem(a,b)});NG.ContextMenu.addContextListener(this.node,function(b){return NG.preventDefault(b)})}}return this.node};NG.ContextMenu.item.prototype.select=function(a){if(this.isDisabled||this.isSeparator||this.childMenu){return}if(this.confirm&&!confirm(this.confirm)){}else{if(this.isCancel){}else{if(this.url){window.location=this.url}else{if(this.func&&isArr(this.func)){this.func[0][this.func[1]]()}else{if(this.func&&isFunc(this.func)){this.func(this,a)}}}}}if(NG.ua.isEng("MSIE")){setTimeout("NG.ContextMenu.closeAll();",0)}else{NG.ContextMenu.closeAll()}};NG.ContextMenu.item.prototype.focus=function(b){this.getNode().className=this.getNode().className.replace(/(^| )context-menu-item-focused( |$)/,"")+" context-menu-item-focused";if(this.childMenu){var a=this.getNode().offsetLeft+this.getMenu().getNode().offsetLeft;var c=this.getNode().offsetTop+this.getMenu().getNode().offsetTop;this.childMenu.targetNode=this.getMenu().targetNode;this.childMenu.show(a+this.getNode().offsetWidth,c,a,c+this.getNode().offsetHeight)}};NG.ContextMenu.item.prototype.blur=function(a){this.getNode().className=this.getNode().className.replace(/(^| )context-menu-item-focused( |$)/,"");if(this.childMenu){this.childMenu.hide()}};NG.ContextMenu.item.prototype.flag=function(a){if(arguments.length==0){a=!this.isFlagged}if(a&&!this.isFlagged){this.getNode().appendChild(document.createElement("div"));this.getNode().lastChild.appendChild(document.createTextNode("✔"))}else{if(!a&&this.isFlagged){this.getNode().removeChild(this.getNode().lastChild)}}this.isFlagged=a};NG.ContextMenu.item.prototype.flagone=function(){var a=this.getMenu();for(var b=0;b<a.items.length;b++){a.items[b].flag(a.items[b]==this)}};NG.ContextMenu.closeAll=function(a){if(NG.ContextMenu.curMenu){NG.ContextMenu.curMenu.hide()}};NG.DOMShuffle=function(b){for(var a=0;a<b.rows[0].cells.length;a++){var d=b.rows[0].cells[a].firstChild;while(d){if(d.nodeType==1){NG.DOMShuffle.install(d)}d=d.nextSibling}}};NG.DOMShuffle.curNode=null;NG.DOMShuffle.markerNode=null;NG.DOMShuffle.width=NG.DOMShuffle.height=NG.DOMShuffle.x=NG.DOMShuffle.y=null;NG.DOMShuffle.install=function(a){var b=a;NG.addEventListener(b,"mousedown",function(c){NG.DOMShuffle.begin(b,c)})};NG.DOMShuffle.begin=function(a,b){if(NG.DOMShuffle.curNode){NG.DOMShuffle.end(b)}NG.DOMShuffle.curNode=a;NG.addEventListener(document,"mousemove",NG.DOMShuffle.move);NG.addEventListener(document,"mouseup",NG.DOMShuffle.end);if(document.selection){document.selection.empty()}NG.preventDefault(b)};NG.DOMShuffle.move=function(j){if(!NG.DOMShuffle.curNode){return NG.DOMShuffle.end(j)}if(!j){j=window.event}if(!NG.DOMShuffle.markerNode){var h=NG.getPagePos(NG.DOMShuffle.curNode);NG.DOMShuffle.x=h.x-j.clientX;NG.DOMShuffle.y=h.y-j.clientY;if(NG.DOMShuffle.curNode.nodeName.toLowerCase()=="tr"){NG.DOMShuffle.markerNode=document.createElement("tr");for(var f=0;f<NG.DOMShuffle.curNode.cells.length;f++){NG.DOMShuffle.markerNode.appendChild(document.createElement("td"));NG.DOMShuffle.markerNode.lastChild.style.height=(NG.DOMShuffle.curNode.cells[f].offsetHeight-2)+"px"}NG.DOMShuffle.curNode.parentNode.insertBefore(NG.DOMShuffle.markerNode,NG.DOMShuffle.curNode);var d=document.createElement("table");d.style.width=NG.DOMShuffle.curNode.offsetWidth+"px";d.style.position="absolute";d.appendChild(document.createElement("tbody"));d.lastChild.appendChild(NG.DOMShuffle.curNode);NG.DOMShuffle.curNode=d;document.body.appendChild(d)}else{NG.DOMShuffle.markerNode=document.createElement("div");NG.DOMShuffle.markerNode.style.height=(NG.DOMShuffle.curNode.offsetHeight-2)+"px";NG.DOMShuffle.markerNode.style.width=(NG.DOMShuffle.curNode.offsetWidth-2)+"px";var g=NG.getComputedStyle(NG.DOMShuffle.curNode);NG.DOMShuffle.curNode.style.width=(NG.DOMShuffle.curNode.offsetWidth-parseInt(g.paddingLeft)-parseInt(g.paddingRight)-parseInt(g.borderLeftWidth)-parseInt(g.borderRightWidth))+"px";NG.DOMShuffle.curNode.parentNode.insertBefore(NG.DOMShuffle.markerNode,NG.DOMShuffle.curNode);NG.DOMShuffle.curNode.style.position="absolute";document.body.appendChild(NG.DOMShuffle.curNode)}NG.DOMShuffle.markerNode.className="shuffle-marker";NG.DOMShuffle.curNode.className+=" shuffle-drag"}NG.DOMShuffle.curNode.style.left=(j.clientX+NG.DOMShuffle.x)+"px";NG.DOMShuffle.curNode.style.top=(j.clientY+NG.DOMShuffle.y)+"px";var b=NG.getPagePos(NG.DOMShuffle.markerNode);var a=NG.DOMShuffle.markerNode.offsetWidth/2;while(NG.DOMShuffle.curNode.offsetLeft+a<b.x&&NG.DOMShuffle.markerNode.parentNode.previousSibling){NG.DOMShuffle.markerNode.parentNode.previousSibling.appendChild(NG.DOMShuffle.markerNode);b=NG.getPagePos(NG.DOMShuffle.markerNode)}while(NG.DOMShuffle.curNode.offsetLeft+a>b.x+NG.DOMShuffle.markerNode.offsetWidth&&NG.DOMShuffle.markerNode.parentNode.nextSibling){NG.DOMShuffle.markerNode.parentNode.nextSibling.appendChild(NG.DOMShuffle.markerNode);b=NG.getPagePos(NG.DOMShuffle.markerNode)}var c=NG.DOMShuffle.markerNode.offsetHeight/2;while(NG.DOMShuffle.curNode.offsetTop+c<b.y&&NG.DOMShuffle.markerNode.previousSibling){NG.DOMShuffle.markerNode.parentNode.insertBefore(NG.DOMShuffle.markerNode,NG.DOMShuffle.markerNode.previousSibling);b=NG.getPagePos(NG.DOMShuffle.markerNode)}while(NG.DOMShuffle.curNode.offsetTop+c>b.y+NG.DOMShuffle.markerNode.offsetHeight&&NG.DOMShuffle.markerNode.nextSibling){if(NG.DOMShuffle.markerNode.nextSibling.nextSibling){NG.DOMShuffle.markerNode.parentNode.insertBefore(NG.DOMShuffle.markerNode,NG.DOMShuffle.markerNode.nextSibling.nextSibling)}else{NG.DOMShuffle.markerNode.parentNode.appendChild(NG.DOMShuffle.markerNode)}b=NG.getPagePos(NG.DOMShuffle.markerNode)}};NG.DOMShuffle.end=function(a){NG.removeEventListener(document,"mousemove",NG.DOMShuffle.move);NG.removeEventListener(document,"mouseup",NG.DOMShuffle.end);if(NG.DOMShuffle.curNode&&NG.DOMShuffle.markerNode){if((NG.DOMShuffle.markerNode.parentNode.nodeName.toLowerCase()=="tbody"||NG.DOMShuffle.markerNode.parentNode.nodeName.toLowerCase()=="table")&&(NG.DOMShuffle.curNode.nodeName.toLowerCase()=="tbody"||NG.DOMShuffle.curNode.nodeName.toLowerCase()=="table")){NG.DOMShuffle.curNode.parentNode.removeChild(NG.DOMShuffle.curNode);NG.DOMShuffle.markerNode.parentNode.insertBefore(NG.DOMShuffle.curNode.getElementsByTagName("tr")[0],NG.DOMShuffle.markerNode)}else{NG.DOMShuffle.curNode.style.left=NG.DOMShuffle.curNode.style.top=NG.DOMShuffle.curNode.style.width="auto";NG.DOMShuffle.markerNode.parentNode.insertBefore(NG.DOMShuffle.curNode,NG.DOMShuffle.markerNode);NG.DOMShuffle.curNode.style.position="relative"}NG.DOMShuffle.markerNode.parentNode.removeChild(NG.DOMShuffle.markerNode);NG.DOMShuffle.curNode.className=NG.DOMShuffle.curNode.className.replace(/(^| )shuffle-drag( |$)/,"")}NG.DOMShuffle.markerNode=NG.DOMShuffle.curNode=null};NG.TextLookup=function(c,b,a){this.init(c,b,a)};NG.TextLookup.prototype.init=function(d,c,a){this.uSecDelay=1000;this.minLength=3;this.minWidth=100;this.displayHeight=100;NG.TextLookup.runOnce();this.url=new NGUrl(c);this.queryArg=(a?a:"q");this.textNode=d;this.eH=this.listNode=this.searchAJAX=this.lastLookup=this.focusedItem=null;this.ignoreNextBlur=this.inProgress=this.isValid=false;this.originalLabel=this.textNode.value;this.originalId=this.textNode.getAttribute("ngid");var b=this;this.textNode._ngTextLookup=function(){return b};NG.addClass(this.textNode,"ng-textlookup");if(this.originalLabel.length>0&&isId(this.originalId)){NG.addClass(this.textNode,"ng-textlookup-valid");this.isValid=true}NG.addEventListener(this.textNode,"focus",function(f){if(b.lastLookup==b.textNode.value){b.show()}});NG.addEventListener(this.textNode,"blur",function(f){b.blur(f)});NG.addEventListener(this.textNode,"keyup",function(f){b.keydown(f)});NG.addEventListener(this.textNode,"paste",function(){b.startSearch()});NG.addEventListener(document,"mousedown",function(f){if(f.target==b.textNode||f.srcElement==b.textNode){return}if(b.listNode&&(f.target==b.listNode||f.srcElement==b.listNode)){b.ignoreNextBlur=true;return}b.hide()})};NG.TextLookup.hasRunOnce=false;NG.TextLookup.runOnce=function(){if(!NG.TextLookup.hasRunOnce){NG.addStyleRule(".ng-textlookup-list","position:absolute; height:100px; border:1px solid #c0c0c0; background-color:white; overflow-y:scroll;");NG.addStyleRule(".ng-textlookup-list div","width:100%; overflow:hidden;");NG.addStyleRule(".ng-textlookup-list div div","padding:3px; padding-left:5px; line-height:110%; white-space:nowrap; cursor:pointer;");NG.addStyleRule(".ng-textlookup-valid","color:black;");NG.addStyleRule(".ng-textlookup","background-repeat:no-repeat; background-position:right center; color:red;");NG.addStyleRule(".ng-textlookup-empty","font-style:italic; color:#c0c0c0; text-align:center; height:200%;");NG.addStyleRule(".ng-textlookup-focus","background-color:#45a6e3; color:white;");NG.TextLookup.hasRunOnce=true}};NG.TextLookup.install=function(c,b,a){if(c._ngTextLookup){return c._ngTextLookup()}return new NG.TextLookup(c,b,a)};NG.TextLookup.prototype.keydown=function(a){switch(a.keyCode){case 40:if(this.focusedItem&&this.focusedItem.nextSibling){this.focusItem(this.focusedItem.nextSibling);this.scrollTofocused()}else{if(!this.focusedItem&&this.listNode&&this.listNode.firstChild&&this.listNode.firstChild.firstChild&&this.listNode.firstChild.firstChild.nodeType==1){this.focusItem(this.listNode.firstChild.firstChild);this.scrollTofocused()}}break;case 38:if(this.focusedItem&&this.focusedItem.previousSibling){this.focusItem(this.focusedItem.previousSibling);this.scrollTofocused()}else{if(!this.focusedItem&&this.listNode&&this.listNode.firstChild&&this.listNode.firstChild.lastChild&&this.listNode.firstChild.lastChild.nodeType==1){this.focusItem(this.listNode.firstChild.lastChild);this.scrollTofocused()}}break;case 13:if(this.focusedItem){this.selectItem(this.focusedItem)}else{if(this.isValid){this.hide()}}this.onfinish();break;case 27:this.cancel();this.onfinish();break;default:this.startSearch()}};NG.TextLookup.prototype.blur=function(a){if(this.ignoreNextBlur){this.ignoreNextBlur=false;this.textNode.focus()}else{this.hide();this.cancel();this.onfinish()}};NG.TextLookup.prototype.startSearch=function(){var b=false;if(this.textNode.value==this.originalLabel){this.select(this.originalId,this.originalLabel);this.hide();return}else{if(this.listNode&&this.listNode.firstChild&&this.listNode.firstChild.nodeType==1){var c=this.listNode.firstChild;for(var a=0;!b&&a<c.childNodes.length;a++){if(c.childNodes[a].nodeType==1&&c.childNodes[a].getAttribute("nglabel")==this.textNode.value){this.selectItem(c.childNodes[a]);b=true}}}}if(!b){this.unselectItem()}if(this.inProgress||this.eH){return}if(this.textNode.value.length<this.minLength){this.hide()}else{if(this.searchAJAX||this.textNode.value.length>=this.minLength){this.search()}}};NG.TextLookup.prototype.search=function(){if(this.lastLookup==this.textNode.value){if(this.eH){clearTimeout(this.eH)}this.eH=null;this.show();return}var a=this;if(!this.searchAJAX){this.searchAJAX=new NG.AJAX();this.searchAJAX.setResponseHandler(function(b){a.results(b)},200);this.searchAJAX.setResponseHandler(function(b){a.logout(b)},401);this.searchAJAX.setResponseHandler(function(b){a.cancel()},"")}else{this.searchAJAX.cancel()}NG.addClass(this.textNode,"ng-textlookup-process");this.lastLookup=this.textNode.value;this.inProgress=true;this.url.addArgument(this.queryArg,this.lastLookup,true);this.searchAJAX.url=this.url.toString();this.searchAJAX.send()};NG.TextLookup.prototype.scrollTofocused=function(){var a=this;if(!a.focusedItem||!a.listNode){return}if(a.focusedItem.offsetTop+a.focusedItem.offsetHeight>a.listNode.scrollTop+a.listNode.offsetHeight||a.focusedItem.offsetTop<a.listNode.scrollTop){a.focusedItem.scrollIntoView()}};NG.TextLookup.prototype.focusItem=function(a){this.blurItem();this.focusedItem=a;NG.addClass(this.focusedItem,"ng-textlookup-focus")};NG.TextLookup.prototype.blurItem=function(){if(this.focusedItem){NG.delClass(this.focusedItem,"ng-textlookup-focus")}this.focusedItem=null};NG.TextLookup.prototype.selectItem=function(a){this.select(a.getAttribute("ngid"),a.firstChild.nodeValue,a.getAttribute("nglabel"))};NG.TextLookup.prototype.select=function(c,b,a){this.textNode.value=b;NG.addClass(this.textNode,"ng-textlookup-valid");this.textNode.setAttribute("ngid",c);this.textNode.setAttribute("nglabel",a);this.isValid=true;this.cancel()};NG.TextLookup.prototype.unselectItem=function(){this.isValid=false;NG.delClass(this.textNode,"ng-textlookup-valid");this.textNode.removeAttribute("ngid");this.textNode.removeAttribute("nglabel")};NG.TextLookup.prototype.logout=function(a){};NG.TextLookup.prototype.cancel=function(a){if(this.searchAJAX){this.searchAJAX.cancel()}if(this.eH){clearTimeout(this.eH)}this.eH=null;this.inProgress=false;NG.delClass(this.textNode,"ng-textlookup-process");this.hide()};NG.TextLookup.prototype.results=function(e){this.inProgress=false;NG.delClass(this.textNode,"ng-textlookup-process");var a=this;if(e&&e.responseXML){var h=document.createElement("div");var d=e.responseXML.getElementsByTagName("item");this.blurItem();var g=null;for(var b=0;b<d.length;b++){h.appendChild(document.createElement("div"));h.lastChild.appendChild(document.createTextNode(d[b].getAttribute("label")));h.lastChild.setAttribute("title",d[b].getAttribute("label"));h.lastChild.setAttribute("alt",d[b].getAttribute("label"));h.lastChild.setAttribute("ngid",d[b].getAttribute("id"));h.lastChild.setAttribute("nglabel",ifnull(d[b].getAttribute("nglabel"),d[b].getAttribute("label")));NG.addEventListener(h.lastChild,"mouseover",function(){a.focusItem(this)});NG.addEventListener(h.lastChild,"mousedown",function(){a.selectItem(this);a.onfinish()});if(d[b].getAttribute("label")==this.textNode.value){this.selectItem(h.lastChild)}}if(d.length==0){h.className="ng-textlookup-empty";h.appendChild(document.createTextNode("Empty"))}else{if(d.length==1){this.focusItem(h.lastChild)}}this.show(h)}this.eH=setTimeout(function(){a.search()},this.uSecDelay)};NG.TextLookup.prototype.show=function(a){if(!this.textNode.parentNode){return this.hide()}var b=NG.getComputedStyle(this.textNode);if(!this.listNode){this.listNode=document.createElement("div");this.listNode.className="ng-textlookup-list";this.listNode.style.height=this.displayHeight+"px";this.listNode.style.fontFamily=b.fontFamily;this.listNode.style.fontSize=b.fontSize}if(a){while(this.listNode.firstChild){this.listNode.removeChild(this.listNode.firstChild)}this.listNode.appendChild(a)}var c=NG.getPagePos(this.textNode);this.listNode.style.width=Math.max(this.minWidth,this.textNode.offsetWidth-NG.getComputedStylePx(this.listNode,"borderLeftWidth")-NG.getComputedStylePx(this.listNode,"borderRightWidth"))+"px";c.y+=window.document.documentElement.scrollTop;c.x+=window.document.documentElement.scrollLeft;NG.ContextMenu.documentPosition(this.listNode,c.x,c.y+this.textNode.offsetHeight,c.x,c.y)};NG.TextLookup.prototype.hide=function(){if(this.listNode&&this.listNode.parentNode){this.listNode.parentNode.removeChild(this.listNode)}};NG.TextLookup.prototype.onfinish=function(){};