		
	// ********************************************************************************************************
	// This script was written by Merrick - www.merrick.nl - info@merrick.nl
	// Unauthorized copying or distribution is not allowed
	// Author: J.E. Hoppenbrouwers
	// Version: 4.2
	// Date: 6 august 2004
	// ********************************************************************************************************

	function validatePrompt (veld, PromptStr) {
	    alert(PromptStr);
	    veld.focus();
	    //alert(veld.type);
	    if (veld.type == 'text') {
			veld.select();
		}
	}
    
    function testcheckedcount(field, min, max, description) {
		text_min = "Please select at least " + min + " option on question '" + description + "'.";
		text_max = "Please select no more than " + max + " options on question '" + description + "'.";
		var checkedCount = 0
		for (var i = 0; i < field.length; i++) {
			if (field[i].checked) {
				checkedCount++
			}
		}
		if (checkedCount < min) {
			alert (text_min);
			field[0].focus();
			return (false);
		}
		if (checkedCount > max) {
			alert (text_max);
			field[0].focus();
			return (false);
		}
		return (true);	
    }
    
    
	function testcurrency(field, description, emptyok) {
		if (!emptyok) {
			text = "Field '" + description + "' contains an unvalid amount.";
		}
		else {
			text = "Field '" + description + "' must contain a valid amount.";
		}
		if (field.value == "" || field.value == " ") {
			if (!emptyok) {
				validatePrompt (field, text);
				return (false);
			}
			else {
				return (true);
			}
		}
		i = field.value.indexOf(".");
		j = field.value.indexOf(",");
		if (((i == -1) && (j == -1)) || ((i != -1) && (j != -1)) || emptyok) {
			validatePrompt (field, text);
			return (false);
		}
		if ((i == -1) && (j != -1)) {
			i = j;
		}
		part1 = field.value.substring(0,i);
		part2 = field.value.substring(i+1, field.value.length);		
		if (isNaN(part1) || isNaN(part2)) {
			validatePrompt (field, text);
			return (false);
		}
		if (part2.length != 2) {
			validatePrompt (field, text);
			return (false);
		}	
		field.value = part1 + "," + part2
		return (true);
	}

    function testtime (field, description, emptyok) {
		if (!emptyok) {
			text = "Field '" + description + "' must contain a valid time."
		}
		else {
			text = "Field '" + description + "' contains an unvalid time."
		}
		text = text + "\n\nPlease enter a time in the following format:\n  two numbers for the hour (00-23),\n  period (:),\n  two numbers for minutes (00-59)."			
		if (field.value == "" || field.value == " ") {
			if (!emptyok) {
				validatePrompt (field, text);
				return (false);
			}
			else {
				return (true);
			}
		}
		if (field.value.length != 5) {
			validatePrompt (field, text);
			return (false);
		}
		if (field.value.substring(2,3) != ":") {
			validatePrompt (field, text);
			return (false);			
		}
		hours = field.value.substring(0,2);
		if (isNaN(hours)) {
			validatePrompt (field, text);
			return (false);			
		}
		if ((hours < 0) || (hours > 23)) {
			validatePrompt (field, text);
			return (false);			
		}
		minutes = field.value.substring(3,5);
		if (isNaN(minutes)) {
			validatePrompt (field, text);
			return (false);			
		}
		if ((minutes < 0) || (minutes > 59)) {
			validatePrompt (field, text);
			return (false);			
		}					
		return (true);
    }

    function testdate (field1, field2, field3, description, emptyok) {
		if (!emptyok) {
			text = "Field '" + description + "' is a required field and must contain a valid date."
		}
		else {
			text = "Field '" + description + "' contains an unvalid date."
		}
		text = text + "\n\nPlease enter dates in the following format:\n  two digits for the day,\n  two digits for the month,\n  four digits for the year."
		if ((field1.value != "" && field1.value != " ") || (field2.value != "" && field2.value != " ") || (field3.value != "" && field3.value != " ")) {
			field_total = field1.value + "-" + field2.value + "-" + field3.value
			if (field_total.length != 10) {
			    alert (text);
			    field1.focus();
			    return (false);
			}
			// characters 3 and 5 must be -
			if (field_total.substring(2,3) != "-" || field_total.substring(5,6) != "-") {
			    alert (text);
			    field1.focus();
			    return (false);
			}
			// get the respective day, month and year parts
			day = field_total.substring(0,2);
			month = field_total.substring(3,5);
			year = field_total.substring(6,10);
			// check whether the respective date parts are valid
			var today = new Date();
			year = ((!year) ? today.getYear():year);
			year = ((!year) ? y2k(today.getYear()):year);
			month = ((!month) ? today.getMonth():month-1);
			if (!day) {
			    alert (text);
			    field1.focus();
			    return (false);
			}
			var test = new Date(year,month,day);
			if ( (y2k(test.getYear()) == year) && (month == test.getMonth()) && (day == test.getDate()) ) {
			    return (true);
			}
		}
		else {
			if (emptyok == false) {
			    validatePrompt (field1, text);
			    return (false);
			}
		}
		return (true);
	}
    

	function testminutes (field1, field2, description, emptyok) {
		if (!emptyok) {
			text = "Please fill in field '" + description + "'."
		}
		else {
			text = "The value in field '" + description + "' is not valid."			
		}
		if ((field1.value == "" || field1.value == " ") && (field2.value == "" || field2.value == " ")){
			if (!emptyok) {
				validatePrompt (field1, text);
				return (false);
			}
			else {
				return (true);
			}
		}
		if (field2.value == "" || field2.value == " ") {
			field2.value = 0;
		}
		else {
			if (isNaN(field2.value)) {
			    validatePrompt (field1, text);
			    return (false);
			}
		}
		minutes = field2.value;
		if (field1.value == "" || field1.value == " ") {
			field1.value = 0;
		}
		else {
			if (isNaN(field1.value)) {
			    validatePrompt (field1, text);
			    return (false);
			}
		}
		hours = field1.value * 60;
		time = hours + minutes;
		if (time == 0) {
			if (!emptyok) {
			    validatePrompt (field1, text);
			    return (false);
			}
			else {
				return (true);
			}
		}
		else {
			return (true);
		}		
	}


	function testnumber (field, description, emptyok) {
		if (!emptyok) {
			text = "Please fill in '" + description + "' (numbers only)."
		}
		else {
			text = "Field '" + description + "' may only contain digits."
		}
    // value must be non-empty and only consists of numbers
        if (field.value != "" && field.value != " ") {
			for (var i = 0; i < field.value.length; i++) {
			    temp = field.value.charAt(i);
			    if (isNaN(temp) || temp == "") {
			        validatePrompt (field, text);
			        return (false);
			    }
			}
		}
		else {
			if (!emptyok) {			        
				validatePrompt (field, text );
				return (false);
			}
        }
        return (true);
    }
    
    
	function testcheck (field, description) {
		text = "You must check option '" + description + "'.";
		if (!field.checked) {
			validatePrompt (field, text);
			field.focus();
			return (false);
		}
		return (true);
	}

	function testradio (field, description, fulltext) {
		if (fulltext != '') {
			text = fulltext;
		} else {
			text = "Please select one of the options of '" + description + "'.";
		}
	    anythingchecked = 0;
	    for (var i = 0; i < field.length; i++) {
	        if (field[i].checked) {
	            anythingchecked = 1;
	            break;
	        }
	    }
	    if (anythingchecked == 0) {
	        validatePrompt (field[0], text);
	        field[0].focus();
	        return (false);
	    }
	    return (true);
	}

	function testnonum(field, description, emptyok) {
		if (field.value == '') {
			text = "Field '" + description + "' is a required field."
		}
		else {
			text = "Field '" + description + "' can not contain numbers."
		}
		// value must be non-empty and not contain numbers
	    if (field.value != "" && field.value != " ") {			
			for (var i = 0; i < field.value.length; i++) {
			    temp = field.value.charAt(i);
			    if (!isNaN(temp) && temp != ' ') {
			        validatePrompt (field, text);
			        return (false);
			    }
			}
		}
		else {
			if (!emptyok) {			        
				validatePrompt (field, text );
				return (false);
			}
	    }
	    return (true);
	}


    function testnotemptyorspace (field, description) {
		text = "Field '" + description + "' is a required field.";
        if (field.value == "" || field.value == " ") {
            validatePrompt (field, text);
            field.focus();
            return (false);
        }
        return (true);
    }

    function testpostcode (field_num, field_alpha, description, emptyok) {
		if (!emptyok) {
			text = "Field '" + description + "' must contain data, but may only contain a valid Dutch postcode.";
		}
		else {
			text = "Field '" + description + "' contains an invalid postcode."
		}
		if (field_num.value != "" && field_num.value != " ") {
			for (var i = 0; i < 4; i++) {
			    temp = field_num.value.charAt(i);
			    if (isNaN(temp) || temp == "") {
			        validatePrompt (field_num, text);
			        return (false);
			    }
			    if (i == 0 && temp == 0) {
			        validatePrompt (field_num, text);
			        return (false);
			    }
			}
			if (!testpostcodealpha(field_alpha, description, emptyok)) {
				return (false);
			}
		}
		else {
			if (emptyok == false) {
			    validatePrompt (field_num, text);
			    return (false);
			}
		}
      	return (true);
    }
    
    function testpostcodealpha (field, description, emptyok) {
		if (!emptyok) {
			text = "Field '" + description + "' must contain data, but may only contain a valid Dutch postcode.";
		}
		else {
			text = "Field '" + description + "' contains an invalid postcode."
		}
		if (field.value != "" && field.value != " ") {
			if (field.value.length != 2) {
				validatePrompt (field, text);
				return (false);
			}
			for (var i = 0; i < 2; i++) {
			    temp_ascii = field.value.charCodeAt(i);
			    if (temp_ascii < 65 || temp_ascii > 122 || field.value == "")  {
					validatePrompt (field, text);
					return (false);
			    }
			    if (i == 0 && temp_ascii == 0) {
			        validatePrompt (field, text);
			        return (false);
			    }
			}
		}
		else {
			if (emptyok == false) {
			    validatePrompt (field, text);
			    return (false);
			}
		}
		return (true);
	}

    function y2k(number) {
        return (number < 1000) ? number + 1900 : number;
    }

	function testphone (field, description, emptyok, mobileok) {
		if (field.value == '') {
			text = "Field '" + description + "' must contain a valid phone number.\n\n(10 digits, plus the dash)";
		}
		else {
			text = "Field '" + description + "' contains an invalid phone number.\n\n(10 digits, plus the dash)";
		}
		
		if (field.value != "" && field.value != " ") {
			if ((field.value == "" || field.value == " ") || (field.value.length != 11)) {
				validatePrompt (field, text);
				return (false);
			}
			if (field.value.charAt(0) != '0') {
			    validatePrompt (field, text);
			    return (false);
			}
			var i = 1;
			var sLength = field.value.length;
			for (var i = 0; i < sLength; i++) {
			    temp = field.value.charAt(i);
			    if (isNaN(temp) && (temp != "-")) {
			        validatePrompt (field, text);
			        return (false);
			    }
			}
			var i = 1;
			while ((i < sLength) && (field.value.charAt(i) != "-")) {
			    i++
			}
			if ((i >= sLength) || (field.value.charAt(i) != "-")) {
			    validatePrompt (field, text);
			    return (false);
			}
				
			var temp = '';
			for (var i = 0; i < sLength; i++) {		    
			    if (field.value.charAt(i) != "-") {
					temp = temp + field.value.charAt(i);
			    }
			}
			if (temp == '0000000000' || temp == '1111111111' || temp == '2222222222' || temp == '3333333333' || temp == '4444444444' || temp == '5555555555' || temp == '6666666666' || temp == '7777777777' || temp == '8888888888' || temp == '999999999') {
			    validatePrompt (field, text);
			    return (false);
			}
			if (!mobileok && field.value.charAt(1) == '6') {
				//text = "In het veld '" + description + "' staat geen geldig telefoonnummer.\n\nVul s.v.p. uw telefoonnummer zonder spaties in (10 cijfers, maar 11 tekens inclusief het scheidingsteken)";
			    validatePrompt (field, "In het veld '" + description + "' mag geen mobiel nummer ingevuld worden.");
			    return (false);
			}
		}
		else {
			if (emptyok == false) {
			    validatePrompt (field, text);
			    return (false);
			}
		}
		return (true);
	}
	
	
    function testshortdate (field1, field2, field3, description, emptyok) {
        text = "Invalid date!";
		// we only accept dates formatted like dd-mm-yyyy or dd/mm/yyyy
		// if the length is unequal to 8, the date is not valid
		// the only exception is when empty variable is equal to "emptyok"
		if ((field1.value != "" && field1.value != " ") || (field2.value != "" && field2.value != " ") || (field3.value != "" && field3.value != " ")) {
			field_total = field1.value + "-" + field2.value + "-" + field3.value
			if (field_total.length != 8) {
			    alert (text);
			    field1.focus();
			    return (false);
			}
			// characters 3 and 5 must be -
			if (field_total.substring(2,3) != "-" || field_total.substring(5,6) != "-") {
			    alert (text);
			    field1.focus();
			    return (false);
			}
			// get the respective day, month and year parts
			day = field_total.substring(0,2);
			month = field_total.substring(3,5);
			year = field_total.substring(6,8);
			if (day > 31) {
			    alert (text);
			    field1.focus();
			    return (false);
			}
			if (month > 12) {
			    alert (text);
			    field1.focus();
			    return (false);
			}				
			// check whether the respective date parts are valid
			var today = new Date();
			year = ((!year) ? today.getYear():year);
			year = ((!year) ? y2k(today.getYear()):year);
			month = ((!month) ? today.getMonth():month-1);
			if (!day) {
			    alert (text);
			    field1.focus();
			    return (false);
			}
			var test = new Date(year,month,day);
			if ( (y2k(test.getYear()) == year) && (month == test.getMonth()) && (day == test.getDate()) ) {
			    return (true);
			}
		}
		else {
			if (emptyok == false) {
			    validatePrompt (field1, text);
			    return (false);
			}
		}
		return (true);
	}
    
    
    function testemail (field, description, emptyok) {
		if (!emptyok) {
			text = "Field '" + description + "' must contain data, but may only be a valid e-mail adress.";
		}
		else {
			text = "Field '" + description + "' contains an invalid e-mail adress."
		}
		if (field.value != "" && field.value != " ") {
			var i = 1;
			var sLength = field.value.length;
			while ((i < sLength) && (field.value.charAt(i) != "@")) {
			    i++
			}

			if ((i >= sLength) || (field.value.charAt(i) != "@")) {
			    validatePrompt (field, text);
			    return (false);
			}
			else i += 2;

			// look for .
			while ((i < sLength) && (field.value.charAt(i) != ".")) {
			    i++
			}

			// there must be at least one character after the .
			if ((i >= sLength - 1) || (field.value.charAt(i) != ".")) {
			    validatePrompt (field, text);
			    return (false);
			}
		}
		else {
			if (emptyok == false) {
			    validatePrompt (field, text);
			    return (false);
			}
		}
		return (true);
    }

	function testtextlength(field, minlength, maxlength, description) {
		text1 = "Field '" + description + "' does not contain enough text.\nYou need to enter at least " + minlength + " characters. You now have " + field.value.length + " characters.";
		text2 = "Field '" + description + "' contains too many characters.\nYou may only enter " + maxlength + " characters. You now have " + field.value.length + " characters.";
		if (field.value.length < minlength) {
		    validatePrompt (field, text1);
        	return false;
    	}
		if (field.value.length > maxlength) {
		    validatePrompt (field, text2);
        	return false;
    	}
    	return (true);
	}

	function testpulldown(field, description) {
		text = "Please select one of the available options in field '" + description + "'.";
		if (field.selectedIndex == 0) {
			validatePrompt (field, text);
			return (false);
		}
		return (true);
	}
	
	function testpassword(field1, field2, description) {
		text = "The two fields for '" + description + "' contain different data. Both fields need to be identical.";
		if (field1.value != field2.value) {
			field1.value = ""
			field2.value = ""
			validatePrompt (field1, text);
			return (false);
		}
		return (true);
	}
