function validator(naam,errormessage,thefunction,control){
		this.naam = naam;
		this.errormessage = errormessage;
		this.thefunction = thefunction;
		this.control = control;
}

function overzichtErrors(form){
	var errors = false;
    s = "Volgende velden zijn ongeldig:" + "\n";
    var i;
    for (i=0; i<validators.length; i++) {
        if (!validators[i].isvalid) {
	        s += "  - " + validators[i].getAttribute("errormessage") + "\n";
	        document.getElementById(validators[i].getAttribute("Id")).style.visibility ="visible";
	        //validators[i].style.visibility ="visible";
	        errors = true;
        }else{
			document.getElementById(validators[i].getAttribute("Id")).style.visibility ="hidden";
			//validators[i].style.visibility ="hidden";
        }
    }
    /*span = document.createElement("SPAN");
    span.innerHTML = s;
    s = span.innerText;*/
    
    var tel = 0;
    var vak = true;
    
    try{      
        for(i=1; i<=10; i++){
            if(document.getElementById('soort' + i).checked){
                tel = tel + 1;
            }
        }
    }catch(err){
        //doe niets
        vak = false;
    }
    
    if(tel == 0 && vak == true){
        s += "  - Gelieve minstens één 'Vakgebied/soort activiteit' aan te vinken.\n"
        errors = true;
    }

    if(!errors){
		document.getElementById(form).submit();
    }else{
		alert(s);
    }

}

function isValidEmail(emailAddress) {
	var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
	return re.test(emailAddress);
}

function hasSelected(value){
	if(value==""){
		return false;
	}
	return true;
}

/*function validate(form){
	for (i=0; i<validators.length; i++) {
		id = validators[i].control;
		control = document.getElementById(id);
		//maken dat hij de functie erkent
		eval("validators[i].thefunction = " + validators[i].thefunction + ";");
		if(!validators[i].thefunction(control.value)){
			validators[i].isvalid = false;
		}else{
			validators[i].isvalid = true;
		}
    }
    overzichtErrors(form);
}*/
function validate(form){
	for (i=0; i<validators.length; i++) {
		id = validators[i].getAttribute("control");
//		alert(id);
		control = document.getElementById(id);
		//maken dat hij de functie erkent
		eval("validators[i].thefunction = " + validators[i].getAttribute("thefunction") + ";");
		if(!validators[i].thefunction(control.value)){
			validators[i].isvalid = false;
		}else{
			validators[i].isvalid = true;
		}
    }
    overzichtErrors(form);
}
function isNotEmpty(tekst){
	if(tekst.length == 0){
		return false;
	}
	tekst = trim(tekst);
	if(tekst.length == 0){
		return false;
	}
	return true;
}

function trim(value) {
	var temp = value;
	var obj = /^(\s*)([\W\w]*)(\b\s*$)/;
	if(obj.test(temp)) {
		temp = temp.replace(obj, '$2');
	}
	var obj = /  /g;
	while(temp.match(obj)) {
		temp = temp.replace(obj," ");
	}
	return temp;
}

function confirmdialog(form,id){
	var name=confirm("Ben je zeker dat je item '"+id+"' wilt verwijderen?\nAlle bijhorende activiteiten zullen ook verwijderd worden.")
	if (name==true){
		form = trim(form);
		document.getElementById('txtButton'+ id).value ="Verwijderen";
		document.getElementById(form + id).submit();
	}
}
function klik(form,id,tekst){
		document.getElementById('txtButton'+ id).value =tekst;
		document.getElementById('form' + id).submit();
}

function SetAllSoorten()
{
  var index = 1;
  var checked;
  if (document.getElementById('alle_soorten').checked == true)
    checked=true;
  else 
    checked=false; 
  
  while (document.getElementById('soort'+ index) != null) 
    {
    document.getElementById('soort'+ index).checked = checked;
    index++;
    } 
    SetSoortGevuld();
}

