/*
 *  Standaardscripts voor ministeriele websites
 */


/*
	TEKSTGROOTTE
	Knoppen en functionaliteit worden automatisch gegenereerd in
	het element met id="tekstgrootte"
*/

var paginaTaal; // welke taal gebruikt de pagina? Gezet in initializeAll

var tekstGrootte = {
	tekst: {
		nl: 'Tekstgrootte ',
		en: 'Text size '
	},
	hulptekstGroter: {
		nl: 'groter',
		en: 'larger'
	},
	hulptekstKleiner: {
		nl: 'kleiner',
		en: 'smaller'
	},
	groterTekst: {
		nl: '+',
		en: '+'
	},
	kleinerTekst: {
		nl: '-',
		en: '-'
	},
	huidig: 2,
	classes: ['kleinst','kleiner','','groter','grootst'],
	groterLink: undefined,
	kleinerLink: undefined,
	oudeLink: undefined,
	styleSheets: [],
	bodyClass: '',
	init: function () {
		var writeroot = document.getElementById('tekstgrootte');
		if (!writeroot) return;
		this.bodyClass = document.body.className;
		$('tekstgrootte').replaceChild = '';
		var header = document.createElement('h2');
		header.appendChild(document.createTextNode(this.tekst[paginaTaal]));
		writeroot.appendChild(header);
		this.groterLink = document.createElement('a');
		this.groterLink.href = '#';
		this.groterLink.title = this.hulptekstGroter[paginaTaal];
		this.groterLink.appendChild(document.createTextNode(this.groterTekst[paginaTaal]));
		this.groterLink.onclick = this.tekstGroter;
		this.kleinerLink = document.createElement('a');
		this.kleinerLink.href = '#';
		this.kleinerLink.title = this.hulptekstKleiner[paginaTaal];
		this.kleinerLink.appendChild(document.createTextNode(this.kleinerTekst[paginaTaal]));
		this.kleinerLink.onclick = this.tekstKleiner;
		writeroot.appendChild(listify([this.kleinerLink,this.groterLink]));
		var oudeWaarde = Cookies.tekstgrootte;
		if (!oudeWaarde) return;
		this.huidig = oudeWaarde;
		this.zetGrootte();
	},
	tekstGroter: function () {
			tekstGrootte.huidig++;
			tekstGrootte.zetGrootte();
			location.reload();
		return false;
	},
	tekstKleiner: function () {
			tekstGrootte.huidig--;
			tekstGrootte.zetGrootte();
			location.reload();
		return false;
	},
	zetGrootte: function () {
		if (this.huidig >= this.classes.length-1)
			this.groterLink.className = 'disabled';
		else
			this.groterLink.className = '';
		if (this.huidig <= 0)
			this.kleinerLink.className = 'disabled';
		else
			this.kleinerLink.className = '';
		if (this.huidig < 0)
			this.huidig = 0;
		if (this.huidig >= this.classes.length)
			this.huidig = this.classes.length-1;
		document.body.className = this.bodyClass + ' ' + this.classes[this.huidig];
		Cookies.create('tekstgrootte',this.huidig,365);
	}
}

var printLink = {
	tekst: {
		nl: "Print deze pagina",
		en: "Print this page"
	},
	init: function () {
		var writeroot = document.getElementById('printlink');
		if (!writeroot) return;
		var link = document.createElement('a');
		link.href = '#';
		link.appendChild(document.createTextNode(this.tekst[paginaTaal]));
		link.onclick = function () {
			window.print();
			return false;
		}
		writeroot.appendChild(link);
	}
}

