function checkform() {
	var fields = new Array('voorletters','achternaam','straat','huisnummer','postcode','woonplaats','telefoonnummer','emailadres');
	var errors = new Array();
	var rege = /^([0-9]{1,4})/;
	if ($F('voorletters') == "") {
		errors.push('voorletters');
	}
	if ($F('achternaam') == "") {
		errors.push('achternaam');
	}
	if ($F('straat') == "") {
		errors.push('straat');
	}
	if (!rege.test($F('huisnummer'))) {
		errors.push('huisnummer');
	}
	if (!CheckPC()) {
		errors.push('postcode');
	}
	if ($F('woonplaats') == "") {
		errors.push('woonplaats');
	}
	if (!checkTelNumber()) {
		errors.push('telefoonnummer');
	}
	if (!checkEmail($F('emailadres'))) {
		errors.push('emailadres');
	}
	for(var i=0;i<fields.length;i++) {
		$(fields[i]).style.background = '#ffffff';
	}
	for(var i=0;i<errors.length;i++) {
		$(errors[i]).style.background = '#ffb09b';
	}
	$(errors[0]).focus();
	if (errors.length > 0) {
		alert("Controlleer a.u.b. de rood gekleurde velden");
		return false;
	}
	return true;
}

function checkfriend() {
	var fields = new Array('uw_naam','uw_emailadres','ont_naam','ont_emailadres');
	var errors = new Array();
	if ($F('uw_naam') == "") {
		errors.push('uw_naam');
	}
	if (!checkEmail($F('uw_emailadres'))) {
		errors.push('uw_emailadres');
	}
	if ($F('ont_naam') == "") {
		errors.push('ont_naam');
	}
	if (!checkEmail($F('ont_emailadres'))) {
		errors.push('ont_emailadres');
	}
	for(var i=0;i<fields.length;i++) {
		$(fields[i]).style.background = '#ffffff';
	}
	for(var i=0;i<errors.length;i++) {
		$(errors[i]).style.background = '#ffb09b';
	}
	$(errors[0]).focus();
	if (errors.length > 0) {
		alert("Controlleer a.u.b. de rood gekleurde velden");
		return false;
	}
	return true;
}
	
	
function checkEmail(mailstring) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,10})+$/.test(mailstring)){
	return true;
	}
}

function CheckPC() 
	{
	if ( $F('land') == "Belgium" ) {
		if ( $('postcode').length < 4 || $('postcode').length > 7 ) {
			return false;
		} else {
			var naw_pc = $F('postcode');
			naw_pc = naw_pc.replace( " ", "");
			if ( naw_pc.length > 4 ) {
			  	return false;
			}
		}
		return true;
	} else {
	if ( $('postcode').length < 6 || $('postcode').length > 7 ) 
		{
	  	return false;
		}
	else
		{
		var i = 0;
		var naw_pc = $F('postcode');
		naw_pc = naw_pc.replace( " ", "");
		
		if ( naw_pc.length != 6 )
			{
		  	return false;
			}
		var spltPostCode = naw_pc.split("");
		var naw_pcAangepast = "";
		var errorCode = 0;
		while ( i <= 3 )
			{
			if ( (/([0-9])/.test(spltPostCode[i])) )
				{
				naw_pcAangepast += spltPostCode[i];
				}
			else
				{
				errorCode = 1;
				}
			i++;
			}
		naw_pcAangepast += " ";
		while ( i <= 5 )
			{
			if ( (/([a-zA-Z])/.test(spltPostCode[i])) )
				{
				spltPostCode[i] = spltPostCode[i].toUpperCase();
				naw_pcAangepast += spltPostCode[i];
				}
			else
				{
			  	errorCode = 1;
				}
			i++;
			}
		if ( errorCode == 1 )
			{
	  		return false;
			}	
		}
		return true;
	}
}


function checkTelNumber() {
if ( $F('land') == "Belgium" ) {
	var tel = $F('telefoonnummer');
		tel = tel.replace( "-", "");
		tel = tel.replace( " ", "");
		tel = tel.replace( ".", "");
		tel = tel.replace( "_", "");
	if ( tel.length < 9 || tel.length > 10 ) {
			return false;
	} else {
		var numericExpression = /^[0-9]+$/;
		if(!tel.match(numericExpression)){
			return false;
		} else {
		return true;
		}
	}
	} else {
	var tel = $F('telefoonnummer');
	if (!tel.match(/^([0]{1}[6]{1}[-\s]*[1-9]{1}[\s]*([0-9]{1}[\s]*){7})|([0]{1}[1-9]{1}[0-9]{1}[0-9]{1}[-\s]*[1-9]{1}[\s]*([0-9]{1}[\s]*){5})|([0]{1}[1-9]{1}[0-9]{1}[-\s]*[1-9]{1}[\s]*([0-9]{1}[\s]*){6})$/)) {
		return false;
	} else {
		return true;
	}
	}
}
