
<!--

/**
 *   Validation of fields.
 *
 *	THIS IS TIGHTLY COUPLED WITH exceptionHandler.jsp 
 *
 *   Pages that use this validator should pass an associative array
 *   that defines arrays of fields that will be tested by this validator.
 *	 In the event that a violation has been found, the error Handler will
 *   report the error using the label associated with the field. The label 
 *   will be assumed to have the domId : domId of the field + "-label".
 *
 * 	 First thing it does is test for disallowed chars in the text fields. 
 *
 *   @params: args is an associative array.
 * 
 *	 Possible elements are: 
 *
 *   	required: An array of required field's dom ids
 *		requiredPair: an array of arrays that contain 2 field ids. At least one must be populated. 
 *      requiredGroup: an array of arrays of field ids, all fields are required, the first has the label
 *      optionalGroup: an array of field ids that comprise 1 value. If any are populated, all must be, otherwise they may be empty.
 *		requiredSelectPair: an array of arrays that contain 2 select field ids. At least one must be populated > 0. 
 *		requiredCheck: An array of checkbox ids that must be checked.
 *		requiredNest: Used to validate a collection, and report that a certain collection is not complete. 
 *		passwordPair: an array of arrays of fields that must match and are not empty. The min and max lengths can be added as additional args. 
 *		emailPair: an array of arrays of fields that must match and are emails (Email and Confirm)
 *		numeric: An array of numeric field's dom ids
 *      certainSize: An array of arrays of fieldIds followed by the size they must be
 *		certainRange: An array of arrays of fieldIds followed by the size they must be within
 *		certainSizes: An array of arrays of fieldIds followed by the size they must be within
 *		regExpMatch: An array of arrays of field ids and the req expression they must match
 *		regExpMatchNest: A base field id and the req expression the collection must match
 *		mutuallyExclusive: An array of arrays of fieldIds of fields that cannot have the same value.
 *		phone: An array of phone field's dom ids
 *		phoneGroup: An array of arrays of fields that make up a phone number. Should be area-code, phone, phone2, ext(optional)
 *		optionalPhoneGroup: An array of arrays of fields that make up a phone number. Should be area-code, phone, phone2, ext(optional)
 *		email: An array of email field's dom ids
 *		matching:An array of field's dom ids that must match
 *		zip: An array of US Zip Code field's dom ids
 *		ssn: An array of ssn field's dom ids
 *		textAreas: An array of Arrays of textAreas and their max sizes
 * 		notPast: a date field that must not be in the past
 *		datePair: An array of arrays of date fields to compare. The
 *			format for this should be:
 *			[ [startMonthFieldId, startDayFieldId, startYearFieldId],
 *				 [endMonthFieldId, endDayFieldId, endYearFieldId]]
 *			For now there is only one pair that will be tested. They will be tested 
 *			to ensure that the end date is >= the start date, and that both dates are 
 *			not in the past. 
 *		pastDatePair:same as above but in the past
 *      In addition the display of the errors can be specified by supplying :
 *		exceptionFieldId: The id of the document element to display the errors in, default is "errorHandler"
 *		exceptionCSSClass: The css classname to use to show the error element, default is "errorExposed"
 *		exceptionCSSHideClass: The css classname to use to hide the error element, default is "errorHidden"
 *		exceptionHeaderHide: "true" or "false" : whether to hide the header for the exception list
 *		exceptionHeader: The header key to use instead of the default. This is the heading for the exception section, if there are exceptions
 *
 *
 *	To validate, define the associative array for the form in the page.
 *  For instance, for a form with 4 fileds, 2 of them required, and 1 a zip: 
 *		var args = {
 *			required:["field2Id","field3Id"],
 *			zip:["field3Id"]
 *		}
 *
 *  and pass args as to this function in the onSubmit:
 *	onSubmit="return validate(args);"
 *
 * 	The dom ids are processed and all fields that fail the tests 
 *  are passed to an exception Handler. 
 *		
 *  Returns true if everything validates, otherwise false, and the exception 
 *  handler displays the problems.
 */
 
