/* --- JavaScript --- */
/* --- General --- */

/* --- add functions to onload event: addLoadEvent(functionName); --- */
/* --- http://simonwillison.net/2004/May/26/addLoadEvent/ --- */
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	}
	else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
}

/* --- createElement() --- */
function createElement(element) {
	if (typeof document.createElementNS != 'undefined') {
		return document.createElementNS('http://www.w3.org/1999/xhtml', element);
	}
	if (typeof document.createElement != 'undefined') {
		return document.createElement(element);
	}
	return false;
}

/* --- setAttributes() --- */
function setAttributes(element,attr) {	// format attr: [['class','actief'],['href','http://www.test.xx']]
	if (typeof element.setAttributeNS != 'undefined') {
		for (a=0; a<attr.length; a++) {
			element.setAttributeNS('http://www.w3.org/1999/xhtml',attr[a][0],attr[a][1]);
		}
	}
	if (typeof element.setAttribute != 'undefined') {
		for (a=0; a<attr.length; a++) {
			element.setAttribute(attr[a][0],attr[a][1]);
		}
	}
	return false;
}

/* --- add className --- */
function addClass(node, className) {
	removeClass(node, className);	// make sure there won't be any doubles
	node.className += " " + className;
}

/* --- remove className --- */
function removeClass(node, className) {
	node.className = node.className.replace(className,"");
}

/* --- check if node has className --- */
function hasClass(node, className) {
	var nodeClass = node.className;
	if (!className && nodeClass != "") return true;			// if no className is specified any className will do
	if (className && nodeClass.indexOf(className) > -1) {	// match, but not exact
		var nodeClasses = nodeClass.split(/\s+/);			// seperate class names (devided by one or more whitespaces)
		for (c=0; c<nodeClasses.length; c++) {
			if (nodeClasses[c] == className) return true
		}
	}
	return false;
}

/* --- get first ancestor that matches the property --- */
function getAncestor(node, property, value, levels) {	// levels is an optional argument
	var parent = node;
	var level = (levels) ? levels : 1;
	do {
		parent = parent.parentNode;
		if (!parent || parent.nodeName == "HTML") return false;	// there is no parent or parent is <html>
		
		if ((parent[property] == value) ? true : hasClass(parent, value)) return parent; // return parent if property matches value
			
		if (levels) level--;
	} while (parent.parentNode && parent.parentNode.nodeName != "HTML" && level > 0);
	return false;
}

/* --- check for CSS support --- */
function cssSupport() {
	if (!document.styleSheets) return false;	// styleSheets object is not supported
	var css = document.styleSheets;
	for (s=0; s<css.length; s++) {
		if (s == 0) {
			if (!(css[0].cssRules || css[0].rules)) return false;	// both methods (cssRules/rules) are not supported
		}
		if (!css[s].disabled) return true;	// at least one of the stylesheets is not disabled
	}
	return false;	// stylesheets are all disabled or not supported at all
}


/* =================================== */
/* ===== site specific functions ===== */
/* =================================== */


///////////// LECGROEP /////////////

/*lecGroep = function() {
	var lectricGroep = document.getElementById('lectricGroep');
	var tooltip = document.getElementById('tooltip');
	if (!lectricGroep || !tooltip) return;
		
	tooltip.onmouseover = function() { showTip(true) };
	tooltip.onmouseout = function() { showTip(false) };
	
	var lecGroepLinks = lectricGroep.getElementsByTagName('a');
	for (a=0; a<lecGroepLinks.length; a++) {
		var lecGroepLink = lecGroepLinks[a];
		
		var tipParent = getAncestor(lecGroepLink, "nodeName", "DIV", 2);
		if (!tipParent) continue;
		
		lecGroepLink.onmouseover = function() { showTip(true) };
		lecGroepLink.onmouseout = function() { showTip(false) };
		break;
	}
}

function showTip(show) {
	var parent = document.getElementById('lectricGroep');
	show ? addClass(parent, "showTooltip") : removeClass(parent, "showTooltip");
}*/


///////////// OVERLABEL /////////////

