/*! myValidate - v2.5 - 2017-02-21 * https://github.com/jonasmello/myValidate * Copyright (c) 2017 Jonas Mello; Licensed MIT */ !function(a,b,c){"use strict";a.fn.myValidate=function(b){var c,d="object"==typeof b&&b.instance||!1,e="object"==typeof b&&b.removeData||!1;return d?this.each(function(){c=new a.myValidate(this,b),e&&a.removeData(this,"myValidate"),a.data(this,"myValidate")||a.data(this,"myValidate",c)}):c=this.each(function(){e&&a.removeData(this,"myValidate"),a.data(this,"myValidate")||a.data(this,"myValidate",new a.myValidate(this,b))}),c},a.myValidate=function(b,c){this.version="2.5",this.element=b,this.callbackSubmit=!0,this.options=a.extend({},a.myValidate.options,c),this.$form=a(this.element),this.reset=a.proxy(function(){this.options.notdisabled?this.$rules=this.$form.find("[data-myrules]").not(":disabled"):this.$rules=this.$form.find("[data-myrules]")},this),this.reset(),this.element&&this.init()},a.myValidate.options={debug:!1,error:"Some required fields are empty.",errorattach:"It is necessary to attach a file.",errormail:"Please enter a valid email address.",errorcpf:"CPF Inválido",errorcnpj:"CNPJ Inválido",erroequal:"Campos {0} e {1} não são iguais",required:"required",notification:".notification","class":"error",errorcolor:"#F00",notdisabled:!0,bind:"keyup change",changeBackground:!0,backgrounds:[["#cc0000","#FFF"],["#cc3333","#FFF"],["#cc6666","#FFF"],["#ff9999","#FFF"],["#e0941c","#FFF"],["#e8a53a","#FFF"],["#eab259","#FFF"],["#efd09e","#FFF"],["#ccffcc","#FFF"],["#66cc66","#FFF"],["#339933","#FFF"],["#006600","#FFF"],["#105610","#FFF"]],passwordValidFrom:60,onValidatePassword:function(a){this.debug&&console.log(a)},onPasswordStrengthChanged:function(a,b){this.debug&&console.log(a,b)},beforeValidate:function(){},callError:function(a,b,c){this.debug&&console.log(a,b,c),b.find(".notification").slideDown()},callSuccess:function(a,b,c){this.debug&&console.log(a,b,c)}},a.myValidate.prototype.validarCPF=function(a){var b,c,d,e,f=a.replace(/\D/g,""),g=/^(\d{1})\1{10}$/;if(11!==f.length)return!1;if(g.test(f))return!1;for(c=0,b=0;9>b;b+=1)c+=parseInt(f.charAt(b),10)*(10-b);if(d=c%11,e=d>1?11-d:0,parseInt(f.charAt(9),10)!==e)return!1;for(c=0,b=0;10>b;b+=1)c+=parseInt(f.charAt(b),10)*(11-b);return d=c%11,e=d>1?11-d:0,parseInt(f.charAt(10),10)!==e?!1:!0},a.myValidate.prototype.validarCNPJ=function(a){var b,c,d,e,f,g=a.replace(/\D/g,""),h=/^(\d{1})\1{13}$/;if(14!==g.length)return!1;if(h.test(g))return!1;for(c=0,b=0;12>b;b+=1)d=(3>=b?5:13)-b,c+=parseInt(g.charAt(b),10)*d;if(c%=11,e=0===c||1===c?0:11-c,parseInt(e,10)===parseInt(g.charAt(12),10)){for(c=0,b=0;13>b;b+=1)d=(4>=b?6:14)-b,c+=parseInt(g.charAt(b),10)*d;if(c%=11,f=0===c||1===c?0:11-c,f===parseInt(g.charAt(13),10))return!0}return!1},a.myValidate.prototype.init=function(){this.elementsOnClick(),this.elSubmit(this.element)},a.myValidate.prototype.elementsOnClick=function(){var b=this,c="form"+(b.element.id.length?"#"+b.element.id:b.element.name.length?'[name="'+b.element.name+'"]':b.element.className.length?"."+b.element.className:"");a(c+' [onclick*="submit()"]').each(function(b,d){a(d).attr("onclick","javascript:$('"+c+"').myValidate().submit();")}),a(c+" [data-submit]").each(function(b,d){a(d).attr("onclick","javascript:$('"+c+"').myValidate().submit();")})},a.myValidate.prototype.elSubmit=function(b){var c=this;a(b).on("submit",{self:c},c.validate)},a.myValidate.prototype.validate=function(b){var c=b?b.data.self:this;c.callbackSubmit=!0,c.$rules.length>0&&(c.getErrorMessage(b),c.options.beforeValidate(c.$form),c.$rules.each(function(){var b=a(this);(b.not(":disabled")||!b.attr("disabled"))&&(""===b.data("myrules")&&b.data("myrules","required"),b.removeClass(c.options["class"]),b.parent().removeClass(c.options["class"]),b.next(".chzn-container").removeClass(c.options["class"]),b.next(".select2-container").find(".select2-selection").removeClass(c.options["class"]),c.isRequired(b).validateEmail(b).validateCpf(b).validateCnpj(b).validateDoc(b).validateSelect(b).validateCheckbox(b).validatePassword(b).validateEqual(b))})),c.callbackSubmit?c.options.callSuccess(b,c.$form,c.callbackSubmit):(b.preventDefault(),b.stopPropagation(),c.options.callError(b,c.$form,c.callbackSubmit))},a.myValidate.prototype.notification=function(b){a(this.options.notification).html(b)},a.myValidate.prototype.getErrorMessage=function(a){var b=a?a.data.self:this;b.options.error=b.$form.data("error")||b.options.error,b.options.errormail=b.$form.data("errormail")||b.options.errormail,b.options.errorattach=b.$form.data("errorattach")||b.options.errorattach,b.options.errorcpf=b.$form.data("errorcpf")||b.options.errorcpf,b.options.errorcnpj=b.$form.data("errorcnpj")||b.options.errorcnpj,b.options.erroequal=b.$form.data("erroequal")||b.options.erroequal},a.myValidate.prototype.isRequired=function(a){return a.filter('[data-myrules*="required"]').length&&this.notVal(a),this},a.myValidate.prototype.notVal=function(a){return(""===a.val()||null===a.val())&&(this.callbackSubmit=!1,this.notification(this.options.error),a.addClass(this.options["class"]),this.notFile(a)),this},a.myValidate.prototype.notFile=function(a){return a.is('input[type="file"]')&&(this.notification(this.options.errorattach),this.callbackSubmit=!1,a.parent().addClass(this.options["class"]).find(".label").addClass(this.options["class"]),this.notification(this.options.errorattach)),this},a.myValidate.prototype.validateEmail=function(a){if(a.filter('[data-myrules*="email"]').length){var b=/^[\d\w]+([_.-]?[\d\w]+)*@([\d\w_-]{2,}(\.){1})+?[\d\w]{2,4}$/;b.test(a.val())||(this.callbackSubmit=!1,a.addClass(this.options["class"]),this.notification(this.options.errormail))}return this},a.myValidate.prototype.validateCpf=function(a){return a.filter('[data-myrules*="cpf"]').length&&(this.validarCPF(a.val())||(this.callbackSubmit=!1,a.addClass(this.options["class"]),this.notification(this.options.errorcpf))),this},a.myValidate.prototype.validateCnpj=function(a){return a.filter('[data-myrules*="cnpj"]').length&&(this.validarCNPJ(a.val())||(this.callbackSubmit=!1,a.addClass(this.options["class"]),this.notification(this.options.errorcnpj))),this},a.myValidate.prototype.validateDoc=function(a){if(a.filter('[data-myrules*="doc"]').length){var b=a.val().replace(/\D/g,""),c=b.length;c>11?this.validarCNPJ(a.val())||(this.callbackSubmit=!1,a.addClass(this.options["class"]),this.notification(this.options.errorcnpj)):this.validarCPF(a.val())||(this.callbackSubmit=!1,a.addClass(this.options["class"]),this.notification(this.options.errorcpf))}return this},a.myValidate.prototype.validateSelect=function(a){return!a.is("select")||""!==a.val()&&null!==a.val()||(this.callbackSubmit=!1,this.notification(this.options.error),a.addClass(this.options["class"]),a.next(".chzn-container").addClass(this.options["class"]),a.next(".select2-container").find(".select2-selection").addClass(this.options["class"])),this},a.myValidate.prototype.validateCheckbox=function(a){return a.is('input[type="checkbox"]')&&!a.is("input:checked")&&(a.parent().addClass(this.options["class"]),this.callbackSubmit=!1,this.notification(this.options.errormail)),this},a.myValidate.prototype.validateEqual=function(a){if(a.filter('[data-myrules*="equal"]').length){var b,c=a.data("myrules").search("equal"),d=a.data("myrules").slice(c),e=a.attr("title")||a.attr("name");d=d.replace("equal[",""),d=d.replace("]",""),d=this.$form.find('[name="'+d+'"]'),b=d.attr("title")||d.attr("name"),""!==d.val()&&d.val()!==a.val()&&(this.callbackSubmit=!1,this.notification(this.options.erroequal.format(e,b)),a.addClass(this.options["class"]),d.addClass(this.options["class"]))}return this},a.myValidate.prototype.validatePassword=function(b){var d=this,e=[],f=[],g=[],h=[],i=[];if(b.filter('[data-myrules*="password"]').length){d.callbackSubmit=!1;for(var j=48;58>j;j++)e.push(j);for(j=65;91>j;j++)f.push(j);for(j=97;123>j;j++)g.push(j);for(j=32;48>j;j++)h.push(j);for(j=58;65>j;j++)h.push(j);for(j=91;97>j;j++)h.push(j);for(j=123;127>j;j++)h.push(j);var k=function(a){var b=a+"",c=b.charCodeAt(0);if(c>=55296&&56319>=c){var d=c;if(1===b.length)return c;var e=b.charCodeAt(1);return 1024*(d-55296)+(e-56320)+65536}return c>=56320&&57343>=c?c:c},l=function(b){var e=Math.ceil(100*b/12);e=e>100?100:e,d.options.onPasswordStrengthChanged.call(a(this),b,e),d.notification("Senha fraca"),e>=d.options.passwordValidFrom&&(d.notification("Senha segura"),d.callbackSubmit=!0,d.options.onValidatePassword.call(a(this),e)),d.options.changeBackground&&(b===c&&(b=a(this)),b=b>12?12:b,a(a(this)).css({"background-color":d.options.backgrounds[b][0],color:d.options.backgrounds[b][1]}))},m=function(){var b=0,c=0,d=0,i=0,j=0,m=a(this).val().trim();b+=2*Math.floor(m.length/8);for(var n=0;nc?(b++,c++):-1!==a.inArray(k(m.charAt(n)),f)&&2>d?(b++,d++):-1!==a.inArray(k(m.charAt(n)),g)&&2>i?(b++,i++):-1!==a.inArray(k(m.charAt(n)),h)&&2>j&&(b++,j++);return l.call(a(this),b),b};b.each(a.proxy(function(b,c){i[a(c)]={background:a(c).css("background"),color:a(c).css("color")},m.call(c),a(c).bind(d.options.bind,function(){m.call(c)})},b))}return this},String.prototype.format||(String.prototype.format=function(){var a=arguments;return this.replace(/{(\d+)}/g,function(b,c){return"undefined"!=typeof a[c]?a[c]:b})})}(jQuery,window);