<!--
	// 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";


/******************************************************************************\
PURPOSE:		To bounce to a new page when needed.
				This will not perform a submit, but will only redirect
				to the next page.
\******************************************************************************/
	
	function bounceToNewPage(sPagePath) {
		if (isWhitespace(sPagePath)) {
			alert("You have not given a page path to redirect to.");
		} else {
			window.location = sPagePath;
		}
	}

/******************************************************************************\ 
   formatMoney() -- formats money
\******************************************************************************/
function formatMoney(sString, oString) {
var decimal = sString.indexOf('.')
var dollars = new String();
var cents = new String();
var sOutPut = ""
var iFirstComma = ""

// Deterime if there is the need to worry about
if (decimal != -1) {
	dollars = sString.substring(0, decimal)
	cents = '.' + sString.substring(sString.indexOf('.') + 1, sString.length)
} else {
	dollars = sString
}

iFirstComma = (dollars.length % 3)

	if (dollars.length > 3) {							// make sure that this needs commas
		for (i = 0; i < dollars.length; i++) {			
			if (iFirstComma == 0) {
				if ((i == 3|| (i % 3) == 0) && i != 0) {
					sOutPut += "," + dollars.charAt(i)
				} else {
					sOutPut += dollars.charAt(i)
				}

			} else {
					if (i == iFirstComma) {
						sOutPut += "," + dollars.charAt(i)
					} else {
						if ((iFirstComma + 3) == i) {
							sOutPut += "," + dollars.charAt(i)
						} else {
							sOutPut += dollars.charAt(i)
						}			
					}
			}
		}
		sOutPut = sOutPut +  cents
	} else {
		sOutPut = sString
	}
	
	oString.value = sOutPut
	return sOutPut;
}

/******************************************************************************\
PURPOSE:  Check to see if the string passed in is a valid time.
	A valid time is defined as a string which is postfixed with either
  "PM" or "AM".  Next it checks to see if there is a colon in the
  string.  If there is, it makes sure that at least one digit preceeds
  it and two proceed it.
\******************************************************************************/

	function IsTime(strTime)
	{
		var strTestTime = new String(strTime);
		strTestTime.toUpperCase();

		var bolTime = false;

		if (strTestTime.indexOf("PM",1) != -1 || strTestTime.indexOf("AM",1))
			bolTime = true;

		if (bolTime && strTestTime.indexOf(":",0) == 0)
			bolTime = false;

		var nColonPlace = strTestTime.indexOf(":",1);
		if (bolTime && ((parseInt(nColonPlace) + 5) < (strTestTime.length - 1) || (parseInt(nColonPlace) + 4) > (strTestTime.length - 1)))
			bolTime = false;


		return bolTime;
	}


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)||(s == "null"))
}

/****************************************************************/

// 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;
}

/******************************************************************************\
 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

 For explanation of optional argument emptyOK,
 see comments of function isInteger.
\******************************************************************************/
function isEmail (s)
{   if (isEmpty(s)) 
       if (isEmail.arguments.length == 1) return defaultEmptyOK;
       else return (isEmail.arguments[1] == true);
   
    // is s whitespace?
    if (isWhitespace(s)) 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) != "@")) 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) != ".")) 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;
}

function ForceEntryList(objField, FieldName)
{	
	if (objField.selectedIndex==0)
	 {
		alert("You need to enter information for " + FieldName);
		objField.focus();
		//objField.select();
		return false;
	}

	return true;
}

function ForceSelect(objField, FieldName)
{	
	if (objField.checked == false )
	 {
		alert("You must pick up the answer for " + FieldName);
		objField.focus();
		//objField.select();
		return false;
	}

	return true;
}


