function ValidateAanmelden(theForm)
{
  if (theForm.gebruikersnaam.value == "")
  {
    alert("Gelieve uw gebruikersnaam in te vullen");
    theForm.gebruikersnaam.focus();
    return (false);
  }
  if (theForm.wachtwoord.value == "")
  {
    alert("Gelieve uw wachtwoord in te vullen");
    theForm.wachtwoord.focus();
    return (false);
  }
  return (true);
}

function ValidateRegistreren(theForm)
{
   if (theForm.naam.value == "")
  {
    alert("Gelieve uw naam in te vullen");
    theForm.naam.focus();
    return (false);
  }
  if (theForm.voornaam.value == "")
  {
    alert("Gelieve uw voornaam in te vullen");
    theForm.voornaam.focus();
    return (false);
  }
  
	var theone
	theone=-1
	for (i=0;i<theForm.hogeschool.length;i++){
		if (theForm.hogeschool[i].checked==true){
			theone=i
		break //exist for loop, as target acquired.
		}
	}
    if (theone == -1){
    alert("Gelieve uw hogeschool aan te duiden");
    return (false);
  	}
  
  if (theForm.opleiding1.value == 0 && theone==0)
  {
    alert("Gelieve de opleiding binnen uw hogeschool aan te duiden");
    theForm.opleiding1.focus();
    return (false);
  } 
    if (theForm.opleiding2.value == 0 && theone==1)
  {
    alert("Gelieve de opleiding binnen uw hogeschool aan te duiden");
    theForm.opleiding2.focus();
    return (false);
  } 
    if (theForm.opleiding3.value == 0 && theone==2)
  {
    alert("Gelieve de opleiding binnen uw hogeschool aan te duiden");
    theForm.opleiding3.focus();
    return (false);
  } 
    if (theForm.GSM.value == "")
  {
    alert("Gelieve uw GSM nummer in te vullen");
    theForm.GSM.focus();
    return (false);
  }
  if (theForm.emailA.value != theForm.emailA2.value)
  {
    alert("Gelieve uw e-mailadres twee keer correct in te vullen");
    theForm.emailA.focus();
    return (false);
  }  
  if (theForm.emailA.value == "")
  {
    alert("Gelieve uw e-mailadres in te vullen");
    theForm.emailA.focus();
    return (false);
  }else{
	  return(studentEmail(theForm.emailA.value));
  }
  if (theForm.emailB.value != theForm.emailB2.value)
  {
    alert("Gelieve uw tweede e-mailadres twee keer correct in te vullen");
    theForm.emailB.focus();
    return (false);
  }else{
	  if (theForm.emailB.value != ""){
		return(studentEmail(theForm.emailB.value));
	  }
  }
  return (true);
}

function ValidateWachtwoordvergeten(theForm)
{
  if (theForm.email.value == "")
  {
    alert("Gelieve uw e-mailadres in te vullen");
    theForm.email.focus();
    return (false);
  }else{
	  return(CyJS_Utils_IsEmailValid(theForm.email.value));
  }
  return (true);
}
function studentEmail(checkThisEmail)
{
var myEMailIsValid = true;
var school1 =  checkThisEmail.indexOf('khbo.be');
var school2 = checkThisEmail.indexOf('katho.be');
var school3 = checkThisEmail.indexOf('howest.be');
var myAtSymbolAt = checkThisEmail.indexOf('@');
var myLastDotAt = checkThisEmail.lastIndexOf('.');
var mySpaceAt = checkThisEmail.indexOf(' ');
var myLength = checkThisEmail.length;

if (school1 > 1 ) 
 {myEMailIsValid = false}
if (school2 > 1 ) 
 {myEMailIsValid = false}
if (school3 > 1 ) 
 {myEMailIsValid = false}
 
if (myAtSymbolAt < 1 ) 
 {myEMailIsValid = false}

if (myLastDotAt < myAtSymbolAt) 
 {myEMailIsValid = false}


if (myLength - myLastDotAt <= 2) 
 {myEMailIsValid = false}

if (mySpaceAt != -1) 
 {myEMailIsValid = false}

if (myEMailIsValid == false)
 {alert("Het ingevulde e-mailadres is niet geldig. Gelieve te corrigeren.")}

return myEMailIsValid
}

function CyJS_Utils_IsEmailValid(checkThisEmail)
{
var myEMailIsValid = true;
var myAtSymbolAt = checkThisEmail.indexOf('@');
var myLastDotAt = checkThisEmail.lastIndexOf('.');
var mySpaceAt = checkThisEmail.indexOf(' ');
var myLength = checkThisEmail.length;

if (myAtSymbolAt < 1 ) 
 {myEMailIsValid = false}

if (myLastDotAt < myAtSymbolAt) 
 {myEMailIsValid = false}


if (myLength - myLastDotAt <= 2) 
 {myEMailIsValid = false}

if (mySpaceAt != -1) 
 {myEMailIsValid = false}

if (myEMailIsValid == false)
 {alert("Het ingevulde e-mailadres is niet geldig. Gelieve te corrigeren.")}

return myEMailIsValid
}

function limitText(limitField, limitNum) {
	if (limitField.value.length > limitNum + 1)
	alert('Opgelet: er mogen slechts ' + limitNum + ' karakters gebruikt worden in dit veld! Het veld wordt afgekort.');
    if (limitField.value.length > limitNum) {
        limitField.value = limitField.value.substring(0, limitNum);
    } 
}

