function formValidator(frm)
{
	for( var i = 0; i < frm.elements.length; i++ )
	{
		var el = frm.elements[i];
		if( el.required )
		{
			if( el.type == 'select-one' && el.selectedIndex == 0 )
			{
				alert( 'The "' + el.control_name + '" field requires a selection.' );
				el.focus();
				return false;
			}
			else if( isEmpty( el ) )
			{
				alert( 'The "' + el.control_name + '" field requires an entry.' );
				el.focus();
				return false;
			}
		}
		
		if( el.numeric )
		{
			if( !isNumeric( el ) )
			{
				alert( 'The "' + el.control_name + '" entry must be a number.' );
				el.focus();
				return false;
			}
		}
		
		if( el.valid_email )
		{
			if( !isValidEmail( el.value ) )
			{
				alert( 'The "' + el.control_name + '" field requires a valid email address.' );
				el.focus();
				return false;
			}
		}
		
		if( el.min_length )
		{
			if( !isLongEnough( el.value, el.min_length ) )
			{
				alert( 'The "' + el.control_name + '" field requires a minimum of ' + el.min_length + ' characters.' );
				el.focus();
				return false;
			}
		}
		
		if( el.max_length )
		{
			if( !isShortEnough( el.value, el.max_length ) )
			{
				alert( 'The "' + el.control_name + '" field can have a maximum of ' + el.max_length + ' characters.' );
				el.focus();
				return false;
			}
		}

		if( el.equal_val )
		{
			if( el.value != frm[el.equal_val].value )
			{
				alert( 'The ' + el.control_name + ' field must equal the ' + frm[el.equal_val].control_name + ' field.' );
				return false;
			}
		}
	}
}

function isEmpty( elmnt )
{
	val = elmnt.value.toString();
	if( val == 'undefined' || val == '' || val == '0' || val == 'null' )
	{
		return true;
	}
	return false;
}

function isLongEnough( elmnt, l )
{
	if( elmnt.length < l )
	{
		return false;
	}
	return true;
}

function isShortEnough( elmnt, l )
{
	if( elmnt.length > l )
	{
		return false;
	}
	return true;
}

function isNumeric( elmnt )
{
	var errCount = 0;
	var numdecs = 0;
	var val = elmnt.value;
	for( var j = 0; j < val.length; j++ )
	{
		var c = val.charAt(j);
		if( ( c >= 0 && c <= 9 ) || c=='.' || ( j==0 && c == '-' ) )
		{
			if( c=='.' )
			{
				numdecs++;
			}
		}
		else
		{
			errCount++;
			break;
		}
	}
	if( errCount > 0 || numdecs > 1 )
	{
		return false;
	}
	return true;
}

function isValidEmail( em )
{
	var pattern = new RegExp( /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/i );
	return( pattern.test( em ) );
}