var printOverview = {
	printlistAdd: {
		nl: "Voeg toe aan printoverzicht",
		en: "Add to print list"
	},
	printlistAdded: {
		nl: "U heeft deze webpagina toegevoegd aan het printoverzicht.",
		en: "You have added this web page to the print list."
	},
	printlistDuplicates: {
		nl: "Deze webpagina stond al in het printoverzicht.",
		en: "This web page was already on the print list."
	},
	printlistFilelimit: {
		nl: "De webpagina is niet toegevoegd aan het printoverzicht. Het maximumaantal te printen webpagina\'s (25) is bereikt. ",
		en: "The web page has not been added to the print list. The maximum number of web pages (25) to print has been reached."
	},
	printlistRemoveAll: {
		nl: "Verwijder alle webpagina\'s",
		en: "Remove all web pages"
	},
	printlistRemoved: {
		nl: "Deze webpagina is verwijderd uit het printoverzicht.",
		en: "This web page has been removed from the print list."
	},
	printlistRemovedAll: {
		nl: "Alle webpaginas zijn verwijderd uit het printoverzicht.",
		en: "All web pages have been removed from the print list."
	},
	printlistOverview: {
		nl: "Mijn printoverzicht",
		en: "My print list"
	},
	printListIntro: {
		nl: "Dit is het overzicht met webpagina's die u heeft geselecteerd om te printen. U kunt webpagina's toevoegen en/of verwijderen.",
		en: "You have selected the following web pages to print. You may add or remove pages from this list."
	},
	printListIntroEmpty: {
		nl: "U kunt webpagina's op deze site selecteren en toevoegen aan het printoverzicht, via de link 'Voeg toe aan printoverzicht' onder aan de webpagina. U heeft nog geen pagina's geselecteerd.",
		en: "You can select web pages on this website and add them to the print list, using the 'Add to print list' link at the bottom of the web page. You have not added any web pages to the print list."
	},
	printListPrint: {
		nl: "Print het overzicht",
		en: "Print the list"
	},
	init: function () {
		//printoverview: link in searchmenu
		this.poc = $('printoverviewcontainer');
		if (this.poc) {
			this.poclink = this.poc.down('a');
			if (this.poclink) {
				this.pochref = this.poclink.getAttribute('href');
				this.poctitle = this.poclink.getAttribute('title');
				this.poclink.update(this.printlistOverview[paginaTaal] + " (" + this.poctitle + ")").addClassName('visible');
				this.poclink.setAttribute('title',this.poctitle + " item(s)");
			}
		}

		//printoverview: add link in footer
		this.po = $('printoverview');
		if (this.po) {
			this.polink = this.po.down('a');
			if (this.polink) {
				this.pohref = this.polink.getAttribute('href');
				this.polink.update(this.printlistAdd[paginaTaal]).addClassName('visible');
				this.polink.onclick = function () {
					printOverview.executePrint(this.pohref);
					return false;
				}.bind(this);
			}
		}

		//printoverview: remove links on overviewpage
		this.por = $('printoverviewlinks');
		if (this.por) {
			this.porlinks = this.por.select('li');
			if (this.porlinks && this.porlinks.length > 0){
				for (var i = 0; i < this.porlinks.length; i++) {
					var porlink = $(this.porlinks[i]).down('span').down('a');
					porlink.onclick = function() {
						return false;
					}
					var porlinkimage = porlink.down('img');
					porlinkimage.setAttribute('ahref',porlink.href);
					Event.observe(porlinkimage, "click", this.removeItem.bindAsEventListener(this), false);
				}
			}
		}
		this.porall = $('printoverviewremoveall');
		if (this.porall) {
			this.poralllink = this.porall.down('a');
			if (this.poralllink) {
				this.porallhref = this.poralllink.getAttribute('href');
				this.poralllink.update(this.printlistRemoveAll[paginaTaal]);
				this.poralllink.onclick = function () {
					printOverview.executePrint(this.porallhref);
					return false;
				}.bind(this);
			}
		}

		//printoverviewintro
		this.poi = $('printoverviewintro');
		if (this.poi) {
			if (!this.por) {
				this.poi.update(this.printListIntroEmpty[paginaTaal]);
			} else {
				this.poi.update(this.printListIntro[paginaTaal]);
			}
		}

		//printoverviewprint
		this.pop = $('printoverviewprint');
		if (this.pop) {
			this.poplink = this.pop.down('a');
			if (this.poplink) {
				this.poplink.update(this.printListPrint[paginaTaal]);
			}
		}
	},
	removeItem: function(e) {
		var el = Event.element(e);
		printOverview.executePrint(el.getAttribute("ahref"));
	},
	executePrint: function (sUrl) {
		sendRequest(sUrl + '&lang=' + paginaTaal,this.updateOverview.bind(this));
	},
	updateOverview: function (req) {
		var response = req.responseText.evalJSON(true);
		this.poclink.update(this.printlistOverview[paginaTaal] + " (" + response["printlistcount"] + ")");
		if (response["duplicates"]) {
			alert(this.printlistDuplicates[paginaTaal]);
		} else if (response["filelimitexceeded"]) {
			alert(this.printlistFilelimit[paginaTaal]);
		} else if (response["mode"] == 1) {
			alert(this.printlistAdded[paginaTaal]);
		} else if (response["mode"] == 2) {
			var printids = response["printids"];
			for (var i = 0; i < printids.length; i++) {
				if ($('print' + printids[i])) {
					$('print' + printids[i]).remove();
					alert(this.printlistRemoved[paginaTaal]);
				}
			}
		} else if (response["mode"] == 3) {
			alert(this.printlistRemovedAll[paginaTaal]);
		}

		if (this.poi && this.por && this.pop && this.porall && response["printlistcount"] == 0) {
			this.por.remove();
			this.porall.remove();
			this.pop.remove();
			this.poi.update(this.printListIntroEmpty[paginaTaal]);
		}
	}
}