function SetAlldoelroepen()
{
  var index = 1;
  var checked;
  if (document.getElementById('alle_doelroepen').checked == true)
    checked=true;
  else 
    {
    checked=false;
    document.getElementById('alle_doelroepen_lager').checked = false;
    document.getElementById('alle_doelroepen_secundair').checked = false;
    } 
  while (document.getElementById('onderwijsniveau'+ index) != null)
    {
    
    document.getElementById('onderwijsniveau'+ index).checked = checked;
    index++;
    } 
    SetOnderwijsniveauGevuld();
}

function SetAlldoelroepen_secundair()
{
  var index = 1;
  var checked;
  if (document.getElementById('alle_doelroepen_secundair').checked == true)
    checked=true;
  else 
    {
    checked=false;
    document.getElementById('alle_doelroepen').checked = false;
    } 
  
  while (document.getElementById('onderwijsniveau'+ index) != null) 
    {
    
    var tempName = document.getElementById('onderwijsniveau'+ index).value;
    tempName = tempName.toLowerCase();
    var temp = tempName.split('secundair');
    if (temp[1]!=null)
      document.getElementById('onderwijsniveau'+ index).checked = checked;
    index++;
    } 
    SetOnderwijsniveauGevuld();
}

function SetAlldoelroepen_lager()
{
  var index = 1;
  var checked;
  if (document.getElementById('alle_doelroepen_lager').checked == true)
    checked=true;
  else 
    {
    checked=false;
    document.getElementById('alle_doelroepen').checked = false;
    } 
    
  while (document.getElementById('onderwijsniveau'+ index) != null) 
    {
    var tempName = document.getElementById('onderwijsniveau'+ index).value;
    tempName = tempName.toLowerCase();
    var temp = tempName.split('basis');
    if (temp[1]!=null)
      document.getElementById('onderwijsniveau'+ index).checked = checked;
    index++;
    } 
    SetOnderwijsniveauGevuld();
}

function Setdoelgroep(obj)
{
    document.getElementById('alle_doelroepen').checked = false;
    document.getElementById('alle_doelroepen_lager').checked = false;
    document.getElementById('alle_doelroepen_secundair').checked = false;
    
    SetOnderwijsniveauGevuld();
    
}

function Setsoort(obj)
{
   document.getElementById('alle_soorten').checked = false;
   SetSoortGevuld();
}

function SetOnderwijsniveauGevuld()
{
   var index=1;
   var onderwijsniveauGevuld='';
   while (document.getElementById('onderwijsniveau'+ index) != null) 
    {
    if (document.getElementById('onderwijsniveau'+ index).checked == true)
      onderwijsniveauGevuld = onderwijsniveauGevuld + document.getElementById('onderwijsniveau'+ index).value + '___';
    index++;  
    } 
    document.getElementById('onderwijsniveauGevuld').value = onderwijsniveauGevuld;
}

function SetSoortGevuld()
{
   var index=1;
   var soortGevuld='';
   while (document.getElementById('soort'+ index) != null) 
    {
    if (document.getElementById('soort'+ index).checked == true)
      soortGevuld = soortGevuld + document.getElementById('soort'+ index).name + '___';
    index++;  
    } 
    document.getElementById('soortGevuld').value = soortGevuld;
}

function preview2Loaded()
{
SetOnderwijsniveauGevuld();
SetSoortGevuld();
}

function gespreidVanKleinerDanTot()
{
var van = document.getElementById("gespreidVan").value;
var tot = document.getElementById("gespreidTot").value;
var tempVan = van.split('-');
var tempTot = tot.split('-');
document.getElementById("ValidateGespreid").style.visibility=="visible";
if (tempTot[2]<tempVan[2])
    {
    if (tempTot[1]<tempVan[1])
      {
        if (tempTot[0]<tempVan[0])
            document.getElementById("ValidateGespreid").style.visibility=="hidden";
      }
    }
if (van=='')
  document.getElementById("ValidateGespreid").style.visibility=="hidden";
if (tot=='')
  document.getElementById("ValidateGespreid").style.visibility=="hidden";
}