//Add trim functionality to String object
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ""); };

function validate(args) {
   	this.exceptionFieldId=args.exceptionFieldId?args.exceptionFieldId:"errorHandler";
   	this.exceptionCSSClass=args.exceptionCSSClass?args.exceptionCSSClass:"errorExposed";
   	this.exceptionCSSHideClass=args.exceptionCSSHideClass?args.exceptionCSSHideClass:"errorHidden";
	this.exceptionHeader=args.exceptionHeader;
   	this.exceptionHeaderHide=args.exceptionHeaderHide;
   	
   	//var bigProbs = checkTexts(args.formName);

//   	if(bigProbs != null) {
//   		exceptions = new Object();
//    	exceptions["bigProbs"]=bigProbs;
//    	exceptions["exceptionFieldId"] = this.exceptionFieldId;
//		exceptions["exceptionCSSClass"] = this.exceptionCSSClass;
//		if(this.exceptionHeaderHide)
//			exceptions["exceptionHeaderHide"] = "true";
//		if(this.exceptionHeader)
//			exceptions["exceptionHeader"] = this.exceptionHeader;
//		// This is a call to the exceptionHandler.jsp method
//		return handleExceptions(exceptions, args.exceptionDisplay);
//   	}
   	
   	
   	this.required=null;
   	this.requiredPair=null;
   	this.optionalGroup=null;
   	this.requiredNest=null;
   	this.regExpMatchNest=null;
   	this.identicalPair=null;
   	this.requiredCheck=null;
   	this.passwordPair=null;
   	this.emailPair = null;
   	this.certainSize=null;
   	this.certainSizes=null;
   	this.certainRange=null;
   	this.regExpMatch=null;
   	this.mutuallyExclusive=null;
   	this.numeric=null;
   	this.phone=null;
   	this.phoneGroup=null;
   	this.optionalPhoneGroup=null;
   	this.email=null;
   	this.zip=null;
   	this.ssn=null;
   	this.textAreas=null;
   	this.datePair=null;
   	this.pastatePair=null;
   	this.notPast=null;
   	
   	
   	
   	
   	var exceptions;
  	if(args.required) {
	  	for(var i = 0; i < args.required.length;i++) {
			if( _empty(document.getElementById(args.required[i]).value) ) {
				if(!this.required)
					this.required = new Array();
				this.required.push(args.required[i]);
			}
	  	}	
	}  
	
	
	if(args.requiredPair) {
	  	for(var i = 0; i < args.requiredPair.length;i++) {
			if( _pairEmpty(args.requiredPair[i]) ) {
				if(!this.requiredPair)
					this.requiredPair = new Array();
				this.requiredPair.push(args.requiredPair[i]);
			}
	  	}	
	} 
	
	if(args.requiredCheck) {
	  	for(var i = 0; i < args.requiredCheck.length;i++) {
			if(! document.getElementById(args.requiredCheck[i]).checked ) {
				if(!this.requiredCheck)
					this.requiredCheck = new Array();
				this.requiredCheck.push(args.requiredCheck[i]);
			}
	  	}	
	} 
	
	if(args.requiredGroup) {
	  	for(var i = 0; i < args.requiredGroup.length;i++) {
	  		for(var j = 0; j < args.requiredGroup[i].length;j++) {
				if( _empty(document.getElementById(args.requiredGroup[i][j]).value) ) {
					if(!this.required)
						this.required = new Array();
					this.required.push(args.requiredGroup[i][0]);
					break;
				}
			}
	  	}	
	} 
	
	if(args.optionalGroup) {
		for(var j = 0; j < args.optionalGroup.length;j++) {
			var exists=false;
		  	for(var i = 0; i < args.optionalGroup[j].length;i++) {
				if( _empty(document.getElementById(args.optionalGroup[j][i]).value) ) {
					continue;
				}
				else{
					exists = true;
					break;
				}
			}
			if(exists) {
				for(var i = 0; i < args.optionalGroup[j].length;i++) {
					if( _empty(document.getElementById(args.optionalGroup[j][i]).value) ) {
						if(!this.optionalGroup)
							this.optionalGroup = new Array();
						this.optionalGroup.push(args.optionalGroup[j][0]);
						break;
					}
				}
			}
		}
	} 
	
	if(args.requiredNest) {
	  	for(var i = 0; i < args.requiredNest[0];i++) {
	  		for(var j = 1; j < args.requiredNest.length;j++) {
	  			var fieldName= args.requiredNest[j] + i;
				if( _empty(document.getElementById(fieldName).value) ) {
					if(!this.requiredNest)
						this.requiredNest = new Array();
					this.requiredNest.push(args.requiredNestDescriptor + " " + (i+1));
					break;
				}
			}
	  	}	
	} 
	if(args.regExpMatchNest) {
		for(var i = 0; i < args.regExpMatchNest[0];i++) {
			var fieldName= args.regExpMatchNest[1] + i;
			if( _noMatch([fieldName,args.regExpMatchNest[2] ]) ) {
				if(!this.regExpMatchNest)
					this.regExpMatchNest = new Array();
				this.regExpMatchNest.push(args.requiredNestDescriptor + " "  + (i+1) + " " +  args.regExpMatchNest[1]);
			}
	  	}	
	} 
	
	
	if(args.requiredSelectPair) {
	  	for(var i = 0; i < args.requiredSelectPair.length;i++) {
			if( _selectPairEmpty(args.requiredSelectPair[i]) ) {
				if(!this.requiredPair)
					this.requiredPair = new Array();
				this.requiredPair.push(args.requiredSelectPair[i]);
			}
	  	}	
	} 
	
	if(args.passwordPair) {
	  	for(var i = 0; i < args.passwordPair.length;i++) { 
	  		if( _requiredPairNotEqual(args.passwordPair[i]) ) {
				if(!this.identicalPair)
					this.identicalPair = new Array();
				this.identicalPair.push(args.passwordPair[i]);
			}
			else if( _fieldLengthNotInRange(args.passwordPair[i][0],args.passwordPair[i][2],args.passwordPair[i][3])  ) {
				if(!this.passwordPair)
					this.passwordPair = new Array();
				this.passwordPair.push(args.passwordPair[i]);
			
			}
			if( _isNotAlphaNumeric(document.getElementById(args.passwordPair[i][0]).value )  ) {
				if(!this.passwordPair)
					this.passwordPair = new Array();
				this.passwordPair.push(args.passwordPair[i]);
			
			}
	  	}	
	} 
	if(args.matching) {
	  	for(var i = 0; i < args.matching.length;i++) { 
	  		if( _requiredPairNotEqual(args.matching[i]) ) {
				if(!this.identicalPair)
					this.identicalPair = new Array();
				this.identicalPair.push(args.matching[i]);
			}
			if( _notRightSize([args.matching[i][0],args.matching[i][2]] ) ) {
				if(!this.certainSize)
					this.certainSize = new Array();
				this.certainSize.push([args.matching[i][0],args.matching[i][2]]);
			}
	  	}	
	} 
	
	if(args.emailPair) {
	  	for(var i = 0; i < args.emailPair.length;i++) {
	  		if( _requiredPairNotEqual(args.emailPair[i]) ) {
				if(!this.identicalPair)
					this.identicalPair = new Array();
				this.identicalPair.push(args.emailPair[i]);
			}
			else if( _isNotEmail(document.getElementById(args.emailPair[i][0]).value)  ){
				if(!this.email)
					this.email = new Array();
				this.email.push(args.emailPair[i][0]);
			}
	  	}	
	} 
	
	
	if(args.mutuallyExclusive) {
	  	for(var i = 0; i < args.mutuallyExclusive.length;i++) {
			if( _valuesEqual(args.mutuallyExclusive[i]) ) {
				if(!this.mutuallyExclusive)
					this.mutuallyExclusive = new Array();
				this.mutuallyExclusive.push(args.mutuallyExclusive[i]);
			}
	  	}	
	}
	
	if(args.certainSize) {
	  	for(var i = 0; i < args.certainSize.length;i++) {
			if( _notRightSize(args.certainSize[i]) ) {
				if(!this.certainSize)
					this.certainSize = new Array();
				this.certainSize.push(args.certainSize[i]);
			}
	  	}	
	} 
	if(args.certainSizes) {
	  	for(var i = 0; i < args.certainSizes.length;i++) {
			if( _notRightSizes(args.certainSizes[i]) ) {
				if(!this.certainSizes)
					this.certainSizes = new Array();
				this.certainSizes.push(args.certainSizes[i]);
			}
	  	}	
	} 
	if(args.certainRange) {
	  	for(var i = 0; i < args.certainRange.length;i++) {
			if( _notInRange(args.certainRange[i]) ) {
				if(!this.certainRange)
					this.certainRange = new Array();
				this.certainRange.push(args.certainRange[i]);
			}
	  	}	
	} 
	
	if(args.regExpMatch) {
	  	for(var i = 0; i < args.regExpMatch.length;i++) {
			if( _noMatch(args.regExpMatch[i]) ) {
				if(!this.regExpMatch)
					this.regExpMatch = new Array();
				this.regExpMatch.push(args.regExpMatch[i]);
			}
	  	}	
	} 
	
	if(args.numeric) {  
		for(var i = 0; i < args.numeric.length;i++) {
			if(_isNotNumber(document.getElementById(args.numeric[i]).value) ) {
				if(!this.numeric)
					this.numeric = new Array();
				this.numeric.push(args.numeric[i]);
			}
		}
	}
	
	if(args.phone) {  
		for(var i = 0; i < args.phone.length;i++) {
			if(_isNotPhone(document.getElementById(args.phone[i]).value) ) {
				if(!this.phone)
					this.phone = new Array();
				this.phone.push(args.phone[i]);
			}
		}
	}
	
	if(args.phoneGroup) {  
		for(var i = 0; i < args.phoneGroup.length;i++) {
			if(_isNotPhoneGroup(args.phoneGroup[i]) ) {
				if(!this.phoneGroup)
					this.phoneGroup = new Array();
				this.phoneGroup.push(args.phoneGroup[i]);
			}
		}
	}
	
	if(args.optionalPhoneGroup) {  
		for(var i = 0; i < args.optionalPhoneGroup.length;i++) {
			if(_isNotPhoneGroupOptional(args.optionalPhoneGroup[i]) ) {
				if(!this.optionalPhoneGroup)
					this.optionalPhoneGroup = new Array();
				this.optionalPhoneGroup.push(args.optionalPhoneGroup[i]);
			}
		}
	}

	if(args.email) {  
		for(var i = 0; i < args.email.length;i++) {
			if(_isNotEmail(document.getElementById(args.email[i]).value) ) {
				if(!this.email)
					this.email = new Array();
				this.email.push(args.email[i]);
			}
		}
	}
	
	if(args.zip) {  
		for(var i = 0;i < args.zip.length;i++) {
			if(_isNotZip(document.getElementById(args.zip[i]).value) ) {
				if(!this.zip)
					this.zip = new Array();
				this.zip.push(args.zip[i]);
			}
		}
	}
	
	
	if(args.ssn) {  
		for(var i = 0; i < args.ssn.length;i++) {
			if(_isNotSSN(document.getElementById(args.ssn[i]).value) ) {
				if(!this.ssn)
					this.ssn = new Array();
				this.ssn.push(args.ssn[i]);
			}
		}
	}
	
	if(args.textAreas) {  
		for(var i = 0; i < args.textAreas.length;i++) {
			if((document.getElementById(args.textAreas[i][0]).value).length > args.textAreas[i][1] ) {
				if(!this.textAreas)
					this.textAreas = new Array();
				this.textAreas.push(args.textAreas[i]);
			}
		}
	}
	
	if(args.notPast) {  
		for(var i = 0; i < args.notPast.length;i++) {
			if(_isPast(args.notPast[i]))  {
				if(!this.notPast)
					this.notPast = new Array();
				this.notPast.push(args.notPast[i]);
			}
		}
	}
	
	if(args.datePair) {  
		if(_datesNotInOrder(args.datePair) )
			this.datePair=args.datePair;
	}
	if(args.pastDatePair) {  
		if(_datesNotInPast(args.pastDatePair) )
			this.pastDatePair=args.pastDatePair;
	}

    
    exceptions = new Object();

    
    if(this.required && this.required.length>0)
    	exceptions["required"]=this.required;
    if(this.requiredNest && this.requiredNest.length>0)
    	exceptions["requiredNest"]=this.requiredNest;
    if(this.regExpMatchNest && this.regExpMatchNest.length>0)
    	exceptions["regExpMatchNest"]=this.regExpMatchNest;
    if(this.requiredPair && this.requiredPair.length>0)
    	exceptions["requiredPair"]=this.requiredPair;
    if(this.optionalGroup && this.optionalGroup.length>0)
    	exceptions["optionalGroup"]=this.optionalGroup;
    if(this.requiredCheck && this.requiredCheck.length>0)
    	exceptions["requiredCheck"]=this.requiredCheck;
    if(this.identicalPair && this.identicalPair.length>0)
    	exceptions["identicalPair"]=this.identicalPair;
    if(this.passwordPair && this.passwordPair.length>0)
    	exceptions["passwordPair"]=this.passwordPair;
	if(this.numeric && this.numeric.length>0)
		exceptions["numeric"]=this.numeric;
	if(this.certainSize && this.certainSize.length > 0 ) 
		exceptions["certainSize"]=this.certainSize;
	if(this.certainSizes && this.certainSizes.length > 0 ) 
		exceptions["certainSizes"]=this.certainSizes;
	if(this.certainRange && this.certainRange.length > 0 ) 
		exceptions["certainRange"]=this.certainRange;
	if(this.mutuallyExclusive && this.mutuallyExclusive.length > 0 ) 
		exceptions["mutuallyExclusive"]=this.mutuallyExclusive;
	if(this.regExpMatch && this.regExpMatch.length > 0 ) 
		exceptions["regExpMatch"]=this.regExpMatch;
	if(this.phone && this.phone.length>0)
		exceptions["phone"]=this.phone;
	if(this.phoneGroup && this.phoneGroup.length>0)
		exceptions["phoneGroup"]=this.phoneGroup;
	if(this.optionalPhoneGroup && this.optionalPhoneGroup.length>0)
		exceptions["optionalPhoneGroup"]=this.optionalPhoneGroup;
	if(this.email && this.email.length>0)
		exceptions["email"]=this.email;
	if(this.ssn && this.ssn.length>0)
		exceptions["ssn"]=this.ssn;
	if(this.textAreas && this.textAreas.length>0)
		exceptions["textAreas"]=this.textAreas;
	if(this.zip && this.zip.length>0)
		exceptions["zip"]=this.zip;
	if(this.notPast && this.notPast.length>0)
		exceptions["notPast"]=this.notPast;
	if(this.datePair && this.datePair.length>0)
		exceptions["datePair"]=this.datePair;

		
	var badJooJoo=false;
	for(i in exceptions){
		badJooJoo=true;
		break;
	}
	
	if(badJooJoo){
		exceptions["exceptionFieldId"] = this.exceptionFieldId;
		exceptions["exceptionCSSClass"] = this.exceptionCSSClass;
		if(this.exceptionHeaderHide)
			exceptions["exceptionHeaderHide"] = "true";
		if(this.exceptionHeader)
			exceptions["exceptionHeader"] = this.exceptionHeader;
		// This is a call to the exceptionHandler.jsp method
		return handleExceptions(exceptions, args.exceptionDisplay);
	}
	
	if(	document.getElementById(this.exceptionFieldId) ){
		document.getElementById(this.exceptionFieldId).innerHTML = "";
		document.getElementById(this.exceptionFieldId).className=this.exceptionCSSHideClass;
	}
	return true;
}



	
	  
