/* hTree version 1.4.1 by Martin Hintzmann Andersen http://www.hintzmann.dk */
if (!dk) {
  var dk = {} ;
  dk.hintzmann = {} ;
} else if (!dk.hintzmann) {
  dk.hintzmann = {};
}
var _h  = dk.hintzmann;

// constructor
_h.Tree = function(id) { 
		this.version = "1.4.1";
		this.lastModified = "20050313";

		this.id = id;
		this.cookiePath = "/";
		this.useIcons   = true;
		this.useCookies = true;
		this.foldersAsLinks = false;
		this.oneSibling = false;
		this.icon = {
			align : "left",
			open : "/gfx/gx_tree_open.gif",
			closed : "/gfx/gx_tree_closed.gif",
			item : "/gfx/gx_tree_item.gif"
		};
		this.navigation = this._keyNavigation;
};
_h.Tree.prototype.isSupported = (document.createElement &&
											document.getElementById && 
											document.getElementsByTagName);
_h.Tree.prototype.build = function() {
	if (!this.isSupported) return;
	this._list = document.getElementById(this.id);
	if (!this._list) return;
	this._list.className = "hTreeJS";
	var aLI = this._list.getElementsByTagName("li");
	for (var i=0;i<aLI.length;i++) {
		var oLI			= aLI[i];
		var count = oLI.getAttribute('id');
		var aUL = oLI.getElementsByTagName("ul");
		if (aUL.length>0) {
			var oUL = aUL[0];
			oLI._hTree_folder = true;
			oUL.setAttribute('id',this.id+'-'+i);
			this.CreateTreeFolder(oLI,oUL);
		} else if(count > 0) {
		   	oLI._hTree_folder = true;
			this.CreateTreeItem(oLI, "true");
		} else {
			oLI._hTree_folder = false;
			this.CreateTreeItem(oLI, "false");
		}
	}
};
_h.Tree.prototype.CreateTreeFolder = function( oLI, oUL ) {
		var me = this;

		if (this.useCookies) { oLI._hTree_open = ((_h.getCookie(oUL.id)) == '1')?true:false; }
		oLI._hTree_open = (_h.hasClass(oUL, "open"))?true:oLI._hTree_open;
		oLI._hTree_open = (_h.hasClass(oUL, "closed"))?false:oLI._hTree_open;
		
/* Link */
		var aLinks = oLI.getElementsByTagName("a");
		if (!aLinks) this.CreateTreeItem(oLI, "false"); 
		
		var oLink = aLinks[0];
		if (oLink.parentNode != oLI) this.CreateTreeItem(oLI, "false"); 
		
		if (this.foldersAsLinks == false) { 
			oLink.href = "#";
			oLink.onclick = function() {
				me.toggle(oLI);
				return false;
			}
		}
		oLink.onkeydown = function(e) {
			var code;
			if (!e) var e = window.event;
			if (e.keyCode) code = e.keyCode;
			else if (e.which) code = e.which;
			me.navigation(code, oLI);
		}
		
		oLink._hTree_oLI = oLI;


/* IMG */		
		var oIMG = null;
		if (this.useIcons) {
			oIMG = document.createElement("img");

			oIMG.src = oLI._hTree_open ? this.icon.open : this.icon.closed;
			oIMG.alt = oLI._hTree_open ? "-": "+";
			oIMG.onclick = function() {
				me.toggle(oLI);
				return false;
			}
			oIMG._hTree_oLI = oLI;

			if (this.icon.align == "left") {
				oLI.insertBefore(oIMG,oLink);
			} else {
				oLI.insertBefore(oIMG,oLink.nextSibling);
			}
		}
		
		oLI._hTree_oUL		= oUL;
		oLI._hTree_oIMG	= oIMG;
		oLI._hTree_oLink  = oLink;

		oUL._hTree_oLI		= oLI;
		oUL.style.display = oLI._hTree_open?'block':'none'; 
	};
			
