
var verzonden = false;

function trim(strText) { 
  // this will get rid of leading spaces 
  while (strText.substring(0,1) == ' ') 
    strText = strText.substring(1, strText.length);

  // this will get rid of trailing spaces 
  while (strText.substring(strText.length-1,strText.length) == ' ')
    strText = strText.substring(0, strText.length-1);

  return strText;
} 

function checkSubmit() {
  if(verzonden==false) {
    verzonden=true;
    return true;
  }
  else {
    alert("\nHet formulier is bezig met verzenden van de gegevens.\n\nEven guduld a.u.b.");
    return false;
  }
}

function testForm() {

for (i=0; i<document.forms[0].length;i++) {
  if (document.forms[0].elements[i].type!="hidden") {
    document.forms[0].elements[i].value = trim(document.forms[0].elements[i].value);
  }
}

if (req_naam==true) {
  if (document.forms[0].elements["naam"].value =="") {
    alert("\nU heeft uw naam niet ingevuld.\n\nVul a.u.b. uw naam in.")
    document.forms[0].elements["naam"].focus();
    return false;
  }

  for (var i = 0; i < document.forms[0].elements["naam"].value.length; i++) {
    var ch = document.forms[0].elements["naam"].value.substring(i, i + 1);
    if (((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) && ch != '.' && ch != '-' && ch != ' ') {
      alert("\nHet veld 'naam' accepteert alleen letters.\n\nVul a.u.b uw naam in.");
      document.forms[0].elements["naam"].select();
      document.forms[0].elements["naam"].focus();
      return false;
    }
  }
}

if (req_adres==true) {
  if (document.forms[0].elements["adres"].value == "") {
    alert("\nU heeft uw adres niet ingevuld.\n\nVul a.u.b. uw adres in.")
    document.forms[0].elements["adres"].focus();
    return false;
  }

  for (var i = 0; i < document.forms[0].elements["adres"].value.length; i++) {
    var ch = document.forms[0].elements["adres"].value .substring(i, i + 1);
    if (((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch )) && (ch < "0" || "9" < ch) && ch != '.'  && ch != ' ' && ch != '-') {
      alert("\nHet veld 'adres' accepteert alleen letters & cijfers.\n\nVul a.u.b uw adres in.");
      document.forms[0].elements["adres"].select();
      document.forms[0].elements["adres"].focus();
      return false;
    }
  }
}

if (req_postcode==true) {
  if (document.forms[0].elements["postcode"].value == "") {
    alert("\nU heeft uw postcode niet ingevuld.\n\nVul a.u.b. uw postcode in.")
    document.forms[0].elements["postcode"].focus();
    return false;
  }

  for (var i = 0; i < document.forms[0].elements["postcode"].value.length; i++) {
    var ch = document.forms[0].elements["postcode"].value .substring(i, i + 1);
    if (((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch )) && (ch < "0" || "9" < ch) && ch != ' ') {
      alert("\nHet veld 'postcode' accepteert alleen letters & cijfers.\n\nVul a.u.b uw postcode in.");
      document.forms[0].elements["postcode"].select();
      document.forms[0].elements["postcode"].focus();
      return false;
    }
  }
}

if (req_woonplaats==true) {
  if (document.forms[0].elements["woonplaats"].value =="") {
    alert("\nU heeft uw woonplaats niet ingevuld.\n\nVul a.u.b. uw woonplaats in.")
    document.forms[0].elements["woonplaats"].focus();
    return false;
  }

  for (var i = 0; i < document.forms[0].elements["woonplaats"].value.length; i++) {
    var ch = document.forms[0].elements["woonplaats"].value.substring(i, i + 1);
    if (((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) && ch != ' ' && ch != '.' && ch != '-') {
      alert("\nHet veld 'woonplaats' accepteert alleen letters.\n\nVul a.u.b uw woonplaats in.");
      document.forms[0].elements["woonplaats"].select();
      document.forms[0].elements["woonplaats"].focus();
      return false;
    }
  }
}

if (req_land==true) {
  if (document.forms[0].elements["land"].value =="") {
    alert("\nU heeft uw land niet ingevuld.\n\nVul a.u.b. uw land in.")
    document.forms[0].elements["land"].focus();
    return false;
  }

  for (var i = 0; i < document.forms[0].elements["land"].value.length; i++) {
    var ch = document.forms[0].elements["land"].value.substring(i, i + 1);
    if (((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) && ch != ' ') {
      alert("\nHet veld 'land' accepteert alleen letters.\n\nVul a.u.b uw land in.");
      document.forms[0].elements["land"].select();
      document.forms[0].elements["land"].focus();
      return false;
    }
  }
}

if (req_telefoon==true) {
  if (document.forms[0].elements["telefoon"].value =="") {
    alert("\nU heeft uw telefoonnummer niet ingevuld.\n\nVul a.u.b. uw telefoonnummer in.")
    document.forms[0].elements["telefoon"].focus();
    return false;
  }

  for (var i = 0; i < document.forms[0].elements["telefoon"].value.length; i++) {
    var ch = document.forms[0].elements["telefoon"].value.substring(i, i + 1);
    if (((ch < "0" || "9" < ch)) && ch != '-' && ch != ' ') {
      alert("\nHet veld 'telefoon' accepteert alleen cijfers.\n\nVul a.u.b uw telefoonnummer in.");
      document.forms[0].elements["telefoon"].select();
      document.forms[0].elements["telefoon"].focus();
      return false;
    }
  }
}

if (req_email==true) {
  if (document.forms[0].elements["email"].value =="") {
    alert("\nU heeft uw emailadres niet ingevuld.\n\nVul a.u.b. uw emailadres in.")
    document.forms[0].elements["email"].focus();
    return false;
  }

  var apestaart = false;
  var punt = false;
  for (var i = 0; i < document.forms[0].elements["email"].value.length; i++) {
    var ch = document.forms[0].elements["email"].value.substring(i, i + 1);
    if (!apestaart && ch=="@") { apestaart = true; }
    if (apestaart && !punt && ch==".") { punt = true; }
    if (((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch )) && (ch < "0" || "9" < ch)  && ch != '@' && ch != '-' && ch != '.' && ch != '_') {
      alert("\nHet veld 'e-mail' kan alleen letters, cijfers en de tekens @-._ bevatten.\n\nVul a.u.b uw emailadres in.");
      document.forms[0].elements["email"].select();
      document.forms[0].elements["email"].focus();
      return false;
    }
  }
  if (!apestaart || !punt) {
    alert("\nHet veld 'e-mail' is niet juist ingevuld.\n\nVul a.u.b uw emailadres in.");
    document.forms[0].elements["email"].select();
    document.forms[0].elements["email"].focus();
    return false;
  }
}

if (!checkSubmit()) { return false; }
  
return true;

}