function ForceSelectItem(objField)
{	
	var i;

	if (!objField[0]) {
		if (objField.checked) {
			iRow = 1;
			return true;
		}
		return false;
	}
	for( i=0; i < objField.length; i++ )
	{
	    if ( objField[i].checked == true)
	    {
		    iRow = i+1;		// iRow is offset by 1.	 	
		    return true;
	    }
    }
	return false;
}

		
/******************************************************************************\
Returns true if the string passed in is a valid integer
  (no alpha characters), else it displays an error message
\******************************************************************************/
function ForceInteger(objField, FieldName)
{
	
	var strField = new String(objField.value);
	
	if (isWhitespace(strField)) return true;
	
	if (parseInt(strField) > 32767) {
		alert(FieldName + " must be a valid numeric entry and should not be greater than 32,767.");
			objField.focus();
			return false;
		} 

	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 number
//  (no alpha characters), else it displays an error message
//
// Mod on 8/15/2001 by DAW. to use the isNaN function
function ForceNumber(objField, FieldName){

	if ( isNaN(objField.value) ) {
		alert(FieldName + " must be a valid numeric entry.  Please do not use commas or dollar signs or any non-numeric symbols.");
		objField.focus();
		objField.select();
		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 (isWhitespace(strField)) return true;

	var i = 0;

	for (i = 0; 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.");
			objField.focus();
			return false;
		}

	return true;
}


/****************************************************************/

// Right trims the string...  Useful for SQL datatypes of CHAR

function RTrim(strTrim)
{
	var str = new String(strTrim);
	var i = 0;
	var c = "";
	var endpos = 0

	for (i = str.length; i >= 0 && endpos == 0; i = i - 1) {
		c = str.charAt(i);
		if (whitespace.indexOf(c) == -1)
			endpos = i;
	}

	return str.substring(0,endpos+1);
}

/****************************************************************/

/* PURPOSE:  Returns true if the string is a valid date number.
	A method is passed in (1 = month, 2 = 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,strMonth,strYear)
{
	var str = new String(strNum);
	var strMon = new String(strMonth);
	var strYr = new String(strYear);
	var i = 0;

	
	if (isNaN(parseInt(str)) || parseInt(str) < 0) return false;

	if (method == 2) {
		if (eval(strMon)==1 || eval(strMon)==3|| eval(strMon)==5|| eval(strMon)==7 || eval(strMon)==8|| eval(strMon)==10 || eval(strMon)==12){
			if (eval(str) > 31)
				return false;
				}
				
		if ((eval(strMon)==4) || (eval(strMon)==6)|| (eval(strMon)==9)||( eval(strMon)==11)){
			if (eval(str) > 30)
				return false;
				}
		if (eval(strMon)==2 && (eval(strYr)%4)==0){
			if (eval(str) > 29)
				return false;
				}
		if (eval(strMon)==2 && (eval(strYr)%4)!=0){
			if (eval(str) > 28)
				return false;
				}
		}
		
	if (method == 1)
		if (eval(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 MM/DD/YYYY format.");
	Field.focus();
}

/****************************************************************/

/* PURPOSE: Checks to see if the string is a valid date.  A valid
	date is defined as any of the following:

MM/DD/YYYY, MM/DD/YY,  M/D/YYYY, MM.DD.YYYY, M.D.YYYY, M.D.YY
MM-DD-YYYY, MM-DD-YY,  M-D-YYYY, MM DD YYYY, M.D.YYYY, M D YY
*/

  function ForceDate(strDate,strField)
{
	var str = new String(strDate.value);
	// if the field is empty, just return true...
	if ((str == null) || (str.length == 0))
		return true;
	//trim the sapces
	String.prototype.trim = new Function("return this.replace(/\\s+$|^\\s*/gi, '');");
	str = str.trim() ;
	//replace the space or dot with "/"
	var objReg	= new RegExp("(\\.)|(\ )|(\\-)",["g"]);
	str = str.replace(objReg, "/");
	
	var i = 0, count = str.length, j = 0;
	while ((str.charAt(i) != "/") && i < count)
		i++;
	
	var addOne = false;
	if (i == 2) addOne = true;
    //check the month
	var strMonth=str.substring(0,i);
	if ((i == count || i > 2) ||(!isDateNumber(0,1,strMonth,0))) {
		PromptErrorMsg(strDate,strField);
		return false;
	}

	j = i+1;
	i = 0;
	while ((str.charAt(i+j) != "/" ) && i+j < count)
		i++;

	if (i+j == count || i > 2) {
		PromptErrorMsg(strDate,strField);
		return false;
	}
	var StrDay = str.substring(j,i+j)
	j = i+3;
	i = 0;
	if (addOne) j++;
	
	while (i+j < count)
		i++;
	var strYear = str.substring(j,i+j);
	if (i != 4) {
		//get the current year, if the keyed in two- digit year greats than current year + 50, put 19 as prefix of year,
		// otherwise put "20". 
		if( i == 2 ){
			var d = new Date();
			var currentYear =(new String(d.getYear())).substring(2,4);
			var  compYear = parseInt(currentYear) + 50;
 			if ( parseInt(strYear) > compYear)
					var strYear = "19" + strYear
			else
					var strYear = "20" + strYear
			}
		else
		{
			PromptErrorMsg(strDate,strField);
			return false;
		}
	}
	//check the year
	if (!isDateNumber(strYear,3,0,0)) {
		PromptErrorMsg(strDate,strField);
		return false;
	}
	 //check the day
	if (!isDateNumber(StrDay,2,strMonth,strYear)) {
		PromptErrorMsg(strDate,strField);
		return false;
	}
	strDate.value = new String(  strMonth  +"/" +StrDay+ "/" + strYear);
	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 (isWhitespace(s)) {
		return true;
		// if the field is empty, just return true...
	}
	
	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;
}

/******************************************************************************\
 This will remove any comma's from a string
\******************************************************************************/
function stripMoney(sString, oString) {
var sOutString = new String();

	for (i = 0; i <= sString.length; i++) {
		if (sString.charAt(i) != ',') {
			sOutString += sString.charAt(i)
		}
	}
	
	oString.value = sOutString	
}

/********************************************************************/
// This function will toggle the status of a text box between
//	edit / readonly
// If the passed in value is false, then it will not allow the changing
//	of the value.
/********************************************************************/	
function toggleEditStatus( bFlag, objField ) {
	if (bFlag == false ) {
		objField.blur();
	}
}

/******************************************************************************\
// Returns true if the string passed in is a valid phone number It accepts either 
//  number with no alpha characters and ten digits or (xxx)xxx-xxxx), else it displays an error message
\******************************************************************************/
function ValidPhoneNumber(objField,strField)
{	
	var s = new String(objField.value);
	var s2 = new String();
	if (isWhitespace(s)) {
		return true;
		// if the field is empty, just return true...
	}
	
	//if the phone number in the format of (xxx)xxx-xxxx,we replace all "(",")" and "-" with""
		
	for (var i=0; i<s.length ; i++){	
		if (s.charAt(i)!='('&& s.charAt(i)!=')'&& s.charAt(i)!='-'&& s.charAt(i)!=' '&& s.charAt(i)!='.'){
			  s2=s2 + s.charAt(i);
			  }
	}
	s = s2;	
	
	// check the string passed in is a valid number(no alpha characters)
	for (var i=0; i<s.length ; i++){	
		if (s.charAt(i)<'0'||s.charAt(i) > '9'){
			alert(strField+" must be a valid NUMERIC entry( ten digits) or in the format of (xxx)xxx-xxxx.");
			objField.focus();
			return false;
			}
	}

	if (s.length != 10 ) {
		alert(strField+" must be a valid numeric entry(TEN digits) or in the format of (xxx)xxx-xxxx.");
		objField.focus();
		return false;
	}	
    objField.value = s;    
    return true;
}

// Returns true if the string passed in is a valid phone Extension number with no alpha characters and 4 digits else it displays an error message
function ValidPhoneExt(objField,strField)
{	
	var s = new String(objField.value);
	var s2 = new String();
	if (isWhitespace(s)) {
		return true;
		// if the field is empty, just return true...
	}
	
	
	
	// check the string passed in is a valid number(no alpha characters)
	for (var i=0; i<s.length ; i++){	
		if (s.charAt(i)<'0'||s.charAt(i) > '9'){
			alert(strField+" must be a valid NUMERIC entry( Max 4 digits).");
			objField.focus();
			return false;
			}
	}

	if (s.length > 4 ) {
		alert(strField+" must be a valid numeric entry(Max 4 digits).");
		objField.focus();
		return false;
	}	
    return true;
}





/****************************************************************/




//-->

