// Test a field's value and optionally display an error message
function validateFieldValue( fieldName, excludeValue, errMsg )
{
	// fieldName is the name of a field on the form named "valid".  If the field is on a different form, pass field object directly to validateFieldValueObj
	// excludeValue is an optional string value to match against.  If matched, the field is considered empty.
	// errMsg is an optional error message which is displayed if a field is empty.

	var thisField = eval( 'document.valid.' + fieldName );
	return validateFieldValueObj( thisField, excludeValue, errMsg );
}

function validateFieldValueObj( thisField, excludeValue, errMsg )
{
	var thisValue = getFieldValue( thisField );

//	thisValue = thisValue.toLowerCase();
//	var excludeValueLower = excludeValue.toLowerCase();

//	alert( 'thisValue = ' + thisValue )
//	alert( 'excludeValueLower  = ' + excludeValueLower  );

	if (thisValue == "" || thisValue.toLowerCase() == excludeValue.toLowerCase() ) {
		if (errMsg != "") {
			alert( errMsg );
		}
		return false;
	}
	return true;
}

// Get a field's first value by name
function getFieldValueByName( fieldName ) {
var thisField = eval( 'document.valid.' + fieldName );
return getFieldValue( thisField );
}


// Get a field's first value by object
function getFieldValue( thisField ) {
//	var thisField = eval( 'document.valid.' + fieldName );
	
	switch (getValueType( thisField ) ) {
		case "text":
			return thisField.value

		case "select":
			if (thisField.selectedIndex < 0) {
				return "";
			} else {
				return thisField.options[thisField.selectedIndex].value;
			}

		case "check":
			if (thisField.length) {
				for (i = 0; i < thisField.length; i++) {
					if (thisField[i].checked) { return thisField[i].value };
				}
			}
			return "";
			
		default:
			return "";
	}
}


// Get the type of value handling needed for a input object
function getValueType( thisField ) {
	if (!thisField.type) {
		return "check";
	} else {
		switch( thisField.type ) {
			case "text":
			case "textarea":
			case "password":
			case "hidden":
				return "text";

			case "select-one":
			case "select-multiple":
				return "select";

			default:
				return "??"
		}
	}
}

