
function jsValidate(category, testThis)
{
	var re,reVal;
	var errorMessage = "Invalid format";

	/* Allow empty values, we'll worry about required items 
	   elsewhere. Also, we are setting focus to the control
	   if it fails validation. User can get in an infinite loop
	   if we don't allow them to blank it out and move on.*/
	if ( testThis.value.length == 0 )
		return true;	

	switch (category.toLowerCase()) {
		case "currency":
			/*  Author: gregg durishan 
				Currency format that allows optional $, optional 
				"-"(MinusSignNegative) OR "()" (ParenNegative) but not both, optional cents, and 
				optional commas separating thousands. Minus sign can be before or after $, but 
				parens must be outside the $.*/
			/* Use this line to allow $, use next line to prevent this */
			/* theExp = "^\\$?\\-?([1-9]{1}[0-9]{0,2}(\\,\\d{3})*(\\.\\d{0,2})?|[1-9]{1}\\d{" + */
			theExp = "^\\-?([1-9]{1}[0-9]{0,2}(\\,\\d{3})*(\\.\\d{0,2})?|[1-9]{1}\\d{" +
						"0,}(\\.\\d{0,2})?|0(\\.\\d{0,2})?|(\\.\\d{1,2})?)$|^\\-?\\$?([1-9]{1" +
						"}\\d{0,2}(\\,\\d{3})*(\\.\\d{0,2})?|[1-9]{1}\\d{0,}(\\.\\d{0,2})?|0(" +
						"\\.\\d{0,2})?|(\\.\\d{1,2})?)$|^\\(\\$?([1-9]{1}\\d{0,2}(\\,\\d{3})*(" +
						"\\.\\d{0,2})?|[1-9]{1}\\d{0,}(\\.\\d{0,2})?|0(\\.\\d{0,2})?|(\\.\\d{1" +
						",2})?)\\)$";
			errorMessage = "Please enter a valid currency";
			break;
			
		case "currency plain":
			/*  Author: Andrew van der Stock
				Matches positive whole numbers with exactly zero or two decimal points if a . is 
				present. Useful for checking currency amounts, such 5 or 5.00 or 5.25. */
			/* This expression prevents insert of $, -, and () */				
			re = /^\d+(?:\.\d{0,2})?$/;
			if ( testThis.value.match(re) ) 
				return true;
			errorMessage = "Please enter a valid currency, please omit $, -, () from your entry.";
			alert(errorMessage);
			testThis.focus();
			return false;			
			break;

		case "date":
			/* Author: Saurabh Nath */
			/* This Validator Validates any date 
				from 1800 - 9999. It takes special care of Leap years and validates any format 
				of type mm/dd/yyyy , m/dd/yyyy , mm/d/yyyy , m/d/yyyy. Since SQL Server does not 
				accept any date before 1/1/1753, so i hope it will meet Your 
				Requirements.(Modified Version of Jason West's Date Validator.)*/
			theExp = "((^(10|12|0?[13578])([/])(3[01]|[12][0-9]|0?[1-9])([/])((1[8" +
					"-9]\\d{2})|([2-9]\\d{3}))$)|(^(11|0?[469])([/])(30|[12][0-9]|0" +
					"?[1-9])([/])((1[8-9]\\d{2})|([2-9]\\d{3}))$)|(^(0?2)([/])(2[0-" +
					"8]|1[0-9]|0?[1-9])([/])((1[8-9]\\d{2})|([2-9]\\d{3}))$)|(^(0?2" +
					")([/])(29)([/])([2468][048]00)$)|(^(0?2)([/])(29)([/])([3579" +
					"][26]00)$)|(^(0?2)([/])(29)([/])([1][89][0][48])$)|(^(0?2)([" +
					"/])(29)([/])([2-9][0-9][0][48])$)|(^(0?2)([/])(29)([/])([1][" +
					"89][2468][048])$)|(^(0?2)([/])(29)([/])([2-9][0-9][2468][048" +
					"])$)|(^(0?2)([/])(29)([/])([1][89][13579][26])$)|(^(0?2)([/]" +
					")(29)([/])([2-9][0-9][13579][26])$))";
			errorMessage = "Please enter the date in MM/DD/YYYY format."
			break;
			
		case "european date":
			re = /^(((0[1-9]|[12]\d|3[01])\/(0[13578]|1[02])\/((1[6-9]|[2-9]\d)\d{2}))|((0[1-9]|[12]\d|30)\/(0[13456789]|1[012])\/((1[6-9]|[2-9]\d)\d{2}))|((0[1-9]|1\d|2[0-8])\/02\/((1[6-9]|[2-9]\d)\d{2}))|(29\/02\/((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))$/;
			if ( testThis.value.match(re) ) 
				return true;
			errorMessage = "Please enter the date in DD/MM/YYYY format.";
			alert(errorMessage);
			testThis.focus();
			return false;			
			break;
				
		case "iso date":
			re = /^[0-9]{4}-(((0[13578]|(10|12))-(0[1-9]|[1-2][0-9]|3[0-1]))|(02-(0[1-9]|[1-2][0-9]))|((0[469]|11)-(0[1-9]|[1-2][0-9]|30)))$/
			if ( testThis.value.match(re) ) 
				return true;
			errorMessage = "Please enter the date in YYYY-MM-DD format.";
			alert(errorMessage);
			testThis.focus();
			return false;			
			break;

		case "digit":
		case "integer":
			theExp = "^\\d+$"
			errorMessage = "Please enter digits only."
			break;
			
		case "zipplus":
			/* Author: Steven Smith
			This regular expression will match either a 5 digit ZIP code or a ZIP+4 code formatted as 
			5 digits, a hyphen, and another 4 digits.
			*/
			theExp = "^\\d{5}$|^\\d{5}-\\d{4}$"	
			errorMessage = "Please enter a valid zip code."
			break;
			
		case "zip":
			/* Author: Steven Smith
			Matches 5 numeric digits, such as a zip code.
			*/
			theExp = "^\\d{5}$"	
			errorMessage = "Please enter a valid zip code."
			break;

		case "gender":
			theExp = "^[M,Fm,f]"
			errorMessage = "Please enter M/F only."
			break;		
			
		case "email":
			/*  Author: bilou mcgyver
				Does not allow IP for domain name : hello@154.145.68.12 
				does not allow litteral addresses "hello, how are you?"@world.com allows numeric 
				domain names after the last "." minimum 2 letters */			
			theExp = "^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]" +
					 "?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$"
			errorMessage = "Please enter a valid email address.";
			break;
		
		case "url plain":
			/* Author: Brad Dobyns
			A regular that validates URL's without the ht(f)tp(s):// and include North American domains (like .us and .ca).
			It will also work with ASP QueryStrings and anchor URL's. 
			Included .uk domain and expression now allows for URLs that contain JSP session IDs.
			Also has ability to include URLs that start with server names.
			*/
			theExp = "^ ?(www.|[a-zA-Z].)[a-zA-Z0-9\-\.]" +
				"+\.(com|edu|gov|mil|net|org|biz|info|name|museum|us|ca|uk|aspx)" +
				"(\:[0-9]+)*(/($|[a-zA-Z0-9\.\,\;\?\'\\\+&%\$#\=~_\-]+))*$"	
				errorMessage = "Please enter a vaild web url."
			break;	
					
		case "url":
			/* Author: Brad Dobyns
			A regular that validates URL's with or without the ht(f)tp(s):// and include North American domains (like .us and .ca).
			It will also work with ASP QueryStrings and anchor URL's. 
			Included .uk domain and expression now allows for URLs that contain JSP session IDs.
			Also has ability to include URLs that start with server names.
			*/
			theExp = "^(((ht|f)tp(s?))\://)?(www.|[a-zA-Z].)[a-zA-Z0-9\-\.]" +
				"+\.(com|edu|gov|mil|net|org|biz|info|name|museum|us|ca|uk|aspx)" +
				"(\:[0-9]+)*(/($|[a-zA-Z0-9\.\,\;\?\'\\\+&%\$#\=~_\-]+))*$"
				errorMessage = "Please enter a vaild web url."
			break;
			
		case "alphanumeric nospace":
			/*	Author:	Steven Smith
				Matches any alphanumeric string (no spaces).
			*/
			re = /^[a-zA-Z0-9]+$/;
			if ( testThis.value.match(re) ) 
				return true;
			errorMessage = "Please enter letters and numbers only.";
			alert(errorMessage);
			testThis.focus();
			return false;			
			break;

		case "number":
			/*  Author: Erik Pettersson
				A regular expression that matches numbers. 
			    Integers or decimal numbers with or without the exponential form. */
			theExp = "^[+-]?([0-9]*\.?[0-9]+|[0-9]+\.?[0-9]*)([eE][+-]?[0-9]+)?$";
			errorMessage = "Please enter a valid number."
			break;		
			
		case "password":
			/* letters, numbers, length between 6 and 15 characters. No special characters.
			   See commented out example to add other characters to expression */
			// theExp = "^([a-zA-Z0-9@*#]{6,15})$"
			theExp = "^([a-zA-Z0-9~.!#$%@*?_-]{4,15})$"
			errorMessage = "Password can contain any combination of letters and numbers and must be between 6 and 15 characters long."
			break;

		case "phone number with extension":
			/* (111) 222-3333 plus any number of characters afterword*/
			theExp = "^\\([0-9]{3}\\) [0-9]{3}-[0-9]{4}.*$"			
			errorMessage = "Please enter your phone number in the format '(555) 555-5555'";
			break;
			
		case "phone number":
		case "phone number hyphens":
			/* ex: "111-222-3333*/
			theExp = "^[0-9]{3}-[0-9]{3}-[0-9]{4}$"			
			errorMessage = "Please enter your phone number in the format '555-555-5555'";
			break;
						
		case "phone number plain":
			/* Style used in Conversent OTIS. All phone numbers 10 digits with spaces as separators 
			   ex: "111 222 3333*/
			theExp = "^[0-9]{3} [0-9]{3} [0-9]{4}$"			
			errorMessage = "Please enter your phone number in the format '555 555 5555'";
			break;

		case "phone number2":
			/* (111) 222-3333*/
			theExp = "^\\([0-9]{3}\\) [0-9]{3}-[0-9]{4}$"			
			errorMessage = "Please enter your phone number in the format '(555) 555-5555'";
			break;
			
		case "ssn":
			theExp = "^([0-9]{3}-[0-9]{2}-[0-9]{4})$";
			errorMessage = "Please enter a valid social security number in the format 555-55-5555."
			break;
			
		case "mm/dd":
			/* date without the year */
			theExp = "^(10|11|12|0?[123456789])([/])((0?[1-9])|((1|2)[0-9])|30|31)$";
			errorMessage = "Please enter MM/DD format. Omit the year, please.";
			break;

		case "mm/yyyy":
			/* date without the day */
			theExp = "(((0[123456789]|10|11|12)([/])(([1][9][0-9][0-9])|([2][0-9][0-9][0-9]))))";
			errorMessage = "Please enter MM/YYYY format. Omit the day, please.";
			break;
		case "mm/yy":
			/* date without the day */
			theExp = "^((0[1-9])|(1[0-2]))\\/(\\d{2})$";
			errorMessage = "Please enter MM/YY format. Omit the day, please.";
			break;

	}
	if (theExp.length > 0 ) {
		re = new RegExp(theExp);
		if ( re.test(testThis.value) ) 
			return true;
	}
	
	alert(errorMessage);
	// testThis.focus();
	// bug in Mozilla/Firefox: focus doesn't work w/o timeout (and still doesn't work well
	// mnb March 2005
	window.setTimeout("document.forms[0]." + testThis.id + ".focus()", 30)
	return false;
}





