// /_scripts/validate.js
//===============================================================================================================================================================
//=     FUNCTION:       isAlpha()
//=     PARAMETERS:     theStr as string is the text to check
//=     RETURNS:        boolean
//=     PURPOSE:        Check an input string to see if it is letters only
//=     AUTHOR:         David Whalen, Byte Interactive <dw@byteinteractive.com> 
//=     DATE:           Jun 21, 2001
//===============================================================================================================================================================
function isAlpha(theStr) {
	var theReg =  /^[A-Za-z]+$/;
	return(theReg.test(theStr));
}

//===============================================================================================================================================================
//=     FUNCTION:       isAlphaNumeric()
//=     PARAMETERS:     theStr as string is the text to check
//=     RETURNS:        boolean
//=     PURPOSE:        Check an input string to see if it is letters or numbers only
//=     AUTHOR:         David Whalen, Byte Interactive <dw@byteinteractive.com> 
//=     DATE:           Jun 21, 2001
//===============================================================================================================================================================
function isAlphaNumeric(theStr) {
	var theReg =  /^[A-Za-z0-9]+$/;
	return(theReg.test(theStr));
}

//===============================================================================================================================================================
//=     FUNCTION:       isEmail() 
//=     PARAMETERS:     theStr as string is the text to check
//=     RETURNS:        boolean
//=     PURPOSE:        Check an input string to see if it represents a valid email address
//=     AUTHOR:         David Whalen, Byte Interactive <dw@byteinteractive.com> 
//=     DATE:           April 18, 2001
//===============================================================================================================================================================
function isEmail(theStr) {
	var theReg = /^[\w\.\-]+\@[\w\.\-]+\.[\w.]{2,}$/;
	return(theReg.test(theStr));
}

//=====================================================================================================================================================
//  FUNCTION:   isNumber
//  ARGUMENTS:  sValue - string
//				theLowerBound - number specifying the minimum value
//				theUpperBound - number specifying the maximum value
//  PURPOSE:    Check and input string to see if it qualifies as a number within a set of bounds
//  RETURNS:    Boolean (true/false)
//  AUTHOR:     David Whalen, <dw@byteinteractive.com>
//  DATE:       June 1, 2001
//=====================================================================================================================================================
function isNumber(theValue, theLowerBound, theUpperBound) {
	var retVal = false;
	if (isNumeric(theValue)) {
		retVal = true;
		if (isNumeric(theLowerBound)) {
			retVal = retVal && (theLowerBound <= theValue);
		}
		if (isNumeric(theUpperBound)) {
			retVal = retVal && (theValue <= theUpperBound);
		}
	}	
	return retVal;
}

//===============================================================================================================================================================
//=     FUNCTION:       isNumeric()
//=     PARAMETERS:     theStr as string is the text to check
//=     RETURNS:        boolean
//=     PURPOSE:        Check an input string to see if it is numeric only
//=     AUTHOR:         David Whalen, Byte Interactive <dw@byteinteractive.com> 
//=     DATE:           May 14, 2001
//===============================================================================================================================================================
function isNumeric(theStr) {
	var theReg =  /^\d+$/;
	return(theReg.test(theStr));
}

//===============================================================================================================================================================
//=     FUNCTION:       isPhoneNumber() 
//=     PARAMETERS:     theStr as string is the text to check
//=     RETURNS:        boolean
//=     PURPOSE:        Check an input string to see if it represents a valid US Phone Number.
//=     AUTHOR:         David Whalen, Byte Interactive <dw@byteinteractive.com> 
//=     DATE:           April 17, 2001
//===============================================================================================================================================================
function isPhoneNumber(theStr) {
	var theReg = /^\(?\d{3}\)?\D?\d{3}\D?\d{4}$/;
	return(theReg.test(theStr));
}

//=====================================================================================================================================================
//  FUNCTION:   isString
//  ARGUMENTS:  theValue - string
//				theMinLength - number specifying the minimum string length
//				theMaxLength - number specifying the maximum string length
//  PURPOSE:    Check and input string to see if it qualifies as a string of an expected length
//  RETURNS:    Boolean (true/false)
//  AUTHOR:     David Whalen, <dw@byteinteractive.com>
//  DATE:       June 1, 2001 (updated June 21, 2001)
//=====================================================================================================================================================
function isString(theValue, theMinLength, theMaxLength) {
	if (isNumeric(theMinLength) && isNumeric(theMaxLength)) {
		retVal = ((theMinLength <= theValue.length) && (theValue.length <= theMaxLength));
	} else if (isNumeric(theMinLength)) {
		retVal = (theMinLength <= theValue.length);
	} else if (isNumeric(theMaxLength)) {
		retVal = (theValue.length <= theMaxLength);
	} else {
		retVal = (0 < theValue.length);
	}
	return retVal;
}

//===============================================================================================================================================================
//=     FUNCTION:       wordCount() 
//=     PARAMETERS:     sText as string is the text to count
//						nLimit as integer is the wordcount limit
//=     RETURNS:        boolean
//=     PURPOSE:        Counts the number of words in an input string
//=     AUTHOR:         Jaycent Drysdale, Byte Interactive <jaycent.drysdale@byteinteractive.com> 
//=     DATE:           May 25, 2004
//===============================================================================================================================================================
function wordCount(sText,nLimit)
{
	var outVal;
	var sValue=sText;
	sValue=sValue.split(" ");
	
	outVal=(sValue.length < (nLimit+1));
	return outVal 
}


//===============================================================================================================================================================
//=     FUNCTION:       isZipCode() 
//=     PARAMETERS:     theStr as string is the text to check
//=     RETURNS:        boolean
//=     PURPOSE:        Check an input string to see if it represents a valid US ZIP Code.
//=     AUTHOR:         David Whalen, Byte Interactive <dw@byteinteractive.com> 
//=     DATE:           April 17, 2001
//===============================================================================================================================================================
function isZipCode(theStr) {
	var theReg =  /^\d{5}(\-\d{4})?$/;
	return(theReg.test(theStr));
}

