/* Generalized client-side validation function for HTML forms.
 *
 * Given a form id, the function checks the values of any
 * input with an id containing the string '_req'.  If the validation
 * passes, true is returned, otehrwise false.  The textarea fields 
 * are checked the same way.
 *
 * If there is a failure, an alert box is displayed requesting the
 * user fill in the field.  The field name is displayed, so the
 * names of the fields should be human readable.
 */
function validateForm(formId) 
{
	var form = document.getElementById(formId);
	if (form) {
		var inputs = form.getElementsByTagName('input');
		if (inputs) {
			for (var i = 0; i < inputs.length; ++i) 
			{
				if (inputs[i].type == 'text' && inputs[i].id.match('_req'))
				{
					if (!validate(inputs[i].value))
					{
						alert("Please enter a value for " + inputs[i].name);
						return false;
					}
				}
			}//endfor
		}
		else
		{
			alert("Error! No Inputs!");
		}

		var areas = form.getElementsByTagName('textarea');
		if (areas) {
			for (var i = 0; i < areas.length; ++i) 
			{
				if (areas[i].name.match('_req'))
				{
					if (!validate(areas[i].value))
					{
						alert("Please enter a value for " + areas[i].name);
						return false;
					}
				}
			}//endfor
		}
		else
		{
			alert("Error! No Areas!");
		}
	}
	else
	{
		alert("Error! No Form!");
		return false;
	}
	return true;
}//end validateForm

/* Checks if the given string is blank.
 * Returns false if so, otherwise true.
 */
function validate(str) 
{
	if (str == '')
	{
		return false;
	}
	return true;
}//end validate