//// --------- restrict access from designated domains-----...
// put this at the top of each js lib
var accepted_domains=new Array("localhost","tfcu23358","tfcu.org", "truliantfcu.org", "truliantfcuonline.org","TFCU.ORG","TFCU.org");
var domaincheck=document.location.href; //retrieve the current URL of user browser
var accepted_ok=false //set acess to false by default

if (domaincheck.indexOf("http")!=-1)
{ //if this is a http request
	for (r=0;r<accepted_domains.length;r++)
	{
		if (domaincheck.indexOf(accepted_domains[r])!=-1)
		{ //if a match is found
			accepted_ok=true //set access to true, and break out of loop
			break
		}
	}
}
else
{
	accepted_ok=true
}
if (!accepted_ok)
{
	//alert("You\'re not allowed to directly link to this .js file on our server!")
	//history.back(-1)
}
//---------------------------- end of restriction code



// ===================================================================
// Author: Matt Kruse <matt@mattkruse.com>
// WWW: http://www.mattkruse.com/
//
// NOTICE: You may use this code for any purpose, commercial or
// private, without any further permission from the author. You may
// remove this notice from your final code if you wish, however it is
// appreciated by the author if at least my web site address is kept.
//
// You may *NOT* re-distribute this code in any way except through its
// use. That means, you can include it in your product, or your web
// site, or any other form where the code is actually being used. You
// may not put the plain javascript up on your site for download or
// include it in your javascript libraries for download.
// If you wish to share this code with others, please just point them
// to the URL instead.
// Please DO NOT link directly to my .js files from your site. Copy
// the files to your server and use them there. Thank you.
// ===================================================================

// HISTORY
// ------------------------------------------------------------------
// December 29, 2003: Added the option to specify a delimiter for
//    multiple valued input field via getInputValue(), etc.

//-------------------------------------------------------------------
// Trim functions
//   Returns string with whitespace trimmed
//-------------------------------------------------------------------
function LTrim(str)
{
	if (str==null)
	{
		return null;
	}
	for(var i=0; str.charAt(i)==" "; i++);
	return str.substring(i, str.length);
}
function RTrim(str)
{
	if (str==null)
	{
		return null;
	}
	for(var i=str.length-1; str.charAt(i)==" "; i--);
	return str.substring(0, i+1);
}
function Trim(str)
{
	return LTrim(RTrim(str));
}
function trim(str)
{
	return LTrim(RTrim(str));
}
function LTrimAll(str)
{
	if (str==null)
	{
		return str;
	}
	for (var i=0; str.charAt(i)==" " || str.charAt(i)=="\n" || str.charAt(i)=="\t"; i++);
	return str.substring(i,str.length);
}
function RTrimAll(str)
{
	if (str==null)
	{
		return str;
	}
	for (var i=str.length-1; str.charAt(i)==" " || str.charAt(i)=="\n" || str.charAt(i)=="\t"; i--);
	return str.substring(0,i+1);
}
function TrimAll(str)
{
	return LTrimAll(RTrimAll(str));
}
//-------------------------------------------------------------------
// isNull(value)
//   Returns true if value is null
//-------------------------------------------------------------------
function isNull(val)
{
	return(val==null);
}

//-------------------------------------------------------------------
// isBlank(value)
//   Returns true if value only contains spaces
//-------------------------------------------------------------------
function isBlank(val)
{
	if(val==null)
	{
		return true;
	}
	for(var i=0;i<val.length;i++)
	{
		if ((val.charAt(i)!=' ')&&(val.charAt(i)!="\t")&&(val.charAt(i)!="\n")&&(val.charAt(i)!="\r"))
		{
			return false;
		}
	}
	return true;
}

//-------------------------------------------------------------------
// isInteger(value)
//   Returns true if value contains all digits
//-------------------------------------------------------------------
function isInteger(val)
{
	if (isBlank(val))
	{
		return false;
	}
	for(var i=0;i<val.length;i++)
	{
		if(!isDigit(val.charAt(i)))
		{
			return false;
		}
	}
	return true;
}

//-------------------------------------------------------------------
// isNumeric(value)
//   Returns true if value contains a positive float value
//-------------------------------------------------------------------
function isNumeric(val)
{
	return (parseFloat(val,10)==(val*1));
}

//-------------------------------------------------------------------
// isNumeric(value)
//   Returns true if value contains a positive float value
//-------------------------------------------------------------------
function isNumber(val)
{
	var reg = /^[0-9]+[0-9\.]*$/
	return reg.test(val);
}


//-------------------------------------------------------------------
// isArray(obj)
// Returns true if the object is an array, else false
//-------------------------------------------------------------------
function isArray(obj)
{
	return (typeof(obj.length)=="undefined") ? false : true;
}

//-------------------------------------------------------------------
// isDigit(value)
//   Returns true if value is a 1-character digit
//-------------------------------------------------------------------
function isDigit(num)
{
	if (num.length>1)
	{
		return false;
	}

	var string="1234567890";
	if (string.indexOf(num)!=-1)
	{
		return true;
	}
	return false;
}

//-------------------------------------------------------------------
// setNullIfBlank(input_object)
//   Sets a form field to "" if it isBlank()
//-------------------------------------------------------------------
function setNullIfBlank(obj){if(isBlank(obj.value)){obj.value="";}}

//-------------------------------------------------------------------
// setFieldsToUpperCase(input_object)
//   Sets value of form field toUpperCase() for all fields passed
//-------------------------------------------------------------------
function setFieldsToUpperCase(){
	for(var i=0;i<arguments.length;i++) {
		arguments[i].value = arguments[i].value.toUpperCase();
		}
	}

//-------------------------------------------------------------------
// disallowBlank(input_object[,message[,true]])
//   Checks a form field for a blank value. Optionally alerts if
//   blank and focuses
//-------------------------------------------------------------------
function disallowBlank(obj){
	var msg=(arguments.length>1)?arguments[1]:"";
	var dofocus=(arguments.length>2)?arguments[2]:false;
	if (isBlank(getInputValue(obj))){
		if(!isBlank(msg)){alert(msg);}
		if(dofocus){
			if (isArray(obj) && (typeof(obj.type)=="undefined")) {obj=obj[0];}
			if(obj.type=="text"||obj.type=="textarea"||obj.type=="password") { obj.select(); }
			obj.focus();
			}
		return true;
		}
	return false;
	}

//-------------------------------------------------------------------
// disallowModify(input_object[,message[,true]])
//   Checks a form field for a value different than defaultValue.
//   Optionally alerts and focuses
//-------------------------------------------------------------------
function disallowModify(obj){
	var msg=(arguments.length>1)?arguments[1]:"";
	var dofocus=(arguments.length>2)?arguments[2]:false;
	if (getInputValue(obj)!=getInputDefaultValue(obj)){
		if(!isBlank(msg)){alert(msg);}
		if(dofocus){
			if (isArray(obj) && (typeof(obj.type)=="undefined")) {obj=obj[0];}
			if(obj.type=="text"||obj.type=="textarea"||obj.type=="password") { obj.select(); }
			obj.focus();
			}
		setInputValue(obj,getInputDefaultValue(obj));
		return true;
		}
	return false;
	}

