/***************************************************************************
 *  $Workfile: ClientValidation.js $
 *  $Archive: /common/js/client_validation.js $
 *  $Author: Amerritt $
 *  $Date: 6/28/00 8:19p $
 *  $Revision: 1 $
 *
 *	$Description Start $
 *	This file contains simple client-side input validation functions.
 *	$Description End $
 *
 *  This program is an unpublished work fully protected by the United
 *  States copyright laws and is considered a trade secret belonging
 *  to myEssay.com. To the extent that this work
 *  may be considered "published," the following notice applies:
 *    "Copyright 1997-2000, myEssay.com."
 *
 *  Any unauthorized use, reproduction, distribution, display,
 *  modification, or disclosure of this program is strictly prohibited.
 ***************************************************************************/

/*****************************************************************************
* Method:			ClientJavaScriptValidation (CONSTRUCTOR)
* Purpose:			This is the constructor for this JavaScript object. This object
* 					will contain all required client-side JavaScript validation.
* Precondition:		N/A
* Inputs:			N/A
* Outputs:			Object of type ClientJavaScriptValidation.
* Postconditions:	Use functions below to validate client side forms by passing form field, etc.
* Usage:			var objClientValidation = new ClientJavaScriptValidation();
*****************************************************************************/
function ClientJavaScriptValidation()
{
	/* properties */

	/* methods */
	this.validateEmail 					= ClientJavaScript_validateEmail;
	this.validateDateFormat				= ClientJavaScript_validateDateFormat;
	this.validateTextField				= ClientJavaScript_validateTextField;
	this.validateSelectField			= ClientJavaScript_validateSelectField;
	this.validateFormTextField			= ClientJavaScript_validateFormTextField;
	this.validateXOrFields				= ClientJavaScript_validateXOrFields;
	this.validateXOrFieldsWithLengths	= ClientJavaScript_validateXOrFieldsWithLengths;
	this.validateXOrSelect				= ClientJavaScript_validateXOrSelect;
	this.validateFormTextLength			= ClientJavaScript_validateFormTextLength;
	this.validateDropDownChoice			= ClientJavaScript_validateDropDownChoice;
	this.validateDateExistence			= ClientJavaScript_validateDateExistence;
	this.validateDateRange				= ClientJavaScript_validateDateRange;
	this.validateInputInt				= ClientJavaScript_validateInputInt;
	this.validateSearchChoice			= ClientJavaScript_validateSearchChoice;
	this.validatePasswords				= ClientJavaScript_validatePasswords;
	this.validateFloatRange				= ClientJavaScript_validateFloatRange;
	this.validateHiddenField			= ClientJavaScript_validateHiddenField;	
	this.validateXORLengthText 			= ClientJavaScript_validateXORLengthText;
	this.validateCreditCard 			= ClientJavaScript_validateCreditCard;	
	this.validateNonNullInt				= ClientJavaScript_validateNonNullInt;
}