/* --- overLabel --- place labels over corresponding form control --- */
/* --- based on http://www.alistapart.com/articles/makingcompactformsmoreaccessible/ ---*/
overLabel = function() {
	var labels;
	if (!(labels = document.getElementsByTagName('label'))) return;
	
	for (l=0; l<labels.length; l++) {
		var label = labels[l];
		if (!(hasClass(label, "overLabel") && label.htmlFor)) continue;
		
		var overControl = document.getElementById(label.htmlFor);
		if (!overControl) continue;
		
		label.forControl = overControl;	// make reference from label to corresponding control
		
		if (overControl.value === "") addClass(overControl.parentNode, "inactive");	// make sure label is only placed on top of control in case it has no value which is not always the case after a reload
		
		overControl.onfocus = function() {
			removeClass(this.parentNode, "inactive");
		}
		
		overControl.onblur = function() {
			if (this.value === "") addClass(this.parentNode, "inactive");
		}
		
		label.onclick = function() {	// needed for Safari
			this.forControl.focus();	// give focus to corresponding control
		}
	}
	
	addClass(document.body, "jsLabelsOn");	// CSS hook to turn it on
}
		
/*clickEmpty = function() {
	var parentSelect = this.parentNode;
	parentSelect.options[0] = parentSelect.labelOption;
	parentSelect.options[0].selected = "selected";
}*/


///////////// INIT MAIN MENU /////////////

initMainMenu = function() {
	var mainMenu = document.getElementById('mainMenu');
	if (!mainMenu) return;
	
	var menuItems = mainMenu.getElementsByTagName('a');
	for (i=0; i<menuItems.length; i++) {
		var menuItem = menuItems[i];
		
		menuItem.onmouseover = menuItem.onfocus = function() {
			addClass(this.parentNode, "jsHover");
		}
		
		menuItem.onmouseout = menuItem.onblur = function() {
			removeClass(this.parentNode, "jsHover");
		}
	}
	
	addClass(mainMenu, "jsHoverOn");
}


///////////// EASY POPUPS /////////////

/*easyPopups = function() {
	var links = document.getElementsByTagName('a');
	pop(links);
	
	var areas = document.getElementsByTagName('area');
	pop(areas);
}

function pop(pops) {
	for (p=0; p<pops.length; p++) {
		var pop = pops[p];
		if (pop.rel != "extern") continue;
		
		pop.onclick = function() {
			window.open(this.href, '_blank');
			return false;
		}
	}
}*/


///////////// ADD JS BUTTONS /////////////

addJSbuttons = function() {
	if (window.print) addJSprint();
}

function addJSprint() {
	var pageTools = document.getElementById('pageTools');
	if (!pageTools) return;
	
	var toolMenu = pageTools.getElementsByTagName('ul')[0];
	if (!toolMenu) return;
	
	var printButton = '<li id="printPage"><a href="javascript:window.print();">Print deze pagina</a></li>';
	toolMenu.innerHTML += printButton;
}


///////////// INFOLIST /////////////

initInfoList = 	function() {
	var siteBody = document.getElementById('siteBody');
	if (!siteBody) return;
	
	var ulists = siteBody.getElementsByTagName('ul');
	for (u=0; u<ulists.length; u++) {
		infoLists(ulists[u]);
	}
	
	var olists = siteBody.getElementsByTagName('ol');
	for (o=0; o<olists.length; o++) {
		infoLists(olists[o]);
	}
}

function infoLists(infoList) {
	if (!getAncestor(infoList, "className", "infoList", 3)) return;
	
	var infoLinks = infoList.getElementsByTagName('a');
	for (a=0; a<infoLinks.length; a++) {
		var infoLink = infoLinks[a];
		if (!infoLink.id) continue;
		
		var subContent = getItemInfo(infoLink.id);
		if (!subContent) continue;
		
		infoLink.href = "#" + subContent.id;
		infoLink.subContent = subContent;
		
		if (hasClass(infoLink.parentNode, "selected")) infoList.selected = infoLink.parentNode;
		if (hasClass(infoLink.subContent, "show")) infoList.show = infoLink.subContent;
		
		infoLink.onclick = function() {
			var infoList = getAncestor(this, "tagName", "UL", 3) || getAncestor(this, "tagName", "OL", 3);
			
			if (infoList) {
				if (infoList.selected) removeClass(infoList.selected, "selected");
				if (infoList.show) removeClass(infoList.show, "show");
				infoList.selected = this.parentNode;
				infoList.show = this.subContent;
			}
			
			addClass(this.parentNode, "selected");
			addClass(this.subContent, "show");
			
			return false;
		}
	}
}

