function validator(thisForm,setLoading) {
				 var errorMessage='Bij het controleren van het formulier is de volgende fout geconstateerd:\n\n';
				 var breakFunction=false;
				 var supportedFiles=" » .jpg, .jpeg of .png (Afbeeldingen)";
				 for(var i=0;i<thisForm.elements.length;i++) {
				 				 thisElement=thisForm.elements[i];
								 if(thisElement.className=='text_req') {
											if(thisElement.value.length==0) {
													 errorMessage=errorMessage + '» Het veld \"' + thisElement.name + '\" is een tekstveld en verplicht.\n';
													 breakFunction=true;
											}
								 }
								 else if(thisElement.className=='text_req2') {
											if((isText(thisElement.value)==false) || (thisElement.value.length==0)) {
													 errorMessage=errorMessage + '» Het veld \"' + thisElement.name + '\" is een tekstveld en verplicht. Gebruik alleen letters, cijfers, \"-\" en \"_\" (geen spaties, punten of andere leestekens)\n';
													 breakFunction=true;
											}
								 }
								 else if(thisElement.className=='textarea_req') {
											if(thisElement.value.length==0) {
													 errorMessage=errorMessage + '» Het veld \"' + thisElement.name + '\" is een memoveld en verplicht.\n';
													 breakFunction=true;
											}
								 }
								 else if(thisElement.className=='textarea_iframe_req') {
								 			// speciale actie:
											// 1. de waarde van dit element moet standaard worden geset bij het submitten
											// 2. de opslag van de iframe vindt plaats in een aparte textarea die verborgen is!
											//    bij fouten moet dus het iframe worden geselecteerd!
											//    iframe maakt ALTIJD gebruik van loaddata.asp dus op basis daarvan wordt het iframe gedefinieerd
											submitfunction();
											if(thisElement.value.length==0) {
													 errorMessage=errorMessage + '» Het veld \"' + thisElement.name + '\" is verplicht.\n';
													 for(x=0;x<window.frames.length;x++) {
													      if(window.frames[x].location.href.match('loaddata.asp')=='loaddata.asp') {
																     theIframe=window.frames[x];
																}
													 }
													 theIframe.document.body.style.background='#cccccc';
													 theIframe.document.body.focus();
													 alert(errorMessage);
													 return false;
													 break;													 
											}
								 }
								 else if(thisElement.className=='numeric_req') {
											if((isNumeric(thisElement.value)==false) || (thisElement.value.length==0)) {
													 errorMessage=errorMessage + '» Het veld \"' + thisElement.name + '\" is verplicht en numeriek.\n';
													 breakFunction=true;
											}
								 }
								 else if(thisElement.className=='numeric') {
											if(isNumeric(thisElement.value)==false) {
													 errorMessage=errorMessage + '» Het veld \"' + thisElement.name + '\" is numeriek.\n';
													 breakFunction=true;
											}
								 }
								 else if(thisElement.className=='postal1') {
											if((isNumeric(thisElement.value)==false) || (thisElement.value.length!=4)) {
													 errorMessage=errorMessage + '» Het veld \"' + thisElement.name + '\" is het verplichte numerieke gedeelte van de postcode (4 cijfers).\n';
													 breakFunction=true;
											}
								 }
								 else if(thisElement.className=='postal2') {
								 			thisElement.value=thisElement.value.toUpperCase();
											if((isAlpha(thisElement.value)==false) || (thisElement.value.length!=2)) {
													 errorMessage=errorMessage + '» Het veld \"' + thisElement.name + '\" is verplichte textuele gedeelte van de postcode (2 letters).\n';
													 breakFunction=true;
											}
								 }
								 else if(thisElement.className=='date_req') {
											if((isDate(thisElement)==false) || (thisElement.value.length==0)) {
													 errorMessage=errorMessage + '» Het veld \"' + thisElement.name + '\" is verplicht en moet ingevuld worden volgens datumnotatie \"DD-MM-JJJJ\".\n';
													 breakFunction=true;
											}
								 }
								 else if(thisElement.className=='date') {
											if(isDate(thisElement)==false) {
													 errorMessage=errorMessage + '» Het veld \"' + thisElement.name + '\" moet ingevuld worden volgens datumnotatie \"DD-MM-JJJJ\".\n';
													 breakFunction=true;
											}
								 }
								 else if(thisElement.className=='select_req') {
											if(thisElement.options[thisElement.selectedIndex].value.length==0) {
													 errorMessage=errorMessage + '» Het veld \"' + thisElement.name + '\" is een verplichte selectielijst.\n';
													 thisElement.style.background='#cccccc';
													 alert(errorMessage);
										      		 thisElement.focus();
													 return false;
											}
								 }
								 else if(thisElement.className=='file_req') {
								 			fileExtension=thisElement.value.substring(thisElement.value.lastIndexOf("."),thisElement.value.length);
											if(thisElement.value.length==0) {
													 errorMessage=errorMessage + '» Het veld \"' + thisElement.name + '\" is van het type \"Bestand\" en is een verplicht veld.\n';
													 breakFunction=true;
											}
								 }
								 else if(thisElement.className=='file') {
								 			fileExtension=thisElement.value.substring(thisElement.value.lastIndexOf("."),thisElement.value.length);
											if(!supportedFiles.match(fileExtension)) {
													 errorMessage=errorMessage + 'Het veld \"' + thisElement.name + '\" is van het type \"Bestand\" en moet één van onderstaande bestandstypen zijn:\n\n' + supportedFiles + '\n\n';
													 breakFunction=true;
											}
								 }
								 else if(thisElement.className=='zoek') {
											if(isText(thisElement.value)==false) {
													 errorMessage=errorMessage + '» Het veld \"' + thisElement.name + '\" is een zoekveld\n» Gebruik hier geen leestekens.\n';
													 breakFunction=true;
											}
								}
								 else if(thisElement.className=='zoek_req') {
											if((isText(thisElement.value)==false) || (thisElement.value.length<=2)) {
													 errorMessage=errorMessage + '» Het veld \"' + thisElement.name + '\" is een verplicht zoekveld\n» Vul minimaal één woord in van 3 karakters of meer (geen leestekens gebruiken).\n';
													 breakFunction=true;
											}
								}

								 if(breakFunction==true) {
											thisElement.style.background='#cccccc';
											alert(errorMessage);
											thisElement.select();
								      		thisElement.focus();
											return false;
								 }
				 }
}