/***************************************************************************** 
* Method:			validateFormTextField
* Purpose:			Verifies that a given form text field value is:
*						1) not shorter than the minimum defined length
*						2) longer than the maximum defined length
*						3) contains only spaces
* Precondition:		N/A
* Inputs: 			<field> - handle to the form field
*					<min> - minimum length for the field. If the field is optional you should use 0
*					<max> - maximum length for the field. 
*					<fieldname> - the "friendly" name for the field. This will be used in the alert box if there is an error  
* Outputs: 			true if there is not an error (violation)
*					false if there is a error (violation)
* Postconditions:	N/A 
* Usage:			- Create a javascipt function that calls this method for all form fields. It should look
* 					like the following: (it takes the form object as input)
*
*					function validateForm(theForm) 
*					{
*						return ( objClientJS.validateFormTextField(theForm.docname, 1, 254, "Name") &&
*						objClientJS.validateFormTextField(theForm.productversion, 1, 20, "Version") &&
*						objClientJS.validateFormTextField(theForm.productshipdate, 0, 10, "Ship date") )
*					}
*		
*					- create a OnSubmit event for the form that call the above function. It should look
* 					like the following: (it passed the form object)
*					<form name="productProperties" method=post action="" onsubmit="return validateForm(document.productProperties)">
****************************************************************************/ 
function ClientJavaScript_validateFormTextField( field, min, max, fieldname )
{
	var str = field.value;
	// replace all spaces with nothing and store in a temp value
	str = str.replace( /(\s+)$/g, "" );

	// verify that the length of the field is not greater than the max or less than the min length	
	if ((field.value.length < min) || (field.value.length > max))
	{
		// alert the user of the error
		alert(fieldname + " must be between " + min + " and " + max + " characters long.");

		// put focus on the form field
		field.focus();
		return false;
		
	}
	// verify that the field does not just contain spaces
	else if ((field.value.length != 0) && ( str == ""))
	{
		// alert the user of the problem
		alert( fieldname + " contains only spaces. Please fill in correctly."  );

		// put focus on the form field
		field.focus();
		return false;
	}
	// no problems. return success
	else return true;
}
/***************************************************************************** 
* Method:			validateTextField
* Purpose:			Verifies that a given form text field is not blank
* Precondition:		N/A
* Inputs: 			<field> - handle to the form field
*					<fieldname> - the "friendly" name for the field. This will be used in the alert box if there is an error  
* Outputs: 			true if there is not an error (violation)
*					false if there is a error (violation)
* Postconditions:	N/A 
* Usage:			- Create a javascipt function that calls this method for all form fields. It should look
* 					like the following: (it takes the form object as input)
*
*					function validateForm(theForm) 
*					{
*						return ( objClientJS.validateFormTextField(theForm.docname, 1, 254, "Name") &&
*						objClientJS.validateFormTextField(theForm.productversion, 1, 20, "Version") &&
*						objClientJS.validateFormTextField(theForm.productshipdate, 0, 10, "Ship date") )
*					}
*		
*					- create a OnSubmit event for the form that call the above function. It should look
* 					like the following: (it passed the form object)
*					<form name="productProperties" method=post action="" onsubmit="return validateForm(document.productProperties)">
****************************************************************************/ 
function ClientJavaScript_validateTextField(field, fieldname)
{
	var str = field.value;
	if ((str == null) || (str == ""))
	{
		// alert the user of the error
		alert("Please enter a " + fieldname + ".");

		// put focus on the form field
		field.focus();
		return false;
		
	}
	// no problems. return success
	else return true;
}
/***************************************************************************** 
* Method:			validateDateFormat
* Purpose:			Verifies that a given value is a valid date
* Precondition:		N/A
* Inputs: 			<field> - handle to the form field
*					<fieldname> - the "friendly" name for the field. This will be used in the alert box if there is an error  
* Outputs: 			true if there is not an error (violation)
*					false if there is a error (violation)
* Postconditions:	N/A 
* Usage:			- Create a javascipt function that calls this method for all form fields. It should look
* 					like the following: (it takes the form object as input)
*
*					function validateForm(theForm) 
*					{
*						return ( objClientJS.validateFormTextField(theForm.docname, 1, 254, "Name") &&
*						objClientJS.validateFormTextField(theForm.productversion, 1, 20, "Version") &&
*						objClientJS.validateFormTextField(theForm.productshipdate, 0, 10, "Ship date") )
*					}
*		
*					- create a OnSubmit event for the form that call the above function. It should look
* 					like the following: (it passed the form object)
*					<form name="productProperties" method=post action="" onsubmit="return validateForm(document.productProperties)">
****************************************************************************/ 
function ClientJavaScript_validateDateFormat(field, fieldname)
{
	var str = field.value;
	var strDateNum = "1" + field.value + "";
	var strDateInt = parseInt(strDateNum,10) + "";
	
	str = str.replace( /\//g, "" );

	if(field.value.length != 10 || isNaN(strDateInt)) {
		// alert the user of the error
		alert("Please enter " + fieldname + " in MM/DD/YYYY format.");

		// put focus on the form field
		field.focus();
		return false;
	
	}

	// no problems. return success
	else return true;
}
/*****************************************************************************
* Method:			validateSelectField
* Purpose:			to check if item selected.
* Precondition:		
* Inputs:			<fieldOne>		= The first select field to be checked. 
*					<fieldNameOne>	= The name of the friendly first field.
* Outputs:			Returns a boolean value, true if everything is okay (a signal to
*					move along in the submission), or false if an incorrect option
*					was chosen (bringing up an alert box)
* Postconditions:	N/A
* Usage:			objClientValidator.validateXOrSelect(<fieldOne>, <fieldTwo>, <fieldNameOne>, <fieldNameTwo>)
*****************************************************************************/
function ClientJavaScript_validateSelectField(fieldOne, fieldNameOne)
{
	var strValueOne		= fieldOne.options[fieldOne.selectedIndex].value;
	
	if ((0 == strValueOne.length))
	{
		alert("Please select a " + fieldNameOne + ".");
		fieldOne.focus();
		return false;
	} else return true;
}



/*****************************************************************************
* Method:			validateXOrFields
* Purpose:			To check for either one field value or another being entered.
* Precondition:		Two form fields needing to be checked for one or the other being filled out.
*					But not both!
* Inputs:			<fieldOne>		= The first field to be checked. 
*					<fieldTwo>		= The second field to be checked against first.
*					<fieldNameOne>	= The name of the friendly first field.
*					<fieldNameTwo>	= The name of the friendly second field.
* Outputs:			Returns a boolean value, true if everything is okay (a signal to
*					move along in the submission), or false if an incorrect option
*					was chosen (bringing up an alert box)
* Postconditions:	N/A
* Usage:			objClientValidator.validateXOrFields(<fieldOne>, <fieldTwo>, <fieldNameOne>, <fieldNameTwo>)
*****************************************************************************/
function ClientJavaScript_validateXOrFields(fieldOne, fieldTwo, fieldNameOne, fieldNameTwo)
{
	var strValueOne		= fieldOne.value;
	var strValueTwo		= fieldTwo.value;
	
	if ((0 == strValueOne.length) && (0 == strValueTwo.length))
	{
		alert("You must enter either " + fieldNameOne + " or " + fieldNameTwo + ".");
		fieldOne.focus();
		return false;
	} else if ((0 != strValueOne.length) && (0 != strValueTwo.length))
	{
		alert("You must enter either " + fieldNameOne + " or " + fieldNameTwo + ", but not both.");
		fieldOne.focus();
		return false;
	} else return true;
}

/*****************************************************************************
* Method:			validateXOrFieldsWithLengths
* Purpose:			To check for either one field value or another being entered. 
*					And also check if the one entered is a valid length.
* Precondition:		Two form fields needing to be checked for one or the other being filled out.
*					But not both!
* Inputs:			<fieldOne>		= The first field to be checked. 
*					<fieldTwo>		= The second field to be checked against first.
*					<fieldNameOne>	= The name of the friendly first field.
*					<fieldNameTwo>	= The name of the friendly second field.
*					<intMinOne>		= The minimun length of field one.
*					<intMaxOne>		= The maximum length of field one.
*					<intMinTwo>		= The minimun length of field two.
*					<intMaxTwo>		= The maximum length of field two.
* Outputs:			Returns a boolean value, true if everything is okay (a signal to
*					move along in the submission), or false if an incorrect option
*					was chosen (bringing up an alert box)
* Postconditions:	N/A
* Usage:			objClientValidator.validateXOrFieldsWithLengths(<fieldOne>, <fieldTwo>, <fieldNameOne>, <fieldNameTwo>, <intMinOne>, <intMaxOne>, <intMinTwo>, <intMaxTwo>)
*****************************************************************************/
function ClientJavaScript_validateXOrFieldsWithLengths(fieldOne, fieldTwo, fieldNameOne, fieldNameTwo, intMinOne, intMaxOne, intMinTwo, intMaxTwo)
{
	var strValueOne		= fieldOne.value;
	var strValueTwo		= fieldTwo.value;
	var intLengthOne	= strValueOne.length;
	var intLengthTwo	= strValueTwo.length;
	if ((0 == intLengthOne) && (0 == intLengthTwo))
	{
		alert("You must enter either " + fieldNameOne + " or " + fieldNameTwo + ".");
		fieldOne.focus();
		return false;
	} else if ((0 != strValueOne.length) && (0 != strValueTwo.length))
	{
		alert("You must enter either " + fieldNameOne + " or " + fieldNameTwo + ", but not both.");
		fieldOne.focus();
		return false;
	} else if ((0 < intLengthOne) && ((intMinOne > intLengthOne) || (intMaxOne < intLengthOne)))
	{
		alert(fieldNameOne + " must be a minimum of " + intMinOne + " but no more than " + intMaxOne + " characters long.");
		fieldOne.focus();
		return false;
	} else if ((0 < intLengthTwo) && ((intMinTwo > intLengthTwo) || (intMaxTwo < intLengthTwo)))
	{
		alert(fieldNameTwo + " must be a minimum of " + intMinTwo + " but no more than " + intMaxTwo + " characters long.");
		fieldTwo.focus();
		return false;
	} else return true;
	
}

/*****************************************************************************
* Method:			validateXOrSelect
* Purpose:			To check for either one select field value or another being selected.
* Precondition:		Two select form fields needing to be checked for one or the other being filled out.
*					But not both!
* Inputs:			<fieldOne>		= The first select field to be checked. 
*					<fieldTwo>		= The second select field to be checked against first.
*					<fieldNameOne>	= The name of the friendly first field.
*					<fieldNameTwo>	= The name of the friendly second field.
* Outputs:			Returns a boolean value, true if everything is okay (a signal to
*					move along in the submission), or false if an incorrect option
*					was chosen (bringing up an alert box)
* Postconditions:	N/A
* Usage:			objClientValidator.validateXOrSelect(<fieldOne>, <fieldTwo>, <fieldNameOne>, <fieldNameTwo>)
*****************************************************************************/
function ClientJavaScript_validateXOrSelect(fieldOne, fieldTwo, fieldNameOne, fieldNameTwo)
{
	var strValueOne		= fieldOne.options[fieldOne.selectedIndex].value;
	var strValueTwo		= fieldTwo.options[fieldTwo.selectedIndex].value;
	
	if ((0 == strValueOne.length) && (0 == strValueTwo.length))
	{
		alert("You must select either " + fieldNameOne + " or " + fieldNameTwo + ".");
		fieldOne.focus();
		return false;
	} else if ((0 != strValueOne.length) && (0 != strValueTwo.length))
	{
		alert("You must select either " + fieldNameOne + " or " + fieldNameTwo + ", but not both.");
		fieldOne.focus();
		return false;
	} else return true;
}

/*****************************************************************************
* Method:			validateEmail
* Purpose:			-
* Precondition:		A text form field used to collect e-mail address from user. 
* Inputs:			<field> = A filed representing the e-mail address to be checked.
* Outputs:			Returns a boolean value, true if everything is okay (a signal to
*					move along in the submission), or false if an incorrect option
*					was chosen (bringing up an alert box)
* Postconditions:	N/A
* Usage:			objClientValidator.validateEmail(<field>)
*****************************************************************************/ 
function ClientJavaScript_validateEmail(field)
{
  var fullEmail = field.value;
  if (fullEmail == "") {
    alert("\nPlease enter your Internet e-mail address.")
    field.focus();
    return false;
  }
  if (fullEmail.indexOf (" ",0) == -1) {}
  else {
    alert("\nYour e-mail address cannot contain spaces.\n\nPlease re-enter your e-mail address.")
    field.select();
    field.focus();
    return false;
  }
  if (fullEmail.indexOf ("@",0) == -1 || fullEmail.indexOf (".",0) == -1) {
    alert("\nYour e-mail address requires that a \"@\" and a \".\" be used.\n\nPlease re-enter your e-mail address.")
    field.select();
    field.focus();
    return false;
  }
  else
    if (fullEmail.length < 8 || fullEmail.substring((fullEmail.length - 1),(fullEmail.length)) == "." ||  fullEmail.substring(0,1) == "@")
    {
    alert("\nYour e-mail address is invalid.\n\nPlease re-enter your e-mail address.")
    field.select();
    field.focus();
    return false;
    }
  else
    {
    return true;
    }

}

/*****************************************************************************
* Method:			validateFormTextLength
* Purpose:			To ensure that a textfield/textbox does not contain entries over
*					the maximum length allowed for their form variable
* Precondition:		That the form it is being used for contains text inputs
*					which have maximum values, but not minimum values & that an
*					input of only spaces is not acceptable
* Inputs:			<field> - the input box which is being validated
*					<max> - the maximum number of characters which can be legally inputted
*					<fieldname> - a string, which is the name of the field to be printed
*					   in the alert box
* Outputs:			Returns a boolean value, true if everything is okay (a signal to
*					move along in the submission), or false if an incorrect option
*					was chosen (bringing up an alert box)
* Postconditions:	N/A
* Usage:			objClientValidator.validateFormTextLength(<field>, <max>, <fieldname>)
*****************************************************************************/
function ClientJavaScript_validateFormTextLength(field, max, fieldname)
{
	var str = field.value;

	//	Replace all spaces with nothing and store in a temp value

	str = str.replace( /(\s+)$/g, "" );

	//	Verify that the length of the field is not greater than the max length

	if (field.value.length > max)
	{
		//	Alert the user of the error

		alert(fieldname + " must be less than " + max + " characters long");

		//	Put focus on the form field

		field.focus();
		return false;
	}

	// Verify that the field does not just contain spaces

	else if ((field.value.length != 0) && ( str == ""))
	{
		//	Alert the user of the problem

		alert(fieldname + " contains only spaces");

		//	Put focus on the form field

		field.focus();
		return false;
	}

	// If the field length is within bounds, accept user input (or lack thereof)

	else return true;
}

/*****************************************************************************
* Method:			validateDropDownChoice
* Purpose:			To check to see if drop down menu choices have been properly made
*					and return an alert if otherwise, w/o sending the form along
* Precondition:		That drop down menus and forms exist, whose fields have been
*					entered in properly and accurately
*					and uses a month array which sets Jan. at 0, Feb. at 1, etc.
* Inputs:			<field> - this is the name of the input box
*					<fieldname> - a string, which is the name of the field to be printed
*					   in the alert box
* Outputs:			Returns a boolean value, true if everything is okay (a signal to
*					move along in the submission), or false if an incorrect option
*					was chosen (bringing up an alert box)
* Postconditions:	N/A
* Usage:			objClientValidator.validateDropDownChoice(<field>, <fieldname>)
*****************************************************************************/
function ClientJavaScript_validateDropDownChoice(field, fieldname)
{
	//	Checks to see if drop down menu has a legitimate choice, and not some
	//	default instruction as a choice

	if(field.value == 0 || field.value == "")
	{
		//	Alert the user of the error

		alert("You must choose an option in the " + fieldname + " drop-down menu.");

		//	Put focus on the form field

		field.focus();
		return false;
	}

	// 	If a valid choice, then do not warn, just send form along for processing

	else return true;
}

/*****************************************************************************
* Method:			validateDateExistence
* Purpose:			To determine if the date entered actually exists
* Precondition:		That a form has a drop down date menu with accurate date integers
*					(that is no more than 31 days, 12 months, years in AD, etc.)
*					and uses a month array which sets Jan. at 0, Feb. at 1, etc.
* Inputs:			<dayfield> - the name of the date input field (value range of 1-31)
*					<monthfield> - the name of the month input field (value range of 0-11)
*					<yearfield> - the name of the year input field (value any integer, no floats
*					  or star dates...)
* Outputs:			Returns a boolean value, true if everything is okay (a signal to
*					move along in the submission), or false if an incorrect option
*					was chosen (bringing up an alert box)
* Postconditions:	N/A
* Usage:			objClientValidator.validateDateExistence(<dayfield>, <monthfield>, <yearfield>)
*****************************************************************************/
function ClientJavaScript_validateDateExistence(dayfield, monthfield, yearfield)
{
	//	The Month values come from an array where Jan. = 0, Feb. = 1, etc.

	//	Check to make sure that months with less than 31 days, don't get a 31st day

	if((monthfield.value == 3 || monthfield.value == 5 || monthfield.value == 8	||
		monthfield.value == 10) && dayfield.value == 31)
	{
		//	Alert the user who tries to denote the 31st in a month that has only 30 days

		alert("Invalid Date Choice: There are not 31 days in this particular month");

		//	Put focus on the form field

		dayfield.focus();
		return false;
	}

	//	Check that Februrary never has a 30th or 31st
	
	else if (monthfield.value == 1 && (dayfield.value == 31 || dayfield.value == 30))
	{
		//	Alert the user who tries to put too many days into February

		alert("February does not have " + dayfield.value + " days.\n  Please enter a valid number.");

		//	Put focus on the form field

		dayfield.focus();
		return false;
	}

	//	Check to see that non-leap years are not designated as such

	else if (((monthfield.value == 1) && (dayfield.value == 29)) &&
		(((yearfield.value % 4) != 0) ||
		(((yearfield.value % 100) == 0) && ((yearfield.value % 400) != 0))))
	{
		//	Alert the user that this is not a leap year

		alert(yearfield.value + " is not a leap year, please enter a valid date.");

		//	Put focus on the form field

		dayfield.focus();
		return false;
	}

	// 	If a valid choice, then do not warn, just send form along for processing

	else return true;
}

/*****************************************************************************
* Method:			validateDateRange
* Purpose:			To determine whether the range of release dates are a valid range.
* Precondition:		That a form has drop down menus for choosing the release dates
*					and that two separate, bookend release dates are to be selected.
*					In addition, the form must have accurate date integers (that is
*					no more than 31 days, 12 months, years in AD, etc.) and use a
*					month array which sets Jan. at 0, Feb. at 1, etc.
* Inputs:			<ryear1field>  = the name of the 1st year input field (value any integer, 
*						 no floats or star dates...)
*					<ryear2field>  = the name of the 2nd year input field (same as above)
*					<rmonth1field> = the name of the 1st month input field (value range of 0-11)
*					<rmonth2field> = the name of the 2nd month input field (value range of 0-11)
*					<rdate1field>  = the name of the 1st date input field (value range of 1-31)
*					<rdate2field>  = the name of the 2nd date input field (value range of 1-31)
*					<errorMessage> = a string which is returned as an error alert message
* Outputs:			Returns a boolean value, true if everything is okay (a signal to
*					move along in the submission), or false if an incorrect option
*					was chosen (bringing up an alert box)
* Postconditions:	Any objects or functions that need to be called after use.
* Usage:			objClientValidator.validateDateRange(<ryear1field>, <ryear2field>, <rmonth1field>, <rmonth2field>, <rdate1field>, <rdate2field>, <errorMessage>)
*****************************************************************************/
function ClientJavaScript_validateDateRange(ryear1field, ryear2field, rmonth1field, rmonth2field, rdate1field, rdate2field, errorMessage)
{
	//	Make temporary integer holders for the field values

	var year1 = parseInt(ryear1field.value);
	var year2 = parseInt(ryear2field.value);
	var month1 = parseInt(rmonth1field.value);
	var month2 = parseInt(rmonth2field.value);
	var date1 = parseInt(rdate1field.value);
	var date2 = parseInt(rdate2field.value);

	//	The Month values come from an array where Jan. = 0, Feb. = 1, etc.

	//	First, check to see that the second release year is >= to the first

	if (year2 < year1)
	{
		//	Alert the user that the second date cannot be less than the first

		alert(errorMessage);

		//	Put focus on the year form field

		ryear2field.focus();
		return false;
	}

	//	Otherwise, check to see if the years are equal & the 2nd month is >= the 1st

	else if ((year2 == year1) && (month2 < month1))
	{
		//	Alert the user that the second date cannot be less than the first

		alert(errorMessage);

		//	Put focus on the month form field

		rmonth2field.focus();
		return false;
	}

	//	Finally, check to see if the years & months are equal & the 2nd date is >= the 1st

	else if ((year2 == year1) && (month2 == month1) && (date2 < date1))
	{
		//	Alert the user that the second date cannot be less than the first

		alert(errorMessage);

		//	Put focus on the date form field

		rdate2field.focus();
		return false;
	}

	//	Otherwise, the dates are acceptable

	else return true;
}

/*****************************************************************************
* Method:			validateInputInt
* Purpose:			To determine if an integer only (& optional) form field has been
*					inputted with an integer
* Precondition:		That a form has a text input box which can optionally be filled
*					out & can only take integer values
* Inputs:			<field>		= this is the name of the input box
*					<fieldname> = a string, which is the name of the field to be printed
*							   in the alert box
* Outputs:			Returns a boolean value, true if everything is okay (a signal to
*					move along in the submission), or false if an incorrect value
*					was entered (bringing up an alert box)
* Postconditions:	N/A
* Usage:			objClientValidator.validateInputInt(<field>, <fieldname>)
*****************************************************************************/
function ClientJavaScript_validateInputInt(field, fieldname)
{
	//	Since this tests for an optional form field, if the value is left blank
	//	don't run any validation tests on it

	if (field.value == "")
		return true;

	//	This else, checks to see if characters instead of numbers have been
	//	inputted into the field

	else if (isNaN(parseInt("1" + field.value)))
	{
		//	Alert the user that non-integer values will not be tolerated

		alert("Please do not enter non-number values in " + fieldname + ".");

		//	Put focus on the errant form field

		field.focus();
		return false;
	}

	//	Just because a NaN wasn't returned in the previous else if doesn't mean
	//	that the input is an integer - this else uses a hack method to ensure that
	//	the value inputted is an integer.  The main thing that is being tested
	//	against is if the user enters a value such as "12faf" which will cause
	//	a DB error but pass the previous tests, since parseInt will just return
	//	the beginning int value.  Also, this will guard against floating point
	//	values being entered.  So please leave the "" at the end of the parsedInput
	//	& actualInput variables, for they are essential.

	else
	{
		var actualInput = ("1" + field.value) + "";
		var parsedInput = parseInt("1" + field.value) + "";

		if(actualInput.length != parsedInput.length)
		{
			//	Alert the user that non-integer values will not be tolerated

			alert("Please do not enter non-number values in " + fieldname + ".");

			//	Put focus on the errant form field

			field.focus();
			return false;
		}

	//	If the number is an integer, and truly blessed, it will survive and be passed on

	return true;
	}
}

/*****************************************************************************
* Method:			validateSearchChoice
* Purpose:			To ensure that a user enters at least 1 value to be searched against
*					in a search page with 3 optional search categories
* Precondition:		That a form have 3 optional search fields, one of which must
*					  be chosen to continue.  That the form it is being used for
*					  contains text inputs, without minimum values & that an
*					  input of only spaces is not acceptable.
* Inputs:			<field1> = the name of the first field to be checked against
*					<field2> = the name of the second field to be checked against
*					<field3> = the name of the third field to be checked against
* Outputs:			Returns a boolean value, true if everything is okay (a signal to
*					move along in the submission), or false if an incorrect value
*					was entered (bringing up an alert box)
* Postconditions:	N/A
* Usage:			objClientValidator.validateSearchChoice(<field1>, <field2>, <field3>)
*****************************************************************************/
function ClientJavaScript_validateSearchChoice(field1, field2, field3)
{
	if (field1.value == "" && field2.value == "" && field3.value == "")
	{
		//	Alert the user that s/he must enter a value in at least one field

		alert("Please narrow your search by entering a value into at least one field.");

		//	Put focus on the errant form field

		field3.focus();
		return false;
	}
	
	//	Otherwise at least one field has been chosen & the search may continue

	else return true;
}



/*****************************************************************************
* Method:			validatePasswords
* Purpose:			-
* Precondition:		A text form field used to validate passwords 
* Inputs:			<field1> = A field representing the original password 
*					<field2> = A field representing the new password
* Outputs:			Returns a boolean value, true if everything is okay (a signal to
*					move along in the submission), or false if an incorrect option
*					was chosen (bringing up an alert box)
* Postconditions:	N/A
* Usage:			objClientValidator.validatePasswords(<field>)
*****************************************************************************/  
function ClientJavaScript_validatePasswords(field1,field2)
{
	var strOriginal		= field1.value + "";
	var strNew			= field2.value + "";
	
	if ((strOriginal == null) || (strOriginal == ""))
	{
		// alert the user of the error
		alert("Please enter a password.");

		// put focus on the form field
		field1.focus();
		return false;
	}
	else if ((strNew == null) || (strNew == ""))
	{
		// alert the user of the error
		alert("Please confirm your password.");

		// put focus on the form field
		field2.focus();
		return false;
	}	
	else if (strOriginal != strNew)
	{
		// alert the user of the error
		alert("The passwords do not match.");

		// put focus on the form field
		field1.focus();
		return false;
	}	
	// no problems. return success
	else return true;	
}
/*****************************************************************************
* Method:			validateFloatRange
* Purpose:			To determine if a float value is within the exceptable range
*					
* Precondition:		That a form has a text input box for float values
*					
* Inputs:			<field>		= this is the name of the input box
*					<fieldname> = a string, which is the name of the field to be printed
*							   in the alert box
*					<minValue> 		= the minimum value
*					<minValue>		= the maximum value
* Outputs:			Returns a boolean value, true if everything is okay (a signal to
*					move along in the submission), or false if an incorrect value
*					was entered (bringing up an alert box)
* Postconditions:	N/A
* Usage:			objClientValidator.validateFloatRange(<field>, <fieldname>,<minValue,<minValue)
*****************************************************************************/
function ClientJavaScript_validateFloatRange(field, fieldname,minValue,maxValue)
{
	//	Since this tests for an optional form field, if the value is left blank
	//	don't run any validation tests on it

	if (field.value == "")
		return true;

	//	This else, checks to see if characters instead of numbers have been
	//	inputted into the field

	else if (isNaN(parseFloat(field.value)))
	{
		//	Alert the user that non-integer values will not be tolerated

		alert("Please do not enter non-number values in " + fieldname + ".");

		//	Put focus on the errant form field

		field.focus();
		return false;
	}
	else
	{
		var actualInput = field.value;
		var parsedInput = parseFloat(actualInput);

		if(parsedInput >= minValue && parsedInput <= maxValue) {
			return true;
		}
		else {
			alert("Please enter a value between " + minValue + " and " + maxValue + " for " + fieldname + ".");

			//	Put focus on the errant form field

			field.focus();		
			return false;
		}

	}
}
/***************************************************************************** 
* Method:			validateHiddenField
* Purpose:			Verifies that a given form hidden field is not blank
* Precondition:		N/A
* Inputs: 			<field> - handle to the form field
*					<fieldname> - the "friendly" name for the field. This will be used in the alert box if there is an error  
* Outputs: 			true if there is not an error (violation)
*					false if there is a error (violation)
* Postconditions:	N/A 
* Usage:			- Create a javascipt function that calls this method for all form fields.
****************************************************************************/ 
function ClientJavaScript_validateHiddenField(field, fieldname)
{
	var str = field.value;
	if ((str == null) || (str == ""))
	{
		// alert the user of the error
		alert("Please enter a " + fieldname + ".");

		// put focus on the form field - can't put focus on hidden field
		//field.focus();
		return false;
		
	}
	// no problems. return success
	else return true;
}
/*****************************************************************************
* Method:			validateXORLengthText
* Purpose:			To ensure that a textfield/textbox is either blank or does not contain entries over
*					the maximum length allowed for their form variable
* Precondition:		
* Inputs:			<field> - the input box which is being validated
*					<max> - the maximum number of characters which can be legally inputted
*					<fieldname> - a string, which is the name of the field to be printed
*					   in the alert box
* Outputs:			Returns a boolean value, true if everything is okay (a signal to
*					move along in the submission), or false if an incorrect option
*					was chosen (bringing up an alert box)
* Postconditions:	N/A
* Usage:			objClientValidator.validateXORLengthText(<field>, <max>, <fieldname>)
*****************************************************************************/
function ClientJavaScript_validateXORLengthText(field, max, fieldname)
{
	var str = field.value;

	if(str == "") {
		return true;
	}

	//	Verify that the length of the field is not greater than the max length
	else if (field.value.length > max)
	{
		//	Alert the user of the error
		alert(fieldname + " may be at most " + max + " character long");
		//	Put focus on the form field
		field.focus();
		return false;
	}

	// If the field length is within bounds, accept user input (or lack thereof)
	else return true;
}
/*****************************************************************************
* Method:			validateCreditCard
* Purpose:			To ensure that a credit card field is filled in and has no spaces
* Precondition:		
* Inputs:			<field> - the input box which is being validated
*					<max> - the maximum number of characters which can be legally inputted
*					<fieldname> - a string, which is the name of the field to be printed
*					   in the alert box
* Outputs:			Returns a boolean value, true if everything is okay (a signal to
*					move along in the submission), or false if an incorrect option
*					was chosen (bringing up an alert box)
* Postconditions:	N/A
* Usage:			objClientValidator.validateCreditCard(<field>, <max>, <fieldname>)
*****************************************************************************/
function ClientJavaScript_validateCreditCard(field,fieldname)
{
	var str = field.value;
	if ((str == null) || (str == ""))
	{
		// alert the user of the error
		alert("Please enter a credit card number.");
		// put focus on the form field
		field.focus();
		return false;
	}
	else if(str.indexOf(" ",0) >= 0) {
    	alert("\nYour credit card cannot contain spaces.\n\nPlease re-enter your credit card number.")
    	field.select();
    	field.focus();
    	return false;	
	}	
	// If okay
	else return true;
}
/*****************************************************************************
* Method:			validateNonNullInt
* Purpose:			To determine if an integer only form field has been
*					inputted with an integer greater than 0
* Inputs:			<field>		= this is the name of the input box
*					<fieldname> = a string, which is the name of the field to be printed
*							   in the alert box
* Outputs:			Returns a boolean value, true if everything is okay (a signal to
*					move along in the submission), or false if an incorrect value
*					was entered (bringing up an alert box)
* Postconditions:	N/A
* Usage:			objClientValidator.validateNonNullInt(<field>, <fieldname>)
*****************************************************************************/
function ClientJavaScript_validateNonNullInt(field, fieldname)
{
	//can't be blank
	if (field.value == "") {
		alert("Please enter a " + fieldname + ".");
		//	Put focus on the errant form field
		field.focus();
		return false;	
	}
	//	This else, checks to see if characters instead of numbers have been
	//	inputted into the field
	else if (isNaN(parseInt("1" + field.value)))
	{
		//	Alert the user that non-integer values will not be tolerated
		alert("Please do not enter non-number values in " + fieldname + ".");
		//	Put focus on the errant form field
		field.focus();
		return false;
	}

	//	Just because a NaN wasn't returned in the previous else if doesn't mean
	//	that the input is an integer - this else uses a hack method to ensure that
	//	the value inputted is an integer.  The main thing that is being tested
	//	against is if the user enters a value such as "12faf" which will cause
	//	a DB error but pass the previous tests, since parseInt will just return
	//	the beginning int value.  Also, this will guard against floating point
	//	values being entered.  So please leave the "" at the end of the parsedInput
	//	& actualInput variables, for they are essential.

	else
	{
		var actualInput = ("1" + field.value) + "";
		var parsedInput = parseInt("1" + field.value) + "";

		if(actualInput.length != parsedInput.length)
		{
			//	Alert the user that non-integer values will not be tolerated
			alert("Please do not enter non-number values in " + fieldname + ".");
			//	Put focus on the errant form field
			field.focus();
			return false;
		}
	//	If the number is an integer, and truly blessed, it will survive and be passed on
	return true;
	}
}