function getItemInfo(linkID) {	// home.js has it's own version of this function which will override this one if home.js is included
	return document.getElementById(linkID + "info");
}


///////////// SITEMAP /////////////

initSitemap = function() {
	var sitemap = document.getElementById('sitemap');
	if (!sitemap) return;
	
	var imgPrefix = "/images/isbw/ico_sitemap_";	// prefix of icon, including path
	var imgExt = ".gif";					// extension of icon
	
	var parents = false;
	
	var items = sitemap.getElementsByTagName('li');
	for (i=0; i<items.length; i++) {
		var item = items[i];
		if (item.getElementsByTagName('li').length < 1) continue;
		
		parents = true;
		
		if (getAncestor(item, "id", "sitemap", 1)) {
			var imgAdditionalName = "toplvl_";
			var imgSize = "21";
		}
		else {
			var imgAdditionalName = "";
			var imgSize = "9";
		}
		
		if (!hasClass(item, "open")) addClass(item, "close");	// close all items that do not have class="open"
		var icon = hasClass(item, "close") ? "Open" : "Sluit";
		
		var control = createElement('a');
		setAttributes(control, [['href', '#']]);
		addClass(control, "control");
		control.innerHTML = '<img src="' + imgPrefix + imgAdditionalName + icon.toLowerCase() + imgExt + '" width="' + imgSize + '" height="' + imgSize + '" alt="' + icon + ' dit item" />';
		var children = item.getElementsByTagName('ul')[0];
		item.insertBefore(control, children);
		
		control.onclick = function() {
			var item = this.parentNode;
			
			//hide sitemap div IE height troubles
			document.getElementById('sitemap').style.display = "none";
			
			var img = this.getElementsByTagName('img')[0];
			if (!img) return;
			
			if (hasClass(item, "close")) {
				removeClass(item, "close");
				
				img.src = img.src.replace("open", "sluit");
				img.alt = img.alt.replace("Sluit", "Open");
			}
			else {
				addClass(item, "close");
				
				img.src = img.src.replace("sluit", "open");
				img.alt = img.alt.replace("Open", "Sluit");
			}
			
			//show sitemap div
			document.getElementById('sitemap').style.display = "block";
			return false;
		}
	}
	
	if (parents) addClass(sitemap, "jsSitemapOn");	// only activate sitemap when there are parents
}


///////////// FAQ /////////////