// Given a field value  will check if the value is empty 
// This is non restrictive.
function _empty(testVal) {
   return (!testVal.trim() || testVal.trim()== "") 
}


// Given an array of field values will check if all are empty 
function _pairEmpty(pair) {
	for (var i = 0; i < pair.length;i++){
		if(!_empty(document.getElementById(pair[i]).value))
			return false;
	
	}
   return true;
}  


// Determine if a field is the right size
function _notRightSize(fieldAndSize) {
	if(fieldAndSize != null && fieldAndSize.length==2) {
		var fieldVal = document.getElementById(fieldAndSize[0]).value;
		if(fieldVal && fieldVal.length == parseInt(fieldAndSize[1]))
			return false;
	}
	return true;
}

// Determine if a field is the right size
function _notRightSizes(fieldAndSize) {
	if(fieldAndSize != null && fieldAndSize.length==2) {
		var fieldVal = document.getElementById(fieldAndSize[0]).value;
		if(fieldVal) {
			for(var i = 0; i < fieldAndSize[1].length;i++) {
				if(fieldVal.length == parseInt(fieldAndSize[1][i]))
					return false;
			}
		}
	}
	return true;
}
// Determine if a field is in range
function _notInRange(fieldAndSize) {
	if(fieldAndSize != null && fieldAndSize.length==3) {
		var fieldVal = document.getElementById(fieldAndSize[0]).value;
		if(fieldVal && fieldVal.length >= parseInt(fieldAndSize[1]) && fieldVal.length <= parseInt(fieldAndSize[2]) )
			return false;
	}
	return true;
}


