<!--
function SetFocus (strControlID){
	document.getElementById(strControlID).focus();
}
function isLetter (c){  
	return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) )
}
function isDate (c){   
	return ( ((c >= "0") && (c <= "9")) || (c == "/") || (c == "-") )
}
function isDigit (c){   
	return ( ((c >= "0") && (c <= "9")) || (c == ".") )
}
function isLetterOrDigit (c){   
	return (isLetter(c) || isDigit(c))
}

function Right(str, n)
/***
        IN: str - the string we are RIGHTing
            n - the number of characters we want to return

        RETVAL: n characters from the right side of the string
***/
{
        if (n <= 0)     // Invalid bound, return blank string
           return "";
        else if (n > String(str).length)   // Invalid bound, return
           return str;                     // entire string
        else { // Valid bound, return appropriate substring
           var iLen = String(str).length;
           return String(str).substring(iLen, iLen - n);
        }
}

function UpdateElementClassToRequired(strElementToUpdate, strDependentElement, strRequiredClassName, strClassName) {
	
	var strElementValue, strElementLabel

	// Get the value of the dependent control
	strElementValue = document.forms[0].elements[strDependentElement].value;
		
	// Check to see if the dependent element has a value
	if (strElementValue.length > 0)
	{
		document.getElementById(strElementToUpdate).className = strRequiredClassName;
		document.forms[0].elements[strElementToUpdate].className = strRequiredClassName;
	}
	else
	{
		document.getElementById(strElementToUpdate).className = strClassName;
		document.forms[0].elements[strElementToUpdate].className = strClassName;
	}
}

function AutoTab(strElementToTabFrom, strElementToTabTo, intElementOffset){
	
	// Fetch the HTML Elements by name
	var arrElementToTabFrom = document.getElementsByName(strElementToTabFrom);	
	var arrElementToTabTo = document.getElementsByName(strElementToTabTo);

	// Tab to the strElementToTabTo when the max length of strElementToTabFrom is met
	if (arrElementToTabFrom[0].value.length == arrElementToTabFrom[0].maxLength)
	{
		// Access the element in the array specified by the incoming argument
		var intElementIndex = parseInt(intElementOffset);
		arrElementToTabTo[intElementIndex].focus();
	}	
}

