function isEmptyText(tb, fname) {

	if (tb.value.length == 0) {
		tb.focus();
		alert('Please enter a value for ' + fname);
		return true;
	}
	return false;
}

function isEmptyLb(lb, fname) {

	if (lb.options[lb.selectedIndex].value.length == 0) {
		lb.focus();
		alert('Please choose a value for ' + fname);
		return true;
	}
	return false;
}
// Routines to enable validation of form text fields.
//

function isPopulated(inpObj, fieldName, beSilent)
{
	var re = /^\s+$/

    OK = re.exec(inpObj.value)
	if ((inpObj.value.length == 0) || OK)
	{
		if (beSilent == 1) {
			return false
		}
		inpObj.focus()
		alert('A value for ' + fieldName + ' is required')
		return false
	}
	
	return true
}

function isInteger(inpObj, fieldName)
{
	if (!isNumeric(inpObj, fieldName))
		return false

	var intVal = parseInt(inpObj.value)

	if (isNaN(intVal))
	{
		inpObj.focus()
		alert('Invalid Integer for ' + fieldName)
		return false
	}

	if (intVal != inpObj.value)
	{
		inpObj.focus()
		alert('Invalid Integer for ' + fieldName)
		return false
	}

	return true
}

function isNumeric(inpObj, fieldName)
{
	if (!isPopulated(inpObj, fieldName, 1)) {
		return true;
	}

	var floatVal = parseFloat(inpObj.value)

	if (isNaN(floatVal))
	{	
		inpObj.focus()
		alert('Invalid numeric value for ' + fieldName)
		return false
	}

	if (floatVal != inpObj.value)
	{
		inpObj.focus()
		alert('Invalid characters in ' + fieldName)
		return false
	}

	return true
}

// If a form has several fields, and the requirement is that at least one of
//	them must contain a value, use this function to check the fields.
//
// Takes a single array param which holds all fields to check.
//
function atLeastOne(formFields) {
	for (i=0; i<formFields.length; i++) {
		if (isPopulated(formFields[i], 'ignore', 1)) {
			return true
		}
	}
	formFields[0].focus()
	alert('Please fill in at least one field.')

	return false;
}

function timeCheck(timeval) {

	var re = /^(\d+):(\d{2})$/

	if (!re.test(timeval)) {
		alert('Invalid time value');
		return false;
	}	

	t = re.exec(timeval)
	if ((t[1] < 0) || (t[1] > 23)) {
		alert('Hours are invalid');
		return false;
	}

	if ((t[2] < 0) || (t[2] > 59)) {
		alert('Minutes are invalid');
		return false;
	}

	return true;

}
