function loadPage(){
	//googleSearchHighlight();
	if (getCookie('extra') !== null && getCookie('extra')==='true'){
		toggle('extra', 'span');
	}
	if (getCookie('hilight') !== null && getCookie('hilight')!==''){
		if (getCookie('prevhilight')!== null && getCookie('prevhilight')!=='' && getCookie('prevhilight')===getCookie('hilight')){
			searchHighlight('resultstable', getCookie('hilight'));
		} else {
			setCookie('prevhilight', getCookie('hilight'));
			deleteCookie('hilight');
		}
	}
}


//taken from http://simon.incutio.com/archive/2004/05/26/addLoadEvent	
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function confirmDelete(){
    var agree=confirm("Are you sure you want to delete?");
    if (agree){
    	return true ;
    }else{
    	return false ;
    }
}
function submitDelete(form){
    if (confirmDelete()){ form.submit();}
}
function validateQuery(query){
	if (query.indexOf("*") === 0  || query.indexOf("?") === 0){
		alert("WARNING: leading wildcards are not supported: " + query + "\nThe query will execute without the leading wildcard.");
		query = query.substring(1, query.length);
	}
	if (query.indexOf("*") === 1){
		alert("WARNING: Please enter at least 2 characters before the * :\nThe query will execute without the *.");
		query = query.substring(0, query.length-1);	
	}
	return query;
}
function searchsubmitValidate(form, queryField, queryPrefixField, searchTermField, queryPostField){
	/* 	
		queryField contains the query as typed by the user
		queryPostField is the field containing the query as it will be posted
	*/
	queryField.value = validateQuery(queryField.value);
	if (trim(queryField.value)!==""){
		searchTermField.value = queryField.value; //keep original query
		queryPostField.value = "(" + queryPrefixField.value + queryField.value + ")";
		form.submit();
	}
}
function quote(element, check){
	if (element.value.indexOf("\"")===0 && element.value.lastIndexOf("\"")===element.value.length-1 && !check.checked){
		element.value=element.value.substring(1, element.value.length-1);
	}else if (element.value.length>0 && element.value.charAt(0)!=="\"" && element.value.charAt(element.value.length-1)!=="\"" && check.checked){
		element.value="\"" +  element.value + "\"";
	}
}
function asterisk(element, check){
	var quoted=false;
	if (element.value.lastIndexOf("*")!==element.value.length-1 && check.checked){
		quoted=false;
		//remove final quote if there is one
    	if (element.value.lastIndexOf("\"")===element.value.length-1){
    		element.value=element.value.substring(0, element.value.length-1);
    		quoted=true;
    	}	
		//add *
		element.value=element.value + "*";	
		//requote
		if (quoted){ element.value=element.value + "\"";}
	}else if (!check.checked){
		quoted=false;
		//remove final quote if there is one
    	if (element.value.lastIndexOf("\"")===element.value.length-1 && element.value.length>0){
    		element.value=element.value.substring(0, element.value.length-1);
    		quoted=true;
    	}
		//remove *
		if (element.value.charAt(element.value.length-1)==="*"){ 
			element.value=element.value.substring(0, element.value.length-1);}
		//requote
		if (quoted){ element.value=element.value + "\"";}
	}
}

function openWindow(title, content){
	newWindow = window.open('',title,'width=600,height=400,resizable=yes');
	newWindow.document.write(content); 
	newWindow.document.close();
}

function toggleLayer(whichLayer, displayStyle){
	var obj, link;
	if (document.getElementById){
		// this is the way the standards work
		obj = document.getElementById(whichLayer);
		link = document.getElementById('toggle'+whichLayer);
	}
	else if (document.all){
		// this is the way old msie versions work
		obj = document.all[whichLayer];
		link = document.getElementById('toggle'+whichLayer);
	}
	else if (document.layers){
		// this is the way nn4 works
		 obj = document.layers[whichLayer];
		 link = document.getElementById('toggle'+whichLayer);
	}

	obj.style.display = obj.style.display? "":displayStyle;
	if (link.className.indexOf('lopen')>-1) { 
		link.className = link.className.replace(/lopen/,'lclosed'); 
	} else if (link.className.indexOf('lclosed')>-1) { 
		link.className = link.className.replace(/lclosed/,'lopen'); 
	}
}

