(function(g){"function"===typeof define&&define.amd?define(["jquery","./jquery.inputmask"],g):g(jQuery)})(function(g){g.extend(g.inputmask.defaults.definitions,{h:{validator:"[01][0-9]|2[0-3]",cardinality:2,prevalidator:[{validator:"[0-2]",cardinality:1}]},s:{validator:"[0-5][0-9]",cardinality:2,prevalidator:[{validator:"[0-5]",cardinality:1}]},d:{validator:"0[1-9]|[12][0-9]|3[01]",cardinality:2,prevalidator:[{validator:"[0-3]",cardinality:1}]},m:{validator:"0[1-9]|1[012]",cardinality:2,prevalidator:[{validator:"[01]",
cardinality:1}]},y:{validator:"(19|20)\\d{2}",cardinality:4,prevalidator:[{validator:"[12]",cardinality:1},{validator:"(19|20)",cardinality:2},{validator:"(19|20)\\d",cardinality:3}]}});g.extend(g.inputmask.defaults.aliases,{"dd/mm/yyyy":{mask:"1/2/y",placeholder:"dd/mm/yyyy",regex:{val1pre:/[0-3]/,val1:/0[1-9]|[12][0-9]|3[01]/,val2pre:function(a){a=g.inputmask.escapeRegex.call(this,a);return RegExp("((0[1-9]|[12][0-9]|3[01])"+a+"[01])")},val2:function(a){a=g.inputmask.escapeRegex.call(this,a);return RegExp("((0[1-9]|[12][0-9])"+
a+"(0[1-9]|1[012]))|(30"+a+"(0[13-9]|1[012]))|(31"+a+"(0[13578]|1[02]))")}},leapday:"29/02/",separator:"/",yearrange:{minyear:1900,maxyear:2099},isInYearRange:function(a,d,c){if(isNaN(a))return!1;var e=parseInt(a.concat(d.toString().slice(a.length)));a=parseInt(a.concat(c.toString().slice(a.length)));return(isNaN(e)?!1:d<=e&&e<=c)||(isNaN(a)?!1:d<=a&&a<=c)},determinebaseyear:function(a,d,c){var e=(new Date).getFullYear();if(a>e)return a;if(d<e){for(var e=d.toString().slice(0,2),b=d.toString().slice(2,
4);d<e+c;)e--;d=e+b;return a>d?a:d}return e},onKeyUp:function(a,d,c,e){d=g(this);a.ctrlKey&&a.keyCode==e.keyCode.RIGHT&&(a=new Date,d.val(a.getDate().toString()+(a.getMonth()+1).toString()+a.getFullYear().toString()))},definitions:{1:{validator:function(a,d,c,e,b){var f=b.regex.val1.test(a);return e||f||a.charAt(1)!=b.separator&&-1=="-./".indexOf(a.charAt(1))||!(f=b.regex.val1.test("0"+a.charAt(0)))?f:(d.buffer[c-1]="0",{refreshFromBuffer:{start:c-1,end:c},pos:c,c:a.charAt(0)})},cardinality:2,prevalidator:[{validator:function(a,
d,c,e,b){isNaN(d.buffer[c+1])||(a+=d.buffer[c+1]);var f=1==a.length?b.regex.val1pre.test(a):b.regex.val1.test(a);return e||f||!(f=b.regex.val1.test("0"+a))?f:(d.buffer[c]="0",c++,{pos:c})},cardinality:1}]},2:{validator:function(a,d,c,e,b){var f=b.mask.indexOf("2")==b.mask.length-1?d.buffer.join("").substr(5,3):d.buffer.join("").substr(0,3);-1!=f.indexOf(b.placeholder[0])&&(f="01"+b.separator);var g=b.regex.val2(b.separator).test(f+a);if(!(e||g||a.charAt(1)!=b.separator&&-1=="-./".indexOf(a.charAt(1)))&&
(g=b.regex.val2(b.separator).test(f+"0"+a.charAt(0))))return d.buffer[c-1]="0",{refreshFromBuffer:{start:c-1,end:c},pos:c,c:a.charAt(0)};if(b.mask.indexOf("2")==b.mask.length-1&&g){if(d.buffer.join("").substr(4,4)+a!=b.leapday)return!0;a=parseInt(d.buffer.join("").substr(0,4),10);return 0===a%4?0===a%100?0===a%400?!0:!1:!0:!1}return g},cardinality:2,prevalidator:[{validator:function(a,d,c,e,b){isNaN(d.buffer[c+1])||(a+=d.buffer[c+1]);var f=b.mask.indexOf("2")==b.mask.length-1?d.buffer.join("").substr(5,
3):d.buffer.join("").substr(0,3);-1!=f.indexOf(b.placeholder[0])&&(f="01"+b.separator);var g=1==a.length?b.regex.val2pre(b.separator).test(f+a):b.regex.val2(b.separator).test(f+a);return e||g||!(g=b.regex.val2(b.separator).test(f+"0"+a))?g:(d.buffer[c]="0",c++,{pos:c})},cardinality:1}]},y:{validator:function(a,d,c,e,b){if(b.isInYearRange(a,b.yearrange.minyear,b.yearrange.maxyear)){if(d.buffer.join("").substr(0,6)!=b.leapday)return!0;a=parseInt(a,10);return 0===a%4?0===a%100?0===a%400?!0:!1:!0:!1}return!1},
cardinality:4,prevalidator:[{validator:function(a,d,c,e,b){var f=b.isInYearRange(a,b.yearrange.minyear,b.yearrange.maxyear);if(!e&&!f){e=b.determinebaseyear(b.yearrange.minyear,b.yearrange.maxyear,a+"0").toString().slice(0,1);if(f=b.isInYearRange(e+a,b.yearrange.minyear,b.yearrange.maxyear))return d.buffer[c++]=e.charAt(0),{pos:c};e=b.determinebaseyear(b.yearrange.minyear,b.yearrange.maxyear,a+"0").toString().slice(0,2);if(f=b.isInYearRange(e+a,b.yearrange.minyear,b.yearrange.maxyear))return d.buffer[c++]=
e.charAt(0),d.buffer[c++]=e.charAt(1),{pos:c}}return f},cardinality:1},{validator:function(a,d,c,e,b){var f=b.isInYearRange(a,b.yearrange.minyear,b.yearrange.maxyear);if(!e&&!f){e=b.determinebaseyear(b.yearrange.minyear,b.yearrange.maxyear,a).toString().slice(0,2);if(f=b.isInYearRange(a[0]+e[1]+a[1],b.yearrange.minyear,b.yearrange.maxyear))return d.buffer[c++]=e.charAt(1),{pos:c};e=b.determinebaseyear(b.yearrange.minyear,b.yearrange.maxyear,a).toString().slice(0,2);b.isInYearRange(e+a,b.yearrange.minyear,
b.yearrange.maxyear)?d.buffer.join("").substr(0,6)!=b.leapday?f=!0:(b=parseInt(a,10),f=0===b%4?0===b%100?0===b%400?!0:!1:!0:!1):f=!1;if(f)return d.buffer[c-1]=e.charAt(0),d.buffer[c++]=e.charAt(1),d.buffer[c++]=a.charAt(0),{refreshFromBuffer:{start:c-3,end:c},pos:c}}return f},cardinality:2},{validator:function(a,d,c,e,b){return b.isInYearRange(a,b.yearrange.minyear,b.yearrange.maxyear)},cardinality:3}]}},insertMode:!1,autoUnmask:!1},"mm/dd/yyyy":{placeholder:"mm/dd/yyyy",alias:"dd/mm/yyyy",regex:{val2pre:function(a){a=
g.inputmask.escapeRegex.call(this,a);return RegExp("((0[13-9]|1[012])"+a+"[0-3])|(02"+a+"[0-2])")},val2:function(a){a=g.inputmask.escapeRegex.call(this,a);return RegExp("((0[1-9]|1[012])"+a+"(0[1-9]|[12][0-9]))|((0[13-9]|1[012])"+a+"30)|((0[13578]|1[02])"+a+"31)")},val1pre:/[01]/,val1:/0[1-9]|1[012]/},leapday:"02/29/",onKeyUp:function(a,d,c,e){d=g(this);a.ctrlKey&&a.keyCode==e.keyCode.RIGHT&&(a=new Date,d.val((a.getMonth()+1).toString()+a.getDate().toString()+a.getFullYear().toString()))}},"yyyy/mm/dd":{mask:"y/1/2",
placeholder:"yyyy/mm/dd",alias:"mm/dd/yyyy",leapday:"/02/29",onKeyUp:function(a,d,c,e){d=g(this);a.ctrlKey&&a.keyCode==e.keyCode.RIGHT&&(a=new Date,d.val(a.getFullYear().toString()+(a.getMonth()+1).toString()+a.getDate().toString()))}},"dd.mm.yyyy":{mask:"1.2.y",placeholder:"dd.mm.yyyy",leapday:"29.02.",separator:".",alias:"dd/mm/yyyy"},"dd-mm-yyyy":{mask:"1-2-y",placeholder:"dd-mm-yyyy",leapday:"29-02-",separator:"-",alias:"dd/mm/yyyy"},"mm.dd.yyyy":{mask:"1.2.y",placeholder:"mm.dd.yyyy",leapday:"02.29.",
separator:".",alias:"mm/dd/yyyy"},"mm-dd-yyyy":{mask:"1-2-y",placeholder:"mm-dd-yyyy",leapday:"02-29-",separator:"-",alias:"mm/dd/yyyy"},"yyyy.mm.dd":{mask:"y.1.2",placeholder:"yyyy.mm.dd",leapday:".02.29",separator:".",alias:"yyyy/mm/dd"},"yyyy-mm-dd":{mask:"y-1-2",placeholder:"yyyy-mm-dd",leapday:"-02-29",separator:"-",alias:"yyyy/mm/dd"},datetime:{mask:"1/2/y h:s",placeholder:"dd/mm/yyyy hh:mm",alias:"dd/mm/yyyy",regex:{hrspre:/[012]/,hrs24:/2[0-4]|1[3-9]/,hrs:/[01][0-9]|2[0-4]/,ampm:/^[a|p|A|P][m|M]/,
mspre:/[0-5]/,ms:/[0-5][0-9]/},timeseparator:":",hourFormat:"24",definitions:{h:{validator:function(a,d,c,e,b){if("24"==b.hourFormat&&24==parseInt(a,10))return d.buffer[c-1]="0",d.buffer[c]="0",{refreshFromBuffer:{start:c-1,end:c},c:"0"};var f=b.regex.hrs.test(a);return e||f||a.charAt(1)!=b.timeseparator&&-1=="-.:".indexOf(a.charAt(1))||!(f=b.regex.hrs.test("0"+a.charAt(0)))?f&&"24"!==b.hourFormat&&b.regex.hrs24.test(a)?(a=parseInt(a,10),d.buffer[c+5]=24==a?"a":"p",d.buffer[c+6]="m",a-=12,10>a?(d.buffer[c]=
a.toString(),d.buffer[c-1]="0"):(d.buffer[c]=a.toString().charAt(1),d.buffer[c-1]=a.toString().charAt(0)),{refreshFromBuffer:{start:c-1,end:c+6},c:d.buffer[c]}):f:(d.buffer[c-1]="0",d.buffer[c]=a.charAt(0),c++,{refreshFromBuffer:{start:c-2,end:c},pos:c,c:b.timeseparator})},cardinality:2,prevalidator:[{validator:function(a,d,c,e,b){var f=b.regex.hrspre.test(a);return e||f||!(f=b.regex.hrs.test("0"+a))?f:(d.buffer[c]="0",c++,{pos:c})},cardinality:1}]},s:{validator:"[0-5][0-9]",cardinality:2,prevalidator:[{validator:function(a,
d,c,e,b){var f=b.regex.mspre.test(a);return e||f||!(f=b.regex.ms.test("0"+a))?f:(d.buffer[c]="0",c++,{pos:c})},cardinality:1}]},t:{validator:function(a,d,c,e,b){return b.regex.ampm.test(a+"m")},casing:"lower",cardinality:1}},insertMode:!1,autoUnmask:!1},datetime12:{mask:"1/2/y h:s t\\m",placeholder:"dd/mm/yyyy hh:mm xm",alias:"datetime",hourFormat:"12"},"hh:mm t":{mask:"h:s t\\m",placeholder:"hh:mm xm",alias:"datetime",hourFormat:"12"},"h:s t":{mask:"h:s t\\m",placeholder:"hh:mm xm",alias:"datetime",
hourFormat:"12"},"hh:mm:ss":{mask:"h:s:s",placeholder:"hh:mm:ss",alias:"datetime",autoUnmask:!1},"hh:mm":{mask:"h:s",placeholder:"hh:mm",alias:"datetime",autoUnmask:!1},date:{alias:"dd/mm/yyyy"},"mm/yyyy":{mask:"1/y",placeholder:"mm/yyyy",leapday:"donotuse",separator:"/",alias:"mm/dd/yyyy"}});return g.fn.inputmask});
