/* Javascript file voor werk.nl van CWI */
/* samengesteld door Michiel Besseling, Toine van Oosten */

// xWinOpen, Copyright 2003-2005 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL
// R. de Gouw 02-01-2006 Moved function initTabs from UI template.
// R. de Gouw 03-01-2006 Merged CMS version
// R. de Gouw 20-01-2006 Added doSaveAs to save the webpage.
// M. Besseling moved cookie functions to menus.js

var isReady = false;
function doSaveAs() {
  if (document.execCommand) {
    if (isReady) {
      document.execCommand("SaveAs");
	}
  }
}

/* start of CMS merge */
function go(url)  {
if(window.location) { window.location=url  }
else document.location.href=url; 
}

<!-- JS Navigeren parent iframe -->
function goTop(url)  {
//Mozilla//
if(window.location) {   
	window.location=url;	
	}
//Internet Explorer //
else  {  
	top.document.location.href=url;
	}
}


function initTabs()
{
  /* initialiseren animating segment tabs in de page header */
  domRollover();
  tableruler();
  setFocusOnForm();
  setMaxLength();
  isReady = true ;
  //window.onresize = setFooter();
  setFooter();
}

var xChildWindow = null;
function openPopup(sUrl,winWidth,winHeight,toolbars)
{ 
  if(typeof winWidth == 'undefined')  var winWidth = 520;
  if(typeof winHeight == 'undefined')  var winHeight = 640;
  if(typeof toolbars == 'undefined')  var toolbars = false;
  var features = "left=0,top=0,width="+ winWidth + ",height=" + winHeight +
    ",resizable=1,scrollbars=1,status=0";
  if(toolbars) features = features + ",location=1,menubar=1,toolbar=1"
    else features = features + ",location=0,menubar=1,toolbar=0";
  if (xChildWindow && !xChildWindow.closed) {xChildWindow.location.href  = sUrl;}
  else {xChildWindow = window.open(sUrl, "myWinName", features);}
  xChildWindow.focus();
  return false;
}

/* end of CMS merge */

function back ()  {
history.go(-1);
}

function toggleLayer(layerID) {
if (document.getElementById) {
	var myLayer = document.getElementById(layerID);
	if(myLayer.className) {
		myLayer.className = (myLayer.className != 'hidden') ?  'hidden' : 'show';
		}
		//setFooter();
	}
}
function showLayer(layerID) {
	if (document.getElementById) {
		var myLayer = document.getElementById(layerID);
		if ( myLayer != null) {
			if(myLayer.className) {
				myLayer.className = 'show';
				//setFooter();
			}
		}
		
	}
}
function hideLayer(layerID) {
	if (document.getElementById) {
		var myLayer = document.getElementById(layerID);
		if ( myLayer != null) {
			if (myLayer.className) {
				myLayer.className = 'hidden';
				//setFooter();
			}
		}
	}
	
}

function showStructuurmenu()  {
	var menu = document.getElementById('structuurmenu');
	menu.style.display = 'block';
//	menu.style.top = window.event.clientY + -40;
	/* menu.style.left = window.event.x + 20;  */
}
function hideStructuurmenu()  {
	var menu = document.getElementById('structuurmenu');
	menu.style.display = 'none';
}

// xDisplay, Copyright 2003,2004,2005 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL
// input ( document element, one of the valid CSS strings for this property )  //
function xDisplay(e,s)
{
  if(!(e=xGetElementById(e))) return null;
  if(e.style && xDef(e.style.display)) {
    if (xStr(s)) e.style.display = s;
    return e.style.display;
  }
  return null;
}
                                

// xTableRowDisplay, Copyright 2004,2005 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL
// Sets the display of a table row. //
// 	bShowif true show the row, else hide it //
// 	secID or element reference of table, tHead, tBody or tFoot  //
// 	nRowzero-based row number //
function xTableRowDisplay(bShow, sec, nRow)
{
  sec = xGetElementById(sec);
  if (sec && nRow < sec.rows.length) {
    sec.rows[nRow].style.display = bShow ? '' : 'none';
  }
}

// xGetElementById, Copyright 2001-2005 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL
// Get an object reference to the element object with the passed ID.  //
//	ele id string or object reference //
function xGetElementById(e)
{
  if(typeof(e)!='string') return e;
  if(document.getElementById) e=document.getElementById(e);
  else if(document.all) e=document.all[e];
  else e=null;
  return e;
}

// xDef, Copyright 2001-2005 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL
// Determine if all arguments are 'defined'. //
function xDef()
{
  for(var i=0; i<arguments.length; ++i){if(typeof(arguments[i])=='undefined') return false;}
  return true;
}