function toggle(id, tag){
	objs = document.getElementsByTagName(tag);
	for (var i = 0; i<objs.length;i++){
		if (objs[i].id === id) {
			if (objs[i].style.display===""){ objs[i].style.display="inline";}
			objs[i].style.display = (objs[i].style.display==="inline")? "none":"inline";
		}
	}
}

var MAX_WORD_LENGTH = 27;

function hyphenateSentence(sentence){
	if (sentence.length>MAX_WORD_LENGTH){
		sentence = sentence.replace(/([-;,\.\?:%!=\/\(\)\\])/g, "$1 ");
	}
	var words = sentence.split(" ");
	var hyphSentence = "";
	for (var i = 0; i<words.length; i++){
		hyphSentence += hyphenate(words[i]) + " ";
	}
	return hyphSentence;
}

function hyphenate(word){
	//simple script for hyphenating words
	var MIN_HYPHWORD2_LENGTH = 3;
	var hyphWord1 = word;
	var hyphWord2 = "";
	var words;
	if (word.length>MAX_WORD_LENGTH){
		//split on max word length
		hyphWord1 = word.substring(0, MAX_WORD_LENGTH);
		hyphWord2 = word.substring(MAX_WORD_LENGTH);
		if (hyphWord2.length < MIN_HYPHWORD2_LENGTH) {
			hyphWord1 = word.substring(0, MAX_WORD_LENGTH-MIN_HYPHWORD2_LENGTH+1);
			hyphWord2 = word.substring(MAX_WORD_LENGTH-MIN_HYPHWORD2_LENGTH+1);
		}
		hyphWord2=hyphenate(hyphWord2);
	}
	return hyphWord1 + ((hyphWord2!=="")?"- " + hyphWord2:"");
}

function setfocus(){
	if (document.forms["logonForm"] && document.forms["searchForm"].visibleQuery){
		document.forms["logonForm"].userName.focus();
		}
	else if (document.forms["localeSearchForm"] && document.forms["localeSearchForm"].visibleQuery){
		document.forms["localeSearchForm"].visibleQuery.focus();
		}
	else if (document.forms["searchForm2"] && document.forms["searchForm2"].query1){
		document.forms["searchForm2"].query1.focus();
		}
	else if (document.forms["searchForm"]) {
		document.forms["searchForm"].visibleQuery.focus();
		}
}

function dateUpdate(field, element, separator){
	var el = document.getElementById(element);
	el.value = 	document.getElementById(field + '.day').value + separator +
				document.getElementById(field + '.month').value + separator +
				document.getElementById(field + '.year').value;
}

function replaceWindowsChars(textField){
	//replace the non-standard chars produced by MSWord
	aString= textField.value;
	if (aString==null) return;
	result= '';
	for (i=0; i<aString.length; i++){
		switch(aString.charCodeAt(i)){
			case 8230: result+= '...'; break; //HORIZONTAL ELLIPSIS
			case 8216: result+= '\''; break; //LEFT SINGLE QUOTATION MARK
			case 8217: result+= '\''; break; //RIGHT SINGLE QUOTATION MARK
			case 8220: result+= '"'; break; //LEFT DOUBLE QUOTATION MARK
			case 8221: result+= '"'; break; //RIGHT DOUBLE QUOTATION MARK
			case 8226: result+= String.fromCharCode(0xb7); break; //BULLET
			default: result+= aString.charAt(i);
		}
	}
	textField.value= result;
}

function checkMail()
{
	var x = document.getElementById("emailInput").value;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(x)) return true;
	else alert('Dit is geen geldig e-mailadres, gelieve één geldig e-mailadres in te vullen');
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
  return false;
}