// ***************** MENU SCRIPT ********************

subnavTimes = new Array(-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1);

setInterval("checkNav()", 20);

function checkNav() {
	for (i = 0; i < subnavTimes.length; i++){
		if (subnavTimes[i] != -1){
			subnavTimes[i]++;
			if (subnavTimes[i] == 20){
				closenav(i + 1);
			}
		}
	}
}

function closeAll(){
	for (i = 0; i < subnavTimes.length; i++){
		if (subnavTimes[i] != -1){
			closenav(i + 1);
		}
	}
}

function opennav(navNr){
	closeAll();
	//swap bg
	nav = 'nav' + navNr;
	//swapbg(nav, true);
	
	//show subnav
	div = document.getElementById('subnav' + navNr);
		
	div.style.display = 'block';
	
	subnavTimes[navNr - 1] = -1;
}

function closenav(navNr){
	nav = 'nav' + navNr;
	//swapbg(nav);
	
	
	//show subnav
	div = document.getElementById('subnav' + navNr);
	//alert(div + " - " + navNr);
	if (div != null){
		div.style.display = 'none';
	}
	
	
	subnavTimes[navNr - 1] = -1;
}

function setClosenav(navNr){
	//alert("hier?");
	subnavTimes[navNr - 1] = 0;
}

// *************************** END: MENU SCRIPT ********************


// Log out
function logout () {
	// Get current url
	url = self.location;
	url = String(url);

	// A #?
	a = url.indexOf('#');
	if (a > 0) {
		url = url.substr(0, a);
	}	

	// Already a ?
	if (url.indexOf('?') > 0) {
		url = url + '&logout=yes';
	} else {
		url = url + '?logout=yes';
	}

	self.location = url;
}



// Keep on top!

function ontop() {
   if (document.layers) {
        document.layers['cms_ontop'].pageY = window.pageYOffset;
		document.layers['cms_ontop2'].pageY = window.pageYOffset;
    }

    else if (document.all) {
	    document.all['cms_ontop'].style.position = 'absolute';
        document.all['cms_ontop'].style.top = document.body.scrollTop;
		document.all['cms_ontop2'].style.position = 'absolute';
        document.all['cms_ontop2'].style.left =  document.body.scrollWidth / 2 + 370;
		document.all['cms_ontop2'].style.top = document.body.scrollTop;
    } else {
		document.getElementById('cms_ontop2').style.position = 'fixed';
        document.getElementById('cms_ontop2').style.left =  document.body.scrollWidth / 2 + 370;
	}

    setTimeout('ontop()',100);

}

// Popup function
function popup (url, width, height) {
	var popurl=url;
	var winl = (screen.width - width) / 2;
    var wint = (screen.height - height) / 2;

	winpops=window.open(popurl,"","width=" + width + ",height=" + height + ",left=" + winl + ",top=" + wint)

	winpops.focus();
}

function swapbg(id, keepon){
	img = document.getElementById(id);
		
	cursrc = img.style.backgroundImage;
	cursrc = cursrc.substr(4, cursrc.length - 5);
		
	overpos = cursrc.indexOf("_h.gif");
	normpos = cursrc.indexOf("_n.gif");
	
	if (normpos != -1) {
		//replace image
		begin = cursrc.substr(0,normpos)
		newsrc = begin + "_h.gif";
		img.style.backgroundImage = 'url(' + newsrc + ')';
	}
	
	if (overpos != -1 && keepon == undefined) {
		//replace image
		begin = cursrc.substr(0,overpos)
		newsrc = begin + "_n.gif";
		img.style.backgroundImage = 'url(' + newsrc + ')';
	}
}

function swap(img){
	cursrc = img.src;
	overpos = cursrc.indexOf("_h.gif");
	normpos = cursrc.indexOf("_n.gif");

	if (normpos != -1) {
		//replace image
		begin = cursrc.substr(0,normpos)
		newsrc = begin + "_h.gif";
		img.src = newsrc;
	}

	

	if (overpos != -1) {
		//replace image
		begin = cursrc.substr(0,overpos)
		newsrc = begin + "_n.gif";
		img.src = newsrc;
	}
}

function submitForm (nm) {	
	document.forms[nm].submit();	
}

function showWindow(e) {	
		hideWindow();
	
		var x=y=0;
    	if (e != '') {
        	x = e.x;
	        y = e.y;
    	}
	
		// Display div 
		var a = document.all['hiddendiv_tekst'].value;
		a = replaceSubstring (a, "[br]", "\n");
		document.all['hiddendiv_tekst'].value = a;
		document.all['hiddendiv'].style.left = x + 60;
		document.all['hiddendiv'].style.top = y- 26;
	
		document.all['hiddendiv'].style.display = 'block';   
	}

function hideWindow () {
	document.all['hiddendiv'].style.display = 'none';
}

function replaceSubstring(inputString, fromString, toString) {
   		// Goes through the inputString and replaces every occurrence of fromString with toString
			var temp = inputString;
				if (fromString == "") {
		    		return inputString;
			   }
				if (toString.indexOf(fromString) == -1) { // If the string being replaced is not a part of the replacement string (normal situation)
			    	while (temp.indexOf(fromString) != -1) {
			        	var toTheLeft = temp.substring(0, temp.indexOf(fromString));
						var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
						temp = toTheLeft + toString + toTheRight;
					}
			} else { // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
			      var midStrings = new Array("~", "`", "_", "^", "#");
			      var midStringLen = 1;
			      var midString = "";
			}
		// Find a string that doesn't exist in the inputString to be used
		// as an "inbetween" string
		while (midString == "") {
        	for (var i=0; i < midStrings.length; i++) {
            	var tempMidString = "";
            	for (var j=0; j < midStringLen; j++) {
					 tempMidString += midStrings[i]; 
				}
		        if (fromString.indexOf(tempMidString) == -1) {
             		midString = tempMidString;
					i = midStrings.length + 1;
				}
			}
		} // Keep on going until we build an "inbetween" string that doesn't exist
		// Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string
		while (temp.indexOf(fromString) != -1) {
        	var toTheLeft = temp.substring(0, temp.indexOf(fromString));
        	var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
        	temp = toTheLeft + midString + toTheRight;
      	}
		// Next, replace the "inbetween" string with the "toString"
		while (temp.indexOf(midString) != -1) {
        	var toTheLeft = temp.substring(0, temp.indexOf(midString));
        	var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
        	temp = toTheLeft + toString + toTheRight;
		}
	return temp; // Send the updated string back to the user
	} // Ends the check to see if the string being replaced is part of the replacement string or not
	
	// Popup function
		function wachtwoordpopup (taal) {
			var popurl='wachtwoordpopup.php?vergeten=1&taal=' + taal;
			winpop4=window.open(popurl,"newwin","width=360,height=240,top=100,left=100,scrollbars=1");
			winpop4.focus();
		}