function getElementsByClassName( clsName , tagName) 
{ 
	var arr = new Array(); 
	var j=0;
	if (typeof tagName == 'undefined') {
		tagName = '*';
	}
	
	var elem = document.getElementsByTagName(tagName);

	for (var i=0; i < elem.length; i++ )
	{
		if ( elem[i].className == clsName )
		{
			arr[j] = elem[i];
			j++;
		}
	}
	return arr;
}

// xGetElementsByTagName, Copyright 2001-2005 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL
// Returns an array of elements which are descendants of parentEle and have tagName. 
// If parentEle is null or not present, document will be used. 
// If tagName is null or not present, "*" will be used.
//	tagName - string  //
//	parentEle - element reference //
function xGetElementsByTagName(t,p)
{
  var list = null;
  t = t || '*';
  p = p || document;
  if (xIE4 || xIE5) {
    if (t == '*') list = p.all;
    else list = p.all.tags(t);
  }
  else if (p.getElementsByTagName) list = p.getElementsByTagName(t);
  return list || new Array();
}

//=====================================================================
//  DOM Image Rollover v3 (hover)
//
//  Demo: http://chrispoole.com/scripts/dom_image_rollover_hover
//=====================================================================
//  copyright Chris Poole
//  http://chrispoole.com
//  This software is licensed under the MIT License 
//  <http://opensource.org/licenses/mit-license.php>
//=====================================================================

function domRollover() {
	if (navigator.userAgent.match(/Opera (\S+)/)) {
		var operaVersion = parseInt(navigator.userAgent.match(/Opera (\S+)/)[1]);
	}
	if (!document.getElementById||operaVersion <7) return;
	var imgarr=document.getElementsByTagName('img');
	var imgPreload=new Array();
	var imgSrc=new Array();
	var imgClass=new Array();
	for (i=0;i<imgarr.length;i++){
		if (imgarr[i].className.indexOf('domroll')!=-1){
			imgSrc[i]=imgarr[i].getAttribute('src');
			imgClass[i]=imgarr[i].className;
			imgPreload[i]=new Image();
			if (imgClass[i].match(/domroll (\S+)/)) {
				imgPreload[i].src = imgClass[i].match(/domroll (\S+)/)[1]
			}
			imgarr[i].setAttribute('xsrc', imgSrc[i]);
			imgarr[i].onmouseover=function(){
				this.setAttribute('src',this.className.match(/domroll (\S+)/)[1])
			}
			imgarr[i].onmouseout=function(){
				this.setAttribute('src',this.getAttribute('xsrc'))
			}
		}
	}
}

/* Part of x.js compiled from X 4.0 with XC 0.27b. Distributed by GNU LGPL. For copyrights, license, documentation and more visit Cross-Browser.com */
// globals, Copyright 2001-2005 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL

var xOp7Up,xOp6Dn,xIE4Up,xIE4,xIE5,xNN4,xUA=navigator.userAgent.toLowerCase();
if(window.opera){
  var i=xUA.indexOf('opera');
  if(i!=-1){
    var v=parseInt(xUA.charAt(i+6));
    xOp7Up=v>=7;
    xOp6Dn=v<7;
  }
}
else if(navigator.vendor!='KDE' && document.all && xUA.indexOf('msie')!=-1){
  xIE4Up=parseFloat(navigator.appVersion)>=4;
  xIE4=xUA.indexOf('msie 4')!=-1;
  xIE5=xUA.indexOf('msie 5')!=-1;
}
else if(document.layers){xNN4=true;}
xMac=xUA.indexOf('mac')!=-1;

									 

/*
	tableruler()
	written by Chris Heilmann for alistapart.
	enables a rollover of rows for each table with the classname "ruler"
*/

function tableruler()
{
	if (document.getElementById && document.createTextNode)
	{
		var tables=document.getElementsByTagName('table');
		for (var i=0;i<tables.length;i++)
		{
			if(tables[i].className=='ruler')
			{
				var trs=tables[i].getElementsByTagName('tr');
				for(var j=0;j<trs.length;j++)
				{
					if(trs[j].parentNode.nodeName=='TBODY')
					{
						trs[j].onmouseover=function(){this.className='ruled';return false}
						trs[j].onmouseout=function(){this.className='';return false}
					}
				}
			}
		}
	}
}

function setFocusOnForm() {
setTimeout('setFocus()',50);
}

