Locale.include("form-validator");FormValidatorConfig.include("componence-formvalidator.css");function JSFormValidator(){this.version="1.2.18";if(!Global.required("JSFormValidatorConfig","JSFormManager","JSTemplate","JSBrowser","JSString","JSVisualElementManager","JSArrayList")){this.install=function(){};this.uninstall=function(){};return null}var fvc=FormValidatorConfig;this.defaultDoubleSeparator=fvc.defaultDoubleSeparator?fvc.defaultDoubleSeparator:",";this.onBeforeValidate=null;this.onAfterValidate=null;this.onAddErrorMessage=null;var errors=[];this.getErrors=function(){return errors};function uninstall(formName){var fm=FormManager;var f=fm.getForm(formName);if(f){var osf=String(this.onSubmit).replace(this.formName,formName);var osfs=f.onSubmitFunctions;osf=new Function(osf);for(var i=0;i<osfs.length;i++){var foo=osfs[i];if(foo.toString()==osf.toString()){osfs.remove(foo);break}}var fe=f.elements;for(var i=0;i<fe.length;i++){var e=fe[i];if(e&&e.errorObject){this.removeErrorMessage(e)}}f.fv=null}else alert("FormValidator.uninstall: form "+formName+" not found !")}this.uninstall=uninstall;function install(){var a=arguments;var fm=FormManager;var t=FormValidatorConfig.FORM_VALIDATOR_DEFAULT_ERROR_BLOCK;var n=a[0];if(a.length==2){t=a[0];n=a[1]}this.currentFocus=null;var f=fm.getForm(n);if(f){f.fv=this;fm.makeFormContentSubmitable(f);this.onSubmit="return FormValidator.validationHandler('"+n+"')";fm.addOnSubmitFunction(n,this.onSubmit);this.template=t;this.formName=n}else alert("FormValidator.install: form "+n+" not found !")}this.install=install;function makeRequired(f,i,m){var e=FormManager.getInput(i,f);if(!e)return false;e.setAttribute("fvRequired","true");if(m)e.setAttribute("fvErrorMessage",m);return true}this.makeRequired=makeRequired;function makeNotRequired(f,i,m){var e=FormManager.getInput(i,f);if(!e)return false;e.removeAttribute("fvRequired");if(m)e.removeAttribute("fvErrorMessage");return true}this.makeNotRequired=makeNotRequired;function assignExpression(f,i,ex,m,n){var e=FormManager.getInput(i,f);if(!e)return false;n=(n)?n:"";e.setAttribute(("ftExpression"+n),ex);if(m)e.setAttribute(("ftExpressionErrorMessage"+n),m)}this.assignExpression=assignExpression;function assignType(f,i,t){var e=FormManager.getInput(i,f);if(!e)return false;e.setAttribute("ftType",t);return true}this.assignType=assignType;function parseExpression(ex,form){var fe=form.elements;var t=new JSTemplate("[","]");t.setTemplateContent("main",ex,true);for(var i=0;i<fe.length;i++){var e=fe[i];var n=e.name;var ft=e.getAttribute("ftType");var ftExp=String(e.getAttribute("ftExpression"));var vName=n;var vValue=n;if(ex.indexOf("[this]")!=-1&&ex==ftExp){vName="this"}if(n==""){vValue=i}if(ft=="number"||ft=="double"||ft=="int"){vValue=String(e.value).replace(this.defaultDoubleSeparator,".");t.setVar(vName,vValue)}else if(ft=="date"){var df=this.getDateFormat(e);var d=DateFormatter.buildDate(eval("form.elements['"+vValue+"'].value"),df).toString();t.setVar(vName,"new Date( '"+d+"' )")}else{if(e.type=="checkbox")t.setVar(vName,"form.elements['"+vValue+"'].checked");else t.setVar(vName,"form.elements['"+vValue+"'].value")}}t.parse("main",false);var r;try{r=eval(t.printVar("main"))}catch(e){r=false}return r}this.parseExpression=parseExpression;function reValidate(e){var c=true;var f=e.form;var fv=(f.fv)?f.fv:FormValidator;if((e.tagName=="INPUT"&&(e.type=="text"||e.type=="password"||e.type=="checkbox"))||e.tagName=="SELECT"||e.tagName=="TEXTAREA"){c=fv.validationForText(e,c)}}this.reValidate=reValidate;function validationHandler(formName,evt){var fm=FormManager;var g=Global;var f=fm.getForm(formName);var fv=(f.fv)?f.fv:FormValidator;var c=true;var fe=f.elements;errors=[];if(g.isDefined(fv.onBeforeValidate)){if(!fv.onBeforeValidate())return false}for(var i=0;i<fe.length;i++){var e=fe[i];if((e.tagName=="INPUT"&&(e.type=="text"||e.type=="password"||e.type=="checkbox"))||e.tagName=="SELECT"||e.tagName=="TEXTAREA")c=fv.validationForText(e,c);if(c==false&&FormValidatorConfig.showFirstError){return c}if(!c){executeOnError(e)}}if(g.isDefined(fv.onAfterValidate)){if(!fv.onAfterValidate(c))return false}return c}this.validationHandler=validationHandler;function validationForText(e,c){var g=Global;var b=Browser;this.removeErrorMessage(e);var ftType=e.getAttribute("ftType");if((b.ie5)?g.isDefined(e.fvRequired):g.isDefined(e.getAttributeNode("fvRequired"))){if(this.isEmptyValue(e)){var m=Locale.formValidator.required;this.addErrorMessage(e,this.getErrorMessageHTML(this.template,m));c=this.setFocus(c,e)}else if(g.isDefined(ftType))c=this.validationByFtType(ftType,e,c);else c=this.validationByExpression(e,c)}else{if(!this.isEmptyValue(e))c=this.validationByFtType(ftType,e,c);else c=this.validationByExpression(e,c)}return c}this.validationForText=validationForText;function validationByExpression(e,c){var g=Global;var r=true;var ex=e.getAttribute("ftExpression");if(g.isDefined(ex)&&ex!=""){if(!this.parseExpression(ex,e.form)){this.addErrorMessage(e,this.getErrorMessageHTML(this.template,e.getAttribute("ftExpressionErrorMessage")));r=false}else this.removeErrorMessage(e)}if(r){var exc=1;while(true){ex=e.getAttribute("ftExpression"+exc);if(g.isDefined(ex)&&ex!=""){if(!this.parseExpression(ex,e.form)){this.addErrorMessage(e,this.getErrorMessageHTML(this.template,e.getAttribute("ftExpressionErrorMessage"+exc)));r=false;break}else this.removeErrorMessage(e);exc++}else break}}return(c&&r)}this.validationByExpression=validationByExpression;function numberFormatsValidation(t,e){var v=Validator;var g=Global;var lfv=Locale.formValidator;var o={};o.result=true;o.message="";o.value=e.value;if(t=="number"||t=="double"){o.value=parseFloat(String(o.value).replace(this.defaultDoubleSeparator,"."));o.result=v.isDouble(o.value);o.message=lfv.notDouble}else if(t=="int"){o.value=parseInt(o.value);o.result=v.isInteger(o.value);o.message=lfv.notInteger}if(o.result){var minValue=e.getAttribute("ftMin");var maxValue=e.getAttribute("ftMax");minValue=(g.isDefined(minValue))?((t=="int")?parseInt(minValue):parseFloat(minValue)):null;maxValue=(g.isDefined(maxValue))?((t=="int")?parseInt(maxValue):parseFloat(maxValue)):null;if(minValue!=null&&minValue>o.value){o.result=false;o.message=String(lfv.minValue).replace("{minValue}",minValue)}else if(maxValue!=null&&maxValue<o.value){o.result=false;o.message=String(lfv.maxValue).replace("{maxValue}",maxValue)}}return o}this.numberFormatsValidation=numberFormatsValidation;function validationByFtType(t,e,c){var v=Validator;var g=Global;var lfv=Locale.formValidator;var r=false;var m="";if(t=="email"){r=v.isEmail(e.value);m=lfv.notEmail}else if(t=="date"){var df=this.getDateFormat(e);r=DateFormatter.dateCheck(e.value,df);m=lfv.notDate}else if(t=="number"||t=="double"||t=="int"){var o=this.numberFormatsValidation(t,e);r=o.result;m=o.message}else if(t=="text")r=true;else r=-1;if(!r&&r!=-1){c=this.setFocus(c,e);this.addErrorMessage(e,this.getErrorMessageHTML(this.template,m))}else{this.removeErrorMessage(e);c=this.validationByExpression(e,c)}return c}this.validationByFtType=validationByFtType;function executeOnError(e){if(!e)return false;var ex=e.getAttribute("fvExecuteOnError");if(!ex)return true;var t=new JSTemplate("[","]");t.setTemplateContent("main",ex,true);t.setVar(e.name,"\""+e.value+"\"");t.parse("main",false);try{return eval(t.printVar("main"))}catch(e){return false}}function setFocus(c,f){if(c){try{f.focus()}catch(e){FormValidator.validateRTF(f)}this.currentFocus=f}return false}this.setFocus=setFocus;function isEmptyValue(o){return(o.type=="checkbox")?(!o.checked):(String(o.value).trim()=="")}this.isEmptyValue=isEmptyValue;function addErrorMessage(o,m){var g=Global;var b=Browser;var e=null;var vem=VisualElementManager;if(g.isDefined(this.onAddErrorMessage)){if(!this.onAddErrorMessage(o,m))return}errors[errors.length]=o;if(o.typeError=="isError"){if(b.ie5||b.ns6||b.op5)o.parentNode.removeChild(o.errorObject)}o.typeError="isError";e=document.createElement("div");e.className="fvErrorObject";var fvErrorMessage=o.getAttribute("fvErrorMessage");m=(fvErrorMessage)?this.getErrorMessageHTML(this.template,fvErrorMessage):m;e.innerHTML=m;o.parentNode.appendChild(e);var ol=vem.getLeft(o);var ot=vem.getTop(o)-e.offsetHeight;var or=ol+o.offsetWidth;var ow=o.offsetWidth;var oh=o.offsetHeight;var ew=e.offsetWidth;var eh=e.offsetHeight;var fvmp=o.getAttribute("fvMessagePos");var p=(fvmp)?fvmp:FormValidatorConfig.messagePos;p=p.toUpperCase();with(e.style){if(p=="TOP"){left=ol+"px";top=(ot)+"px"}else if(p=="RIGHT"){left=(ol+ow)+"px";top=(ot+eh)+"px"}else if(p=="LEFT"){left=(ol-ew)+"px";top=(ot+eh)+"px"}else if(p=="BOTTOM"){left=ol+"px";top=(ot+oh+eh)+"px"}else if(p=="TOP-RIGHT"||p=="RIGHT-TOP"){left=(ol+ow)+"px";top=(ot)+"px"}else if(p=="TOP-LEFT"||p=="LEFT-TOP"){left=(ol-ew)+"px";top=(ot)+"px"}else if(p=="BOTTOM-RIGHT"||p=="RIGHT-BOTTOM"){left=(ol+ow)+"px";top=(ot+oh+eh)+"px"}else if(p=="BOTTOM-LEFT"||p=="LEFT-BOTTOM"){left=(ol-ew)+"px";top=(ot+oh+eh)+"px"}}o.errorObject=e}this.addErrorMessage=addErrorMessage;function removeErrorMessage(o){if(o.typeError=="isError"){var b=Browser;var c=this.currentFocus;if(b.ie5||b.ns6||b.op5){if(o.errorObject.removeNode){o.errorObject.removeNode(true)}else{o.errorObject.parentNode.removeChild(o.errorObject)}if(c!=null){try{c.focus()}catch(e){FormValidator.validateRTF(c,true)}}}o.typeError="noneError"}}this.removeErrorMessage=removeErrorMessage;function getErrorMessageHTML(tpl,m){var t=new JSTemplate();t.setTemplateContent("main",tpl,true);t.setVar("errormessage",m);t.parse("main",false);return t.printVar("main")}this.getErrorMessageHTML=getErrorMessageHTML;function getDateFormat(e){var b=Browser;var g=Global;var isDFA=((b.ie5)?g.isDefined(e.fvDateFormat):g.isDefined(e.getAttributeNode("fvDateFormat")));return(isDFA)?e.getAttribute("fvDateFormat"):FormValidatorConfig.defaultDateFormat}this.getDateFormat=getDateFormat;function validateRTF(t,f){if(t.tagName=="TEXTAREA"&&window.RTF){var id="RTF_"+t.form.name+"_"+t.name;var i=RTF.getIFrame(id);if(i){if(f&&i.errorObject){}else{var e=t.parentNode.lastChild;if(e&&e.style)e.style.left=VisualElementManager.getLeft(i)+i.offsetWidth-e.offsetWidth}}}}this.validateRTF=validateRTF}var FormValidator=new JSFormValidator();