/*--------------------------------------------------|
| dTree 2.05 | www.destroydrop.com/javascript/tree/ |
|---------------------------------------------------|
| Copyright (c) 2002-2003 Geir Landr・              |
|                                                   |
| This script can be used freely as long as all     |
| copyright messages are intact.                    |
|                                                   |
| Updated: 17.04.2003                               |
|--------------------------------------------------*/
function Node(a,b,c,d,e,f,g,h,i){this.id=a;this.pid=b;this.name=c;this.url=d;this.title=e;this.target=f;this.icon=g;this.iconOpen=h;this._io=i||false;this._is=false;this._ls=false;this._hc=false;this._ai=0;this._p};function dTree(a){this.config={target:null,folderLinks:true,useSelection:true,useCookies:true,useLines:true,useIcons:true,useStatusText:false,closeSameLevel:false,inOrder:false};this.icon={root:'img/base.gif',folder:'img/folder.gif',folderOpen:'img/folderopen.gif',node:'img/page.gif',empty:'img/empty.gif',line:'img/line.gif',join:'img/join.gif',joinBottom:'img/joinbottom.gif',plus:'img/plus.gif',plusBottom:'img/plusbottom.gif',minus:'img/minus.gif',minusBottom:'img/minusbottom.gif',nlPlus:'img/nolines_plus.gif',nlMinus:'img/nolines_minus.gif'};this.obj=a;this.aNodes=[];this.aIndent=[];this.root=new Node(-1);this.selectedNode=null;this.selectedFound=false;this.completed=false};dTree.prototype.add=function(a,b,c,d,e,f,g,h,i){this.aNodes[this.aNodes.length]=new Node(a,b,c,d,e,f,g,h,i)};dTree.prototype.openAll=function(){this.oAll(true)};dTree.prototype.closeAll=function(){this.oAll(false)};dTree.prototype.toString=function(){var a='<div class="dtree">\n';if(document.getElementById){if(this.config.useCookies)this.selectedNode=this.getSelected();a+=this.addNode(this.root)}else a+='Browser not supported.';a+='</div>';if(!this.selectedFound)this.selectedNode=null;this.completed=true;return a};dTree.prototype.addNode=function(a){var b='';var n=0;if(this.config.inOrder)n=a._ai;for(n;n<this.aNodes.length;n++){if(this.aNodes[n].pid==a.id){var c=this.aNodes[n];c._p=a;c._ai=n;this.setCS(c);if(!c.target&&this.config.target)c.target=this.config.target;if(c._hc&&!c._io&&this.config.useCookies)c._io=this.isOpen(c.id);if(!this.config.folderLinks&&c._hc)c.url=null;if(this.config.useSelection&&c.id==this.selectedNode&&!this.selectedFound){c._is=true;this.selectedNode=n;this.selectedFound=true}b+=this.node(c,n);if(c._ls)break}}return b};dTree.prototype.node=function(a,b){var c='<div class="dTreeNode">'+this.indent(a,b);if(this.config.useIcons){if(!a.icon)a.icon=(this.root.id==a.pid)?this.icon.root:((a._hc)?this.icon.folder:this.icon.node);if(!a.iconOpen)a.iconOpen=(a._hc)?this.icon.folderOpen:this.icon.node;if(this.root.id==a.pid){a.icon=this.icon.root;a.iconOpen=this.icon.root}c+='<img id="i'+this.obj+b+'" src="'+((a._io)?a.iconOpen:a.icon)+'" alt="" />'}if(a.url){c+='<a id="s'+this.obj+b+'" class="'+((this.config.useSelection)?((a._is?'nodeSel':'node')):'node')+'" href="'+a.url+'"';if(a.title)c+=' title="'+a.title+'"';if(a.target)c+=' target="'+a.target+'"';if(this.config.useStatusText)c+=' onmouseover="window.status=\''+a.name+'\';return true;" onmouseout="window.status=\'\';return true;" ';if(this.config.useSelection&&((a._hc&&this.config.folderLinks)||!a._hc))c+=' onclick="javascript: '+this.obj+'.s('+b+');"';c+='>'}else if((!this.config.folderLinks||!a.url)&&a._hc&&a.pid!=this.root.id)c+='<a href="javascript: '+this.obj+'.o('+b+');" class="node">';c+=a.name;if(a.url||((!this.config.folderLinks||!a.url)&&a._hc))c+='</a>';c+='</div>';if(a._hc){c+='<div id="d'+this.obj+b+'" class="clip" style="display:'+((this.root.id==a.pid||a._io)?'block':'none')+';">';c+=this.addNode(a);c+='</div>'}this.aIndent.pop();return c};dTree.prototype.indent=function(a,b){var c='';if(this.root.id!=a.pid){for(var n=0;n<this.aIndent.length;n++)c+='<img src="'+((this.aIndent[n]==1&&this.config.useLines)?this.icon.line:this.icon.empty)+'" alt="" />';(a._ls)?this.aIndent.push(0):this.aIndent.push(1);if(a._hc){c+='<a href="javascript: '+this.obj+'.o('+b+');"><img id="j'+this.obj+b+'" src="';if(!this.config.useLines)c+=(a._io)?this.icon.nlMinus:this.icon.nlPlus;else c+=((a._io)?((a._ls&&this.config.useLines)?this.icon.minusBottom:this.icon.minus):((a._ls&&this.config.useLines)?this.icon.plusBottom:this.icon.plus));c+='" alt="" /></a>'}else c+='<img src="'+((this.config.useLines)?((a._ls)?this.icon.joinBottom:this.icon.join):this.icon.empty)+'" alt="" />'}return c};dTree.prototype.setCS=function(a){var b;for(var n=0;n<this.aNodes.length;n++){if(this.aNodes[n].pid==a.id)a._hc=true;if(this.aNodes[n].pid==a.pid)b=this.aNodes[n].id}if(b==a.id)a._ls=true};dTree.prototype.getSelected=function(){var a=this.getCookie('cs'+this.obj);return(a)?a:null};dTree.prototype.s=function(a){if(!this.config.useSelection)return;var b=this.aNodes[a];if(b._hc&&!this.config.folderLinks)return;if(this.selectedNode!=a){if(this.selectedNode||this.selectedNode==0){eOld=document.getElementById("s"+this.obj+this.selectedNode);eOld.className="node"}eNew=document.getElementById("s"+this.obj+a);eNew.className="nodeSel";this.selectedNode=a;if(this.config.useCookies)this.setCookie('cs'+this.obj,b.id)}};dTree.prototype.o=function(a){var b=this.aNodes[a];this.nodeStatus(!b._io,a,b._ls);b._io=!b._io;if(this.config.closeSameLevel)this.closeLevel(b);if(this.config.useCookies)this.updateCookie()};dTree.prototype.oAll=function(a){for(var n=0;n<this.aNodes.length;n++){if(this.aNodes[n]._hc&&this.aNodes[n].pid!=this.root.id){this.nodeStatus(a,n,this.aNodes[n]._ls);this.aNodes[n]._io=a}}if(this.config.useCookies)this.updateCookie()};dTree.prototype.openTo=function(a,b,c){if(!c){for(var n=0;n<this.aNodes.length;n++){if(this.aNodes[n].id==a){a=n;break}}}var d=this.aNodes[a];if(d.pid==this.root.id||!d._p)return;d._io=true;d._is=b;if(this.completed&&d._hc)this.nodeStatus(true,d._ai,d._ls);if(this.completed&&b)this.s(d._ai);else if(b)this._sn=d._ai;this.openTo(d._p._ai,false,true)};dTree.prototype.closeLevel=function(a){for(var n=0;n<this.aNodes.length;n++){if(this.aNodes[n].pid==a.pid&&this.aNodes[n].id!=a.id&&this.aNodes[n]._hc){this.nodeStatus(false,n,this.aNodes[n]._ls);this.aNodes[n]._io=false;this.closeAllChildren(this.aNodes[n])}}};dTree.prototype.closeAllChildren=function(a){for(var n=0;n<this.aNodes.length;n++){if(this.aNodes[n].pid==a.id&&this.aNodes[n]._hc){if(this.aNodes[n]._io)this.nodeStatus(false,n,this.aNodes[n]._ls);this.aNodes[n]._io=false;this.closeAllChildren(this.aNodes[n])}}};dTree.prototype.nodeStatus=function(a,b,c){eDiv=document.getElementById('d'+this.obj+b);eJoin=document.getElementById('j'+this.obj+b);if(this.config.useIcons){eIcon=document.getElementById('i'+this.obj+b);eIcon.src=(a)?this.aNodes[b].iconOpen:this.aNodes[b].icon}eJoin.src=(this.config.useLines)?((a)?((c)?this.icon.minusBottom:this.icon.minus):((c)?this.icon.plusBottom:this.icon.plus)):((a)?this.icon.nlMinus:this.icon.nlPlus);eDiv.style.display=(a)?'block':'none'};dTree.prototype.clearCookie=function(){var a=new Date();var b=new Date(a.getTime()-1000*60*60*24);this.setCookie('co'+this.obj,'cookieValue',b);this.setCookie('cs'+this.obj,'cookieValue',b)};dTree.prototype.setCookie=function(a,b,c,d,e,f){document.cookie=escape(a)+'='+escape(b)+(c?'; expires='+c.toGMTString():'')+(d?'; path='+d:'')+(e?'; domain='+e:'')+(f?'; secure':'')};dTree.prototype.getCookie=function(a){var b='';var c=document.cookie.indexOf(escape(a)+'=');if(c!=-1){var d=c+(escape(a)+'=').length;var e=document.cookie.indexOf(';',d);if(e!=-1)b=unescape(document.cookie.substring(d,e));else b=unescape(document.cookie.substring(d))}return(b)};dTree.prototype.updateCookie=function(){var a='';for(var n=0;n<this.aNodes.length;n++){if(this.aNodes[n]._io&&this.aNodes[n].pid!=this.root.id){if(a)a+='.';a+=this.aNodes[n].id}}this.setCookie('co'+this.obj,a)};dTree.prototype.isOpen=function(a){var b=this.getCookie('co'+this.obj).split('.');for(var n=0;n<b.length;n++)if(b[n]==a)return true;return false};if(!Array.prototype.push){Array.prototype.push=function array_push(){for(var i=0;i<arguments.length;i++)this[this.length]=arguments[i];return this.length}}if(!Array.prototype.pop){Array.prototype.pop=function array_pop(){lastElement=this[this.length-1];this.length=Math.max(this.length-1,0);return lastElement}}