function setFocus() {
/* Dit script zet (bij default) de focus op een invoerveld van het eerste form */
/* Velden  Hidden, submit, Select of display NONE worden overgeslagen */
/* Script kan per pagina worden geconfigureerd door een scriptregel in de BODY te zetten */
/* De variabele focusOn kan een ID (string) bevatten, of de waarde -1 voor geen focus */
/* Voorbeeld:  <script type="text/javascript">focusOn = "-1"; </script>   
/* -> NIET automatisch focus zetten */
/* Voorbeeld:  <script type="text/javascript">focusOn = "postcode"; </script>  */
/* -> focus automatisch zetten op veld met id = postcode */

/* controleer of script voor de pagina geconfigureerd is */
	if(typeof focusOn == 'undefined')  
		{focusOn = "";}
/* controleer of er GEEN focus gezet moet worden */
	if (focusOn == "-1" ) {return;} 
/* controleer of er forms aanwezig zijn anders dan het login formulier */
	if(document.forms.length>1 || (document.forms.length == 1 && !(document.forms['loginForm'])) ) 
		{
		if (document.getElementById(focusOn))
			{
				document.getElementById(focusOn).focus();
			}
		else
			{
			aForm = document.forms[0];
				{
				/* itereer over alle form-velden */
				var i;
				var max = aForm.length;
				for( i = 0; i < max; i++ ) 
					{
					/* Sluit form-velden uit die geen focus kunnen krijgen */
					if( aForm.elements[ i ].type != "hidden" &&
						aForm.elements[ i ].type != "submit" &&
						aForm.elements[ i ].style.display != 'none' &&
						aForm.elements[ i ].nodeName != 'SELECT' &&
						//aForm.elements[ i ].type != 'radio' &&
                                                aForm.elements[ i ].name != 'p_mainsearch' &&
						!aForm.elements[ i ].disabled &&
						!aForm.elements[ i ].readOnly )
							{
							/* zet de focus indien mogelijk en stop script */
							try {
								aForm.elements[ i ].focus();
							} catch (e) {// just ignore maybe an element in a hidden parent container 
							}
							break;
							}
					}
				}
			}
		}
}

/* Teller max aantal tekens voor textareas */
/* Bron: Quicksmode.org */
/* Gebruik: setMaxLength() in onload */
/* Voeg attribuut maxlength toe aan textarea OF ( cols EN rows) */
/* bijv <textarea name="mytext" maxlength="1200"></textarea> */
/* bijv <textarea name="mytext" cols="60" rows="20"></textarea> */
function setMaxLength()
{
	var x = document.getElementsByTagName('textarea');
	var counter = document.createElement('div');
	counter.className = 'counter';
	for (var i=0;i<x.length;i++)
	{
		if	(
			 x[i].getAttribute('maxlength')
			 |
			(x[i].cols && x[i].rows)
			)
		{
			var counterClone = counter.cloneNode(true);
			if(typeof x[i].getAttribute('maxlength') == 'undefined')
				{
					var maxlength = x[i].getAttribute('maxlength');
				}
			else
				{
					var  maxlength = x[i].cols * x[i].rows;
				}
			counterClone.relatedElement = x[i];
			counterClone.innerHTML = 'Maximaal ' + maxlength + ' tekens toegestaan, <span>0</span> tekens ingevuld.' ;
			x[i].parentNode.insertBefore(counterClone,x[i].nextSibling);
			x[i].relatedElement = counterClone.getElementsByTagName('span')[0];

			x[i].onkeyup = x[i].onchange = checkMaxLength;
			x[i].onkeyup();
		}
	}
}

function checkMaxLength()
{
	/*var maxLength = this.getAttribute('maxlength');*/
	if(typeof this.getAttribute('maxlength') == 'undefined')
				{
					var maxLength = this.getAttribute('maxlength');
				}
			else
				{
					var  maxLength = this.cols * this.rows;
				}
	var currentLength = this.value.length;
	if (currentLength > maxLength)
		this.relatedElement.className = 'toomuch';
	else
		this.relatedElement.className = '';
	this.relatedElement.firstChild.nodeValue = currentLength;
	// not innerHTML
}

function initShowHideListDetails() 
{
/* stylesheet aanpassen voor script-enabled browsers */
if (document.styleSheets[0] && document.styleSheets[0].addRule)
	{
	document.styleSheets[0].addRule('#main ul.toggleDetails li div', 'display:none;');
	document.styleSheets[0].addRule('#main ul.toggleDetails li', 'cursor:pointer;');
	}
	else 
	{
	if (document.styleSheets[0] && document.styleSheets[0].insertRule)
		{
		document.styleSheets[0].insertRule('#main ul.toggleDetails li div {display:none;}',document.styleSheets[0].cssRules.length);
		document.styleSheets[0].insertRule('#main ul.toggleDetails li {cursor:pointer;}',document.styleSheets[0].cssRules.length);

		}
	}

var ularr=document.getElementsByTagName('ul');
for (i=0;i<ularr.length;i++)
	{
	oList = ularr[i];
	if (oList.className=='toggleDetails')
		{
		for(j=0;oList.childNodes && j<oList.childNodes.length;j++)
			{
			oNode = oList.childNodes[j];
			oNode.title="Toon of verberg introtekst"; 
			oNode.onclick=function() 
				{
					this.className = (this.className == '') ?  'detailsVisible' : '';
				}
			}
		}
	}
}