//-------------------------------------------------------------------
// commifyArray(array[,delimiter])
//   Take an array of values and turn it into a comma-separated string
//   Pass an optional second argument to specify a delimiter other than
//   comma.
//-------------------------------------------------------------------
function commifyArray(obj,delimiter){
	if (typeof(delimiter)=="undefined" || delimiter==null) {
		delimiter = ",";
		}
	var s="";
	if(obj==null||obj.length<=0){return s;}
	for(var i=0;i<obj.length;i++){
		s=s+((s=="")?"":delimiter)+obj[i].toString();
		}
	return s;
	}

//-------------------------------------------------------------------
// getSingleInputValue(input_object,use_default,delimiter)
//   Utility function used by others
//-------------------------------------------------------------------
function getSingleInputValue(obj,use_default,delimiter) {
	switch(obj.type){
		case 'radio': case 'checkbox': return(((use_default)?obj.defaultChecked:obj.checked)?obj.value:null);
		case 'text': case 'hidden': case 'textarea': return(use_default)?obj.defaultValue:obj.value;
		case 'password': return((use_default)?null:obj.value);
		case 'select-one':
			if (obj.options==null) { return null; }
			if(use_default){
				var o=obj.options;
				for(var i=0;i<o.length;i++){if(o[i].defaultSelected){return o[i].value;}}
				return o[0].value;
				}
			if (obj.selectedIndex<0){return null;}
			return(obj.options.length>0)?obj.options[obj.selectedIndex].value:null;
		case 'select-multiple':
			if (obj.options==null) { return null; }
			var values=new Array();
			for(var i=0;i<obj.options.length;i++) {
				if((use_default&&obj.options[i].defaultSelected)||(!use_default&&obj.options[i].selected)) {
					values[values.length]=obj.options[i].value;
					}
				}
			return (values.length==0)?null:commifyArray(values,delimiter);
		}
	alert("FATAL ERROR: Field type "+obj.type+" is not supported for this function");
	return null;
	}

//-------------------------------------------------------------------
// getSingleInputText(input_object,use_default,delimiter)
//   Utility function used by others
//-------------------------------------------------------------------
function getSingleInputText(obj,use_default,delimiter) {
	switch(obj.type){
		case 'radio': case 'checkbox': 	return "";
		case 'text': case 'hidden': case 'textarea': return(use_default)?obj.defaultValue:obj.value;
		case 'password': return((use_default)?null:obj.value);
		case 'select-one':
			if (obj.options==null) { return null; }
			if(use_default){
				var o=obj.options;
				for(var i=0;i<o.length;i++){if(o[i].defaultSelected){return o[i].text;}}
				return o[0].text;
				}
			if (obj.selectedIndex<0){return null;}
			return(obj.options.length>0)?obj.options[obj.selectedIndex].text:null;
		case 'select-multiple':
			if (obj.options==null) { return null; }
			var values=new Array();
			for(var i=0;i<obj.options.length;i++) {
				if((use_default&&obj.options[i].defaultSelected)||(!use_default&&obj.options[i].selected)) {
					values[values.length]=obj.options[i].text;
					}
				}
			return (values.length==0)?null:commifyArray(values,delimiter);
		}
	alert("FATAL ERROR: Field type "+obj.type+" is not supported for this function");
	return null;
	}

//-------------------------------------------------------------------
// setSingleInputValue(input_object,value)
//   Utility function used by others
//-------------------------------------------------------------------
function setSingleInputValue(obj,value) {
	switch(obj.type){
		case 'radio': case 'checkbox': if(obj.value==value){obj.checked=true;return true;}else{obj.checked=false;return false;}
		case 'text': case 'hidden': case 'textarea': case 'password': obj.value=value;return true;
		case 'select-one': case 'select-multiple':
			var o=obj.options;
			for(var i=0;i<o.length;i++){
				if(o[i].value==value){o[i].selected=true;}
				else{o[i].selected=false;}
				}
			return true;
		}
	alert("FATAL ERROR: Field type "+obj.type+" is not supported for this function");
	return false;
	}

//-------------------------------------------------------------------
// getInputValue(input_object[,delimiter])
//   Get the value of any form input field
//   Multiple-select fields are returned as comma-separated values, or
//   delmited by the optional second argument
//   (Doesn't support input types: button,file,reset,submit)
//-------------------------------------------------------------------
function getInputValue(obj,delimiter) {
	var use_default=(arguments.length>2)?arguments[2]:false;
	if (isArray(obj) && (typeof(obj.type)=="undefined")) {
		var values=new Array();
		for(var i=0;i<obj.length;i++){
			var v=getSingleInputValue(obj[i],use_default,delimiter);
			if(v!=null){values[values.length]=v;}
			}
		return commifyArray(values,delimiter);
		}
	return getSingleInputValue(obj,use_default,delimiter);
	}

//-------------------------------------------------------------------
// getInputText(input_object[,delimiter])
//   Get the displayed text of any form input field
//   Multiple-select fields are returned as comma-separated values, or
//   delmited by the optional second argument
//   (Doesn't support input types: button,file,reset,submit)
//-------------------------------------------------------------------
function getInputText(obj,delimiter) {
	var use_default=(arguments.length>2)?arguments[2]:false;
	if (isArray(obj) && (typeof(obj.type)=="undefined")) {
		var values=new Array();
		for(var i=0;i<obj.length;i++){
			var v=getSingleInputText(obj[i],use_default,delimiter);
			if(v!=null){values[values.length]=v;}
			}
		return commifyArray(values,delimiter);
		}
	return getSingleInputText(obj,use_default,delimiter);
	}

//-------------------------------------------------------------------
// getInputDefaultValue(input_object[,delimiter])
//   Get the default value of any form input field when it was created
//   Multiple-select fields are returned as comma-separated values, or
//   delmited by the optional second argument
//   (Doesn't support input types: button,file,password,reset,submit)
//-------------------------------------------------------------------
function getInputDefaultValue(obj,delimiter){return getInputValue(obj,delimiter,true);}

//-------------------------------------------------------------------
// isChanged(input_object)
//   Returns true if input object's value has changed since it was
//   created.
//-------------------------------------------------------------------
function isChanged(obj){return(getInputValue(obj)!=getInputDefaultValue(obj));}

//-------------------------------------------------------------------
// setInputValue(obj,value)
//   Set the value of any form field. In cases where no matching value
//   is available (select, radio, etc) then no option will be selected
//   (Doesn't support input types: button,file,password,reset,submit)
//-------------------------------------------------------------------
function setInputValue(obj,value) {
	var use_default=(arguments.length>1)?arguments[1]:false;
	if(isArray(obj)&&(typeof(obj.type)=="undefined")){
		for(var i=0;i<obj.length;i++){setSingleInputValue(obj[i],value);}
		}
	else{setSingleInputValue(obj,value);}
	}

