
/* Feel free to use this script and Remove this 
 * disclaimer as you like, as long as you leave
 * my bottle of whiskey in my home intact while
 * I'm not around. :p
 *
 *
 * Form validation script by Dave Bleeker.
 * Release:  April 2002
 * Modified: November  2005
 *
 * The original source of this file was 
 * used for http://webboard.xs4all.nl/webboard/
 *
 */

function checkForm(theForm)
{
  //====================================================//
  // CONFIGURING ERROR MESSAGES HERE.                   //
  //====================================================//

  var emptyNameError 				= "Er is geen Naam ingevuld.\n";
  var emptyEmailError 				= "Er is geen E-mailadres ingevuld.\n";
  var wrongEmailError				= "Het E-mailadres is onjuist.\n";
  var emptyTelefoonnummerError		= "Er is geen Telefoonnummer ingevuld.\n";

/*
  var emptyStraatError 		= "Er is geen straat + huisnummer ingevuld.\n";
  var emptyPostcodeError	= "Er is geen postcode + woonplaats ingevuld.\n";
  var emptyWoonplaatsError	= "Er is geen woonplaats ingevuld.\n";
*/

  //======================================================//
  // Leave as it is or remove the check on elements you   //
  // don't bother to check.                               //
  //======================================================//

  var errorMsg = "";
  var error = false;

  if (theForm.naam.value == "")
  {
    errorMsg += emptyNameError;
    error = true;

  }
  if (theForm.email.value == "")
  {
    errorMsg += emptyEmailError;
    error = true; 
  }
  else
  {
    if (!validateEmail(theForm.email.value))
    {
      errorMsg += wrongEmailError;
      error = true;
    }
  }
  
  if (theForm.telefoonnummer.value == "")
  {
    errorMsg += emptyTelefoonnummerError;
    error = true;
  }

  if (!error)
  {
    document.forms[0].submit();
  }
  else 
  {
    alert(errorMsg); 
  }
}

function validateEmail(str) 
{
  // Generic email validator script.
		
  var index = str.indexOf("@");

  if ( (index < 1) ||										// Can't start with @
     (str.indexOf(".") < 1) ||								// Same here
     (str.indexOf("\"") > -1) ||							// No " allowed
     (str.indexOf("'") > -1) ||								// No ' allowed
     (str.length < 5) ||									// a@b.c is actually a valid adress
     ((index > 2) && (str.indexOf("@", index+1) != -1)) )	// Only one @ is allowed
  return false;
  else return true;
}

// End of this fabulous validation script :)