function setFooter() {
if (document.getElementById) 
	{
	if(document.getElementById('pageHeight') && document.getElementById('sidebar') ) 
		{ 
			pageHeightImg=document.getElementById('pageHeight');
			var compHeight = document.getElementById('sidebar').offsetHeight;
			pageHeightImg.height=compHeight+60;
		}
	}
}

/*
 * This is the function that actually highlights a text string by
 * adding HTML tags before and after all occurrences of the search
 * term. You can pass your own tags if you'd like, or if the
 * highlightStartTag or highlightEndTag parameters are omitted or
 * are empty strings then the default <font> tags will be used.
 */
function doHighlight(bodyText, searchTerm, highlightStartTag, highlightEndTag) 
{
  // the highlightStartTag and highlightEndTag parameters are optional
  if ((!highlightStartTag) || (!highlightEndTag)) {
    highlightStartTag = "<span class='highlight'>";
    highlightEndTag = "</span>";
  }
  
  // find all occurences of the search term in the given text,
  // and add some "highlight" tags to them (we're not using a
  // regular expression search, because we want to filter out
  // matches that occur within HTML tags and script blocks, so
  // we have to do a little extra validation)
  var newText = "";
  var i = -1;
  var lcSearchTerm = searchTerm.toLowerCase();
  var lcBodyText = bodyText.toLowerCase();
  lcSearchTerm = lcSearchTerm.replace(/(^\s+|\s+$)/g,''); // trim
  lcSearchTerm = lcSearchTerm.replace(/\+/g,''); // +
//  lcSearchTerm = lcSearchTerm.replace("&lt;","<");
//  lcSearchTerm = lcSearchTerm.replace("&gt;",">");
//  lcSearchTerm = lcSearchTerm.replace("&amp;","&");
//  lcSearchTerm = lcSearchTerm.replace("&quot;","\"");
//  lcSearchTerm = lcSearchTerm.replace("&#39;","'");
  
  if (lcSearchTerm.length >= 3) {
	  while (bodyText.length > 0) {
	    i = lcBodyText.indexOf(lcSearchTerm, i+1);
	    if (i < 0) {
	      newText += bodyText;
	      bodyText = "";
	    } else {
	      // skip anything inside an HTML tag
	      if (bodyText.lastIndexOf(">", i) >= bodyText.lastIndexOf("<", i)) {
	        // skip anything inside a <script> block
	        if (lcBodyText.lastIndexOf("/script>", i) >= lcBodyText.lastIndexOf("<script", i)) {
	          newText += bodyText.substring(0, i) + highlightStartTag + bodyText.substr(i, lcSearchTerm.length) + highlightEndTag;
	          bodyText = bodyText.substr(i + lcSearchTerm.length);
	          lcBodyText = bodyText.toLowerCase();
	          i = -1;
	        }
	      }
	    }
	 }
  }
  
  if (newText.length == 0)  {
    return bodyText;
  }
  else {
    return newText;
  }
}


/*
 * This is sort of a wrapper function to the doHighlight function.
 * It takes the searchText that you pass, optionally splits it into
 * separate words, and transforms the text on the current web page.
 * Only the "searchText" parameter is required; all other parameters
 * are optional and can be omitted.
 * bodyElement element containing the body text to be highlighted
 */
function highlightSearchTerms(searchText, treatAsPhrase, warnOnFailure, highlightStartTag, highlightEndTag, bodyElement)
{

  if ( searchText == "") {
    return true;
  }


  // if the treatAsPhrase parameter is true, then we should search for 
  // the entire phrase that was entered; otherwise, we will split the
  // search string so that each word is searched for and highlighted
  // individually
  if (treatAsPhrase) {
    searchArray = [searchText];
  } else {
    searchArray = searchText.split(" ");
  }

  var el = document.body;
  if (bodyElement) {
  	el = bodyElement;
  } 
  
  if (!el|| typeof(el.innerHTML) == "undefined") {
    if (warnOnFailure) {
      alert("Sorry, for some reason the text of this page is unavailable. Searching will not work.");
    }
    return false;
  }
  
  var bodyText = el.innerHTML;
  for (var i = 0; i < searchArray.length; i++) {
    bodyText = doHighlight(bodyText, searchArray[i], highlightStartTag, highlightEndTag);
  }
  
  el.innerHTML = bodyText;
  return true;
}

