!function(e,t,a,n){"use strict";t="undefined"!=typeof t&&t.Math==Math?t:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")(),e.fn.calendar=function(t){var o,r=e(this),i=r.selector||"",l=(new Date).getTime(),u=[],d=arguments[0],s="string"==typeof d,p=[].slice.call(arguments,1);return r.each(function(){var r,c,f=e.isPlainObject(t)?e.extend(!0,{},e.fn.calendar.settings,t):e.extend({},e.fn.calendar.settings),g=f.className,h=f.namespace,m=f.selector,y=f.formatter,v=f.parser,D=f.metadata,b=f.error,C="."+h,M="module-"+h,w=e(this),x=w.find(m.input),k=w.find(m.popup),T=w.find(m.activator),H=this,F=w.data(M),I=!1,N=!1;c={initialize:function(){c.debug("Initializing calendar for",H),r=c.get.isTouch(),c.setup.popup(),c.setup.inline(),c.setup.input(),c.setup.date(),c.create.calendar(),c.bind.events(),c.instantiate()},instantiate:function(){c.verbose("Storing instance of calendar"),F=c,w.data(M,F)},destroy:function(){c.verbose("Destroying previous calendar for",H),w.removeData(M),c.unbind.events()},setup:{popup:function(){if(!f.inline&&(T.length||(T=w.children().first(),T.length))){if(e.fn.popup===n)return void c.error(b.popup);k.length||(k=e("
").addClass(g.popup).prependTo(T.parent())),k.addClass(g.calendar);var t=f.onVisible,a=f.onHidden;x.length||(k.attr("tabindex","0"),t=function(){return c.focus(),f.onVisible.apply(k,arguments)},a=function(){return c.blur(),f.onHidden.apply(k,arguments)});var o=function(){return c.set.focusDate(c.get.date()),c.set.mode(f.startMode),f.onShow.apply(k,arguments)},r=f.on||(x.length?"focus":"click"),i=e.extend({},f.popupOptions,{popup:k,on:r,hoverable:"hover"===r,onShow:o,onVisible:t,onHide:f.onHide,onHidden:a});c.popup(i)}},inline:function(){T.length&&!f.inline||(k=e("").addClass(g.calendar).appendTo(w),x.length||k.attr("tabindex","0"))},input:function(){f.touchReadonly&&x.length&&r&&x.prop("readonly",!0)},date:function(){if(x.length){var e=x.val(),t=v.date(e,f);c.set.date(t,f.formatInput,!1)}}},create:{calendar:function(){var t,a,n,o,r,i=c.get.mode(),l=new Date,u=c.get.date(),d=c.get.focusDate(),s=d||u||f.initialDate||l;s=c.helper.dateInRange(s),d||(d=s,c.set.focusDate(d,!1,!1));var p=s.getMinutes(),h=s.getHours(),m=s.getDate(),v=s.getMonth(),b=s.getFullYear(),C="year"===i,M="month"===i,w="day"===i,x="hour"===i,T="minute"===i,H="time"===f.type,F=w?7:x?4:3,I=7===F?"seven":4===F?"four":"three",N=w||x?6:4,O=(new Date(b,v,1).getDay()-f.firstDayOfWeek%7+7)%7;if(!f.constantHeight&&w){var Y=new Date(b,v+1,0).getDate()+O;N=Math.ceil(Y/7)}var E=C?10:M?1:0,R=w?1:0,A=x||T?1:0,S=x||T?m:1,j=new Date(b-E,v-R,S-A,h),V=new Date(b+E,v+R,S+A,h),P=C?new Date(10*Math.ceil(b/10)-9,0,0):M?new Date(b,0,0):w?new Date(b,v,0):new Date(b,v,m,(-1)),q=C?new Date(10*Math.ceil(b/10)+1,0,1):M?new Date(b+1,0,1):w?new Date(b,v+1,1):new Date(b,v,m+1),J=e("").addClass(g.table).addClass(I+" column").addClass(i);if(!H){var K=e("").appendTo(J);o=e("
").appendTo(K),r=e(" | ").attr("colspan",""+F).appendTo(o);var W=e("").addClass(g.link).appendTo(r);W.text(y.header(s,i,f));var z=M?f.disableYear?"day":"year":w?f.disableMonth?"year":"month":"day";W.data(D.mode,z);var L=e("").addClass(g.prev).appendTo(r);L.data(D.focusDate,j),L.toggleClass(g.disabledCell,!c.helper.isDateInRange(P,i)),e("").addClass(g.prevIcon).appendTo(L);var B=e("").addClass(g.next).appendTo(r);if(B.data(D.focusDate,V),B.toggleClass(g.disabledCell,!c.helper.isDateInRange(q,i)),e("").addClass(g.nextIcon).appendTo(B),w)for(o=e("
").appendTo(K),t=0;t").appendTo(o),r.text(y.dayColumnHeader((t+f.firstDayOfWeek)%7,f))}var U=e("").appendTo(J);for(t=C?10*Math.ceil(b/10)-9:w?1-O:0,a=0;a").appendTo(U),n=0;n").addClass(g.cell).appendTo(o),r.text(Z),r.data(D.date,Q);var G=w&&Q.getMonth()!==v,X=G||!c.helper.isDateInRange(Q,i),$=c.helper.dateEqual(Q,u,i);r.toggleClass(g.adjacentCell,G),r.toggleClass(g.disabledCell,X),r.toggleClass(g.activeCell,$),x||T||r.toggleClass(g.todayCell,c.helper.dateEqual(Q,l,i)),c.helper.dateEqual(Q,d,i)&&c.set.focusDate(Q,!1,!1)}if(f.today){var _=e("
").appendTo(U),ee=e(" | ").attr("colspan",""+F).addClass(g.today).appendTo(_);ee.text(y.today(f)),ee.data(D.date,l)}c.update.focus(!1,J),k.empty(),J.appendTo(k)}},update:{focus:function(t,a){a=a||k;var n=c.get.mode(),o=c.get.date(),i=c.get.focusDate(),l=c.get.startDate(),u=c.get.endDate(),d=(t?i:null)||o||(r?null:i);a.find("td").each(function(){var t=e(this),a=t.data(D.date);if(a){var o=t.hasClass(g.disabledCell),s=t.hasClass(g.activeCell),p=c.helper.dateEqual(a,i,n),f=!!d&&(!!l&&c.helper.isDateInRange(a,n,l,d)||!!u&&c.helper.isDateInRange(a,n,d,u));t.toggleClass(g.focusCell,p&&(!r||I)),t.toggleClass(g.rangeCell,f&&!s&&!o)}})}},refresh:function(){c.create.calendar()},bind:{events:function(){k.on("mousedown"+C,c.event.mousedown),k.on("touchstart"+C,c.event.mousedown),k.on("mouseup"+C,c.event.mouseup),k.on("touchend"+C,c.event.mouseup),k.on("mouseover"+C,c.event.mouseover),x.length?(x.on("input"+C,c.event.inputChange),x.on("focus"+C,c.event.inputFocus),x.on("blur"+C,c.event.inputBlur),x.on("click"+C,c.event.inputClick),x.on("keydown"+C,c.event.keydown)):k.on("keydown"+C,c.event.keydown)}},unbind:{events:function(){k.off(C),x.length&&x.off(C)}},event:{mouseover:function(t){var a=e(t.target),n=a.data(D.date),o=1===t.buttons;n&&c.set.focusDate(n,!1,!0,o)},mousedown:function(t){x.length&&t.preventDefault(),I=t.type.indexOf("touch")>=0;var a=e(t.target),n=a.data(D.date);n&&c.set.focusDate(n,!1,!0,!0)},mouseup:function(t){c.focus(),t.preventDefault(),t.stopPropagation(),I=!1;var a=e(t.target),n=a.parent();(n.data(D.date)||n.data(D.focusDate)||n.data(D.mode))&&(a=n);var o=a.data(D.date),r=a.data(D.focusDate),i=a.data(D.mode);if(o){var l=a.hasClass(g.today);c.selectDate(o,l)}else r?c.set.focusDate(r):i&&c.set.mode(i)},keydown:function(e){if(27!==e.keyCode&&9!==e.keyCode||c.popup("hide"),c.popup("is visible"))if(37===e.keyCode||38===e.keyCode||39===e.keyCode||40===e.keyCode){var t=c.get.mode(),a="day"===t?7:"hour"===t?4:3,n=37===e.keyCode?-1:38===e.keyCode?-a:39==e.keyCode?1:a;n*="minute"===t?5:1;var o=c.get.focusDate()||c.get.date()||new Date,r=o.getFullYear()+("year"===t?n:0),i=o.getMonth()+("month"===t?n:0),l=o.getDate()+("day"===t?n:0),u=o.getHours()+("hour"===t?n:0),d=o.getMinutes()+("minute"===t?n:0),s=new Date(r,i,l,u,d);"time"===f.type&&(s=c.helper.mergeDateTime(o,s)),c.helper.isDateInRange(s,t)&&c.set.focusDate(s)}else if(13===e.keyCode){var p=c.get.focusDate();p&&c.selectDate(p)}38!==e.keyCode&&40!==e.keyCode||(e.preventDefault(),c.popup("show"))},inputChange:function(){var e=x.val(),t=v.date(e,f);c.set.date(t,!1)},inputFocus:function(){k.addClass(g.active)},inputBlur:function(){if(k.removeClass(g.active),f.formatInput){var e=c.get.date(),t=y.datetime(e,f);x.val(t)}},inputClick:function(){c.popup("show")}},get:{date:function(){return w.data(D.date)||null},focusDate:function(){return w.data(D.focusDate)||null},startDate:function(){var e=c.get.calendarModule(f.startCalendar);return(e?e.get.date():w.data(D.startDate))||null},endDate:function(){var e=c.get.calendarModule(f.endCalendar);return(e?e.get.date():w.data(D.endDate))||null},mode:function(){var t=w.data(D.mode)||f.startMode,a=c.get.validModes();return e.inArray(t,a)>=0?t:"time"===f.type?"hour":"month"===f.type?"month":"year"===f.type?"year":"day"},validModes:function(){var e=[];return"time"!==f.type&&(f.disableYear&&"year"!==f.type||e.push("year"),(!f.disableMonth&&"year"!==f.type||"month"===f.type)&&e.push("month"),f.type.indexOf("date")>=0&&e.push("day")),f.type.indexOf("time")>=0&&(e.push("hour"),f.disableMinute||e.push("minute")),e},isTouch:function(){try{return a.createEvent("TouchEvent"),!0}catch(e){return!1}},calendarModule:function(t){return t?(t instanceof e||(t=w.parent().children(t).first()),t.data(M)):null}},set:{date:function(e,t,a){t=t!==!1,a=a!==!1,e=c.helper.sanitiseDate(e),e=c.helper.dateInRange(e);var o=y.datetime(e,f);if(a&&f.onChange.call(H,e,o)===!1)return!1;var r=c.get.endDate();r&&e&&e>r&&c.set.endDate(n),c.set.dataKeyValue(D.date,e),c.set.focusDate(e),t&&x.length&&x.val(o)},startDate:function(e,t){e=c.helper.sanitiseDate(e);var a=c.get.calendarModule(f.startCalendar);a&&a.set.date(e),c.set.dataKeyValue(D.startDate,e,t)},endDate:function(e,t){e=c.helper.sanitiseDate(e);var a=c.get.calendarModule(f.endCalendar);a&&a.set.date(e),c.set.dataKeyValue(D.endDate,e,t)},focusDate:function(e,t,a,n){e=c.helper.sanitiseDate(e),e=c.helper.dateInRange(e);var o=c.set.dataKeyValue(D.focusDate,e,t);a=a!==!1&&o&&t===!1||N!=n,N=n,a&&c.update.focus(n)},mode:function(e,t){c.set.dataKeyValue(D.mode,e,t)},dataKeyValue:function(e,t,a){var n=w.data(e),o=n===t||n<=t&&n>=t;return t?w.data(e,t):w.removeData(e),a=a!==!1&&!o,a&&c.create.calendar(),!o}},selectDate:function(e,t){var a=c.get.mode(),n=t||"minute"===a||f.disableMinute&&"hour"===a||"date"===f.type&&"day"===a||"month"===f.type&&"month"===a||"year"===f.type&&"year"===a;if(n){var o=c.set.date(e)===!1;if(!o&&f.closable){c.popup("hide");var r=c.get.calendarModule(f.endCalendar);r&&(r.popup("show"),r.focus())}}else{var i="year"===a?f.disableMonth?"day":"month":"month"===a?"day":"day"===a?"hour":"minute";c.set.mode(i),"hour"===a||"day"===a&&c.get.date()?c.set.date(e):c.set.focusDate(e)}},changeDate:function(e){c.set.date(e)},clear:function(){c.set.date(n)},popup:function(){return T.popup.apply(T,arguments)},focus:function(){x.length?x.focus():k.focus()},blur:function(){x.length?x.blur():k.blur()},helper:{sanitiseDate:function(e){return e?(e instanceof Date||(e=v.date(""+e,f)),isNaN(e.getTime())?n:e):n},dateDiff:function(e,t,a){a=a||"day";var n="time"===f.type,o="year"===a,r=o||"month"===a,i="minute"===a,l=i||"hour"===a;return e=new Date(n?2e3:e.getFullYear(),n?0:o?0:e.getMonth(),n?1:r?1:e.getDate(),l?e.getHours():0,i?5*Math.floor(e.getMinutes()/5):0),t=new Date(n?2e3:t.getFullYear(),n?0:o?0:t.getMonth(),n?1:r?1:t.getDate(),l?t.getHours():0,i?5*Math.floor(t.getMinutes()/5):0),t.getTime()-e.getTime()},dateEqual:function(e,t,a){return!!e&&!!t&&0===c.helper.dateDiff(e,t,a)},isDateInRange:function(e,t,a,n){if(!a&&!n){var o=c.get.startDate();a=o&&f.minDate?new Date(Math.max(o,f.minDate)):o||f.minDate,n=f.maxDate}return a=a&&new Date(a.getFullYear(),a.getMonth(),a.getDate(),a.getHours(),5*Math.ceil(a.getMinutes()/5)),!(!e||a&&c.helper.dateDiff(e,a,t)>0||n&&c.helper.dateDiff(n,e,t)>0)},dateInRange:function(e,t,a){if(!t&&!a){var n=c.get.startDate();t=n&&f.minDate?new Date(Math.max(n,f.minDate)):n||f.minDate,a=f.maxDate}t=t&&new Date(t.getFullYear(),t.getMonth(),t.getDate(),t.getHours(),5*Math.ceil(t.getMinutes()/5));var o="time"===f.type;return e?t&&c.helper.dateDiff(e,t,"minute")>0?o?c.helper.mergeDateTime(e,t):t:a&&c.helper.dateDiff(a,e,"minute")>0?o?c.helper.mergeDateTime(e,a):a:e:e},mergeDateTime:function(e,t){return e&&t?new Date(e.getFullYear(),e.getMonth(),e.getDate(),t.getHours(),t.getMinutes()):t}},setting:function(t,a){if(c.debug("Changing setting",t,a),e.isPlainObject(t))e.extend(!0,f,t);else{if(a===n)return f[t];e.isPlainObject(f[t])?e.extend(!0,f[t],a):f[t]=a}},internal:function(t,a){return c.debug("Changing internal",t,a),a===n?c[t]:void(e.isPlainObject(t)?e.extend(!0,c,t):c[t]=a)},debug:function(){!f.silent&&f.debug&&(f.performance?c.performance.log(arguments):(c.debug=Function.prototype.bind.call(console.info,console,f.name+":"),c.debug.apply(console,arguments)))},verbose:function(){!f.silent&&f.verbose&&f.debug&&(f.performance?c.performance.log(arguments):(c.verbose=Function.prototype.bind.call(console.info,console,f.name+":"),c.verbose.apply(console,arguments)))},error:function(){f.silent||(c.error=Function.prototype.bind.call(console.error,console,f.name+":"),c.error.apply(console,arguments))},performance:{log:function(e){var t,a,n;f.performance&&(t=(new Date).getTime(),n=l||t,a=t-n,l=t,u.push({Name:e[0],Arguments:[].slice.call(e,1)||"",Element:H,"Execution Time":a})),clearTimeout(c.performance.timer),c.performance.timer=setTimeout(c.performance.display,500)},display:function(){var t=f.name+":",a=0;l=!1,clearTimeout(c.performance.timer),e.each(u,function(e,t){a+=t["Execution Time"]}),t+=" "+a+"ms",i&&(t+=" '"+i+"'"),(console.group!==n||console.table!==n)&&u.length>0&&(console.groupCollapsed(t),console.table?console.table(u):e.each(u,function(e,t){console.log(t.Name+": "+t["Execution Time"]+"ms")}),console.groupEnd()),u=[]}},invoke:function(t,a,r){var i,l,u,d=F;return a=a||p,r=H||r,"string"==typeof t&&d!==n&&(t=t.split(/[\. ]/),i=t.length-1,e.each(t,function(a,o){var r=a!=i?o+t[a+1].charAt(0).toUpperCase()+t[a+1].slice(1):t;if(e.isPlainObject(d[r])&&a!=i)d=d[r];else{if(d[r]!==n)return l=d[r],!1;if(!e.isPlainObject(d[o])||a==i)return d[o]!==n?(l=d[o],!1):(c.error(b.method,t),!1);d=d[o]}})),e.isFunction(l)?u=l.apply(r,a):l!==n&&(u=l),e.isArray(o)?o.push(u):o!==n?o=[o,u]:u!==n&&(o=u),l}},s?(F===n&&c.initialize(),c.invoke(d)):(F!==n&&F.invoke("destroy"),c.initialize())}),o!==n?o:r},e.fn.calendar.settings={name:"Calendar",namespace:"calendar",silent:!1,debug:!1,verbose:!1,performance:!1,type:"datetime",firstDayOfWeek:0,constantHeight:!0,today:!1,closable:!0,monthFirst:!0,touchReadonly:!0,inline:!1,on:null,initialDate:null,startMode:!1,minDate:null,maxDate:null,ampm:!0,disableYear:!1,disableMonth:!1,disableMinute:!1,formatInput:!0,startCalendar:null,endCalendar:null,popupOptions:{position:"bottom left",lastResort:"bottom left",prefer:"opposite",hideOnScroll:!1},text:{days:["S","M","T","W","T","F","S"],months:["January","February","March","April","May","June","July","August","September","October","November","December"],monthsShort:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],today:"Today",now:"Now",am:"AM",pm:"PM"},formatter:{header:function(e,t,a){return"year"===t?a.formatter.yearHeader(e,a):"month"===t?a.formatter.monthHeader(e,a):"day"===t?a.formatter.dayHeader(e,a):"hour"===t?a.formatter.hourHeader(e,a):a.formatter.minuteHeader(e,a)},yearHeader:function(e,t){var a=10*Math.ceil(e.getFullYear()/10);return a-9+" - "+(a+2)},monthHeader:function(e,t){return e.getFullYear()},dayHeader:function(e,t){var a=t.text.months[e.getMonth()],n=e.getFullYear();return a+" "+n},hourHeader:function(e,t){return t.formatter.date(e,t)},minuteHeader:function(e,t){return t.formatter.date(e,t)},dayColumnHeader:function(e,t){return t.text.days[e]},datetime:function(e,t){if(!e)return"";var a="time"===t.type?"":t.formatter.date(e,t),n=t.type.indexOf("time")<0?"":t.formatter.time(e,t,!1),o="datetime"===t.type?" ":"";return a+o+n},date:function(e,t){if(!e)return"";var a=e.getDate(),n=t.text.months[e.getMonth()],o=e.getFullYear();return"year"===t.type?o:"month"===t.type?n+" "+o:(t.monthFirst?n+" "+a:a+" "+n)+", "+o},time:function(e,t,a){if(!e)return"";var n=e.getHours(),o=e.getMinutes(),r="";return t.ampm&&(r=" "+(n<12?t.text.am:t.text.pm),n=0===n?12:n>12?n-12:n),n+":"+(o<10?"0":"")+o+r},today:function(e){return"date"===e.type?e.text.today:e.text.now}},parser:{date:function(t,a){if(!t)return null;if(t=(""+t).trim().toLowerCase(),0===t.length)return null;var o,r,i,l=-1,u=-1,d=-1,s=-1,p=-1,c=n,f="time"===a.type,g=a.type.indexOf("time")<0,h=t.split(a.regExp.dateWords),m=t.split(a.regExp.dateNumbers);if(!g)for(c=e.inArray(a.text.am.toLowerCase(),h)>=0||!(e.inArray(a.text.pm.toLowerCase(),h)>=0)&&n,o=0;o=0){if(u<0||l<0){var v=y.split(":");for(i=0;i=0)break}}for(o=0;o59){p=r,m.splice(o,1);break}if(s<0)for(o=0;o1||a.monthFirst?o:1===o?0:1,r=parseInt(m[i]),!isNaN(r)&&1<=r&&r<=12){s=r,m.splice(i,1);break}for(o=0;o=0;o--)if(r=parseInt(m[o]),!isNaN(r)){r<99&&(r+=2e3),p=r,m.splice(o,1);break}}if(!g){if(u<0)for(o=0;o