function toggle_menu(menuid) {
	
	document.getElementById('submenustart').style.display = 'none';
	document.getElementById('submenuvgsd').style.display = 'none';
	document.getElementById('submenucommissies').style.display = 'none';
	document.getElementById('submenuforum').style.display = 'none';
	
	document.getElementById('hmenu_start').childNodes[0].style.backgroundImage = 'url(/blokken/images/hmenu_start.gif)';
	document.getElementById('hmenu_vgsd').childNodes[0].style.backgroundImage = 'url(/blokken/images/hmenu_vgsd.gif)';
	document.getElementById('hmenu_commissies').childNodes[0].style.backgroundImage = 'url(/blokken/images/hmenu_commissies.gif)';
	document.getElementById('hmenu_forum').childNodes[0].style.backgroundImage = 'url(/blokken/images/hmenu_forum.gif)';
	
	document.getElementById('submenu'+menuid).style.display = 'inline';	
	document.getElementById('hmenu_'+menuid).childNodes[0].style.backgroundImage = 'url(/blokken/images/hmenu_'+menuid+'_active.gif)';
}

function triggerNext(offset, velden)
{
	var arr = new Array();
	arr = velden.split(',');
	for (var i=0; i<arr.length; i++)
	{
		var l=document.getElementById('mytable').rows.length;
		var x=document.getElementById('mytable').insertRow(l);
		var y=x.insertCell(0);
		var z=x.insertCell(1);
		y.innerHTML=arr[i];
		z.innerHTML="<input id='"+arr[i]+"' type='text' name='"+arr[i]+"' />";
	}
}

function toggle(el, els)
{
	arr = els.split(',');
	for (var i=0; i<arr.length; i++)
	{
		document.getElementById(arr[i]).style.display = 'none';
	}
	document.getElementById(el).style.display = 'inline';
}

function addKolom(velden, id)
{
	var arr = new Array();
	arr = velden.split(',');
	for (var i=0; i<arr.length; i++)
	{
		var l=document.getElementById('kolomtable').rows.length;
		var x=document.getElementById('kolomtable').insertRow(l);
		id2 = ( (l-i) / arr.length) + 1;
		var y=x.insertCell(0);
		var z=x.insertCell(1);
		y.innerHTML=arr[i] + "_" + id2;
		z.innerHTML="<input type='text' name='"+arr[i]+id2+"' />";
	}
}

function addKolomKeyDown(velden)
{
	var keynum;

	if(window.event) // IE
	{
	  keynum = e.keyCode;
	}
	else if(e.which) // Netscape/Firefox/Opera
	{
	  keynum = e.which;
	}
	
	alert(keynum);
}

function getXmlHttpObject()
{
 var xmlHttp;

 try
 {  // Firefox, Opera 8.0+, Safari  
    xmlHttp=new XMLHttpRequest();  
 }
 catch (e)
 {  // Internet Explorer  
    try
    {    
        xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    
    }
    catch (e)
    {    
        try
        {      
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");      
        }
        catch (e)
        {      
            alert("Your browser does not support AJAX!");      
            return false;      
        }    
    }  
 }
 
 return xmlHttp;
}

function changeSubmit(frm, actn)
{	
	document.getElementById(frm).action = actn;
	document.getElementById(frm).submit();
}

