/*
 Pikaday

 Copyright 2014 David Bushell | BSD & MIT license | https://github.com/dbushell/Pikaday
*/
(function(m,q){if("object"===typeof exports){try{var u=require("moment")}catch(h){}module.exports=q(u)}else"function"===typeof define&&define.amd?define(function(h){try{u=h("moment")}catch(v){}return q(u)}):m.Pikaday=q(m.moment)})(this,function(m){var q="function"===typeof m,u=!!window.addEventListener,h=window.document,v=window.setTimeout,r=function(a,b,c,d){u?a.addEventListener(b,c,!!d):a.attachEvent("on"+b,c)},t=function(a,b,c,d){u?a.removeEventListener(b,c,!!d):a.detachEvent("on"+b,c)},B=function(a,
b,c){if(h.createEvent){var d=h.createEvent("HTMLEvents");d.initEvent(b,!0,!1);d=w(d,c);a.dispatchEvent(d)}else h.createEventObject&&(d=h.createEventObject(),d=w(d,c),a.fireEvent("on"+b,d))},e=function(a,b){return-1!==(" "+a.className+" ").indexOf(" "+b+" ")},y=function(a){return/Array/.test(Object.prototype.toString.call(a))},k=function(a){return/Date/.test(Object.prototype.toString.call(a))&&!isNaN(a.getTime())},z=function(a){k(a)&&a.setHours(0,0,0,0)},A=function(a,b){return a.getTime()===b.getTime()},
w=function(a,b,c){var d,p;for(d in b)if((p=void 0!==a[d])&&"object"===typeof b[d]&&null!==b[d]&&void 0===b[d].nodeName)k(b[d])?c&&(a[d]=new Date(b[d].getTime())):y(b[d])?c&&(a[d]=b[d].slice(0)):a[d]=w({},b[d],c);else if(c||!p)a[d]=b[d];return a},C=function(a){0>a.month&&(a.year-=Math.ceil(Math.abs(a.month)/12),a.month+=12);11<a.month&&(a.year+=Math.floor(Math.abs(a.month)/12),a.month-=12);return a},D={field:null,bound:void 0,position:"bottom left",reposition:!0,format:"YYYY-MM-DD",defaultDate:null,
setDefaultDate:!1,firstDay:0,minDate:null,maxDate:null,yearRange:10,showWeekNumber:!1,minYear:0,maxYear:9999,minMonth:void 0,maxMonth:void 0,startRange:null,endRange:null,isRTL:!1,yearSuffix:"",showMonthAfterYear:!1,numberOfMonths:1,mainCalendar:"left",container:void 0,i18n:{previousMonth:"Previous Month",nextMonth:"Next Month",months:"January February March April May June July August September October November December".split(" "),weekdays:"Sunday Monday Tuesday Wednesday Thursday Friday Saturday".split(" "),
weekdaysShort:"Sun Mon Tue Wed Thu Fri Sat".split(" ")},theme:null,onSelect:null,onOpen:null,onClose:null,onDraw:null},E=function(a,b,c){for(b+=a.firstDay;7<=b;)b-=7;return c?a.i18n.weekdaysShort[b]:a.i18n.weekdays[b]},H=function(a){if(a.isEmpty)return'<td class="is-empty"></td>';var b=[];a.isDisabled&&b.push("is-disabled");a.isToday&&b.push("is-today");a.isSelected&&b.push("is-selected");a.isInRange&&b.push("is-inrange");a.isStartRange&&b.push("is-startrange");a.isEndRange&&b.push("is-endrange");
return'<td data-day="'+a.day+'" class="'+b.join(" ")+'"><button class="pika-button pika-day" type="button" data-pika-year="'+a.year+'" data-pika-month="'+a.month+'" data-pika-day="'+a.day+'">'+a.day+"</button></td>"},I=function(a,b,c){var d=new Date(c,0,1);return'<td class="pika-week">'+Math.ceil(((new Date(c,b,a)-d)/864E5+d.getDay()+1)/7)+"</td>"},J=function(a,b){return"<tr>"+(b?a.reverse():a).join("")+"</tr>"},K=function(a,b,c,d,p){var f,g=a._o,h=c===g.minYear,F=c===g.maxYear,l='<div class="pika-title">',
k=!0,n=!0;var e=[];for(f=0;12>f;f++)e.push('<option value="'+(c===p?f-b:12+f-b)+'"'+(f===d?" selected":"")+(h&&f<g.minMonth||F&&f>g.maxMonth?"disabled":"")+">"+g.i18n.months[f]+"</option>");p='<div class="pika-label">'+g.i18n.months[d]+'<select class="pika-select pika-select-month" tabindex="-1">'+e.join("")+"</select></div>";if(y(g.yearRange)){f=g.yearRange[0];var m=g.yearRange[1]+1}else f=c-g.yearRange,m=1+c+g.yearRange;for(e=[];f<m&&f<=g.maxYear;f++)f>=g.minYear&&e.push('<option value="'+f+'"'+
(f===c?" selected":"")+">"+f+"</option>");c='<div class="pika-label">'+c+g.yearSuffix+'<select class="pika-select pika-select-year" tabindex="-1">'+e.join("")+"</select></div>";l=g.showMonthAfterYear?l+(c+p):l+(p+c);h&&(0===d||g.minMonth>=d)&&(k=!1);F&&(11===d||g.maxMonth<=d)&&(n=!1);0===b&&(l+='<button class="pika-prev'+(k?"":" is-disabled")+'" type="button">'+g.i18n.previousMonth+"</button>");b===a._o.numberOfMonths-1&&(l+='<button class="pika-next'+(n?"":" is-disabled")+'" type="button">'+g.i18n.nextMonth+
"</button>");return l+"</div>"},G=function(a){var b=this,c=b.config(a);b._onMouseDown=function(a){if(b._v){a=a||window.event;var d=a.target||a.srcElement;if(d)if(e(d.parentNode,"is-disabled")||(e(d,"pika-button")&&!e(d,"is-empty")?(b.setDate(new Date(d.getAttribute("data-pika-year"),d.getAttribute("data-pika-month"),d.getAttribute("data-pika-day"))),c.bound&&v(function(){b.hide();c.field&&c.field.blur()},100)):e(d,"pika-prev")?b.prevMonth():e(d,"pika-next")&&b.nextMonth()),e(d,"pika-select"))b._c=
!0;else if(a.preventDefault)a.preventDefault();else return a.returnValue=!1}};b._onChange=function(a){a=a||window.event;(a=a.target||a.srcElement)&&(e(a,"pika-select-month")?b.gotoMonth(a.value):e(a,"pika-select-year")&&b.gotoYear(a.value))};b._onInputChange=function(a){a.firedBy!==b&&(a=q?(a=m(c.field.value,c.format))&&a.isValid()?a.toDate():null:new Date(Date.parse(c.field.value)),k(a)&&b.setDate(a),b._v||b.show())};b._onInputFocus=function(){b.show()};b._onInputClick=function(){b.show()};b._onInputBlur=
function(){var a=h.activeElement;do if(e(a,"pika-single"))return;while(a=a.parentNode);b._c||(b._b=v(function(){b.hide()},50));b._c=!1};b._onClick=function(a){a=a||window.event;var d=a=a.target||a.srcElement;if(a){u||!e(a,"pika-select")||a.onchange||(a.setAttribute("onchange","return;"),r(a,"change",b._onChange));do if(e(d,"pika-single")||d===c.trigger)return;while(d=d.parentNode);b._v&&a!==c.trigger&&d!==c.trigger&&b.hide()}};b.el=h.createElement("div");b.el.className="pika-single"+(c.isRTL?" is-rtl":
"")+(c.theme?" "+c.theme:"");r(b.el,"mousedown",b._onMouseDown,!0);r(b.el,"touchend",b._onMouseDown,!0);r(b.el,"change",b._onChange);c.field&&(c.container?c.container.appendChild(b.el):c.bound?h.body.appendChild(b.el):c.field.parentNode.insertBefore(b.el,c.field.nextSibling),r(c.field,"change",b._onInputChange),c.defaultDate||(c.defaultDate=q&&c.field.value?m(c.field.value,c.format).toDate():new Date(Date.parse(c.field.value)),c.setDefaultDate=!0));a=c.defaultDate;k(a)?c.setDefaultDate?b.setDate(a,
!0):b.gotoDate(a):b.gotoDate(new Date);c.bound?(this.hide(),b.el.className+=" is-bound",r(c.trigger,"click",b._onInputClick),r(c.trigger,"focus",b._onInputFocus),r(c.trigger,"blur",b._onInputBlur)):this.show()};G.prototype={config:function(a){this._o||(this._o=w({},D,!0));a=w(this._o,a,!0);a.isRTL=!!a.isRTL;a.field=a.field&&a.field.nodeName?a.field:null;a.theme="string"===typeof a.theme&&a.theme?a.theme:null;a.bound=!!(void 0!==a.bound?a.field&&a.bound:a.field);a.trigger=a.trigger&&a.trigger.nodeName?
a.trigger:a.field;a.disableWeekends=!!a.disableWeekends;a.disableDayFn="function"===typeof a.disableDayFn?a.disableDayFn:null;var b=parseInt(a.numberOfMonths,10)||1;a.numberOfMonths=4<b?4:b;k(a.minDate)||(a.minDate=!1);k(a.maxDate)||(a.maxDate=!1);a.minDate&&a.maxDate&&a.maxDate<a.minDate&&(a.maxDate=a.minDate=!1);a.minDate&&this.setMinDate(a.minDate);a.maxDate&&(z(a.maxDate),a.maxYear=a.maxDate.getFullYear(),a.maxMonth=a.maxDate.getMonth());y(a.yearRange)?(b=(new Date).getFullYear()-10,a.yearRange[0]=
parseInt(a.yearRange[0],10)||b,a.yearRange[1]=parseInt(a.yearRange[1],10)||b):(a.yearRange=Math.abs(parseInt(a.yearRange,10))||D.yearRange,100<a.yearRange&&(a.yearRange=100));return a},toString:function(a){return k(this._d)?q?m(this._d).format(a||this._o.format):this._d.toDateString():""},getMoment:function(){return q?m(this._d):null},setMoment:function(a,b){q&&m.isMoment(a)&&this.setDate(a.toDate(),b)},getDate:function(){return k(this._d)?new Date(this._d.getTime()):null},setDate:function(a,b){if(!a)return this._d=
null,this._o.field&&(this._o.field.value="",B(this._o.field,"change",{firedBy:this})),this.draw();"string"===typeof a&&(a=new Date(Date.parse(a)));if(k(a)){var c=this._o.minDate,d=this._o.maxDate;k(c)&&a<c?a=c:k(d)&&a>d&&(a=d);this._d=new Date(a.getTime());z(this._d);this.gotoDate(this._d);this._o.field&&(this._o.field.value=this.toString(),B(this._o.field,"change",{firedBy:this}));b||"function"!==typeof this._o.onSelect||this._o.onSelect.call(this,this.getDate())}},gotoDate:function(a){var b=!0;
if(k(a)){if(this.calendars){b=new Date(this.calendars[0].year,this.calendars[0].month,1);var c=new Date(this.calendars[this.calendars.length-1].year,this.calendars[this.calendars.length-1].month,1),d=a.getTime();c.setMonth(c.getMonth()+1);c.setDate(c.getDate()-1);b=d<b.getTime()||c.getTime()<d}b&&(this.calendars=[{month:a.getMonth(),year:a.getFullYear()}],"right"===this._o.mainCalendar&&(this.calendars[0].month+=1-this._o.numberOfMonths));this.adjustCalendars()}},adjustCalendars:function(){this.calendars[0]=
C(this.calendars[0]);for(var a=1;a<this._o.numberOfMonths;a++)this.calendars[a]=C({month:this.calendars[0].month+a,year:this.calendars[0].year});this.draw()},gotoToday:function(){this.gotoDate(new Date)},gotoMonth:function(a){isNaN(a)||(this.calendars[0].month=parseInt(a,10),this.adjustCalendars())},nextMonth:function(){this.calendars[0].month++;this.adjustCalendars()},prevMonth:function(){this.calendars[0].month--;this.adjustCalendars()},gotoYear:function(a){isNaN(a)||(this.calendars[0].year=parseInt(a,
10),this.adjustCalendars())},setMinDate:function(a){z(a);this._o.minDate=a;this._o.minYear=a.getFullYear();this._o.minMonth=a.getMonth()},setMaxDate:function(a){this._o.maxDate=a},setStartRange:function(a){this._o.startRange=a},setEndRange:function(a){this._o.endRange=a},draw:function(a){if(this._v||a){var b=this._o,c=b.minYear,d=b.maxYear,p=b.minMonth,f=b.maxMonth;a="";this._y<=c&&(this._y=c,!isNaN(p)&&this._m<p&&(this._m=p));this._y>=d&&(this._y=d,!isNaN(f)&&this._m>f&&(this._m=f));for(c=0;c<b.numberOfMonths;c++)a+=
'<div class="pika-lendar">'+K(this,c,this.calendars[c].year,this.calendars[c].month,this.calendars[0].year)+this.render(this.calendars[c].year,this.calendars[c].month)+"</div>";this.el.innerHTML=a;b.bound&&"hidden"!==b.field.type&&v(function(){b.trigger.focus()},1);if("function"===typeof this._o.onDraw){var g=this;v(function(){g._o.onDraw.call(g)},0)}}},adjustPosition:function(){var a;if(!this._o.container){this.el.style.position="absolute";var b=a=this._o.trigger;var c=this.el.offsetWidth;var d=
this.el.offsetHeight;var p=window.innerWidth||h.documentElement.clientWidth;var f=window.innerHeight||h.documentElement.clientHeight;var g=window.pageYOffset||h.body.scrollTop||h.documentElement.scrollTop;if("function"===typeof a.getBoundingClientRect){b=a.getBoundingClientRect();var e=b.left+window.pageXOffset;var k=b.bottom+window.pageYOffset}else for(e=b.offsetLeft,k=b.offsetTop+b.offsetHeight;b=b.offsetParent;)e+=b.offsetLeft,k+=b.offsetTop;if(this._o.reposition&&e+c>p||-1<this._o.position.indexOf("right")&&
0<e-c+a.offsetWidth)e=e-c+a.offsetWidth;if(this._o.reposition&&k+d>f+g||-1<this._o.position.indexOf("top")&&0<k-d-a.offsetHeight)k=k-d-a.offsetHeight;this.el.style.left=e+"px";this.el.style.top=k+"px"}},render:function(a,b){var c=this._o,d=new Date;var e=[31,0===a%4&&0!==a%100||0===a%400?29:28,31,30,31,30,31,31,30,31,30,31][b];var f=(new Date(a,b,1)).getDay(),g=[],h=[];z(d);0<c.firstDay&&(f-=c.firstDay,0>f&&(f+=7));for(var m=e+f,l=m;7<l;)l-=7;m+=7-l;for(var q=l=0;l<m;l++){var n=new Date(a,b,1+(l-
f)),r=k(this._d)?A(n,this._d):!1,t=A(n,d),u=l<f||l>=e+f,v=c.startRange&&A(c.startRange,n),w=c.endRange&&A(c.endRange,n),y=c.startRange&&c.endRange&&c.startRange<n&&n<c.endRange,x;!(x=c.minDate&&n<c.minDate||c.maxDate&&n>c.maxDate)&&(x=c.disableWeekends)&&(x=n.getDay(),x=0===x||6===x);n=x||c.disableDayFn&&c.disableDayFn(n);h.push(H({day:1+(l-f),month:b,year:a,isSelected:r,isToday:t,isDisabled:n,isEmpty:u,isStartRange:v,isEndRange:w,isInRange:y}));7===++q&&(c.showWeekNumber&&h.unshift(I(l-f,b,a)),g.push(J(h,
c.isRTL)),h=[],q=0)}e=[];c.showWeekNumber&&e.push("<th></th>");for(d=0;7>d;d++)e.push('<th scope="col"><abbr title="'+E(c,d)+'">'+E(c,d,!0)+"</abbr></th>");return'<table cellpadding="0" cellspacing="0" class="pika-table">'+("<thead>"+(c.isRTL?e.reverse():e).join("")+"</thead>")+("<tbody>"+g.join("")+"</tbody>")+"</table>"},isVisible:function(){return this._v},show:function(){if(!this._v){var a=this.el;var b=(" "+a.className+" ").replace(" is-hidden "," ");b=b.trim?b.trim():b.replace(/^\s+|\s+$/g,
"");a.className=b;this._v=!0;this.draw();this._o.bound&&(r(h,"click",this._onClick),this.adjustPosition());"function"===typeof this._o.onOpen&&this._o.onOpen.call(this)}},hide:function(){var a=this._v;if(!1!==a){this._o.bound&&t(h,"click",this._onClick);this.el.style.position="static";this.el.style.left="auto";this.el.style.top="auto";var b=this.el;e(b,"is-hidden")||(b.className=""===b.className?"is-hidden":b.className+" is-hidden");this._v=!1;void 0!==a&&"function"===typeof this._o.onClose&&this._o.onClose.call(this)}},
destroy:function(){this.hide();t(this.el,"mousedown",this._onMouseDown,!0);t(this.el,"touchend",this._onMouseDown,!0);t(this.el,"change",this._onChange);this._o.field&&(t(this._o.field,"change",this._onInputChange),this._o.bound&&(t(this._o.trigger,"click",this._onInputClick),t(this._o.trigger,"focus",this._onInputFocus),t(this._o.trigger,"blur",this._onInputBlur)));this.el.parentNode&&this.el.parentNode.removeChild(this.el)}};return G});