<!--

	// 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:  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))

}



/****************************************************************/



// Returns true if string s contains a whitespace character.



function containsWhitespace (s)



{   var i;



    // 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 if current character contains whitespace.

	var c = s.charAt(i);



	if (whitespace.indexOf(c) != -1) return true;

    }



    // All characters are whitespace.

    return false;

}



/****************************************************************/



/****************************************************************/



// 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)

{   

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

}

		

/****************************************************************/



// 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 isNumber(strField) {



	if (isWhitespace(strField)) return false;

	

	if (isNaN(strField)) 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 isMoney(strField)

{

	

	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) != '.')) {

			return false;

		}



	return true;

}



function createDate (intDay, intMonth, intYear) {



	var objDate = new Date();

	objDate.setDate(intDay);

	objDate.setMonth(intMonth);

	objDate.setYear(intYear);



	return objDate;

}



/****************************************************************/



// 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 values make up a valid (and existing) date

*/



function isValidDate (day, month, year) {                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      

	var DayArray = new Array(31,28,31,30,31,30,31,31,30,31,30,31);

	var intDay = Number(day);

	var intMonth = Number(month);

	var intYear = Number(year);



	// Check if valid parameters

	if (isNaN(intDay) || isNaN(intDay) || isNaN(intYear)) return false;

	if ((intDay == 0) || (intMonth == 0) || (intMonth > 12)) return false;

	

	// Amend days in Feb if leap year

	if ((intYear % 4 == 0 && intYear % 100 != 0) || (intYear % 400 == 0 )){

  		DayArray[1]=29;

  	}

  	

	// Check if day exists within month

	if (intDay <= DayArray[intMonth - 1] && day > 0 ) return true;

	else return false;

}



/****************************************************************/

-->
