<!--
	// This file contains the data validation JavaScript functions

// DEFINE VARIABLES
var whitespace = " \t\n\r";
var defaultEmptyOK = false;
var digits = "0123456789";
var lowercaseLetters = "abcdefghijklmnopqrstuvwxyz"
var uppercaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
var digitsInUSPhoneNumber = 10;
/****************************************************************/
// 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;
    if (isEmpty(s)) return true;
    for (i = 0; i < s.length; i++)
    {   
		var c = s.charAt(i);
		if (whitespace.indexOf(c) == -1) return false;
    }
    return true;
}
/****************************************************************/
// Returns the number of non-whitespace characters in a string.
function nonWhitespaceChars(s)
{   var i,j;
    if (isEmpty(s)) return 0;
	j=0;
    for (i = 0; i < s.length; i++)
    {   
		var c = s.charAt(i);
		if (whitespace.indexOf(c) == -1) j++;
    }
    return j;
}
/****************************************************************/
// isEmail (STRING s [, BOOLEAN emptyOK])
// 
// Email address must be of form a@b.c ... in other words:
// * there must be at least one character before the @
// * there must be at least one character before and after the .
// * the characters @ and . are both required
function isEmail(s)
{   if (isEmpty(s)) return false;
    if (isWhitespace(s)) return false;
    var i = 1;
    var sLength = s.length;
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }
    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}
/****************************************************************/
// Checks to see if a required field is blank.  If it is, a warning
// message is displayed...
function ForceEntry(objField, FieldName)
{
	var strField = new String(objField.value);
	if (isWhitespace(strField)) {
		alert("You need to enter information for " + FieldName);
		objField.focus();
		objField.select();
		return false;
	}
	return true;
}
/****************************************************************/
// Returns true if the string passed in is a valid number
//  (no alpha characters), else it displays an error message
function ForceNumber(objField, FieldName)
{
	var strField = new String(objField.value);
	if (isWhitespace(strField)) return true;
	var i = 0;
	for (i = 0; i < strField.length; i++)
		if (strField.charAt(i) < '0' || strField.charAt(i) > '9') {
			alert(FieldName + " must be a valid numeric entry.  Please do not use commas or dollar signs or any non-numeric symbols.");
			objField.focus();
			return false;
		}
	return true;
}
/****************************************************************/
// Returns true if the string passed in is a valid money
//  (no alpha characters except a decimal place), 
//   else it displays an error message

function ForceMoney(objField, FieldName)
{
	var strField = new String(objField.value);
	
    if (isEmpty(strField)) 
	{
		if (ForceMoney.arguments.length == 2) return defaultEmptyOK;
       	else return (ForceMoney.arguments[2] == true);
	}

	if (isWhitespace(strField))
	{
		alert("Please enter the " + FieldName + ".");
		return false;
	} 
	var i = 0;
		if ((strField.charAt(0) < '0' || strField.charAt(i) > '9') && (strField.charAt(i) != '.') && (strField.charAt(i) != '-')) {
			alert(FieldName + " must be a valid numeric entry. Please do not use commas or dollar signs or any non-numeric symbols.");
			objField.focus();
			return false;
		}
	for (i = 1; i < strField.length; i++)
		if ((strField.charAt(i) < '0' || strField.charAt(i) > '9') && (strField.charAt(i) != '.')) {
			alert(FieldName + " must be a valid numeric entry. Please do not use commas or dollar signs or any non-numeric symbols. Negative values must be preceeded by a minus sign (no spaces). ");
			objField.focus();
			return false;
		}
	return true;
}
// Removes all characters which appear in string bag from string s.
/****************************************************************/
function stripCharsInBag (s, bag)
{   var i;
    var returnString = "";
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}
/****************************************************************/
// Removes all whitespace characters from s.
// Global variable whitespace (see above)
// defines which characters are considered whitespace.
function stripWhitespace (s)
{   return stripCharsInBag (s, whitespace)
}
/****************************************************************/
// Returns true if character c is an English letter 
// (A .. Z, a..z).
//
// NOTE: Need i18n version to support European characters.
// This could be tricky due to different character
// sets and orderings for various languages and platforms.
function isLetter (c)
{   return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) )
}
/****************************************************************/
// Returns true if character c is a digit 
// (0 .. 9).
function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}
/****************************************************************/
// Returns true if character c is a letter or digit.
function isLetterOrDigit (c)
{   return (isLetter(c) || isDigit(c))
}
/****************************************************************/
// This function determines if the string passed in is a valid
// Canadian postal code.  L#L#L# or L#L #L#. If the
// string is valid, it returns true, else false.

function isPostalcode(strPostalCode)
{
	var s = new String(strPostalCode);
	s = stripWhitespace(s);
	if (s.length != 6)
		return false;
	for (var i=0; i < s.length; i++)
		if ((i==1) || (i==3) || (i==5))
		{
			if (!isDigit(s.charAt(i))) return false;
		}
		else
		{
			if (!isLetter(s.charAt(i))) return false;
		}
	return true;
}
/****************************************************************/
// isUSPhoneNumber (STRING s [, BOOLEAN emptyOK])
// 
// isUSPhoneNumber returns true if string s is a valid U.S. Phone
// Number.  Must be 10 digits.
function isUSPhoneNumber (s)
{   if (isEmpty(s)) 
	{
       if (isUSPhoneNumber.arguments.length == 1) return defaultEmptyOK;
       else return (isUSPhoneNumber.arguments[1] == true);
	}
	s=stripCharsNotInBag (s, digits);	   
    return (isInteger(s) && s.length == digitsInUSPhoneNumber);
}
/****************************************************************/
function isInteger (s)
{   var i;
    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (!isDigit(c)) return false;
    }
    return true;
}
/****************************************************************/
function stripCharsNotInBag (s, bag)
{   var i;
    var returnString = "";
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (bag.indexOf(c) != -1) returnString += c;
    }
    return returnString;
}
/****************************************************************/