initFaq = function() {
	var faq = document.getElementById('faq');
	if (!faq) return;
	
	var answers = faq.getElementsByTagName('dd');
	if (!answers[0] || !answers[0].previousSibling) return;	// either the previousSibling property is not supported or the <dl> is corrupt (starts with a <dd>)
	
	for (a=0; a<answers.length; a++) {
		var answer = answers[a];
		
		removeClass(answer, "open");	// collapse answer
		removeClass(answer, "start");	// remove non-JS layout
		
		var intros = answer.getElementsByTagName('span');
		for (i=0; i<intros.length; i++) {
			if (!hasClass(intros[i], "intro")) {
				if (intro) {
					var rest = true;
					break;
				}
				continue;
			}
			var intro = intros[i];
		}
		if (intro && rest) intro.innerHTML += "<span>...</span>";	// add dots after intro, but only if the intro is not the whole answer
		
		var ddArr = [];
		var prevSibling = answer;
		
		do {	// find corresponding <dt>
			if (!prevSibling.done && prevSibling.nodeName == "DD") {
				ddArr[ddArr.length] = prevSibling;
				prevSibling.done = true;
			}
			var prevSibling = prevSibling.previousSibling;
		} while (prevSibling.nodeName == "DD" || prevSibling.nodeType == 3);
		
		if (prevSibling.nodeName != "DT" || ddArr.length == 0) continue;
		var question = prevSibling;
		
		var questionLabels = question.getElementsByTagName('span');
		for (s=0; s<questionLabels.length; s++) {
			if (!hasClass(questionLabels[s], "question")) continue;
			var questionLabel = questionLabels[s];
			break;
		}
		if (!questionLabel) return;
		questionLabel.innerHTML = '<a href="#">' + questionLabel.innerHTML + '</a>';	// add <a> to the question in order to make it accessible for keyboard
				
		question.answers = ddArr;
		
		questionLabel.onclick = function() {	// click question
			var dl = getAncestor(this.parentNode, "nodeName", "DL");
			if (!dl) return;
			
			if (dl.current && this.parentNode != dl.current) {
				for (c=0; c<dl.current.answers.length; c++) {
					removeClass(dl.current.answers[c], "open");
				}
				removeClass(dl.current, "open");
			}
			
			var openState = hasClass(this.parentNode, "open");
			for (n=0; n<this.parentNode.answers.length; n++) {
				openState ? removeClass(this.parentNode.answers[n], "open") : addClass(this.parentNode.answers[n], "open")
			}
			openState ? removeClass(this.parentNode, "open") : addClass(this.parentNode, "open")
			
			dl.current = this.parentNode;
			
			return false;
		}
		
		questionLabel.onmouseover = questionLabel.onfocus = function() {	// focus question
			addClass(this, "jsHover");
		}
		
		questionLabel.onmouseout = questionLabel.onblur = function() {	// blur question
			removeClass(this, "jsHover");
		}
		
		var checkBoxes = answer.getElementsByTagName('input');
		for (i=0; i<checkBoxes.length; i++) {
			var checkBox = checkBoxes[i];
			if (!(hasClass(checkBox, "notUseful") || hasClass(checkBox, "useful"))) continue;
			
			if (hasClass(checkBox, "notUseful")) answer.notUseful = checkBox;
			if (hasClass(checkBox, "useful")) answer.useful = checkBox;
			
			var divs = answer.getElementsByTagName('div');
			for (d=0; d<divs.length; d++) {
				var missInAnswer = divs[d];
				if (!hasClass(missInAnswer, "missingInAnswer")) continue;
				
				answer.missing = missInAnswer;
				break;
			}
			
			checkBox.onclick = function() {	// select useful/not useful
				var answer = getAncestor(this, "tagName", "DD", 5);
				if (!answer) return;
				
				if (answer.notUseful.checked) {
					addClass(answer, "notUseful");
				}
				else {
					removeClass(answer, "notUseful");
				}
			}
		}
	}
}


///////////// CUSTOM SELECTS /////////////

customSelects = function() {
	var searchFilters = document.getElementById('searchFilters');
	if (!searchFilters) return;
	
	var pulldowns = searchFilters.getElementsByTagName('div');
	for (p=0; p<pulldowns.length; p++) {
		var pulldown = pulldowns[p];
		if (!hasClass(pulldown, "pulldown")) continue;
		
		var labels = pulldown.getElementsByTagName('p');
		for (l=0; l<labels.length; l++) {
			if (!hasClass(labels[l], "label")) continue;
			var label = labels[l];
			break;
		}
		
		if (label) var selectBox = getAncestor(label, "tagName", "DIV", 2);
		if (!selectBox) continue;
		
		label.innerHTML = '<a href="#">' + label.innerHTML + '<img class="icon" src="images/ico_select.gif" width="23" height="23" alt="" /></a>';
		
		selectBox.onclick = function() {
			hasClass(this, "open") ? removeClass(this, "open") : addClass(this, "open");
		}
		
		/*var labelLink = label.getElementsByTagName('a')[0];
		if (labelLink) {
			labelLink.onclick = function() {
				hasClass(this.parentNode, "open") ? removeClass(this.parentNode, "open") : addClass(this.parentNode, "open");
				return false;
			}
		}*/
		
		selectBox.onmouseout = selectBox.onblur = function() {
			removeClass(this, "open");
		}
		
		addClass(pulldown, "select");
	}
}


///////////// CLICKABLE ITEMS /////////////

/* --- clickableItems --- make entire itemes clickable --- */
/*clickableItems = function() {
	var siteBody = document.getElementById('siteBody');
	if (!siteBody) return;
	
	// publications section -|- add section for every clickable item type //
	var uls = siteBody.getElementsByTagName('ul');
	for (u=0; u<uls.length; u++) {
		var ul = uls[u];
		if (!hasClass(ul, "publications")) continue;
		
		var lis = ul.getElementsByTagName('li');
		for (l=0; l<lis.length; l++) {
			var li = lis[l];
			
			clickAllOver(li);
		}
	}
	// end publications section //
}*/

