Element.prototype.findEntry = findEntry;
Element.prototype.show = show;
Element.prototype.showtree = showtree;
Element.prototype.expandSection = expandSection;
Element.prototype.expandPath = expandPath;
Element.prototype.expandPath2 = expandPath2;
Element.prototype.expandPath3 = expandPath3;
var localdoc = document;
var tableWidth = 170;
var localwin = window;
var interations = 0;
var idCount = 0;

var ns4=document.layers?1:0;
var ie4=document.all?1:0;
var ns6=document.getElementById&&!document.all?1:0;

function Element(name, number, path)
{
	this.name = name.first("|");

	this.child = null;
	this.next = null;
	this.expand = 0;
	this.secure = 0
	this.url = name.rest("|");
	this.target = this.url.word("#", 2);
	if(this.target != "")
	{
		if(this.url.word("#", 3) == "S")
			this.secure = 1;
		this.url = this.url.first("#");
	}

	this.number = number;
	if(this.url == "")
		this.path = path;
	else
	{
		var p = path.lastIndexOf("->");
		if(p == -1)
			this.path = "";
		else
			this.path = path.substring(0, p);
	}
	var nav = navinfo.quickFind(this.path, "|");

	if(nav != "")
	{
		this.center = nav.word("|", 3);
		this.newscat = nav.word("|", 4);
		if(this.url == "")
			this.status = nav.word("|", 2).replace(/'/, "&#8217;");
		else
			this.status = this.name.replace(/'/, "&#8217;");
	}
	else
	{
		this.status = this.name.replace(/'/, "&#8217;");
		this.center = "";
		this.newscat = newsCategory;
	}
}

function findEntry(number)
{
	var entry = null;
	if(this.number == number)
		return(this);
	if(this.child != null)
		entry = this.child.findEntry(number);
	if(entry != null)
		return(entry);
	if(this.next != null)
		entry = this.next.findEntry(number);
	return(entry);
}

function loadCenter(entry)
{
	if(entry.center != "")
	{
		var w = self;
		var hops = 0;
		for(hops = 0; !w.KISTERS_CENTER & hops < 10; hops++)
		{
			w = w.parent;
		}
		if(hops != 10)
			if(w.KISTERS_CENTER)
			{
				var center;
				if(entry.center.toLowerCase().indexOf("&newscategory=") == -1 && entry.newscat != "")
					center = entry.center + "&NewsCategory=" + entry.newscat;
				else
					center = entry.center;
				var c = center.replace(/\//g, "\\/");
				c = c.replace(/\?/g, "\\?");
				w.KISTERS_CENTER.location.href = center;
			}
	}
}

function Loading_verstecken()
{
	if(navigator.family == 'nn4')
		document.LoadPageMessage.visibility="hidden";
	else
		LoadPageMessage.style.visibility="hidden";
}
function expandSection2(number, win)
{
	var s1 = win.document.getElementById("entry" + number).style;

	var ele = win.document.getElementById("a" + number);
	var img = win.document.createAttribute("src");
	if(s1.display == 'none')
	{
		closeLevel(number, win.document);
		s1.display = 'block';
		img.nodeValue=thisWebName + "springfill_menu_open.gif";
		ele.setAttributeNode(img);
		return(true);
	}
	else
	{
		img.nodeValue=thisWebName + "springfill_menu_close.gif";
		ele.setAttributeNode(img);
		s1.display = 'none';
		return(false);
	}
}
function expandSection(number, win)
{
	if(expandSection2(number, win))
	{
		var entry = this.findEntry(number);
		if(entry != null)
			loadCenter(entry);
	}
}
function closeLevel(number, doc)
{
	var pre=number.leftback('.');
   var i=1;
	while(i>0)
	{
		num=(pre==""?i:pre+"."+i);
	   var d=doc.getElementById("entry"+num);
		if(d)
		{
			if(d.style.display!='none')
			{
				var ele = doc.getElementById("a"+num);
				var img = doc.createAttribute("src");
				img.nodeValue=thisWebName + "springfill_menu_close.gif";
				ele.setAttributeNode(img);
				d.style.display = 'none';
			}
        closeLevel(num+".1", doc);
			i++;
		}
		else
			i=-1;
	}
}

function show(doc)
{
	localdoc = doc;
	doc.writeln('<div class="MenuLeft" onMouseOver="resetEntry();">');
	idCount=0;
	this.showtree(1);
	doc.writeln("</div>");
}

function createURL(entry)
{
	var pos = entry.indexOf("#");
	var url = (pos < 0) ? entry : entry.substring(0, pos);
	
	if(url.indexOf("file:") == 0)
		return(url);
	if(isUNID(url.substr(0, 32)))
		url = "0/" + url.substr(0, 32);
	if(url.indexOf("http:") == 0)
		url = url.substring(5);
	if(url.indexOf("//") != 0 && url.indexOf("/") != 0)
		url = thisWebName + url;
	if(url.indexOf("//") != 0 && url.indexOf("/") == 0)
		url = "//" + location.hostname + url;
	return("http:" + url);
}
function isUNID(entry)
{
	if(entry.match(/\w+/) == entry)
		return(true);
	return(false);
}
function showtree(level)
{
	var style="style='padding-left:" + level*10 + "px;'";
	if(this.url != "")
	{
		var newsCategory = (this.newscat != "") ? "&NewsCategory=" + this.newscat : "";
		var url = (this.target != "") ? createURL(this.url) : createURL(this.url) + "!Open" + newsCategory;
		var target = (this.target != "") ? this.target : "KISTERS_CENTER";
		this.id = "l" + (idCount++);
		localdoc.write("<a " + style + " onmouseout=\"status='';return true;\" onmouseover=\"status='" + this.status + "';return true;\" id=\"" + this.id + "\" href=\"" + url + "\" target=\"" + target + "\">");
		if(this.secure)
			localdoc.write(this.name + '<img class="Key" hspace=5 src="/library.nsf/Images/ServiceImages/$file/key.gif" alt="">');
		else
			localdoc.write(this.name);
		localdoc.write("</a>");
	}
	else
	{
		localdoc.write("<a " + style + " onmouseout=\"status='';return true;\" onmouseover=\"status='" + this.status + "';return true;\" href=\"javascript:tree.expandSection('" + this.number + "', window);\">");
		localdoc.write("<img id=\"a" + this.number + "\" src=\"" + thisWebName + (this.expand?"springfill_menu_open.gif":"springfill_menu_close.gif") + "\" alt=\"\">");
		localdoc.write(this.name);
		localdoc.write("</a>");
	}

//	if((navigator.DOMCSS1 || this.expand == true || navigator.family == 'opera') && this.child != null)
	if(this.child != null)
	{
		localdoc.write("<div style=\"display:" + (this.expand ? "block":"none") + "\" id=\"entry" + this.number + "\">");
		this.child.showtree(level+1);
		localdoc.writeln("</div>");
	}

	if(this.next != null)
		this.next.showtree(level);
}

function addEntry(e1, e2)
{
	iterations = 0;
	 var path = "";
	var number = "1";
	var first = e1;
	ret = addEntry1(e1, e2, number, path);
	return(first == null ? ret : first);
}
function addEntry1(e1, e2, number, path)
{
	if(e2 == "")
		return(e1);

	var name1 = e2.first("->");
	var name2 = e2.rest("->");
	var newpath = (path == "") ? name1 : path + "->" + name1;
	var e3 = null;
	var pos = number.lastIndexOf(".");
	var n = Number(number.slice(pos + 1));

	 while(e1 != null)
	 {
		if(e1.name == name1)
		{
			return(addEntry1(e1.child, name2, e1.number + ".1", newpath));
		}
		e3 = e1;
		if(e1.child)
			n = n + 1;
		e1 = e1.next;
	 }
	if(name2 != "")
	{
		number = (pos == -1 ? n: number.substring(0, pos) + "." + n);
		e1 = new Element(name1, number, newpath);
	}
	else
		e1 = new Element(name1, 0, newpath);

	if(e3 != null)
		e3.next = e1;
	if(name2 != "")
		e1.child = addEntry1(e1.child, name2, e1.number + ".1", newpath);
	return(e1);
}
var obj;
var treeWindow;
function expandPath3(win)
{
	treeWindow = win;
	this.expandPath();
}
function expandPath()
{
	if(top.KISTERS_MAIN)
		if(top.KISTERS_MAIN.KISTERS_CENTER)
		{
			obj = top.KISTERS_MAIN.KISTERS_CENTER;
			if(obj.NavPath)
			{
				this.expandPath2(obj.NavPath);
				return(true);
			}
			else
				return(highlightEntry(this));
		}
		else
			if(top.KISTERS_CENTER)
			{
				obj = top.KISTERS_CENTER;
				if(obj.NavPath)
				{
					this.expandPath2(obj.NavPath);
					return(true);
				}
				else
					return(false);
			}
	return(true);
}
function expandPath2(path)
{
	var name1 = path.first("->");
	var name2 = path.rest("->");
	var e1 = this;
	while(e1 != null)
	{
		if(e1.name == name1)
		{
			expandSection2(String(e1.number), treeWindow);
			e1.expand = true;
			if(e1.child != null)
				if(name2 != "")
					return(e1.child.expandPath2(name2));
				else
					return(highlightEntry(e1.child));
			return(false);
		}
		e1 = e1.next;
	}
	return(false);
}
function highlightEntry(e1)
{
	if(obj.NavTitle)
	{
		while(e1!=null)
		{
			if(e1.name==obj.NavTitle)
			{
				var ele = treeWindow.document.getElementById(e1.id);
				var id = treeWindow.document.createAttribute("id");
				id.nodeValue="high";
				ele.setAttributeNode(id);
				return(true);
			}
			e1=e1.next;
		}
	}
	return(false);
}
function resetEntry()
{
	style=document.getElementById("high");
	if(style)
		style.id="";
}

