
<!--
	// This file contains the data validation JavaScript functions
	// It is included in the HTML pages with forms that need these
	// data validation routines.


// DEFINE VARIABLES

// whitespace characters
var whitespace = " \t\n\r";



//****************************************************************/

function ForceID(objField, MinLength, MaxLength, ID)
{ var Message = ""
var valid = true
	Message = "Invalid "
	Message = Message + ID
	Message = Message + ". \n"
	Message = Message + ID + " must be " + MinLength + " to " + MaxLength + " characters long and \n"
	Message = Message + "can contain only the letters A-Z and numbers 0-9 \n"
		
	var strField = new String(objField.value)
	if (isWhitespace(strField)) {
	ErrorMsg = ErrorMsg + Message
	return false; }
	
	if (strField.length > MaxLength || strField.length < MinLength)
		{ErrorMsg = ErrorMsg + Message
	return false; }
	
	var i = 0;
	for (i = 0; i < strField.length; i++)
	{
		if ((strField.charCodeAt(i) > 96 && strField.charCodeAt(i) < 123) || (strField.charCodeAt(i) > 47 && strField.charCodeAt(i) < 58))
		{}
		else
		{ErrorMsg = ErrorMsg + Message;
		return false;}
			
	}
}

//****************************************************************/
function ForceNumber(objField, Message)
{
	var strField = new String(objField.value);
	
	if (isWhitespace(strField)) {
	ErrorMsg = ErrorMsg + Message
	return false; }

	var i = 0;

	for (i = 0; i < strField.length; i++)
		if (strField.charAt(i) < '0' || strField.charAt(i) > '9') {
			ErrorMsg = ErrorMsg + Message
			return false;
		}

	
}


//****************************************************************/

function replaceAll (s, fromStr, toStr)
{
	var new_s = s;
	for (i = 0; i < 100 && new_s.indexOf (fromStr) != -1; i++)
	{
		new_s = new_s.replace (fromStr, toStr);
	}
	return new_s;
}

/****************************************************************/

/* PURPOSE:  Since we are using the single tick mark as the
	string delimiter to construct our SQL queries, a string with
	a tick mark in it will cause a SQL error.  Therefore we replace
	all "'" with "''", which eliminates the possibility of a SQL error.
*/

function sqlSafe (s)
{
	var new_s = s;
	new_s = replaceAll (new_s, "'", "|");
	new_s = replaceAll (new_s, "|", "''");
	new_s = replaceAll (new_s, "\"", "|");
	new_s = replaceAll (new_s, "|", "''");
	return new_s;
}

/****************************************************************/

function makeSafe (i)
{
	i.value = sqlSafe (i.value);
}

/****************************************************************/

// 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;
}


/****************************************************************/

// Checks to see if a required field is blank.  If it is, a warning
// message is displayed...

function ForceEntry(objField, Message)
{
	var strField = new String(objField.value);
	if (isWhitespace(strField)) {
		ErrorMsg = ErrorMsg + Message;
		return false;
	}


}
		

/****************************************************************/

/* PURPOSE:  Returns true if the string is a valid date number.
	A method is passed in (2 = month, 1 = day).  If the string is
	nonnumeric, false is passed back.  If the day in the date string
	is greater than 31, false is returned.  If the month is greater
	than 12, an error is returned.
*/

function isDateNumber(strNum,method)
{
	var str = new String(strNum);
	var i = 0;

	if (isNaN(parseInt(str)) || parseInt(str) < 0) return false;

	if (method == 2)
		if (parseInt(str) > 31)
			return false;
	if (method == 1)
		if (parseInt(str) > 12)
			return false;

	for (i = 0; i < str.length; i++)
		if (str.charAt(i) < '0' || str.charAt(i) > '9')
			return false;


	return true;
}

/****************************************************************/

// Displays an alert box with the passed in string...

//function PromptErrorMsg(Field,strError)
//{
//	alert("You have entered an invalid date for " + strError + ".  Please make sure your date format is in M/D/Y format.");
//	Field.focus();
//}
function PromptErrorMsg(Field)
{var Message = new String
Message = Field + ".  Please make sure your date format is in D/M/Y format. \n";
ErrorMsg = ErrorMsg + Message }

