function checkNEmail(form) {
	if (isBlank(form.email.value) || isBlank(form.name.value) || !isEmailValid(form.email.value) ) {
		alert("Please enter a valid Name and  Email Address .\nThe email or name you have typed in does not appear to be valid.");
		form.email.focus();
		return false;
	}
}

function checkEmail(form) {
	if (isBlank(form.email.value) || !isEmailValid(form.email.value) ) {
		alert("Please enter a valid Email Address.\nThe email you have typed in does not appear to be valid.");
		form.email.focus();
		return false;
	}
	return true;
}

function isBlank(fieldValue) {
	var blankSpaces = / /g;
	fieldValue = fieldValue.replace(blankSpaces, "");
	return (fieldValue == "") ? true : false;
}

function isEmailValid(fieldValue) {
	var emailFilter = /^.+@.+\..{2,4}$/;
	var atSignFound = 0;
	for (var i = 0; i <= fieldValue.length; i++)
		if ( fieldValue.charAt(i) == "@" )
			atSignFound++;
		if ( atSignFound > 1 )
		return false;
		else
		return ( emailFilter.test(fieldValue) && !doesEmailHaveInvalidChar(fieldValue) ) ? true : false;
}

function doesEmailHaveInvalidChar(fieldValue) {
	var illegalChars = /[\(\)\<\>\,\;\:\\\/\"\[\] ]/;
	return ( illegalChars.test(fieldValue) ) ? true : false;
}

function doesStringContainNonABCChar(fieldValue) {
	var legalChars = /[A-Za-z]/;
	return ( legalChars.test(fieldValue) ) ? false : true;
}

function doesContainNonAlfaChar(fieldValue) {
	var legalChars = /[A-Za-z0-9]/;
	return ( legalChars.test(fieldValue) ) ? false : true;
}

function validateForm() {
	
	var noButton = "Please choose a button before completing your order.";
	var message = "Please enter correct values in fields:\n\n";
	var basis = message;
	
	// check if button is selected
	if ($('besteld').getElements('span').length == 0)
	{
		alert(noButton);
		return false;
	} else {
		
		// one or more buttons selected, continue validation

		if ($('naam').value == "") {message += "name\n";}
		if ($('adres').value == "") {message += "adress\n";}
		if ($('woonplaats').value == "") {message += "city\n";}
		if (!isEmailValid($('mail').value)) {message += "email\n";}

		if (message != basis) {
			alert(message);
			return false;
		}else {
			
			var res  = "Please check if the following information is correct.\n\n";
			res += "Name:        " +		$('naam').value		+"\n";
			res += "Address:    " +	$('adres').value	+"\n";
			res += "City:           " +		$('woonplaats').value	+"\n";
			res += "Email:          " +		$('mail').value		+"\n";
			res += "Telephone: " +	$('telefoonnummer').value	+"\n\n";

			res += "Press OK to confirm your order.";
			confirm(res);
			if ($('bestellingafronden'))
			{
				$('bestellingafronden').submit();
			} else {
				$('bestellingafronden_en').submit();
			}
			return false;
		}
	}
}