ACMS.Dispatch._validate.validators=[];ACMS.Dispatch._validate.validators.checked=[];ACMS.Dispatch._validate=function(elm){ACMS.Dispatch._validate.extract(elm);ACMS.Dispatch._validate.setValidator(elm)};ACMS.Dispatch._validate.setValidator=function(elm){var $field=ACMS.Dispatch._validate.input(elm);_.each($field,function(val,i){var name=$(val).attr("name");if(!name){return}name=name.replace(/\[[\d]*\]/,"");$(val).data("oldvalue",$(val).val());setInterval(function(){var oldvalue=$(val).data("oldvalue");var value=$(val).val();if(oldvalue!=value){$(val).trigger("change")}$(val).data("oldvalue",value)},100);$(val).bind("blur input change",function(){var validator=ACMS.Dispatch._validate.validators[name];var success=true;var matches=$(this).attr("name").match(/\[([\d]+)\]/);var number=false;if(matches){number=matches[1]}_.each(validator,function(obj,i){if(!obj||!obj.validator){return}if(!ACMS.Library.Validator.isFunction(obj.validator)||"all_"===obj.validator.substring(0,4)){return}var valid=true;obj.number=parseInt(number);if(obj.type==="checkbox"||obj.type==="radio"){if(obj.validator==="required"){var v=false;_.each($('[name^="'+obj.field+'"]'),function(item){if($(item).prop("checked")){v=true}});valid=v}else{return}}else{valid=ACMS.Library.Validator[obj.validator]($(val).val(),obj.arg,val)}ACMS.Dispatch._validate.label(obj,valid);success&=valid});ACMS.Dispatch._validate.toggleClass(name,success);return true})})};ACMS.Dispatch._validate.all=function(elm){var $field=ACMS.Dispatch._validate.input(elm),res=true;_.each(ACMS.Dispatch._validate.validators.checked,function(obj,i){var $input=$field.filter('[name="'+obj.field+'"], [name="'+obj.field+"[]"+'"]');var success=ACMS.Library.Validator[obj.validator]($input,obj.arg);ACMS.Dispatch._validate.label(obj,success);res&=success});_.each($field,function(val,i){var name=$(val).attr("name");if(!name){return}name=name.replace(/\[[\d]*\]/,"");var validator=ACMS.Dispatch._validate.validators[name];var success=true;_.each(validator,function(obj,i){if(!obj||!obj.validator){return}if(!ACMS.Library.Validator.isFunction(obj.validator)||"all_"===obj.validator.substring(0,4)){return}var valid=true;if(obj.type==="checkbox"||obj.type==="radio"){if(obj.validator==="required"){var v=false;_.each($('[name^="'+obj.field+'"]'),function(item){if($(item).prop("checked")){v=true}});valid=v}else{return}}else{valid=ACMS.Library.Validator[obj.validator]($(val).val(),obj.arg,val)}var matches=$(val).attr("name").match(/\[([\d]+)\]/);if(matches){obj.number=parseInt(matches[1])}ACMS.Dispatch._validate.label(obj,valid);success&=valid});ACMS.Dispatch._validate.toggleClass(name,success);res&=success});return!!res};ACMS.Dispatch._validate.extract=function(elm){ACMS.Dispatch._validate.input(elm).each(function(){if(this.name.match(/^(.*):(validator|v)#(.*)$/)){var field=RegExp.$1,validator=RegExp.$3,obj={field:field,validator:validator,arg:$(this).val(),id:$(this).attr("id"),type:$('[name^="'+field+'"]').attr("type"),number:-1};if("all_"==obj.validator.substring(0,4)){ACMS.Dispatch._validate.validators.checked.push(obj)}if(!ACMS.Dispatch._validate.validators[field]){ACMS.Dispatch._validate.validators[field]=[]}ACMS.Dispatch._validate.validators[field].push(obj)}})};ACMS.Dispatch._validate.input=function(elm){return $(":input:not(:disabled)",elm)};ACMS.Dispatch._validate.label=function(obj,valid){var $label=$('[data-validator-label="'+obj.id+'"]');if($label.length<1){$label=$('label[for="'+obj.id+'"]')}if($label.length>1&&obj.number>-1){$label=$($label.get(obj.number))}if($label.size()){$label.removeClass(ACMS.Config.validatorResultClass);$label.removeClass(ACMS.Config.validatorResultClass+"0");$label.removeClass(ACMS.Config.validatorResultClass+"1");$label.addClass("validator-result-"+(valid?"1":"0"))}};ACMS.Dispatch._validate.toggleClass=function(name,success){var $custom=$('[data-validator="'+name+'"]');if($custom.size()){var ok=ACMS.Config.validatorOkClass,ng=ACMS.Config.validatorNgClass;if(success){$custom.removeClass(ng).addClass(ok)}else{$custom.removeClass(ok).addClass(ng)}}};