/* <documentation about="ABOUT library.js" type="GENERAL">
	<summary>This file is a library: it contains general functions used for the entire application.
		No page initialisation calls are made in this file; there is one exception: Lib.addEvent(window, "unload", Lib.eventCache.flush): This removes all attached events.
		Make your function calls in the specific javascript files, in the [namespace].init()
	</summary>
	<namespace>nsUCBInternet</namespace>
</documentation> */
var Lib = {};

/* <documentation about="Lib.debug/Lib.allowAlert" type="global variables">
	<summary>These variables are used for debugging - do not change</summary>
	<namespace>Lib</namespace>
</documentation> */
Lib.debug = false;
Lib.allowAlert = true;

/* <documentation about="Lib.safari/Lib.opera/Lib.ie" type="global variables">
	<summary>Browser checks</summary>
	<namespace>Lib</namespace>
</documentation> */
Lib.safari = (navigator.userAgent.toLowerCase().indexOf('safari') != - 1);
Lib.opera = window.opera ? true : false;
Lib.ie = (document.all && document.getElementById) ? true : false;
Lib.ie6 = ((navigator.platform.toLowerCase() != -1) && (navigator.userAgent.toLowerCase().indexOf("msie 6")!=-1)) ? true : false;
Lib.pageIsStyled = false;
Lib.selectIsClicked = false;
Lib.selectAlternates = [];

/* <documentation about="Lib.newWindowToolTipText" type="global variables">
	<summary>Title text shown on mouse over of a link which opens in a new window</summary>
	<namespace>Lib</namespace>
</documentation> */
Lib.newWindowToolTipText = "deze link opent in een nieuw venster";


/* ========== CORE ============================================================================ */
/* <documentation about="Lib.addEvent" type="CORE FUNCTION">
	<summary>Adds events to elements of the DOM</summary>
	<namespace>Lib</namespace>
	<param type="object" descr="A reference to the node on which the event has been set (HTML element).">obj</param>
	<param type="string" descr="The name of the event ">evt</param>
	<param type="object" descr="A reference to the function which handles the event.">fn</param>
</documentation> */
Lib.addEvent = function (obj,evt,fn) {
	if (obj.addEventListener)
		obj.addEventListener(evt,fn,false);
	else if (obj.attachEvent)
		obj.attachEvent('on'+evt,fn);
}

/* <documentation about="Lib.removeEvent" type="CORE FUNCTION">
	<summary>Removes events to elements of the DOM</summary>
	<namespace>Lib</namespace>
	<param type="object" descr="A reference to the node on which the event has been set (HTML element).">obj</param>
	<param type="string" descr="The name of the event ">evt</param>
	<param type="object" descr="A reference to the function which handles the event.">fn</param>
</documentation> */
Lib.removeEvent = function (obj,evt,fn) {
	if (obj.removeEventListener)
		obj.removeEventListener(evt,fn,false);
	else if (obj.detachEvent)
		obj.detachEvent('on'+evt,fn);
}

Lib.eventCache = function(){
	try {
		var listEvents = [];

		/*  Implement array.push for browsers which don't support it natively. (used in EventCache)
		Please remove this if it's already in other code */
		if(Array.prototype.push == null){
			Array.prototype.push = function(){
				for(var i = 0; i < arguments.length; i++){
					this[this.length] = arguments[i];
		       	};
		        return this.length;
			};
		};

	    return {
			listEvents : listEvents,

			/* <documentation about="Lib.eventCache.add" type="CORE FUNCTION">
				<summary>Keeping track of all the attached events</summary>
				<namespace>Lib</namespace>
				<param type="object" descr="A reference to the node on which the event has been set (HTML element).">node</param>
				<param type="string" descr="The name of the event">sEventName</param>
				<param type="object" descr="A reference to the function which handles the event. ">fHandler</param>
				<param type="bool" descr="A boolean which determines whether the event is triggered in capture mode or not. Does not apply to Internet Explorer.">bCapture</param>
			</documentation> */
			add : 	function(node, sEventName, fHandler, bCapture){
						listEvents.push(arguments);
					},

		 	/* <documentation about="Lib.eventCache.flush" type="CORE FUNCTION">
				<summary>Used to remove (detach) all cached events.</summary>
			</documentation> */
			flush : 	function(){
					var i, item;
					for(i = listEvents.length - 1; i >= 0; i = i - 1){
						item = listEvents[i];
	                 	Lib.removeEvent(item[0], item[1], item[2])

						item[0][item[1]] = null;
					};
			}
	      };
	} catch (ex){ Lib.errHandler(ex); }
}();

