// given a field name, return the first matching field's value, if any
function getValueByFieldName(fieldName) {
//fieldName MUST be specified; formName MAY be specified as optional second parameter
var testing=false;
var fieldName;
var fieldIndex, formIndex;
var theField, theForm;
var values=new Array();
for (formIndex=0;formIndex < document.forms.length; formIndex++) {
theForm=document.forms[formIndex];
//if (testing) alert('getValueByFieldName is examining form named "'+theForm.name+'"');//testing
	if (arguments.length>1 && arguments[1]!=theForm.name) continue;
	for (fieldIndex=0 ; fieldIndex < theForm.elements.length; fieldIndex++) {
	theField=theForm.elements[fieldIndex];
//if (testing) alert('getValueByFieldName is examining field named "'+theField.name+'"');//testing
		if (theField.name != fieldName) continue;
if (testing) alert('getValueByFieldName found a '+theField.type+' field named "'+theField.name+' in a form named "'+theForm.name+'"');//testing
		switch (theField.type) {
			case 'radio':
			case 'checkbox':
if(testing) alert('radio/checkbox "checked" property: '+theField.checked);//testing
				if (theField.checked) values[values.length]= theField.value;
				break;
			case 'select':
				values[values.length]= theField.options[theField.selectedIndex].value;
				break;
			case 'text':
			default:
				values[values.length]= theField.value;
			}//switch
		}//for element
	}//for form
switch (values.length) {
	case 0:
		return '';
		break;
	case 1:
		return values[0];
		break;
	default://actually, probably the exception, but switch doesn't allow >1 as a condition
		return values;//all of them!
	}//switch
}//function
		
