// Encoding: UTF-8
// Latest update: 2010-05-02

var url_root = "http://users.skynet.be/jeugdkoor.erpe/";
var url_start = url_root + "index.html";
var url_feed = url_root + "nieuws.xml";


// keep out of frame
if (top.location != self.location){
	if (location.replace){
		top.location.replace(url_start);
	}
	else{
		top.location.href = url_start;
	}
}

function d_alert(s){
	if(window.location.hash == "#debug"){
		alert(s);
	}
} 


/**
 * Checks if an element has a given class
 * @param {Object} e			Element to check.
 * @param {String} theClass		Classname to check for.
 */
function hasClass(e, theClass){
	if(e.className) {
		return(e.className.match( new RegExp('\\b'+theClass+'\\b','g')));
	}
	return false;
}
	


/**
 * Adds a paragraph with the page's last modification date.
 * @param {String} id
 */
function PageTimestamp( id ){
	var p = document.createElement("p");

	if ( lastMod ){
		p.appendChild(document.createTextNode(lastMod()));
	}
	
	document.getElementById( id ).appendChild(p);
}




/**
 * Adds a paragraph with the page URL.
 * @param {String} id
 */
function PageUrl( id ){
	var p = document.createElement("p");

	p.appendChild(document.createTextNode("URL: "));
	p.appendChild(document.createTextNode(document.URL));
	
	document.getElementById( id ).appendChild(p);
}


/**
 * Appends the page validation links, selectable by a bitfield.
 * @param {String} id
 * @param {Number} flags
 */ 
function AppendPageValidate( obj , flags ) {
	var checks = [
		{bit: 0x01,	href: "http://validator.w3.org/check/referer", 										
					add: "", 			
					title: "test de HTML code", 	
					test: "HTML"},
		{bit: 0x02, href: "http://jigsaw.w3.org/css-validator/check/referer",							
					add: "", 			
					title: "test de CSS code",		
					test: "CSS"},
		{bit: 0x04, href: "http://www.icra.org/sitelabel/",												
					add: "", 			
					title: "test het ICRA label",	
					test: "ICRA"},
		{bit: 0x08, href: "http://feedvalidator.org/check.cgi?url=",									
					add: url_feed, 		
					title: "test de RSS feed",		
					test: "RSS"},
		{bit: 0x10, href: "http://microformatique.com/optimus/?format=validate&uri=",					
					add: document.URL, 	
					title: "test de microformats",	
					test: "uF"},		
		{bit: 0x20, href: "http://validator.w3.org/checklink?check=Check&hide_type=all&summary=on&uri=",
					add: document.URL, 	
					title: "test de links (let op - kan lang duren !)",			
					test: "links"},
		{bit: 0x40, href: "http://wave.webaim.org/refer",
					add: "", 	
					title: "test de toegankelijkheid",			
					test: "WAVE"}
		];
	var empty = true ;
	var p = obj;

	for (var i = 0; i < checks.length; i++) {
		if ((flags & checks[i].bit) == checks[i].bit) {
			if (!empty) {
				p.appendChild(document.createTextNode(" | "));
			}
			
			var a = document.createElement("a");
			a.setAttribute("href", checks[i].href + checks[i].add);
			a.setAttribute("title", checks[i].title);
			a.className = "noredirect";		// don't redirect through go.html (these tests work on the original page URL)
			a.appendChild(document.createTextNode(checks[i].test));
			p.appendChild(a);
			empty = false;
		}
	}
}


/**
 * Adds a paragraph with the page validation links, selectable by a bitfield.
 * @param {String} id
 * @param {Number} flags
 */ 
function PageValidate( id , flags ) {
	var p = document.createElement("p");
	AppendPageValidate( p, flags );
	document.getElementById( id ).appendChild(p);
}



/**
 * Fills the pagefooter with given id.
 * @param {Object} id
 * @param {Object} fields
 * @param {Object} flags
 */
function PageFooter( id, fields, flags ){
	var span;
	// right part
	if (fields & 0x01 == 0x01) {
		span = document.createElement("span");
		span.className = "floatright";
		if ( lastMod ){
			span.appendChild(document.createTextNode(lastMod()));
		}
		document.getElementById( id ).appendChild(span);
	}
	// left part
	span = document.createElement("span");
	span.className = "floatleft";
	AppendPageValidate( span, flags );
	document.getElementById( id ).appendChild(span);
}