// Determine if a field matches a regular expression
function _noMatch(fieldAndRE) {
	if(fieldAndRE != null && fieldAndRE.length==2) {
		var fieldVal = document.getElementById(fieldAndRE[0]).value;
		var pattern = fieldAndRE[1];
		if(pattern.exec(fieldVal) )
			return false;
	}
	return true;
}

// Given an array of field values will check if all are empty 
function _selectPairEmpty(pair) {
	for (var i = 0; i < pair.length;i++){
		var val = document.getElementById(pair[i]).value; 
		if(!_empty(val) && val > 0)
			return false;
	
	}
   return true;
}  


// Given an array of field values will check if they exist and are equal
function _requiredPairNotEqual(pair) {
	var val1 = document.getElementById(pair[0]).value; 
	var val2 = document.getElementById(pair[1]).value; 
	
	if(!val1 || !val2) 
		return true;
	if(val1 == "" || val2 =="")
		return true;
	if(val1 == val2)
		return false;
	return true;
}  


// Given an array of field values will check if they are equal
function _valuesEqual(pair) {
	var val1 = document.getElementById(pair[0]).value; 
	var val2 = document.getElementById(pair[1]).value; 
	if(val1 == val2)
		return true;
   return false;
}  



// Given an id will check if the input is a number 
function _isNotNumber(testVal) {
  var pattern = /^[0-9]*\.?[0-9]*$/;
  return (!pattern.exec(testVal) || isNaN(testVal) );
}