var gaTerugLink = {
	tekst: {
		nl: "Ga terug",
		en: "Go back"
	},
	init: function () {
		var writeroot = document.getElementById('gateruglink');
		if (!writeroot) return;
		var link = document.createElement('a');
		link.href = '#';
		link.appendChild(document.createTextNode(writeroot.title ? writeroot.title : this.tekst[paginaTaal]));
		link.onclick = function () {
			window.history.go(-1);
			return false;
		}
		writeroot.appendChild(link);
	}
}

var stuurdoor = {
	writeroot: undefined,
	init: function () {
		var link = $('stuurdoor');
		this.writeroot = $('stuurdoorFormulier');
		if (!link || !this.writeroot) return;
		link.onclick = function() {stuurdoor.haalFormulier(link.getAttribute('href') + '&doc=nohtml'); return false};
	},
	haalFormulier: function (sUrl) {
		sendRequest(sUrl,this.toonFormulier);
	},
	toonFormulier: function (req) {
		stuurdoor.writeroot.update(req.responseText);
		popups.initPopups(stuurdoor.writeroot);
	}
}

var popups = {
	standaardBreedte: 800,
	standaardHoogte: 600,
	waarschuwingTekst: {
		nl: '(opent in popup)',
		en: '(opens in popup)'
	},
	init: function () {
		this.initPopups(document);
	},
	initPopups: function (obj) {
		var x = obj.getElementsByTagName('a');
		for (var i=0;i<x.length;i++) {
			if (x[i].getAttribute('rel') && x[i].getAttribute('rel').indexOf('popup') != -1) {
				x[i].firstChild.nodeValue += ' ' + this.waarschuwingTekst[paginaTaal];
				x[i].onclick = function(){popups.openPopup(this); return false};
			}
		}
	},
	openPopup: function (link) {
		var breedte = this.standaardBreedte;
		var hoogte = this.standaardHoogte;
		var data = link.getAttribute('rel').split(';');
		if (data.length == 3) {
			breedte = data[1];
			hoogte = data[2];
		}
		window.open(link.href,'popup','width='+breedte+',height='+hoogte+',resizable=yes,scrollbars=yes');
	}
}

var bloklinks = {
	speciaal: ['extern','anker','download'],
	init: function () {
		var lists = document.getElementsByTagName('li');
		for (var i=0;i<lists.length;i++) {
			if (lists[i].className.indexOf('bloklink') == -1) continue;
			var ul = lists[i].parentNode;
			if (!ul.gedaan) {
				ul.className += ' js-aan';
				ul.gedaan = true;
			}
			var classes = lists[i].className;
			var classesHover = classes + ' over';
			for (var j=0;j<this.speciaal.length;j++) {
				if (classes.indexOf(this.speciaal[j]) != -1) {
					classesHover = classes.replace(this.speciaal[j],this.speciaal[j]+'Over');
					break;
				}
			}
			lists[i].origClass = classes;
			lists[i].hoverClass = classesHover;
			lists[i].onmouseover = function () {
				this.className = this.hoverClass;
			}
			lists[i].onmouseout = function () {
				this.className = this.origClass;
			}

			lists[i].onclick = function () {
				//Use onclick code if available, otherwise, use the href
				if(this.getElementsByTagName('a')[0].onclick){
					this.getElementsByTagName('a')[0].onclick();

					var pdfOnclick = this.getElementsByTagName('a')[0].getAttribute("onclick");
					if (pdfOnclick.indexOf("dcsMultiTrack") > -1) {

						var href = this.getElementsByTagName('a')[0].href;
						location.href = href;
					}
				}else{
					var href = this.getElementsByTagName('a')[0].href;
					location.href = href;
				}
				return false;
			}
		}
	}
}

var thematabbladlinks = {
	speciaal: ['extern','anker','download'],
	init: function () {
		var lists = document.getElementsByTagName('span');
		for (var i=0;i<lists.length;i++) {
			if (lists[i].className.indexOf('thematabbladlink') == -1) continue;

			var classes = lists[i].className;

			var classesHover = classes + ' over';

			lists[i].onmouseover = function () {
				lists[i].className = classesHover;
			}
			lists[i].onmouseout = function () {
				lists[i].className = classes;
			}
		}
	}
}
/*<CCUSTOM>
 * New poll results based on classname rather than an id
 */
var pollresultaten = {
	factor: undefined,
	init: function () {
		var uls = document.getElementsByTagName('ul');
		for(var j=0; j<uls.length; j++) {
			var classNames = uls[j].className.split(' ');
			for(var k=0; k<classNames.length; k++) {
				if(classNames[k] == 'poll-res') {
					var writeroot = uls[j];
					if (!writeroot) return;
					var items = writeroot.getElementsByTagName('li');
					for (var i=0;i<items.length;i++) {
						var spans = items[i].getElementsByTagName('span');
						if (!spans.length) continue;
						var staaf = spans[0];
						if (!this.factor)
							this.factor = staaf.offsetWidth/100;
						var percentage = parseInt(spans[1].firstChild.nodeValue);
						var innerSpan = document.createElement('span');
						innerSpan.style.width = percentage * this.factor + 'px';
						staaf.appendChild(innerSpan);
					}
					break;
				}
			}
		}
	}
}
/*</CCUSTOM>*/

