function VAL(FORM){
	var inp = document.getElementById(FORM).getElementsByTagName('input'); var sel = document.getElementById(FORM).getElementsByTagName('select');
	var RED = 'red'; var color = 'white'; var Error = false;
	for(i=0; i < inp.length; i++){ 
		if(inp[i].className.match("VAL_DATE") != null){ if(DATE_validator(inp[i]) == false){ inp[i].style.backgroundColor = RED; Error = true; }else{ inp[i].style.backgroundColor = color; } }
		else if(inp[i].className.match("VAL_NUM") != null){ if(NUM_validator(inp[i].value) == false){ inp[i].style.backgroundColor = RED; Error = true; }else{ inp[i].style.backgroundColor = color; } }
		else if(inp[i].className.match("VAL_trueNUM") != null){ if(true_NUM(inp[i].value) == false){ inp[i].style.backgroundColor = RED; Error = true; }else{ inp[i].style.backgroundColor = color; } }
		else if(inp[i].className.match("VAL_PC") != null){ if(PC_validator(inp[i].value) == false){ inp[i].style.backgroundColor = RED; Error = true; }else{ inp[i].style.backgroundColor = color; } }
		else if(inp[i].className.match("VAL_PROC") != null){ if(PROC_validator(inp[i].value) == false){ inp[i].style.backgroundColor = RED; Error = true;  }else{ inp[i].style.backgroundColor = color; } }
		else if(inp[i].className.match("VAL_CUR") != null){
			if(CUR_validator(inp[i].value) == 'FALSE'){ inp[i].style.backgroundColor = RED; Error = true; } else { inp[i].value = CUR_validator(inp[i].value); inp[i].style.backgroundColor = color; }
		} else{ inp[i].style.backgroundColor = color; } 
	} for(i=0; i < sel.length; i++){ 
		if(sel[i].className.match("VAL_SEL") != null){ if(sel[i].value == '0'){ sel[i].style.backgroundColor = RED; Error = true; }else{ sel[i].style.backgroundColor = color; } }
	} if(Error == true){ return false; } else { document.getElementById(FORM).submit(); }
}

function DATE_validator(veld){
	var checkstr = "0123456789"; var Datevalue, DateTemp = ""; var seperator = "-"; var day, month, year, i; var leap = 0; var err = false;
		DateValue = veld.value; for(i = 0; i < DateValue.length; i++) { if (checkstr.indexOf(DateValue.substr(i,1)) >= 0) { DateTemp = DateTemp + DateValue.substr(i,1); } }
		DateValue = DateTemp; if(DateValue.length == 6) { DateValue = DateValue.substr(0,4) + '20' + DateValue.substr(4,2); } if(DateValue.length != 8) { err = true;}
		year = DateValue.substr(4,4); if(year == 0) { err = true; }
		month = DateValue.substr(2,2); if((month < 1) || (month > 12)) { err = true; }
		day = DateValue.substr(0,2);
	if(day < 1) { err = true; }
	if((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) { leap = 1; }
	if((month == 2) && (leap == 1) && (day > 29)) { err = true; }
	if((month == 2) && (leap != 1) && (day > 28)) { err = true; }
	if((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) { err = true; }
	if((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) { err = true; }
	if(err == false){ veld.value = day + seperator + month + seperator + year; }
	else { return false; }
}

function NUM_validator(veld) { 
	var NUM = "0123456789-"; var Error = false; for (z = 0; z < veld.length; z++){ var char = veld.charAt(z); if(NUM.indexOf(char) == -1){ Error = true; } } if(Error == true){ return false; }
}

function true_NUM(veld) { 
	var NUM = "0123456789"; var Error = false; for (z = 0; z < veld.length; z++){ var char = veld.charAt(z); if(NUM.indexOf(char) == -1){ Error = true; } } if(Error == true){ return false; }
}

function PC_validator(veld) { 
	var NUM = "0123456789"; var Error = false; if(veld.length != 4){ Error = true; return false; }; if((veld*1) < 1000 || (veld*1) > 9999){ Error = true; return false; }
		for (z = 0; z < veld.length; z++){ var char = veld.charAt(z); if(NUM.indexOf(char) == -1){ Error = true; } } if(Error == true){ return false; }
}

function PROC_validator(veld) { 
	var NUM = "0123456789"; var Error = false; if(veld > 100){ Error = true; } for (z = 0; z < veld.length; z++){ var char = veld.charAt(z); if(NUM.indexOf(char) == -1){ Error = true; } } if(Error == true){ return false; }
}
	
function CUR_validator(veld,NOINPUT){
	if(NOINPUT == null){ veld = veld.replace(/,/, "."); } var NUM = "0123456789."; var Error = false; for (z = 0; z < veld.length; z++){ var char = veld.charAt(z); if(NUM.indexOf(char) == -1){ Error = true; } }
	if(Error == true){ return 'FALSE'; } else { veld = veld === '' || veld === null ? 0.00 : veld; return parseFloat(veld).toFixed(2); }
}

function bigimage(thischeck){
	if(thischeck.checked == 1){
		document.getElementById("spanAfb").style.display = "block";
		document.getElementById("afbeelding").style.display = "block";
	}else{
		var parent = document.getElementById('fileInputContainer'),
		newFileInput = document.createElement('input');
		parent.removeChild(document.getElementById('afbeelding'));
		newFileInput.setAttribute('type', 'file');
		newFileInput.setAttribute('id', 'afbeelding');
		newFileInput.setAttribute('style', 'color: #c177FF; width: 90%;');
		parent.appendChild(newFileInput);
		document.getElementById("spanAfb").style.display = "none";
		document.getElementById("afbeelding").style.display = "none";
	}
}

function validate_required(field){
	with(field){ if(value == null || value == ""){ return false; } else{ return true; } }
}
function validate_email(field){
	with(field){ apos = value.indexOf("@"); dotpos=value.lastIndexOf("."); if(apos < 1 || dotpos-apos < 2){ return false; } else { return true; } }
}
function validate_phone(field) {
	with(field){ var stripped = value.replace(/[\(\)\.\-\ ]/g, ''); if(isNaN(parseInt(stripped)) || !(stripped.length == 10)){ return false; } else { value = stripped; return true; } }
}
function validate_postcode(field) {
with(field){if(!value.match(/[1-9][0-9]{3}[a-zA-Z]{2}/)){return false;} else{return true;}}
}

	