function showEdit(id, tabel, redirect, database)
{		
	if (database == null){
    	database = '';
 	}
 	redirect = redirect.replace(/^\//,'');
	
	el = document.getElementById('edit');
		
	if (el.style.display != 'block')
	{		
		var xmlHttp = getXmlHttpObject();
  
		xmlHttp.onreadystatechange=function()
		{
		  if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		  {          		  				  	  
		  	el.style.display = 'block';
		    el.style.height = 'auto';
		    el.style.top = (document.body.scrollTop + 100) + 'px';
		    var s = xmlHttp.responseText;		    
			el.innerHTML = s;			
		  }
		}		  			
		
		xmlHttp.open("GET","blokken/ajax/tabel.php?database="+database+"&tabel=" + tabel + "&id=" + id+ "&redirect=" +redirect+ "&sid="+Math.random(),true); 
		xmlHttp.send(null);
	} else {
		el.style.display = 'none';
	}	
}

function showEdit_stamboom(lid)
{		
	el = document.getElementById('edit');
	
	if (el.style.display != 'block') {		
		var xmlHttp = getXmlHttpObject();
		
		xmlHttp.onreadystatechange=function() {
			if( xmlHttp.readyState==4 ) {  				  	  	    
				el.innerHTML = xmlHttp.responseText.toString();
				el.style.display = 'block';	
			}
		}		
		
		xmlHttp.open("GET","blokken/ajax/stamboom.php?lid="+lid,true); 
		xmlHttp.send(null);
	} else {
		el.style.display = 'none';
	}	
}

function mailprotect(user,host,ext) {
	window.location.href='mailto:'+user+'@'+host+'.'+ext;
}

function disab(val)
{
	if(val=="1") {
		document.form1.select[0].checked=true;
		document.form1.newtitle.disabled=false;
		document.form1.bijschrift.disabled=false;
		document.form1.rx.disabled=true;
	}
	if(val=="2") {
		document.form1.select[1].checked=true;
		document.form1.newtitle.disabled=true;
		document.form1.bijschrift.disabled=true;
		document.form1.rx.disabled=false;
	}
}

function MultiSelector( list_target, max )
{
	this.list_target = list_target;
	this.count = 0;
	this.id = 0;
	if( max )
	{
		this.max = max;
	} else 
	{
		this.max = -1;
	};
	this.addElement = function( element )
	{
		if( element.tagName == 'INPUT' && element.type == 'file' )
		{
			this.id++;
			element.name = 'file[]'; 
			element.multi_selector = this;
			element.onchange = function()
			{
				var new_element = document.createElement( 'input' );
				new_element.type = 'file';
				this.parentNode.insertBefore( new_element, this );
				this.multi_selector.addElement( new_element );
				this.multi_selector.addListRow( this );
				this.style.position = 'absolute';
				this.style.left = '-1000px';};
				if( this.max != -1 && this.count >= this.max )
				{
					element.disabled = true;
				};
				this.count++;
				this.current_element = element;
		} else 
		{
			alert( 'Error: not a file input element' );
		};
	};
	this.addListRow = function( element )
	{
		var new_row = document.createElement( 'div' );
		var new_row_button = document.createElement( 'input' );
		new_row_button.type = 'button';
		new_row_button.value = 'Delete';
		new_row.element = element;
		new_row_button.onclick= function()
		{
			this.parentNode.element.parentNode.removeChild( this.parentNode.element );
			this.parentNode.parentNode.removeChild( this.parentNode );
			this.parentNode.element.multi_selector.count--;
			this.parentNode.element.multi_selector.current_element.disabled = false;
			return false;
		};
		new_row.innerHTML = element.value;new_row.appendChild( new_row_button );
		this.list_target.appendChild( new_row );
	};
};

// Die functie hierboven is bah!
function fileSelectorPlus( AttachId, AttachFileSelector, maxAmount ) {
	
	if (!(this.outputE = document.getElementById(AttachId))) {
		throw new Error("Kon niet uitvoerElement niet vinden");
	}
	if (!(this.inputE = document.getElementById(AttachFileSelector))) {
		throw new Error("Kon niet invoerElement niet vinden");
	}
	this.maxAmount = (!maxAmount) ? false : maxAmount;
	this.useMulti = (typeof this.inputE.files != "undefined" && window.FileReader) ? true : false;
	
	if (this.useMulti) {
		var flist = this.inputE.files;
		var outputE = this.outputE;
		var changeFunction = function() {
			 for (var i = 0; i < flist.length; i++) {
 				var file = flist[i];
    			var imageType =  /image\/jpeg/;
    
    			if (!file.type.match(imageType)) {
      				continue;
    			}
    			if (file.size > 2097152) {
   					continue;
	   			}
    
			    var img = document.createElement("img");
			    img.classList.add("thumb");
			    img.file = file;
			    outputE.appendChild(img);
    
			    var reader = new FileReader();
			    reader.onload = (function(aImg) { return function(e) { aImg.src = e.target.result; }; })(img);
			    reader.readAsDataURL(file);
  			}
		};
	}
	else {
		var counter = 1;
		var amount = 0;
		var max = this.maxAmount;
		var outputE = this.outputE;
		var lel = this.inputE;
		var changeFunction = function() {
			// Make new button
			var nEl = document.createElement("input");
			nEl.type = "file";
			counter++;
			nEl.name = "file_" + counter;
			attachE(nEl,"change", changeFunction);
			nEl = this.parentNode.appendChild(nEl);
			amount++;
			if (max && amount == max) {
				nEl.disabled = true;
			}
			
			// Prepare output...
			this.style.display = "none";
			var li = document.createElement("div");
			var btn = document.createElement("a");
			btn.appendChild(document.createTextNode("Verwijderen"));
			li.appendChild(btn);
			li.appendChild(document.createTextNode(" " + this.value));
			li = outputE.appendChild(li);
			btn = li.firstChild;
			btn.linkedItem = this;
			attachE(btn, "click", function() {
				lel.disabled = false;
				amount--;
				this.linkedItem.parentNode.removeChild(this.linkedItem);
				this.parentNode.parentNode.removeChild(this.parentNode);
			});
			lel = nEl;
		};
	}
	attachE(this.inputE, "change", changeFunction);
}

function checkAanmelden ( form )
{
  if (form.voornaam.value == "") {
    alert( "Vul je voornaam in." );
    form.voornaam.focus();
    return false ;
  }
  if (form.init.value == "") {
    alert( "Vul je initialen in." );
    form.init.focus();
    return false ;
  }
  if (form.naam.value == "") {
    alert( "Vul je achternaam in." );
    form.naam.focus();
    return false ;
  }
  if (form.date.value == "") {
    alert( "Vul je geboortedatum in." );
    form.date.focus();
    return false ;
  }
  if (form.adres.value == "") {
    alert( "Vul je adres in." );
    form.adres.focus();
    return false ;
  }
  if (form.postcode.value == "") {
    alert( "Vul je postcode in." );
    form.postcode.focus();
    return false ;
  }
  if (form.plaats.value == "") {
    alert( "Vul je woonplaats in." );
    form.email.focus();
    return false ;
  }
  if (form.email.value == "") {
    alert( "Vul je emailadres in." );
    form.email.focus();
    return false ;
  }
  return true ;
}

function attachE(element, evnt, func) {
	if (window.addEventListener) {
		element.addEventListener(evnt,func,false);
	}
	else if (window.attachEvent) {
		element.attachEvent("on"+evnt,func);
	}
	else {
		throw new Error("Je browser is ronduit slecht. Doe een update...");
	}
};

function formrender(mode, count){
	var new_row = document.createElement( 'div' );
	if (mode = "radio") {
		this.id	= 0;
		var new_element = document.createElement( 'input' );
		new_element.type = 'text';
		new_element.name = 'radio_' + this.id++;
	};
	if (mode = "checkbox") {
		this.id	= 0;
	};
	if (mode = "text") {
		this.id	= 0;
	};
}

function noDefault(element) {
	if (element.defaultValue && element.defaultValue == element.value) {
		element.value = "";
	}
}

// Splashfoto functie..
//
// 2010 - Webbit der VGSD.
//
// Todo: incalculeren dat de afbeelding groter wordt dan de paginabreedte.
// Todo: lokale configuratie mogelijk maken. Nu is de configuarie altijd globaal.
// 
// Mogelijkerwijs, script ook nog minimaliseren, en documenteren.

splashFoto = (function() {

	var f = function(thumbImg, largeUrl , anker) {
	
		var nImg = document.createElement("img");
		
		var bW = thumbImg.width; 
		var bH = thumbImg.height;
	
		var timer = false;
		nImg.onload = function() {
			
			// Doe een aspectfit..
			var resizeX = (nImg.width || nImg.naturalWidth)> f.maxW;
			var resizeY = (nImg.height || nImg.naturalHeight)> f.maxH;
			var eW, eH;
			
			if (!resizeX && !resizeY) {
				eW = nImg.width;
				eH = nImg.height;
			}
			else if (resizeX && !resizeY) {
				eW = f.maxW;
				eH = nImg.height * (f.maxW / nImg.width);
			}
			else if (!resizeX && resizeY) {
				eW = nImg.width * (f.maxH / nImg.height);
				eH = f.maxH; 
			}
			else {
				// Dubbelfit
				if (nImg.width / nImg.height > f.maxW / f.maxH) {
					eW = f.maxW;
					eH = nImg.height * (f.maxW / nImg.width);
				}
				else {
					eW = nImg.width * (f.maxH / nImg.height);
					eH = f.maxH;
				}
			}
			
			nImg.width = bW;
			nImg.height = bH;
			
			// Draai zichtbaarheid om...
			this.style.visibility = "visible";
			thumbImg.style.visibility = "hidden";
			
			var p = 0;
			timer = window.setInterval(function() {
				p += (1000/f.fps) / f.aniLength;
				if (p >= 1) {
					nImg.width = eW;
					nImg.height = eH;
					nImg.style.marginLeft = ((eW-bW)/f.horF) + "px";
					nImg.style.marginTop = ((eH-bH)/f.verF) + "px";
					window.clearInterval(timer);
				}
				else {
					nImg.width = f.easingFunction(bW, eW, p);
					nImg.height = f.easingFunction(bH, eH, p);
					nImg.style.marginLeft = ((nImg.width-bW)/f.horF) + "px";
					nImg.style.marginTop = ((nImg.height-bH)/f.verF) + "px";
				}			
			},1000/f.fps);
		};
		
		nImg.style.position = "absolute";
		nImg.style.left = findPosX(thumbImg) + "px";
		nImg.style.top = findPosY(thumbImg) + "px";	
		nImg.style.display = "block";	
		
		
		nImg.style.visibility = "hidden";
		nImg.src = largeUrl;
		nImg.onmouseout = function() {
			nImg.onload = function(){};
			if (timer) {
				window.clearInterval(timer);
			}
			nImg.parentNode.removeChild(nImg);
			thumbImg.style.visibility = "visible";
			if (_last == nImg) {
				_last = null;
			}
		};
		
		// Hebben we een anker?
		if (!anker && thumbImg.parentNode.tagName.toLowerCase() == "a") {
			anker = thumbImg.parentNode;
		}
		if (anker) {
			nImg.onclick = function() {
				nImg.style.cursor = "pointer";
				location.href = nImg.href;
			}
		}
		
		nImg = thumbImg.parentNode.insertBefore(nImg,thumbImg);
		
		// Verwijder andere eventuele splashers.
		if (_last) {
			_last.onmouseout();
		}
		_last = nImg;
		
	};
	
	// Zorg dat er maar eentje gemaximaliseerd kan blijven, dus stel
	// een private variable in.
	var _last = null;
	
	// En dan nu de standaardconfiguratie.
	f.fps = 30;
	f.aniLength = 500;
	f.maxW = 500;
	f.maxH = 500;
	f.horF = -1;
	f.verF = -2;
	f.easingFunction = function(begin, end, p) { 
		var d = (end - begin);
		if (p<=.5) {
			return ((p*p*4)*d)/2 + begin;
		}
		else {
			p = 0.5-(p-0.5);
			return (1-(p*p*4))*d/2 + d/2 + begin;
		}
	};
	
	return f;
	
})();

function findPosX(obj)
{
	var curleft = 0;
	if(obj.offsetParent)
	    while(1) 
	    {
	      curleft += obj.offsetLeft;
	      if(!obj.offsetParent)
	        break;
	      obj = obj.offsetParent;
	    }
	else if(obj.x)
	    curleft += obj.x;
	    
	var screenLeft = (document.body.clientWidth - 950) / 2;
	return curleft - screenLeft;
}

function findPosY(obj)
{
	var curtop = 0;
	if(obj.offsetParent)
	    while(1)
	    {
	      curtop += obj.offsetTop;
	      if(!obj.offsetParent)
	        break;
	      obj = obj.offsetParent;
	    }
	else if(obj.y)
	    curtop += obj.y;
	    
	return curtop - 198 // Top;
}

// showPlaatje, inmiddels verouderd. Gebruik splashFoto in plaats hiervan.
function showPlaatje(el, plaatje, link)
{
	im = document.getElementById('plaatje');
	
	im.style.left = findPosX(el) + 'px';
	im.style.top = findPosY(el) + 'px';
	
	im.src = plaatje;
	im.style.display = 'block';	
	if (link != null) {
		im.style.cursor = 'pointer';
		im.onclick = function() {location.href = link; }
	}
}
