/**
 * Check that the user has actually selected a checkbox or radio value.
 *
 * @param     form
 *            the HTML form containing the checkbox or radio button.
 * @param     fieldName
 *            the name given to the checkbox or radio button field(s).
 * @param     emptyMessage
 *            the message to display if none of the form elements have been
 *            checked.
 * @return    true if at least one of the named checkboxes or radio buttons
 *            has been checked, false otherwise.
 */
function
checkCheckboxSelection(form, fieldName, emptyMessage) {
	with (form) {
		for (var i = 0; i < form.elements.length; i++) {
			if (form.elements[i].name == fieldName &&
			    form.elements[i].checked == true) {
				return true;
			}
		}
	}
	alert(emptyMessage);
	return false;
}

/**
 * Check an email address.
 *
 * @param     emailField
 *            the HTML form text element which contains the email address.
 * @param     errorMessage
 *            the message to display if the contents of the form element is
 *            not a valid email address.
 * @return    true if the contents of the form element are a valid email
 *            address, false otherwise.
 */
function
checkEmail(emailField, errorMessage) {
	var emailAddress = /^([a-zA-Z0-9_\.-]+)@([a-zA-Z0-9_-]+)\.([a-zA-Z0-9_\.-]+)$/;
	if (emailField.value.search(emailAddress) == -1) {
		alert(errorMessage);
		return false;
	}
	return true;
}

/**
 * Check if the user has selected a value greater than a minimum index.
 * This includes checking that something has actually been selected as
 * a minimum.
 *
 * @param     select
 *            the HTML form <select> element.
 * @param     lowestIndex
 *            the lowest valid index for a selection.
 * @param     errorMessage
 *            the message to display if a valid selection has not been
 *            made.
 * @return    true if a valid selection has been chosen from the select
 *            element, false otherwise.
 */
function
checkSelect(select, lowestIndex, errorMessage) {
	if (lowestIndex < -1) {
		lowestIndex = -1;
	}
	if (select.selectedIndex <= lowestIndex) {
		alert(errorMessage);
		return false;
	}
	return true;
}