_h.Tree.prototype.CreateTreeItem = function(oLI, haschildren) {
		var me = this;
		
		var aLinks = oLI.getElementsByTagName("a");
		if (aLinks) {
			var oLink = aLinks[0];
			if (oLink) {
				if (oLink.parentNode == oLI) {
					oLink.onkeydown = function(e) {
						var code;
						if (!e) var e = window.event;
						if (e.keyCode) code = e.keyCode;
						else if (e.which) code = e.which;
						me.navigation(code, oLI);
					}
					if(haschildren == "true"){
						oLink.href = "#";
						oLink.onclick = function() {
							me.servertoggle(oLI, oLink.id);
							return false;
						}
					}
				}
				oLI._hTree_oLink  = oLink;
			}		
		}

		oLI._hTree_open = false;

		if (this.useIcons) {
			var oIMG = document.createElement("img");

			if(haschildren == "false"){
				oIMG.src = this.icon.item;
				oIMG.alt = "::";
			}
			else{
				oIMG.src = this.icon.closed;
				oIMG.alt = "+";
				oIMG.onclick = function() {
				if (aLinks) {
					var oLink = aLinks[0];
					if (oLink) {
						me.servertoggle(oLI, oLink.id);
					}	
				}	
				return false;
				}		
			}

			if (this.icon.align == "left") {
				oLI.insertBefore(oIMG,oLI.firstChild);	
			} else {
				oLI.insertBefore(oIMG,oLI.firstChild.nextSibling);	
			}
		}
	};							
_h.Tree.prototype.toggle = function (oLI) {
		if (oLI._hTree_folder == true) {
			if (oLI._hTree_open == true) { 
				this.collapse(oLI); 
			} else { 
				if (this.oneSibling == true) {
					this.closeSiblings(oLI);
				}
				this.expand(oLI); 
			}
		}
	};
_h.Tree.prototype.servertoggle = function (oLI, name) {
		name = name.replace('#','');
		var qs = new QS(document.location.search);
		qs.replaceValue("showtree", encodeURIComponent(name) + "#" + name);		
		document.location = qs.getQueryString();
	};
_h.Tree.prototype.collapse = function (oLI) {
		var oIMG = oLI._hTree_oIMG;
		var oUL	= oLI._hTree_oUL;
	
		oUL.style.display = "none";
		if (oIMG) {
			oIMG.src = this.icon.closed;
			oIMG.alt = "+";
		}
		oLI._hTree_open = false;
		_h.setCookie(oUL.id, "0", this.cookiePath); 
}	
_h.Tree.prototype.expand = function (oLI) {
		var oIMG = oLI._hTree_oIMG;
		var oUL	= oLI._hTree_oUL;

		oUL.style.display = "block";  
		if (oIMG) {
			oIMG.src = this.icon.open;
			oIMG.alt = "-";
		}
		oLI._hTree_open = true;
		_h.setCookie(oUL.id, "1", this.cookiePath);
}	
_h.Tree.prototype.select = function(oLI) {
		if (oLI._hTree_oLink)
			oLI._hTree_oLink.focus()
};
_h.Tree.prototype.closeSiblings = function(oLI) {
		var oUL = oLI.parentNode;
		for (var x=oUL.childNodes.length-1; x >= 0; x--) {
			if (oUL.childNodes[x].nodeType == 3) { continue; } //TEXT_NODE
			if (oUL.childNodes[x] != oLI) {
				if (oUL.childNodes[x]._hTree_open) {
					this.collapse(oUL.childNodes[x]);
				}
			}
		}
};
_h.Tree.prototype.getNextLI = function(oLI) {
		var oUL = oLI.parentNode;
		var bCurrentLI = false;
		for (var x=0; x < oUL.childNodes.length; x++) {
			if (oUL.childNodes[x].nodeType == 3) { continue; } //TEXT_NODE
			if (oLI == oUL.childNodes[x]) {
				bCurrentLI = true;
				continue;
			}
			if (bCurrentLI == true) {
				return oUL.childNodes[x];
			}
		}
		return this.getNextLI(oUL.parentNode);
};
_h.Tree.prototype.getPrevLI = function(oLI) {
		var oUL = oLI.parentNode;
		var bCurrentLI = false;
		for (var x=oUL.childNodes.length-1; x >= 0; x--) {
			if (oUL.childNodes[x].nodeType == 3) { continue; } //TEXT_NODE
			if (oUL.childNodes[x] == oLI) {
				bCurrentLI = true;
				continue;
			}
			if (bCurrentLI == true) {
				if (oUL.childNodes[x]._hTree_open) {
					return this.getLast(oUL.childNodes[x]);
				} else {
					return oUL.childNodes[x];
				}
			}
		}
		return oUL.parentNode;
};
_h.Tree.prototype.getLast = function(oLI) {
		var oUL = oLI._hTree_oUL;
		for (var x=oUL.childNodes.length-1; x >= 0; x--) {
			if (oUL.childNodes[x].nodeType == 3) { continue; } //TEXT_NODE
			if (oUL.childNodes[x]._hTree_open) {
				return this.getLast(oUL.childNodes[x]);
			} else {
				return oUL.childNodes[x];
			}
		}
};
_h.Tree.prototype._keyNavigation = function(code, oLI) {	
		if ((code == 37) || (code == 38) || (code == 39) || (code == 40)) {
			var oIMG = oLI._hTree_oIMG;
			var oUL	= oLI._hTree_oUL;
			
			if (code == 37) { /* Left */
				if (oLI._hTree_open) {
					this.toggle(oLI);
				} else {
					this.select(oLI.parentNode.parentNode);
				}
			} else if (code == 38) { /* Up */
				var oLI_prev =  this.getPrevLI(oLI); 
				if (oLI_prev) { this.select(oLI_prev);}
				return false;
			} else if (code == 39) { /* Right */
				if (oLI._hTree_open) {
					if (oLI.getElementsByTagName("li")) {
						this.select(oLI.getElementsByTagName("li")[0])
					}
				} else {
					this.toggle(oLI);
				}
			} else if (code == 40) { /* Down */
				if (oLI._hTree_open) {
					if (oLI.getElementsByTagName("li")) {
						this.select(oLI.getElementsByTagName("li")[0])
					}
				} else {
					var oLI_next = this.getNextLI(oLI);
					if (oLI_next) { this.select(oLI_next); }
				}
			}
		} else {
			return true;
		}
};


