	var theMessage = "Please complete the following: \n-----------------------------------\n";
	var noErrors = theMessage;
	var FucusToControl='';

	function Trim(myStr) {
		return LTrim(RTrim(myStr));
	}

	function LTrim(myStr) {
		if (myStr.charAt(0) == ' ') {
			myStr = LTrim(myStr.substring(1));
		}
		return myStr;
	}

	function RTrim(myStr) {
		if (myStr.charAt(myStr.length - 1) == ' ') {
			myStr = RTrim(myStr.substring(0, myStr.length - 1));
		}
		return myStr;
	}



	//----------Form submit--------------------------
	function validateFields(frm) {
		//Note: all parameters must be in lower case inside the tag: field, name, minlength, reqired, format, etc		
		for (i=0;i<frm.length;i++) {
		
			//check for required fields
			//to use, add required=1 in the <input> <textare> etc.
			//example 1: <input type='text' name='firstname' required='1'>
			//
			//example 2: <input type='radio' name='hello' required='1' field="Status">abc
			//			 <input type='radio' name='hello' value='y'>def
			//			 <input type='radio' name='hello' value='z'>ghi
			//
			//example 3: <select required="1" field="status">
			//              <option>....
			//           </select>
			validateFieldName = (frm[i].field ? frm[i].field : frm[i].name);

			if (frm[i].required == '1') {
				if (frm[i].type.toLowerCase() == 'text' || frm[i].type.toLowerCase() == 'password' || frm[i].tagName.toLowerCase() == 'textarea') {
					if (Trim(frm[i].value) == '') {						
						theMessage = theMessage + "\n  -->  " + validateFieldName;
						if (FucusToControl == '')  FucusToControl = frm[i];
					}
				}

				if (frm[i].tagName.toLowerCase() == 'select') {
					if (frm[i][frm[i].selectedIndex].value == '') {
						theMessage = theMessage + "\n  -->  " + validateFieldName;
						if (FucusToControl == '')  FucusToControl = frm[i];
					}
				}

				if (frm[i].type.toLowerCase() == 'radio') {
					var radioSelected = false
					var radioName = frm[i].name;
					for (j=0;j<frm.all[radioName].length;j++) {
						if (frm.all[radioName][j].checked) {
							radioSelected = true;
						}
					}
					if (!radioSelected) {
						theMessage = theMessage + "\n  -->  " + validateFieldName;
					}
				}
			}



			//check for minimum length
			//to use, add minlength in textarea, text fields.
			//you can have a min length field and not required.  in this case, if user enters any value then it must be at least n chars.
			//example: <input type='text' name='firstname' minlength='5'>
			//	if user enters nothing then it's valid
			//	if user enters 'hi' then it's not valid

			if (frm[i].type.toLowerCase() == 'text' || frm[i].tagName.toLowerCase() == 'textarea') {
				if (frm[i].minlength != '' && Trim(frm[i].value).length > 0) {
					if (Trim(frm[i].value).length < parseInt(frm[i].minlength)) {
						theMessage = theMessage + "\n  -->  " + validateFieldName + ' must be at least ' + frm[i].minlength + ' characters.';
						if (FucusToControl == '')  FucusToControl = frm[i];					}
				}
				if (frm[i].maxlength != '' && Trim(frm[i].value).length > 0) {
					if (Trim(frm[i].value).length > parseInt(frm[i].maxnlength)) {
						theMessage = theMessage + "\n  -->  " + validateFieldName + ' can be at most ' + frm[i].minlength + ' characters.'
						if (FucusToControl == '')  FucusToControl = frm[i];					}
				}
			}


			//check for fields formats
			//to use, add required=1 in the <input> <textare> etc.
			//valid parameters: phone, ssn, email
			//example: <input type='text' name='firstname' format='phone'>

			if (frm[i].type == 'text' && frm[i].format && (Trim(frm[i].value) != '')) {

				if (frm[i].format == 'email' && !isValidEmail(frm[i].value)) {					
					theMessage = theMessage + "\n  -->  " + 'Invalid ' + validateFieldName + ' entered'
						if (FucusToControl == '')  FucusToControl = frm[i];				}

				if (frm[i].format == 'date' && !isValidDate(frm[i].value)) {
					theMessage = theMessage + "\n  -->  " +'Invalid ' + validateFieldName + ' entered.\n\nValid format: mm/dd/yyyy'
						if (FucusToControl == '')  FucusToControl = frm[i];				}

				if (frm[i].format == 'numeric' && isNaN(frm[i].value)) {
					theMessage = theMessage + "\n  -->  " +'Invalid ' + validateFieldName + ' entered'
						if (FucusToControl == '')  FucusToControl = frm[i];				}
			}
		}

		return false;
	}

	function isValidEmail(str) {
		//One or more characters before the "@"
		//An optional "[", because user@[255.255.255.0] is a valid e-mail
		//A sequence of letters, numbers, and periods, which are all valid domain or IP address characters
		//A period followed by a 2-3 letter suffix
		//An optional "]"
		if (str.match(/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/)) {
			return true
		} 
		return false;
	}


	function isValidSSN(str) {
		//valid formats: 123-45-6789 or 123456789
		if (str.match(/\d{3}-\d{2}-\d{4}/)) {
			return true;
		}
		if (str.match(/\d{9}/)) {
			return true;
		}
		return false;
	}


	function isValidPhone(str) {
		//valid formats: 818-555-1234, 8185551234
		if (str.match(/\d{10}/)) {
			return true;
		} 
		if (str.match(/\d{3}-\d{3}-\d{4}/)) {
			return true;
		}
		return false;
	}

	function isValidDate(str) {
		//valid formats: mmddyyyy,  mm/dd/yyyy, mm-dd-yyyy, m/d/yyyy
		//this should cover most cases.
		//however, if user enters 01/32/2002, javascript will still return
		//	valid date as 02/01/2002 (ie, 01/31/2002 + 1 day)

		if (str.match(/\d{1,2}\D{1}\d{1,2}\D{1}\d{4}/)) {
			var testDate = new Date(str);
		}


		if (str.match(/\d{8}/)) {
			var testmonth = str.substring(1,2);
			var testdate  = str.substring(3,4);
			var testyear  = str.substring(5,8);
			var testDate = new Date(testyear, testmonth, testdate);
		}

		if (!isNaN(testDate)) {
			return true;
		}

		return false;

	}


//Checks to see if a plus or minus sign (optional) is at the start of the string, then one or more digits, 
//then an optional grouping of a decimal followed by one or more digits at the end of the string. 
function isValidNumber(inpString) {
   return /^[-+]?\d+(\.\d+)?$/.test(inpString);
}
function is2Character(inpString){
   return /^\w{2}$/.test(inpString);
}
function checkValueType(field,fieldName){
  var inputv = eval('document.forms[0].'+field+'.value');
  if(!isValidNumber(inputv)){
		eval("document.forms[0]."+field+".value = '' "); 
    alert("Please enter digit number for the '"+fieldName+"'"); 
		eval("document.forms[0]."+field+".focus()");
	}
}
function check2Character(field,fieldName){
  var inputv = eval('document.forms[0].'+field+'.value');
  if(!is2Character(inputv)){
		eval("document.forms[0]."+field+".value = '' "); 
    alert("Please enter two charachers for the '"+fieldName+"'"); 
		eval("document.forms[0]."+field+".focus()");
	}
}