
function FCKeditor_OnComplete(naam)
{
	if (naam == FCKeditorAPI.GetInstance('bericht') || FCKeditorAPI.GetInstance('message') || FCKeditorAPI.GetInstance('bericht_volleybal')){
		naam.EditorWindow.parent.document.getElementById("xExpanded").style.display = "none";
	}
}

function reload_iframe () {
obj = document.getElementById('knvb_laden');
obj.style.display = "";
obj = document.getElementById('frameWrapper');
obj.style.display = "none";
var f = document.getElementById('frame');
f.contentWindow.location.reload(true);
}

function onload_knvb(theIframe) {
	obj = document.getElementById('knvb_laden');
	obj.style.display = "none";
	obj = document.getElementById('frameWrapper');
	obj.style.display = "";
	//obj = document.getElementById('iframe_reload');
	//obj.style.display = "";
	var theDocument = theIframe.contentWindow.document;
	var theHeight = theDocument.getElementById('knvb').scrollHeight +20;
	theIframe.scrolling = 'no';
	theIframe.style.overflow = 'hidden';
	theIframe.frameBorder = 0;
	theIframe.height = theHeight;
}


function checkgebruikersForm() {
	theForm = document.myform;
	var theMessage = "Volg de volgende aanwijzingen: \n-----------------------------------\n";
	var errors = "0"
	
	if	(!valid_required(theForm.voornaam))	{
		errors = "1"
		theMessage = theMessage + "\n --> Vul voornaam in.";
	}
	if	(!valid_required(theForm.achternaam))	{
		errors = "1"
		theMessage = theMessage + "\n --> Vul achternaam in.";
	}
	if (!checktel(theForm.tel.value,"1234567890-")) {
		errors = "1";
		theForm.tel.style.border = "3px solid #c30";
		theMessage = theMessage + "\n --> Vul juiste telefoonnummer in.";
	}
	if	(!checkemail(theForm.email))	{
		errors = "1"
		theMessage = theMessage + "\n --> Vul juiste email adres is.";
	}
	if	(!valid_required(theForm.team_id))	{
		errors = "1"
		theMessage = theMessage + "\n --> Kies een team";
	}	
	if	(!valid_required(theForm.password))	{
		errors = "1"
		theMessage = theMessage + "\n --> Vul wachtwoord in.";
	}
	if (errors == "0") {
		return true
	}
	else {
		alert (theMessage);
		return false;
	}
}

function checkledenForm() {
	var theMessage = "Volg de volgende aanwijzingen: \n-----------------------------------\n";
	theForm = document.myform;       
	var errors = "0"
	if	(!valid_required(theForm.voornaam))	{
		errors = "1"
		theMessage = theMessage + "\n --> Vul voornaam in.";
	}	
	if	(!valid_required(theForm.achternaam))	{
		errors = "1";
		theMessage = theMessage + "\n --> Vul achternaam in.";
	}

	if (!checkdate(theForm.geboortedatum)) {
		theMessage = theMessage + "\n --> Vul juiste datum in.";
		errors = "1";
	}
	/*
	if	(!valid_required(theForm.team_id))	{
		theMessage = theMessage + "\n --> Kies een team.";
		errors = "1";
	}
	*/
	if (errors == "0") {
		return true
	}
	else {
		alert(theMessage)
		return false
	}
}
function checkverslagenForm() {
	theForm = document.myform;
	var theMessage = "Volg de volgende aanwijzingen: \n-----------------------------------\n";
	var errors = "0"
	if	(!valid_required(theForm.titel))	{
		errors = "1"
		theMessage = theMessage + "\n --> Vul titel in.";
	}
	if (!checkdate(theForm.datum)) {
		errors = "1";
		theMessage = theMessage + "\n --> Vul juiste datum in.";

	}
	if	(!valid_required(theForm.team_id))	{
		theMessage = theMessage + "\n --> Kies een team.";
		errors = "1";
	}
	if (!valid_required(theForm.verslag)) {	
		theMessage = theMessage + "\n --> Vul verslag in.";
		errors = "1";
	}
	if (errors == "0") {
		return true
	}
	else {
		alert (theMessage);
		return false;
	}
}

