function TreeView(objName,imagePath){
	this.target=null;
	this.useSelection=true;
	this.folderLinks=true;
	this.useNamesAsTitle=true;
	this.useLines=true;
	this.useIcons=true;
	this.useCookies=false;
	this.closeSameLevel=false;
	this.inOrder=false;
	this.userFriendlyStatusText=false,
	this.icons={empty:imagePath+'empty.gif',root:imagePath+'folder.gif',folder:imagePath+'folder.gif',folderOpen:imagePath+'folderopen.gif',node:imagePath+'page.gif',line:imagePath+'line.gif',join:imagePath+'join.gif',joinBottom:imagePath+'joinbottom.gif',nlPlus:imagePath+'nolines_plus.gif',nlMinus:imagePath+'nolines_minus.gif',plus:imagePath+'plus.gif',plusBottom:imagePath+'plusbottom.gif',minus:imagePath+'minus.gif',minusBottom:imagePath+'minusbottom.gif'};
	this.obj=objName;
	this.aNodes=[];
	this.aIndent=[];
	this.root=new Node(-1);
	this.selectedNode=null;
	this.selectedFound=false;
	this.completed=false;
};
TreeView.prototype.add=function(id,pid,name,url,title,icon,iconOpen,target,open){
	this.aNodes[this.aNodes.length]=new Node(id,pid,name,url,title,icon,iconOpen,target,open);
};
TreeView.prototype.openAll=function(){
	this.oAll(true);
};
TreeView.prototype.closeAll=function(){
	this.oAll(false);
};
TreeView.prototype.oAll=function(status){
	for(var i=0;i<this.aNodes.length;i++){
		if(this.aNodes[i]._hc&&this.aNodes[i].pid!=this.root.id){
			this.nodeStatus(status,i,this.aNodes[i]._ls);
			this.aNodes[i]._io=status;
		};
	};
	if(this.useCookies)
		this.updateCookie();
};
TreeView.prototype.toString=function(){
	var str='<div class="TreeView">\n';
	if(document.getElementById){
		if(this.useCookies)
			this.selectedNode=this.getSelected();
		str+=this.getChildNodesHtml(this.root);
	} else { 
		str+='Browser not supported.'; 
	}
	str+='</div>';
	if(!this.selectedFound)
		this.selectedNode=null;
	
	this.completed=true;return str;
};
TreeView.prototype.getNodeHtml=function(node,nodeId){
	var str='<div class="dTreeNode"><table cellspacing=0 cellpadding=0><tr><td>'+this.indent(node,nodeId);
	if(this.useIcons){
		if(!node.icon)
			node.icon=(this.root.id==node.pid)?this.icons.root:((node._hc)?this.icons.folder:this.icons.node);
		if(!node.iconOpen)
			node.iconOpen=(node._hc)?this.icons.folderOpen:this.icons.node;
		if(this.root.id==node.pid){
			node.icon=this.icons.root;
			node.iconOpen=this.icons.root;
		};
		str+='<img id="i'+this.obj+nodeId+'" src="'+((node._io)?node.iconOpen:node.icon)+'" alt="" />';
	};
	str += '</td><td>';
	if(node.url){
		str+='<a id="s'+this.obj+nodeId+'" class="'+((this.useSelection)?((node._is?'nodeSel':'node')):'node')+'" href="'+node.url+'"';
	if(node.target)
		str+=' target="'+node.target+'"';
	if(!node.title&&this.useNamesAsTitle)
		node.title=node.name;if(node.title)
	str+=' title="'+node.title+'"';
	if(this.userFriendlyStatusText)
		str+=' onmouseover="window.status=\''+node.name+'\';return true;" onmouseout="window.status=\'\';return true;" ';
		if(this.useSelection&&((node._hc&&this.folderLinks)||!node._hc))
			str+=' onclick="javascript: '+this.obj+'.highlight('+nodeId+');"';
		str+='>';
	} else if((!this.folderLinks||!node.url)&&node._hc&&node.pid!=this.root.id){
		str+='<a href="javascript: '+this.obj+'.toggle('+nodeId+');" class="node">';
	};
	str+=node.name;
	if(node.url||((!this.folderLinks||!node.url)&&node._hc))
		str+='</a>';
	str+='</td></tr></table></div>';
	if(node._hc){
		str+='<div id="d'+this.obj+nodeId+'" class="clip" style="display:'+((this.root.id==node.pid||node._io)?'block':'none')+';">';
		str+=this.getChildNodesHtml(node);
		str+='</div>';
	};
	
	this.aIndent.pop();
	return str;
};
TreeView.prototype.indent=function(node,nodeId){
	var str='';
	if(this.root.id!=node.pid){
		for(var n=0;n<this.aIndent.length;n++){
			str+='<img src="'+((this.aIndent[n]==1&&this.useLines)?this.icons.line:this.icons.empty)+'" alt="" />';
		};
		(node._ls)?this.aIndent.push(0):this.aIndent.push(1);
		if(node._hc){
			str+='<a href="javascript: '+this.obj+'.toggle('+nodeId+');"><img border=0 id="j'+this.obj+nodeId+'" src="';
			if(!this.useLines){
				str+=(node._io)?this.icons.nlMinus:this.icons.nlPlus;
			}else{ 
				str+= ((node._io)?((node._ls&&this.useLines)?this.icons.minusBottom:this.icons.minus):((node._ls&&this.useLines)?this.icons.plusBottom:this.icons.plus));
				str+='" alt="" /></a>';
			}
		} else {
			str+='<img src="'+((this.useLines)?((node._ls)?this.icons.joinBottom:this.icons.join):this.icons.empty)+'" alt="" />';
		}
	};
	return str
};
TreeView.prototype.getChildNodesHtml=function(pNode){
	var str='';
	var n=0;
	if(this.inOrder)
		n=pNode._ai;
	for(n;n<this.aNodes.length;n++){
		if(this.aNodes[n].pid==pNode.id){
			var cn=this.aNodes[n];
			cn._p=pNode;
			cn._ai=n;
			this.setCS(cn);
			if(!cn.target&&this.target)
				cn.target=this.target;
			if(cn._hc&&!cn._io&&this.useCookies)
				cn._io=this.isOpen(cn.id);
			if(!this.folderLinks&&cn._hc)
				cn.url=null;
			if(this.useSelection&&cn.id==this.selectedNode&&!this.selectedFound){
				cn._is=true;this.selectedNode=n;
				this.selectedFound=true;
			};
			str+=this.getNodeHtml(cn,n);
			if(cn._ls)break;
		};
	};
	return str;
};
TreeView.prototype.setCS=function(node){
	var lastId;
	for(var n=0;n<this.aNodes.length;n++){
		if(this.aNodes[n].pid==node.id)
			node._hc=true;
		if(this.aNodes[n].pid==node.pid)
			lastId=this.aNodes[n].id;
	};
	if(lastId==node.id)
		node._ls=true;
};
TreeView.prototype.getSelected=function(){
	var sn=this.getCookie('cs'+this.obj);
	return(sn)?sn:null;
};
TreeView.prototype.highlight=function(id){
	if(!this.useSelection)
		return;
	var cn=this.aNodes[id];
	if(cn._hc&&!this.folderLinks)
		return;
	if(this.selectedNode!=id){
		if(this.selectedNode||this.selectedNode==0){
			eOld=document.getElementById("s"+this.obj+this.selectedNode);
			eOld.className="node";
		};
		eNew=document.getElementById("s"+this.obj+id);
		eNew.className="nodeSel";
		this.selectedNode=id;
		if(this.useCookies)
			this.setCookie('cs'+this.obj,cn.id);
	};
};
TreeView.prototype.toggle=function(id){
	var cn=this.aNodes[id];
	this.nodeStatus(!cn._io,id,cn._ls);
	cn._io=!cn._io;
	if(this.closeSameLevel)
		this.closeLevel(cn);
	if(this.useCookies)
		this.updateCookie();
};
TreeView.prototype.closeLevel=function(node){
	for(var n=0;n<this.aNodes.length;n++){
		if(this.aNodes[n].pid==node.pid&&this.aNodes[n].id!=node.id&&this.aNodes[n]._hc){
			this.nodeStatus(false,n,this.aNodes[n]._ls);
			this.aNodes[n]._io=false;
			this.closeAllChildren(this.aNodes[n]);
		};
	};
};
TreeView.prototype.closeAllChildren=function(node){
	for(var n=0;n<this.aNodes.length;n++){
		if(this.aNodes[n].pid==node.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]);
		};
	};
};
TreeView.prototype.nodeStatus=function(status,id,bottom){
	eDiv=document.getElementById('d'+this.obj+id);
	eJoin=document.getElementById('j'+this.obj+id);
	if(this.useIcons){
		eIcon=document.getElementById('i'+this.obj+id);
		eIcon.src=(status)?this.aNodes[id].iconOpen:this.aNodes[id].icon;
	};
	eJoin.src=(this.useLines)?((status)?((bottom)?this.icons.minusBottom:this.icons.minus):((bottom)?this.icons.plusBottom:this.icons.plus)):((status)?this.icons.nlMinus:this.icons.nlPlus);
	eDiv.style.display=(status)?'block':'none';
};
TreeView.prototype.getCookie=function(cookieName){
	var cookieValue='';
	var posName=document.cookie.indexOf(escape(cookieName)+'=');
	if(posName!=-1){
		var posValue=posName+(escape(cookieName)+'=').length;
		var endPos=document.cookie.indexOf(';',posValue);
		if(endPos!=-1)
			cookieValue=unescape(document.cookie.substring(posValue,endPos));
		else 
			cookieValue=unescape(document.cookie.substring(posValue));
	};
	return(cookieValue);
};
TreeView.prototype.setCookie=function(cookieName,cookieValue,expires,path,domain,secure){
	document.cookie=escape(cookieName)+'='+escape(cookieValue)+(expires?'; expires='+expires.toGMTString():'')+(path?'; path='+path:'')+(domain?'; domain='+domain:'')+(secure?'; secure':'');
};
TreeView.prototype.clearCookie=function(){
	var now=new Date();
	var yesterday=new Date(now.getTime()-1000*60*60*24);
	this.setCookie('co'+this.obj,'cookieValue',yesterday);
	this.setCookie('cs'+this.obj,'cookieValue',yesterday);
};
TreeView.prototype.updateCookie=function(){
	var str='';
	for(var n=0;n<this.aNodes.length;n++){
		if(this.aNodes[n]._io&&this.aNodes[n].pid!=this.root.id){
			if(str)
				str+='.';
			str+=this.aNodes[n].id;
		};
	};
	this.setCookie('co'+this.obj,str);
	};
TreeView.prototype.isOpen=function(id){
	var aOpen=this.getCookie('co'+this.obj).split('.');
	for(var n=0;n<aOpen.length;n++){
		if(aOpen[n]==id)
			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;
	};
};function Node(id,pid,name,url,title,icon,iconOpen,target,open){
	this.id=id;
	this.pid=pid;
	this.name=name;
	this.url=url;
	this.title=title;
	this.target=target;
	this.icon=icon;
	if(iconOpen)
		this.iconOpen=iconOpen;
	else 
		this.iconOpen=icon;
	this._io=open||false;
	this._is=false;
	this._ls=false;
	this._hc=false;
	this._ai=0;
	this._p;
};