/* <documentation about="Lib.debugAlert" type="CORE FUNCTION">
	<summary>Displays alert with error message, if alert is allowed (not cancelled in confirm) and Lib.debug = true</summary>
	<namespace>Lib</namespace>
	<param type="string" descr="Message to display in alert">message</param>
</documentation> */
Lib.debugAlert = function (message) {
		if(Lib.allowAlert && Lib.debug) { Lib.allowAlert = confirm(message); }
	}


/* <documentation about="Lib.errHandler" type="CORE FUNCTION">
	<summary>Handles errors in javascript application</summary>
	<namespace>Lib</namespace>
	<param type="object" descr="Error object">err</param>
</documentation> */
Lib.errHandler = function (err) {
		var errorText = "";
		for (var i in err) { errorText += i + "=" + err[i] + "\n"; }
		Lib.debugAlert("An error has occured: \n\n" + errorText + "\nSee Firefox browser for correct linenumbers.");
		return true;
	}
/* ========== END CORE ====================================================================== */

/* ========== GENERAL FUNCTIONS ============================================================= */
/* <documentation about="Lib.getWindowHeight" type="general function">
	<summary>Gets innerheight of browser window</summary>
	<namespace>Lib</namespace>
	<returns>Inner window height in pixels (integer)</returns>
</documentation> */
Lib.getWindowHeight = function () {
	var myHeight = 0;
	if( typeof( window.innerHeight ) == 'number' ) {
		//Non-IE
		myHeight = window.innerHeight;
	} else if( document.documentElement &&  document.documentElement.clientHeight  ) {
		//IE 6+ in 'standards compliant mode'
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && document.body.clientHeight) {
		//IE 4 compatible
		myHeight = document.body.clientHeight;
	}
	return myHeight;
}
/* <documentation about="Lib.getWindowWidth" type="general function">
	<summary>Gets innerwidth of browser window</summary>
	<namespace>Lib</namespace>
	<returns>Inner window width in pixels (integer)</returns>
</documentation> */
Lib.getWindowWidth = function () {
	var myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myHeight = window.innerWidth;
	} else if( document.documentElement &&  document.documentElement.clientWidth  ) {
		//IE 6+ in 'standards compliant mode'
		myHeight = document.documentElement.clientWidth;
	} else if( document.body && document.body.clientWidth) {
		//IE 4 compatible
		myHeight = document.body.clientWidth;
	}
	return myHeight;
}
/* <documentation about="Lib.getScrollY" type="general function">
	<summary>Get scrolling distance from the top of the window in pixels</summary>
	<namespace>Lib</namespace>
	<returns>Scrolling distance in pixels (integer)</returns>
</documentation> */
Lib.getScrollY = function () {
  var scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
  }
  return scrOfY;
}

/* <documentation about="Lib.findElementPosition" type="general function">
	<summary>Find position of a HTML element relative to window</summary>
	<namespace>Lib</namespace>
	<param type="object" descr="HTML element">elem</param>
	<returns>array [left (integer), top (integer)]</returns>
</documentation> */
Lib.findElementPosition = function (elem){
	var curleft = curtop = 0;
	if (elem.offsetParent) {

		curleft = elem.offsetLeft
		curtop = elem.offsetTop
		while (elem = elem.offsetParent) {
			curleft += elem.offsetLeft
			curtop += elem.offsetTop
		}
	}
	return [curleft,curtop];
}

/* <documentation about="Lib.elementIsHidden" type="general function">
	<summary>Checks if an element is hidden (has parent with className 'hide'</summary>
	<namespace>Lib</namespace>
	<param type="object" descr="HTML element">obj</param>
	<returns>true or false</returns>
</documentation> */
Lib.elementIsHidden = function (elem) {
	var isHidden = false;

	while ( elem && !isHidden) {
		elem = elem.parentNode;
		if(elem && elem.className && elem.className.indexOf("hide") != -1) { isHidden=true; }
	}
    return isHidden;
}

