!function(e){var t,n=function(){var e=document.createElement("input"),t="onpaste";return e.setAttribute(t,""),"function"==typeof e[t]?"paste":"input"}()+".mask",a=navigator.userAgent,r=/iphone/i.test(a),i=/android/i.test(a);e.mask={definitions:{9:"[0-9]",a:"[A-Za-z]","*":"[A-Za-z0-9]"},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(a,o){var c,l,s,u,f;return!a&&this.length>0?e(this[0]).data(e.mask.dataName)():(o=e.extend({placeholder:e.mask.placeholder,completed:null},o),c=e.mask.definitions,l=[],s=f=a.length,u=null,e.each(a.split(""),(function(e,t){"?"==t?(f--,s=e):c[t]?(l.push(RegExp(c[t])),null===u&&(u=l.length-1)):l.push(null)})),this.trigger("unmask").each((function(){function h(e){for(;f>++e&&!l[e];);return e}function d(e,t){var n,a;if(!(0>e)){for(n=e,a=h(t);f>n;n++)if(l[n]){if(!(f>a&&l[n].test(k[a])))break;k[n]=k[a],k[a]=o.placeholder,a=h(a)}p(),v.caret(Math.max(u,e))}}function m(e,t){var n;for(n=e;t>n&&f>n;n++)l[n]&&(k[n]=o.placeholder)}function p(){v.val(k.join(""))}function g(e){var t,n,a=v.val(),r=-1;for(t=0,pos=0;f>t;t++)if(l[t]){for(k[t]=o.placeholder;pos++<a.length;)if(n=a.charAt(pos-1),l[t].test(n)){k[t]=n,r=t;break}if(pos>a.length)break}else k[t]===a.charAt(pos)&&t!==s&&(pos++,r=t);return e?p():s>r+1?(v.val(""),m(0,f)):(p(),v.val(v.val().substring(0,r+1))),s?t:u}var v=e(this),k=e.map(a.split(""),(function(e){return"?"!=e?c[e]?o.placeholder:e:void 0})),b=v.val();v.data(e.mask.dataName,(function(){return e.map(k,(function(e,t){return l[t]&&e!=o.placeholder?e:null})).join("")})),v.attr("readonly")||v.one("unmask",(function(){v.unbind(".mask").removeData(e.mask.dataName)})).bind("focus.mask",(function(){var e;clearTimeout(t),b=v.val(),e=g(),t=setTimeout((function(){p(),e==a.length?v.caret(0,e):v.caret(e)}),10)})).bind("blur.mask",(function(){g(),v.val()!=b&&v.change()})).bind("keydown.mask",(function(e){var t,n,a,i=e.which;8===i||46===i||r&&127===i?(n=(t=v.caret()).begin,0==(a=t.end)-n&&(n=46!==i?function(e){for(;--e>=0&&!l[e];);return e}(n):a=h(n-1),a=46===i?h(a):a),m(n,a),d(n,a-1),e.preventDefault()):27==i&&(v.val(b),v.caret(0,g()),e.preventDefault())})).bind("keypress.mask",(function(t){var n,a,r,c=t.which,s=v.caret();t.ctrlKey||t.altKey||t.metaKey||32>c||c&&(0!=s.end-s.begin&&(m(s.begin,s.end),d(s.begin,s.end-1)),n=h(s.begin-1),f>n&&(a=String.fromCharCode(c),l[n].test(a)&&(function(e){var t,n,a,r;for(t=e,n=o.placeholder;f>t;t++)if(l[t]){if(a=h(t),r=k[t],k[t]=n,!(f>a&&l[a].test(r)))break;n=r}}(n),k[n]=a,p(),r=h(n),i?setTimeout(e.proxy(e.fn.caret,v,r),0):v.caret(r),o.completed&&r>=f&&o.completed.call(v))),t.preventDefault())})).bind(n,(function(){setTimeout((function(){var e=g(!0);v.caret(e),o.completed&&e==v.val().length&&o.completed.call(v)}),0)})),g()})))}})}(jQuery);