var zoomPhotos = {
	vergrootTekst: {
		nl: '<span>Vergroten</span>',
		en: '<span>Enlarge</span>'
	},
	verkleinTekst: {
		nl: '<span>Verkleinen</span>',
		en: '<span>Reduce</span>'
	},
	minimumMarge: 180,
	init: function () {
		var x = document.getElementsByTagName('div');
		for (var i=0;i<x.length;i++) {
			if (x[i].className.indexOf('zoom') != -1) {
				var link = x[i].getElementsByTagName('a')[0];
				link.normalPhoto = link.getElementsByTagName('img')[0];
				link.onclick = zoomPhotos.zoom;
				var tekst = link.getElementsByTagName('span')[0];
				tekst.replaceChild = this.vergrootTekst[paginaTaal];
			}
		}
	},
	zoom: function () {
		if (!this.zoomedPhoto) {
			this.zoomedPhoto = zoomPhotos.createImg(this.href, this.normalPhoto.alt, this.normalPhoto.title);
			this.zoomedPhoto.className = 'zoomPhoto';
			this.insertBefore(this.zoomedPhoto,this.normalPhoto);
		}
		this.normalPhoto.style.display = 'none';
		this.zoomedPhoto.style.display = 'block';
		var span = this.getElementsByTagName('span')[0];
		span.originalText = span.firstChild.nodeValue;
		span.className = 'zoomout';
		span.replaceChild = zoomPhotos.verkleinTekst[paginaTaal];
		var zoomPhoto = this.zoomedPhoto;
		if (!zoomPhoto.width) {
			var breedteMeting = setInterval(function () {
				if (zoomPhoto.width > 0) {
					zoomPhotos.sizeContent(zoomPhoto);
					clearInterval(breedteMeting);
				}
			},250);
		}
		else
			zoomPhotos.sizeContent(zoomPhoto);
		this.onclick = zoomPhotos.unzoom;
		return false;
	},
	unzoom: function () {
		this.normalPhoto.style.display = 'block';
		this.zoomedPhoto.style.display = 'none';
		this.onclick = zoomPhotos.zoom;
		var span = this.getElementsByTagName('span')[0];
		span.className = 'zoomin';
		span.replaceChild = span.originalText;
		var zoomContainer = this.normalPhoto.parentNode.parentNode;
		zoomContainer.style.marginRight = '';
		return false;
	},
	createImg: function (source, alt, title) {
		var newImage = document.createElement('img');
		newImage.src = source;
		newImage.alt = alt;
		newImage.title = title;
		return newImage;
	},
	sizeContent: function (obj) { // obj is img.zoomPhoto, wiens parentNode de link is
		var fotoBreedte = obj.width;
		var zoomContainer = obj.parentNode.parentNode; // div.zoom
		var contentVlak = zoomContainer.parentNode; // container van div.zoom
		var totaleBreedte = contentVlak.offsetWidth;
		var verschil = totaleBreedte - fotoBreedte;
		if (verschil < this.minimumMarge) {
			if (verschil > 0)
				zoomContainer.style.marginRight = verschil + 'px';
		}
	}
}

var RSSFeed = {
	RSSReadroot: undefined,
	RSSWriteroot: undefined,
	RSSURL: 'http://www.rekenkamer.nl/rss/',
	init: function () {
		this.RSSReadroot = document.getElementById('rss');
		if (!this.RSSReadroot) return;
		this.RSSReadroot.onclick = this.create;
		this.RSSWriteroot = document.getElementById('rss-url');
		this.RSSReadroot.elements[this.RSSReadroot.elements.length-1].style.display = 'none';
		this.RSSReadroot.onclick();
	},

	create: function () {
		var x = this.elements;
		var aanvinkFlag = false;
		var RSSString = RSSFeed.RSSURL;
		for (var i=0;i<x.length;i++) {
			if (x[i].type != 'checkbox') continue;
			if (!x[i].checked) continue;
			RSSString += x[i].name + '/';
			aanvinkFlag = true;
		}
		if (!aanvinkFlag) {
			RSSFeed.RSSWriteroot.style.display = 'none';
			return;
		}
		else
			RSSFeed.RSSWriteroot.style.display = 'block';
		if (!this.writeroot)
			RSSFeed.container(RSSString);
		else
			this.writeroot.href = this.writeroot.replaceChild = RSSString;
	},
	container: function(linkText) {
		var par = document.createElement('p');
		par.appendChild(document.createTextNode('Uw gegenereerde URL is:'));
		var span = document.createElement('span');
		var link = document.createElement('a');
		link.href = link.replaceChild = linkText;
		span.appendChild(link);
		par.appendChild(span);
		this.RSSWriteroot.appendChild(par);
		this.RSSReadroot.writeroot = link;
	}
}