/* <documentation about="Lib.elementsExists" type="general function">
	<summary>Checks if all the elements with the id specified in the arguments of this function exist; returns true if they do exist; false if one or more do not exist</summary>
	<namespace>Lib</namespace>
	<param type="array of strings" descr="Id's of HTML elements">[array]</param>
	<returns>boolean</returns>
</documentation> */
Lib.elementsExists = function () {
	var result = true;
	for(var i=0; i< arguments.length; i++) {
		if(!document.getElementById(arguments[i])) result=false;
	}
	return result;
}

/* <documentation about="Lib.addStyleSheet" type="general function">
	<summary>Adds stylesheet to the document</summary>
	<namespace>Lib</namespace>
	<param type="string" descr="Relative path to the stylesheet for example '../css/stylesheet.css'">relPath</param>
</documentation> */
Lib.addStyleSheet = function (relPath) {
	if(document.getElementsByTagName("head"))
	{
		var head = document.getElementsByTagName("head")[0];
		var newStyle = document.createElement("link");
   		newStyle.setAttribute("type", "text/css");
		newStyle.setAttribute("rel", "stylesheet");
		newStyle.setAttribute("href", relPath);
		head.appendChild(newStyle);
	}
}

/* <documentation about="Lib.switchStyleSheet" type="general function">
	<summary>Enable/disable stylesheet</summary>
	<namespace>Lib</namespace>
	<param type="string" descr="Value of the title attribute of link-tag that has to be adjusted">linkTitle</param>
</documentation> */
Lib.switchStyleSheet = function (linkTitle) {
	if(document.getElementsByTagName("head"))
	{
		var head = document.getElementsByTagName("head")[0];
		var linkElements = head.getElementsByTagName("link");
		for(var i=0; i< linkElements.length; i++) {
			if(linkElements[i].getAttribute("title") != linkTitle) { continue; }
			linkElements[i].disabled ? linkElements[i].disabled = false : linkElements[i].disabled = true;
		}
	}
}

/* <documentation about="Lib.getBodyId" type="general function">
	<summary>Gets  id of body element</summary>
	<namespace>Lib</namespace>
	<returns>id (string)</returns>
</documentation> */
Lib.getBodyId = function ()  {
 	try {
		var body = document.getElementsByTagName("body")[0];
		return body.id;
	} catch (ex){ Lib.errHandler(ex); }
 }

/* <documentation about="Lib.getNextElement" type="general function">
	<summary>Gets next element in DOM tree; while ignoring text nodes</summary>
	<namespace>Lib</namespace>
	<param type="object" descr="HTML element">elem</param>
	<returns>HTML element</returns>
</documentation> */
Lib.getNextElement = function ( elem ) {
    do { elem = elem.nextSibling; }
	while ( elem && elem.nodeType != 1 );
    return elem;
}


/* <documentation about="Lib.getPreviousElement" type="general function">
	<summary>Gets previous element in DOM tree; while ignoring text nodes</summary>
	<namespace>Lib</namespace>
	<param type="object" descr="HTML element">elem</param>
	<returns>HTML element</returns>
</documentation> */
Lib.getPreviousElement = function ( elem ) {
	do { elem = elem.previousSibling; }
	while ( elem && elem.nodeType != 1 );
	return elem;
}

