function checktextfield(field, errorlabel) {
	var value = field.value;

	// --- Remove spaces at the beginning and end ----------------------------------------
	value = value.replace(/^\s*/, "").replace(/\s*$/, "");
	field.value = value;

	if (value.length == 0) {
		return "Vul "+errorlabel+" in.\n";
	}
	return "";
}

function checkemailfield(field, mandatory) {
	if (!mandatory && field.value.length == 0) return "";
	if (field.value.search( /^[^\s\@\#\$\%\^\&\*\(\)\+=\{\[\]\}\|\\\/<>!]+@[^\s\@\#\$\%\^\&\*\(\)\+=\{\[\]\}\|\\\/<>!]+\.[^\s\@\#\$\%\^\&\*\(\)\+=\{\[\]\}\|\\\/<>!]+$/) == -1) {
		return "Vul een geldig e-mail adres in.\n";
	}
	return "";
}

function checkphonefield(field, errorlabel, mandatory) {
	var errstr = "";
	
	if (mandatory) {
		errstr = errstr + checktextfield(field, errorlabel);
		if (errstr.length > 0) return errstr;
	}
	
	if (field.value.search(/^\+?[0-9- \(\)]*$/) == -1) {
		return "Vul een geldige waarde voor " + errorlabel + " in.\n";
	}
	return "";
}

function checkintegerfield(field, errorlabel, mandatory, minimum, maximum) {
	var value = parseInt(field.value, 10);
	if (field.value.length > 0 || mandatory) {
		if (isNaN(value)) return "Geef een geldige waarde voor "+errorlabel+".\n";
		if (value < minimum || value > maximum) {
			return "De waarde voor "+errorlabel+" moet liggen tussen "+minimum+" en "+
			maximum+".\n";
		}
	}
	
	if (!isNaN(value)) field.value = value;
	return "";
}

function checkfloatfield(field, errorlabel, mandatory, minimum, maximum) {
	var tmpvalue = field.value.replace(/,/, ".");
	var value = parseFloat(tmpvalue);
	if (field.value.length > 0 || mandatory) {
		if (isNaN(value)) return "Geef een geldige waarde voor "+errorlabel+".\n";
		if (value < minimum || value > maximum) {
			return "De waarde voor "+errorlabel+" moet liggen tussen "+minimum+" en "+
			maximum+".\n";
		}
	}
	
	if (!isNaN(value)) field.value = value;
	return "";
}

function matchfield(field, errstr, pattern) {
	if (field.value.search(pattern) == -1) {
		return errstr;
	}
	return "";
}

function checkdatefield(field, errlabel) {
	var testDate;
	var arrDate = field.value.match(/(\d\d?)[ \/-](\d\d?)[ \/-](\d\d\d\d)/);

	if (arrDate && arrDate.length == 4) {
		// --- First test if all values are numbers --------------------------------------
		if (!isNaN(arrDate[3]) && !isNaN(arrDate[2]) && !isNaN(arrDate[1])) {
			testDate = new Date(arrDate[3], arrDate[2] - 1, arrDate[1]);
			if (arrDate[3] == testDate.getFullYear()
			&&  arrDate[2] - 1 == testDate.getMonth()
			&&  arrDate[1] == testDate.getDate()) {
				return "";
			}
		}
	}
	return "Voor een geldige datum in "+errlabel+" in.\nHet formaat is DD/MM/JJJJ.\n";
}

function getHeight(objectid) {
	var object = (document.getElementById) ? document.getElementById(objectid) : document.all[objectid];
	if (object) {
		if (object.clientHeight) {
			return parseInt(object.clientHeight);
		}else if (window.getComputedStyle(object,null).getPropertyValue('height')) {
			return parseInt(window.getComputedStyle(object,null).getPropertyValue('height'));
		}else{
			return 0;
		}
	}
}

function getWidth(objectid) {
	var object = (document.getElementById) ? document.getElementById(objectid) : document.all[objectid];
	if (object) {
		if (object.clientWidth) {
			return parseInt(object.clientWidth);
		}else if (window.getComputedStyle(object,null).getPropertyValue('width')) {
			return parseInt(window.getComputedStyle(object,null).getPropertyValue('width'));
		}else{
			return 0;
		}
	}
}

function resizeWindow(objid) {
	var height = getHeight(objid);
	var width = getWidth(objid);
	var win_height = (window.innerHeight) ? window.innerHeight : document.body.clientHeight;
	var win_width = (window.innerWidth) ? window.innerWidth : document.body.clientWidth;
	
	if (window.navigator.appName == "Netscape") win_height -= 50;
	
	if (height < 50) height = 50;
	else if (height > 400) height = 400;
	if (width < 200) width = 200;
	else if (width > 400) width = 400;
	self.resizeBy(width - win_width, height - win_height);
	self.focus();
}

function resizeBigWindow(objid) {
	var height = getHeight(objid);
	var width = getWidth(objid);
	var win_height = (window.innerHeight) ? window.innerHeight : document.body.clientHeight;
	var win_width = (window.innerWidth) ? window.innerWidth : document.body.clientWidth;
	
	if (window.navigator.appName == "Netscape") win_height -= 50;
	
	if (height < 50) height = 50;
	else if (height > 600) height = 600;
	if (width < 200) width = 200;
	else if (width > 800) width = 800;
	self.resizeBy(width - win_width, height - win_height);
	//alert("widthxheight = " + width + "x" + height);
	self.focus();
}

function messageWindow(msgurl, scrollbars) {
	window.open(msgurl, "messagewindow", "height=50,width=200,statusbar=no,scrollbars=" + scrollbars + ",left=" + screen.width/3 + ",top=" + screen.height/4);
}

function messageBigWindow(msgurl, scrollbars) {
	window.open(msgurl, "messagewindow", "height=100,width=400,statusbar=no,scrollbars=" + scrollbars + ",left=" + screen.width/5 + ",top=" + screen.height/10);
}

function openAWindow(msgurl, wheight, wwidth, scrollbars) {
	window.open(msgurl, "messagewindow", "height="+wheight+",width="+wwidth+",statusbar=no,scrollbars=" + scrollbars + ",left=" + screen.width/5 + ",top=" + screen.height/10);
}

function submitForm(myform, action) {
	oldaction = myform.action;
	oldtarget = myform.target;
	myform.action = action;
	myform.target = "messagewindow";
	messageWindow("", "no");
	myform.submit();
	myform.action = oldaction;
	myform.target = oldtarget;
}

function setVisibility(objid, state) {
	var divObj = (document.getElementById) ? document.getElementById(objid) : document.all[objid];
	
	if (divObj) {
		divObj.style.visibility = state;
	}
}

function isVisible(objid) {
	var divObj = (document.getElementById) ? document.getElementById(objid) : document.all[objid];
	
	if (divObj) {
		if (divObj.style.visibility == 'visible') {
			return true;
		}
	}
	return false;
}
