function checkForm(form){
	removeError('fout');
	
	
	$("#email").css('border','1px solid #a7a6aa');
	$("#vnaam").css('border','1px solid #a7a6aa');
	$("#fnaam").css('border','1px solid #a7a6aa');
	$("#invoice_name").css('border','1px solid #a7a6aa');
	$("#invoice_address1").css('border','1px solid #a7a6aa');
	
	$('#nok1').css('display','none');
	$('#nok2').css('display','none');
	$('#nok3').css('display','none');
	$('#nok4').css('display','none');
	$('#nok5').css('display','none');
	$('#nok6').css('display','none');
	$('#nok7').css('display','none');
	$('#nok8').css('display','none');
	$('#nok9').css('display','none');
	
	$("#invoice_address2").css('border','1px solid #a7a6aa');
	$("#zip").css('border','1px solid #a7a6aa');
	$("#country").css('border','1px solid #a7a6aa');
	$("#city").css('border','1px solid #a7a6aa');
	
	var email = form.email.value;
	var fnaam = form.fnaam.value;
	var vnaam = form.vnaam.value;
	
	var returnvar = true;
	if(fnaam.length==0){
		fout="Lastname is required!";	
		newOne(fout,'fout');
		document.getElementById('fout').style.marginBottom="10px";
		$("#fnaam").css('border','1px solid red');
		$("#fnaam").focus();
		$("#nok1").css('display','inline');
		returnvar=false;
	}
	if(vnaam.length==0){
		fout="Firstname is required!";	
		newOne(fout,'fout');
		document.getElementById('fout').style.marginBottom="10px";
		$("#vnaam").css('border','1px solid red');
		$("#vnaam").focus();
		$("#nok2").css('display','inline');
		returnvar=false;
	}
	if(email.length!=0){
		// Controle op geldig emailadres
		if(!checkEmail(email)){
			fout="A valid email is required!";	
			newOne(fout,'fout');
			$("#email").css('border','1px solid red');
			$("#email").focus();
			$("#nok3").css('display','inline');
			document.getElementById('fout').style.marginBottom="10px";
			returnvar=false;
		}
	}
	else{
		fout="Email is required!";	
		newOne(fout,'fout');
		document.getElementById('fout').style.marginBottom="10px";
		$("#email").css('border','1px solid red');
		$("#email").focus();
		$("#nok3").css('display','inline');
		returnvar=false;
	}
	if(document.getElementById('radio3').checked){
		var name = form.invoice_name.value;
		var ad1 = form.invoice_address1.value;
		var ad2 = form.invoice_address2.value;
		var zip = form.invoice_zip.value;
		var city = form.invoice_city.value;
		var country = form.invoice_country.value;
		if(name.length==0){
			fout="Organisation name is required!";	
			newOne(fout,'fout');
			document.getElementById('fout').style.marginBottom="10px";
			$("#invoice_name").css('border','1px solid red');
			$("#invoice_name").focus();
			$("#nok4").css('display','inline');
			returnvar=false;
		}
		if(ad1.length==0){
			fout="Full address is required";	
			newOne(fout,'fout');
			document.getElementById('fout').style.marginBottom="10px";
			$("#invoice_address1").css('border','1px solid red');
			$("#invoice_address1").focus();
			$("#nok5").css('display','inline');
			returnvar=false;
		}
		if(ad2.length==0){
			fout="Full address is required";	
			newOne(fout,'fout');
			document.getElementById('fout').style.marginBottom="10px";
			$("#invoice_address2").css('border','1px solid red');
			$("#invoice_address2").focus();
			$("#nok6").css('display','inline');
			returnvar=false;
		}
		if(zip.length==0){
			fout="Zip/postal code is required";	
			newOne(fout,'fout');
			document.getElementById('fout').style.marginBottom="10px";
			$("#invoice_zip").css('border','1px solid red');
			$("#invoice_zip").focus();
			$("#nok7").css('display','inline');
			returnvar=false;
		}
		if(city.length==0){
			fout="City is required";	
			newOne(fout,'fout');
			document.getElementById('fout').style.marginBottom="10px";
			$("#invoice_city").css('border','1px solid red');
			$("#invoice_city").focus();
			$("#nok8").css('display','inline');
			returnvar=false;
		}
		if(country.length==0){
			fout="Country is required";	
			newOne(fout,'fout');
			document.getElementById('fout').style.marginBottom="10px";
			$("#invoice_country").css('border','1px solid red');
			$("#invoice_country").focus();
			$("#nok9").css('display','inline');
			returnvar=false;
		}	
	}
	if(returnvar){
		sendInschrijving(form);
	}
	return false;
}

/*  Controleren of het een geldig emailadres is
	
	@return false als het emailadres NIET klopt
	@return true als het emailadres overéénkomt met het patroon
	
*/
function checkEmail(email){
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
		if (filter.test(email)) return true;
		else return false;
}

/* Deze functie verwijderd de eerdere getoonde foutmeldingen */
function removeError(foutdiv){
	var foutdiv = document.getElementById(foutdiv);
	while(foutdiv.firstChild != null){
		foutdiv.removeChild(foutdiv.firstChild);
	}
}

/* Deze functie toont de specifieke foutmelding */
function newOne(fout,input){
	var newEl = document.createElement('p');
	var newTx = document.createTextNode(fout);
	newEl.appendChild(newTx);
	var newPara = document.getElementById(input);
	newPara.appendChild(newEl);
}




$(function()
	{
	
	$("#par1").click(function(event) {
	$("#div4").css("display","none");
	$("#div2").css("display","none");
	$("#div3").css("display","none");
	$("#div1").fadeIn(800);
	$("#div1").focus();
	$("#handeling").css("display","inline");
	$("#radio1").attr("checked","checked")
	});
	
	$("#par2").click(function(event) {
	$("#div4").css("display","none");
	$("#div1").css("display","none");
	$("#div3").css("display","none");
	$("#div2").fadeIn(800);
	$("#div2").focus();
	$("#handeling").css("display","inline");
	$("#radio2").attr("checked","checked")
	});
	
	$("#par3").click(function(event) {
	$("#div4").css("display","none");
	$("#div1").css("display","none");
	$("#div2").css("display","none");
	$("#div3").fadeIn(800);
	$("#div3").focus();
	$("#handeling").css("display","inline");
	$("#radio3").attr("checked","checked")
	});
	
	}
);