/* <documentation about="Lib.getElementsByClassName" type="general function">
	<summary>Used to find HTML elements with certain classname</summary>
	<namespace>Lib</namespace>
	<param type="string" descr="Classname you are looking for">searchClass</param>
	<param type="string" descr="An optional tag name to narrow the search to specific tags e.g. "a" for links (optional, defaults to  "*").">tagName</param>
	<param type="string" descr="An optional object container to search inside. This narrows the scope of the search (optional, defaults to document).">elem</param>
	<returns>Array of HTML elements</returns>
</documentation> */
Lib.getElementsByClassName = function (searchClass, tagName, containerElement) {
	tagName = tagName || "*";
	containerElement = containerElement || document;

	var allElements = containerElement.getElementsByTagName(tagName);
	if (!allElements.length &&  tagName == "*" &&  containerElement.all) allElements = containerElement.all;

	var elementsFound = new Array();
	var delim = searchClass.indexOf("|") != -1  ? '|' : " ";

	var arrClass = searchClass.split(delim);
	for (var i = 0, j = allElements.length; i < j; i++) {
		var arrObjClass = allElements[i].className.split(" ");
		if (delim == " " && arrClass.length > arrObjClass.length) { continue; }
		var c = 0;
		comparisonLoop:
			for (var k = 0, l = arrObjClass.length; k < l; k++) {
				for (var m = 0, n = arrClass.length; m < n; m++) {
					if (arrClass[m] == arrObjClass[k]) c++;
					if (( delim == "|" && c == 1) || (delim == " " && c == arrClass.length)) {
						elementsFound.push(allElements[i]);
					break comparisonLoop;
				}
			}
		}
	}
	return elementsFound;
}
/* <documentation about="Lib.getElementByTitle" type="general function">
	<summary>Get Elements by title attribute</summary>
	<namespace>Lib</namespace>
	<param type="string" descr="Value of title attribute you are looking for">searchTitle</param>
	<param type="string" descr="An optional tag name to narrow the search to specific tags e.g. "a" for links (optional, defaults to  "*").">tagName</param>
	<param type="string" descr="An optional object container to search inside. This narrows the scope of the search (optional, defaults to document).">elem</param>
	<returns>Array of HTML elements</returns>
</documentation> */
Lib.getElementsByTitle = function (searchTitle, tagName, containerElement) {
	tagName = tagName || "*";
	containerElement = containerElement || document;

	var allElements = containerElement.getElementsByTagName(tagName);
	if (!allElements.length &&  tagName == "*" &&  containerElement.all) allElements = containerElement.all;

	var elementsFound = new Array();

	for (var i = 0, j = allElements.length; i < j; i++) {
		if (allElements[i].title == searchTitle) {
			elementsFound.push(allElements[i]);
		}
	}
	return elementsFound;
}

/* <documentation about="Lib.removeElements" type="general function">
	<summary>Used to remove HTML elements</summary>
	<namespace>Lib</namespace>
	<param type="string" descr="An optional tag name to narrow the search to specific tags e.g. "a" for links (optional, defaults to "*").">tagName</param>
	<param type="string" descr="Classname you are looking for">searchClass</param>
	<param type="string" descr="An optional object container to search inside. This narrows the scope of the search (optional, defaults to document).">elem</param>
</documentation> */
Lib.removeElements = function (tagName, searchClass, containerElement) {
	var elementToRemove = Lib.getElementsByClassName(searchClass, tagName, containerElement);

	for(var i=0; i< elementToRemove.length; i++) {
		elementToRemove[i].parentNode.removeChild(elementToRemove[i]);
	}
}

/* <documentation about="Lib.trim" type="general function">
	<summary>Used to trim a variable (removing spaces left and right)</summary>
	<namespace>Lib</namespace>
	<param type="string" descr="Variables that you want to trim">stringToTrim</param>
	<returns>Trimmed variable (string)</returns>
</documentation> */
Lib.trim = function(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g, '') ;
}

/* <documentation about="Lib.inputAutoClear" type="general function">
	<summary>Resets default value in text filed when text field is left empty</summary>
	<namespace>Lib</namespace>
</documentation> */
Lib.inputAutoClear = function () {
	var inputFields = Lib.getElementsByClassName("text", "input");
	for (var i=0; i<inputFields.length; i++) {
		// Add a onfocus to every text input with class "text"
		// This will store the initial value for restoring it when the box stays empty when losing focus
		inputFields[i].onfocus = function() { if (!this.getAttribute("default")||this.getAttribute("default")== this.value) {this.setAttribute("default", this.value); this.value = "";} };
		Lib.eventCache.add(inputFields[i], "onfocus", function() { if (!this.getAttribute("default")||this.getAttribute("default")== this.value) {this.setAttribute("default", this.value); this.value = "";} }, false);

		// Add a onblur to every text input with class "text"
		// This will restore the initial value if no value is inserted
		inputFields[i].onblur = function() { if (this.value.length==0) { this.value = this.getAttribute("default")} };
		Lib.eventCache.add(inputFields[i], "onblur", function() { if (this.value.length==0) {this.value = this.getAttribute("default")} }, false);
	}
}

