var ExtValidate=new Class({getOptions:function(){return{validateOnBlur:true,errorClass:"error",errorMsgClass:"errorMessage",dateFormat:"dd/MM/yy",onFail:Class.empty,onSuccess:false,showErrorsInline:true,label:"Please wait..."}},setHandler:function(c,d){if(typeof c=="function"){tmp=d;d=c;c=tmp}if((pos=c.indexOf("."))!=-1){type=c.substr(0,pos);c=c.substr(pos+1)}else{type="text";c=c}this.handlers.hasKey(type)||this.handlers.set(type,$H());this.handlers.get(type).set(c,d)},initialize:function(c,d){this.setOptions(this.getOptions(),
d);this.handlers=$H();$H({"text.longer":function(a){var b=a.className.match(/validate-[a-zA-Z0-9\_\-]+-([0-9]+)/);if(b==null||b[1]==null)return true;return a.value.length>=b[1]?true:{valid:false,msg:a.getProperty("alt")||"Please enter at least "+b[1]+" characters."}},"password._default":function(a){return a.value==""?false:true},"password.longer":function(a){var b=a.className.match(/validate-[a-zA-Z0-9\_\-]+-([0-9]+)/);if(b==null||b[1]==null)return true;return a.value.length>=b[1]?true:{valid:false,
msg:a.getProperty("alt")||"Please enter at least "+b[1]+" characters."}},"text.email":function(a){var b=/^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/;return a.value.toUpperCase().match(b)?true:{valid:false,msg:a.getProperty("alt")||"Please enter valid email."}},"text.numeric":function(a){var b=/[-+]?[0-9]*\.?[0-9]+/;return a.value.match(b)?true:{valid:false,msg:a.getProperty("alt")||"Please enter a valid number"}},"text.postcode":function(a){var b=/^([Gg][Ii][Rr] 0[Aa]{2})|((([A-Za-z][0-9]{1,2})|(([A-Za-z][A-Ha-hJ-Yj-y][0-9]{1,2})|(([A-Za-z][0-9][A-Za-z])|([A-Za-z][A-Ha-hJ-Yj-y][0-9]?[A-Za-z])))) [0-9][A-Za-z]{2})$/;
return a.value.match(b)?true:{valid:false,msg:"Please enter a valid postcode"}},"checkbox._default":function(a){return a.checked?true:false},"checkbox.moreone":function(a){a=$A(this.form[a.name]);var b=false;a.each(function(e,f){if(e.checked)b=true});a=a.getLast();return b?{msgEl:a,valid:true,msg:null}:{msgEl:a,valid:false,msg:a.getProperty("alt")||"Please select at least one option"}},"radio._default":function(a){a=$A(this.form[a.name]);var b=false;a.each(function(e,f){if(e.checked)b=true});a=a.getLast();
return b?{msgEl:a,valid:true,msg:null}:{msgEl:a,valid:false,msg:"Please select an option"}}}).each(this.setHandler,this);$H(this.options.routers).each(this.setHandler,this);this.clearMsg=typeof this.options.clearMsg=="function"?this.options.clearMsg:function(a){a.removeClass(this.options.errorClass);if(a.$error!=undefined){a.$error.remove();a.$error=undefined}};this.setMsg=typeof this.options.setMsg=="function"?this.options.setMsg:function(a,b){if(b==undefined)b=a.title;if(this.options.showErrorsInline){if(a.$error==
undefined)a.$error=(new Element("span")).addClass(this.options.errorMsgClass).setText(b).injectAfter(a);else a.$error.setText(b);a.addClass(this.options.errorClass)}};this.form=$(c);this.options.t&&this.form.hasClass("queue")&&this.form.adopt(new Element("input",{name:this.options.t,value:"1",type:"hidden"})).adopt(new Element("input",{name:"action",value:"extvalidate",type:"hidden"})).adopt(new Element("input",{name:"task",value:"queue",type:"hidden"}));this.elements=this.form.getElements(".required");
this.list=[];this.elements.each(function(a,b){this.options.validateOnBlur&&a.addEvent("blur",this.validate.bind(this,[a]))},this);this.form.addEvent("submit",function(a){var b=new Event(a),e=true;this.elements.each(function(f,g){if(this.validate(f))this.list.remove(f);else{b.stop();e=false;this.list.include(f)}}.bind(this));if(e)if(this.options.onSuccess){b.stop();this.options.onSuccess(this.form)}else this.form.getElement("input[type=submit]").setProperty("value",this.options.label);else this.options.onFail(this.getList())}.bind(this))},
getList:function(){var c=new Element("ul");this.list.each(function(d,a){if(d.title!=""){a=(new Element("li")).injectInside(c);(new Element("label")).setProperty("for",d.id).setText(d.title).injectInside(a)}});return c},checkField:function(c,d,a){var b=true;if(this.handlers.get(d).hasKey(a)){b=this.handlers.get(d).get(a).attempt([c],this);if(typeof b=="object"){msgEl=b.msgEl||c;msg=b.msg;b=b.valid}else{msg=null;b=b;msgEl=c}b||this.setMsg(msgEl,msg)}return b},validate:function(c){var d=true;this.clearMsg(c);
var a=c.className&&c.className.search(/validate-([a-zA-Z0-9\_\-]+)/)!=-1?c.className.match(/validate-([a-zA-Z0-9\_\-]+)/)[1]:"";_type=c.type;_handler="_default";switch(_type){case "textarea":case "select-one":_type="text";break}if(this.handlers.hasKey(_type)){if(this.handlers.get(_type).hasKey(a))_handler=a;else{d=a.match(/^([a-zA-Z0-9\_\-]+)-([0-9]+)$/);if(d!=null)_handler=d[1]}if(_type=="text")if(c.value!="")d=this.checkField(c,_type,_handler);else{d=false;this.setMsg(c)}else d=this.checkField(c,
_type,_handler)}return d}});ExtValidate.implement(new Options);ExtValidate.implement(new Events);