/*v['to_disable'] = ['IDToDisable1','IDToDisable2'];	If the submit is successfull, these items will be disabled, assumed that these will be buttons	this prevents double clicksv['warnHTML'] = true;	if true an HTML Element will be populated with the details of all problems	If there is no value in v['DispELID']v['DispELID'] = "idoferrortext";	Used when v['warnHTML'] is set to true;validator.FieldArray['name'] 					= Name of the fieldFieldArray['mn']					= Minimum LengthFieldArray['mx']		 				= Maximum LengthFieldArray['MatchOther'] 						= match another fieldFieldArray['ml'] 						= label of matching fieldFieldArray['filterName']		= validation typeFieldArray['required']			= requiredFieldArray['LabelObj'] 			= LableObject	If an object is provided no other checking is requredFieldArray['LabelID']			= label idFieldArray['v'] 						= valueFieldArray['FieldObj']			= Field ObjectFieldArray['Descrip']			= Field Description*/function validator(){	this.CustomAlert 	= null;	this.DebugAlert	 	= null;	this.ValDialog 		= false;	this.ErrorCount 		= 0;	this.warnHTML		= true;	this.DispELID			= false;	this.ConfirmSubmit = false;	this.FieldArray		= {};		this.to_disable		=[]			this.LabelClasses={ 	'errorlabel': 'Error', 									'goodlabel'	: 'Normal'};	this.formObj 			= document.forms[0];													this.changeHandler = function(){//		alert( "Change")	}	this.blurHandler = function(){//		alert( "blur")	}	this.itext = function ( element ){		if(typeof(element.innerText) != "undefined"){			return element.textContent;			} else {			return element.innerText				}	}	this.GetErrorCode = function ( EachFieldArr ){		EachFieldArr['ErrorCode']=null;		var ValueStr = String(EachFieldArr['v']);		var FiltFuncCode;		var ftype = EachFieldArr.Filter?typeof(EachFieldArr.Filter):null;		if(EachFieldArr['required']&&!EachFieldArr['v'])			return 'RequiredField';		if(EachFieldArr['mn']&&ValueStr.length<EachFieldArr['mn'])			return 'MinLen';		if(EachFieldArr['mx']&&ValueStr.length>EachFieldArr['mx'])			return 'MaxLen';		if( (ftype == 'function') && 		(FiltFuncCode=EachFieldArr.Filter(ValueStr,this.formObj)))			if (typeof(FiltFuncCode)!='string'){				if( this.messages['fill'][EachFieldArr['filterName']] ){					return EachFieldArr['filterName'];				} else {					return 'Invalid';				}			} else				return FiltFuncCode;						if( (ftype == 'object') && !(FiltFuncCode = EachFieldArr.Filter.test(ValueStr)) )				if( this.messages['fill'][EachFieldArr['filterName']] )					return EachFieldArr['filterName'];				else					return 'Invalid';		if(EachFieldArr['MatchOther']){			var OtherFieldName = EachFieldArr['MatchOther'];			var OtherFieldObj = this.FieldArray[ OtherFieldName ];			if( OtherFieldObj['v']!= EachFieldArr['v']){				EachFieldArr['ml']=OtherFieldObj['Descrip'];				return 'MatchOther';			}		}			return null;	}//this.GetErrorCode	this.exec = function(){		this.ErrorCount=0;		var EachFieldArr;		var thisErrorCode;		var thisErrorText;		this.WebErrText='';		this.NormErrText='';		var FocusField;				for(var EachFieldName in this.FieldArray){			var EachFieldArr = this.FieldArray[EachFieldName];			EachFieldArr['v']=this.GetFieldValue( EachFieldArr['FieldObj'] );		}		for(var EachFieldName in this.FieldArray){			var EachFieldArr = this.FieldArray[EachFieldName];			thisErrorCode = EachFieldArr['ErrorCode'] = this.GetErrorCode( EachFieldArr );			if(thisErrorCode){				this.ErrorCount++;				thisErrorText='';				thisErrorText = this.GetFmtText('fill',thisErrorCode,EachFieldArr);				if(!thisErrorText)					thisErrorText=thisErrorCode;				this.WebErrText+=thisErrorText+'<br>';				this.NormErrText+=thisErrorText+"\n";				if( EachFieldArr.LabelObj){					if( EachFieldArr.LabelClasses && EachFieldArr.LabelClasses['errorlabel'] )						EachFieldArr.LabelObj.className=EachFieldArr.LabelClasses['errorlabel'];									else if( this.LabelClasses['errorlabel'] )						EachFieldArr.LabelObj.className=this.LabelClasses['errorlabel'];													}				if(!FocusField){					FocusField=this.formObj.elements[EachFieldName];					if( !FocusField.focus || FocusField.type =='hidden')						FocusField = null;				}			} else {				if( EachFieldArr.LabelObj){					if( EachFieldArr.LabelClasses && EachFieldArr.LabelClasses['goodlabel'] )						EachFieldArr.LabelObj.className=EachFieldArr.LabelClasses['goodlabel'];									else if( this.LabelClasses['goodlabel'] )						EachFieldArr.LabelObj.className=this.LabelClasses['goodlabel'];													}			}		}		if(this.ErrorCount){			this.WebErrText=this.GetFmtText('boxes',0,{'error':this.WebErrText});			if( this.ValDialog )				alert(this.NormErrText);			if(this.warnHTML && this.DispElement){				this.DispElement.innerHTML=this.WebErrText;				this.DispElement.style.display='block';			}			if(FocusField)				FocusField.focus();			if( this.CustomAlert )				return this.CustomAlert();							return false;		}		if( this.ConfirmSubmit && !confirm(this.GetFmtText('confirm',0)))			return false;		if( this.ShowSubmitting ){			this.DispElement.innerHTML=this.GetFmtText('boxes',1);			this.DispElement.style.display='block';		}		for(eachToDisable in this.to_disable){			var EachElement=this.GetElByID(this.to_disable[eachToDisable]);			if(EachElement&&EachElement.disabled!=null)				EachElement.disabled=true;		}		return true;	}//this.exec	this.GetElByID = function (FieldName){		if( document.all)			return document.all[FieldName]		if(document.getElementById)			return document.getElementById(FieldName)		return null	}//this.GetElByID			this.GetFieldValue = function( Parm1 ){		var x = typeof( Parm1);		if (typeof( Parm1)=="string"){			FieldObj =	this.FieldArray[Parm1].FieldObj					} else {			FieldObj = Parm1				}		if (FieldObj.value)			return FieldObj.value;		if(FieldObj.type=='checkbox'){			if(FieldObj.checked&&FieldObj.value)				return FieldObj.value;			return null;		} 		if(FieldObj.options){			if( FieldObj.selectedIndex>-1){				var option = FieldObj.options[FieldObj.selectedIndex]				if (option.value) 					return option.value				return option.text			}			return null;		}			if(FieldObj.length>0) {			for(var ElCount=0;ElCount<FieldObj.length;ElCount++)				if(FieldObj[ElCount].checked)					return FieldObj[ElCount].value;		}				return null;	}//this.GetFieldValue	this.GetFmtText=function(MsgCat,MsgNum){		var ErrorText=this.messages[MsgCat][MsgNum];		if(!ErrorText)			return false;		var ArgName;					if(typeof(ErrorText)=='function')			ErrorText=ErrorText( this.formObj.name );		for(var ArgCount=2;ArgCount<arguments.length;ArgCount++)			for(ArgName in arguments[ArgCount])				ErrorText=ErrorText.replace('%'+ArgName+'%',arguments[ArgCount][ArgName]);		ErrorText=ErrorText.replace('%form%',this.formObj.name);		return ErrorText	}//this.GetFmtText	this.InitOneField = function ( FieldName ){		var EachFieldArr = this.FieldArray[FieldName]		EachFieldArr['name']=FieldName;			if( !EachFieldArr['filterName']){			EachFieldArr['Filter']= null;		} else if( this.ValidationArray[EachFieldArr['filterName']]){			EachFieldArr['Filter'] = this.ValidationArray[EachFieldArr['filterName']];		} else {			EachFieldArr['Filter'] = EachFieldArr['filterName'];		}		var PropList=['Descrip'];		for(PropName in PropList){			if(!EachFieldArr[PropList[PropName]])				return this.ReturnError(this.GetFmtText('setup','MissingProp',EachFieldArr,{'attr':PropList[PropName]}));		}		var thisFieldObj=EachFieldArr['FieldObj']=this.formObj.elements[FieldName];		if(!thisFieldObj)			return this.ReturnError(this.GetFmtText('setup','BadField',EachFieldArr));		thisLabelObj = EachFieldArr['LabelObj']		if( !thisLabelObj){			if( EachFieldArr['LabelID']){				thisLabelObj = EachFieldArr['LabelObj'] = this.GetElByID(EachFieldArr['LabelID']);					if(!thisLabelObj)					return this.ReturnError(this.GetFmtText('setup','BadLabel',EachFieldArr));			}		}			if ( thisLabelObj && thisLabelObj.className )	{			if(EachFieldArr.LabelClasses && EachFieldArr.LabelClasses['goodlabel'])				thisLabelObj.className=EachFieldArr.LabelClasses['goodlabel'];				else if(this.LabelClasses['goodlabel'])					thisLabelObj.className=this.LabelClasses['goodlabel'];							}		if( EachFieldArr['LabelID']){			if(EachFieldArr['MatchOther']){				var OtherField = this.FieldArray[EachFieldArr['MatchOther']];				if( !OtherField )					return this.ReturnError(this.GetFmtText('setup','BadMatchField',EachFieldArr));			}			if( EachFieldArr["CheckChange"]){				this.attachevent( EachFieldArr['FieldObj'], 'change', function () {return v.changeHandler()})					this.attachevent( EachFieldArr['FieldObj'], 'blur', 	function () {return v.blurHandler()})				}			//			if(thisLabelObj){	EachFieldArr['LabelObj']=thisLabelObj;}		}	}//this.InitOneField	this.messages={		'setup':{			'noform':'Form "%form%" can not be found in this document',			'displayarea':'Can not find display area for output (id="%dispname%")',			'MissingProp':'Incomplete field dscription for "%name%". Attribute "%attr%" is missing',			'BadField':'Can not find form field "%name%" in the form "%form%"',			'BadLabel':'Can not find label tag (id="%LabelName%")',			'BadMatchField':'Can not verify match. Field "%MatchOther%" was not found'		},		'fill':{			'RequiredField':'"%Descrip%" is a required field',			'Invalid'		:'"%v%" is not valid value for "%Descrip%"',			'usdate'			:'"%v%" is not valid value for "%Descrip%"',			'time'			:'"%v%" is not valid value for "%Descrip%"',			'MinLen'		:'Value for "%Descrip%" must be %mn% characters or more',			'MaxLen'		:'Value for "%Descrip%" must be no longer than %mx% characters',			'MatchOther':'"%Descrip%" must match "%ml%"',			'alpha'			:'Value for "%Descrip%" must be alpha',			'alphanum'	:'Value for "%Descrip%" must be alpha-numeric',			'email_1'		:'Value for "%Descrip%" must be a valid email, invalid format, (check @ and .\'s)',			'email_2'		:'Value for "%Descrip%" must be a valid email, The username portion invalid characters.',			'email_3'		:'Value for "%Descrip%" must be a valid email, Ths domain name portion contains invalid characters.',			'email_4'		:'Value for "%Descrip%" must be a valid email, The username doesn\'t seem to be valid.',			'email_5'		:'Value for "%Descrip%" must be a valid email, Destination IP address is invalid!',			'email_6'		:'Value for "%Descrip%" must be a valid email, The domain name does not seem to be valid.',			'email_7'		:'Value for "%Descrip%" must be a valid email, The address must end in a well-known domain or two letter country.',			'email_8'		:'Value for "%Descrip%" must be a valid email, This address is missing a hostname!'		},		'boxes':{			'old0':'<p style="color:white; background: red">%error%</p>',			'1':'<table cellpadding="0" cellspacing="0" border="0" width="100%">'+				'<tr><td bgcolor="#CCCC33"><table cellpadding="15" cellspacing="1" border="0" width="100%">'+				'<tr><td bgcolor="#FFFFCC" style="color: green; font-weight: bold;">Submitting ...</td></tr>'+				'</table></td></tr><tr><td height="10">&nbsp;</td></tr></table>',			'0':'<hr style="color:#FF0000; height:2px;" />'+				'%error%'+				'<hr style="color:#FF0000; height:2px;" />'											},		'confirm':{			'0':'The "%form%" form is to be submitted. Are you sure?'		}	}//this.messages	this.ValidationArray={		'alpha':/^[a-zA-Z\.\-]*$/,		'alphanum':/^\w+$/,		'unsigned':/^\d+$/,		'integer':/^[\+\-]?\d*$/,		'real':/^[\+\-]?\d*\.?\d*$/,		'email2':/^[\w-\.]+\@[\w\.-]+\.[a-z]{2,4}$/,		'phone':/^[\d\.\s\-]+$/,		'usdate':function( FieldValue){				var regxdate=/^(\d{1,2})\-(\d{1,2})\-(\d{4})$/;					if(!regxdate.test( FieldValue ))					return 'date';				if(RegExp.$1>31||RegExp.$2>12)					return 'date';				var TempDate=new Date(RegExp.$3,Number(RegExp.$2-1),RegExp.$1);				if(TempDate.getMonth()!=Number(RegExp.$2-1))					return true;				return false;			},		'time':function(FieldValue){				var regxtime=/^(\d{1,2})\:(\d{1,2})\:(\d{1,2})$/;				if(!regxtime.test(FieldValue))					return 'time';				if(RegExp.$1>23||RegExp.$2>59||RegExp.$3>59)					return 'time';				return false;		},		'email': function (FieldValue) {				var emailPat=/^(.+)@(.+)$/;				var matchArray=FieldValue.match(emailPat);				if (matchArray==null) 					return 'email_1';				var user=matchArray[1];				for (var i=0; i<user.length; i++) {					if (user.charCodeAt(i)>127)						return 'email_2';				}				var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";				var validChars="\[^\\s" + specialChars + "\]";				var atom=validChars + '+';				var quotedUser="(\"[^\"]*\")";				var word="(" + atom + "|" + quotedUser + ")";								var userPat=new RegExp("^" + word + "(\\." + word + ")*$");								if (user.match(userPat)==null)					return 'email_4';				var domain=matchArray[2];				for (var i=0; i<domain.length; i++) {					if (domain.charCodeAt(i)>127)						return 'email_3';				}				var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;				var IPArray=domain.match(ipDomainPat);				if (IPArray!=null) {					for (var i=1;i<=4;i++) {						if (IPArray[i]>255)							return 'email_5';					}					return false;				} 								var atomPat=new RegExp("^" + atom + "$");				var domArr=domain.split(".");				for (i=0;i<domArr.length;i++) {					if (domArr[i].search(atomPat)==-1)						return 'email_6';				}				var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;				var TLD = domArr[domArr.length-1]				if ( TLD.length!=2 && TLD.search(knownDomsPat)==-1) {					return 'email_7';				}				if (domArr.length<2) {					return 'email_8';				}				return false;			}	};//this.ValidationArray	this.addvalidation = function( valname , valobj, msgobj ){		ValidationArray[valname]  = valobj;		if(typeof(msgobj)=='object'){			for(var EachMsgName in msgobj)				messages['fill'][EachMsgName]		= msgobj[EachMsgName];		} else{			messages['fill'][valname]		= msgtext		}	}//this.addvalidation	this.addField = function ( FieldName , parms ){		function findsib( Element){			function FindParent( Element, name){				if( !Element ) 					return null				var parent = Element.parentNode				if( ! parent )					return null				if( parent.nodeName == name)					return parent				return FindParent( parent, name)				}			if( !Element ) 				return null			if ( !Element.nodeName &&Element.length ){				Element = Element[0]						}			if ( Element.nodeName != "TD")				Element = FindParent( Element, "TD")					if( !Element ) 				return null			sib = 	Element.previousSibling			if( !sib ){				var TR = Element.parentNode;				if(TR && TR.nodeName=="TR"){					TR = TR.previousSibling								}				if(TR && TR.nodeName=="TR"){					sib = TR.firstChild;				}			}			if( !sib ){				return null			}										if ( v.itext(sib) == "" )				return findsib( sib )			if ( v.itext(sib) == "**" )				return findsib( sib )			return sib		}//findsib				var thisFieldObj = this.formObj[ FieldName]		if (! thisFieldObj)			return false		var EachFieldArr = {}		EachFieldArr['name'] 			= FieldName;		EachFieldArr['FieldObj']	= thisFieldObj;		if( this.fieldDefaults)			for( var parmName in this.fieldDefaults )				EachFieldArr[parmName] = this.fieldDefaults[parmName];		for( var parmName in parms )			EachFieldArr[parmName] = parms[parmName]		if(!EachFieldArr['LabelObj']){			if(!EachFieldArr['LabelID'] )				EachFieldArr['LabelID'] = 't_' + FieldName;			EachFieldArr['LabelObj'] = document.getElementById( EachFieldArr['LabelID'] )		}		if (!EachFieldArr['LabelObj']) {			var sib = findsib( EachFieldArr['FieldObj'] )			if( sib){				if(sib.id)					EachFieldArr['LabelID'] = sib.id				else					sib.id = EachFieldArr['LabelID']				EachFieldArr['LabelObj'] = sib			}		}		if(EachFieldArr['LabelObj']){			if(!EachFieldArr['Descrip'])				EachFieldArr['Descrip'] = v.itext(EachFieldArr['LabelObj'])		}		this.FieldArray[FieldName] = EachFieldArr;	}//this.addField	this.attachevent = function(eventobj, eventname, func){		if( eventobj.addEventListener)			eventobj.addEventListener(eventname,func,false);		else if( eventobj.attachEvent)			eventobj.attachEvent('on' + eventname, func )	}//this.attachevent	this.attachevent = function(obj, evt, fnc, useCapture){		if( !obj['on'+evt] ){			 obj['on'+evt]=fnc;			 return true;		}		if (!useCapture) useCapture=false;		if (obj.addEventListener){			obj.addEventListener(evt,fnc,useCapture);			return true;		} else if (obj.attachEvent) {			return obj.attachEvent("on"+evt,fnc);		} else{			obj['on'+evt]=fnc;		}	}//this.attachevent	this.init = function (){		this.ReturnError=this.DebugAlert?function(alertparm){alert(alertparm);return false}:function(){return false};		if(!this.formObj)			return this.ReturnError(this.GetFmtText('setup','noform'));				var EachFieldName;		for( EachFieldName in this.FieldArray )			this.InitOneField(EachFieldName)		if(!this.DispElement){			if( !this.DispELID)				this.DispELID = 'error_'+this.formObj.name;			this.DispElement=this.GetElByID( this.DispELID );		}		if( this.warnHTML ||this.ShowSubmitting ){			if( !this.DispElement )				return this.ReturnError(this.GetFmtText('setup','displayarea',{'dispname':'error_'+this.formObj.name}) );			this.DispElement.style.display='none';			this.DispElement.innerHTML='';		}		this.attachevent( this.formObj, 'submit', function () {return v.exec() })	}}//function validator