/* <documentation about="Lib.tableRowHover" type="general function">
	<summary>Adds a hover style to table rows with links</summary>
	<namespace>Lib</namespace>
</documentation> */
Lib.tableRowHover = function () {
	var rows = document.getElementsByTagName('tr');
	for (var i=0; i<rows.length; i++) {
		var links = rows[i].getElementsByTagName('a');
		// loop through the links
		if (links.length > 0 && links.length < 2) {
			rows[i].linkpath = links[0].href;
			rows[i].onmouseover = function () {
				this.className = 'hover';
			}
			rows[i].onmouseout = function () {
				this.className = '';
			}
			rows[i].onclick = function () {
				document.location = this.linkpath;
			}
		}
	}
}
/* <documentation about="Lib.EventlistHover" type="general function">
	<summary>Adds a hover style to items with links in the eventlist component</summary>
	<namespace>Lib</namespace>
</documentation> */
Lib.EventlistHover = function () {
	// get ul with class 'event-list'
	var eventlist = Lib.getElementsByClassName("event-list", "ul");
	//get li elements inside 'event-list' ul
	for (var i=0; i<eventlist.length; i++) {
		var listitems = eventlist[i].getElementsByTagName('li');
		//alert(listitems);

		for (var i=0; i<listitems.length; i++) {
			if (listitems[i].className == "all-events") { continue }
			listitems[i].onmouseover = function () {
				this.className = 'hover';
			}
			listitems[i].onmouseout = function () {
				this.className = '';
			}
		}
	}
}
/* <documentation about="Lib.NewslistHover" type="general function">
	<summary>Adds a hover style to items with links in the newslist component</summary>
	<namespace>Lib</namespace>
</documentation> */
Lib.NewslistHover = function () {
	// get ul with class 'event-list'
	var newslist = Lib.getElementsByClassName("news-list", "ul");
	//get li elements inside 'news-list' ul
	for (var i=0; i<newslist.length; i++) {
		var listitems = newslist[i].getElementsByTagName('li');
		//alert(listitems);

		for (var i=0; i<listitems.length; i++) {
			// get links in listitems
			var links = listitems[i].getElementsByTagName('a');
			if (links[0]) {
				listitems[i].linkpath = links[0].href;

				listitems[i].onmouseover = function () {
					this.className = 'hover';
				}
				listitems[i].onmouseout = function () {
					this.className = '';
				}
				listitems[i].onclick = function () {
					document.location = this.linkpath;
				}
			}
		}
	}
}

/* <documentation about="Lib.FoldingLists" type="general function">
	<summary>Adds toggle functionality (open and close) to uni-menu </summary>
	<namespace>Lib</namespace>
</documentation> */
Lib.FoldingLists = function () {

	var toggleTab = function (hyperlink) {
		if(hyperlink.submenu.className == "sub-uni-menu hide") {
			var subunilists = Lib.getElementsByClassName("sub-uni-menu", "ul");
			for(var j=0; j<subunilists.length;j++) {
				if (subunilists[j].className.indexOf("hide") < 0) { subunilists[j].className += " hide"; 	}
			}
			hyperlink.submenu.className = "sub-uni-menu";
		}
		else  {
			hyperlink.submenu.className = "sub-uni-menu hide";
		}
	}
	//Lib.debug = true;
	// get ul with class 'uni-menu'
	var unilists = Lib.getElementsByClassName("uni-menu", "ul");

	var listitems = unilists[0].getElementsByTagName("li");

	for(var j=0; j<listitems.length;j++) {
		var span = listitems[j].getElementsByTagName("span")[0];

		if(span) {

			var hyperlink = document.createElement("a");
			hyperlink.href="#";
			hyperlink.innerHTML = span.innerHTML;
			listitems[j].insertBefore(hyperlink,span);
			listitems[j].removeChild(span);

			hyperlink.submenu = Lib.getNextElement(hyperlink);
			//alert(hyperlink.submenu.className);

			hyperlink.onclick = function () { toggleTab(this);return false; };
			Lib.eventCache.add(hyperlink, "onclick", function () { toggleTab(this);return false; }, false);
		}
	}
}

