// form_validation.js - functions for easy validation of HTML forms.

function ValidateInputNotEmpty(field, errorMessage) {
	if (!field) {
		alert('missing field! ' + errorMessage);
		return false;
	}
	if (!field.value) {
		alert(errorMessage);
		return false;
	}
	return true;
}

function ValidateSelect(field, errorMessage) {
	if (!field) {
		alert('missing field! ' + errorMessage);
		return false;
	}
	if (!field.selectedIndex) {
		alert(errorMessage);
		return false;
	}
	return true;
}






function ValidateNotEmpty(field, fieldName, youForgotLabel) {
	if (!youForgotLabel)
		youForgotLabel = "You forgot to fill in the ";
	return ValidateInputNotEmpty(field, youForgotLabel + fieldName + "!");
}

// validate all fields in the argument list.
// EXAMPLE: onsubmit='return ValidateAllNotEmpty(this, "name", "email")'
function ValidateAllNotEmpty(theForm, youForgotLabel) {
	for (i=1; i<arguments.length; ++i) {
		fieldInternalName = arguments[i];
		fieldName = fieldInternalName.replace(/_/g," ");
		if (!ValidateNotEmpty(theForm[fieldInternalName], fieldName, youForgotLabel))
			return false;
	}
	return true;
}