/**
 * Adds a paragraph with the copyright notice.
 * @param {Object} id
 */
function Copyright( id ){
	if ( YearNow )	{
		if (id == "copyright") {//new
			if(document.getElementById(id)){
				document.getElementById(id).innerHTML = "©2005-" + YearNow() + " Jeugdkoor Erpe";
			}
		}
		else {//old
			var p = document.createElement("p");
			p.appendChild(document.createTextNode("©2005-"));
			p.appendChild(document.createTextNode(YearNow()));
			p.appendChild(document.createTextNode(" Jeugdkoor Erpe"));
			document.getElementById(id).appendChild(p);
		}
	}
}

////////////////////////////////////////////////////////////////////////////////////////////////

// 2005-12-25 Added Today()
// 2006-01-15 renamed dtFuture() to DaysToGo()
// 2006-10-25 added YearNow()
// 2007-01-28 modified FFuture(), added FFutureFromId(), syntax clean-up

function YearNow()	// geef huidig jaar in 4 cijfers
{
	var date = new Date();
	return(date.getFullYear());
}

function twodigits(inValue)
{
	if (inValue > 9) {return inValue;} else {return "0" + inValue;}
}

function DagNaam(d) // vertaal dagnummer 0..6 naar dagnaam zondag..zaterdag
{
 var dn = ["zondag","maandag","dinsdag","woensdag","donderdag","vrijdag","zaterdag"];
 return ((d > 6) ? "?" : dn[d]); 
}

function MaandNaam(m) // vertaal maandnummer 0..11 naar maandnaam januari..december
{
 var mn = ["januari","februari","maart","april","mei","juni","juli","augustus","september","oktober","november","december"];
 return ((m > 11) ? "?" : mn[m]); 
}

function dagDDmaandJJJJ(date) // formatteer een Date object als "dag DD maand JJJJ"
{
 return (DagNaam(date.getDay()) + " " + date.getDate() + " " + MaandNaam(date.getMonth())+ " " + date.getFullYear());
}

function DDmaandJJJJ(date) // formatteer een Date object als "DD maand JJJJ"
{
 return (date.getDate() + " " + MaandNaam(date.getMonth())+ " " + date.getFullYear());
}

function DDmaand(date) // formatteer een Date object als "DD maand" (bijv. "1 april")
{
 return (date.getDate() + " " + MaandNaam(date.getMonth()));
}


function lastMod()
{
	// (functie ontleend aan www.quirksmode.org en licht aangepast)
	
	if  (document.lastModified === ""){return "";}
	
	var x = new Date (document.lastModified);
	Modif = new Date(x.toGMTString());
	Year = takeYear(Modif);
	Month = Modif.getMonth();
	Day = Modif.getDate();
	Mod = (Date.UTC(Year,Month,Day,0,0,0))/86400000;
	x = new Date();
	today = new Date(x.toGMTString());
	Year2 = takeYear(today);
	Month2 = today.getMonth();
	Day2 = today.getDate();
	now = (Date.UTC(Year2,Month2,Day2,0,0,0))/86400000;
	daysago = now - Mod;
	if (daysago < 0) {return '';}
	unit = 'dagen';
	if (daysago > 730)
	{
		daysago = Math.floor(daysago/365);
		unit = 'jaar';
	}
	else if (daysago > 60)
	{
		daysago = Math.floor(daysago/30);
		unit = 'maanden';
	}
	else if (daysago > 14)
	{
		daysago = Math.floor(daysago/7);
		unit = 'weken';
	}
	var towrite = 'Pagina laatst gewijzigd: ';
	if      ( (daysago === 0) && (unit == 'dagen') ) {towrite += 'vandaag';}
	else if ( (daysago == 1) && (unit == 'dagen') ) {towrite += 'gisteren';}
	else if ( (daysago == 2) && (unit == 'dagen') ) {towrite += 'eergisteren';}
	else {towrite += daysago + ' ' + unit + ' geleden';}
	return towrite;
}

function takeYear(theDate)
{
	var x = theDate.getYear();
	var y = x % 100;
	y += (y < 38) ? 2000 : 1900;
	return y;
}

function DocTimeStamp()
{
/* var lm = new Date(document.lastModified);
 return("Pagina laatst gewijzigd op " + DDmaandJJJJ(lm));*/
 return(lastMod());
}