/* <documentation about="Lib.listHover" type="general function">
	<summary>Adds a hover style to h3's with links</summary>
	<namespace>Lib</namespace>
</documentation> */
Lib.listHover = function () {
	// get  linklists
	var linklists = Lib.getElementsByClassName("link-list", "ul");
	//alert(linklists.length);


}
/* <documentation about="Lib.styleDropdowns" type="specific function">
	<summary>Replaces dropdowns with classname "_dhtml-select" (selects) with styled dropdowns</summary>
	<namespace>Lib</namespace>
</documentation> */
Lib.styleDropdowns = function () {

	var documentClick = function() {
		if(!Lib.selectIsClicked) {
			closeSelects();
		}
		else { Lib.selectIsClicked = false; }
	}

	var openSelect = function (selectReplace) {
		Lib.selectIsClicked = selectReplace.getAttribute('orig_id');
		var targetSelect	= document.getElementById(selectReplace.getAttribute('orig_id') + '_alt');
		var targetSelectDD 	= document.getElementById(selectReplace.getAttribute('orig_id') + '_alt_dropdown');
		lastClickedItem		= selectReplace.getAttribute('orig_id') + '_alt_dropdown';

		if (targetSelectDD.getAttribute('open') == 'true') {
			targetSelectDD.setAttribute('open', 'false');
			targetSelectDD.style.display = 'none';
			targetSelectDD.style.height = "auto";
			targetSelectDD.style.overflow = "visible";
		}
		else {
			closeSelects();

			targetSelectDD.setAttribute('open', 'true');
			targetSelectDD.style.display = 'block';

			/*var body = document.getElementsByTagName("body")[0];
			var firstDiv = document.getElementsByTagName("div")[0];
			body.insertBefore(targetSelectDD, firstDiv);
			targetSelectDD.style.left = targetSelect.offsetLeft + "px";
			targetSelectDD.style.top = targetSelect.offsetTop + "px"; */


			if(targetSelectDD.offsetHeight>150) {
				targetSelectDD.style.overflow = "auto";
				targetSelectDD.style.overflowY = "scroll";
				targetSelectDD.style.overflowX = "hidden";
				targetSelectDD.style.height = "150px";
			}
		}
	}

	var closeSelects = function () {
		var options = Lib.getElementsByClassName("dhtml-select_options", "div");
		for (var i=0; i<options.length; i++) {
			options[i].setAttribute('open', 'false');
			options[i].style.display = 'none';
		}
	}

	var optionClick = function (optionReplaceLink) {

		document.getElementById(optionReplaceLink.getAttribute('select')).options[optionReplaceLink.getAttribute('position')].selected = "selected";

		var newOption = document.createElement('dt');

		if (!optionReplaceLink.text) { newOption.innerHTML = "<span>"+ optionReplaceLink.childNodes[0].toString() + "</span>"; }
		else { newOption.innerHTML = "<span>"+ optionReplaceLink.text+ "</span>"; }

		document.getElementById(optionReplaceLink.getAttribute('select_alt')).childNodes[0].replaceChild(newOption, document.getElementById(optionReplaceLink.getAttribute('select_alt')).childNodes[0].childNodes[0]);

	}


	if(Lib.pageIsStyled) {

		var candidates = Lib.getElementsByClassName("_dhtml-select", "select");
		for (var i=0; i<candidates.length; i++) {

			// Retrieve the required information from the original select box
			var origSelect = candidates[i];
			var origClass = origSelect.className.replace(" hide", "").substring(1);

			// Create replacement select box
			Lib.selectAlternates[Lib.selectAlternates.length] = origSelect.getAttribute('id') + '_alt_dropdown';

			var selectReplace = document.createElement('div');
				selectReplace.setAttribute('id', origSelect.getAttribute('id') + '_alt');
				selectReplace.setAttribute('orig_id', origSelect.getAttribute('id'));
				selectReplace.className = origClass;

			selectReplace.onclick = function() { openSelect (this); };
			Lib.eventCache.add(selectReplace, "onclick", function() { openSelect (this); }, false);

			var selectReplaceList = document.createElement('dl');
			var optionReplace = document.createElement('dt');
			var selectReplaceText = document.createTextNode(origSelect.options[0].text);
			optionReplace.appendChild(selectReplaceText);
			selectReplaceList.appendChild(optionReplace);
			selectReplace.appendChild(selectReplaceList);

			// Create replacement select box dropdown
			var selectReplaceOptions = document.createElement('div');
			selectReplaceOptions.setAttribute('id', origSelect.getAttribute('id') + '_alt_dropdown');
			selectReplaceOptions.className = origClass + '_options';
			var selectReplaceList = document.createElement('dl');

			for (var j= 0; j<origSelect.options.length; j++) {
				if (j != 0 ) { // to hide the first 'option' from the list
		      		var optionReplace = document.createElement('dt');
					optionReplaceLink = document.createElement('a')
					optionReplaceLink.href= "#";
					optionReplaceLink.setAttribute('position', j);
					optionReplaceLink.setAttribute('select_alt', origSelect.getAttribute('id') + '_alt');
					optionReplaceLink.setAttribute('select', origSelect.getAttribute('id'));

					optionReplaceLink.onclick = function() { optionClick(this); return false; };
					Lib.eventCache.add(optionReplaceLink, "onclick", function() { optionClick(this); return false;}, false);

					optionReplaceText = document.createTextNode(origSelect.options[j].text);

					optionReplaceLink.appendChild(optionReplaceText);
					optionReplace.appendChild(optionReplaceLink);
					selectReplaceList.appendChild(optionReplace);
				}
			}

			// Append the replacement selectbox to the form
			selectReplaceOptions.appendChild(selectReplaceList);
			selectReplace.appendChild(selectReplaceOptions);
			origSelect.parentNode.insertBefore(selectReplace, origSelect);

			// Hide the original selectbox
			origSelect.className = "hide";
		}
		Lib.addEvent (document, "click", documentClick);
		Lib.eventCache.add(document, "onclick", documentClick, false);
	}
}

