function CheckText(veld,veldnaam){

var tekst	=	veld.value;

	if(tekst == '' ){
		alert('Het veld ['+veldnaam+'] is niet correct ingevuld');
		veld.style.backgroundColor  = "#FAD3D5";
		veld.focus();
		return false;
		
	}else{
		veld.style.backgroundColor = "";
		return true;
		
	}
	
}
function CheckDropDown(veld,veldnaam){

	if(veld.options[veld.selectedIndex].value == ''){
		alert('Het veld ['+veldnaam+'] is niet correct ingevuld');
		veld.style.backgroundColor  = "#FAD3D5";	
		return false
	}else{
		veld.style.backgroundColor  = "";
		return true;
		
	}

	
}

function CheckGeboorteDatum(dag,maand,jaar){

var geboorte	=	true;

dag.style.backgroundColor  = "";
maand.style.backgroundColor  = "";
jaar.style.backgroundColor  = "";

	if(dag.options[dag.selectedIndex].value == ''){
		geboorte	=	false;	
		dag.style.backgroundColor  = "#FAD3D5";
	}else if(maand.options[maand.selectedIndex].value== ''){
		geboorte	=	false;
		maand.style.backgroundColor  = "#FAD3D5";
	}else if(jaar.options[jaar.selectedIndex].value== ''){
		geboorte	=	false;
		jaar.style.backgroundColor  = "#FAD3D5";
	}
	if(!geboorte){
		alert('Uw geboortedatum is nog niet correct ingevuld');	
	}
	return geboorte;
	
}

function trim(str) { 
     str = str.replace( /^\s+/g, "" ); // strip leading 
     str = str.replace( /\s+$/g, "" ); // strip trailing 

     return str; 
} 



function CheckEmail(veld,veldnaam) {

var str	=	trim(veld.value);

var result;
veld.style.backgroundColor  = "";
veld.focus();

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		    alert('Het veld ['+veldnaam+'] is niet correct ingevuld');
			veld.style.backgroundColor  = "#FAD3D5";
		     return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert('Het veld ['+veldnaam+'] is niet correct ingevuld');
		   veld.style.backgroundColor  = "#FAD3D5";
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert('Het veld ['+veldnaam+'] is niet correct ingevuld');
			veld.style.backgroundColor  = "#FAD3D5";
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert('Het veld ['+veldnaam+'] is niet correct ingevuld');
			veld.style.backgroundColor  = "#FAD3D5";
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert('Het veld ['+veldnaam+'] is niet correct ingevuld');
			veld.style.backgroundColor  = "#FAD3D5";
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert('Het veld ['+veldnaam+'] is niet correct ingevuld');
			veld.style.backgroundColor  = "#FAD3D5";
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert('Het veld ['+veldnaam+'] is niet correct ingevuld');
			veld.style.backgroundColor  = "#FAD3D5";
		    return false
		 }
		 

 		 return true					
	}


function CheckCheckbox(veld,bericht){
	
	if(veld.checked!=true){
		alert(bericht);
		veld.style.backgroundColor  = "#FAD3D5";
		return false;
		
	}else{
		veld.style.backgroundColor  = "";
		return true;
	}	
	
}

function CheckForm(){


var form	=	document.aanmelden;

var result = true;

result	=	CheckText(form.voornaam,'Voornaam');
if(result == true){
	result	=	CheckText(form.achternaam,'Achternaam');
}
if(result == true){
	result	=	CheckDropDown(form.geslacht,'Geslacht');
}
if(result == true){
	result	=	CheckGeboorteDatum(form.geboortedag,form.geboortemaand,form.geboortejaar);
}

if(result == true){
	result	=	CheckEmail(form.email,'E-mailadres');
}
if(result == true){
	result	=	CheckText(form.wachtwoord,'Wachtwoord');
}

if(result == true){
	result	=	CheckCheckbox(form.akkoord,'U moet nog akkoord gaan met het privacybeleid en\nen de algemene voorwaarden.');
}


	
	return result;

}