// Given an id will check if the input is a char string 
function _isNotAlphaNumeric(testVal) {
  var pattern = /^[a-zA-Z0-9]*\.?[a-zA-Z0-9]*$/;
  return (!pattern.exec(testVal) );
}


// Check for zip code
function _isNotZip(testVal) {
	var pattern = /\d{5}(-\d{4})?/;
	return !pattern.exec(testVal);
}

// Check for SSN
function _isNotSSN(testVal) {
	var pattern = /^\d{3}\-\d{2}\-\d{4}$/;
	return !pattern.exec(testVal);
}

// Test the email generally
function _isNotEmail(testVal) {
	var pattern = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,4}))$/;
	var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/;
    return (!pattern.exec(testVal) || !(testVal.match(illegalChars)==null) );
}



// Check for phone: US and International
function _isNotPhone(testVal){
	var usPattern = /^\d{10,14}$/;
	var intPattern = /^\d(\d|-){7,20}/;
	return (!usPattern.exec(testVal) || !intPattern.exec(testVal) );
}


// Check for phone: US and International
function _isNotPhoneGroup(args){
	var ac=document.getElementById(args[0]).value;
	if(!ac || ac =="")
		return true;
	var ph1=document.getElementById(args[1]).value;
	if(!ph1 || ph1 =="")
		return true;
	var ph2=document.getElementById(args[2]).value;
	if(!ph2 || ph2 =="")
		return true;
	var ext="";
	if(args[3])
		ext = document.getElementById(args[3]).value;
	return _isNotPhone("" + ac + ph1 + ph2 + ext);
}

