/* Linkermenuscript.js */
// Detacom Business Applications
// Laatste wijziging: 20051228T1257

function dyna_styliseAllTagsByClass(strTagName, strClassName, strStyleAttribute, strStyleNewValue) {
//function expects a tag (an element tag) and a style class.
//calling example: var res = dyna_styliseAllTagsByClass("A", "menubar","color","#00f");
//function puts new style value to all tags with that style class in the current document.
//function returns false when expected parameters are not received.

var myNodeList, elmt;

	if ((document.getElementsByTagName)&&(strTagName)&&(strClassName)&&(strStyleAttribute)&&(strStyleNewValue)) {
		myNodeList = document.getElementsByTagName(strTagName);
		for(var i = new Number(0); i<myNodeList.length; i++) {
			elmt = myNodeList[i];
			if ((elmt)&&(elmt.className)){
				if(elmt.className==strClassName) {
					elmt.style[strStyleAttribute]=strStyleNewValue;
				}
			}
		}
		delete i;
	}
	delete myNodeList;
	delete elmt;
	return true;
}


function dyna_showParentsByClasses(myNode, strClassNames) {
//function expects a document Node (an element), and a (list of) style class(es).
//calling example: var res = dyna_showParentsByClasses(elmt, "menuitem, dropmenu");
//function recursively finds parentNode within the range of given classes, in myNode, and shows it.
//function always returns true.

var nPa = new Object();
	if ((myNode)&&(myNode.parentNode)&&(strClassNames)) {
		nPa = myNode.parentNode;
		if (nPa.className) {
			if (strClassNames.indexOf(nPa.className)!=(-1)){
				nPa.style["display"]="block";
				return dyna_showParentsByClasses(nPa, strClassNames);
			}
		}
	}
	delete nPa;
	return true;
}

function dyna_stopBubbling(evt) {
//function expects window.event.
//calling example: var res = dyna_stopBubbling(event);
//function tries several bubbling schemas to cancel event propagation.
//event propagation happens when a child element hands the event to its parent.
//in such cases a function that was meant to be executed once, 
//could be executed several times, yielding unexpected results.

	if (evt) {
		if (evt.stopPropagation) evt.stopPropagation();
		if (evt.preventDefault) evt.preventDefault();
		if (evt.preventBubble) evt.preventBubble();
		if (evt.cancelBubble) evt.cancelBubble=1;
	}
	return true;
}

function dyna_ToggleVis(evt, tagToHide, classToHide, idToShow, parentclassesToShow) {
//function expects evt == window.event.
//call from click event like so: onclick="dyna_ToggleVis(event,'li','menuitem','menuitem2','submenudefinitie, menudefinitie');".
//function first hides all menu tags with a tag tagToHide and class classToHide.
//function then shows all parents with classes parentclassesToShow of element idToShow.
//function then shows element idToShow.
//thus only one branch of the menu tree is shown at a time.

	if ((document.getElementById)&&(idToShow)) {
		var elmt=new Object(document.getElementById(idToShow));
		if ((elmt)&&(elmt.nodeName)) {
			dyna_styliseAllTagsByClass(tagToHide, classToHide, 'display', 'none');
			dyna_showParentsByClasses(elmt, parentclassesToShow);
			elmt.style.display = 'block';
		}
		delete elmt;
	}
	dyna_stopBubbling(evt);
	return false;
}

function dyna_ArrowDown(idImgToPointDown, strClassImgToPointRight) {
//call from click event like so: onclick="dyna_ArrowDown('img_sublevel388','sublevel_image');".
//function checks for existence of image with id idImgToPointDown.
//If it exists, function sees to it that all tags of type Image, with class strClassImgToPointRight get a right-pointing arrow
//function then makes the image with id idImgToPointDown have a down-pointing arrow.
//thus allowing to have only one element with a down-pointing arrow at a time.

var elmt, strSrc;

//make the image with id idImgToPointDown have a down-pointing arrow.
	if ((document.getElementById)&&(idImgToPointDown)) {
		elmt = document.getElementById(idImgToPointDown);
		if ((elmt)&&(elmt.src)) {
			strSrc = elmt.src.toLowerCase();
			if (strSrc.indexOf("foldertrue",1)>1) {
				//when img exists, reset the arrow on all images
				var ret = dyna_ArrowRight(strClassImgToPointRight);
				//make our image have down-pointing arrow
				elmt.src = "/images/system/folderdown.gif";
			}
		}
	}
	delete elmt;
	delete strSrc;
	return true;
}

function dyna_ArrowRight(strClassImgToPointRight) {
//all tags of type Image, with class classImgToPointRight get a right-pointing arrow

var elmt, strSrc, myNodeList;

	if ((document.getElementsByTagName)&&(strClassImgToPointRight)) {
		myNodeList = document.getElementsByTagName('img');
		for(var i = new Number(0); i<myNodeList.length; i++) {
			elmt = myNodeList[i];
			if ((elmt)&&(elmt.className)&&(elmt.src)){
				if(elmt.className==strClassImgToPointRight) {
					strSrc = elmt.src.toLowerCase();
					if (strSrc.indexOf("folderdown",1)>1) {
						elmt.src = "/images/system/foldertrue.gif";
					}
				}
			}
		}
		delete i;
	}
	delete myNodeList;
	delete elmt;
	delete strSrc;
	return true;
}