//-------------------------------------------------------------------
// isFormModified(form_object,hidden_fields,ignore_fields)
//   Check to see if anything in a form has been changed. By default
//   it will check all visible form elements and ignore all hidden
//   fields.
//   You can pass a comma-separated list of field names to check in
//   addition to visible fields (for hiddens, etc).
//   You can also pass a comma-separated list of field names to be
//   ignored in the check.
//-------------------------------------------------------------------
function isFormModified(theform,hidden_fields,ignore_fields){
	if(hidden_fields==null){hidden_fields="";}
	if(ignore_fields==null){ignore_fields="";}
	var hiddenFields=new Object();
	var ignoreFields=new Object();
	var i,field;
	var hidden_fields_array=hidden_fields.split(',');
	for (i=0;i<hidden_fields_array.length;i++) {
		hiddenFields[Trim(hidden_fields_array[i])]=true;
		}
	var ignore_fields_array=ignore_fields.split(',');
	for (i=0;i<ignore_fields_array.length;i++) {
		ignoreFields[Trim(ignore_fields_array[i])]=true;
		}
	for (i=0;i<theform.elements.length;i++) {
		var changed=false;
		var name=theform.elements[i].name;
		if(!isBlank(name)){
			var type=theform.elements[i].type;
			if(!ignoreFields[name]){
				if(type=="hidden"&&hiddenFields[name]){changed=isChanged(theform[name]);}
				else if(type=="hidden"){changed=false;}
				else {changed=isChanged(theform[name]);}
				}
			}
		if(changed){return true;}
		}
		return false;
	}
//  ===================end of code by Matt Kruse <matt@mattkruse.com> ======================================


//   ================= coded modified from code above
//-------------------------------------------------------------------
// Trim functions
//   Returns string with whitespace trimmed
//-------------------------------------------------------------------
// trim space from left
function lTrim(str)
{
	if (str==null)
	{
		return null;
	}
	for(var i=0; str.charAt(i)==" "; i++);
	return str.substring(i, str.length);
}
// trim space from right
function rTrim(str)
{
	if (str==null)
	{
		return null;
	}
	for(var i=str.length-1; str.charAt(i)==" "; i--);
	return str.substring(0, i+1);
}
// trim space from both left and right
function trim(str)
{
	return lTrim(RTrim(str));
}
// trim space, \n, \t from left
function lTrimAll(str)
{
	if (str==null)
	{
		return str;
	}
	for (var i=0; str.charAt(i)==" " || str.charAt(i)=="\n" || str.charAt(i)=="\t"; i++);
	return str.substring(i,str.length);
}
// trim space, \n, \t from right
function rTrimAll(str)
{
	if (str==null)
	{
		return str;
	}
	for (var i=str.length-1; str.charAt(i)==" " || str.charAt(i)=="\n" || str.charAt(i)=="\t"; i--);
	return str.substring(0,i+1);
}
// trim space, \n, \t from borth left and right
function trimAll(str)
{
	return lTrimAll(rTrimAll(str));
}
//// ---- end of string trimming  functions  ------------------------------

//// ==========================================================================================================


//----------------begin code by Truliant FCU ------------------- ....
//--------------

//verify if the input is empty (null or only spaces)
function isEmpty(str)
{
	if (isBlank(str) || isNull(str))
	{
		return true;
	}
	return false;
}


// verify email address
function isEmail(str)
{
	//valid email address pattern:
	//	1. One or more characters before the "@"
	//	2. An optional "[", because user@[255.255.255.0] is a valid e-mail
	//	3. A sequence of letters, numbers, and periods, which are all valid domain or IP address characters
	//	4. A period followed by a 2-3 letter suffix
	//	5. An optional "]"

	var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
	var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid

	return (!reg1.test(str) && reg2.test(str)) ;
}

// verify URL pattern
function isUrl(str)
{
	//valid URL pattern:
	//	1. http:// or https://
	//	2. followed by: *.*[.*]?.[a-z]{2,3}.*
	//		e.g., www.truliantfcu.org, www.sina.com.cn

	var reg = /^((http)|(https)){1}:\/\/(([0-9a-zA-Z]*)(\.([0-9a-zA-Z]*))+(\.[a-zA-Z]{2,3})).*$/;  // valid

	return reg.test(str) ;
}


// verify 3-digit area code
function isAreacode(str)
{
	//valid area code pattern:
	//	1. 3 digits: xxx
	//	2. area codes are in range: 2xx-9xx (ref: http://www.the-acr.com/codes/usa2.htm)

	var reg = /^([2-9]{1}[0-9]{2})$/;

	return reg.test(str) ;
}

// verify complete 10-digit phone number
function isPhone(str)
{
	//valid phone number patterns:
	//	1. 10 digits: xxxxxxxxxx OR
	//	2. (xxx)xxxxxxx or (xxx)xxx-xxxx OR
	//	3. xxx-xxxxxxx or xxx-xxx-xxxx
	//	4. area code must start with non-zero digit

	var reg = /^(([1-9]{1}[0-9]{9})|(\([1-9]{1}[0-9]{2}\)[0-9]{7})|(\([1-9]{1}[0-9]{2}\)[0-9]{3}-[0-9]{4})|([1-9]{1}[0-9]{2}-[0-9]{7})|([1-9]{1}[0-9]{2}-[0-9]{3}-[0-9]{4}))$/; // valid phone pattern

	return reg.test(str) ;
}


// verify 4-digit phone number
function isPhoneExt(str)
{
	//valid phone number patterns:
	//	1. 1 - 4 digits

	var reg = /^([0-9]{1,4})$/; // valid phone pattern

	return reg.test(str) ;
}


// verify firstname and lastname
function isName(str)
{
	//valid name pattern:
	//	1. a-zA-Z
	//	2. firstname lastname  (one single space as separator) OR
	//	3. firstname middlename lastname

	var reg = /^([a-zA-Z]{1}[a-zA-Z\.]*\s?[a-zA-Z\.]*[\s?[a-zA-Z\.]*]?)$/; // valid pattern

	return reg.test(str) ;
}


// verify extended name, like company name, with numerical digits allowed
function isExtendedname(str)
{
	//valid name pattern:
	//	1. a-zA-Z
	//	2. 0-9

	var reg = /^([0-9a-zA-Z]{1}[0-9a-zA-Z\.]*(\s?[0-9a-zA-Z\.])*)$/; // valid pattern

	return reg.test(str) ;
}
// for compatibility with old version of forms only; may removed when all forms are updated
function isExtendedName(str)
{
	//valid name pattern:
	//	1. a-zA-Z
	//	2. 0-9

	var reg = /^([0-9a-zA-Z]{1}[0-9a-zA-Z\.]*(\s?[0-9a-zA-Z\.])*)$/; // valid pattern

	return reg.test(str) ;
}


// verify 4-digit year
function isYear(str)
{
	//valid year pattern:
	//	1. year in the range of 19xx
	//  2. year in the range of 2xxx

	var reg = /^(19[0-9]{2})$/; // valid pattern : 19xx
	var reg2 = /^(2[0-9]{3})$/; // valid pattern: 2xxx
	return (reg.test(str) || reg2.test(str)) ;
}


