/*
* Tjerk Valentijn 2004 Eurotransplant ICT
* JS utilities for ET Web
*/

/* for two sidecolumns and for setting location of helper navigation */
function setSideColHeights() {
	var lc = document.getElementById('relative-navigation');
	var mc = document.getElementById('content');
	var rc = document.getElementById('secondary-navigation');

	lc.style.height='auto';
	mc.style.height='auto';
	rc.style.height='auto';

	var lcHeight = mc.offsetHeight;
	var mcHeight = mc.offsetHeight;
	var rcHeight = rc.offsetHeight;
	var height   = "";
	
	if (mcHeight < rcHeight) {
		height = rcHeight;
	} else {
		height = mcHeight;
	}	

	if (height < 440) {
		height = 440;
	}

	lc.style.height = (height + 5) + "px";
	mc.style.height = height + "px";
	rc.style.height = (height - 15) + "px";

/* window.status = document.compatMode + "; " + navigator.userAgent; */
}

/* for primary navigation menus. only should and need to load in Exploder */
sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}

/* for secondary navigation menus. onload close menus except for newsalertmenu */
function initiateMenu() {
	document.getElementById("secmenu-item1").style.display="none";
	document.getElementById("secmenu-item2").style.display="none";
	return;
}

/* for secondary navigation menus. onclick show or hide menuitem */
function changeMenuItemStatus(cObject) {

	var cObjectIndex = cObject.id.charAt(4); // plusx

	var curStyle = document.getElementById("secmenu-item" + cObjectIndex).style;
	var imgname = cObject.getAttribute('src');
	if (curStyle.display != "none") {
		curStyle.display = "none";
		cObject.setAttribute("src","pics/plus.gif");
	} else {
		curStyle.display = "block";
		cObject.setAttribute("src","pics/min.gif");
	}	

	for (i=0;i<3;i++) {
		if (i != cObjectIndex) {
			document.getElementById("secmenu-item" + i).style.display="none";
			document.getElementById("plus" + i).setAttribute("src","pics/plus.gif");
		}
	}

	setSideColHeights();
	return;
}

/* see the alaistapart website, this is currently not used */
function tableRuler() {
	if (document.getElementById && document.createTextNode) {
		var defs=document.getElementsByTagName('dl');
		var dts = defs[0].getElementsByTagName('dt');
		var dds = defs[0].getElementsByTagName('dd');
		for(var j=0;j<dts.length;j++) {
       			dts[j].onmouseover=function(){this.className='ruled';return false}
       			dts[j].onmouseout=function() {this.className='';return false}
   	 	}
 	}
}

/* add url to a link for in printpage */
function showHREF() {
	if (document.getElementsByTagName) {
		onlyContentLinks = document.getElementById("content");
		whichLink = onlyContentLinks.getElementsByTagName("a");
		for (var i=0; i<whichLink.length; i++) {
			useLink = whichLink[i];
			showLink = useLink.getAttribute("href")

			if (useLink.getAttribute("target") != "_blank") {
				checkShow = showLink.lastIndexOf("/");
				showLink = showLink.substring(checkShow+1,showLink.length);

				lastSlash = document.location.href.lastIndexOf("/");
				directory = document.location.href.substring(0,lastSlash);

				showLink = directory + '/' + showLink;
			}

			newSpan = document.createElement("span");
			showTitle = document.createTextNode(' [' + showLink + ']');
			newSpan.appendChild(showTitle);
			useLink.parentNode.insertBefore(newSpan,useLink.nextSibling);
			newSpan.className='printLink';
		}
	}
}


/* script adds a class .external to an external link */
/* this is because the old beast from Redmond does not support css2 attribute selectors */
/* Tjerkv 1/12/2005 8:39AM added feature for explorer to set language */

function addExternalLinkClass() {
	if (navigator.userAgent.toLowerCase().indexOf('msie') != -1) {
		aa = document.getElementsByTagName('a');
		for (i=0; i<aa.length; i++) {
			//alert(aa[i].lang);
			var lang = aa[i].getAttribute("xml:lang");
			if (lang != "") {
				aa[i].className += ' lang_'+lang;
			}
			if (aa[i].target == "_blank") {
				aa[i].className += ' external';
			}
		}
	}
}


/* JavaScript 'find as you type' feature, inspired by MozillaThunderbird mail-client */
/* best used on dl lists (with dt and dd) and ol or ul (with li) */
/* invoke like <input id="searchfield" type="text" onkeyup="findAsYouType(this.value,'dd','dt');" onblur="findAsYouType(this.value,'dd','dt');" /> */
/* version 1.0 Tjerk Valentijn 2004 */

function findAsYouType(str, sTag, sTagTitle) {
	str = str.toLowerCase();
	var liList = document.getElementsByTagName(sTag);
	for (var i=0; i<liList.length; i++) {
		var kids = liList[i].childNodes;
		if (kids[0].nodeType == 3) {
			//nodetype: text
			var cTag = kids[0].nodeValue.toLowerCase();
		}
		if (kids[0].nodeType == 1) {
			//nodetype: element, so get it's text
			kidskids = kids[0].childNodes;
			var cTag = kidskids[0].nodeValue.toLowerCase();
		}
		if(cTag.indexOf(str) == -1) {
			liList.item(i).style.display='none';
			if (sTagTitle != '') {
				document.getElementsByTagName(sTagTitle).item(i).style.display='none';
			}
		} else {
			liList.item(i).style.display='block';
			if (sTagTitle != '') {
				document.getElementsByTagName(sTagTitle).item(i).style.display='block';
			}
		}
	}
}


function hideElements(strName) {
	var list = document.getElementsByTagName(strName);
	for (var i=0; i<list.length; i++) {
		document.getElementsByTagName(strName).item(i).style.display='none';
	}
}

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

/* ---------------------------------------------- RUNTIME (no functions only execution)  ---------------------------------------------- */

if (window.attachEvent) {
	/* only works in Exploder, not needed in Moz/Opera */
	/* for primary navigation menus */
	window.attachEvent("onload", sfHover);
}

addLoadEvent(initiateMenu);
addLoadEvent(setSideColHeights);
addLoadEvent(addExternalLinkClass);