// Check for phone: US and International
// This is for an optional phone group
// If it is empty, report that it is OK, otherwise test
function _isNotPhoneGroupOptional(args){
	var ac=document.getElementById(args[0]).value;
	var ph1=document.getElementById(args[1]).value;
	var ph2=document.getElementById(args[2]).value;
	var ext="";
	if(args[3])
		ext = document.getElementById(args[3]).value;
	if((!ac||ac=="") && (!ph1||ph1=="") && (!ph2||ph2=="") && (!ext||ext==""))
		return false;
	return _isNotPhone("" + ac + ph1 + ph2 + ext);
}



function _fieldLengthNotInRange(domId, min, max) {
	var val = document.getElementById(domId).value;
	if(!val || val=="")
		return true;
	if(val.length >= min && val.length <= max)
		return false;
	return true;
}

/** 
	Determine if the date has passed.
	
*/
function _isPast(args){
	var startMonth=document.getElementById(args[0]).value;
	var startDay=document.getElementById(args[1]).value;
	var startYear=document.getElementById(args[2]).value;
	

	for(var i = 0; i < months.length;i++){
		if(months[i] == startMonth){
			startMonth = i;
			break;
		}
	}
	
	
	var now = new Date();
	var today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
	var start = new Date(startYear, startMonth, startDay);
	
	if(today.valueOf() > start.valueOf()){
		return true;
	}
	return false;
}

//**************************************************
// Ensure that text fields do not contain malicious 
// or disallowed characters.
//**************************************************
function checkTexts(fName) {
	var problemFields=null;
	
	var fX = document.getElementById(fName);

	if(fX) {
		var inputs = fX.getElementsByTagName("input");
		if(inputs) {
			for(var i = 0; i < inputs.length; i++ ) {
				if( (inputs[i].getAttribute("type")!="text" &&
						inputs[i].getAttribute("type")!="password") || 
						inputs[i].getAttribute("readonly") == 'readonly' ||
                                                inputs[i].getAttribute("readonly") == true) {
					continue;
				}
				
				
				if(_containsDisallowed(inputs[i].value) ) {
					if(!problemFields)
						problemFields = new Array();
					problemFields.push(inputs[i].id);
				}
			}
		}
	}
	return problemFields;

}

function _containsDisallowed(test) {
   	var probs = ["system.exit","<",">","./"];
   	var pattern = "";
   	test = test.toString().toLowerCase();
   	for(var k = 0; k < probs.length; k++) {
	    pattern = new RegExp(probs[k]);
	    if((pattern.exec(test)) != null ){
		    return true;
		}
   	}
  
   	if(test.indexOf("|") > 0) return true;
   	
  	return false;
}






-->