/*
 *  Form Validation Script
 *  Copyright (c) 2006 David Parker
 *  pcs@davidparker.org
 *
 */
        function checkRequired(o, fieldName) {
                if (o.value == "") {
                        alert("Please enter a value for " + fieldName);
                        o.focus();
                        return false;
                }
                return true;
        }

        function checkRequiredNumeric(o, length, fieldName) {
                var strValidChars = "0123456789";
                var strChar;
                var blnResult = true;
                var strString;

                strString = o.value;

                if (strString.length != length) {
                        alert("Please enter a " + length + "-digit value for " + fieldName);
                        o.focus();
                        return false;
                }

                //  test strString consists of valid characters listed above
                for (i = 0; i < strString.length && blnResult == true; i++)
                {
                        strChar = strString.charAt(i);
                        if (strValidChars.indexOf(strChar) == -1)
                        {
                                alert("Please enter a numeric value for " + fieldName);
                                o.focus();
                                blnResult = false;
                        }
                }
                return blnResult;
        }
	
	function checkMinLength(o, minLength, fieldName) {
		if (o.value.length < minLength) {
			alert(fieldName + " must be at least " + minLength + " characters");
			o.focus();
			return false;
		}
		return true;
	}

	function checkMaxLength(o, maxLength, fieldName) {
		if (o.value.length > maxLength) {
			alert(fieldName + " must contain no more than " + maxLength + " characters");
			o.focus();
			return false;
		}
		return true;
	}

	// If optional is true, then it's not a required field.
	function checkEmailSyntax(o, optional, fieldName) {
		if (optional && o.value == "") {
			return true;
		}

		if (/^[^ ]+@[^ ]+\.\w{2,}$/.test(o.value)){
			return true;
		} else {
			alert(fieldName + " isn't in a valid format. Please re-enter it.");
			o.focus();
		}
	}