var faqLijst = {
	init: function () {
		var x = document.getElementById('faqlijst');
		if (!x) return;
		var items = x.getElementsByTagName('li');
		for (var i=0;i<items.length;i++) {
			items[i].onclick = this.toggle;
			items[i].onmouseover = function () {
				this.moStatus = 'Over';
				faqLijst.changeClass(this);
			}
			items[i].onmouseout = function () {
				this.moStatus = '';
				faqLijst.changeClass(this);
			}
			items[i].originalClass = items[i].className;
			items[i].className += ' dicht';
			items[i].status = 'dicht';
		}
	},
	toggle: function () {
		this.status = (this.status == 'dicht') ? 'open' : 'dicht';
		faqLijst.changeClass(this);
	},
	changeClass: function (obj) {
		obj.className = obj.originalClass + ' ' + obj.status + obj.moStatus;
	}
}

/* Tabbladen op de onderzoekpagina */
var onderzoekentabs = {
	init: function() {
		if((a = document.getElementById('onderzoekentabs'))) {
				 var arNewButtons = new Array;
			    var togglerElements = document.getElementById('onderzoekentabs').getElementsByTagName('div');
				 var buttonsTemp = "";
				 var currenttabnr = 1;
				 if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
					 var ieversion=new Number(RegExp.$1); // capture x.x portion and store as a number
				 }
			    for (var i = 1; i < togglerElements.length + 1; i++) {
			       var togglerElement = togglerElements[i-1];
				    if (togglerElement.className == 'tabbladlink') {
							togglerElement.style.display = 'none';
							var divWidth = "";
							var	tabindextouse = " tabindex=\"" + togglerElement.getElementsByTagName('span')[0].innerHTML + "\"";
							if(ieversion==6) {divWidth = "style=\"width:" + (togglerElement.firstChild.nodeValue.length * 7) + "px;\"";}; /*inline styling voor IE6*/
							buttonsTemp = buttonsTemp + "<span " + divWidth + tabindextouse + " class=\"tabbladlink\" id=\"tabbladlink" + currenttabnr + "\" onmouseover=\"selectOnderzoekTabMouseOver(" + currenttabnr + ")\" onmouseout=\"selectOnderzoekTabMouseOut(" + currenttabnr + ")\" onKeyPress=\"selectOnderzoekTab(" + currenttabnr + ")\" onclick=\"selectOnderzoekTab(" + currenttabnr + ")\">" + togglerElement.firstChild.nodeValue + "</span>";
							currenttabnr++;
					}
			    }
				 $('tabbuttons').update(buttonsTemp);
				 selectOnderzoekTab(1);
		}
	}
}

function selectOnderzoekTab(tabnr) {
   var togglerElements = document.getElementById('tabbuttons').getElementsByTagName('span');
	for (var i = 1; i < togglerElements.length + 1; i++) {togglerElements[i-1].className = 'tabbladlink';}
	togglerElements = document.getElementById('onderzoekentabs').getElementsByTagName('div');
	for (var i = 0; i < togglerElements.length; i++) {
	     var togglerElement = togglerElements[i];
	     if ((togglerElement.className == 'statuscontent')) {togglerElement.style.display = 'none';}
	}
	document.getElementById('tabblad' + tabnr).style.display = 'block';
	document.getElementById('tabbladlink' + tabnr).className = 'tabbladlinkselected';
}

function selectOnderzoekTabMouseOver(tabnr) {
	document.getElementById('tabbladlink' + tabnr).className = 'tabbladlinkselected';
}
function selectOnderzoekTabMouseOut(tabnr) {
	if (document.getElementById('tabblad' + tabnr).style.display != 'block'){
	document.getElementById('tabbladlink' + tabnr).className = 'tabbladlink';
	}
}

