
var cdDate =  "14102008";

/*------------------------------------------------------------------- 
Deeply modified by Bled Internet (www.bled-internet.com)
in order to improve the display efficiency.

Author's Statement:
This script is based on ideas of the author.
You may copy, modify and use it for any purpose. The only condition is that if you publish web pages that use this script 
you point to its author at a suitable place and don't remove this Statement from it.
It's your responsibility to handle possible bugs even if you didn't modify anything. I cannot promise any support.
Dieter Bungers
GMD (www.gmd.de) and infovation (www.infovation.de)
--------------------------------------------------------------------*/

// global variables:

var isIE = navigator.appName.toLowerCase().indexOf("explorer") > -1;
var isNS = navigator.appName.toLowerCase().indexOf("netscape") > -1;
var scrollPosY, addScroll; 
var lastExpandedIndex = -1;
var currentLevel, noLink;

// toDisplay: Array to keep the display status for each heading. It is initialised so only the 
//top level headings are displayed (headings preceeded by a single string without a dot):  

var firstNode = new Array(tocTab.length);
var nextNode = new Array(tocTab.length);
var parentNode = new Array(tocTab.length);
var toDisplay = new Array(tocTab.length);
var node = new Array();

node[0] = -1;

for (ir=0; ir < tocTab.length; ir++) {

	level = parseInt(tocTab[ir][0]);

	toDisplay[ir] = level <= maxToDisplayLevel;
	firstNode[ir] = -1;
	nextNode[ir] = -1;

	n = node[level];
	if (n >= 0) {		// next Node
		nextNode[n] = ir;
	}
	else {			// first Node
		if (level > 0)	firstNode[node[level-1]] = ir;
	}
	if (level > 0) {
		parentNode[ir] = node[level-1];
	}

	node[level] = ir;
	node[level+1] = -1;
}

// ***************************************
// The function undisplay
// ***************************************

function undisplay(node) {

	if (node >= 0 && toDisplay[node]) {
		toDisplay[node] = false;
		undisplay(firstNode[node]);
		undisplay(nextNode[node]);
	}
}


// ***************************************
// The function display
// ***************************************

function display(i) {
		if (i >= 0 && toDisplay[i]) {
			thisLevel = parseInt(tocTab[i][0]);
			isCurrent = (i == currentIndex);

// Setting the heading's symbol depending on whether this heading is expanded or not or if 
// it is a leaf. It is expanded if the next heading has a greater level than this one AND 
// has to be displayed: 
			if (i < tocTab.length-1) {
				nextLevel = parseInt(tocTab[i+1][0]);
				img = (thisLevel >= nextLevel) ? "leaf" : ((toDisplay[i+1]) ? "minus" : "plus");
			} 
			else img = "leaf"; // The last heading is always a leaf.

// If the scoll parameter is set true than increment the scrollPosY value:
			if (addScroll) scrollPosY+=lineHeight;
			if (isCurrent) addScroll=false;

// Now writing this ToC line, i.e. a table row...:			
			toc.document.writeln("<tr>");

// ...first some empty cells for the line indent depending on the level of this heading...:
			for (k=1; k<=thisLevel; k++) {
				toc.document.writeln("<td>&nbsp;</td>");
			}

// ...then the hading symbol and the heading text each with a javaScript link caling just 
// this function reDisplay again: 

			var backcolor;
			if (isNS) backcolor =  "";
			else	backcolor =  " onmouseover=\"javascript:this.style.background='#D8DEDE'\""  	
					+ " onmouseout=\"javascript:this.style.background='#FFFFFF'\"";

			toc.document.writeln("<td valign=top height=\"" + lineHeight+ "\">"
			+ "<a href=\"javascript:elt='" + tocTab[i][1] + "';\" onMouseDown=\"top.reDisplay(" 
			+ i + "," + tocBehaviour[0] + "," + tocLinks[0] + ",event)\">"
			+ "<img src=\"Images/" + img + ".gif\" border=0 alt=\""
			+ tocTab[i][1] + "\"></a></td>\n" 
			+ "<td colspan=" + (nCols-thisLevel) 
			+ "><a href=\"javascript:elt='" + tocTab[i][1] + "';\" onMouseDown=\"top.reDisplay(" 
			+ i + "," + tocBehaviour[1] + "," + tocLinks[1] + ",event)\""
			+ backcolor
			+ ">&nbsp;" + tocTab[i][1] + "&nbsp;"  	
			+ "</a></td></tr>");


// Display childs and brothers
		display(firstNode[i]);
		display(nextNode[i]);
		}
}

// ***************************************
// The function redisplays the ToC and the content 
// ***************************************