function isNumeric(thisValue) {
				 for(var x=0;x<thisValue.length;x++) {
				 				 if((thisValue.charAt(x)<"0") || (thisValue.charAt(x)>"9")) {
								 			return false;
											break;
								 }
				 }
}

function isAlpha(thisValue) {
				 for(var x=0;x<thisValue.length;x++) {
				 				 if(!(((thisValue.charAt(x)>="a") && (thisValue.charAt(x)<="z")) || ((thisValue.charAt(x)>="A") && (thisValue.charAt(x)<="Z")))) {
								 			return false;
											break;
								 }
				 }
}

function isText(thisValue) {
	var supportedSpecialChars="àáäèéëêìí.,ïòóöùúü ";
		for(var x=0;x<thisValue.length;x++) {
			if((thisValue.charAt(x)>="a") && (thisValue.charAt(x)<="z")) {
				continue;
			}
			else if((thisValue.charAt(x)>="A") && (thisValue.charAt(x)<="Z")) {
				continue;
			}
			else if((thisValue.charAt(x)>="0") && (thisValue.charAt(x)<="9")) {
				continue;
			}
			//else if(supportedSpecialChars.match(thisValue.charAt(x).toString)) {
			//	continue;
			//}
			else if((thisValue.charAt(x)=="_") || (thisValue.charAt(x)=="-")) {
				continue;
			}
			else {
				return false;
				break;
			}
		}
}