/* --- clickAllOver --- */
/*clickAllOver = function(node) {

	node.getUrl = function() {
		var url = this.getElementsByTagName('a')[0];
		return (url) ? url.href : false; 
	}
	
	node.url = node.getUrl();
	
	if (!node.url) return;
	
	node.onclick = function() {
		window.location.href = this.url;
	}
	
	node.onmouseover = function() {
		addClass(this, "jsHover");
	}
	
	node.onmouseout = function() {
		removeClass(this, "jsHover");
	}
}*/


///////////// SELECT NAVIGATION /////////////

/* --- initSelectNav --- initialezes autosubmit on <select>s that have class="selectNav", works with keyboard too (in IE, FX and Op) --- */
/*initSelectNav = function() {
	var selects = document.getElementsByTagName('select');
	
	var countSelectNavs = false;
	for (s=0; s<selects.length; s++) {
		var selectNav = selects[s];
		if (!hasClass(selectNav, "selectNav")) continue;
		
		selectNav.onfocus = function() {
			this.origVal = this.value;
		}
		
		selectNav.onchange = function() {
			if (this.newVal) this.origVal = this.newVal;
			this.newVal = this.value;
		}
		
		selectNav.onblur = selectNav.onclick = function() {
			if (this.newVal && this.newVal != this.origVal) this.form.submit();
		}
		
		countSelectNavs = true;
	}
	
	if (countSelectNavs) addClass(document.body, "jsSelectNavOn");
}*/


///////////// OPEN CHATBOX /////////////

var chatLinkText, chatLinkPos, chatLinkText2, chatLinkPos2;

openChatBox = function() {
	var chatBox = document.getElementById('chatBox');
	if (!chatBox) return;
	
	var snippets = [["eduAdvice", chatLinkText, chatLinkPos], ["eduAdvice2", chatLinkText2, chatLinkPos2]];
	
	for (s=0; s<snippets.length; s++) {
		initChatLinks(chatBox, snippets[s]);
	}
	
	var closeLinks = chatBox.getElementsByTagName('a');
	for (a=0; a<closeLinks.length; a++) {
		var closeLink = closeLinks[a];
		if (!hasClass(closeLink, "close")) continue;
		
		closeLink.onclick = function() {
			var chatBox = document.getElementById('chatBox');
			if (!chatBox) return;
			
			removeClass(document.body, "boxOpen");
			return false;
		}
	}
}

initChatLinks = function(chatBox, snippet) {
	var ancestor = snippet[0];
	var chatLinkText = snippet[1];
	var chatLinkPos = snippet[2];

	var eduAdvice = document.getElementById(ancestor);
	if (!eduAdvice) return;
	
	var chatLinkItem = createElement('li');
	chatLinkItem.innerHTML = '<a class="chatLink" href="#chatBox">' + (chatLinkText ? chatLinkText : 'Chat met een medewerker') + '</a>'; // chatLinkText is set in content
	
	var listItems = eduAdvice.getElementsByTagName('li');
	if ((chatLinkPos || chatLinkPos === 0) && chatLinkPos < listItems.length) {
		for (i=0; i<listItems.length; i++) {
			if (i != chatLinkPos) continue;
			var listItem = listItems[i];
			
			listItem.parentNode.insertBefore(chatLinkItem, listItem);
			break;
		}
	}
	else {
		var list = eduAdvice.getElementsByTagName('ul')[0];
		if (!list) return;
		
		list.appendChild(chatLinkItem);
	}
	
	var box = document.getElementById('box');
	if (!box) return;
	
	addClass(chatBox, "jsCalc");	// class="jsCalc" makes shure (using CSS) JS can calculate clientHeight
	var boxHeight = box.clientHeight;
	removeClass(chatBox, "jsCalc");

	//var chatLink = document.getElementById('chatLink');
	var chatLinks = eduAdvice.getElementsByTagName('a');
	for (c=0; c<chatLinks.length; c++) {
		var chatLink = chatLinks[c];
		if (!hasClass(chatLink, "chatLink")) continue;
		
		chatLink.boxHeight = boxHeight; // ref to boxHeight
		
		chatLink.onclick = function() {
			this.calcPos();
			addClass(document.body, "boxOpen");
			//return false;
		}
		
		chatLink.calcPos = function() {
			if (self.innerHeight) var viewportHeight = self.innerHeight;	// all except Explorer
			else if (document.documentElement && document.documentElement.clientHeight) var viewportHeight = document.documentElement.clientHeight;	// Explorer 6 Strict Mode
			else if (document.body) var viewportHeight = document.body.clientHeight;	// other Explorers
		
			if (viewportHeight && (this.boxHeight || this.boxHeight === 0)) {
				var heightDiff = viewportHeight - this.boxHeight;
				var boxTop = heightDiff / 2;
				box.style.top = heightDiff > 253 ? "203px" : (boxTop > 0 ? boxTop + "px" : "0px");
			}
		}
		
		break;
	}
}