function reDisplay(currentindex,tocChange,nolink,e) {
// Input parameters:
// currentindex: 
// tocChange: Controls how to change the ToC. 0 = No change, 1 = Change with automatic collapsing 
//   of expanded headings that are not on the path to the current heading, 2 = Change wthout automatic 
//   colapsing (as use for example by Windows Explorer or Mac OS).
// nolink: Controls wether the content's URL shall be changed to the value given by the 3rd element  
//   of an tocTab's entry (= 0) or not (= 1).
// e: The event that triggered the function call. If it is set it must be the event object.

// If there is an event that triggered the function call: Checking the control key depending 
// on the browser used. If it is pressed and tocChange is greater than 0 tocChange is set to 2 
// so the ToC schanges without automatic collapsing: 

	currentIndex = currentindex;
	noLink = nolink;

	var yScrollOffset;
	if (e) {
		ctrlKeyDown = (isIE) ? e.ctrlKey : (e.modifiers==2);
		if (tocChange && ctrlKeyDown) tocChange = 2;

		if (document.body.scrollTop) { // netscape etc.
			yScrollOffset = toc.document.body.scrollTop;
		}
		else if (toc.pageYOffset) { // IE, mozilla etc.
			yScrollOffset = toc.pageYOffset;
		}
	}

//	currentLevel = the level of the current heading:
	currentLevel = parseInt(tocTab[currentIndex][0]);

// currentIsExpanded = Expand/Collaps-state of the current heading:
	if (currentIndex < tocTab.length-1) {
		nextLevel = parseInt(tocTab[currentIndex+1][0]);
		currentIsExpanded = nextLevel > currentLevel && toDisplay[currentIndex+1];
	} 
	else currentIsExpanded = false;

// Determining the new URL and target (if given) of the current heading
	theHref = (noLink) ? "" : tocTab[currentIndex][2];
	theTarget = tocTab[currentIndex][3];

// ***************************************
// Determining which heading to display:
// ***************************************

	if (tocChange) {

		if (currentIsExpanded) { 
			// close the descendant headings
			undisplay(firstNode[currentIndex]);
		}
 		else {
			if (tocChange == 1) { // automatic collapsing
				// close the old path
				if (lastExpandedIndex >= 0) {
					for (n=lastExpandedIndex; parseInt(tocTab[n][0]) > maxToDisplayLevel; n=parentNode[n]);
					undisplay(firstNode[n]);
				}
			}
			// display the path from the the current heading to the root
			for (ir=currentIndex; ir >= 0; ir=parentNode[ir]) {
				// display the childs
				for (n=firstNode[ir]; n >= 0; n=nextNode[n]) {
					toDisplay[n] = true;
				}
			}

			lastExpandedIndex = currentIndex;
		}
	} 


// ***************************************
// Displaying the headings:
// ***************************************

	scrollPosY=0; 
	addScroll=tocScroll;


// Initializing the ToC window's document and displaying the title on it's top. 
// The ToC is performed by a HTML table:

//	toc.document.clear();
//	toc.document.open("text/html", "replace"); 
//	toc.document.open("replace"); 
	toc.document.open();

	toc.document.write("<html>\n<head>\n<title>ToC</title>\n<link rel=\"stylesheet\" type=\"text/css\" href=\"content.css\">\n"
		+ "</head>\n<body bgcolor=\"" + backColor + "\">\n"
		+ "<table border=0 cellspacing=0 cellpadding=0 width=\"" + lineMaxWidth 
		+ "\">\n<tr>\n");

// This is for defining the number of columns of the ToC table and the width of the last one. 
// The first cells of each following row shall be empty or contain the heading symbol, 
// the last ones are reserved for displaying the heding's text:
	for (k=0; k<nCols; k++) {
		toc.document.write("<td>&nbsp; </td>");
	}
	toc.document.write("<td width=240>&nbsp; </td></tr>");

	display(1);

// ***************************************
// Closing the ToC document,  scrolling its frame window and displaying new content in the content 
// frame or in the top window if required 
// ***************************************

// Closing the ToC table and the document
	toc.document.writeln("</table>");
	for (i=1; i <= 20; i++) {
		toc.document.writeln("<p>&nbsp; </p>");
	}
	toc.document.writeln("</body></html>");
	toc.document.close();
	
//	toc.document.writeln("</table>\n</body></html>");
//	toc.document.close();

// Scrolling the ToC if required
	if (tocScroll) {
		if (scrollPosY < 300) {
			toc.scroll(0, 0);
		}
		else if (yScrollOffset) {
			toc.scroll(0, yScrollOffset);
		}
		else {
			toc.scroll(0, scrollPosY);
		}
	}

// Setting the top or content window's location if required
	if (theHref.indexOf('?') >= 0) { 
		theHref += '&newdate=' + cdDate;
	}
	if (theHref) 
		if (theTarget=="top") top.location.href = theHref;
		else if (theTarget=="parent") parent.location.href = theHref;
		else if (theTarget=="blank") open(theHref,"");
		else mainFrame.location.href = theHref;

}