function DaysToGo(YYYY,MM,DD)
{
	Future = (Date.UTC(YYYY,MM-1,DD,0,0,0))/86400000;
	x = new Date();
	today = new Date(x.toGMTString());
	Year2 = takeYear(today);
	Month2 = today.getMonth();
	Day2 = today.getDate();
	now = (Date.UTC(Year2,Month2,Day2,0,0,0))/86400000;
	daystogo = Future - now;
	return daystogo;
}

function FFuture(YYYY,MM,DD)
{
	var today = new Date();
	var day = today.getDay();
	var towrite = "";
	var daystogo = DaysToGo(YYYY,MM,DD);
	if 	    (daystogo < -2)  {towrite = "";}
	else if (daystogo == -2) {towrite = "eergisteren, <br><br>";}
	else if (daystogo == -1) {towrite = "gisteren, <br><br>";}
	else if (daystogo === 0) {towrite = "vandaag, <br><br>";}
	else if (daystogo == 1)  {towrite = "morgen, <br><br>";}
	else if (daystogo == 2)  {towrite = "overmorgen, <br><br>";}
/*	else if (daystogo < 7) 	 {towrite = "deze week <br><br>";}
	else if (daystogo < 14)  {towrite = "volgende week <br><br>";}*/
	else if (daystogo <= 8)
	{
		if ( ( 5 >= day ) && ( day >= (8-daystogo) ) ){
			towrite = "volgende week <br><br>";}
		else{
			towrite = "deze week <br><br>";}
	}
	else if (daystogo < 16)
	{
		if ( day == 6 ){
			towrite = "volgende week <br><br>";}
		else if ( day < (15-daystogo) ){
			towrite = "volgende week <br><br>";}
		else{
			towrite = "";}
	}
	else {towrite = "";}
	return towrite;
}

function FFutureFromId(dYYYYMMDD){
	return FFuture(	dYYYYMMDD.slice(1,5),
					dYYYYMMDD.slice(5,7),
					dYYYYMMDD.slice(7,9));
}




function Today(){		/* geef vandaag weer als YYYYMMDD */
	var today,d = new Date();
	today = d.getFullYear();
	var mm = d.getMonth()+1;
	today+= ((mm<10)?"0":"") + mm;
	var dd = d.getDate();
	today+= ((dd<10)?"0":"") + dd;
	return today;
}



////////////////////////////////////////////////////////////////////////////////////////////////

Date.MILLISECONDS_PER_DAY = 86400000; // equals 24 * 60 * 60 * 1000

// new public instance methods for Date()
/**
 * Returns the absolute day number
 */
Date.prototype.getDayOfEpoch = function(){
	return (Math.floor(this.getTime() / Date.MILLISECONDS_PER_DAY) + 1);
};
	
/**
 * Returns the absolute week number
 * @param {number} [nWeekStartsOn]		The day at which a new week starts (0=sunday, 1=monday, etc...; default is 1 for monday)
 */
Date.prototype.getWeekOfEpoch = function(nWeekStart){
	var nWeekStartsOn = (nWeekStart === undefined) ? 1 : nWeekStart ;
	var nThisDayNumber = this.getDayOfEpoch();		// absolute day number of the given date
	// correct for the fact that 1/1/1970 was a Thursday (day number 4)
	var nWeekStartAdjusted = (nWeekStartsOn > 4) ? (nWeekStartsOn - 4) : (nWeekStartsOn - 4 + 7) ;	// range 1..7

	return Math.floor( ( nThisDayNumber + 13 - nWeekStartAdjusted ) / 7);
};






//////////////////////////////////////////////////////////////////////////////////////////////

/*
 * Cookies object, 
 * originally from www.quirksmode.org,
 * modified to NOT save its own copies of name/value pairs as object properties,
 * improved using encodeURIComponent() and decodeURIComponent().
 * 
 * See cookie specs at http://wp.netscape.com/newsref/std/cookie_spec.html
 *				   and http://developer.mozilla.org/en/docs/DOM:document.cookie
 */

/**
 * Cookies object.
 * The new methods 
 *  read(), write(), clear() and list()
 * replace the old methods
 *  init(), create() and erase()
 */