/* THEMAS TABS */
var thematabs = {
	init: function() {

		if((a = document.getElementById('thematabs'))) {
				 document.getElementById('thematabs').className="";
				 document.getElementById('nieuwsthemas').className="nieuws-home";
				 var arNewButtons = new Array;
			    var togglerElements = document.getElementById('thematabs').getElementsByTagName('span');
				 var buttonsTemp = "";
				 var currenttabnr = 1;
				 var currenttabindexnr = 1;
				 if((test = document.getElementById('menuindexused'))) {currenttabindexnr = $('menuindexused').firstChild.nodeValue + 1 }
			    for (var i = 1; i < togglerElements.length + 1; i++) {
			      var togglerElement = togglerElements[i-1];
				    if (togglerElement.className == 'thematabbladlink') {
							togglerElement.style.display = 'none';
							var tabindextouse = togglerElement.getElementsByTagName('span')[0].innerHTML;
					    buttonsTemp = buttonsTemp + "<span tabindex=\"" + tabindextouse + "\" onmouseover=\"selectThemaTabMouseOver(" + currenttabnr + ")\" onmouseout=\"selectThemaTabMouseOut(" + currenttabnr + ")\" class=\"thematabbladlink\" id=\"thematabbladlink" + currenttabnr + "\" onKeyPress=\"selectThemaTab(" + currenttabnr + ")\" onclick=\"selectThemaTab(" + currenttabnr + ")\">" + togglerElement.firstChild.nodeValue + "</span>";
							currenttabnr++;
				 	  }
			    }
				 $('thematabbuttons').update(buttonsTemp);
				 selectThemaTab(1);
		}
	}
}

function selectThemaTab(tabnr) {
   var togglerElements = document.getElementById('thematabbuttons').getElementsByTagName('span');
	for (var i = 1; i < togglerElements.length + 1; i++) {togglerElements[i-1].className = 'thematabbladlink';}
	togglerElements = document.getElementById('thematabs').getElementsByTagName('div');
	for (var i = 0; i < togglerElements.length; i++) {
	     var togglerElement = togglerElements[i];
	     if ((togglerElement.className == 'statuscontent')) {togglerElement.style.display = 'none';}
	}
	document.getElementById('thematabblad' + tabnr).style.display = 'block';
	document.getElementById('thematabbladlink' + tabnr).className = 'thematabbladlinkselected';

	//document.getElementById('thematabblad' + tabnr).style.position = 'relative';
	//document.getElementById('thematabcontent' + tabnr).className = 'absolute';
	//document.getElementById('thematabcontent' + tabnr).style.top = '70px';
}

function selectThemaTabMouseOver(tabnr) {

	document.getElementById('thematabbladlink' + tabnr).className = 'thematabbladlinkselected';
}
function selectThemaTabMouseOut(tabnr) {
	if (document.getElementById('thematabblad' + tabnr).style.display != 'block'){
	document.getElementById('thematabbladlink' + tabnr).className = 'thematabbladlink';
	}
}

function showhideFilters() {
	var checkElement = document.getElementById('informatietype');
	if(checkElement.value=="onderzoek"){
		document.getElementById('departmentfilter').style.display = 'inline';
		document.getElementById('department').style.display = 'inline';
		document.getElementById('kamercommissiefilter').style.display = 'inline';
		document.getElementById('kamercommissie').style.display = 'inline';
	} else {
		document.getElementById('departmentfilter').style.display = 'none';
		document.getElementById('department').style.display = 'none';
		document.getElementById('kamercommissiefilter').style.display = 'none';
		document.getElementById('kamercommissie').style.display = 'none';
	}


}

/*homepagemarqueee*/
var homepagemarquee = {
	init: function() {

		if((a = document.getElementById('homepagegallery'))) {
				 var e, i = 0;
				while (e = document.getElementById('homepagegallery').getElementsByTagName ('dt') [i++]) {
					if (e.className == 'switch') {
					e.onclick = function () {
							var getEls = document.getElementById('homepagegallery').getElementsByTagName('dd');
							for (var z=0; z<getEls.length; z++) {
							getEls[z].className=getEls[z].className.replace('show', 'hide');
							w=getEls[z].previousSibling;
							while (w.nodeType!=1) {
								w=w.previousSibling;
								}
							w.className=w.className.replace('switchover', 'switch');
							w.className=w.className.replace('switch off', 'switchover');
							}
						this.className = this.className == 'switch' ? 'switchover' : 'switch off';
						x=this.nextSibling;
						while (x.nodeType!=1) {
							x=x.nextSibling;
							}
						x.className = this.className == 'switchover' ? 'show' : 'hide';
						}
					}
				}
		}
	}
}