// verify month
function isMonth(str)
{
	//valid month pattern:
	//	1. month range 0-9,00-09 (1 or 2 digits)
	//	2. month rage 10-12 (2 digits)

	//var reg = /^(([0-9]{1})|(0[0-9]{1}))?$/; // month 00 - 09
	//OR split into reg,reg2
	var reg  = /^(0?[1-9]{1})$/; // month 1-9, or 01 - 09
	var reg2 = /^(1[0-2]{1})$/; // month 10 - 12
	return (reg.test(str)||reg2.test(str)) ;
}


// verify day of month
function isDay(str)
{
	//valid day pattern:
	//	1  day range 1-9 or 01-09 (1 or 2 digits)
	//	2. day range 10-29 (2 digits)
	//	3. day range 30-31 (2 digits)

	var reg  = /^(0?[1-9]{1})$/; // day 1 - 9, or 01 - 09
	var reg2 = /^([12]{1}[0-9]?)$/; // day 10 - 29
	var reg3 = /^(3[0-1]{1})$/; // day 30-31
	return  (reg.test(str) || reg2.test(str)|| reg3.test(str)) ;
}


// verify date
function isDate(str)
{
	//valid date pattern: month/year or month/day/year;month and day can be 1 or 2 digits; year must be 4 digits
	//	1. 09/19xx or
	//	2. 09/2xxx or
	//	3. 09-19xx or
	//	4. 09-2xxx or
	//	5. 09/10/19xx or
	//	6. 09/10/2xxx or
	//	7. 09-10-1920 or
	//	8. 09-10-2xxx

	//month/year or month-year
	var reg  = /^((0?[1-9]{1})|(1[0-2]{1}))\/19[0-9]{2}$/; // valid pattern 1
	var reg2 = /^((0?[1-9]{1})|(1[0-2]{1}))\/2[0-9]{3}$/; // valid pattern 2
	var reg3 = /^((0?[1-9]{1})|(1[0-2]{1}))-19[0-9]{2}$/; // valid pattern 3
	var reg4 = /^((0?[1-9]{1})|(1[0-2]{1}))-2[0-9]{3}$/; // valid pattern 4

	//month/day/year or month-day-year
	var reg5 = /^(((0?[1-9]{1})|(1[0-2]{1}))\/((0?[1-9]{1})|([1-2]{1}[0-9]{1})|(3[0,1]))\/19[0-9]{2})$/; // valid pattern 5
	var reg6 = /^(((0?[1-9]{1})|(1[0-2]{1}))\/((0?[1-9]{1})|([1-2]{1}[0-9]{1})|(3[0,1]))\/2[0-9]{3})$/; // valid pattern 6
	var reg7 = /^(((0?[1-9]{1})|(1[0-2]{1}))-((0?[1-9]{1})|([1-2]{1}[0-9]{1})|(3[0,1]))-19[0-9]{2})$/; // valid pattern 7
	var reg8 = /^(((0?[1-9]{1})|(1[0-2]{1}))-((0?[1-9]{1})|([1-2]{1}[0-9]{1})|(3[0,1]))-2[0-9]{3})$/; // valid pattern 8

	return  (reg.test(str) || reg2.test(str) || reg3.test(str) || reg4.test(str)
				|| reg5.test(str) || reg6.test(str) || reg7.test(str) || reg8.test(str))  ;
}

// verify date & time
function isDatetime(str)
{
	//valid date pattern: month/day/year HH:MM:ss; 
	// month and day can be 1 or 2 digits; year must be 4 digits
	// hour and minuts are 2 digits; seconds are optional
	 
	//	1. 09/10/19xx HH:MM:ss (am|pm)
	//	2. 09/10/2xxx HH:MM:ss (am|pm)
	//	3. 09-10-19xx HH:MM:ss (am|pm)
	//	4. 09-10-2xxx HH:MM:ss (am|pm)

	//month/day/year or month-day-year
	var reg1 = /^(((0?[1-9]{1})|(1[0-2]{1}))[\/-]((0?[1-9]{1})|([1-2]{1}[0-9]{1})|(3[0,1]))[\/-]19[0-9]{2})\s?\d{2}:\d{2}(:\d{2})?\s?(am|pm)?$/; // valid pattern 5
	var reg2 = /^(((0?[1-9]{1})|(1[0-2]{1}))[\/-]((0?[1-9]{1})|([1-2]{1}[0-9]{1})|(3[0,1]))[\/-]2[0-9]{3})\s?\d{2}:\d{2}(:\d{2})?\s?(am|pm)?$/; // valid pattern 6

	return  (reg1.test(str) || reg2.test(str))  ;
}

// verify date  of birth
function isBirthday(str)
{
	//valid date pattern: month/year or month/day/year; month and day can be 1 or 2 digits; year must be 4 digits
	//	1. 09/10/19xx or
	//	2. 09/10/2xxx or
	//	3. 09-10-1920 or
	//	4. 09-10-2xxx

	//month/day/year or month-day-year
	//					MM								DD										YYYY
	var reg	 = /^(((0?[1-9]{1})|(1[0-2]{1}))\/((0?[1-9]{1})|([1-2]{1}[0-9]{1})|(3[0,1]))\/19[0-9]{2})$/; 	// valid pattern 1
	var reg2 = /^(((0?[1-9]{1})|(1[0-2]{1}))\/((0?[1-9]{1})|([1-2]{1}[0-9]{1})|(3[0,1]))\/2[0-9]{3})$/; 	// valid pattern 2
	var reg3 = /^(((0?[1-9]{1})|(1[0-2]{1}))-((0?[1-9]{1})|([1-2]{1}[0-9]{1})|(3[0,1]))-19[0-9]{2})$/; 		// valid pattern 3
	var reg4 = /^(((0?[1-9]{1})|(1[0-2]{1}))-((0?[1-9]{1})|([1-2]{1}[0-9]{1})|(3[0,1]))-2[0-9]{3})$/; 		// valid pattern 4

	return  (reg.test(str) || reg2.test(str) || reg3.test(str) || reg4.test(str));
}


// verify the number is amount of dallors
function isDollars(str)
{
	//valid dollar amount patterns:
	//	1. a group of digits [0-9]* or
	//	2. [1-9]*.xx ( start with digits, followed by '.' and at most two digits after '.'

	var reg = /^([0-9]{1,}(\,[0-9]{3})*(\.[0-9]{1,2})?)$/;
	return reg.test(str) ;
}

// verify the mileage of vehicle
function isMileage(str)
{
	//valid mileage patterns:
	//	1. a group of digits [0-9]* or
	//	2. [0-9]*,[0-9]* ( start with digits, followed by ',' and digits; may repeat twice

	var reg = /^(([1-9]{1}[0-9]*)(\,[0-9]{3}){0,2})$/;
	return reg.test(str) ;
}

// verify the vehicle identification number (VIN)
function isVIN(str)
{
	//valid VIN patterns:
	//	1. a group of digits [0-9a-zA-Z]*

	var reg = /^([0-9a-zA-Z]{13,17})$/;
	return reg.test(str) ;
}

