function check_invoer() {

  foutMelding ('&nbsp;');

  // check naam instelling
  instelling= document.getElementById('instelling').value;
  if (instelling.length < 1) {
    showError('instelling');
    document.getElementById('instelling').focus();
    return;
  }

  // geen controle op instellingsnummer
  
  // check naam contactpersoon
  contactpersoon = document.getElementById('contactpersoon').value;
  if (contactpersoon.length < 1) {
    showError('contactpersoon');
    document.getElementById('contactpersoon').focus();
    return;
  }

  // geen controle op functie

  // check email adres
  if (document.getElementById('emailadres').value.length < 1) {
    showError('email1');
    document.getElementById('emailadres').focus();
    return;
  }

  if (!check_email(document.getElementById('emailadres').value)) {
    showError('email2');
    document.getElementById('emailadres').focus();
    return;

  }

  // check onderwerp
  subject = document.getElementById('subject').value;
  if (subject.length < 1) {
    showError('subject');
    document.getElementById('subject').focus();
    return;
  }

// check vraag
  if (document.getElementById('vraag').value.length < 1) {
    showError('vraag');
    document.getElementById('vraag').focus();
    return;
  }
  if (document.getElementById('vraag').value.length > 1000) {
    showError('vraag2');
    document.getElementById('vraag').focus();
    return;
  }

  // document.getElementById('contactForm').action='verstuurEmail.asp';
  //document.getElementById('contactForm').submit();
 vars =   'type=gemeente'+
          '&instelling='+escape(document.getElementById('instelling').value)+
          '&instellingsnr='+escape(document.getElementById('instellingsnr').value)+
          '&contactpersoon='+escape(document.getElementById('contactpersoon').value)+
          '&functie='+escape(document.getElementById('functie').value)+
          '&emailadres='+escape(document.getElementById('emailadres').value)+
          '&subject=SCI-instellingen: '+escape(document.getElementById('subject').value)+
          '&vraag='+escape(document.getElementById('vraag').value);
    loadXMLDoc('/includes/verzendEmail.asp','POST',vars);
}

function foutMelding (str) {
  document.getElementById('tekst1').innerHTML = str;

  if (document.getElementById('tekst1').innerHTML == "&nbsp;") {
   document.getElementById('tekst1').style.display = "none";
  } else {
   document.getElementById('tekst1').style.display = "block";
  }

}

function showError(err) {
  switch (err) {
    case "instelling":
      foutMelding('Naam van de instelling is verplicht om in te vullen.');
      break;
    case "contactpersoon":
      foutMelding('Naam van de contactpersoon is verplicht om in te vullen.');
      break;
    case "email1":
      foutMelding('E-mail adres is verplicht om in te vullen.');
      break;
    case "email2":
      foutMelding('E-mail adres is onjuist.');
      break;
    case "subject":
      foutMelding('Onderwerp is verplicht om in te vullen.');
      break;
    case "vraag":
      foutMelding('U hebt geen vraag gesteld.');
      break;
    case "vraag2":
      foutMelding('Max aantal tekens is 1000.');
      break;
    case "ok":
      foutMelding("Uw email is verzonden.");
      break;
    case "nok":
      foutMelding('Helaas is er een storing opgetreden tijdens het versturen van uw e-mail.');
      break;
  }
}

function check_email(e) {
  ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.\@-_QWERTYUIOPASDFGHJKLZXCVBNM";
  for(h=0; h < e.length ;h++){
    if(ok.indexOf(e.charAt(h))<0){ 
      return false;
    }		
  }
  
  atSign = e.indexOf('@');
  if (atSign > 0) {
    p1 = e.indexOf('.',atSign);
    if (p1 <= (atSign+2)) {
    // er moeten twee tekens tussen @ en eerste punt (.) staan
      return false;
    }
    // lastIndexOf gebruiken omdat er meerdere punten kunnen zitten in een email-adres
    p1  = e.lastIndexOf('.');
    // -3 omdat length begint met 1 en lastIndexOf met nul 
    if (p1 > (e.length -3)) {
      return false
    }
  } else {
  // geen @  in email adres  
    return false;
  }
  return true;
}

// indien verzendEmail.asp goed is gegaan dan wordt deze functie aangeroepen

function exec_function_after_req_OK() {
  // sluit contact div
  // toon bedankt voor mail
  showError('ok');
}
function exec_function_after_req_NOT_OK() {
  // sluit contact div
  // toon bedankt voor mail
  showError('nok');
}
//alert (findPosX(document.getElementById('spanNaam')));
//  alert(document.getElementById('spanNaam').style.width);
  // = '400';
// -->
