function CheckText(control,controlLabel,maxLength) {
	/*  
		This function is used primarily to check the length of a text field or text area
		and is best to be used from the OnKeyUp and OnPaste events for the control.  It is
		extremely useful in making sure a field that is being sent to the database is not over the
		field size defined in the database.
			
		Parameters:
			
			control				The control you want to check.  Normally sent using a "this" keyword.
			controlLabel		The string label on the control, or some other way of identifying the field being
										edited.  It will be used in the alert to describe the problem to the user.
			maxLength			The numeric maximum Length of the field.  The text in the field will be
										truncated to this length.
										
		Sample call:
			
			CheckText(this,"Additional Information",255)
	*/
	
	if (control.value.length > maxLength) {
		window.alert("Entries in the " + controlLabel + " field are limited to " + maxLength + " characters.  Your input will be reduced to that length.")
		control.value = control.value.substr(0,maxLength)
	}
}


function IsValidEmailAddress(valueToCheck) {
	/*		
		Parameters:
			
			valueToCheck		String with potential e-mail address
			
		Returns:
		
			true or false
										
		Sample call:
			
			onclick="IsValidEmailAddress(document.Form1.txtEMail.value)"
	*/
	var emailPattern

	emailPattern = /^[a-z][a-z_0-9\.]+@[a-z_0-9]+\.{1}[a-z]{2,}$/i;
	if (emailPattern.test(valueToCheck)) {
		return true;
	}
	else {
		return false;
	}
}
			

			
function IsNumeric(valueToCheck, maxDecimalPlaces, allowNegative) {
	/*		
		Parameters:
			
			valueToCheck			String with potential numeric value
			maxDecimalPlaces	Maximum number of positions after one decimal point
			allowNegative			If true, will allow one negative sign(-) at beginning of value
			
		Returns:
		
			true or false
										
		Sample call:
			
			onclick="IsNumeric(this.value, 2, false)"
	*/
	var decimalCheck = ""
	var negativeCheck = ""
	var numericPattern
	
	if (maxDecimalPlaces > 0) {
		decimalCheck = "[\.]?[0-9]{0," + maxDecimalPlaces + "}"
	}
	
	if (allowNegative) {
		negativeCheck = "[-]?"
	}
	
	numericPattern = new RegExp("^" + negativeCheck + "[0-9]*" + decimalCheck + "$","i");
				
	if (numericPattern.test(valueToCheck)) {
		return true;
	}
	else {
		return false;
	}
}
			
function IsNumericKeyPress(keyPressedCode, currentValue, maxDecimalPlaces, allowNegative) {
	/*		
		Parameters:
			
			keyPressedCode		Code of the Key pressed
			currentValue			Value in the field before the key pressed is appended
			maxDecimalPlaces	Maximum number of positions after one decimal point
			allowNegative			If true, will allow one negative sign(-) at beginning of value
			
		Returns:
		
			true or false
										
		Sample call:
			
			 onKeyPress="return IsNumericKeyPress(event.keyCode, this.value, 2, false);"
	*/
	var selectedText, myValue

	selectedText = document.selection.createRange().text
	if (selectedText.length == 0) {
		myValue = currentValue + String.fromCharCode(keyPressedCode)
	}
	else {
		if (currentValue.length == selectedText.length) {
			myValue = String.fromCharCode(keyPressedCode)
		}
		else {
			//this currently does not handle the ability to check 'what if the selected text was replaced with the key pressed'
			myValue = String.fromCharCode(keyPressedCode)
		}
	}
	
	return (IsNumeric(myValue, maxDecimalPlaces, allowNegative))
}
			
function IsNumericClipboard(maxDecimalPlaces, allowNegative) {
	/*		
		Parameters:
			
			maxDecimalPlaces	Maximum number of positions after one decimal point
			allowNegative			If true, will allow one negative sign(-) at beginning of value
			
		Returns:
		
			true or false
										
		Sample call:
			
			onpaste="return IsNumericClipboard(2, false);"
	*/
	return (IsNumeric(window.clipboardData.getData("Text"), maxDecimalPlaces, allowNegative))
}