function isDate(objName) {
	//var strDatestyle = "US"; //United States date style
	var strDatestyle = "EU";  //European date style
	var strDate;
	var strDateArray;
	var strDay;
	var strMonth;
	var strYear;
	var intday;
	var intMonth;
	var intYear;
	var booFound = false;
	var datefield = objName;
	var strSeparatorArray = new Array("-"," ","/",".");
	var intElementNr;
	var err = 0;
	var strMonthArray = new Array(12);
	strMonthArray[0] = "01";
	strMonthArray[1] = "02";
	strMonthArray[2] = "03";
	strMonthArray[3] = "04";
	strMonthArray[4] = "05";
	strMonthArray[5] = "06";
	strMonthArray[6] = "07";
	strMonthArray[7] = "08";
	strMonthArray[8] = "09";
	strMonthArray[9] = "10";
	strMonthArray[10] = "11";
	strMonthArray[11] = "12";
	strDate = datefield.value;
	if (strDate.length < 1) {
		return true;
	}
	for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
		if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
			strDateArray = strDate.split(strSeparatorArray[intElementNr]);
			if (strDateArray.length != 3) {
				err = 1;
				return false;
			}
			else {
				strDay = strDateArray[0];
				strMonth = strDateArray[1];
				strYear = strDateArray[2];
			}
			booFound = true;
	 	}
	}
	if (booFound == false) {
		if (strDate.length>5) {
			strDay = strDate.substr(0, 2);
			strMonth = strDate.substr(2, 2);
			strYear = strDate.substr(4);
	   	}
		else {
			return false;
		}
	}
	
	if (strYear.length == 2) {
		strYear = '20' + strYear;
	}
	if (strYear.length == 1) {
       if(strYear>4) {
           strYear = '200' + strYear;       
       }
       else {
       	   strYear = '200' + strYear;       
       }
	}
	
	// US style
	if (strDatestyle == "US") {
		strTemp = strDay;
		strDay = strMonth;
		strMonth = strTemp;
	}
	intday = parseInt(strDay, 10);
	if (isNaN(intday)) {
		err = 2;
		return false;
	}
	intMonth = parseInt(strMonth, 10);
	if (isNaN(intMonth)) {
		for (i = 0;i<12;i++) {
			if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) {
				intMonth = i+1;
				strMonth = strMonthArray[i];
				i = 12;
	   		}
		}
		if (isNaN(intMonth)) {
			err = 3;
			return false;
	  	}
	}
	intYear = parseInt(strYear, 10);
	if (isNaN(intYear)) {
		err = 4;
		return false;
	}
	if (intMonth>12 || intMonth<1) {
		err = 5;
		return false;
	}
	if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
		err = 6;
		return false;
	}
	if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
		err = 7;
		return false;
	}
	if (intMonth == 2) {
		if (intday < 1) {
			err = 8;
			return false;
		}
		if (LeapYear(intYear) == true) {
			if (intday > 29) {
				err = 9;
				return false;
			}
		}
		else {
			if (intday > 28) {
				err = 10;
				return false;
			}
		}
	}
	if(strYear.length!=4) {
		return false;
	}
	if (strDatestyle == "US") {
		datefield.value = strMonthArray[intMonth-1] + " " + intday+" " + strYear;
	}
	else {
		if(intday < 10){
			datefield.value = "0" + intday + "-" + strMonthArray[intMonth-1] + "-" + strYear;
		}
		else {
			datefield.value = intday + "-" + strMonthArray[intMonth-1] + "-" + strYear;
		}
	}
	return true;
}

function LeapYear(intYear) {
	if (intYear % 100 == 0) {
		if (intYear % 400 == 0) {
			return true;
		}
	}
	else {
		if ((intYear % 4) == 0) {
			return true;
		}
	}
	return false;
}

function checkForm(thisFormId) {
	var count=0;
	thisForm=getElement(thisFormId);
	if(thisForm) {
		for(var i=0;i<thisForm.elements.length;i++) {
			if((thisForm.elements[i].value.length>0) && (thisForm.elements[i].className!="submit")) {
				count++;
			}
			if(thisForm.elements[i].className=="submit") {
				break;
			}
		}
		if(count==0) {
			alert("Vul ten minste één van de velden van het formulier in!");
			thisForm.elements[0].focus();
			return false;
		}
		else {
			return true;
		}
	}
}