/* <documentation about="Lib.printPage" type="specific function">
	<summary>Adds functionality to print button</summary>
	<namespace>Lib</namespace>
</documentation> */
Lib.printPage = function () {
    var printButton = document.getElementById("print-button");
    printButton.onclick = function() {
        window.print();
        return false;
    }
}


<!--

//====================== variabele bepalen - max, min en gemiddelde (100%) tekstgrootte
//====================== define variable - max, min and medium (100%) textsize
var mintextsize = 1;
var midtextsize = 3;
var maxtextsize = 5;

//====================== zoeken binnen document naar tekstgrootte controls
//====================== search document for textresize controls

/* <documentation about="Lib.textSize" type="specific function">
	<summary>Adds functionality to text resize links</summary>
	<namespace>Lib</namespace>
</documentation> */
Lib.textSize = function () {

	this.textControls = new Array();
	// bestaat tekstgrootte op deze pagina?
	// does textresize exist of this page?
	var tc = document.getElementById('textresize');
	if (!tc) {
		return false;
	}
	else {

        this.plus = document.getElementById('larger');

		this.textControls[this.textControls.length] = new controlObjs(this,this.plus);
        this.minus = document.getElementById('smaller');
		this.textControls[this.textControls.length] = new controlObjs(this,this.minus);
		// lees cookie en set tekstgrootte
		// read cookie and set textsize

		if(!(getCookieVal('MinFinFontSize') == '')){
			fontChange(getCookieVal('MinFinFontSize'));
			dimension = getCookieVal('MinFinFontSize');
			this.size = dimension.charAt(4);
			//check voor max of min tekstgrootte
			// check for max of min textsize
			checkOnactive(this.plus,this.minus,this.size);
		}
		// als er geen cookie is, set tekstgrootte naar gemiddeld (3)
		// if there isn't already a cookie, set textsize to medium (3)
		else {
			this.size = midtextsize;

		}
		this.ss = 'size' + this.size;
	}
}

