text: ﻿/* http://keith-wood.name/calendars.html
     Calendars date picker for jQuery v2.0.0.
     Written by Keith Wood (kbwood{at}iinet.com.au) August 2009.
     Available under the MIT (https://github.com/jquery/jquery/blob/master/MIT-LICENSE.txt) license. 
     Please attribute the author if you use it. */
  (function($){var F='calendarsPicker';$.JQPlugin.createPlugin({name:F,defaultRenderer:{picker:'<div class="calendars">'+'<div class="calendars-nav">{link:prev}{link:today}{link:next}</div>{months}'+'{popup:start}<div class="calendars-ctrl">{link:clear}{link:close}</div>{popup:end}'+'<div class="calendars-clear-fix"></div></div>',monthRow:'<div class="calendars-month-row">{months}</div>',month:'<div class="calendars-month"><div class="calendars-month-header">{monthHeader}</div>'+'<table><thead>{weekHeader}</thead><tbody>{weeks}</tbody></table></div>',weekHeader:'<tr>{days}</tr>',dayHeader:'<th>{day}</th>',week:'<tr>{days}</tr>',day:'<td>{day}</td>',monthSelector:'.calendars-month',daySelector:'td',rtlClass:'calendars-rtl',multiClass:'calendars-multi',defaultClass:'',selectedClass:'calendars-selected',highlightedClass:'calendars-highlight',todayClass:'calendars-today',otherMonthClass:'calendars-other-month',weekendClass:'calendars-weekend',commandClass:'calendars-cmd',commandButtonClass:'',commandLinkClass:'',disabledClass:'calendars-disabled'},commands:{prev:{text:'prevText',status:'prevStatus',keystroke:{keyCode:33},enabled:function(a){var b=a.curMinDate();return(!b||a.drawDate.newDate().add(1-a.options.monthsToStep-a.options.monthsOffset,'m').day(a.options.calendar.minDay).add(-1,'d').compareTo(b)!==-1)},date:function(a){return a.drawDate.newDate().add(-a.options.monthsToStep-a.options.monthsOffset,'m').day(a.options.calendar.minDay)},action:function(a){G.changeMonth(this,-a.options.monthsToStep)}},prevJump:{text:'prevJumpText',status:'prevJumpStatus',keystroke:{keyCode:33,ctrlKey:true},enabled:function(a){var b=a.curMinDate();return(!b||a.drawDate.newDate().add(1-a.options.monthsToJump-a.options.monthsOffset,'m').day(a.options.calendar.minDay).add(-1,'d').compareTo(b)!==-1)},date:function(a){return a.drawDate.newDate().add(-a.options.monthsToJump-a.options.monthsOffset,'m').day(a.options.calendar.minDay)},action:function(a){G.changeMonth(this,-a.options.monthsToJump)}},next:{text:'nextText',status:'nextStatus',keystroke:{keyCode:34},enabled:function(a){var b=a.get('maxDate');return(!b||a.drawDate.newDate().add(a.options.monthsToStep-a.options.monthsOffset,'m').day(a.options.calendar.minDay).compareTo(b)!==+1)},date:function(a){return a.drawDate.newDate().add(a.options.monthsToStep-a.options.monthsOffset,'m').day(a.options.calendar.minDay)},action:function(a){G.changeMonth(this,a.options.monthsToStep)}},nextJump:{text:'nextJumpText',status:'nextJumpStatus',keystroke:{keyCode:34,ctrlKey:true},enabled:function(a){var b=a.get('maxDate');return(!b||a.drawDate.newDate().add(a.options.monthsToJump-a.options.monthsOffset,'m').day(a.options.calendar.minDay).compareTo(b)!==+1)},date:function(a){return a.drawDate.newDate().add(a.options.monthsToJump-a.options.monthsOffset,'m').day(a.options.calendar.minDay)},action:function(a){G.changeMonth(this,a.options.monthsToJump)}},current:{text:'currentText',status:'currentStatus',keystroke:{keyCode:36,ctrlKey:true},enabled:function(a){var b=a.curMinDate();var c=a.get('maxDate');var d=a.selectedDates[0]||a.options.calendar.today();return(!b||d.compareTo(b)!==-1)&&(!c||d.compareTo(c)!==+1)},date:function(a){return a.selectedDates[0]||a.options.calendar.today()},action:function(a){var b=a.selectedDates[0]||a.options.calendar.today();G.showMonth(this,b.year(),b.month())}},today:{text:'todayText',status:'todayStatus',keystroke:{keyCode:36,ctrlKey:true},enabled:function(a){var b=a.curMinDate();var c=a.get('maxDate');return(!b||a.options.calendar.today().compareTo(b)!==-1)&&(!c||a.options.calendar.today().compareTo(c)!==+1)},date:function(a){return a.options.calendar.today()},action:function(a){G.showMonth(this)}},clear:{text:'clearText',status:'clearStatus',keystroke:{keyCode:35,ctrlKey:true},enabled:function(a){return true},date:function(a){return null},action:function(a){G.clear(this)}},close:{text:'closeText',status:'closeStatus',keystroke:{keyCode:27},enabled:function(a){return true},date:function(a){return null},action:function(a){G.hide(this)}},prevWeek:{text:'prevWeekText',status:'prevWeekStatus',keystroke:{keyCode:38,ctrlKey:true},enabled:function(a){var b=a.curMinDate();return(!b||a.drawDate.newDate().add(-a.options.calendar.daysInWeek(),'d').compareTo(b)!==-1)},date:function(a){return a.drawDate.newDate().add(-a.options.calendar.daysInWeek(),'d')},action:function(a){G.changeDay(this,-a.options.calendar.daysInWeek())}},prevDay:{text:'prevDayText',status:'prevDayStatus',keystroke:{keyCode:37,ctrlKey:true},enabled:function(a){var b=a.curMinDate();return(!b||a.drawDate.newDate().add(-1,'d').compareTo(b)!==-1)},date:function(a){return a.drawDate.newDate().add(-1,'d')},action:function(a){G.changeDay(this,-1)}},nextDay:{text:'nextDayText',status:'nextDayStatus',keystroke:{keyCode:39,ctrlKey:true},enabled:function(a){var b=a.get('maxDate');return(!b||a.drawDate.newDate().add(1,'d').compareTo(b)!==+1)},date:function(a){return a.drawDate.newDate().add(1,'d')},action:function(a){G.changeDay(this,1)}},nextWeek:{text:'nextWeekText',status:'nextWeekStatus',keystroke:{keyCode:40,ctrlKey:true},enabled:function(a){var b=a.get('maxDate');return(!b||a.drawDate.newDate().add(a.options.calendar.daysInWeek(),'d').compareTo(b)!==+1)},date:function(a){return a.drawDate.newDate().add(a.options.calendar.daysInWeek(),'d')},action:function(a){G.changeDay(this,a.options.calendar.daysInWeek())}}},defaultOptions:{calendar:$.calendars.instance(),pickerClass:'',showOnFocus:true,showTrigger:null,showAnim:'show',showOptions:{},showSpeed:'normal',popupContainer:null,alignment:'bottom',fixedWeeks:false,firstDay:null,calculateWeek:null,monthsToShow:1,monthsOffset:0,monthsToStep:1,monthsToJump:12,useMouseWheel:true,changeMonth:true,yearRange:'c-10:c+10',showOtherMonths:false,selectOtherMonths:false,defaultDate:null,selectDefaultDate:false,minDate:null,maxDate:null,dateFormat:null,autoSize:false,rangeSelect:false,rangeSeparator:' - ',multiSelect:0,multiSeparator:',',onDate:null,onShow:null,onChangeMonthYear:null,onSelect:null,onClose:null,altField:null,altFormat:null,constrainInput:true,commandsAsDateFormat:false,commands:{}},regionalOptions:{'':{renderer:{},prevText:'&lt;Prev',prevStatus:'Show the previous month',prevJumpText:'&lt;&lt;',prevJumpStatus:'Show the previous year',nextText:'Next&gt;',nextStatus:'Show the next month',nextJumpText:'&gt;&gt;',nextJumpStatus:'Show the next year',currentText:'Current',currentStatus:'Show the current month',todayText:'Today',todayStatus:'Show today\'s month',clearText:'Clear',clearStatus:'Clear all the dates',closeText:'Close',closeStatus:'Close the datepicker',yearStatus:'Change the year',monthStatus:'Change the month',weekText:'Wk',weekStatus:'Week of the year',dayStatus:'Select DD, M d, yyyy',defaultStatus:'Select a date',isRTL:false}},_getters:['getDate','isDisabled','isSelectable','retrieveDate'],_disabled:[],_popupClass:'calendars-popup',_triggerClass:'calendars-trigger',_disableClass:'calendars-disable',_monthYearClass:'calendars-month-year',_curMonthClass:'calendars-month-',_anyYearClass:'calendars-any-year',_curDoWClass:'calendars-dow-',_init:function(){this.defaultOptions.commands=this.commands;this.regionalOptions[''].renderer=this.defaultRenderer;this._super()},_instSettings:function(b,c){return{selectedDates:[],drawDate:null,pickingRange:false,inline:($.inArray(b[0].nodeName.toLowerCase(),['div','span'])>-1),get:function(a){if($.inArray(a,['defaultDate','minDate','maxDate'])>-1){return this.options.calendar.determineDate(this.options[a],null,this.selectedDates[0],this.get('dateFormat'),this.getConfig())}if(a==='dateFormat'){return this.options.dateFormat||this.options.calendar.local.dateFormat}return this.options[a]},curMinDate:function(){return(this.pickingRange?this.selectedDates[0]:this.get('minDate'))},getConfig:function(){return{dayNamesShort:this.options.dayNamesShort,dayNames:this.options.dayNames,monthNamesShort:this.options.monthNamesShort,monthNames:this.options.monthNames,calculateWeek:this.options.calculateWeek,shortYearCutoff:this.options.shortYearCutoff}}}},_postAttach:function(a,b){if(b.inline){b.drawDate=G._checkMinMax((b.selectedDates[0]||b.get('defaultDate')||b.options.calendar.today()).newDate(),b);b.prevDate=b.drawDate.newDate();this._update(a[0]);if($.fn.mousewheel){a.mousewheel(this._doMouseWheel)}}else{this._attachments(a,b);a.on('keydown.'+b.name,this._keyDown).on('keypress.'+b.name,this._keyPress).on('keyup.'+b.name,this._keyUp);if(a.attr('disabled')){this.disable(a[0])}}},_optionsChanged:function(b,c,d){if(d.calendar&&d.calendar!==c.options.calendar){var e=function(a){return(typeof c.options[a]==='object'?null:c.options[a])};d=$.extend({defaultDate:e('defaultDate'),minDate:e('minDate'),maxDate:e('maxDate')},d);c.selectedDates=[];c.drawDate=null}var f=c.selectedDates;$.extend(c.options,d);this.setDate(b[0],f,null,false,true);c.pickingRange=false;var g=c.options.calendar;var h=c.get('defaultDate');c.drawDate=this._checkMinMax((h?h:c.drawDate)||h||g.today(),c).newDate();if(!c.inline){this._attachments(b,c)}if(c.inline||c.div){this._update(b[0])}},_attachments:function(a,b){a.off('focus.'+b.name);if(b.options.showOnFocus){a.on('focus.'+b.name,this.show)}if(b.trigger){b.trigger.remove()}var c=b.options.showTrigger;b.trigger=(!c?$([]):$(c).clone().removeAttr('id').addClass(this._triggerClass)[b.options.isRTL?'insertBefore':'insertAfter'](a).click(function(){if(!G.isDisabled(a[0])){G[G.curInst===b?'hide':'show'](a[0])}}));this._autoSize(a,b);var d=this._extractDates(b,a.val());if(d){this.setDate(a[0],d,null,true)}var e=b.get('defaultDate');if(b.options.selectDefaultDate&&e&&b.selectedDates.length===0){this.setDate(a[0],(e||b.options.calendar.today()).newDate())}},_autoSize:function(d,e){if(e.options.autoSize&&!e.inline){var f=e.options.calendar;var g=f.newDate(2009,10,20);var h=e.get('dateFormat');if(h.match(/[DM]/)){var j=function(a){var b=0;var c=0;for(var i=0;i<a.length;i++){if(a[i].length>b){b=a[i].length;c=i}}return c};g.month(j(f.local[h.match(/MM/)?'monthNames':'monthNamesShort'])+1);g.day(j(f.local[h.match(/DD/)?'dayNames':'dayNamesShort'])+20-g.dayOfWeek())}e.elem.attr('size',g.formatDate(h).length)}},_preDestroy:function(a,b){if(b.trigger){b.trigger.remove()}a.empty().off('.'+b.name);if(b.inline&&$.fn.mousewheel){a.unmousewheel()}if(!b.inline&&b.options.autoSize){a.removeAttr('size')}},multipleEvents:function(b){var c=arguments;return function(a){for(var i=0;i<c.length;i++){c[i].apply(this,arguments)}}},enable:function(b){b=$(b);if(!b.hasClass(this._getMarker())){return}var c=this._getInst(b);if(c.inline){b.children('.'+this._disableClass).remove().end().find('button,select').prop('disabled',false).end().find('a').attr('href','javascript:void(0)')}else{b.prop('disabled',false);c.trigger.filter('button.'+this._triggerClass).prop('disabled',false).end().filter('img.'+this._triggerClass).css({opacity:'1.0',cursor:''})}this._disabled=$.map(this._disabled,function(a){return(a===b[0]?null:a)})},disable:function(b){b=$(b);if(!b.hasClass(this._getMarker())){return}var c=this._getInst(b);if(c.inline){var d=b.children(':last');var e=d.offset();var f={left:0,top:0};d.parents().each(function(){if($(this).css('position')==='relative'){f=$(this).offset();return false}});var g=b.css('zIndex');g=(g==='auto'?0:parseInt(g,10))+1;b.prepend('<div class="'+this._disableClass+'" style="'+'width: '+d.outerWidth()+'px; height: '+d.outerHeight()+'px; left: '+(e.left-f.left)+'px; top: '+(e.top-f.top)+'px; z-index: '+g+'"></div>').find('button,select').prop('disabled',true).end().find('a').removeAttr('href')}else{b.prop('disabled',true);c.trigger.filter('button.'+this._triggerClass).prop('disabled',true).end().filter('img.'+this._triggerClass).css({opacity:'0.5',cursor:'default'})}this._disabled=$.map(this._disabled,function(a){return(a===b[0]?null:a)});this._disabled.push(b[0])},isDisabled:function(a){return(a&&$.inArray(a,this._disabled)>-1)},show:function(a){a=$(a.target||a);var b=G._getInst(a);if(G.curInst===b){return}if(G.curInst){G.hide(G.curInst,true)}if(!$.isEmptyObject(b)){b.lastVal=null;b.selectedDates=G._extractDates(b,a.val());b.pickingRange=false;b.drawDate=G._checkMinMax((b.selectedDates[0]||b.get('defaultDate')||b.options.calendar.today()).newDate(),b);b.prevDate=b.drawDate.newDate();G.curInst=b;G._update(a[0],true);var c=G._checkOffset(b);b.div.css({left:c.left,top:c.top});var d=b.options.showAnim;var e=b.options.showSpeed;e=(e==='normal'&&$.ui&&parseInt($.ui.version.substring(2))>=8?'_default':e);if($.effects&&($.effects[d]||($.effects.effect&&$.effects.effect[d]))){var f=b.div.data();for(var g in f){if(g.match(/^ec\.storage\./)){f[g]=b._mainDiv.css(g.replace(/ec\.storage\./,''))}}b.div.data(f).show(d,b.options.showOptions,e)}else{b.div[d||'show'](d?e:0)}}},_extractDates:function(a,b){if(b===a.lastVal){return}a.lastVal=b;b=b.split(a.options.multiSelect?a.options.multiSeparator:(a.options.rangeSelect?a.options.rangeSeparator:'\x00'));var c=[];for(var i=0;i<b.length;i++){try{var d=a.options.calendar.parseDate(a.get('dateFormat'),b[i]);if(d){var f=false;for(var j=0;j<c.length;j++){if(c[j].compareTo(d)===0){f=true;break}}if(!f){c.push(d)}}}catch(e){}}c.splice(a.options.multiSelect||(a.options.rangeSelect?2:1),c.length);if(a.options.rangeSelect&&c.length===1){c[1]=c[0]}return c},_update:function(a,b){a=$(a.target||a);var c=G._getInst(a);if(!$.isEmptyObject(c)){if(c.inline||G.curInst===c){if($.isFunction(c.options.onChangeMonthYear)&&(!c.prevDate||c.prevDate.year()!==c.drawDate.year()||c.prevDate.month()!==c.drawDate.month())){c.options.onChangeMonthYear.apply(a[0],[c.drawDate.year(),c.drawDate.month()])}}if(c.inline){a.html(this._generateContent(a[0],c))}else if(G.curInst===c){if(!c.div){c.div=$('<div></div>').addClass(this._popupClass).css({display:(b?'none':'static'),position:'absolute',left:a.offset().left,top:a.offset().top+a.outerHeight()}).appendTo($(c.options.popupContainer||'body'));if($.fn.mousewheel){c.div.mousewheel(this._doMouseWheel)}}c.div.html(this._generateContent(a[0],c));a.focus()}}},_updateInput:function(a,b){var c=this._getInst(a);if(!$.isEmptyObject(c)){var d='';var e='';var f=(c.options.multiSelect?c.options.multiSeparator:c.options.rangeSeparator);var g=c.options.calendar;var h=c.get('dateFormat');var j=c.options.altFormat||h;for(var i=0;i<c.selectedDates.length;i++){d+=(b?'':(i>0?f:'')+g.formatDate(h,c.selectedDates[i]));e+=(i>0?f:'')+g.formatDate(j,c.selectedDates[i])}if(!c.inline&&!b){$(a).val(d)}$(c.options.altField).val(e);if($.isFunction(c.options.onSelect)&&!b&&!c.inSelect){c.inSelect=true;c.options.onSelect.apply(a,[c.selectedDates]);c.inSelect=false}}},_getBorders:function(b){var c=function(a){return{thin:1,medium:3,thick:5}[a]||a};return[parseFloat(c(b.css('border-left-width'))),parseFloat(c(b.css('border-top-width')))]},_checkOffset:function(a){var b=(a.elem.is(':hidden')&&a.trigger?a.trigger:a.elem);var c=b.offset();var d=$(window).width();var e=$(window).height();if(d===0){return c}var f=false;$(a.elem).parents().each(function(){f|=$(this).css('position')==='fixed';return!f});var g=document.documentElement.scrollLeft||document.body.scrollLeft;var h=document.documentElement.scrollTop||document.body.scrollTop;var i=c.top-(f?h:0)-a.div.outerHeight();var j=c.top-(f?h:0)+b.outerHeight();var k=c.left-(f?g:0);var l=c.left-(f?g:0)+b.outerWidth()-a.div.outerWidth();var m=(c.left-g+a.div.outerWidth())>d;var n=(c.top-h+a.elem.outerHeight()+a.div.outerHeight())>e;a.div.css('position',f?'fixed':'absolute');var o=a.options.alignment;if(o==='topLeft'){c={left:k,top:i}}else if(o==='topRight'){c={left:l,top:i}}else if(o==='bottomLeft'){c={left:k,top:j}}else if(o==='bottomRight'){c={left:l,top:j}}else if(o==='top'){c={left:(a.options.isRTL||m?l:k),top:i}}else{c={left:(a.options.isRTL||m?l:k),top:(n?i:j)}}c.left=Math.max((f?0:g),c.left);c.top=Math.max((f?0:h),c.top);return c},_checkExternalClick:function(a){if(!G.curInst){return}var b=$(a.target);if(b.closest('.'+G._popupClass+',.'+G._triggerClass).length===0&&!b.hasClass(G._getMarker())){G.hide(G.curInst)}},hide:function(a,b){if(!a){return}var c=this._getInst(a);if($.isEmptyObject(c)){c=a}if(c&&c===G.curInst){var d=(b?'':c.options.showAnim);var e=c.options.showSpeed;e=(e==='normal'&&$.ui&&parseInt($.ui.version.substring(2))>=8?'_default':e);var f=function(){if(!c.div){return}c.div.remove();c.div=null;G.curInst=null;if($.isFunction(c.options.onClose)){c.options.onClose.apply(a,[c.selectedDates])}};c.div.stop();if($.effects&&($.effects[d]||($.effects.effect&&$.effects.effect[d]))){c.div.hide(d,c.options.showOptions,e,f)}else{var g=(d==='slideDown'?'slideUp':(d==='fadeIn'?'fadeOut':'hide'));c.div[g]((d?e:''),f)}if(!d){f()}}},_keyDown:function(a){var b=a.target;var c=G._getInst(b);var d=false;if(c.div){if(a.keyCode===9){G.hide(b)}else if(a.keyCode===13){G.selectDate(b,$('a.'+c.options.renderer.highlightedClass,c.div)[0]);d=true}else{var e=c.options.commands;for(var f in e){var g=e[f];if(g.keystroke.keyCode===a.keyCode&&!!g.keystroke.ctrlKey===!!(a.ctrlKey||a.metaKey)&&!!g.keystroke.altKey===a.altKey&&!!g.keystroke.shiftKey===a.shiftKey){G.performAction(b,f);d=true;break}}}}else{var g=c.options.commands.current;if(g.keystroke.keyCode===a.keyCode&&!!g.keystroke.ctrlKey===!!(a.ctrlKey||a.metaKey)&&!!g.keystroke.altKey===a.altKey&&!!g.keystroke.shiftKey===a.shiftKey){G.show(b);d=true}}c.ctrlKey=((a.keyCode<48&&a.keyCode!==32)||a.ctrlKey||a.metaKey);if(d){a.preventDefault();a.stopPropagation()}return!d},_keyPress:function(a){var b=G._getInst(a.target);if(!$.isEmptyObject(b)&&b.options.constrainInput){var c=String.fromCharCode(a.keyCode||a.charCode);var d=G._allowedChars(b);return(a.metaKey||b.ctrlKey||c<' '||!d||d.indexOf(c)>-1)}return true},_allowedChars:function(a){var b=(a.options.multiSelect?a.options.multiSeparator:(a.options.rangeSelect?a.options.rangeSeparator:''));var c=false;var d=false;var e=a.get('dateFormat');for(var i=0;i<e.length;i++){var f=e.charAt(i);if(c){if(f==="'"&&e.charAt(i+1)!=="'"){c=false}else{b+=f}}else{switch(f){case'd':case'm':case'o':case'w':b+=(d?'':'0123456789');d=true;break;case'y':case'@':case'!':b+=(d?'':'0123456789')+'-';d=true;break;case'J':b+=(d?'':'0123456789')+'-.';d=true;break;case'D':case'M':case'Y':return null;case"'":if(e.charAt(i+1)==="'"){b+="'"}else{c=true}break;default:b+=f}}}return b},_keyUp:function(a){var b=a.target;var c=G._getInst(b);if(!$.isEmptyObject(c)&&!c.ctrlKey&&c.lastVal!==c.elem.val()){try{var d=G._extractDates(c,c.elem.val());if(d.length>0){G.setDate(b,d,null,true)}}catch(a){}}return true},_doMouseWheel:function(a,b){var c=(G.curInst&&G.curInst.elem[0])||$(a.target).closest('.'+G._getMarker())[0];if(G.isDisabled(c)){return}var d=G._getInst(c);if(d.options.useMouseWheel){b=(b<0?-1:+1);G.changeMonth(c,-d.options[a.ctrlKey?'monthsToJump':'monthsToStep']*b)}a.preventDefault()},clear:function(a){var b=this._getInst(a);if(!$.isEmptyObject(b)){b.selectedDates=[];this.hide(a);var c=b.get('defaultDate');if(b.options.selectDefaultDate&&c){this.setDate(a,(c||b.options.calendar.today()).newDate())}else{this._updateInput(a)}}},getDate:function(a){var b=this._getInst(a);return(!$.isEmptyObject(b)?b.selectedDates:[])},setDate:function(a,b,c,d,e){var f=this._getInst(a);if(!$.isEmptyObject(f)){if(!$.isArray(b)){b=[b];if(c){b.push(c)}}var g=f.get('minDate');var h=f.get('maxDate');var k=f.selectedDates[0];f.selectedDates=[];for(var i=0;i<b.length;i++){var l=f.options.calendar.determineDate(b[i],null,k,f.get('dateFormat'),f.getConfig());if(l){if((!g||l.compareTo(g)!==-1)&&(!h||l.compareTo(h)!==+1)){var m=false;for(var j=0;j<f.selectedDates.length;j++){if(f.selectedDates[j].compareTo(l)===0){m=true;break}}if(!m){f.selectedDates.push(l)}}}}f.selectedDates.splice(f.options.multiSelect||(f.options.rangeSelect?2:1),f.selectedDates.length);if(f.options.rangeSelect){switch(f.selectedDates.length){case 1:f.selectedDates[1]=f.selectedDates[0];break;case 2:f.selectedDates[1]=(f.selectedDates[0].compareTo(f.selectedDates[1])===+1?f.selectedDates[0]:f.selectedDates[1]);break}f.pickingRange=false}f.prevDate=(f.drawDate?f.drawDate.newDate():null);f.drawDate=this._checkMinMax((f.selectedDates[0]||f.get('defaultDate')||f.options.calendar.today()).newDate(),f);if(!e){this._update(a);this._updateInput(a,d)}}},isSelectable:function(a,b){var c=this._getInst(a);if($.isEmptyObject(c)){return false}b=c.options.calendar.determineDate(b,c.selectedDates[0]||c.options.calendar.today(),null,c.options.dateFormat,c.getConfig());return this._isSelectable(a,b,c.options.onDate,c.get('minDate'),c.get('maxDate'))},_isSelectable:function(a,b,c,d,e){var f=(typeof c==='boolean'?{selectable:c}:(!$.isFunction(c)?{}:c.apply(a,[b,true])));return(f.selectable!==false)&&(!d||b.toJD()>=d.toJD())&&(!e||b.toJD()<=e.toJD())},performAction:function(a,b){var c=this._getInst(a);if(!$.isEmptyObject(c)&&!this.isDisabled(a)){var d=c.options.commands;if(d[b]&&d[b].enabled.apply(a,[c])){d[b].action.apply(a,[c])}}},showMonth:function(a,b,c,d){var e=this._getInst(a);if(!$.isEmptyObject(e)&&(d!=null||(e.drawDate.year()!==b||e.drawDate.month()!==c))){e.prevDate=e.drawDate.newDate();var f=e.options.calendar;var g=this._checkMinMax((b!=null?f.newDate(b,c,1):f.today()),e);e.drawDate.date(g.year(),g.month(),(d!=null?d:Math.min(e.drawDate.day(),f.daysInMonth(g.year(),g.month()))));this._update(a)}},changeMonth:function(a,b){var c=this._getInst(a);if(!$.isEmptyObject(c)){var d=c.drawDate.newDate().add(b,'m');this.showMonth(a,d.year(),d.month())}},changeDay:function(a,b){var c=this._getInst(a);if(!$.isEmptyObject(c)){var d=c.drawDate.newDate().add(b,'d');this.showMonth(a,d.year(),d.month(),d.day())}},_checkMinMax:function(a,b){var c=b.get('minDate');var d=b.get('maxDate');a=(c&&a.compareTo(c)===-1?c.newDate():a);a=(d&&a.compareTo(d)===+1?d.newDate():a);return a},retrieveDate:function(a,b){var c=this._getInst(a);return($.isEmptyObject(c)?null:c.options.calendar.fromJD(parseFloat(b.className.replace(/^.*jd(\d+\.5).*$/,'$1'))))},selectDate:function(a,b){var c=this._getInst(a);if(!$.isEmptyObject(c)&&!this.isDisabled(a)){var d=this.retrieveDate(a,b);if(c.options.multiSelect){var e=false;for(var i=0;i<c.selectedDates.length;i++){if(d.compareTo(c.selectedDates[i])===0){c.selectedDates.splice(i,1);e=true;break}}if(!e&&c.selectedDates.length<c.options.multiSelect){c.selectedDates.push(d)}}else if(c.options.rangeSelect){if(c.pickingRange){c.selectedDates[1]=d}else{c.selectedDates=[d,d]}c.pickingRange=!c.pickingRange}else{c.selectedDates=[d]}c.prevDate=d.newDate();this._updateInput(a);if(c.inline||c.pickingRange||c.selectedDates.length<(c.options.multiSelect||(c.options.rangeSelect?2:1))){this._update(a)}else{this.hide(a)}}},_generateContent:function(h,i){var j=i.options.monthsToShow;j=($.isArray(j)?j:[1,j]);i.drawDate=this._checkMinMax(i.drawDate||i.get('defaultDate')||i.options.calendar.today(),i);var k=i.drawDate.newDate().add(-i.options.monthsOffset,'m');var l='';for(var m=0;m<j[0];m++){var n='';for(var o=0;o<j[1];o++){n+=this._generateMonth(h,i,k.year(),k.month(),i.options.calendar,i.options.renderer,(m===0&&o===0));k.add(1,'m')}l+=this._prepare(i.options.renderer.monthRow,i).replace(/\{months\}/,n)}var p=this._prepare(i.options.renderer.picker,i).replace(/\{months\}/,l).replace(/\{weekHeader\}/g,this._generateDayHeaders(i,i.options.calendar,i.options.renderer));var q=function(a,b,c,d,e){if(p.indexOf('{'+a+':'+d+'}')===-1){return}var f=i.options.commands[d];var g=(i.options.commandsAsDateFormat?f.date.apply(h,[i]):null);p=p.replace(new RegExp('\\{'+a+':'+d+'\\}','g'),'<'+b+(f.status?' title="'+i.options[f.status]+'"':'')+' class="'+i.options.renderer.commandClass+' '+i.options.renderer.commandClass+'-'+d+' '+e+(f.enabled(i)?'':' '+i.options.renderer.disabledClass)+'">'+(g?g.formatDate(i.options[f.text]):i.options[f.text])+'</'+c+'>')};for(var r in i.options.commands){q('button','button type="button"','button',r,i.options.renderer.commandButtonClass);q('link','a href="javascript:void(0)"','a',r,i.options.renderer.commandLinkClass)}p=$(p);if(j[1]>1){var s=0;$(i.options.renderer.monthSelector,p).each(function(){var a=++s%j[1];$(this).addClass(a===1?'first':(a===0?'last':''))})}var t=this;p.find(i.options.renderer.daySelector+' a').hover(function(){(i.inline?$(this).closest('.'+t._getMarker()):i.div).find(i.options.renderer.daySelector+' a').removeClass(i.options.renderer.highlightedClass);$(this).addClass(i.options.renderer.highlightedClass)},function(){(i.inline?$(this).closest('.'+t._getMarker()):i.div).find(i.options.renderer.daySelector+' a').removeClass(i.options.renderer.highlightedClass)}).click(function(){t.selectDate(h,this)}).end().find('select.'+this._monthYearClass+':not(.'+this._anyYearClass+')').change(function(){var a=$(this).val().split('/');t.showMonth(h,parseInt(a[1],10),parseInt(a[0],10))}).end().find('select.'+this._anyYearClass).click(function(){$(this).css('visibility','hidden').next('input').css({left:this.offsetLeft,top:this.offsetTop,width:this.offsetWidth,height:this.offsetHeight}).show().focus()}).end().find('input.'+t._monthYearClass).change(function(){try{var a=parseInt($(this).val(),10);a=(isNaN(a)?i.drawDate.year():a);t.showMonth(h,a,i.drawDate.month(),i.drawDate.day())}catch(e){alert(e)}}).keydown(function(a){if(a.keyCode===13){$(a.elem).change()}else if(a.keyCode===27){$(a.elem).hide().prev('select').css('visibility','visible');i.elem.focus()}});p.find('.'+i.options.renderer.commandClass).click(function(){if(!$(this).hasClass(i.options.renderer.disabledClass)){var a=this.className.replace(new RegExp('^.*'+i.options.renderer.commandClass+'-([^ ]+).*$'),'$1');G.performAction(h,a)}});if(i.options.isRTL){p.addClass(i.options.renderer.rtlClass)}if(j[0]*j[1]>1){p.addClass(i.options.renderer.multiClass)}if(i.options.pickerClass){p.addClass(i.options.pickerClass)}$('body').append(p);var u=0;p.find(i.options.renderer.monthSelector).each(function(){u+=$(this).outerWidth()});p.width(u/j[0]);if($.isFunction(i.options.onShow)){i.options.onShow.apply(h,[p,i.options.calendar,i])}return p},_generateMonth:function(a,b,c,d,e,f,g){var h=e.daysInMonth(c,d);var j=b.options.monthsToShow;j=($.isArray(j)?j:[1,j]);var k=b.options.fixedWeeks||(j[0]*j[1]>1);var l=b.options.firstDay;l=(l==null?e.local.firstDay:l);var m=(e.dayOfWeek(c,d,e.minDay)-l+e.daysInWeek())%e.daysInWeek();var n=(k?6:Math.ceil((m+h)/e.daysInWeek()));var o=b.options.selectOtherMonths&&b.options.showOtherMonths;var p=(b.pickingRange?b.selectedDates[0]:b.get('minDate'));var q=b.get('maxDate');var r=f.week.indexOf('{weekOfYear}')>-1;var s=e.today();var t=e.newDate(c,d,e.minDay);t.add(-m-(k&&(t.dayOfWeek()===l||t.daysInMonth()<e.daysInWeek())?e.daysInWeek():0),'d');var u=t.toJD();var v='';for(var w=0;w<n;w++){var x=(!r?'':'<span class="jd'+u+'">'+($.isFunction(b.options.calculateWeek)?b.options.calculateWeek(t):t.weekOfYear())+'</span>');var y='';for(var z=0;z<e.daysInWeek();z++){var A=false;if(b.options.rangeSelect&&b.selectedDates.length>0){A=(t.compareTo(b.selectedDates[0])!==-1&&t.compareTo(b.selectedDates[1])!==+1)}else{for(var i=0;i<b.selectedDates.length;i++){if(b.selectedDates[i].compareTo(t)===0){A=true;break}}}var B=(!$.isFunction(b.options.onDate)?{}:b.options.onDate.apply(a,[t,t.month()===d]));var C=(o||t.month()===d)&&this._isSelectable(a,t,B.selectable,p,q);y+=this._prepare(f.day,b).replace(/\{day\}/g,(C?'<a href="javascript:void(0)"':'<span')+' class="jd'+u+' '+(B.dateClass||'')+(A&&(o||t.month()===d)?' '+f.selectedClass:'')+(C?' '+f.defaultClass:'')+(t.weekDay()?'':' '+f.weekendClass)+(t.month()===d?'':' '+f.otherMonthClass)+(t.compareTo(s)===0&&t.month()===d?' '+f.todayClass:'')+(t.compareTo(b.drawDate)===0&&t.month()===d?' '+f.highlightedClass:'')+'"'+(B.title||(b.options.dayStatus&&C)?' title="'+(B.title||t.formatDate(b.options.dayStatus))+'"':'')+'>'+(b.options.showOtherMonths||t.month()===d?B.content||t.day():'&nbsp;')+(C?'</a>':'</span>'));t.add(1,'d');u++}v+=this._prepare(f.week,b).replace(/\{days\}/g,y).replace(/\{weekOfYear\}/g,x)}var D=this._prepare(f.month,b).match(/\{monthHeader(:[^\}]+)?\}/);D=(D[0].length<=13?'MM yyyy':D[0].substring(13,D[0].length-1));D=(g?this._generateMonthSelection(b,c,d,p,q,D,e,f):e.formatDate(D,e.newDate(c,d,e.minDay)));var E=this._prepare(f.weekHeader,b).replace(/\{days\}/g,this._generateDayHeaders(b,e,f));return this._prepare(f.month,b).replace(/\{monthHeader(:[^\}]+)?\}/g,D).replace(/\{weekHeader\}/g,E).replace(/\{weeks\}/g,v)},_generateDayHeaders:function(a,b,c){var d=a.options.firstDay;d=(d==null?b.local.firstDay:d);var e='';for(var f=0;f<b.daysInWeek();f++){var g=(f+d)%b.daysInWeek();e+=this._prepare(c.dayHeader,a).replace(/\{day\}/g,'<span class="'+this._curDoWClass+g+'" title="'+b.local.dayNames[g]+'">'+b.local.dayNamesMin[g]+'</span>')}return e},_generateMonthSelection:function(a,b,c,d,e,f,g){if(!a.options.changeMonth){return g.formatDate(f,g.newDate(b,c,1))}var h=g.local['monthNames'+(f.match(/mm/i)?'':'Short')];var i=f.replace(/m+/i,'\\x2E').replace(/y+/i,'\\x2F');var j='<select class="'+this._monthYearClass+'" title="'+a.options.monthStatus+'">';var k=g.monthsInYear(b)+g.minMonth;for(var m=g.minMonth;m<k;m++){if((!d||g.newDate(b,m,g.daysInMonth(b,m)-1+g.minDay).compareTo(d)!==-1)&&(!e||g.newDate(b,m,g.minDay).compareTo(e)!==+1)){j+='<option value="'+m+'/'+b+'"'+(c===m?' selected="selected"':'')+'>'+h[m-g.minMonth]+'</option>'}}j+='</select>';i=i.replace(/\\x2E/,j);var l=a.options.yearRange;if(l==='any'){j='<select class="'+this._monthYearClass+' '+this._anyYearClass+'" title="'+a.options.yearStatus+'">'+'<option>'+b+'</option></select>'+'<input class="'+this._monthYearClass+' '+this._curMonthClass+c+'" value="'+b+'">'}else{l=l.split(':');var n=g.today().year();var o=(l[0].match('c[+-].*')?b+parseInt(l[0].substring(1),10):((l[0].match('[+-].*')?n:0)+parseInt(l[0],10)));var p=(l[1].match('c[+-].*')?b+parseInt(l[1].substring(1),10):((l[1].match('[+-].*')?n:0)+parseInt(l[1],10)));j='<select class="'+this._monthYearClass+'" title="'+a.options.yearStatus+'">';o=g.newDate(o+1,g.firstMonth,g.minDay).add(-1,'d');p=g.newDate(p,g.firstMonth,g.minDay);var q=function(y){if(y!==0||g.hasYearZero){j+='<option value="'+Math.min(c,g.monthsInYear(y)-1+g.minMonth)+'/'+y+'"'+(b===y?' selected="selected"':'')+'>'+y+'</option>'}};if(o.toJD()<p.toJD()){o=(d&&d.compareTo(o)===+1?d:o).year();p=(e&&e.compareTo(p)===-1?e:p).year();for(var y=o;y<=p;y++){q(y)}}else{o=(e&&e.compareTo(o)===-1?e:o).year();p=(d&&d.compareTo(p)===+1?d:p).year();for(var y=o;y>=p;y--){q(y)}}j+='</select>'}i=i.replace(/\\x2F/,j);return i},_prepare:function(e,f){var g=function(a,b){while(true){var c=e.indexOf('{'+a+':start}');if(c===-1){return}var d=e.substring(c).indexOf('{'+a+':end}');if(d>-1){e=e.substring(0,c)+(b?e.substr(c+a.length+8,d-a.length-8):'')+e.substring(c+d+a.length+6)}}};g('inline',f.inline);g('popup',!f.inline);var h=/\{l10n:([^\}]+)\}/;var i=null;while(i=h.exec(e)){e=e.replace(i[0],f.options[i[1]])}return e}});var G=$.calendarsPicker;$(function(){$(document).on('mousedown.'+F,G._checkExternalClick).on('resize.'+F,function(){G.hide(G.curInst)})})})(jQuery);