(function(e,t,n,a){e.fn.validateForm=function(t,n){var i,o=e(this),r=e.extend(!0,{},e.fn.validateForm.settings,n),s=arguments[0],l=[].slice.call(arguments,1);return o.each(function(){var n,o=e(this),c=e(this).find(r.selector.group),d=(e(this).find(r.selector.field),e(this).find(r.selector.prompt),[]),u=(o.selector||"",o.data("module-"+r.namespace)),f="string"==typeof s,p=r.namespace,g=r.metadata,m=r.className,h=r.errors;n={initialize:function(){n.verbose("Initializing form validation"),t===a&&e.isEmptyObject(t)?n.error(h.noFields,o):(e.fn.defaultText!==a&&e.each(t,function(e,t){n.field.add.defaultText(t)}),o.on("submit."+p,n.validate.form))},destroy:function(){o.off(p)},field:{find:function(t){var n=o.find(r.selector.field);return n.filter("#"+t).size()>0?n.filter("#"+t):n.filter('[name="'+t+'"]').size()>0?n.filter('[name="'+t+'"]'):n.filter("[data-"+g.validate+'="'+t+'"]').size()>0?n.filter("[data-"+g.validate+'="'+t+'"]'):e("")},add:{defaultText:function(e){var t=n.field.find(e.identifier);e.defaultText!==a&&t.defaultText(e.defaultText)},error:function(t,a){var i=n.field.find(t.identifier),o=i.closest(c),s=c.find(s),l=0!==s.size();o.addClass(m.error),r.inlineError&&(l||(s=e("
").addClass(m.prompt).insertBefore(i)),s.html(a[0]).fadeIn(r.animateSpeed))}},remove:{error:function(e){var t=n.field.find(e.identifier),a=t.closest(c),i=c.find(i);a.removeClass(m.error),r.inlineError&&i.hide()}}},validate:{form:function(a){var i=!0;return d=[],e.each(t,function(e,t){n.validate.field(t)||(i=!1)}),i?e.proxy(r.onSuccess,this)(a):e.proxy(r.onFailure,this)(d)},field:function(t){var i=n.field.find(t.identifier),o=!0,s=[];return t.rules!==a&&e.each(t.rules,function(e,a){n.validate.rule(t,a)||(n.debug("Field is invalid",t.identifier,a.type),s.push(a.prompt),o=!1)}),o?(n.field.remove.error(t,s),r.onValid(i),!0):(d=d.concat(s),n.field.add.error(t,s),e.proxy(r.onInvalid,i)(s),!1)},rule:function(t,i){var s,l,c=n.field.find(t.identifier),d=i.type,u=t.defaultText!==a?t.defaultText:!1,f=c.val()==u?"":c.val(),p=/\[(.*?)\]/i,g=p.exec(d),m=!0;return g!==a&&null!=g?(s=g[1],l=d.replace(g[0],""),m=e.proxy(r.rules[l],o)(f,s)):m="checked"==d?c.filter(":checked").size()>0:r.rules[d](f),m}},setting:function(e,t){return t===a?r[e]:(r[e]=t,a)},verbose:function(){r.verbose&&n.debug.apply(this,arguments)},debug:function(){var e=[],t=r.moduleName+": "+arguments[0],n=[].slice.call(arguments,1),a=console.info||console.log||function(){};a=Function.prototype.bind.call(a,console),r.debug&&(e.push(t),a.apply(console,e.concat(n)))},error:function(){var e=[],t=r.moduleName+": "+arguments[0],n=[].slice.call(arguments,1),a=console.warn||console.log||function(){};a=Function.prototype.bind.call(a,console),r.debug&&(e.push(t),e.concat(n),a.apply(console,e.concat(n)))},invoke:function(t,i,o){var r,s;return o=o||[].slice.call(arguments,2),"string"==typeof t&&u!==a&&(t=t.split("."),r=t.length-1,e.each(t,function(t,i){return e.isPlainObject(u[i])&&t!=r?(u=u[i],!0):u[i]!==a?(s=u[i],!0):(n.error(h.method),!1)})),e.isFunction(s)?s.apply(i,o):s}},f?i=n.invoke(s,this,l):n.initialize()}),i!==a?i:this},e.fn.validateForm.settings={moduleName:"Validate Form Module",debug:!0,verbose:!1,namespace:"validate",animateSpeed:150,inlineError:!1,onValid:function(){},onInvalid:function(){},onSuccess:function(){return!0},onFailure:function(){return!1},metadata:{validate:"validate"},errors:{method:"The method you called is not defined.",noFields:"No validation object specified."},selector:{group:".field",prompt:".prompt",field:"input, textarea, select"},className:{error:"error",prompt:"prompt"},rules:{empty:function(e){return!(e===a||""===e)},email:function(e){var t=RegExp("[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?");return t.test(e)},length:function(e,t){return e!==a?e.length>=t:!1},not:function(e,t){return e!=t},maxLength:function(e,t){return e!==a?t>=e.length:!1},match:function(t,n){var i,o=e(this);return o.find("#"+n).size()>0?i=o.find("#"+n).val():o.find("[name="+n+"]").size()>0?i=o.find("[name="+n+"]").val():o.find('[data-validate="'+n+'"]').size()>0&&(i=o.find('[data-validate="'+n+'"]').val()),i!==a?""+t==""+i:!1},url:function(e){var t=/(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;return t.test(e)}}}})(jQuery,window,document);