//////////////////////////////////////////////////////////////////////
// formCheck.js
//////////////////////////////////////////////////////////////////////
var defaultEmptyOK = false;
var whitespace = " \t\n\r";
var mPrefix = "You did not enter a value into the field for "
var mSuffix = ". This is a required field. Please enter it now."

function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

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;
}

function warnEmpty (theField, s)
{   theField.focus();
    alert(mPrefix + s + mSuffix);
    return false;
}

function checkString (theField, s, emptyOK) {
  var result = false;
  if (checkString.arguments.length == 2) emptyOK = defaultEmptyOK;
  if ((emptyOK == true) && (isEmpty(theField.value))) {
    result = true;
  } else if (isWhitespace(theField.value)) result = warnEmpty (theField, s)
  else result = true;
  return result;
}