var Cookies = {
	/**
	 * Reads the given cookie.
	 * @param {String} cookieName
	 */
	read: function(name) {
		var allCookies = document.cookie.split('; ');
		for ( var i = 0; i < allCookies.length; i++ ) {
			var cookiePair = allCookies[i].split('=');
			if (cookiePair[0] == name) {
				return decodeURIComponent(cookiePair[1]);
			}
		}
		return "";
	},
	/**
	 * Writes the given cookie.
	 * @param {String} name
	 * @param {Object} value
	 * @param {Object} days (optional, default is 365, 0 means session cookie)
	 * @param {Object} path (optional, default is "/")
	 */
	write: function (name, value, days, path) {
		if( ! path ){
			path = "/";
		}
		if(days === 0){
			expires = "";
		}
		else{
			if ( ! days ) {
				days = 365;
			}
		
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			expires = "; expires=" + date.toUTCString();
		}
		document.cookie = name + "=" +  encodeURIComponent(value) + expires + "; path=" + path;
	},
	/**
	 * Clears (deletes) the given cookie.
	 * @param {String} name
	 */
	clear: function (name) {
		this.write(name, '', -1);
	},
	/**
	 * Lists the names of all cookies.
	 */
	list: function () {
		var allCookies = document.cookie.split('; ');
		var theList = [];
		for ( var i = 0; i < allCookies.length; i++ ) {
			var cookiePair = allCookies[i].split('=');
			theList.push(cookiePair[0]);
		}
		return theList;
	}
};








////////////////////////////////////////////////////////////////////////////////////////////////

/*
	Browserdetect script originally from http://www.quirksmode.org/js/detect.html
	
	2006/11/10	Added detection of SeaMonkey browser
	2008/03/22	Added detection of K-Meleon browser
				Modif'd Safari case to show the version (not the build) (at least for the Windows version)
	2008/03/25	Added browser language detection
	2008/03/27	Modif'd to return also the full version information
	2008/12/15	Added detection of Chrome browser
	
	Before use, call BrowserDetect.init()
	
	After that, you can use
    * BrowserDetect.browser		to obtain the browser name
    * BrowserDetect.version		to obtain the browser version
    * BrowserDetect.fullversion	to obtain the full browser version
    * BrowserDetect.OS			to obtain the OS name 			
    * BrowserDetect.language	to obtain the browser language 			
*/
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) 
					|| "An unknown browser";
		this.fullversion = this.searchVersion(navigator.userAgent)
					|| this.searchVersion(navigator.appVersion)
					|| "an unknown version";
		this.version = parseFloat(this.fullversion);
		this.OS = this.searchString(this.dataOS) 
					|| "an unknown OS";
		this.language = navigator.language 
					 || navigator.browserLanguage 
					 || "an unknown language";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					{ return data[i].identity; }
			}
			else if (dataProp)
				{ return data[i].identity; }
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) { return; }
		return this.parseDottedDecimal(dataString.substring(index+this.versionSearchString.length+1));
	},
	parseDottedDecimal: function (dataString) {
		var length = 0;
		var re = /[0-9\.]/;
		for (var i = 0; i < dataString.length; i++){
			if( (dataString.charAt(i).match(re))){ length++; }
			else{ break; }
		}
		return (dataString.substr(0, length));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			versionSearch: "Version",		/*added gvh 2008/03/22*/
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "SeaMonkey",
			identity: "SeaMonkey"
		},
		{
			string: navigator.userAgent,
			subString: "K-Meleon",
			identity: "K-Meleon"
		},
		{ // added gvh 2008/12/15
			string: navigator.userAgent,
			subString: "Chrome",
			versionSearch: "Chrome",
			identity: "Chrome"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};

////////////////////////////////////////////////////////////////////////////////////////////////

/**
 * Moves the browser to a new URL.
 * @param {string} newUrl	The new URL to go to.
 */
function gotoUrl(newUrl){
	if (location.replace){
		location.replace(newUrl);
	}
	else{
		location.href = newUrl;
	}
}

////////////////////////////////////////////////////////////////////////////////////////////

/**
 * Moves the child with given id to the first position. (tested in IE6, FF2, Opera 9, Safari 3.0.4)
 * @param {string} id 	Id of the child that should be moved to first position.
 */
function moveChildFirst(id){
	var theChild = document.getElementById(id) ;
	if (theChild) {
		var theParent = theChild.parentNode;
		var theFirstChild = theParent.firstChild;
		theParent.insertBefore(theChild, theFirstChild);
	}
}

/**
 * Moves the child with given id to the last position. (tested in IE6, FF2, Opera 9, Safari 3.0.4)
 * @param {string} id 	Id of the child that should be moved to last position.
 */
