/*###################################################################
# toggleHidden.js
# ---------------
# This Script is supposed to do the following:
# - Get called by an event handler
# - find out where it was called from
# - check if the caller has child nodes
# - if yes, toggle hidden state
# -------------------------------------------------------------------
# © Dirk Salewski, 2006
#
# http://www.salewski.com/
# 
# In contrast to mere screendesign COMPUTERPROGRAMS are protected by 
# copyright. This JavaScript legally qualifies as computerprogram. 
# Without written permission You are not allowed to make copys of 
# this program, in parts or as a whole. This, of course, does not 
# apply to the use of JavaScript itself, i.e. it's functions and 
# classes. Violations of my rights will be prosecuted.
# 
# Im Gegensatz zu reinem Screendesign sind COMPUTERPROGRAMME durch 
# das Urheberrecht geschützt. Dieses Script erfüllt die gesetzlichen 
# Voraussetzungen für die Einordnung als Computerprogramm. Damit ist 
# es untersagt, ohne schriftliche Erlaubnis Kopien dieses Scripts an-
# zufertigen, sei es als ganzes oder in Teilen. Dies trifft selbst-
# verständlich nicht auf die Benutzung der Sprache JavaScript als 
# solches zu. Jegliche Verletzung meiner Rechte wird zur Anzeige
# gebracht.
###################################################################*/

function prcPreparePage(strId) {
	if (document.getElementById) {
		/* True vars */
		var strClasses;
		var strElements = new Array();
		var strNodeValue;
		var strA;
		var strStrong;
		var strId;
		var strName;
		var strHref;
		/* Counters */
		var i;
		/* Main Voodoo */
		for (i=0;i<prcPreparePage.arguments.length; i++) {
			strElements[i] = prcPreparePage.arguments[i];
		}
		for (i=0;i<strElements.length;i++) {
			strA = document.createElement("a");
			strStrong = document.createElement("strong");
			strNodeValue = document.createTextNode(document.getElementById(strElements[i]).firstChild.firstChild.nodeValue);
			strStrong.appendChild(strNodeValue);
			strA.appendChild(strStrong);
			strId = document.createAttribute("id");
			strId.nodeValue = "a" + i;
			strName = document.createAttribute("name");
			strName.nodeValue = "a" + i;
			strHref = document.createAttribute("href");
			strHref.nodeValue = "javascript:prcToggleHidden('li" + i + "')";
			strA.setAttributeNode(strId);
			strA.setAttributeNode(strName);
			strA.setAttributeNode(strHref);
			document.getElementById(strElements[i]).replaceChild(strA, document.getElementById(strElements[i]).firstChild);
		}
		for (i=0;i<strElements.length;i++) {
			prcToggleHidden(strElements[i]);
		}
	}
}

function prcToggleHidden(strCaller) {
	/* True vars */
	var intChildNumber;
	var strClasses;
	var bolSearch;
	var strHide;
	var strAtt;
	/* Counters */
	var i;
	/* Main Voodoo */
	strHide = "no_s";
	intChildNumber = document.getElementById(strCaller).childNodes.length;
	for (i=1;i<intChildNumber;i++) {
		if (document.getElementById(strCaller).childNodes[i].className) {
			bolSearch = document.getElementById(strCaller).childNodes[i].className.search(strHide);
			if(bolSearch==-1) {
				strClasses = document.getElementById(strCaller).childNodes[i].className;
				document.getElementById(strCaller).childNodes[i].className = strClasses + " " + strHide;
			} else {
				strClasses = document.getElementById(strCaller).childNodes[i].className.replace(strHide, "");
				document.getElementById(strCaller).childNodes[i].className = strClasses;
			}
		} else {
			if (document.getElementById(strCaller).childNodes[i].nodeType==1) {
				var myClass = document.createAttribute("class");
				myClass.nodeValue = "no_s";
				document.getElementById(strCaller).childNodes[i].setAttributeNode(myClass);
			}
		}
	}
}
