function RunValidate(theForm) {
	
//theForm is the actual form, NOT THE NAME OF THE FORM!!	
	//VALIDATION LEGEND
	var chkRequired = /R/					//check for Required value(has to have a value)
	var chkDate = /D/						//check for valid date format
	var chkTime = /T/						//check for valid time format
	var chkNumber = /N/						//field can only contain valid numbers
	var chkEmail = /E/						//valid email format
	var chkPhone = /P/						//valid phone number format
	var chkZip = /Z/						//valid zip code format(5 digits. with optional "-" and 4 more digits
	var chkSelect = /S/						//choice has value of string of length>0 or #>0
	var chkSingleQuotes = /Q/				//check for single quotes
											//	- checks unless you add in the Q
	var chkHTML = /H/						//check for invalid html tags("<input", "<script", "<meta") 
											//	- checks unless you add in the H
	var chkCompareDate1 = /C1a/				//Compare Date to C2a
	var chkCompareDate2 = /C2a/				//Compare Date to C1a
	var chkCompareDate3 = /C1b/				//Compare Date to C2b
	var chkCompareDate4 = /C2b/				//Compare Date to C1b
	var chkSwitch = /x/						//if (x) present compare both date ranges to each other...
	var chkGreaterThanToday = /Gt/			//check for date > today(return error if not)
	var chkLessThanToday = /Lt/				//check for date < today(return error if not)
	var chkGreaterThanEqualToday = /Ge/		//check for date >= today(return error if not)
	var chkLessThanEqualToday = /Le/		//check for date <= today(return error if not)
	var chkValueGroup = /Gr/					//Check to see if at least one value out of the group has a value
	var chkForTrue = /true/
	var chkStringMatch = /M/				//check for 2 strings Matching
		
	var err = ""
	var theGroupValues = ""
	
	var theMatch1 = ""
	var theMatch2 = ""
	var theStringName1 = ""
	var theStringName2 = ""


	
	
	for (i=0; i < theForm.length ;i++){
		
		var theString = theForm[i].getAttribute("validate")
		var theFriendlyName = theForm[i].getAttribute("friendly")
		
		theFieldName = ((theForm[i].getAttribute("friendly") == "") ||(theForm[i].getAttribute("friendly") == null))?theForm[i].name:theForm[i].getAttribute("friendly")

		with (theForm[i]){
				// Required Validation 
				if (chkRequired.test(theString)){ 
					if(value == "") {
						err += theFieldName + " cannot be null or empty.\n"
					}
				}
				
				// Date Check Validation
				if (chkDate.test(theString)) {
					theRE =/^\d{1,2}[\.\/]\d{1,2}[\.\/]\d{4}$/
					if (value) {
						if (!theRE.test(value)) {
							err += theFieldName + " is not a valid date. \nDates must be in the format m/d/yyyy.\n\n"
						}
					}
				}
				
				// Time Check Validation
				if (chkTime.test(theString)) {
					theRE =/\d{1,2}:\d{2}:\d{2}\s[AM|PM]{1}/i
					if (value) {
						if (!theRE.test(value)) {
							err += theFieldName + " is not a valid time. \nTimes must be in the format h:mm:ss AM/PM\n\n"
						}
					}
				}
				
				// Valid Numbers Only Validaion
				if (chkNumber.test(theString)){
					if (isNaN(value)) {
						err += theFieldName + " must be a valid number.\n"
					}
				}
				
				// Email
				if (chkEmail.test(theString)) {
					theRE = /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/g;

					///^([\w\.]+)@([A-Za-z0-9_.]+)\.(\w{2,4})$/gi
					if (value) {
						if (!theRE.test(value)) {
							err += theFieldName + " must be a valid email.\n"
						}
					}
				}

				// Phone Number
				if (chkPhone.test(theString)) {
					theRE = /^[19]{0,1}[-./]{0,1}(\d{0}|[\(]{0,1}\d{3}[\)]{0,1})[-./]{0,1}\d{3}[-./]{0,1}\d{4}$/ // /([19])([\.-])(\()(\d{3})(\))([-\.])((\d{3}[-.]d{4})||(d{7}))/
					if (value) {
						if (!(theRE.test(value))) {
							err += theFieldName + " must be a valid phone number format.\n"
						}
					}
				}
				//Zip
				if (chkZip.test(theString)) {
					theRE = /^\d{5}(|\d{4}|\-\d{4})$/i
					if (value) {
						if (!(theRE.test(value))) {
							err += theFieldName + " must be a valid zip code format.\n"
						}
					}
				}
				
/*				// Select
				if (chkSelect.test(theString)) {
					if (options[selectedIndex].value) {
						if (!isNaN(options[selectedIndex].value)) {
							if (options[selectedIndex].value.length > 0) {
								if (options[selectedIndex].value.toUpperCase() != 'NULL') {
									//do nothing
								}
							}
						} else {
							err += "You must pick one of the choices for the " + theFieldName + " dropdown.\n"
						}
					}
				}
*/	
				//Single quotes
				if (!chkSingleQuotes.test(theString)) {
					theRE = /\'/
					if ((value)&&(name != "ID")) {
						if (theRE.test(value)) {
							err += theFieldName + " must not contain single quotes.\n"
						}
					}
				}	

				//HTML
				if (!chkHTML.test(theString)) {
					theRE = /\<(input|script|meta)/i
					if (value) {
						if (theRE.test(value)) {
							err += theFieldName + " must not contain any of the following HTML tags.\n\t - <input>\n\t - <script>\n\t - <meta>\n"
						}
					}
				}	
				
				//check for strings Matching
				if (chkStringMatch.test(theString)) {
					if (theMatch1 == "") {
						theMatch1 = value
					} else if ((theMatch2 == "")&&(theMatch1 != "")) theMatch2 = value

					if (theStringName1 == "") {
						theStringName1 = theFieldName
					} else if ((theStringName2 == "")&&(theStringName1 != "")) theStringName2 = theFieldName
				}		

				// Set Date Values for Comparison
				if ( chkCompareDate1.test(theString) ){
					var Date1 = new Date(value)
					var Name1 = theFieldName
				}	
				if ( chkCompareDate2.test(theString) ){
					var Date2 = new Date(value)
					var Name2 = theFieldName
				}
				if ( chkCompareDate3.test(theString) ){
					var Date3 = new Date(value)
					var Name3 = theFieldName
				}	
				if ( chkCompareDate4.test(theString) ){
					var Date4 = new Date(value)
					var Name4 = theFieldName
				}
				if (chkValueGroup.test(theString) ){
					var theGroupValues
					theGroupValues += checked + " "
				}
				
				//today date checks
				var Today = new Date()
				if (chkGreaterThanToday.test(theString)) {
					var theDate = new Date(value)
					if (theDate <= Today) err += theFieldName + " must be greater than today's date.\n"
				}
				if (chkLessThanToday.test(theString)) {
					var theDate = new Date(value)
					if (theDate >= Today) err += theFieldName + " must be less than today's date.\n"
				}
				if (chkGreaterThanEqualToday.test(theString)) {
					var theDate = new Date(value)
					if (theDate < Today) err += theFieldName + " must be greater than or equal to today's date.\n"
				}
				if (chkLessThanEqualToday.test(theString)) {
					var theDate = new Date(value)
					if (theDate > Today) err += theFieldName + " must be less than or equal to today's date.\n"
				}
				
								
		} //With
	} //For Loop

			if ((theMatch1 != theMatch2)&&(theMatch1 != "")) err += theStringName1 + " and " + theStringName2 + " must match."

			try {
				if (Date1 > Date2){
					err += Name1 + " must be less than " + Name2 + ".\n"
				}
				if (Date3 > Date4){
					err += Name3 + " must be less than " + Name4 + ".\n"
				}
				if (chkSwitch){
					if (Date1 > Date3){
						err += Name1 + " cannot be greater than " + Name3 + ".\n"
					}
					if (Date2 < Date4){
						err += Name2 + " cannot be greater than " + Name4 + ".\n"
					}
				}	
			} catch (e) {
				//if the date validation fails, just turn it over to the server error 
				//handling. Just do nothing.
			}

			if ((theGroupValues>'')&&(!chkForTrue.test(theGroupValues))) {
				err += "You must select at least one of the group options."
			}

	if (err == '') {
		//theForm.submit()
		return true
	} else {
		alert(err)
		return false
	}
}//function

 /*
	NDenny - 4/5/02
	Purpose - test for html tags
 */	

//test for html tags from the string
 function HasHTML(theString) {
	var theRE = /\<[\/]{0,1}([\w\s\"\/\.\=]+)\>/gi
	return (theRE.test(theString))
}

//-- PROTOTYPING ---------------------------------------------------------------------------------------
/*
this is an extension of the Date object. It will return a date formatted as "01/01/2002"
to call, instatiate a Date:
	var theDate = new Date("1/1/2002")
then call the FormatLongDate method of the date object:
	var x = theDate.FormatLongDate()
	alert(x)
result:
	01/01/2002
*/
Date.prototype.FormatLongDate = function() {
	return (((theDate.getMonth() + 1)>9)?(theDate.getMonth() + 1):("0" + (theDate.getMonth() + 1))) + "/" + ((theDate.getDate()>9)?theDate.getDate():("0" + theDate.getDate())) + "/" + theDate.getFullYear()
}

String.prototype.IsEmail = function () {
		var theRE = /^(\w+)@([A-Za-z0-9_.]+)\.(\w{2,})$/gi
		return (this.match(theRE))?true:false
}