///////////// LOCATIONINFO/////////////
var locationLinkText, locationLinkPos;

openLocationBox = function() {
	var locationBox = document.getElementById('locatieBox');
	if (!locationBox) return;
	
	var snippet = [["routeLink", locationLinkText, locationLinkPos]];
	
	for (s=0; s<snippet.length; s++) {
		initLocationLink(locationBox, snippet[s]);
	}
	
	var closeLinks = locationBox.getElementsByTagName('a');
	for (a=0; a<closeLinks.length; a++) {
		var closeLink = closeLinks[a];
		if (!hasClass(closeLink, "close")) continue;
		
		closeLink.onclick = function() {
			var locationBox = document.getElementById('locatieBox');
			if (!locationBox) return;
			
			removeClass(document.body, "boxOpen");
			return false;
		}
	}
}

initLocationLink = function(locationBox, snippet) {
	var ancestor = snippet[0];
	var locationLinkText = snippet[1];
	var locationLinkPos = snippet[2];
	
	var box = document.getElementById('box');
	if (!box) return;
	
	addClass(locationBox, "jsCalc");	// class="jsCalc" makes shure (using CSS) JS can calculate clientHeight
	var boxHeight = box.clientHeight;
	removeClass(locationBox, "jsCalc");

	var temp = document.getElementById(ancestor);
	if (!temp) return;
	
	var locationLinks = temp.getElementsByTagName('a');
	for (c=0; c<locationLinks.length; c++) {
		var locationLink = locationLinks[c];
		if (!hasClass(locationLink, "locationLink")) continue;
		
		locationLink.boxHeight = boxHeight; // ref to boxHeight
		
		locationLink.onclick = function() {
			this.calcPos();
			addClass(document.body, "boxOpen");
			//return false;
		}
		
		locationLink.calcPos = function() {
			if (self.innerHeight) var viewportHeight = self.innerHeight;	// all except Explorer
			else if (document.documentElement && document.documentElement.clientHeight) var viewportHeight = document.documentElement.clientHeight;	// Explorer 6 Strict Mode
			else if (document.body) var viewportHeight = document.body.clientHeight;	// other Explorers
		
			if (viewportHeight && (this.boxHeight || this.boxHeight === 0)) {
				var heightDiff = viewportHeight - this.boxHeight;
				var boxTop = heightDiff / 2;
				box.style.top = heightDiff > 253 ? "203px" : (boxTop > 0 ? boxTop + "px" : "0px");
			}
		}
		
		break;
	}
}

///////////// POPINFO /////////////

/* --- popInfo --- */
/*popInfo = function() {
	// DIV section -|- add section for every tagName //
	var divs = document.getElementsByTagName('div');
	popThisInfo(divs);
	// end DIV section //
	
	addClass(document.body, "jsPopInfoOn");	// CSS hook to turn it on
}

function popThisInfo(nodelist) {
	for (n=0; n<nodelist.length; n++) {
		var node = nodelist[n];
		if (!hasClass(node, "popInfo")) continue;
		
		node.onmouseover =  function() {
			addClass(this, "jsHover");
		}
		
		node.onmouseout = function() {
			removeClass(this, "jsHover");
		}
		
		// in order to make it work for keyboard as well... //
		var popLink = node.getElementsByTagName('a')[0];
		if (!popLink) continue;
		
		var ancestor = popLink;
		popLink.ancestorLevel = 0;
		do {
			ancestor = ancestor.parentNode;
			popLink.ancestorLevel++;
		} while (ancestor == node || popLink.ancestorLevel > 10);
		
		if (popLink.ancestorLevel > 10) continue;
				
		popLink.onfocus = function() {
			var node = getParent(this);
			node.onmouseover();
		}
		
		popLink.onblur = function() {
			var node = getParent(this);
			node.onmouseout();
		}
	}
}

function getParent(node) {
	var ancestor = node;
	for (p=1; p<node.ancestorLevel; p++) {
		ancestor = ancestor.parentNode;
	}
	return ancestor;
}*/