function Validate(){
	var blnValid = true
	var intErrorTextLength = 0
	
	// Loop through all the elements on the form (assumes one form per page), applying class-level validation
	
	for (ctr = 0; ctr < document.forms[0].elements.length; ctr++)
	{
		var strClassName
		var strElementName
		var strElementValue 
		var strLastInvalidLabel			// used when multiple input boxes share a single label (ie. phone #'s)
		var strElementLabel
		
		// Save the CLASS attribute of the current element
		strClassName = document.forms[0].elements[ctr].className;
		
		// Save the ID attribute of the current element
		strElementName = document.forms[0].elements[ctr].id;
		
		// Save the VALUE attribute of the current element
		strElementValue = document.forms[0].elements[ctr].value;
		
		// Get the length of the name/id of the current element
		var intNameLength = strElementName.length;
		
		// Replace the "txt" or "cbo" prefix with "lbl"
		strElementLabel = "lbl" + strElementName.substring(3,intNameLength);
		
		//strElementLabel = document.forms[0].elements[ctr].replace("txt", "lbl");
		//strElementLabel = strElementName.replace("txt", "lbl");
		//strElementLabel = strElementLabel.replace("cbo", "lbl");

		switch(strClassName)
		{
			case "InputBoxRequiredSmall":		
				if (strElementValue.length < 1 || strElementValue == "-99")
				{
					// Value was left empty or no selection in combo box was made
					blnValid = false;
					// Apply an invalid data class to the corresponding label
					document.getElementById(strElementLabel).className = "InvalidFormData";			
					break;
				}
				// If it gets here, the data must be valid
				document.getElementById(strElementLabel).className = "ValidFormData";
				break;									
		
			case "InputBoxRequired":		
				if (strElementValue.length < 1 || strElementValue == "-99")
				{
					// Value was left empty or no selection in combo box was made
					blnValid = false;
					// Apply an invalid data class to the corresponding label
					document.getElementById(strElementLabel).className = "InvalidFormData";			
					break;
				}
				// If it gets here, the data must be valid
				document.getElementById(strElementLabel).className = "ValidFormData";
				break;
				
			case "InputBoxTextArea":		
				if (strElementValue.length < 1 || strElementValue == "-99")
				{
					// Value was left empty or no selection in combo box was made
					blnValid = false;
					// Apply an invalid data class to the corresponding label
					document.getElementById(strElementLabel).className = "InvalidFormData";			
					break;
				}
				if (strElementValue.length > 8000)
				{
					// Value is too Long for the database to handle (varchar 8000)
					blnValid = false;
					intErrorTextLength = strElementValue.length;
					// Apply an invalid data class to the corresponding label
					document.getElementById(strElementLabel).className = "InvalidFormData";			
					break;
				}				
				// If it gets here, the data must be valid
				document.getElementById(strElementLabel).className = "ValidFormData";
				break;													

			case "InputBoxNumber":
				// Loop through each character in the value								
				for (intLetterCtr = 0; intLetterCtr < strElementValue.length; intLetterCtr++)
				{
					var c = strElementValue.charAt(intLetterCtr);
					if (!isDigit(c))
					{
						blnValid = false;
						// Apply an invalid data class to the corresponding label
						document.getElementById(strElementLabel).className = "InvalidFormData";	
						// Save the name of this label to prevent it from being changed back to valid
						strLastInvalidLabel = strElementLabel
						break;
					}
				}	
				// If it gets here, the data must be valid
				if (strElementLabel != strLastInvalidLabel)
					{
					document.getElementById(strElementLabel).className = "ValidFormData";
					}
				break;					
										
			case "InputBoxRequiredNumber":
				if (strElementValue.length < 1 || strElementValue == "-99")
				{
					// Value was left empty or no selection in combo box was made
					blnValid = false;
					// Apply an invalid data class to the corresponding label
					document.getElementById(strElementLabel).className = "InvalidFormData";	
					// Save the name of this label to prevent it from being changed back to valid
					strLastInvalidLabel = strElementLabel							
					break;
				}	
				// Loop through each character in the value				
				for (intLetterCtr = 0; intLetterCtr < strElementValue.length; intLetterCtr++)
				{			
					var c = strElementValue.charAt(intLetterCtr);
					if (!isDigit(c))
					{
						blnValid = false;
						// apply an invalid data class to the corresponding label
						document.getElementById(strElementLabel).className = "InvalidFormData";	
						// Save the name of this label to prevent it from being changed back to valid
						strLastInvalidLabel = strElementLabel								
						break;
					}	
				}	
				// If it gets here, the data must be valid
				if (strElementLabel != strLastInvalidLabel)
					{
					document.getElementById(strElementLabel).className = "ValidFormData";
					}
				break;		
			
			case "InputBoxEmail":
				if (strElementValue.indexOf("@") < 0 || strElementValue.indexOf(".") < 0)
				{
					// The value appears to be an invalid email address missing the "@" ot "."
					blnValid = false;
					// Apply an invalid data class to the corresponding label
					document.getElementById(strElementLabel).className = "InvalidFormData";			
					break;
				}
				// If it gets here, the data must be valid
				document.getElementById(strElementLabel).className = "ValidFormData";
				break;

			case "InputBoxFileUpload":
				if (strElementValue.length < 1 || strElementValue == "-99")
				{
					// Value was left empty or no selection in combo box was made
					blnValid = false;
					// Apply an invalid data class to the corresponding label
					document.getElementById(strElementLabel).className = "InvalidFormData";			
					break;
				}
				// If it gets here, the data must be valid
				document.getElementById(strElementLabel).className = "ValidFormData";
				break;
			// New 04-28-04 check extensions
			case "InputBoxImageUpload":
				if (strElementValue.length < 1 || strElementValue == "-99")
				{
					// Value was left empty
					blnValid = false;
					// Apply an invalid data class to the corresponding label
					document.getElementById(strElementLabel).className = "InvalidFormData";			
					break;
				}
				if (Right(strElementValue,4) != ".JPG")
				{
					if (Right(strElementValue,4) != ".GIF")
					{
						if (Right(strElementValue,4) != ".BMP")
						{
							if (Right(strElementValue,4) != ".PNG")
							{
								if (Right(strElementValue,4) != "JPEG")
								{
									if (Right(strElementValue,4) != ".jpg")
									{
										if (Right(strElementValue,4) != ".gif")
										{
											if (Right(strElementValue,4) != ".bmp")
											{
												if (Right(strElementValue,4) != ".png")
												{
													if (Right(strElementValue,4) != "jpeg")
													{
														// Value was not the correct image types
														blnValid = false;
														// Apply an invalid data class to the corresponding label
														document.getElementById(strElementLabel).className = "InvalidFormData";			
														break;
													}
												}
											}
										}
									}
								}
							}
						}
					}
				}		
				// If it gets here, the data must be valid
				document.getElementById(strElementLabel).className = "ValidFormData";
				break;

			case "InputBoxRequiredEmail":
				if (strElementValue.length < 1 || strElementValue == "-99")
				{
					// Value was left empty or no selection in combo box was made
					blnValid = false;
					// Apply an invalid data class to the corresponding label
					document.getElementById(strElementLabel).className = "InvalidFormData";			
					break;
				}	
				if (strElementValue.indexOf("@") < 0 || strElementValue.indexOf(".") < 0)
				{
					// The value appears to be an invalid email address missing the "@" or "."
					blnValid = false;
					// Apply an invalid data class to the corresponding label
					document.getElementById(strElementLabel).className = "InvalidFormData";			
					break;
				}				
				// If it gets here, the data must be valid
				document.getElementById(strElementLabel).className = "ValidFormData";
				break;		

			case "InputBoxRequiredURL":
				if (strElementValue.length < 1 || strElementValue == "-99")
				{
					// Value was left empty or no selection in combo box was made
					blnValid = false;
					// Apply an invalid data class to the corresponding label
					document.getElementById(strElementLabel).className = "InvalidFormData";			
					break;
				}	
				if (strElementValue.indexOf(".") < 0)
				{
					// The value appears to be an invalid email address missing the "."
					blnValid = false;
					// Apply an invalid data class to the corresponding label
					document.getElementById(strElementLabel).className = "InvalidFormData";			
					break;
				}				
				// If it gets here, the data must be valid
				document.getElementById(strElementLabel).className = "ValidFormData";
				break;	

			case "InputBoxDate":
				// Loop through each character in the value				
				for (intLetterCtr = 0; intLetterCtr < strElementValue.length; intLetterCtr++)
				{			
					var c = strElementValue.charAt(intLetterCtr);
					if (!isDate(c))
					{
						blnValid = false;
						// apply an invalid data class to the corresponding label
						document.getElementById(strElementLabel).className = "InvalidFormData";	
						break;
					}	
				}
				// If it gets here, the data must be valid
				if (strElementLabel != strLastInvalidLabel)
					{
					document.getElementById(strElementLabel).className = "ValidFormData";
					}
				break;		

			case "InputBoxRequiredDate":
				var now = new Date();
				var Today = (now.getMonth() + 1) + "/" + now.getDate() + "/" + now.getFullYear(); 	
								
				if (strElementValue.length < 1 )
				{
					// Value was left empty or no selection in combo box was made
					blnValid = false;
					// Apply an invalid data class to the corresponding label
					document.getElementById(strElementLabel).className = "InvalidFormData";	
					// Save the name of this label to prevent it from being changed back to valid
					strLastInvalidLabel = strElementLabel							
					break;
				}	
				// Loop through each character in the value				
				for (intLetterCtr = 0; intLetterCtr < strElementValue.length; intLetterCtr++)
				{			
					var c = strElementValue.charAt(intLetterCtr);
					if (!isDate(c))
					{
						blnValid = false;
						// apply an invalid data class to the corresponding label
						document.getElementById(strElementLabel).className = "InvalidFormData";	
						// Save the name of this label to prevent it from being changed back to valid
						strLastInvalidLabel = strElementLabel								
						break;
					}	
				}	
				// If it gets here, the data must be valid
				if (strElementLabel != strLastInvalidLabel)
					{
					document.getElementById(strElementLabel).className = "ValidFormData";
					}
				break;		
		}		
	}
	
	// If any data is invalid, display a message box
	if (blnValid == false)
	{
		if (intErrorTextLength > 0)
		{
		alert("Your message is too long, it contains " + intErrorTextLength + " characters.  The maximum message length is 8000 characters");
		return false;
		}
		else
		{
		alert("The identified fields contain invalid data.");
		return false;
		}
	}		
}	
//-->
