codice:
var FormCheck=new Class({Implements:[Options,Events],options:{tipsClass:"fc-tbx",errorClass:"fc-error",fieldErrorClass:"fc-field-error",trimValue:false,validateDisabled:false,submitByAjax:false,ajaxResponseDiv:false,ajaxEvalScripts:false,onAjaxRequest:$empty,onAjaxSuccess:$empty,onAjaxFailure:$empty,display:{showErrors:0,titlesInsteadNames:0,errorsLocation:1,indicateErrors:1,indicateErrorsInit:0,keepFocusOnError:0,checkValueIfEmpty:1,addClassErrorToField:0,fixPngForIe:1,replaceTipsEffect:1,flashTips:0,closeTipsButton:1,tipsPosition:"right",tipsOffsetX:-45,tipsOffsetY:0,listErrorsAtTop:false,scrollToFirst:true,fadeDuration:300},alerts:{required:"This field is required.",alpha:"This field accepts alphabetic characters only.",alphanum:"This field accepts alphanumeric characters only.",nodigit:"No digits are accepted.",digit:"Please enter a valid integer.",digitltd:"The value must be between %0 and %1",number:"Please enter a valid number.",email:"Please enter a valid email.",phone:"Please enter a valid phone.",url:"Please enter a valid url.",confirm:"This field is different from %0",differs:"This value must be different of %0",length_str:"The length is incorrect, it must be between %0 and %1",length_fix:"Sono richiesti minino %0 caratteri",lengthmax:"The length is incorrect, it must be at max %0",lengthmin:"The length is incorrect, it must be at least %0",checkbox:"Please check the box",radios:"Please select a radio",select:"Please choose a value"},regexp:{required:/[^.*]/,alpha:/^[a-z ._-]+$/i,alphanum:/^[a-z0-9 ._-]+$/i,digit:/^[-+]?[0-9]+$/,nodigit:/^[^0-9]+$/,number:/^[-+]?\d*\.?\d+$/,email:/^[a-z0-9._%-]+@[a-z0-9.-]+\.[a-z]{2,4}$/i,phone:/^[\d\s ().-]+$/,url:/^(http|https|ftp)\:\/\/[a-z0-9\-\.]+\.[a-z]{2,3}(:[a-z0-9]*)?\/?([a-z0-9\-\._\?\,\'\/\\\+&%\$#\=~])*$/i}},initialize:function(C,A){if(this.form=$(C)){this.form.isValid=true;this.regex=["length"];this.setOptions(A);if(typeof (formcheckLanguage)!="undefined"){this.options.alerts=$merge(this.options.alerts,formcheckLanguage)}this.validations=[];this.alreadyIndicated=false;this.firstError=false;var B=new Hash(this.options.regexp);B.each(function(E,D){this.regex.push(D)},this);this.form.getElements("*[class*=validate]").each(function(D){this.register(D)},this);this.form.addEvents({submit:this.onSubmit.bind(this)});if(this.options.display.fixPngForIe){this.fixIeStuffs()}document.addEvent("mousewheel",function(){this.isScrolling=false}.bind(this))}},register:function(el){el.validation=[];el.getProperty("class").split(" ").each(function(classX){if(classX.match(/^validate(\[.+\])$/)){var validators=eval(classX.match(/^validate(\[.+\])$/)[1]);for(var i=0;i<validators.length;i++){el.validation.push(validators[i]);if(validators[i].match(/^confirm\[/)){var field=eval(validators[i].match(/^.+(\[.+\])$/)[1].replace(/([A-Z0-9\._-]+)/i,"'$1'"));if(this.form[field].validation.contains("required")){el.validation.push("required")}}}this.addListener(el)}},this)},dispose:function(A){this.validations.erase(A)},addListener:function(B){this.validations.push(B);B.errors=[];if(this.options.display.indicateErrorsInit){this.validations.each(function(C){if(!this.manageError(C,"submit")){this.form.isValid=false}},this);return true}if(B.validation[0]=="submit"){B.addEvent("click",function(C){this.onSubmit(C)}.bind(this));return true}if(this.isChildType(B)==false){B.addEvent("blur",function(){(function(){if(!this.fxRunning&&(B.element||this.options.display.showErrors==1)&&(this.options.display.checkValueIfEmpty||B.value)){this.manageError(B,"blur")}}.bind(this)).delay(100)}.bind(this))}else{if(this.isChildType(B)==true){var A=this.form.getElements('input[name="'+B.getProperty("name")+'"]');A.each(function(C){C.addEvent("blur",function(){(function(){if((B.element||this.options.display.showErrors==1)&&(this.options.display.checkValueIfEmpty||B.value)){this.manageError(B,"click")}}.bind(this)).delay(100)}.bind(this))},this)}}},validate:function(el){el.errors=[];el.isOk=true;if(!this.options.validateDisabled&&el.get("disabled")){return true}if(this.options.trimValue&&el.value){el.value=el.value.trim()}el.validation.each(function(rule){if(this.isChildType(el)){if(this.validateGroup(el)==false){el.isOk=false}}else{var ruleArgs=[];if(rule.match(/^.+\[/)){var ruleMethod=rule.split("[")[0];ruleArgs=eval(rule.match(/^.+(\[.+\])$/)[1].replace(/([A-Z0-9\._-]+)/i,"'$1'"))}else{var ruleMethod=rule}if(this.regex.contains(ruleMethod)&&el.get("tag")!="select"){if(this.validateRegex(el,ruleMethod,ruleArgs)==false){el.isOk=false}}if(ruleMethod=="confirm"){if(this.validateConfirm(el,ruleArgs)==false){el.isOk=false}}if(ruleMethod=="differs"){if(this.validateDiffers(el,ruleArgs)==false){el.isOk=false}}if(el.get("tag")=="select"||(el.type=="checkbox"&&ruleMethod=="required")){if(this.simpleValidate(el)==false){el.isOk=false}}if(rule.match(/%[A-Z0-9\._-]+$/i)||(el.isOk&&rule.match(/~[A-Z0-9\._-]+$/i))){if(eval(rule.slice(1)+"(el)")==false){el.isOk=false}}}},this);if(el.isOk){return true}else{return false}},simpleValidate:function(A){if(A.get("tag")=="select"&&A.selectedIndex<=0){A.errors.push(this.options.alerts.select);return false}else{if(A.type=="checkbox"&&A.checked==false){A.errors.push(this.options.alerts.checkbox);return false}}return true},validateRegex:function(C,B,D){var E="";if(D[1]&&B=="length"){if(D[1]==-1){this.options.regexp.length=new RegExp("^[\\s\\S]{"+D[0]+",}$");E=this.options.alerts.lengthmin.replace("%0",D[0])}else{if(D[0]==D[1]){this.options.regexp.length=new RegExp("^[\\s\\S]{"+D[0]+"}$");E=this.options.alerts.length_fix.replace("%0",D[0])}else{this.options.regexp.length=new RegExp("^[\\s\\S]{"+D[0]+","+D[1]+"}$");E=this.options.alerts.length_str.replace("%0",D[0]).replace("%1",D[1])}}}else{if(D[0]&&B=="length"){this.options.regexp.length=new RegExp("^.{0,"+D[0]+"}$");E=this.options.alerts.lengthmax.replace("%0",D[0])}else{E=this.options.alerts[B]}}if(D[1]&&B=="digit"){var A=true;if(!this.options.regexp.digit.test(C.value)){C.errors.push(this.options.alerts[B]);A=false}if(D[1]==-1){if(C.value>=D[0]){var F=true}else{var F=false}E=this.options.alerts.digitmin.replace("%0",D[0])}else{if(C.value>=D[0]&&C.value<=D[1]){var F=true}else{var F=false}E=this.options.alerts.digitltd.replace("%0",D[0]).replace("%1",D[1])}if(A==false||F==false){C.errors.push(E);return false}}else{if(this.options.regexp[B].test(C.value)==false){C.errors.push(E);return false}}return true},validateConfirm:function(B,C){var A=C[0];if(B.value!=this.form[A].value){if(this.options.display.titlesInsteadNames){var D=this.options.alerts.confirm.replace("%0",this.form[A].getProperty("title"))}else{var D=this.options.alerts.confirm.replace("%0",A)}B.errors.push(D);return false}return true},validateDiffers:function(A,C){var B=C[0];if(A.value==this.form[B].value){if(this.options.display.titlesInsteadNames){var D=this.options.alerts.differs.replace("%0",this.form[B].getProperty("title"))}else{var D=this.options.alerts.differs.replace("%0",B)}A.errors.push(D);return false}return true},isChildType:function(A)