// verify the time of day
function isTime(str)
{
	//valid time patterns:
	//	1. [0-9]{1,2}:[0-9]{2}
	//	2. [0-9]{1,2}:[0-9]{2}(am|pm)

	var reg = /^([0-9]{1,2}:([0-9]{2})(am|AM|pm|PM)?)$/;
	return reg.test(str) ;
}

// verify SSN format
function isSSN(str)
{
	//valid SSN patterns:
	//  Any 9 digits in the format:
	//	1. xxxxxxxxx or
	//	2. xxx-xx-xxxx

	var reg = /^(([0-9]{9})|([0-9]{3}-[0-9]{2}-[0-9]{4}))$/;
	return reg.test(str) ;
}

// verify SSN format
function isSsn(str)
{
	//valid SSN patterns:
	//  Any 9 digits in the format:
	//	1. xxxxxxxxx or
	//	2. xxx-xx-xxxx

	var reg = /^(([0-9]{9})|([0-9]{3}-[0-9]{2}-[0-9]{4}))$/;
	return reg.test(str) ;
}

// verify Mailing Address format
function isMailing(str)
{
	//valid Mailing Address patterns:
	//	1. valid characters: space, #, ., -, [0-9],[a-zA-Z]
	//  2. must start with street number followed by a space
	//	3. p.o.box

	var reg = /^([-\s\.#,a-zA-Z0-9]+)$/;
	return reg.test(str) ;
}

// verify Street Address format
function isStreet(str)
{
	//valid Street Address patterns:
	//	1. valid characters: space, #, ., -, [0-9],[a-zA-Z]
	//  2. must start with street number followed by a space

	var reg = /^([0-9]+\s[-\s\.#,a-zA-Z0-9]+)$/;
	return reg.test(str) ;
}

// verify City name format
function isCity(str)
{
	//valid City name patterns:
	//	1. valid characters: space, -, [a-zA-Z]
	//  2. must start with [a-zA-Z]; if followed by a space or -, must also be followed by another [a-zA-Z] after it. can repeat multiple times.

	var reg = /^([a-zA-Z]+([\s-]?[a-zA-Z]+)+)$/;
	return reg.test(str);
}


// verify State name format
function isState(str)
{
	//valid State name patterns:
	//	1. valid characters: space, a-zA-Z
	//  2. [a-zA-Z] or [a-zA-Z] [a-zA-Z]
	//		must start with [a-zA-Z]; if followed by a space,  must also be followed once by another [a-zA-Z] after it.

	var reg = /^([a-zA-Z]+([\s]?[a-zA-Z]+)?)$/;
	return reg.test(str);
}

// verify 5 digit zipcode
function isZipcode(str)
{
	//valid zipcode pattern:
	//	1. 5 digits: xxxxx
	//	2. zipcode can start with 0

	var reg = /^([0-9]{5})$/; // valid pattern

	return reg.test(str);
}

//verify regular text string
function isText(str)
{
	return /.*/.test(Trim(str));	//accept everything
}

//set up flag of javascript support in client browser
function js_validated(flag)
{
	//if this hidden would be generated in the form, it means the javascript is enabled in browser, no matter what the flag is; then server-side PHP code would only
	//	need to check if $_REQUEST['js_validated'] is set, if set, do not do PHP validate
	//for client side js validation:
	//	flag=1, js validation would be applied in client side;
	//	flag=0, js validation would not be applied in client side even if the browser js support is enabled; then server-side validation must be conducted.
	document.write("<input type='hidden' name='js_validated' value='" + flag + "'>")
}




//	/* ---- form data processing code: old version using functions-----------------
//
//	//each form field should have a <label for='fieldname'> associated with it.
//	//if there is error with the field data, the color of <label> will be set to 'RED' through 'style.color="red"'
//
//	 //addError() - add error message to errorsArray[]
//	 //getError() - retrieve error message from errorsArray[]
//	 //hasError() - check if there is item in errorsArray[]
//	 //resetError() - reset errorsArray[]
//	 //label_color() - set or restore color of labels
//
//	 declare this array to be used as an associative array with fieldanme as index, errMsg as value
//	var errorsArray   = new Array();
//
//	 declare this array to be used as an associative array with fieldanme as index, original label color as value
//	var label_colors  = new Array();
//
//	add new error message based on specified 'fieldname', 'errMsg'
//	if the 'errMsg' is empty '', meaning no error, the array size will decrement*/
//	function addError(fieldname, errMsg)
//	{
//		argument : fieldname - the name of a form field
//					 errMsg    - error message to be added with 'fieldname'
//
//		errorsArray[fieldname] = errMsg;
//
//		set the array length property which is not automatically increases for an associative array
//		if((errMsg==''))
//		{
//			if (errorsArray.length > 1) //unset this 'fieldname'
//				errorsArray.length -= 1;
//		}
//		else
//			errorsArray.length += 1;
//
//		 access function arguments...
//				document.write('arguments: ' + arguments.length + '<br />');
//				document.write('argument : ' + arguments[0] + '<br />');
//				document.write('argument : ' + arguments[1] + '<br />');
//	}
//
//	 check if there is any error
//	function hasError()
//	{
//		return errorsArray.length ;
//	}
//
//	retrieve error message based on specified 'fieldname'
//	function getError(fieldname)
//	{
//		argument : fieldname - the name of a form field
//
//		if ((typeof errorsArray[fieldname]) == 'undefined')
//			return '';
//		else
//			return errorsArray[fieldname];
//	}
//
//	reset errorsArray[]
//	function resetError()
//	{
//		errorsArray = new Array();
//	}
//
//	change the color for the label of field with error
//	function label_color(frm)
//	{
//		argument : frm - the form handle
//
//		var labels = frm.getElementsByTagName("label"); //get all label tags into an array
//		var label, index=0;
//
//			document.write('label length: '+labels.length +'<br />');
//			document.write('label length: '+labels[0].htmlFor +'<br />');
//
//			Loop through labels retrieved
//		while(index < labels.length)
//		{
//			get one lable for processing
//			label = labels[index];
//
//			initialize
//			avoid saving twice, especially the error color 'red' which should not be saved at all
//			if(typeof label_colors[label.htmlFor] == 'undefined')
//			{
//				label_colors[label.htmlFor] = label.style.color; //'#000000'; //save the original color
//			}
//
//			if its corresponding field value has error, change the label color
//			if(getError(label.htmlFor) != '')
//			{
//				save original color
//				to save only the original label color, avoid saving the 'red' color for indicating error.
//				if the original color style in 'label.style.color' is not set, then its value would be just ''.
//				if (label.style.color != 'red')
//				{
//					alert('saving color for ' + label.htmlFor + ' color='+label.style.color)
//					label_colors[label.htmlFor] = label.style.color;
//				}
//
//				set color 'RED' to the label to indicate error
//				label.style.color = 'red';
//			}
//			else
//			{
//				label.style.colr = label_colors[label.htmlFor];
//			}
//
//			index ++ ;
//
//		}
//for debug
//		for(key in label_colors)
//			alert('==== saved colors: ' + key + ' : '+ label_colors[key])

//	}
	// ------ end of error processing code: ------------------





//========================== form data processing code  : validate form based on data types used in from =========================
// NOTE:
//	1. Require the defintion of array of fields to be validated in each html page
//	2. Default rule to pass form data from browser to server:
//		- 'radio, checkbox, multiple selection' will not be passed in $_REQUEST if not checked or selected.
//		- 'select' will be passed because it always has the first <option> as default
//	3. Each form field should have a <label for='fieldname'> associated with it. if there is error with the field data, the color of <label> will be set to 'RED' through 'style.color="red"'
//
//
// JS class to validate form:
// 	 All public member functions (declared with 'this.') must be called with prefix 'this.'
//   member functions:
//	 	addError()    - add error message to errorsArray[]
//	 	getError()    - retrieve error message from errorsArray[]
//	 	hasError()    - check if there is item in errorsArray[]
//	 	resetError()  - reset errorsArray[]
//	 	label_color() - set or restore color of labels

function class_validation(frm)
{
	 //public
	 //declare this array to be used as an associative array with fieldanme as index, errMsg as value
		//this.errorsArray   = new Array();
	 //declare this array to be used as an associative array with fieldanme as index, original label color as value
		//this.label_colors  = new Array();
	//	 however, declaration here would not be able to keep the origial color between two separate submit ***

	//add new error message based on specified 'fieldname', 'errMsg'
	this.addError =function (fieldname, errMsg)
	{
		//argument : fieldname - the name of a form field
		//			 errMsg    - error message to be added with 'fieldname'

		//errMsg = errMsg.replace(/\[\]/, '');	//before adding, remove the character '[]' in some special fields names, like checkboxgroup, and multi_select
		errorsArray[fieldname] = errMsg; 	//add error message

		//set the array length property which is not automatically increases for an associative array
		if((errMsg==''))
		{
			if (errorsArray.length > 1) //unset this 'fieldname'
				errorsArray.length -= 1;
		}
		else
			errorsArray.length += 1;

		// access function arguments...
		//		document.write('arguments: ' + arguments.length + '<br />');
		//		document.write('argument : ' + arguments[0] + '<br />');
		//		document.write('argument : ' + arguments[1] + '<br />');
	}

	// check if there is any error
	this.hasError=function()
	{
		return errorsArray.length ;
	}

	//retrieve error message based on specified 'fieldname'
	this.getError=function(fieldname)
	{
		//argument : fieldname - the name of a form field
		if ((typeof errorsArray[fieldname]) == 'undefined')
		{
			return '';
		}
		else
		{
			return errorsArray[fieldname];
		}
	}


	//display error messages
	this.displayError=function()
	{
		var err = "Error checklist: " + this.hasError() + " errors \n -------------------------------\n";
		var i = 1;
		for(var index in errorsArray)
		{
			////replace the '_' or '[]' with space ' ' in index string;
			////remove index string included in the array element
			//	var reg = new RegExp(index);	//construct a new reg using array 'index'?
			//	err += index.replace(/(_)|(\[\])/g, ' ') + ' :  ' + errorsArray[index].replace(reg,'') + "\n";

			err += i++ + '. '+ index.replace(/(_)|(\[\])/g, ' ') + ' :  ' + errorsArray[index] + "\n";
		}
		alert(err);
	}


	//reset errorsArray[]
	this.resetError=function()
	{
		errorsArray = new Array();
	}

	//change the color for the label of field with error
	this.label_color=function (frm)
	{
		//argument : frm - the form handle

		var labels = frm.getElementsByTagName("label"); //get all label tags into an array
		var label, index=0;
		var Opera = 0;
		if ( navigator.userAgent.indexOf('Opera') != -1)
		{
			Opera = 1;
		}

		//	Loop through labels retrieved
		while(index < labels.length)
		{
			//get one lable for processing
			label = labels[index];
			
			////remove error flag which may come from last submit
//			if(Opera)
//			{
//				label.innerHTML = label.innerHTML.replace(/<span.*>.*<.*span>$/gi, "");	
//			}


			//initialize
			//avoid saving twice, especially the error color 'red' which should not be saved at all
			if(typeof label_colors[label.htmlFor] == 'undefined')
			{
				label_colors[label.htmlFor] = label.style.color; //'#000000';
			}


			//if its corresponding field value has error, change the label color
			if(this.getError(label.htmlFor) != '')
			{
				//IE and Mozilla can keep the original colors of the lable for form fields, while Opera cannot
				//if all original form labels are in black, the code block 'if(Opera){}' would not be necessary
				//note: added string ':error!' to label may change the layout of the form fields.
//				if(Opera)
//				{
//					var reg = /(<.*>!)(.*)(<.*>)$/gi;
//					if (!reg.test(label.innerText))
//					{
//						//label.innerHTML = label.innerHTML +" <span style='color:red'>: error!</span>";	//add error flag
//					}
//				}
//				else
				{
					//save original color
					//to save only the original label color, avoid saving the 'red' color for indicating error.
					//if the original color style in 'label.style.color' is not set, then its value would be just ''.
					if (label.style.color != 'red')
					{
						label_colors[label.htmlFor] = label.style.color;
					}

					//set color 'RED' to the label to indicate error
					label.style.color = 'red';
				}
			}
			else
			{
//				if(Opera)
//				{ 
//					//label.innerHTML = label.innerHTML.replace(/<span.*>.*<.*span>$/gi, "");	//remove error flag
//				}
//				else
				{
					//label.style.color = label_colors[label.htmlFor];	//restore the original color
					label.style.color = '#000000';	//set color to normal 'black'
				}
			}

			index ++ ;

		}
	}//end label_color()
	this.labelColor = this.label_color	//give an alias for naming consistency since label_color() has been used;
										//with this alias, both names will work
	
	// ------ end of error processing code: ------------------
}//end of class_validation()



// declare this array to be used as an associative array with fieldanme as index, errMsg as value
var errorsArray   = new Array();

// declare this array to be used as an associative array with fieldanme as index, original label color as value
var label_colors  = new Array();

//constant array of error descriptions in a hash table: type -> description
var errorsDesc    = {
					"birthday"		:		"check date format",
					"checkboxgroup"	:		"must check one",
					"city"			:		"is bad city name",
					"date"			:		"check date format",
					"datetime"		:		"check date & time format",
					"dollars"		: 		"should be number",
					"email"			:  		"check email format",
					"extendedname"	:		"is not valid name",
					"integer"		:		"must be an integer number",
					"mailing"		:		"is not valid mailing address",
					"name"			:  		"check letters in spelling",
					"number"		:		"is not a numeric vaue",
					"phone"			:		"should be 10 digits",
					"radiogroup"	: 		"must check one",
					"select"		:		"must select one",
					"ssn" 			:		"SSN should 9 digits",
					"street"		:		"street number followed by street name",
					"text" 			:		"can not be empty",
					"year"			:		"year should be four digits",
					"zipcode"		:		"should be 5 digits",
					"url"			:		"is bad URL",
					"vin"			:		"is bad VIN number" 
				};

//instantiate of class: declare outside of function validate_form() so that the code including this .js file could access it
var validator = new class_validation( )	//instance

//validate the passed form
//argument: frm - name or id of the form to validate
//			showAlert - 1=show alert window with errors; 0=not show
function validate_form(frm, showAlert)
{
		//now setup a parameter which would control the dipslay of alert window for error message
		//by default, the error message will be alerted
		//sometimes it is necessary to not popup the window before some other processing of the form, like fields dependence checking 
		//which wuold normally come after validate_form() is called
		var showAlert = (showAlert == null) ? 1 : 0;	//1 - to show alert window; 0 - not show
		
		//instantiate of class
//		var validator = new class_validation( )	//instance

		validator.resetError();		//reset the object holding the array of errors on every submit

		var numElements = frm.elements.length; //number of elements in the form, including 'reset','submit' button if any

		var numUnchecked = 0; //flag to hold number of unchecked 'radio' or 'checkbox' in a group of radio or checkbox

		var count =0;		//count the number items (radio button or checkbox) has been checked in a radio or checkbox group

		for(var i = 0; i < numElements; i++)	//loop through all form elements
		{
			var elem  = frm.elements[i]
			var value = trim(elem.value)

			//skip 'submit', 'reset'  fields
			if ((elem.type == 'submit') || (elem.type == 'reset'))
				continue;

			elem.value = value;		//assign trimmed value back;
			
			//skip those fields that do not require validation: not set in array 'fields'
			var fieldtype = new String('') ;
			if ((fields[elem.name] != undefined) && (fields[elem.name]["type"] != undefined))
			{
				//get the data type of the field
				fieldtype = fields[elem.name]["type"]

				//uppercase the first character to match corresponding validation function name.
				//the lettercase may be specified in array 'fields', here it is just double check
				fieldtype = fieldtype.substr(0,1).toUpperCase() + fieldtype.substr(1);
			}
			else
				continue;	 //skipt to next element

			//to do: editing to make the data types more complete
			// Array 'fields' should be prepared in the html page containing the form to be validated
			var ftype = fieldtype.toLowerCase();
			switch(ftype)
			{
				case 'integer':		//a integer value, check format and range
						if(fields[elem.name]["required"] || (!fields[elem.name]["required"] && !isEmpty(value)))
						{
							if(!isInteger(value))
							{
								validator.addError(elem.name,  errorsDesc[ftype]);
							}
							else if((fields[elem.name]["min"]!=null) && (value < fields[elem.name]["min"]))
							{
								validator.addError(elem.name,  ' is less than Minimum ' + fields[elem.name]["min"]);
							}
							else if((fields[elem.name]["max"]!=null) && (value > fields[elem.name]["max"]))
							{
								validator.addError(elem.name,  ' is greater than Maximum ' + fields[elem.name]["max"]);
							}
						}
						break;

				case 'number':		//a numeric value, check format and range
						if(fields[elem.name]["required"] || (!fields[elem.name]["required"] && !isEmpty(value)))
						{
							if(!isNumber(value))
							{
								validator.addError(elem.name,  errorsDesc[ftype]);
							}
							else if((fields[elem.name]["min"]!=null) && (value < fields[elem.name]["min"]))
							{
								validator.addError(elem.name,  ' is less than Minimum ' + fields[elem.name]["min"]);
							}
							else if((fields[elem.name]["max"]!=null) && (value > fields[elem.name]["max"]))
							{
								validator.addError(elem.name,  ' is greater than Maximum ' + fields[elem.name]["max"]);
							}
						}
						break;

				case 'url':			//http://
				case 'email':		//email
				case 'birthday':	//birthday
				case 'date':		//date
				case 'datetime':		//date & time
				case 'ssn':			//SSN
				case 'zipcode':		//zipcode
				case 'street':  	//street address
				case 'city':		//city name
				case 'mailing':		//mailing address
				case 'name':		//name
				case 'extendedname':	//extended name
				case 'phone':		//phone
				case 'dollars':		//dollars
				case 'text':		//regular text
						//alert(elem.name + ': ' + value + ': '+ 'is'+fieldtype) //for debug
						var valid = eval('is' + fieldtype + '(value)')		//evaluate the field value by calling function isTYPE()
						if(fields[elem.name]["required"])
						{
							if(isEmpty(value) || !valid)
							{
								validator.addError(elem.name, errorsDesc[ftype]);
							}
						}
						else
						{
							if(!isEmpty(value) && !valid)
							{
								validator.addError(elem.name, errorsDesc[ftype]);
							}
						}
						break;

				case 'radiogroup':		//radio button group
				case 'checkboxgroup':	//checkbox group
						if(fields[elem.name]["required"])
						{
							count ++;
							var numButtons = fields[elem.name]["size"] //2  //this constant should be set to the number of radio or checkbox in the group

							if(!elem.checked)
							{
								numUnchecked += 1;	//count non-selected options
							}

							if(numUnchecked == numButtons) //if none is selected, add error message
							{
								validator.addError(elem.name, errorsDesc[ftype]);
							}
						}
						if(count == numButtons) //buttons in this group are all checked, now reset counter
						{
							numUnchecked = 0;
							count = 0;
						}

						break;

				case 'select': 		//<select> list
					if(fields[elem.name]["required"])
					{
						if((fields[elem.name]["multiple"]==undefined) || (fields[elem.name]["multiple"]==false))
						{
							if((elem.selectedIndex == 0) && (!fields[elem.name]["firstOK"]))
							{
								validator.addError(elem.name, errorsDesc[ftype]);
							}
						}
						else if((fields[elem.name]["multiple"]==true)) //multiple choice
						{
							var numSelected = 0;
							for (var ii = 0; ii < elem.length; ii ++ )
							{
								if(elem[ii].selected)
								{
									numSelected += 1;
									break;	//no need check more if one is selected
								}
							}
							if (numSelected == 0)
							{
								validator.addError(elem.name,  errorsDesc[ftype]);
							}
						}
					}
					break;

				case 'multi_select':	// <select> with 'multiple' enabled. //this is not used now
					if (fields[elem.name]["required"])
					{
						var numSelected = 0;
						for (var ii = 0; ii < elem.length; ii ++ )
						{
							if(elem[ii].selected)
							{
								numSelected += 1;
								break;	//no need check more if one is selected
							}
						}
						if (numSelected == 0)
						{
							validator.addError(elem.name,  ' must be selected');
						}
					}
					break;

				default:
					break;
			}
			//------------------------------------------------------------------------
		}

		//set colors of the labels whose corresponding fields has error in submitted form
		validator.label_color(frm);

		//display a alert window
	 	if(validator.hasError())
	 	{
 			(showAlert) ? validator.displayError() : '';
			return false;
	 	}

	 	return true;	//true
	}

////==============================================================================================



//----- old version : check on each form field without data type defintion
//----- using class defined above : class_validation{}
//
//	function validate_form(frm)
//	{
//		//argument: frm - the form to validate (it is 'document.car' in this case)
//		frm = document.car;
//		var validator = new class_validation( )	//instance
//
//		reset the object holding the array of errors on every submit
//		validator.resetError();
//
//		var numElements = frm.elements.length; //number of elements in the form
//
//		var numUnchecked = 0; //flag to hold number of unchecked 'radio' or 'checkbox' in a group of radio or checkbox
//
//		for(var i = 0; i < numElements; i++)
//		{
//			var elem = frm.elements[i]
//			var value = trim(elem.value)
//
//			skip 'submit', 'reset' etc fields
//			if ((elem.name == 'submit') || (elem.name == 'reset'))
//				continue;
//
//			skip those fields that do not require validation: not set in array 'fields'
//			var fieldtype =new String('') ;
//			if ((fields[elem.name]!=undefined) && (fields[elem.name]["type"]!=undefined))
//			{
//				fieldtype = fields[elem.name]["type"]
//				fieldtype = fieldtype.replace(/([a-zA-Z]{1})(.*)/g, "$f1$2");
//
//				uppercase the first character to match corresponding validation function name
//				the lettercase may be specified in array 'fields', here it is just double check
//				fieldtype = fieldtype.substr(0,1).toUpperCase() + fieldtype.substr(1);
//			}
//			else
//				continue;
//
//			to do: editing --------------------------------------------------------
//			 array 'fields' should be prepared by each form to be validated
//			switch(fieldtype.toLowerCase())
//			{
//				case 'integer':
//					if(fields[elem.name]["required"] ||(!fields[elem.name]["required"] && !isEmpty(value)))
//					{
//						if(!isInteger(value))
//						{
//							validator.addError(elem.name, elem.name + ' is not an integer');
//						}
//						else if((fields[elem.name]["min"]!=null) && (value<fields[elem.name]["min"]))
//						{
//							validator.addError(elem.name, elem.name + ' is less than Minimum');
//						}
//						else if((fields[elem.name]["max"]!=null) && (value>fields[elem.name]["max"]))
//						{
//							validator.addError(elem.name, elem.name + ' is greater than Maximum');
//						}
//					}
//					break;
//
//				case 'dollars':
//					if(fields[elem.name]["required"])
//					{
//						if(!isDollars(value))
//						{
//							validator.addError(elem.name, elem.name + ' is invalid');
//						}
//					}
//					else
//					{
//						if(!isEmpty(value) && !isDollars(value))
//						{
//							validator.addError(elem.name, elem.name + ' is invalid');
//						}
//					}
//					break;
//
//				case 'email':	//email
//					if(fields[elem.name]["required"])
//					{
//						if(!isEmail(value))
//						{
//							validator.addError(elem.name, elem.name + ' is invalid');
//						}
//					}
//					else
//					{
//						if(!isEmpty(value) && !isEmail(value))
//						{
//							validator.addError(elem.name, elem.name + ' is invalid');
//						}
//					}
//					break;
//
//				case 'birthday':	//birthday
//					if(fields[elem.name]["required"])
//					{
//						if(!isBirthday(value))
//						{
//							validator.addError(elem.name, elem.name + ' is invalid');
//						}
//					}
//					else
//					{
//						if(!isEmpty(value) && !isBirthday(value))
//						{
//							validator.addError(elem.name, elem.name + ' is invalid');
//						}
//					}
//					break;
//
//				case 'date':	//date
//					if(fields[elem.name]["required"])
//					{
//						if(!isDate(value))
//						{
//							validator.addError(elem.name, elem.name + ' is invalid');
//						}
//					}
//					else
//					{
//						if(!isEmpty(value) && !isDate(value))
//						{
//							validator.addError(elem.name, elem.name + ' is invalid');
//						}
//					}
//					break;
//
//				case 'ssn':	//SSN
//					if(fields[elem.name]["required"])
//					{
//						if(!isSSN(value))
//						{
//							validator.addError(elem.name, elem.name + ' is invalid');
//						}
//					}
//					else
//					{
//						if(!isEmpty(value) && !isSSN(value))
//						{
//							validator.addError(elem.name, elem.name + ' is invalid');
//						}
//					}
//					break;
//
//				case 'zipcode':	//zipcode
//					if(fields[elem.name]["required"])
//					{
//						if(!isZipcode(value))
//						{
//							validator.addError(elem.name, elem.name + ' is invalid');
//						}
//					}
//					else
//					{
//						if(!isEmpty(value) && !isZipcode(value))
//						{
//							validator.addError(elem.name, elem.name + ' is invalid');
//						}
//					}
//					break;
//
//				case 'name':	//name
//					var valid = eval('is'+fieldtype+'(value)')
//					if(fields[elem.name]["required"])
//					{
//						if(isEmpty(value) || !valid)
//						{
//							validator.addError(elem.name, elem.name + ' is invalid');
//						}
//					}
//					else
//					{
//						if(!isEmpty(value) && !isName(value))
//						if(!isEmpty(value) && !valid)
//						{
//							validator.addError(elem.name, elem.name + ' is invalid');
//						}
//					}
//					break;
//
//				case 'text':	//general text
//					if(fields[elem.name]["required"])
//					{
//						if(isEmpty(value))
//						{
//							validator.addError(elem.name, elem.name + ' is invalid');
//						}
//					}
//					break;
//
//				case 'radiogroup':	//radio button group
//				case 'checkboxgroup':	//checkbox group
//					var numButtons = fields[elem.name]["size"] //2  //this constant should be set to the number of radio or checkbox in the group
//					if(fields[elem.name]["required"])
//					{
//						if(!elem.checked)
//						numUnchecked += 1;
//
//						if(numUnchecked == numButtons)
//						{
//							validator.addError(elem.name, elem.name + ' must be checked');
//						}
//					}
//					break;
//
//				case 'select': //<select> list
//					if(fields[elem.name]["required"])
//					{
//						if((elem.selectedIndex==0) && (!fields[elem.name]["firstOK"]))
//						{
//							validator.addError(elem.name, elem.name + ' is invalid');
//						}
//					}
//					break;
//
//				default:
//					break;
//			}
//			------------------------------------------------------------------------
//		}
//
//		set colors of the labels whose corresponding fields has error in submitted form
//		validator.label_color(frm);
//
//		display a alert window
//	 	if(validator.hasError())
//	 	{
// 			validator.displayError();
//			return false;
//	 	}
//
//	 	return false;	//true
//	}
//
////============================== end of version 1 ==========================================


////to do:
//		group all data validatin functions into one class




//// -- change the color for the label for the field with error --//
////this is an separate function from validate_class->label_color
//it would be called directly in webpage containing the web form to color additional fields which are not validated by main function validate_form()
//parameters:
//	'frm': name of the form
//	'errors': associative array with fieldname as index
function label_color2(frm, errors)
{
	//argument : frm - the form handle
	//			 errors - array of errors with field.name as key

	var labels = frm.getElementsByTagName("label"); //get all label tags into an array
	var label, index=0;

	//	Loop through labels retrieved
	while (index < labels.length)
	{
		//get one lable for processing
		label = labels[index];

		//if its corresponding field value has error, change the label color
		if ((errors[label.htmlFor] != undefined))
		{
			//set color 'RED' to the label to indicate error
			label.style.color = 'red';
		}
		else
		{	//restore to 'black'
			label.style.color = 'black';
		}
		index ++	//move to next label
		
	}//end of while()
}//end function