function checkagendaForm() {
	theForm = document.myform;
	var oEditor = FCKeditorAPI.GetInstance('omschrijving'); 
	var theMessage = "Volg de volgende aanwijzingen: \n-----------------------------------\n";
	var errors = "0"
	if (!checkdate(theForm.datum)) {
		errors = "1";
		theMessage = theMessage + "\n --> Vul juiste datum in.";
	}
	/*
	if (!checktime(theForm.tijd)) {
		errors = "1";
		theMessage = theMessage + "\n --> Vul juiste tijd in.";
	}
	*/
	if	(!valid_required(theForm.locatie))	{
		errors = "1"
		theMessage = theMessage + "\n --> Vul locatie in.";
	}
	if	(oEditor.GetXHTML(true) == "")	{
		theMessage = theMessage + "\n --> Vul verslag in.";
		errors = "1";
	}
	if (errors == "0") {
		return true
	}
	else {
		alert (theMessage);
		return false;
	}
}

function checkdate(field) {
	date = field.value;
	date = date.replace(" ", "-");
	date = date.replace(" ", "-");
	date = date.replace("/", "-");
	date = date.replace("/", "-");
	if (date.length>7&&!(date.split("-")[0]*1>31)&&!(date.split("-")[1]*1>12)&&!(date.split("-")[2]*1<1900)) {	//Must be longer than 7 characters, first (two) digit(s) NOT greater than 31, second (two) digit(s) NOT greater than 12 and last 4 greater than 1900
		field.style.border = "1px solid gray";
		return true;
	}
	else {
		field.style.border = "3px solid #c30";
		return false;
	}
}	

function show(id){
	if (document.getElementById(id)){
		obj = document.getElementById(id);
		if (obj.style.display == "none" ){
			obj.style.display = "";
		}
	}
}

function hide(id){
	if (document.getElementById(id)){
		obj = document.getElementById(id);
		obj.style.display = "none";
	}
}

function valid_required(field)	{
	if(field.value == "") {
		field.style.border = "3px solid #c30";
		return false;
	}
	else {
		field.style.border = "1px solid gray";
		return true;
	}
}


function checktime(field) {
	value = field.value
   var colonCount = 0;
   var hasMeridian = false;
   for (var i=0; i<value.length; i++) {
      var ch = value.substring(i, i+1);
      if ( (ch < '0') || (ch > '9') ) {
         if ( (ch != ':') && (ch != ' ') && (ch != 'a') && (ch != 'A') && (ch != 'p') && (ch != 'P') && (ch != 'm') && (ch != 'M')) {
            return false;
         }
      }
      if (ch == ':') { colonCount++; }
      if ( (ch == 'p') || (ch == 'P') || (ch == 'a') || (ch == 'A') ) { hasMeridian = true; }
   }
   if ( (colonCount < 1) || (colonCount > 2) ) { field.style.border = "3px solid #c30"; return false; }
   var hh = value.substring(0, value.indexOf(":"));
   if ( (parseFloat(hh) < 0) || (parseFloat(hh) > 23) ) { field.style.border = "3px solid #c30"; return false; }
   if (hasMeridian) {
      if ( (parseFloat(hh) < 1) || (parseFloat(hh) > 12) ) {field.style.border = "3px solid #c30";  return false; }
   }
   if (colonCount == 2) {
      var mm = value.substring(value.indexOf(":")+1, value.lastIndexOf(":"));
   } else {
      var mm = value.substring(value.indexOf(":")+1, value.length);
   }
   if ( (parseFloat(mm) < 0) || (parseFloat(mm) > 59) ) { field.style.border = "3px solid #c30"; return false; }
   if (colonCount == 2) {
      var ss = value.substring(value.lastIndexOf(":")+1, value.length);
   } else {
      var ss = "00";
   }
   if ( (parseFloat(ss) < 0) || (parseFloat(ss) > 59) ) { field.style.border = "3px solid #c30"; return false; }
   field.style.border = "1px solid gray";
   return true;
}

function checkemail(field)
{
with (field)
{
apos=value.indexOf("@");
dotpos=value.lastIndexOf(".");
if (field.value == "") {
	return true;
}
else if (apos<1||dotpos-apos<2) 
  {field.style.border = "3px solid #c30"; return false;}
else {return true;}
}
}

function checktel(NumStr, String)
{
    for(var Idx=0; Idx<NumStr.length; Idx++)
    {
        var Char = NumStr.charAt(Idx);
        var Match = false;

        for(var Idx1=0; Idx1<String.length; Idx1++)
        {
            if(Char == String.charAt (Idx1))
                Match = true;
        }

        if (!Match)
            return false;
    }
    return true;
}

