// errorLite v2.0 by Bruno Bernardino | 2013.03.23 | https://github.com/BrunoBernardino/ErrorLite (function(){var e,t,n;t={generateID:function(){var e;e=function(){return((1+window.Math.random())*65536|0).toString(16).substring(1)};return(e()+e()+"-"+e()+"-4"+e().substr(0,3)+"-"+e()+"-"+e()+e()+e()).toLowerCase()}};e={options:{}};n={init:function(t){var r;r={dataType:"type",dataErrorTitle:"errorTitle",dataErrorHelp:"errorHelp",errorRequiredTitle:"Required",errorRequiredHelp:"This field is required.",errorMaxLengthTitle:"Too Big",errorMaxLengthHelp:"This field's value is too big. The maximum number of characters for it is {maxLength}.",autoCheck:true,errorClass:"errorLite-error",position:"inside",animation:{type:"fade",speed:"fast",easing:"swing",onComplete:$.noop,extra:{margin:3}}};t=$.extend(r,t);e.options=$.extend({},t);return this.each(function(){var e,r;e=$(this);r=e.data("errorLite");if(!r){e.data("errorLite",{target:e});if(t.autoCheck){n.validate.call(this,t)}$(this).on("blur.errorLite",function(){return n.validate.call(this,t)});return $(this).on("focus.errorLite",function(){return n.hideError.call(this,t)})}})},destroy:function(){$(window).off(".errorLite");return this.each(function(){var e,t;e=$(this);t=e.data("errorLite");return e.removeData("errorLite")})},validate:function(t){var r,i,s,o,u,a;if(typeof t==="undefined"){t=e.options}r=$(this);a="";s=false;o=0;i=$(this).val();u=null;switch(r.attr("type")){case"email":case"url":case"number":a=r.attr("type");break;case"tel":a="alphanumeric-extended";break;default:switch(r.data(t.dataType)){case"alphanumeric":case"alphanumeric-extended":case"email":case"url":case"number":case"slug":a=r.data(t.dataType)}}if(r.prop("required")){s=true}if(r.attr("maxlength")){o=window.parseInt(r.attr("maxlength"),10)}if(a===""&&!s&&o<=0){return true}switch(a){case"alphanumeric":u=/[^a-z0-9]/g;if(u.test(i)){n.showError.call(this,{title:"Invalid",help:"This field's value isn't alphanumeric. It must consist only of numbers and/or (non-special) letters."},t);return false}break;case"alphanumeric-extended":u=/[^\u0000-\u00FFa-z0-9\-\._ ]/g;if(u.test(i)){n.showError.call(this,{title:"Invalid",help:"This field's value isn't alphanumeric. It must consist only of numbers, letters, dots, underscores, dashes and spaces."},t);return false}break;case"email":u=/^\S+@\S+\.\S+$/g;if(i.length>0&&!u.test(i)){n.showError.call(this,{title:"Invalid",help:"This field's value isn't an email. It must be a valid email address."},t);return false}break;case"url":u=/^(http|ftp|https):\/\/\S+\.\S+$/g;if(i.length>0&&!u.test(i)){n.showError.call(this,{title:"Invalid",help:"This field's value isn't an URL. It must be a valid URL and start with http://, for example."},t);return false}break;case"number":u=/[^\d]/g;if(u.test(i)){n.showError.call(this,{title:"Invalid",help:"This field's value isn't a number. It must be a valid natural number."},t);return false}break;case"slug":u=/[^a-z0-9\-_]/g;if(u.test(i)){n.showError.call(this,{title:"Invalid",help:"This field's value isn't a valid slug. It must consist only of numbers, lowercase (non-special) letters, underscores and dashes."},t);return false}}if(s&&i.length===0){n.showError.call(this,{title:t.errorRequiredTitle,help:t.errorRequiredHelp},t);return false}if(o>0&&i.length>o){n.showError.call(this,{title:t.errorMaxLengthTitle,help:t.errorMaxLengthHelp.replace("{maxLength}",o)},t);return false}return true},showError:function(r,i){var s,o,u,a;if(typeof i==="undefined"){i=e.options}s=$(this);if(s.siblings("."+i.errorClass).length){return true}if(s.data(i.dataErrorTitle)&&r.title!==i.errorRequiredTitle&&r.title!==i.errorMaxLengthTitle){r.title=s.data(i.dataErrorTitle)}if(s.data(i.dataErrorHelp)&&r.help!==i.errorRequiredHelp&&r.help!==i.errorMaxLengthHelp){r.help=s.data(i.dataErrorHelp)}a=t.generateID.call(this);u="errorLite-error-"+a;o='
'+r.title+"
";s.after(o);switch(i.position){case"outside":$("#"+u).css({"margin-left":s.outerWidth()+i.animation.extra.margin});break;default:$("#"+u).css({"margin-left":s.outerWidth()-$("#"+u).outerWidth()-i.animation.extra.margin})}switch(i.animation.type){case"slide":$("#"+u).slideDown(i.animation.speed,i.animation.easing,i.animation.onComplete);break;default:$("#"+u).fadeIn(i.animation.speed,i.animation.easing,i.animation.onComplete)}return $("#"+u).on("click.errorLite",function(e){e.preventDefault();return n.hideError.call(s,i)})},hideError:function(t){if(typeof t==="undefined"){t=e.options}switch(t.animation.type){case"slide":return $(this).siblings("."+t.errorClass).slideUp(t.animation.speed,t.animation.easing,function(){return $(this).remove()});default:return $(this).siblings("."+t.errorClass).fadeOut(t.animation.speed,t.animation.easing,function(){return $(this).remove()})}},hideAllErrors:function(t){if(typeof t==="undefined"){t=e.options}switch(t.animation.type){case"slide":return $("."+t.errorClass).slideUp(t.animation.speed,t.animation.easing,function(){return $(this).remove()});default:return $("."+t.errorClass).fadeOut(t.animation.speed,t.animation.easing,function(){return $(this).remove()})}}};$.fn.errorLite=function(e){if(n[e]){return n[e].apply(this,Array.prototype.slice.call(arguments,1))}else if(typeof e==="object"||!e){return n.init.apply(this,arguments)}else{return $.error("Method "+e+" does not exist on jQuery.errorLite")}}}).call(this)