function showHideTab(showelement,hideelements) {
	var dispStyle;

	//hide siteContent and sideBar div for IE 6
	document.getElementById('siteContent').style.display = "none";
	document.getElementById('sideBar').style.display = "none";
			
	if (navigator.appName.indexOf("Microsoft") > -1) { dispStyle = 'inline'; } 
	else { dispStyle = 'block';	}
	
	var opleidingTabs = document.getElementById('opleidingen');
	var tabs = opleidingTabs.getElementsByTagName('li');
	/*
	var siteContent = document.getElementById('trainingBody');
	var tabContent = siteContent.getElementsByTagName('div') */;
	for (var j=0; j<tabs.length; j++) {
		var tab = tabs[j];
		removeClass(tab, "active");
		//document.getElementById(tab).className = "";
	}
	
	for (var i=0; i<hideelements.length; i++) {
		var hideelement = hideelements[i];
		//var tab = hideelement+'tab';
		//var tab = document.getElementById(hideelement+'tab');
		//removeClass(showelement+'tab', "firstactive");
		document.getElementById(hideelement).style.display = "none";
		document.getElementById(hideelement).style.height = "1px";	
		document.getElementById(hideelement).style.visibility = "hidden";		
	} 
	/* for (var i=0; i<tabs.length; i++) {
		var tab = tabs[i];
		
		addClass(tab,"");
			//document.getElementById(tab).style.display = dispStyle; 
			//document.getElementById(tab).style.height = "auto";  	
		if ((showelement+'tab') == tab) {
			addClass(tab,"firstactive");
		}
		
	}  */
	//addClass(showelement+'tab',"firstactive");
	
	/* for (var j=0; j<tabContent.length; j++) {
		var content = tabContent[i];
		if (!hasClass(content, "tabContent")) continue;
		if (hassClass(content,"tabContent")) {
			document.getElementById(content).style.display = "none"; 
			document.getElementById(content).style.height = "1px";  	
		}
	} */
	//if (document.getElementById(showelement+'tab'))	{
		//document.getElementById(showelement+'tab').className = "firstactive";
		//addClass(showelement+'tab',"firstactive");
		document.getElementById(showelement+'tab').className = "active";
		document.getElementById(showelement).style.display = dispStyle; 
		document.getElementById(showelement).style.height = "auto";  
		document.getElementById(showelement).style.visibility = "visible";		
	//}

	document.getElementById('siteContent').style.display = "block";
	document.getElementById('sideBar').style.display = "block";
}

function showHideTabs(showelement) {
	var dispStyle;

	//hide siteContent and sideBar div for IE 6
	document.getElementById('siteContent').style.display = "none";
	document.getElementById('sideBar').style.display = "none";
			
	if (navigator.appName.indexOf("Microsoft") > -1) { dispStyle = 'inline'; } 
	else { dispStyle = 'block';	}
	
	var opleidingTabs = document.getElementById('opleidingen');
	var tabs = opleidingTabs.getElementsByTagName('li');
	
	//hide all tabs
	for (var j=0; j<tabs.length; j++) {
		var tab = tabs[j];
		var selectedTab = document.getElementById(showelement+'tab')
		if (selectedTab == tab) {
			if (hasClass(selectedTab,"first")) {
				removeClass(tab, "first");	
				addClass(tab, "firstactive");					
			}
			else
				addClass(tab,"active");
		} 
		else {		
			removeClass(tab, "active");		
		}
	}
	
	//show selected tab
	//document.getElementById(showelement+'tab').className = "active";
	//document.getElementById(showelement+'tab').style.display = dispStyle; 
	//document.getElementById(showelement+'tab').style.height = "auto";  
	//document.getElementById(showelement+'tab').style.visibility = "visible";

	var tabContent = document.getElementById('tabContents');
	var tabContainers = tabContent.getElementsByTagName('div'); 
	
	//show/hide selected tab div
	for (var j=0; j<tabContainers.length; j++) {
		var tabCt = tabContainers[j];
		if (document.getElementById(showelement) == tabCt) {
			tabCt.style.display = "block";
			tabCt.style.height = "auto";  		
		}
		else {
			tabCt.style.display = "none";
			tabCt.style.height = "auto";  
		}
	}	
	
	document.getElementById('siteContent').style.display = "block";
	document.getElementById('sideBar').style.display = "block";
}

