// name: de algemene naam groep die op display none gezet moet worden;
// numberToHide: het aantal id's van de groep (vanaf 1);
// idToShow: het nummer van de groep dat getoond moet worden;
function showHide(name, numberToHide, idToShow) {
	//alert(name +" | "+numberToHide+" | "+idToShow);
	for (i = 0; i < numberToHide; i++) {
		$(name+i).setStyle('display', 'none');
	}
	$(name + idToShow).setStyle('display', 'block');
}


//to make ie hover stuff...
sfHover = function() {
	var sfEls = document.getElementById("mainnav").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"), "");
		}
	}
}

function loadSubMenu(pageID) {
	$('submenu_container').innerHTML = '';
	//load current submenu into submenu-section
	if (!isNaN(pageID)) {	//check if pageID is numeric
		if ($('li'+pageID) != undefined) { //check if li exists
			var oMenu = $('li'+pageID);
			if (oMenu.childNodes.length > 1) { //check if menu has submenu
				var thisTitle = '<h1>' + oMenu.childNodes[0].innerHTML + '</h1>';
				var thisSubMenu = '<ul id=submenu>' + oMenu.childNodes[1].innerHTML + '</ul>';
				$('submenu_container').innerHTML = thisTitle + thisSubMenu;
			}
		}
	}
	return true;
}

// Resize window
function resizeWindow() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
	var margintop = (myHeight  - 580)/2;
	if (margintop<1)margintop = 0;
  $("container").style.margin = margintop+"px auto 0px auto";
}


// verbeterde functie om eerste form-element te selecteren indien aanwezig
function focusFirst() {
	if ((typeof(document.forms[1]) != "undefined")) {
		if ((typeof(document.forms[1].elements[0]) != "undefined")) {
			document.forms[1].elements[0].focus();
		}
	}
}

//functie om pagina te openen via javascript
function go(paginaURL) {
	parent.location.href = paginaURL;
}

// event handling and $-function--------------------------------------------
function $() {
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string')
			element = document.getElementById(element);
		if (arguments.length == 1)
			return element;
		elements.push(element);
	}
	return elements;
}
function removeEvent( obj, type, fn )
{
	if (obj.removeEventListener)
		obj.removeEventListener( type, fn, false );
	else if (obj.detachEvent)
	{
		obj.detachEvent( "on"+type, obj[type+fn] );
		obj[type+fn] = null;
		obj["e"+type+fn] = null;
	}
}
function addLoadEvent(func) {
	var oldonload = window.onload;

	if (typeof window.onload != "function") {
		window.onload = func;
	} else {
		window.onload = function () {
			oldonload();
			func();
		}
	}
}

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp('(^|\\s)'+searchClass+'(\\s|$)');
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}
// -------------------------------------------------------------------------


// string manipulations ----------------------------------------------------
function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}
function trim(str){   return str.replace(/^\s*|\s*$/g,"");}
// -------------------------------------------------------------------------

/* == Set cookie == */
function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}

function FixCookieDate (date) {
  var base = new Date(0);
  var skew = base.getTime(); // dawn of (Unix) time - should be 0
  if (skew > 0)  // Except on the Mac - ahead of its time
    date.setTime (date.getTime() - skew);
}

/* ================================================================================================= */
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else {var expires = "";}
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');

	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function delRekCookie( name, path, domain ) {
	if ( readCookie( name ) )
		document.cookie = name + "=" +
		( ( path ) ? ";path=" + path : "") +
		( ( domain ) ? ";domain=" + domain : "" ) +
		";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}


function preloadImages() {
  var d=document; if(d.images){ if(!d.p) d.p=new Array();
    var i,j=d.p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.p[j]=new Image; d.p[j++].src=a[i];}}
}

function roll_over(img_name, img_src) {
	document[img_name].src = img_src;
}


// -------------------------------------------------------------------------
/* ================ Automatic Popup's ================ */
function setPopLinks() {
	var x = document.getElementsByTagName('a');
	//console.log (x);
 	for (var i=0;i<x.length;i++) {
		if (x[i].className.indexOf('popup') >= 0) {
			x[i].onclick = function () {
				return pop(this.href)
			}
			x[i].title += ' (opent in nieuw venster)';
		}
	}
}

function pop(url) {
	newwindow=window.open(url);
	if (window.focus) {newwindow.focus()}
	return false;
}

// -------------------------------------------------------------------------