/*<CCUSTOM>
/* reageer blok weblog */
function openklapperForms(openklaplink,ankerlocatie,openteklappenelement,classnaam) {
	// bestaat de link?
	var pk = document.getElementById(openklaplink);
	var otke = document.getElementById(openteklappenelement);
	if (!pk || !otke) {
		return false;
	}
	else {
		//het reageren blok openen als de reactie wordt aangepast.	(#reageren staat in de url)
		var strHref = window.location.href;
		if ( strHref.indexOf(ankerlocatie) > -1 )
		{
			document.getElementById(openteklappenelement).style.display = 'block';
			pk.getElementsByTagName("a")[0].className = "open";
		}
		else
		{
			document.getElementById(openteklappenelement).style.display = 'none';
		}

		// verberg of toon formulier
		pk.onclick = function () {
			var fieldset = document.getElementById(openteklappenelement)
			if (fieldset.style.display == 'block') {
				fieldset.style.display = 'none';
				pk.getElementsByTagName("a")[0].removeAttribute('class')
				pk.getElementsByTagName("a")[0].href="#top";
			} else {
				fieldset.style.display = 'block';
				pk.getElementsByTagName("a")[0].className = classnaam;
				pk.getElementsByTagName("a")[0].href=ankerlocatie;
			}
		}
	}
}
/* toggle CC-adres voor stuurdoor */
function toggleCC() {
	var checkId = 'taf_kopie';
	var fromAddress = 'fromaddress';
	var ccAddress = 'taf_cc';
	if (document.getElementById(checkId).checked) {
		document.getElementById(ccAddress).value = document.getElementById(fromAddress).value;
	} else {
		document.getElementById(ccAddress).value = "";
	}
}

/* toggle all checkboxes voor SMS en e-mail attenderingen */
function toggleCheckBoxAll(checkBoxObj, toggleAllId) {
	var toggleCheckBox = document.getElementById(toggleAllId);
	if (!checkBoxObj.checked && toggleCheckBox.checked) {
		toggleCheckBox.checked = false;
	}
}

function toggleCheckBoxes(toggleAllObj, containerId, matchField) {
	var container = document.getElementById(containerId);
	var inputs = container.getElementsByTagName('input');
	for (i = 0; i < inputs.length; i++) {
  		if (inputs[i].type == 'checkbox' && inputs[i].id != toggleAllObj.id && inputs[i].name == matchField) {
      			inputs[i].checked = toggleAllObj.checked;
      		}
	}
}

/* AUTODOWNLOAD */
var g_downloadNotClicked;
var autodownload = {
	init: function() {
		if(a = document.getElementById('autodownload')) {
			var linkElement = document.getElementById('autodownloadlink');
			var divAutodownload = document.getElementById('autodownload');
			var divAutodownloadDesc = document.getElementById('autodownloaddescription');
			g_downloadNotClicked = true;
			divAutodownloadDesc.style.display = "block";
			divAutodownload.innerHTML = "<br/><span>Uw download opent automatisch over </span><span id=\"autodownloadcountdown\">5</span><span> seconden</span>" + "<a id=\"autodownloadlink\" href=\"" + linkElement.href + "\" onclick=\"stopDownload();\"><h2>Klik hier om het bestand direct te downloaden.</h2></a>"
			startDownload(5);
			$(document).observe('keydown', function(k){if (k.keyCode == 27) stopDownload("nl")});
		}
		if(a = document.getElementById('autodownload_en')) {
			var linkElement = document.getElementById('autodownloadlink');
			var divAutodownload = document.getElementById('autodownload_en');
			var divAutodownloadDesc = document.getElementById('autodownloaddescription');
			g_downloadNotClicked = true;
			divAutodownloadDesc.style.display = "block";
			divAutodownload.innerHTML = "<br/><span>Your download will open automatically in </span><span id=\"autodownloadcountdown\">5</span><span> seconds</span>" + "<a id=\"autodownloadlink\" href=\"" + linkElement.href + "\" onclick=\"stopDownload();\"><h2>Click here to download the file directly.</h2></a>"
			startDownload(5);
			$(document).observe('keydown', function(k){if (k.keyCode == 27) stopDownload("en")});
		}
	}
}

function stopDownload(blnEscaped){
	document.getElementById('autodownloadcountdown').innerHTML = "0";
	g_downloadNotClicked = false;
	if(blnEscaped=="nl") document.getElementById('autodownload').innerHTML = "<br/><span>Automatisch downloaden is afgebroken.</span>" + "<h2><a id=\"autodownloadlink\" href=\"" + document.getElementById('autodownloadlink').href + "\" onclick=\"stopDownload();\">Klik hier om het bestand direct te downloaden.</a></h2>";
	if(blnEscaped=="en") document.getElementById('autodownload').innerHTML = "<br/><span>Automatic download aborted.</span>" + "<h2><a id=\"autodownloadlink\" href=\"" + document.getElementById('autodownloadlink').href + "\" onclick=\"stopDownload();\">Click here to download the file directly.</a></h2>";
}

function startDownload(iCountdown){
	if(g_downloadNotClicked){
		var iNewCountdown = iCountdown - 1;
		var divAutodownloadCounter = document.getElementById('autodownloadcountdown');
		divAutodownloadCounter.innerHTML = iNewCountdown;
		if(iNewCountdown == 0){
			location.replace(document.getElementById('autodownloadlink').href);
		}
		else{
			setTimeout("if(" + g_downloadNotClicked + "){startDownload(" + iNewCountdown + ")};",1000);
		}
	}
}
/*</CCUSTOM>*/

