// JavaScript functies voor formulier-validatie

function checkTxtField(x,y) {
  if (window.document.getElementById(x).value=="") {
    foutmelding=foutmelding+"\n"+y;
    error=1;
    }
  }

function checkPostNrField(x,y) {
  a = window.document.getElementById(x).value
  if (isNaN(a) || a<1000 || a>9999) {
    foutmelding=foutmelding+"\n"+y;
    error=1;
    }
  }

function checkNrField(x,y) {
  a = window.document.getElementById(x).value
  if (isNaN(a) || a=="") {
    foutmelding=foutmelding+"\n"+y;
    error=1;
    }
  }

function checkNumberLimits(x,y,min,max) {
  a = window.document.getElementById(x).value
  if (isNaN(a) || a=="") {
    foutmelding=foutmelding+"\n"+y;
    error=1;
    } else if (window.document.getElementById(x).value<min || window.document.getElementById(x).value>max) {
      foutmelding=foutmelding+"\n"+y;
      error=1;
    }
  }

function checkEmailAddress(x,y) {
  a = window.document.getElementById(x).value;
  p1 = a.indexOf("@");
  p2 = a.lastIndexOf(".");
  if (p1<1 || p2<3 || p2-p1<2) {
    foutmelding=foutmelding+"\n"+y;
    error=1;
    }
  }

function checkPasswords(x1,x2,y) {
  if (window.document.getElementById(x1).value.toLowerCase()!=window.document.getElementById(x2).value.toLowerCase()) {
    foutmelding=foutmelding+"\n"+y;
    error=1;
    }
  }

function checkFieldMinLength(x,l,y) {
  if (window.document.getElementById(x).value.length < l) {
    foutmelding=foutmelding+"\n"+y;
    error=1;
    }
  }

function checkDoubleQuotes(x,y) {
  pos = window.document.getElementById(x).value.indexOf('"');
  if (pos != -1) {
    foutmelding=foutmelding+"\n"+y;
    error=1;
    }
  }

function checkNoSpaces(x,y) {
  pos = window.document.getElementById(x).value.indexOf(' ');
  if (pos != -1) {
    foutmelding=foutmelding+"\n"+y;
    error=1;
    }
  }

// bij deze functie is het mogelijk om enkel te controleren als de bijhorende radio-button geselecteerd is (aangeduid met id=z!!)
function checkNrField_radiocheck(x,y,z) {
  if (window.document.getElementById(z).checked) {
    a = window.document.getElementById(x).value
    if (isNaN(a) || a=="") {
      foutmelding=foutmelding+"\n"+y;
      error=1;
      }
    }
  }

// bij deze functie is het mogelijk om enkel te controleren als de bijhorende radio-button geselecteerd is (aangeduid met id=z!!)
function checkTxtField_radiocheck(x,y,z) {
  if (window.document.getElementById(z).checked) {
    if (window.document.getElementById(x).value=="") {
      foutmelding=foutmelding+"\n"+y;
      error=1;
      }
    }
  }

function checkRadioButtons(x,y,start,end) {
  // x=ID-basename, start/end=volnummer (vb: reeks van ID's: datum1,datum2,datum3,datum4 >> x=datum; start=1; end=4)
  foundCheck=false;
  for (i=start;i<=end;i++) {
    if (document.getElementById(x+i).checked) {
      foundCheck=true;
      }
    }
  if (!foundCheck) {
    foutmelding=foutmelding+"\n"+y;
    error=1;
    }
  }
