addLoadEvent(AdvancedSearchDOM);

function AdvancedSearchDOM() {
	var frmAdvancedSearch = document.getElementById("advancedSearchForm");
	if(frmAdvancedSearch) {
		frmAdvancedSearch.onsubmit = function () {
			return validateAdvancedSearch(this);
		}
	}
}

function kalender(datum, formulier) {
	theWidth = 275;
	theHeight = 200;
	theTop = (screen.height-theHeight*1.5)/2;
	theLeft = (screen.width-theWidth)/2;
	winopts = "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=no,resizable=no,copyhistory=0,width="+theWidth+",height="+theHeight+",top="+theTop+",left="+theLeft;
	smallwindow=window.open("kalender.dhtml?formulier="+formulier+",datum="+datum,"Kalender",winopts);
	smallwindow.focus();
}
function validate_date(day,month,year) {
	var error = 0;
	
	if (isNaN(day) || isNaN(month) || isNaN(year)) {
		error++;
	}
	if(year < 1800) {
		error++;
	}
	if(month < 1 || month > 12) {
		error++;
	}
	if(day < 1 || day > 31) {
		error++;
	}

	if(((month==4)||(month==6)||(month==9)||(month==11))&&(day > 30)) {
		error +=1;
	}
	if(((month==1)||(month==3)||(month==5)||(month==7)||(month==8)||(month==10)||(month==12))&&(day > 31)) {
		error +=1;
	}
	if(month==2) {
		var schrikkeljaar = false;
		if ((year % 4 == 0) ^ (year % 100 == 0) ^ (year % 400 == 0)) {
			 schrikkeljaar = true;
		}
		if ((schrikkeljaar == false)&&(day>28)) {
			error +=1;
		}
		if ((schrikkeljaar == true)&&(day>29)) {
			error +=1;
		}
	}	
	if (error > 0) {
		return false;
	}else{
		return true;
	}
}
function validateAdvancedSearch(theForm) {
	var error = 0;
	var msg = "";
			
	if (theForm.na_dag.value!="" || theForm.na_maand.value!="" || theForm.na_jaar.value!="") {
		if ((theForm.na_dag.value=="" || theForm.na_maand.value=="" || theForm.na_jaar.value=="")
		   || (!validate_date(theForm.na_dag.value, theForm.na_maand.value, theForm.na_jaar.value))) {
				alert("Gelieve een geldige datum tot in te geven.");
				return false;
		}
	}
	return true;
}
