!function(e){"function"==typeof define&&define.amd?define(["jquery"],e):e("object"==typeof exports?require("jquery"):jQuery)}((function(e){var t,n=navigator.userAgent,a=/iphone/i.test(n),i=/chrome/i.test(n),r=/android/i.test(n);e.mask={definitions:{9:"[0-9]",a:"[A-Za-z]","*":"[A-Za-z0-9]"},autoclear:!0,dataName:"rawMaskFn",placeholder:"_"},e.fn.extend({caret:function(e,t){var n;if(0!==this.length&&!this.is(":hidden"))return"number"==typeof e?(t="number"==typeof t?t:e,this.each((function(){this.setSelectionRange?this.setSelectionRange(e,t):this.createTextRange&&((n=this.createTextRange()).collapse(!0),n.moveEnd("character",t),n.moveStart("character",e),n.select())}))):(this[0].setSelectionRange?(e=this[0].selectionStart,t=this[0].selectionEnd):document.selection&&document.selection.createRange&&(n=document.selection.createRange(),e=0-n.duplicate().moveStart("character",-1e5),t=e+n.text.length),{begin:e,end:t})},unmask:function(){return this.trigger("unmask")},mask:function(n,o){var c,u,l,s,f,d,h;if(!n&&this.length>0){var m=e(this[0]).data(e.mask.dataName);return m?m():void 0}return o=e.extend({autoclear:e.mask.autoclear,placeholder:e.mask.placeholder,completed:null},o),c=e.mask.definitions,u=[],l=d=n.length,s=null,e.each(n.split(""),(function(e,t){"?"==t?(d--,l=e):c[t]?(u.push(new RegExp(c[t])),null===s&&(s=u.length-1),l>e&&(f=u.length-1)):u.push(null)})),this.trigger("unmask").each((function(){function m(){if(o.completed){for(var e=s;f>=e;e++)if(u[e]&&R[e]===g(e))return;o.completed.call(x)}}function g(e){return o.placeholder.charAt(e<o.placeholder.length?e:0)}function p(e){for(;++e<d&&!u[e];);return e}function v(e,t){var n,a;if(!(0>e)){for(n=e,a=p(t);d>n;n++)if(u[n]){if(!(d>a&&u[n].test(R[a])))break;R[n]=R[a],R[a]=g(a),a=p(a)}y(),x.caret(Math.max(s,e))}}function k(){j(),x.val()!=S&&x.change()}function b(e,t){var n;for(n=e;t>n&&d>n;n++)u[n]&&(R[n]=g(n))}function y(){x.val(R.join(""))}function j(e){var t,n,a,i=x.val(),r=-1;for(t=0,a=0;d>t;t++)if(u[t]){for(R[t]=g(t);a++<i.length;)if(n=i.charAt(a-1),u[t].test(n)){R[t]=n,r=t;break}if(a>i.length){b(t+1,d);break}}else R[t]===i.charAt(a)&&a++,l>t&&(r=t);return e?y():l>r+1?o.autoclear||R.join("")===q?(x.val()&&x.val(""),b(0,d)):y():(y(),x.val(x.val().substring(0,r+1))),l?t:s}var x=e(this),R=e.map(n.split(""),(function(e,t){return"?"!=e?c[e]?g(t):e:void 0})),q=R.join(""),S=x.val();x.data(e.mask.dataName,(function(){return e.map(R,(function(e,t){return u[t]&&e!=g(t)?e:null})).join("")})),x.one("unmask",(function(){x.off(".mask").removeData(e.mask.dataName)})).on("focus.mask",(function(){var e;x.prop("readonly")||(clearTimeout(t),S=x.val(),e=j(),t=setTimeout((function(){x.get(0)===document.activeElement&&(y(),e==n.replace("?","").length?x.caret(0,e):x.caret(e))}),10))})).on("blur.mask",k).on("keydown.mask",(function(e){if(!x.prop("readonly")){var t,n,i,r=e.which||e.keyCode;h=x.val(),8===r||46===r||a&&127===r?(n=(t=x.caret()).begin,(i=t.end)-n==0&&(n=46!==r?function(e){for(;--e>=0&&!u[e];);return e}(n):i=p(n-1),i=46===r?p(i):i),b(n,i),v(n,i-1),e.preventDefault()):13===r?k.call(this,e):27===r&&(x.val(S),x.caret(0,j()),e.preventDefault())}})).on("keypress.mask",(function(t){if(!x.prop("readonly")){var n,a,i,o=t.which||t.keyCode,c=x.caret();if(!(t.ctrlKey||t.altKey||t.metaKey||32>o)&&o&&13!==o){if(c.end-c.begin!=0&&(b(c.begin,c.end),v(c.begin,c.end-1)),n=p(c.begin-1),d>n&&(a=String.fromCharCode(o),u[n].test(a))){if(function(e){var t,n,a,i;for(t=e,n=g(e);d>t;t++)if(u[t]){if(a=p(t),i=R[t],R[t]=n,!(d>a&&u[a].test(i)))break;n=i}}(n),R[n]=a,y(),i=p(n),r){setTimeout((function(){e.proxy(e.fn.caret,x,i)()}),0)}else x.caret(i);c.begin<=f&&m()}t.preventDefault()}}})).on("input.mask paste.mask",(function(){x.prop("readonly")||setTimeout((function(){var e=j(!0);x.caret(e),m()}),0)})),i&&r&&x.off("input.mask").on("input.mask",(function(){var e=x.val(),t=x.caret();if(h&&h.length&&h.length>e.length){for(j(!0);t.begin>0&&!u[t.begin-1];)t.begin--;if(0===t.begin)for(;t.begin<s&&!u[t.begin];)t.begin++;x.caret(t.begin,t.begin)}else{for(j(!0);t.begin<d&&!u[t.begin];)t.begin++;x.caret(t.begin,t.begin)}m()})),j()}))}})})),jQuery((function(e){e(".jqMaskedInput:not(.jqInitedMaskedInput)").livequery((function(){var t=e(this),n=t.attr("mask"),a=e.extend({mask:n},t.data());t.addClass("jqInitedMaskedInput").mask(a.mask,a)}))}));