/****************************************************************/

/* PURPOSE: Checks to see if the string is a valid date.  A valid
	date is defined as any of the following:

		MM/DD/YY, MM/DD/YYYY, M/D/YY, M/D/YYYY,
		MM-DD-YY, MM-DD-YYYY, M-D-YY, M-D-YYYY
*/

function ForceDate(strDate)
{
	var str = new String(strDate.value);

	if (isWhitespace(str)) {
		PromptErrorMsg("You didn't enter a date!");
		//ErrorMsg="White Space";
		return false;
		// if the field is empty, just return false...
	}

	var i = 0, count = str.length, j = 0;
	while ((str.charAt(i) != "/" && str.charAt(i) != "-") && i < count)
		i++;

	if (i == count || i > 2) {
		PromptErrorMsg("First numbers wrong length");
		//ErrorMsg="First numbers wrong length";
		return false;
	}

	var addOne = false;
	if (i == 2) addOne = true;

	if (!isDateNumber(str.substring(0,i),2)) {
		PromptErrorMsg("First number wrong");
		//ErrorMsg="First number wrong";
		return false;
	}

	j = i+1;
	i = 0;

	while ((str.charAt(i+j) != "/" && str.charAt(j+i) != "-") && i+j < count)
		i++;

	if (i+j == count || i > 2) {
		PromptErrorMsg("Second number wrong length");
		//ErrorMsg="Second number wrong length";
		return false;
	}

	if (!isDateNumber(str.substring(j,i+j),1)) {
		PromptErrorMsg("Second number wrong");
		//ErrorMsg="Second number wrong";
		return false;
	}

	j = i+3;
	i = 0;

	if (addOne) j++;

	while (i+j < count)
		i++;


//	if (i != 2 && i != 4) {
	if (i != 4) {
		PromptErrorMsg("Year number wrong length");
		//ErrorMsg="Year number wrong length";
		return false;
	}

	if (!isDateNumber(str.substring(j,i+j),3)) {
		PromptErrorMsg("Year number wrong");
		//ErrorMsg="Year number wrong";
		return false;
	}

	return true;
}

/****************************************************************/

// This function determines if the string passed in is a valid
// US zip code.  It accepts either ##### or #####-####.  If the
// string is valid, it returns true, else false.

function isZipcode(strZip)
{
	var s = new String(strZip);

	if (s.length != 5 && s.length != 10)
		// inappropriate length
		return false;


	for (var i=0; i < s.length; i++)
		if ((s.charAt(i) < '0' || s.charAt(s) > '9') && s.charAt(i) != '-')
			return false;

	return true;
}

/****************************************************************/

// This function ensures that a field is less than or equal to the
// Length passed in.  You must call this function with the element
// name in your form (for example: "ForceLength(document.forms[0].txtElement)"
// as opposed to "ForceLength(document.forms[0].txtElement.value)"
// If the field's value is too large, an error message is displayed
// and false is returned, else true is returned.

function ForceLength(objField, nLength, strWarning)
{
	var strField = new String(objField.value);

	if (strField.length < nLength) {
		//alert(strWarning);
		return false;
	} else
		return true;
}
/*********************************************************/

function isEmail(s, Message) {
  if (isEmpty(s)) {
  	ErrorMsg = ErrorMsg + Message;
  	return false;}
     //if (isEmail.arguments.length == 1) return defaultEmptyOK;
     //else return (isEmail.arguments[1] == true);
   
    // is s whitespace?
   if (isWhitespace(s)) {
	   ErrorMsg = ErrorMsg + Message;
	   return false;}
    
    // there must be >= 1 character before @, so we
    // start looking at character position 1 
    // (i.e. second character)
    var i = 1;
    var sLength = s.length;

    // look for @
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) {
	ErrorMsg = ErrorMsg + Message; 
	return false;}
    else i += 2;

    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) {
	ErrorMsg = ErrorMsg + Message;
	return false; }
    else return true;
}

/*********************************************************/ -->