IEfixHeight = function() {
	//hide siteContent and sideBar div for IE 6
	document.getElementById('siteContent').style.display = "none";
	document.getElementById('sideBar').style.display = "none";
	//hide siteContent and sideBar div for IE 6
	document.getElementById('sideBar').style.display = "block";
	document.getElementById('siteContent').style.display = "block";
}

///////////// MISSING IN ANSWER /////////////
function submitMissingInAnswer(formId) {
	$.ajax({
		type: "POST",
		url: "/smartsite.dws?id=ISBW-VGV-FEEDBACK",
		data: $("#form-"+formId).serialize(),
		success: function(html){
			$("#usefulForYou-"+formId).html('<p>Bedankt voor uw reactie.</p>');
			//$("#feedback-"+formId).text('<p>Bedankt voor uw reactie.</p>');
		},
		error:  function(html){
			$("#usefulForYou-"+formId).text('<p>Helaas is uw reactie kan niet worden verstuurd. Probeer het later nog eens.</p>');
		}
	});	
}
 
/* function attachEvents() {
	$(".submit").click(function(){
		missingInAnswer();
	});
	return false;
} */

/* $(document).ready(function() { 
	$(".missingInAnswer").each(function(n) {
		attachEvents(n+1);
		//alert(n);
	});	
	return false;
}); 
*/
/* ar getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1]
var FFextraHeight=parseFloat(getFFVersion)>=0.1? 3 : 0 //extra height in px to add to iframe in FireFox 1.0+ browsers

resizeCaller = function() {
	//var dyniframe=new Array()
	iframeids = document.getElementById('connexis');
	
	for (i=0; i<iframeids.length; i++) {
		if (document.getElementById)
			resizeIframe(iframeids)
		
		//reveal iframe for lower end browsers? (see var above):
		if ((document.all || document.getElementById) && iframehide=="no") {
			var tempobj=document.all? document.all[iframeids] : document.getElementById(iframeids)
			tempobj.style.display="block"
		}
	}
}

function resizeIframe(iframeid) {
	var currentfr= iframeid; //document.getElementById('connexis')
	
	if (currentfr && !window.opera){
		currentfr.style.display="block"
	
	if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight) //ns6 syntax
		currentfr.height = currentfr.contentDocument.body.offsetHeight+FFextraHeight; 
	else if (currentfr.Document && currentfr.Document.body.scrollHeight) //ie5+ syntax
		currentfr.height = currentfr.Document.body.scrollHeight;
	
	if (currentfr.addEventListener)
		currentfr.addEventListener("load", readjustIframe, false)
	else if (currentfr.attachEvent) {
			currentfr.detachEvent("onload", readjustIframe) // Bug fix line
			currentfr.attachEvent("onload", readjustIframe)
		}
	}
}

function readjustIframe(loadevt) {
	var crossevt=(window.event)? event : loadevt
	var iframeroot=(crossevt.currentTarget)? crossevt.currentTarget : crossevt.srcElement
	if (iframeroot)
		resizeIframe(iframeroot.id);
} */
/* =================================== */
/* === call functions on page load === */
/* =================================== */




/* --- call functions only if the used methods are supported --- */
if (document.getElementById && document.createElement) {
	addLoadEvent(addJSbuttons);
	if (cssSupport()) {
		//addLoadEvent(lecGroep);
		//addLoadEvent(popInfo);
		//addLoadEvent(initSelectNav);
		//addLoadEvent(overLabel);
		addLoadEvent(initMainMenu);
		addLoadEvent(initInfoList);
		addLoadEvent(initSitemap);
		addLoadEvent(initFaq);
		addLoadEvent(customSelects);
		addLoadEvent(openChatBox);
		//addLoadEvent(resizeIframe);
		addLoadEvent(openLocationBox);
	}
	//addLoadEvent(clickableItems);
	//addLoadEvent(easyPopups);
}