function moveChildLast(id){
	var theChild = document.getElementById(id) ;
	if (theChild) {
		var theParent = theChild.parentNode;
		var theOldChild = theParent.removeChild(theChild);
		theParent.appendChild(theOldChild);
	}
}



/**
 * Use of the query string in URL's
 */
var query = {
	/**
	 * Returns the actual query data as an object.
	 * @return {Object}
	 */
	toObject : function(){
		var name, t;
		var q = {};
		
		// get the query, without the leading '?'
		var x = window.location.search.substring(1);
		// replace plusses with blanks
		x = x.replace(/\+/g, ' ');
		// semicolons as separators are nonstandard, but we accept them (not required if query was created by ourselves)
		x = x.replace(/;/g, '&');
		// split at every '&'
		x = x.split('&');
		
		for (var i = 0; i < x.length; i++){
			t = x[i].split('=', 2);
			name = decodeURIComponent(t[0]);
			if (!q[name]) {
				q[name] = [];
			}
			if (t.length > 1) {
				q[name][q[name].length] = decodeURIComponent(t[1]);
			}
			// next two lines are nonstandard
			else {
				q[name][q[name].length] = true;
				// if not a 'name=value' pair given, but only a name, then this is assumed to be a boolean which received a value of true
			}
		}
		return q;
	},
	/**
	 * Returns a query string from a two-dimensional array of name/value pairs.
	 * @param {Array} aa		Two-dimensional array; list of name/value pairs.
	 * @return {String}
	 */
	create : function( aa ){
		var result = "";
		for( var p = 0; p < aa.length; p++ ){
			// add an ampersand & (except the first time)
			if(result !== ""){ result += "&"; }
			// add the 'name' part (properly encoded)
			result += encodeURIComponent(aa[p][0]);
			if (aa[p].length > 1) {
				// add an equal sign =
				result += "=";
				// add the 'value' part (properly encoded)
//				result += encodeURIComponent(aa[p][1]);
				result += encodeURIComponent(aa[p][1]).replace(/\%20/g ,"+");	// replace %20 (space) with a '+'
			}
		}
		// prepend a query sign ?
		if(result !== ""){ result = "?" + result; }
		
		return result;
	}
};



/**
 * Modifies all external links' href to go through the 'go.html' page.
 * 
 * Several methods are possible, selected with 0/1 in the inner 'if else else' test.
 * Attention: Some browsers (e.g. Opera 9 and Safari 3) still have the redirected url in the href
 * when returning to the page with the 'Back' button. We must take care to not redirect twice!
 * 
 * encodeURIComponent() is required for those URL's containing a ? = or &
 */
function externalLinksGo(){
	var encode = function(uri){
		return encodeURIComponent(uri);
	};
	var sToAdd = "go.html?url=";
	var a = document.getElementsByTagName("a");
	for(var i = 0; i < a.length; i++){
		// external links with class "noredirect" must not be changed (e.g. page checks HTML, CSS etc...)
		if(hasClass(a[i], "noredirect")){
			continue;
		}
		if( a[i].href.substring(0,7) == "http://"){
			if (a[i].href.substring(0, url_root.length) !== url_root) {
				if (0) {// method 1: directly modify the href (debug mode)
					//  Take care to not redirect twice!
					var j = a[i].href.indexOf(sToAdd);
					if (j == -1) {
						a[i].href = sToAdd + encode(a[i].href);
					}
//					else{
//						d_alert(sToAdd + " found at index " + j + " onload()");
//					}
				}
				else { // method 3: make the jump at onclick() [dont't change the href; no problems with the Back key]
					a[i].onclick = function(){
												window.location.href = sToAdd + encode(this.href);
												return false;
					};					
				}
			}
		}
	}
}




////////////////////////////////////////////////////////////////////////////////////////////

// test 2010/01/17
function getDivsOfClass(theClass, obj){
	if (!obj) { obj = document;}
	var resultArray = [];
	var divs = obj.getElementsByTagName("div");
	for (var j=0; j<divs.length; j++) {
		if (hasClass(divs[j], theClass)) {
			resultArray.push(divs[j]);
		}
	}
	var testNode = resultArray[0];
	if (!testNode)	{return [];}
	return resultArray;
}


/*
 * Table-Of-Contents script adapted from http://www.quirksmode.org/quirksmode.js
 */