// Helper functions
_h.getCookie = function(name) { 
	var arg = name + "=";  
	var alen = arg.length;  
	var clen = document.cookie.length;  
	var i = 0;  
	while (i < clen) {
		var j = i + alen;    
		if (document.cookie.substring(i, j) == arg) {
			var endstr = document.cookie.indexOf (";", j);
			if (endstr == -1) endstr = document.cookie.length;
			return unescape(document.cookie.substring(j, endstr));
 		}
		i = document.cookie.indexOf(" ", i) + 1;    
		if (i == 0) break;   
	}  
	return null;
}
_h.setCookie = function(key, value, path) {
	document.cookie= key + "=" + escape(value) + ((path) ? "; path=" + path : "");
}
_h.hasClass = function (el, className) {
	var cs, j
	cs = el.className.split(" ");
	for (j = 0; j < cs.length; j++) {
		if (cs[j] == className) {
			return true;
		}
	}
	return false;
} 
_h.addClass = function (el, className) {
	if (el.className==null) 
		el.className='';
	el.className+=(el.className.length>0?' ':'')+className;
}
_h.removeClass = function (el, className) {
  var cs, j, remainClass
  remainClass = new Array();
  cs = el.className.split(" ");
  for (j = 0; j < cs.length; j++) {
    if (cs[j] != className) {
      remainClass.push(cs[j]);
	 }
  }
  el.className = remainClass.join(" ");
}
_h.addEvent = function (oEl, sEvent, sFunction, useCapture) {	
	if (oEl) {
		if (oEl.addEventListener) { // MOZ
			oEl.addEventListener(sEvent,sFunction,useCapture);
			return true;
		} else if (oEl.attachEvent) { // IE5
			var r = oEl.attachEvent("on"+sEvent,sFunction);
			return r;
//		} else if (document.all) { // IE4
//			eval('oEl.on'+sEvent+'='+sFunction+';');
//		} else {
//		  alert("Handler could not be attached");
		}
	}
}

// Array.push() - Add an element to the end of an array
if (typeof(Array.prototype.push) == 'undefined') {
  Array.prototype.push = function() {
  	var currentLength = this.length;
  	for (var i = 0; i < arguments.length; i++) {
  		this[currentLength + i] = arguments[i];
  	}
  	return this.length;
  };
}
