// m is an abbreviation for "missing"
var mPrefix = "You did not enter a value into the "
var mSuffix = " field. This is a required field."

// Global variable defaultEmptyOK defines default return value 
// for many functions when they are passed the empty string.
var defaultEmptyOK = false

// whitespace characters
var whitespace = " \t\n\r";

// s is an abbreviation for "string"


// Notify user that required field theField is empty.
// String s describes expected contents of theField.value.
// Put focus in theField and return false.
function warnEmpty (theField, s)
{
	alert(mPrefix + s + mSuffix)
	theField.focus();
	return false
}


// Check whether string s is empty.
function isEmpty(s)
{
	return ((s == null) || (s.length == 0))
}


// Returns true if string s is empty or 
// whitespace characters only.
function isWhitespace (s)
{   
	var i;

    // Is s empty?
    if (isEmpty(s)) return true;

    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);

        if (whitespace.indexOf(c) == -1) return false;
    }

    // All characters are whitespace.
    return true;
}

// checkString (TEXTFIELD theField, STRING s, [, BOOLEAN emptyOK==false])
//
// Check that string theField.value is not all whitespace.
function checkString (theField, s, emptyOK)
{   
	// Next line is needed on NN3 to avoid "undefined is not a number" error
    // in equality comparison below.
    if (checkString.arguments.length == 2)
	{
		emptyOK = defaultEmptyOK;
	}

    if ((emptyOK == true) && (isEmpty(theField.value))) 
	{
		return true;
	}

    if (isWhitespace(theField.value))
	{
       return warnEmpty (theField, s);
	}
    else
	{
		return true;
	}
}