function getElementsByTagNames(list,obj) {
	if (!obj) { obj = document;}
	var tagNames = list.split(',');
	var resultArray = [];

	for (var i=0;i<tagNames.length;i++) 	{
		var tags = obj.getElementsByTagName(tagNames[i]);
		for (var j=0;j<tags.length;j++) 
		{
			resultArray.push(tags[j]);
		}
	}

	var testNode = resultArray[0];
	if (!testNode)	{return [];}
	if (testNode.sourceIndex) {
		resultArray.sort(function (a,b) {
				return a.sourceIndex - b.sourceIndex;
		});
	}
	else if (testNode.compareDocumentPosition) {
		resultArray.sort(function (a,b) {
				return 3 - (a.compareDocumentPosition(b) & 6);
		});
	}
	return resultArray;
}	
	
function createTOC() {
	var y = document.createElement('div');
	y.id = 'innertoc';
	var a = y.appendChild(document.createElement('span'));
	a.id = 'contentheader';
	a.innerHTML = 'Op deze pagina:';
	var z = y.appendChild(document.createElement('div'));
	var toBeTOCced = getElementsByTagNames('h2,h3,h4,h5');
//	var toBeTOCced = getDivsOfClass("item");// test 2010/01/17
	if (toBeTOCced.length < 2) { return false; }
	
	for (var i=0; i < toBeTOCced.length; i++){
		var tmp = document.createElement('a');
		tmp.innerHTML = toBeTOCced[i].innerHTML;
		z.appendChild(tmp);
		tmp.className = 'toc' + toBeTOCced[i].nodeName;
		var headerId = toBeTOCced[i].id || 'link' + i;		
		tmp.href = '#' + headerId;		
		toBeTOCced[i].id = headerId;
	}
	return y;
}

function appendTOC(idname){
	var ToC = createTOC();
	if (ToC) {document.getElementById(idname).appendChild(ToC);}
}


/* PUSH AND SHIFT FOR IE5 */

function Array_push() {
	var A_p = 0;
	for (A_p = 0; A_p < arguments.length; A_p++) {
		this[this.length] = arguments[A_p];
	}
	return this.length;
}

if (typeof Array.prototype.push == "undefined") {
	Array.prototype.push = Array_push;
}

function Array_shift() {
	var A_s = 0;
	var response = this[0];
	for (A_s = 0; A_s < this.length-1; A_s++) {
		this[A_s] = this[A_s + 1];
	}
	this.length--;
	return response;
}

if (typeof Array.prototype.shift == "undefined") {
	Array.prototype.shift = Array_shift;
}







////////////////////////////////////////////////////////////////////////////////
/**
 * @author Thomas Frank (http://www.thomasfrank.se/easier_than_ajax.html)
 */
/**
 * Includes the JS from the given url, and calls the given onload when ready.
 * @param {String} url
 * @param {Object} onload
 * @param {Boolean} allowCache
 */
includeJS=function(url,onload,allowCache){
     url=allowCache?url:url+'&nocache='+Math.random();
     url=url.split('?').length>1?url:url.replace(/\&/,'?');
     onload=typeof onload=="function"?onload:function(){};
     var js=document.createElement('script');
     js.setAttribute('src',url);
     js.addEventListener && function(){js.addEventListener('load',onload,false)}();
     js.onreadystatechange=
          function(){this.readyState=='complete' && onload.call()};
     document.getElementsByTagName('head').item(0).appendChild(js);
};



/////////////////////////////////////////////////

