
function Node(id,indent,text,target,url,tooltip,iconOpen,iconClose,isOpen) {    
	this.id=id; this.indent=indent; this.text=makeSize(text,10,200); this.target=target;                 
	this.url=url; this.tooltip=tooltip; this.iconOpen=iconOpen; this.iconClose=iconClose;              
	this.parent=null; this.childs=[]; this.isOpen=isOpen;   
}                                                  
function treemenu(name, showLines, showIcons, useCookies , mode , size) {                    
	this.name=name; this.showLines=showLines; this.showIcons=showIcons; this.nodes=[]; 
	this.root=new Node(-1,-1,'root'); this.selected=-1; this.maxIndent=0;  this.expire=1; 
	this.openNodes = '';  this.classDepth= 2;   
	if (size) this.size=size;
	else this.size=200; 
	mode=parseInt(mode);
	if (!mode) mode=4;
		this.defaults = {                                                             
		iconRoot:'/images/rtl_tree/mode'+mode+'/root.gif', iconItem:'/images/rtl_tree/mode'+mode+'/item.gif',  
		iconOpen:'/images/rtl_tree/mode'+mode+'/open.gif', iconClose:'/images/rtl_tree/mode'+mode+'/close.gif', 
		passLine:'/images/rtl_tree/mode'+mode+'/passline.gif', empty:'/images/rtl_tree/mode'+mode+'/empty.gif', 
		tieLine:'/images/rtl_tree/mode'+mode+'/tieline.gif', tiePlus:'/images/rtl_tree/mode'+mode+'/tieplus.gif',
		endLine:'/images/rtl_tree/mode'+mode+'/endline.gif', endPlus:'/images/rtl_tree/mode'+mode+'/endplus.gif',
		rectPlus:'/images/rtl_tree/mode'+mode+'/rectplus.gif', tieMinus:'/images/rtl_tree/mode'+mode+'/tieminus.gif', 
		rectMinus:'/images/rtl_tree/mode'+mode+'/rectminus.gif', endMinus:'/images/rtl_tree/mode'+mode+'/endminus.gif', 
		minIcon:'/images/rtl_tree/mode'+mode+'/minicon.gif'  
	} 
}                                                                                
treemenu.prototype.put = function(open, label, target, url,tooltip, iconOpen, iconClose) {
	if (this.selected==-1) this.selected = this.nodes.length;                      
	this.add(open, label, target, url, tooltip, iconOpen, iconClose); 
}            
treemenu.prototype.add = function(open, label, target, url,tooltip, iconOpen, iconClose) {
	var indent = 0;                                                                
	while (label.charAt(indent)==' ') indent++;                                    
	if (this.maxIndent<indent) this.maxIndent = indent;
	var id     = this.nodes.length;                            
	var isOpen = (open==0) ? false : true;                                         
	if (this.openNodes && id<this.openNodes.length)                                
	isOpen = (this.openNodes.charAt(id)=='1') ? true : false;                  
	var node   = new Node(id, indent, label.substr(indent),                        
	target, url, tooltip, iconOpen, iconClose, isOpen);      
	this.nodes[this.nodes.length] = node;                                          
	for (i=this.nodes.length-1; i>=0; i--)                                         
	if (this.nodes[i].indent < indent) { node.parent = this.nodes[i];   break; } 
	if (!node.parent) node.parent = this.root;                                     
	if (node.parent.indent<node.indent-1)                                          
	alert('Indent of "' + node.text +'" must be <' + (node.parent.indent+2)); 
	node.parent.childs[node.parent.childs.length] = node; 
}                        
treemenu.prototype.toString = function() {
	var str = '<div class="TreeMenu">';                                            
	var lastIndent = 0;                                                            
	for (id=0; id<this.nodes.length; id++) {                                       
	var node = this.nodes[id]                                                    
	if (lastIndent < node.indent) lastIndent = node.indent;                      
	while (lastIndent>node.indent) { str += '</div>';   lastIndent--; }          
	str += this.writeNode(node);                                                 
	if (0<node.childs.length) {                                                  
	 str += '<div id="' + this.name + 'SubTree_' + id                           
		 +  '" style="display:'                                                 
		 +  ((node.isOpen) ? 'block' : 'none') + '">'; } }                      
	for (i=lastIndent; i>0; i--) str += '</div>';                                  
	str += '</div>';                                                               
	this.loadSelected();                                                           
	// alert(str);                                                                  
	return str;  
}                                                                 
treemenu.prototype.writeNode = function(node) {                                 
	if (node.target=='hide') return '';                                            
	var str = '<div>'                                                              
		 + this.writeIndenting(node)  + this.writeTieUpIcon(node)               
		 + this.writeNodeSymbol(node) + this.writeNodeText(node) + '</div>';    
	return str; 
}                                                                  
treemenu.prototype.writeIndenting = function(node) {                            
	if (node.indent < 2) return '';                                                
	var str      = '';                                                             
	var icons    = [];                                                             
	var ancestor = node.parent;                                                    
	for (i=node.indent-2; i>=0; i--, ancestor=ancestor.parent) {                   
		icons[i] = (this.isLastChild(ancestor) ? 'empty' : 'passLine');  
	}        
	for (i=0; i<=node.indent-2; i++) {                                             
		var icon = this.defaults.empty;                                           
		if (this.showLines && icons[i]!='empty') icon = this.defaults.passLine;   
		str += '<img name="' + icons[i] + '" src="' + icon + '" alt="" />';
	}     
	return str;  
}                                                                 
treemenu.prototype.writeTieUpIcon = function(node)  {                           
	if (node.indent < 1) return '';                                                
	var icon = this.getTieUpIcon(node);                                            
	var str  = '';                                                                 
	if (0==node.childs.length)                                                     
	  str = '<img id="' + this.name + 'TieUp_' + node.id                        
		  + '" src="' + icon + '" alt="" />';                                   
	else str = '<a href="javascript: ' + this.name + '.toggle(' + node.id + ')">'  
		  +  '<img id="' + this.name + 'TieUp_' + node.id                       
		  +  '" src="' + icon + '" alt="" /></a>';                              
	return str; 
}                                                                  
treemenu.prototype.getTieUpIcon = function(node) {                              
	if (0 == node.childs.length) {                                                 
		if      (!this.showLines)        return this.defaults.empty;                 
		else if (this.isLastChild(node)) return this.defaults.endLine;               
		else                             return this.defaults.tieLine; 
	}            
	else if (node.isOpen) {                                                        
		if      (!this.showLines)        return this.defaults.rectMinus;             
		else if (this.isLastChild(node)) return this.defaults.endMinus;              
		else                             return this.defaults.tieMinus; 
	}            
	else {                                                                         
		if      (!this.showLines)        return this.defaults.rectPlus;              
		else if (this.isLastChild(node)) return this.defaults.endPlus;               
		else                             return this.defaults.tiePlus;  
	} 
}          
treemenu.prototype.writeNodeSymbol = function(node) {                           
	var icon = this.getNodeSymbol(node) ;                                          
	if (0==node.childs.length) {                                                   
		var str = '';                                                                
		if (node.url) {    str += '<a href="' + node.url + '"';                      
			if (node.target) str += ' target="' + node.target + '")';                  
							  str += '">'; 
		}                                            
		str += '<img id="' + this.name + 'Symbol_' + node.id                         
		   +  '" src="'   + icon + '" alt="" />';                                   
		if (node.url) str += '</a>';                                                 
		return str; 
	}                                                                
	return   '<a href="javascript: ' + this.name + '.toggle(' + node.id + ')">'    
		  + '<img id="' + this.name + 'Symbol_' + node.id                       
		  + '" src="' + icon + '" alt="" /></a>'; 
}                             
treemenu.prototype.getNodeSymbol = function(node) {                             
	if (!this.showIcons)  return this.defaults.minIcon;                            
	if (0==node.childs.length) {                                                   
	if (node.iconOpen)  return node.iconOpen;                                    
	else                return this.defaults.iconItem;  }                        
	else if (node.isOpen) {                                                        
	if (node.iconOpen)  return node.iconOpen;                                    
	else                return this.defaults.iconOpen;  }                        
	else {                                                                         
	if (node.iconClose) return node.iconClose;                                   
	else                return this.defaults.iconClose; }
}                      
treemenu.prototype.writeNodeText = function(node) {                             
	var cls = this.getNodeTextClass(node, this.selected);                          
	var str = '<a id="' + this.name + 'Node_' + node.id + '" class="' + cls + '"'; 
	if (node.url) str += ' href="' + node.url + '"';                               
	else          str += ' href="javascript: '+this.name+'.toggle('+node.id+')"';  
	if (node.url && node.target)  str += ' target="' + node.target   + '"';        
	if (node.tooltip)             str += ' title="'  + node.tooltip  + '"';        
	str += ' onclick="javascript: ' + this.name + '.pick(' + node.id + ')"';   
	str += '>' + node.text + ((node.url) ? '</a>' : '</a>') ;                      
	return str; 
}          
treemenu.prototype.getNodeTextClass = function(node, selectID) {                
	var cls = (node.id==selectID) ? 'Selected' : 'Node';                           
	if (!node.url) cls = 'Item';                                                   
	return cls + '_' + Math.min(node.indent, this.classDepth);
}                   
treemenu.prototype.loadSelected = function() { 
	this.loadNode(this.selected); 
}  
treemenu.prototype.loadNode = function(id) {                                    
	if (id<0) return;                                                              
	if (this.nodes[id].target=='hide') return;                                     
	for (var i=0; i<parent.frames.length; i++) {                                  
		if (parent.frames[i].name==this.nodes[id].target) {                         
			parent.frames[i].location.href = this.nodes[id].url;                      
			break; 
		} 
	} 
}                                                              
treemenu.prototype.pick = function(id) {                                       
	var node = this.nodes[id];                                                    
	if (node.url) {                                                               
		if      (node.indent==0       && this.showIcons==false) this.toggle(id);    
		else if (node.childs.length>0 && node.isOpen==false)    this.toggle(id); 
	}  
	this.select(id); 
}  
treemenu.prototype.select = function(id) {                                      
	if (!this.nodes[id].url) return;                                               
	if (this.selected >= 0) {                                                      
		node = document.getElementById(this.name + 'Node_' + this.selected);         
		name = this.getNodeTextClass(this.nodes[this.selected],-1);                  
		if (node && name) node.className = name;                                     
		this.selected  = -1;  
	}                                                      
	node = document.getElementById(this.name + 'Node_' + id);                      
	name = this.getNodeTextClass(this.nodes[id], id);                              
	if (node && name) node.className = name;                                       
	this.selected  = id;                                                           
	this.openAncestors(id);                                                        
}  
treemenu.prototype.openAncestors = function(id) {                               
	if (id<0) return;                                                              
	var ancestor = this.nodes[id].parent;                                          
	while(ancestor.indent>=0) {                                                    
		if (!ancestor.isOpen) { ancestor.isOpen=true;  this.updateNode(ancestor); }  
		ancestor = ancestor.parent;  
	} 
} 
treemenu.prototype.selectPath = function(path) {                                
	path = this.pathWithSlash(path);                                               
	if (this.selected>=0) {                                                        
		var url = this.pathWithSlash(this.nodes[this.selected].url);                 
		if (url==path) return; 
	}                                                    
	for (id=0; id<this.nodes.length; id++) {                                       
		var url = this.pathWithSlash(this.nodes[id].url);                            
		if (url && url==path) { 
			this.select(id);    
			break; 
		} 
	}
}                     
treemenu.prototype.pathWithSlash = function(path) {                             
	var parts = path.split("\\");                                                  
	var str   = parts[0];                                                          
	for (i=1; i<parts.length; i++) str = str + '/' + parts[i];                     
	return str; 
}                                                                  
treemenu.prototype.toggle = function(id) {                                      
	if (this.nodes[id].childs.length==0) return;                                   
	this.nodes[id].isOpen = !this.nodes[id].isOpen;                                
	this.updateNode(this.nodes[id]);                                               
}  
treemenu.prototype.updateNode = function(node) {                                
	subTree = document.getElementById(this.name + 'SubTree_' + node.id);           
	tieUp   = document.getElementById(this.name + 'TieUp_'   + node.id);           
	symbol  = document.getElementById(this.name + 'Symbol_'  + node.id);           
	if (subTree) subTree.style.display = (node.isOpen) ? 'block' : 'none';         
	if (tieUp)   tieUp.src   = this.getTieUpIcon(node);                            
	if (symbol)  symbol.src  = this.getNodeSymbol(node); 
}                         
treemenu.prototype.isLastChild = function(node) {                               
	var parent = node.parent;                                                      
	return ((node == parent.childs[parent.childs.length-1]) ? true : false); 
}     
treemenu.prototype.level = function(level) {                                    
	for (id=0; id<this.nodes.length; id++) {                                       
	this.nodes[id].isOpen = (this.nodes[id].indent<level) ? true : false;        
	this.updateNode(this.nodes[id]); }                                           
}                                                
treemenu.prototype.lines = function(bool) {                                     
	if (this.showLines == bool) return;                                            
	this.showLines = bool;                                                         
	var passLines = document.getElementsByName("passLine");                        
	if (!passLines) return;                                                        
	for (i=0; i<passLines.length; i++) {                                           
		passLines[i].src = (bool) ? this.defaults.passLine : this.defaults.empty; 
	}  
	for (id=0; id<this.nodes.length; id++) {                                       
		if (this.nodes[id].indent < 1) continue;                                     
		var tieUp = document.getElementById(this.name + 'TieUp_' + id);              
		if (tieUp) tieUp.src = this.getTieUpIcon(this.nodes[id]);  
	}                 
} 
treemenu.prototype.icons = function(bool) {                                     
	if (this.showIcons == bool) return;                                            
	this.showIcons = bool;                                                        
	for (id=0; id<this.nodes.length; id++) {                                      
	var icon  = this.getNodeSymbol(this.nodes[id]);                             
	var image = document.getElementById(this.name + 'Symbol_' + id)             
	if (image)  image.src = icon; }                                             
}                                               
treemenu.prototype.expiration = function(expire) {                             
	this.expire = expire; 
}                
//----------------------------------------------------------------
function showHidePanel(id){
	if(id){// changing dispaly of child nodes.		
		if(document.getElementById(id)) {
			if(document.getElementById(id).style.display==""){document.getElementById(id).style.display="none";	}
			else{document.getElementById(id).style.display="";}
		}
		if(document.getElementById("img_"+id)){		// changing bullet to collapse or expand state.
			if(document.getElementById("img_"+id).src.indexOf("rectminus.gif")!=-1)	document.getElementById("img_"+id).src="/images/rtl_tree/rectplus.gif";
			else document.getElementById("img_"+id).src="/images/rtl_tree/rectminus.gif";
		}
	}
}
function showHidePanelrelated(id){
	if(id){// changing dispaly of child nodes.		
		if(document.getElementById(id)) {
			if(document.getElementById(id).style.display==""){document.getElementById(id).style.display="none";}
			else{document.getElementById(id).style.display="";}
		}
		if(document.getElementById("img_"+id)){		// changing bullet to collapse or expand state.
			if(document.getElementById("img_"+id).src.indexOf("rectminusr.gif")!=-1)	document.getElementById("img_"+id).src="/images/categories/rectplusr.gif";
			else document.getElementById("img_"+id).src="/images/categories/rectminusr.gif";
		}
	}
}