//====================== object collectie en klik-functie
//====================== object collection and click event
controlObjs = function(textSize,control) {
	this.textSize = textSize;
	this.control = control;
	this.direction = this.control.id;
	this.direction.controlObjs = this;
	this.control.controlObjs = this;
	this.control.onclick = function () {

		this.controlObjs.textControl();
        return false;
    }
}

//====================== deze functie checkt dat de tekstgrootte is niet minder dan 1 en niet groter dan 5
//====================== this function checks that the text size is no less than 1 and no greater than 5
controlObjs.prototype.checkControl = function () {
	//alert(this.textSize.grootte);
	if ((this.control.id == 'smaller') && (this.textSize.size < mintextsize)) {
		this.textSize.size ++;
		return false;
	}
	else if ((this.control.id == 'larger') &&(this.textSize.size > maxtextsize)) {
		this.textSize.size --;
		return false;
	}
	else {
		return true;
	}
}

//====================== links wordt onactief als de grootste of de kleinste tekstgrootte is al in gebruik
//====================== links are deactivated if the largest or the smallest textsize is active
checkOnactive = function (plus,minus,size) {
	this.plus = plus;
	this.minus = minus;
	this.size = size;
	// reset styles
	this.plus.className = 'tekstvergroten';
	this.minus.className = 'tekstverkleinen';
	if (this.size == mintextsize) {
		this.minus.className += ' inactive';
	}
	else if (this.size == maxtextsize) {
		this.plus.className += ' inactive';
	}
	return false;
}

//====================== fontChange roepen als de font niet al te groot of te klein is
//====================== call the fontChange function if the font is not already to large or to small
controlObjs.prototype.textControl = function () {
	if (this.direction == 'larger') {
		this.textSize.size ++;
	}
	else {
		this.textSize.size --;
	}
	if (this.checkControl()) {
		checkOnactive(this.textSize.plus,this.textSize.minus,this.textSize.size);
		this.textSize.ss = 'size' + this.textSize.size;
		fontChange(this.textSize.ss);
	}
}

//====================== zoeken naar stylesheet link elementen met een 'title' attribute
//====================== wissel van stylesheet
//====================== search for stylesheet link elementen with a 'title' attribute
//====================== and switch stylesheet
function fontChange(title) {
	var i, a, main;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
			if(a.getAttribute("title").indexOf("size")>-1) a.disabled = true;
			if(a.getAttribute("title") == title) a.disabled = false;
		}
	}
	setCookie("MinFinFontSize", title);
}

// -- COOKIE FUNCTIONS:

function getCookie (name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
		return getCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}
	return null;
}

function setCookie (name, value) {
	var argv = setCookie.arguments;
	var argc = setCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	document.cookie = name + "=" + escape (value) + ";"+
	((expires == null) ? "" : (" expires=" + expires.toGMTString())) +
	((path == null) ? "" : ("; path=" + path)) +
	((domain == null) ? "" : ("; domain=" + domain)) +
	((secure == true) ? "; secure" : "");
}

function getCookieVal(offset) {
	var cookieValue = "";
	var cookies = document.cookie.split(";");
	for(var i=0; i<cookies.length; i++){
		if(cookies[i].indexOf(offset) > -1){
			cookieValue = cookies[i].substring(cookies[i].indexOf("=")+1);
		}
	}
	return cookieValue;
}

if(!(getCookieVal('MinFinFontSize') == '')){
	fontChange(getCookieVal('MinFinFontSize'));
}





Lib.setPageIsStyled = function () {
	if(Lib.elementsExists("page-content")) { if(parseInt(document.getElementById("page-content").offsetWidth) > 0) { Lib.pageIsStyled = true; }	 }
	if(!Lib.pageIsStyled) { Lib.removeStyleSheet ("js-enabled.css"); }
}

/* ========== END GENERAL FUNCTIONS ========================================================= */

/* <documentation about="Add eventhandler Lib.eventCache.flush on window unload" type="FUNCTION CALL">
	<summary>Calling Lib.addEvent: Add Lib.eventCache.flush as eventhandler on window onunload: Detach all attached events (solves memory leak in ie)</summary>
</documentation> */
Lib.addEvent(window, "unload", Lib.eventCache.flush);