var spel = {
	spelletjes: [
	{	naam: "Schaak",				img: "spelletjes/schaak_eh.jpg",		url: "schaak_tm4.html"	}, 
	{	naam: "Fishy",				img: "spelletjes/fishy_eh.jpg",			url: "fishy.html"		}, 
	{	naam: "Vier op 'n rij",		img: "spelletjes/4op1rij_eh.jpg",		url: "4op1rij.html"		}, 
/*
	{	naam: "Tetris",				img: "spelletjes/tetris_eh.jpg",		url: "tetris.html"		}, 
	{	naam: "Reversi",			img: "spelletjes/reversi_eh.jpg",		url: "reversi.html"		}, 
	{	naam: "Digger",				img: "spelletjes/digger_eh.jpg",		url: "digger.html"		}, 
	{	naam: "Lines",				img: "spelletjes/lines_eh.jpg",			url: "lines.html"		}, 
	{	naam: "Tail Gunner",		img: "spelletjes/tailgunner_eh.jpg",	url: "tailgunn.html"	}, 
	{	naam: "Javanoid",			img: "spelletjes/javanoid_eh.jpg",		url: "javanoid.html"	}, 
	{	naam: "Warp",				img: "spelletjes/warp_eh.jpg",			url: "warp.html"		}, 
*/
	{	naam: "Mastermind",			img: "spelletjes/mastermind_eh.jpg",	url: "mastermind.html"	}, 
	{	naam: "Rubik's Kubus",		img: "spelletjes/rubik_eh.jpg",			url: "rubik.html"		}, 
	{	naam: "Sokoban",			img: "spelletjes/sokoban_eh.jpg",		url: "sokoban.html"		}
	],
	
	insertSpelletjeVanDeWeekBefore: function(id){
		var weekNumber = (new Date()).getWeekOfEpoch();
		var s = weekNumber % this.spelletjes.length;
		
		var div = document.createElement("div");
		div.className = "agenda";
		div.id = "SVDW";
		var h = document.createElement("h2");
		h.innerHTML = "Spelletje van de week";
		div.appendChild(h);
		h = document.createElement("h3");
		h.innerHTML = this.spelletjes[s].naam;
		div.appendChild(h);
		div.appendChild(document.createElement("br"));
		var div2 = document.createElement("div");
		div2.style.textAlign = "center";
		div.appendChild(div2);
		var a = document.createElement("a");
		a.href = this.spelletjes[s].url;
		a.title = this.spelletjes[s].naam;
		var img = document.createElement("img");
		img.src = this.spelletjes[s].img;
		a.appendChild(img);
		div2.appendChild(a);
		var p = document.createElement("p");
		p.className = "meer";
		a = document.createElement("a");
		a.href = "spellen.html#SPELLETJES";
		a.innerHTML = "meer spelletjes...";
		p.appendChild(a);
		div.appendChild(p);
		var ref = document.getElementById(id);
		ref.parentNode.insertBefore(div, ref);
	}
};


//////////////////////////////////////////
function styleZebraTables(){
	var tables = document.getElementsByTagName("table");
	for (var t=0; t<tables.length; t++){
		if(hasClass(tables[t], "zebra")){
			//alert("zebra table found");
			var rows = tables[t].getElementsByTagName("tbody")[0].getElementsByTagName("tr");
			for (var r=0; r<rows.length; r++){
				rows[r].className = (r%2 === 0)?"even":"odd";
			}
		}
	}
}




function globalAtEndOfPage(title){
	// voeg de tab "Nieuws" toe op het hoofdmenu
	addSiteheaderNavigationItem("Nieuws", "nieuws.html", title);

	// set external links
	externalLinksGo();

	// style the zebra tables
	styleZebraTables();
}


function globalOnLoad(){
	// set the actual copyright year
	Copyright("copyright");
	// vul het WIE tellertje dynamisch in
	fillWIE();
}


/**
 * Loads an XML file 
 * and either processes it with the given function (asynchronous mode; preferred method) 
 * or returns it as a DOM object (synchronous mode).
 * @param {String} filename			the XML file to load
 * @param {Object} [processXML]		function to call when the XML is ready (asynchronous!); if absent, works synchronously
 * @return {Object}					in async mode: success flag; in sync mode: the XML object
 */