/* INITIALISATIE
	aangeroepen door DOMContentReady
*/

var inits = [
	'tekstGrootte',
	'printLink',
	'printOverview',
	'popups',
	'bloklinks',
	'thematabbladlinks',
	'pollresultaten',
	'zoomPhotos',
	'RSSFeed',
	'faqLijst',
	'stuurdoor',
	'gaTerugLink',
	'lowLightbox',
	'onderzoekentabs',
	'thematabs',
	'homepagemarquee',
	'autodownload'
];

function initializeAll() {
	paginaTaal = document.documentElement.lang || 'nl';
	for (var i=0;i<inits.length;i++) {
		if (window[inits[i]])
			window[inits[i]].init();
	}
	openklapperForms("reageerKnopRegister","#reageren","reageerweblogformulier","open");
	openklapperForms("voorkeuropenlink","#persoonlijkevoorkeuren","persoonlijkevoorkeuren","open");
}

/* UTILITIES */

function listify(dataArray) {
	var x = document.createElement('ul');
	for (var i=0;i<dataArray.length;i++) {
		var y = document.createElement('li');
		y.appendChild(dataArray[i]);
		x.appendChild(y);
	}
	return x;
}

function sendRequest(url,callback,postData) {
	var req = createXMLHTTPObject();
	if (!req) return;
	var method = (postData) ? "POST" : "GET";
	req.open(method,url,true);
	req.setRequestHeader('User-Agent','XMLHTTP/1.0');
	if (postData)
		req.setRequestHeader('Content-type','application/x-www-form-urlencoded');
		req.onreadystatechange = function () {
		if (req.readyState != 4) return;
		if (req.status != 200 && req.status != 304) {
			// alert('HTTP error ' + req.status);
			callback(req.status);
			return;
		}
		callback(req);
	}
	if (req.readyState == 4) return;
	req.send(postData);
}

var XMLHttpFactories = [
	function () {return new XMLHttpRequest()},
	function () {return new ActiveXObject("Msxml2.XMLHTTP")},
	function () {return new ActiveXObject("Msxml3.XMLHTTP")},
	function () {return new ActiveXObject("Microsoft.XMLHTTP")},
];

function createXMLHTTPObject() {
	var xmlhttp = false;
	for (var i=0;i<XMLHttpFactories.length;i++)
	{
		try {
			xmlhttp = XMLHttpFactories[i]();
		}
		catch (e) {
			continue;
		}
		break;
	}
	return xmlhttp;
}

// 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
}

// The .bind method from Prototype.js
if (typeof Function.prototype.bind == "undefined") {
	Function.prototype.bind = function(){
		var fn = this, args = Array.prototype.slice.call(arguments), object = args.shift();
		return function(){
			return fn.apply(object, args.concat(Array.prototype.slice.call(arguments)));
		};
	};
}

// IE check
if (window.ActiveXObject) window.ie = window[window.XMLHttpRequest ? 'ie7' : 'ie6'] = true;


/* COOKIES */

var Cookies = {
	init: function () {
		var allCookies = document.cookie.split('; ');
		for (var i=0;i<allCookies.length;i++) {
			var cookiePair = allCookies[i].split('=');
			this[cookiePair[0]] = cookiePair[1];
		}
	},
	create: function (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=/";
		this[name] = value;
	},
	erase: function (name) {
		this.create(name,'',-1);
		this[name] = undefined;
	},
	eraseAll: function () {
		for (var i in this) {
			if (typeof this[i] == 'function') continue;
			this.erase(i);
		}
	}
};
Cookies.init();

/* DOMCONTENTREADY */

function ContentReady() {
	// quit if this function has already been called
	if (arguments.callee.done) return;

	// flag this function so we don't do the same thing twice
	arguments.callee.done = true;

	// kill the timer
	if (_timer) clearInterval(_timer);

	// do stuff
	initializeAll();
};

/* for Mozilla/Opera9 */
if (document.addEventListener) {
	document.addEventListener("DOMContentLoaded", ContentReady, false);
}

/* for Internet Explorer */
/*@cc_on @*/
/*@if (@_win32)
	document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
	var script = document.getElementById("__ie_onload");
	script.onreadystatechange = function() {
		if (this.readyState == "complete") {
			ContentReady(); // call the onload handler
		}
	};
/*@end @*/

/* for Safari */
if (/WebKit/i.test(navigator.userAgent)) { // sniff
	var _timer = setInterval(function() {
		if (/loaded|complete/.test(document.readyState)) {
			ContentReady(); // call the onload handler
		}
	}, 10);
}

/* for other browsers */
window.onload = ContentReady;
