/*
Form validation functions
Copyright (c) 2002 Ylab, Utrecht, NL
2003-12-09; yohan@ylab.nl: Created
*/
function validateForm(frm){
  if (!isNotNull (frm['voornaam'], "Voornaam")) return false;
  if (!isNotNull (frm['achternaam'], "Achternaam")) return false;
	if (!frm['email'].value && !frm['telefoon'].value){
	  alert("Vul een e-mailadres of telefoonnummer in,\nwij nemen dan contact met je op voor een afspraak.");
	  return false;
	}
  if (!isEmail (frm['email'], "E-mailadres")) return false;
	if (!isNotNull (frm['onderwerp'], "Onderwerp")) return false;

	return true;
}

function errormsg(errorcode, guiName, val){
	switch (errorcode)
	{
		case 1: alert('Het veld ' + guiName + ' moet ingevuld zijn.'); break;
		case 2: alert('Het e-mailadres is onvolledig.'); break;
		default: alert('Ongedefineerde foutcode: ' + errorcode); break;
  }
}

function isNotNull (field, guiName){
	//validates if a field contains a value
  //field: input element text|hidden
  //guiName: fieldname to communicate with user
	if ( (!field.value) || (field.value == "") )
	{
		errormsg(1, guiName);
		if(field.focus) {field.focus();}
		return false;
	}
	return true;
}

function isEmail (field, guiName){
	//validates if a textbox contains a valid email address
	var str = field.value;
	if (!str) return true;
	var at = str.indexOf('@');
	if ( (at < 2) || (str.indexOf('.',at+1) < 4) )
	{
		errormsg(2, guiName);
		if(field.focus) {field.focus();}
		return false;
	}
	return true;
}

