/*  */
function OpslaanBericht() {
	document.formulier.action.value = "opslaan";
	CheckFormulier(); 
}

function wijzig_status(id, status, email) {
	document.formulier.id.value = id;
	document.formulier.status.value = status;
	document.formulier.email.value = email;
	document.formulier.submit();
}

function CheckFormulier () {

	result = true;
	if (document.formulier.naam) {
		if (document.formulier.naam.value == "") {
			alert ('U moet het veld Voornaam & achternaam invullen');
			document.formulier.naam.focus();
			result = false;
		}
	}

	if (result && document.formulier.email) {
		if (document.formulier.email.value != "") {
		    if (!CheckEmail(document.formulier.email.value)) {
          	    alert("Ongeldig e-mail adres")
    	        document.formulier.email.focus();
    			result = false;
		    }
		}
	}

    if (result && document.formulier.afdeling_1 && !CheckAfdeling()) {
		alert ('U moet minimaal 1 afdelingen invullen (max. 4)');
		document.formulier.afdeling_1.focus();
		result = false;
	}
	
	
	if (result == true) {
		document.formulier.submit();
	}
	
	return result;
	
}

function CheckEmail(str) {

	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	
	if (str.indexOf(at)==-1)
	   return false

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
	    return false;

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
	    return false;

	 if (str.indexOf(at,(lat+1))!=-1)
	    return false;

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
	    return false;

	 if (str.indexOf(dot,(lat+2))==-1)
	    return false;
	
	 if (str.indexOf(" ")!=-1)
	    return false;
	    
	 return true					
}

function CheckAfdeling() {
	objForm=document.forms.formulier;
	var countCats=0;
	var found = false;
	var result;
		
	for (i=0; i<objForm.elements.length;i++) {
		if (objForm.elements[i].name.indexOf('afdeling') >= 0) {
			found = true;
			if (objForm.elements[i].checked==true) {
				countCats++;
			}
		}		
	}
	
	if (found) {
		result = (countCats >0) && (countCats<4);
	} else {
		result = true;
	}
		
	return (result)
}
function InvulveldChecken() {
	if (document.zoekformulier.search_for.value.length>0) {
		document.zoekformulier.submit();
	} else {
		alert ('U moet iets invullen in het veld "Zoeken op".');
		document.zoekformulier.search_for.focus();
	}
}