function loadXML( filename, processXML ){
	/* Supported browsers		used method
	 * --------------------		--------------------------------------------
	 * - Internet Explorer		ActiveX		(Note: an IE-only method without ActiveX is described at http://dean.edwards.name/weblog/2006/04/easy-xml/)
	 * - Firefox				XMLHttpRequest
	 * - Opera					XMLHttpRequest
	 * - Safari					XMLHttpRequest
	 * - Chrome					XMLHttpRequest
	 */
	var async = ( typeof(processXML) == 'function' ) ;
	//alert("async = " + async ) ;

	var xml = null, req = false;
	
	try {
		// method for Internet Explorer (ActiveX)
		xml = new ActiveXObject("Microsoft.XMLDOM");
		xml.async = async;
		if( async ){
			xml.onreadystatechange = function(){
				if (xml.readyState == 4) {
					processXML(xml);
				}
			};
		}
		//alert("using method ActiveX");
		xml.load(filename);
		return (async ? true : xml );	// success
	}
	catch(e) {
		//alert("ActiveX failed");
		xml = null;
	}

	try {
		// this method works in FF, Opera, Safari and Chrome (info at http://ajaxpatterns.org/XMLHttpRequest_Call)
		req = new XMLHttpRequest();
		if( async ) {
			req.onreadystatechange = function(){
				if ( (req.readyState == 4) ) {
					processXML(req.responseXML);
				}
			};
		}
		req.open("GET", filename, async);
		req.send("");
		if( ! async ){
			xml = req.responseXML;
		}
		return (async ? true : xml );	// success
	} 
	catch (e) {
		//alert("XMLHttpRequest() failed");
		xml = null;
		req = false;
	}
	
	try {
		// this method works in FF, Opera (not Safari, not Chrome) (from the original from http://www.puuba.com)
		if(document.implementation && document.implementation.createDocument){
			xml = document.implementation.createDocument("", "", null);
			if (async) {
				xml.onload = function(){
					processXML(xml);
				};
			}
			xml.load(filename);
			return (async ? true : xml );	// success
		}
	}
	catch (e) {
		//alert("document.implementation failed");
		xml = null;
		req = false;
	}

	return (async ? false : null );	// failure
}


/**
 * Voeg een item toe aan de DIV met id "navigation" binnen het element met id "siteheader".
 * Het item is ofwel een <A> ofwel een <SPAN> met als inhoud de gegeven 'text'.
 * Is het een <A> dan wordt de gegeven 'href' gebruikt.
 * Is de gegeven 'title' gelijk aan de 'text' dan wordt het item een <SPAN>, zoniet een <A>.
 */
function addSiteheaderNavigationItem(text, href, title){
	var siteheader = document.getElementById("siteheader");
	var siteheaderdivs = siteheader.getElementsByTagName("div");
	
	for (var i = 0; i < siteheaderdivs.length; i++){
		if(hasClass(siteheaderdivs[i], "navigation")){
			if (title && (title == text)) {
				var a = document.createElement("span");
			}
			else {
				a = document.createElement("a");
				a.href = href;
			}
			a.innerHTML = text;
			siteheaderdivs[i].appendChild(a);
			
			// truuk om het 'redraw' probleem van IE6 op te lossen
			siteheader.style.display = "none";
			siteheader.style.display = "block";
			
			return true;
		}
	}
	return false;
}



/**
 * Functies voor het W.I.E. tellertje
 */
function fillWIE(){
	// zoek het parent element met het juiste id
	var parent = document.getElementById("bezoekers");
	if (parent) {
		// vervang document.write() door een lege functie (we hebben de document.write's 
		//	van het WIE script niet nodig)
		document.write = function(args){};

		// laad het WIE script dynamisch	
		var script = document.createElement("script");
		script.src = "http://www.wieonline.nl/wie/wie.php?user=JeugdkoorErpe";
		script.type = "text/javascript";
		parent.appendChild(script);

		var div = document.createElement("div");
		div.innerHTML = "&nbsp;";
		var br = document.createElement("br");
		parent.appendChild(div);
		parent.appendChild(br);
		parent.appendChild(br);

		// check met tussenpozen of de WIEnu variabele al beschikbaar is (i.e. script geladen)		
		theInterval = window.setInterval(function check(){
			if (typeof(WIEnu) != "undefined") {
				if (WIEnu > 1) {
					div.innerHTML = "Er zijn " + WIEnu + " bezoekers online";
				}
				window.clearInterval(theInterval);
			}
		}, 100);
	}
}	



// voorlopig niet gebruikt...
function overwriteDocumentWrite(){
	//
	// document.write() from http://www.gfilter.net/?Post=Making-Document.Write-Actually-Work		
	document.write = function(args) {
	    var dwNode = document.createElement('DIV');
	    dwNode.innerHTML = args;
	
	    document.body.appendChild(dwNode);
	 
	    // Script nodes in innerHTML won't run unless we eval them
	    var runScripts = function(e) {
	        if (e.nodeType != 1) {
				return;
			}
	 
	        if (e.tagName.toLowerCase() == 'script') {
	            eval(e.text);
	        }
	        else {
	            var n = e.firstChild;
	            while (n) {
	                if (n.nodeType == 1) {
						runScripts(n);
					}
	 
	                n = n.nextSibling;
	            }
	        }
	    };

		runScripts(dwNode);
	};
	// end of document.write() replacement
}


