Allow searching for IPs' logs
[mediawiki.git] / resources / jquery.ui / jquery.ui.datepicker.js
blob1fcea12a1c80f5d2f6c1715e34390429d8e29b89
1 /*!
2  * jQuery UI Datepicker 1.8.24
3  *
4  * Copyright 2012, AUTHORS.txt (http://jqueryui.com/about)
5  * Dual licensed under the MIT or GPL Version 2 licenses.
6  * http://jquery.org/license
7  *
8  * http://docs.jquery.com/UI/Datepicker
9  *
10  * Depends:
11  *      jquery.ui.core.js
12  */
13 (function( $, undefined ) {
15 $.extend($.ui, { datepicker: { version: "1.8.24" } });
17 var PROP_NAME = 'datepicker';
18 var dpuuid = new Date().getTime();
19 var instActive;
21 /* Date picker manager.
22    Use the singleton instance of this class, $.datepicker, to interact with the date picker.
23    Settings for (groups of) date pickers are maintained in an instance object,
24    allowing multiple different settings on the same page. */
26 function Datepicker() {
27         this.debug = false; // Change this to true to start debugging
28         this._curInst = null; // The current instance in use
29         this._keyEvent = false; // If the last event was a key event
30         this._disabledInputs = []; // List of date picker inputs that have been disabled
31         this._datepickerShowing = false; // True if the popup picker is showing , false if not
32         this._inDialog = false; // True if showing within a "dialog", false if not
33         this._mainDivId = 'ui-datepicker-div'; // The ID of the main datepicker division
34         this._inlineClass = 'ui-datepicker-inline'; // The name of the inline marker class
35         this._appendClass = 'ui-datepicker-append'; // The name of the append marker class
36         this._triggerClass = 'ui-datepicker-trigger'; // The name of the trigger marker class
37         this._dialogClass = 'ui-datepicker-dialog'; // The name of the dialog marker class
38         this._disableClass = 'ui-datepicker-disabled'; // The name of the disabled covering marker class
39         this._unselectableClass = 'ui-datepicker-unselectable'; // The name of the unselectable cell marker class
40         this._currentClass = 'ui-datepicker-current-day'; // The name of the current day marker class
41         this._dayOverClass = 'ui-datepicker-days-cell-over'; // The name of the day hover marker class
42         this.regional = []; // Available regional settings, indexed by language code
43         this.regional[''] = { // Default regional settings
44                 closeText: 'Done', // Display text for close link
45                 prevText: 'Prev', // Display text for previous month link
46                 nextText: 'Next', // Display text for next month link
47                 currentText: 'Today', // Display text for current month link
48                 monthNames: ['January','February','March','April','May','June',
49                         'July','August','September','October','November','December'], // Names of months for drop-down and formatting
50                 monthNamesShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], // For formatting
51                 dayNames: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'], // For formatting
52                 dayNamesShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'], // For formatting
53                 dayNamesMin: ['Su','Mo','Tu','We','Th','Fr','Sa'], // Column headings for days starting at Sunday
54                 weekHeader: 'Wk', // Column header for week of the year
55                 dateFormat: 'mm/dd/yy', // See format options on parseDate
56                 firstDay: 0, // The first day of the week, Sun = 0, Mon = 1, ...
57                 isRTL: false, // True if right-to-left language, false if left-to-right
58                 showMonthAfterYear: false, // True if the year select precedes month, false for month then year
59                 yearSuffix: '' // Additional text to append to the year in the month headers
60         };
61         this._defaults = { // Global defaults for all the date picker instances
62                 showOn: 'focus', // 'focus' for popup on focus,
63                         // 'button' for trigger button, or 'both' for either
64                 showAnim: 'fadeIn', // Name of jQuery animation for popup
65                 showOptions: {}, // Options for enhanced animations
66                 defaultDate: null, // Used when field is blank: actual date,
67                         // +/-number for offset from today, null for today
68                 appendText: '', // Display text following the input box, e.g. showing the format
69                 buttonText: '...', // Text for trigger button
70                 buttonImage: '', // URL for trigger button image
71                 buttonImageOnly: false, // True if the image appears alone, false if it appears on a button
72                 hideIfNoPrevNext: false, // True to hide next/previous month links
73                         // if not applicable, false to just disable them
74                 navigationAsDateFormat: false, // True if date formatting applied to prev/today/next links
75                 gotoCurrent: false, // True if today link goes back to current selection instead
76                 changeMonth: false, // True if month can be selected directly, false if only prev/next
77                 changeYear: false, // True if year can be selected directly, false if only prev/next
78                 yearRange: 'c-10:c+10', // Range of years to display in drop-down,
79                         // either relative to today's year (-nn:+nn), relative to currently displayed year
80                         // (c-nn:c+nn), absolute (nnnn:nnnn), or a combination of the above (nnnn:-n)
81                 showOtherMonths: false, // True to show dates in other months, false to leave blank
82                 selectOtherMonths: false, // True to allow selection of dates in other months, false for unselectable
83                 showWeek: false, // True to show week of the year, false to not show it
84                 calculateWeek: this.iso8601Week, // How to calculate the week of the year,
85                         // takes a Date and returns the number of the week for it
86                 shortYearCutoff: '+10', // Short year values < this are in the current century,
87                         // > this are in the previous century,
88                         // string value starting with '+' for current year + value
89                 minDate: null, // The earliest selectable date, or null for no limit
90                 maxDate: null, // The latest selectable date, or null for no limit
91                 duration: 'fast', // Duration of display/closure
92                 beforeShowDay: null, // Function that takes a date and returns an array with
93                         // [0] = true if selectable, false if not, [1] = custom CSS class name(s) or '',
94                         // [2] = cell title (optional), e.g. $.datepicker.noWeekends
95                 beforeShow: null, // Function that takes an input field and
96                         // returns a set of custom settings for the date picker
97                 onSelect: null, // Define a callback function when a date is selected
98                 onChangeMonthYear: null, // Define a callback function when the month or year is changed
99                 onClose: null, // Define a callback function when the datepicker is closed
100                 numberOfMonths: 1, // Number of months to show at a time
101                 showCurrentAtPos: 0, // The position in multipe months at which to show the current month (starting at 0)
102                 stepMonths: 1, // Number of months to step back/forward
103                 stepBigMonths: 12, // Number of months to step back/forward for the big links
104                 altField: '', // Selector for an alternate field to store selected dates into
105                 altFormat: '', // The date format to use for the alternate field
106                 constrainInput: true, // The input is constrained by the current date format
107                 showButtonPanel: false, // True to show button panel, false to not show it
108                 autoSize: false, // True to size the input for the date format, false to leave as is
109                 disabled: false // The initial disabled state
110         };
111         $.extend(this._defaults, this.regional['']);
112         this.dpDiv = bindHover($('<div id="' + this._mainDivId + '" class="ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all"></div>'));
115 $.extend(Datepicker.prototype, {
116         /* Class name added to elements to indicate already configured with a date picker. */
117         markerClassName: 'hasDatepicker',
118         
119         //Keep track of the maximum number of rows displayed (see #7043)
120         maxRows: 4,
122         /* Debug logging (if enabled). */
123         log: function () {
124                 if (this.debug)
125                         console.log.apply('', arguments);
126         },
127         
128         // TODO rename to "widget" when switching to widget factory
129         _widgetDatepicker: function() {
130                 return this.dpDiv;
131         },
133         /* Override the default settings for all instances of the date picker.
134            @param  settings  object - the new settings to use as defaults (anonymous object)
135            @return the manager object */
136         setDefaults: function(settings) {
137                 extendRemove(this._defaults, settings || {});
138                 return this;
139         },
141         /* Attach the date picker to a jQuery selection.
142            @param  target    element - the target input field or division or span
143            @param  settings  object - the new settings to use for this date picker instance (anonymous) */
144         _attachDatepicker: function(target, settings) {
145                 // check for settings on the control itself - in namespace 'date:'
146                 var inlineSettings = null;
147                 for (var attrName in this._defaults) {
148                         var attrValue = target.getAttribute('date:' + attrName);
149                         if (attrValue) {
150                                 inlineSettings = inlineSettings || {};
151                                 try {
152                                         inlineSettings[attrName] = eval(attrValue);
153                                 } catch (err) {
154                                         inlineSettings[attrName] = attrValue;
155                                 }
156                         }
157                 }
158                 var nodeName = target.nodeName.toLowerCase();
159                 var inline = (nodeName == 'div' || nodeName == 'span');
160                 if (!target.id) {
161                         this.uuid += 1;
162                         target.id = 'dp' + this.uuid;
163                 }
164                 var inst = this._newInst($(target), inline);
165                 inst.settings = $.extend({}, settings || {}, inlineSettings || {});
166                 if (nodeName == 'input') {
167                         this._connectDatepicker(target, inst);
168                 } else if (inline) {
169                         this._inlineDatepicker(target, inst);
170                 }
171         },
173         /* Create a new instance object. */
174         _newInst: function(target, inline) {
175                 var id = target[0].id.replace(/([^A-Za-z0-9_-])/g, '\\\\$1'); // escape jQuery meta chars
176                 return {id: id, input: target, // associated target
177                         selectedDay: 0, selectedMonth: 0, selectedYear: 0, // current selection
178                         drawMonth: 0, drawYear: 0, // month being drawn
179                         inline: inline, // is datepicker inline or not
180                         dpDiv: (!inline ? this.dpDiv : // presentation div
181                         bindHover($('<div class="' + this._inlineClass + ' ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all"></div>')))};
182         },
184         /* Attach the date picker to an input field. */
185         _connectDatepicker: function(target, inst) {
186                 var input = $(target);
187                 inst.append = $([]);
188                 inst.trigger = $([]);
189                 if (input.hasClass(this.markerClassName))
190                         return;
191                 this._attachments(input, inst);
192                 input.addClass(this.markerClassName).keydown(this._doKeyDown).
193                         keypress(this._doKeyPress).keyup(this._doKeyUp).
194                         bind("setData.datepicker", function(event, key, value) {
195                                 inst.settings[key] = value;
196                         }).bind("getData.datepicker", function(event, key) {
197                                 return this._get(inst, key);
198                         });
199                 this._autoSize(inst);
200                 $.data(target, PROP_NAME, inst);
201                 //If disabled option is true, disable the datepicker once it has been attached to the input (see ticket #5665)
202                 if( inst.settings.disabled ) {
203                         this._disableDatepicker( target );
204                 }
205         },
207         /* Make attachments based on settings. */
208         _attachments: function(input, inst) {
209                 var appendText = this._get(inst, 'appendText');
210                 var isRTL = this._get(inst, 'isRTL');
211                 if (inst.append)
212                         inst.append.remove();
213                 if (appendText) {
214                         inst.append = $('<span class="' + this._appendClass + '">' + appendText + '</span>');
215                         input[isRTL ? 'before' : 'after'](inst.append);
216                 }
217                 input.unbind('focus', this._showDatepicker);
218                 if (inst.trigger)
219                         inst.trigger.remove();
220                 var showOn = this._get(inst, 'showOn');
221                 if (showOn == 'focus' || showOn == 'both') // pop-up date picker when in the marked field
222                         input.focus(this._showDatepicker);
223                 if (showOn == 'button' || showOn == 'both') { // pop-up date picker when button clicked
224                         var buttonText = this._get(inst, 'buttonText');
225                         var buttonImage = this._get(inst, 'buttonImage');
226                         inst.trigger = $(this._get(inst, 'buttonImageOnly') ?
227                                 $('<img/>').addClass(this._triggerClass).
228                                         attr({ src: buttonImage, alt: buttonText, title: buttonText }) :
229                                 $('<button type="button"></button>').addClass(this._triggerClass).
230                                         html(buttonImage == '' ? buttonText : $('<img/>').attr(
231                                         { src:buttonImage, alt:buttonText, title:buttonText })));
232                         input[isRTL ? 'before' : 'after'](inst.trigger);
233                         inst.trigger.click(function() {
234                                 if ($.datepicker._datepickerShowing && $.datepicker._lastInput == input[0])
235                                         $.datepicker._hideDatepicker();
236                                 else if ($.datepicker._datepickerShowing && $.datepicker._lastInput != input[0]) {
237                                         $.datepicker._hideDatepicker(); 
238                                         $.datepicker._showDatepicker(input[0]);
239                                 } else
240                                         $.datepicker._showDatepicker(input[0]);
241                                 return false;
242                         });
243                 }
244         },
246         /* Apply the maximum length for the date format. */
247         _autoSize: function(inst) {
248                 if (this._get(inst, 'autoSize') && !inst.inline) {
249                         var date = new Date(2009, 12 - 1, 20); // Ensure double digits
250                         var dateFormat = this._get(inst, 'dateFormat');
251                         if (dateFormat.match(/[DM]/)) {
252                                 var findMax = function(names) {
253                                         var max = 0;
254                                         var maxI = 0;
255                                         for (var i = 0; i < names.length; i++) {
256                                                 if (names[i].length > max) {
257                                                         max = names[i].length;
258                                                         maxI = i;
259                                                 }
260                                         }
261                                         return maxI;
262                                 };
263                                 date.setMonth(findMax(this._get(inst, (dateFormat.match(/MM/) ?
264                                         'monthNames' : 'monthNamesShort'))));
265                                 date.setDate(findMax(this._get(inst, (dateFormat.match(/DD/) ?
266                                         'dayNames' : 'dayNamesShort'))) + 20 - date.getDay());
267                         }
268                         inst.input.attr('size', this._formatDate(inst, date).length);
269                 }
270         },
272         /* Attach an inline date picker to a div. */
273         _inlineDatepicker: function(target, inst) {
274                 var divSpan = $(target);
275                 if (divSpan.hasClass(this.markerClassName))
276                         return;
277                 divSpan.addClass(this.markerClassName).append(inst.dpDiv).
278                         bind("setData.datepicker", function(event, key, value){
279                                 inst.settings[key] = value;
280                         }).bind("getData.datepicker", function(event, key){
281                                 return this._get(inst, key);
282                         });
283                 $.data(target, PROP_NAME, inst);
284                 this._setDate(inst, this._getDefaultDate(inst), true);
285                 this._updateDatepicker(inst);
286                 this._updateAlternate(inst);
287                 //If disabled option is true, disable the datepicker before showing it (see ticket #5665)
288                 if( inst.settings.disabled ) {
289                         this._disableDatepicker( target );
290                 }
291                 // Set display:block in place of inst.dpDiv.show() which won't work on disconnected elements
292                 // http://bugs.jqueryui.com/ticket/7552 - A Datepicker created on a detached div has zero height
293                 inst.dpDiv.css( "display", "block" );
294         },
296         /* Pop-up the date picker in a "dialog" box.
297            @param  input     element - ignored
298            @param  date      string or Date - the initial date to display
299            @param  onSelect  function - the function to call when a date is selected
300            @param  settings  object - update the dialog date picker instance's settings (anonymous object)
301            @param  pos       int[2] - coordinates for the dialog's position within the screen or
302                              event - with x/y coordinates or
303                              leave empty for default (screen centre)
304            @return the manager object */
305         _dialogDatepicker: function(input, date, onSelect, settings, pos) {
306                 var inst = this._dialogInst; // internal instance
307                 if (!inst) {
308                         this.uuid += 1;
309                         var id = 'dp' + this.uuid;
310                         this._dialogInput = $('<input type="text" id="' + id +
311                                 '" style="position: absolute; top: -100px; width: 0px;"/>');
312                         this._dialogInput.keydown(this._doKeyDown);
313                         $('body').append(this._dialogInput);
314                         inst = this._dialogInst = this._newInst(this._dialogInput, false);
315                         inst.settings = {};
316                         $.data(this._dialogInput[0], PROP_NAME, inst);
317                 }
318                 extendRemove(inst.settings, settings || {});
319                 date = (date && date.constructor == Date ? this._formatDate(inst, date) : date);
320                 this._dialogInput.val(date);
322                 this._pos = (pos ? (pos.length ? pos : [pos.pageX, pos.pageY]) : null);
323                 if (!this._pos) {
324                         var browserWidth = document.documentElement.clientWidth;
325                         var browserHeight = document.documentElement.clientHeight;
326                         var scrollX = document.documentElement.scrollLeft || document.body.scrollLeft;
327                         var scrollY = document.documentElement.scrollTop || document.body.scrollTop;
328                         this._pos = // should use actual width/height below
329                                 [(browserWidth / 2) - 100 + scrollX, (browserHeight / 2) - 150 + scrollY];
330                 }
332                 // move input on screen for focus, but hidden behind dialog
333                 this._dialogInput.css('left', (this._pos[0] + 20) + 'px').css('top', this._pos[1] + 'px');
334                 inst.settings.onSelect = onSelect;
335                 this._inDialog = true;
336                 this.dpDiv.addClass(this._dialogClass);
337                 this._showDatepicker(this._dialogInput[0]);
338                 if ($.blockUI)
339                         $.blockUI(this.dpDiv);
340                 $.data(this._dialogInput[0], PROP_NAME, inst);
341                 return this;
342         },
344         /* Detach a datepicker from its control.
345            @param  target    element - the target input field or division or span */
346         _destroyDatepicker: function(target) {
347                 var $target = $(target);
348                 var inst = $.data(target, PROP_NAME);
349                 if (!$target.hasClass(this.markerClassName)) {
350                         return;
351                 }
352                 var nodeName = target.nodeName.toLowerCase();
353                 $.removeData(target, PROP_NAME);
354                 if (nodeName == 'input') {
355                         inst.append.remove();
356                         inst.trigger.remove();
357                         $target.removeClass(this.markerClassName).
358                                 unbind('focus', this._showDatepicker).
359                                 unbind('keydown', this._doKeyDown).
360                                 unbind('keypress', this._doKeyPress).
361                                 unbind('keyup', this._doKeyUp);
362                 } else if (nodeName == 'div' || nodeName == 'span')
363                         $target.removeClass(this.markerClassName).empty();
364         },
366         /* Enable the date picker to a jQuery selection.
367            @param  target    element - the target input field or division or span */
368         _enableDatepicker: function(target) {
369                 var $target = $(target);
370                 var inst = $.data(target, PROP_NAME);
371                 if (!$target.hasClass(this.markerClassName)) {
372                         return;
373                 }
374                 var nodeName = target.nodeName.toLowerCase();
375                 if (nodeName == 'input') {
376                         target.disabled = false;
377                         inst.trigger.filter('button').
378                                 each(function() { this.disabled = false; }).end().
379                                 filter('img').css({opacity: '1.0', cursor: ''});
380                 }
381                 else if (nodeName == 'div' || nodeName == 'span') {
382                         var inline = $target.children('.' + this._inlineClass);
383                         inline.children().removeClass('ui-state-disabled');
384                         inline.find("select.ui-datepicker-month, select.ui-datepicker-year").
385                                 removeAttr("disabled");
386                 }
387                 this._disabledInputs = $.map(this._disabledInputs,
388                         function(value) { return (value == target ? null : value); }); // delete entry
389         },
391         /* Disable the date picker to a jQuery selection.
392            @param  target    element - the target input field or division or span */
393         _disableDatepicker: function(target) {
394                 var $target = $(target);
395                 var inst = $.data(target, PROP_NAME);
396                 if (!$target.hasClass(this.markerClassName)) {
397                         return;
398                 }
399                 var nodeName = target.nodeName.toLowerCase();
400                 if (nodeName == 'input') {
401                         target.disabled = true;
402                         inst.trigger.filter('button').
403                                 each(function() { this.disabled = true; }).end().
404                                 filter('img').css({opacity: '0.5', cursor: 'default'});
405                 }
406                 else if (nodeName == 'div' || nodeName == 'span') {
407                         var inline = $target.children('.' + this._inlineClass);
408                         inline.children().addClass('ui-state-disabled');
409                         inline.find("select.ui-datepicker-month, select.ui-datepicker-year").
410                                 attr("disabled", "disabled");
411                 }
412                 this._disabledInputs = $.map(this._disabledInputs,
413                         function(value) { return (value == target ? null : value); }); // delete entry
414                 this._disabledInputs[this._disabledInputs.length] = target;
415         },
417         /* Is the first field in a jQuery collection disabled as a datepicker?
418            @param  target    element - the target input field or division or span
419            @return boolean - true if disabled, false if enabled */
420         _isDisabledDatepicker: function(target) {
421                 if (!target) {
422                         return false;
423                 }
424                 for (var i = 0; i < this._disabledInputs.length; i++) {
425                         if (this._disabledInputs[i] == target)
426                                 return true;
427                 }
428                 return false;
429         },
431         /* Retrieve the instance data for the target control.
432            @param  target  element - the target input field or division or span
433            @return  object - the associated instance data
434            @throws  error if a jQuery problem getting data */
435         _getInst: function(target) {
436                 try {
437                         return $.data(target, PROP_NAME);
438                 }
439                 catch (err) {
440                         throw 'Missing instance data for this datepicker';
441                 }
442         },
444         /* Update or retrieve the settings for a date picker attached to an input field or division.
445            @param  target  element - the target input field or division or span
446            @param  name    object - the new settings to update or
447                            string - the name of the setting to change or retrieve,
448                            when retrieving also 'all' for all instance settings or
449                            'defaults' for all global defaults
450            @param  value   any - the new value for the setting
451                            (omit if above is an object or to retrieve a value) */
452         _optionDatepicker: function(target, name, value) {
453                 var inst = this._getInst(target);
454                 if (arguments.length == 2 && typeof name == 'string') {
455                         return (name == 'defaults' ? $.extend({}, $.datepicker._defaults) :
456                                 (inst ? (name == 'all' ? $.extend({}, inst.settings) :
457                                 this._get(inst, name)) : null));
458                 }
459                 var settings = name || {};
460                 if (typeof name == 'string') {
461                         settings = {};
462                         settings[name] = value;
463                 }
464                 if (inst) {
465                         if (this._curInst == inst) {
466                                 this._hideDatepicker();
467                         }
468                         var date = this._getDateDatepicker(target, true);
469                         var minDate = this._getMinMaxDate(inst, 'min');
470                         var maxDate = this._getMinMaxDate(inst, 'max');
471                         extendRemove(inst.settings, settings);
472                         // reformat the old minDate/maxDate values if dateFormat changes and a new minDate/maxDate isn't provided
473                         if (minDate !== null && settings['dateFormat'] !== undefined && settings['minDate'] === undefined)
474                                 inst.settings.minDate = this._formatDate(inst, minDate);
475                         if (maxDate !== null && settings['dateFormat'] !== undefined && settings['maxDate'] === undefined)
476                                 inst.settings.maxDate = this._formatDate(inst, maxDate);
477                         this._attachments($(target), inst);
478                         this._autoSize(inst);
479                         this._setDate(inst, date);
480                         this._updateAlternate(inst);
481                         this._updateDatepicker(inst);
482                 }
483         },
485         // change method deprecated
486         _changeDatepicker: function(target, name, value) {
487                 this._optionDatepicker(target, name, value);
488         },
490         /* Redraw the date picker attached to an input field or division.
491            @param  target  element - the target input field or division or span */
492         _refreshDatepicker: function(target) {
493                 var inst = this._getInst(target);
494                 if (inst) {
495                         this._updateDatepicker(inst);
496                 }
497         },
499         /* Set the dates for a jQuery selection.
500            @param  target   element - the target input field or division or span
501            @param  date     Date - the new date */
502         _setDateDatepicker: function(target, date) {
503                 var inst = this._getInst(target);
504                 if (inst) {
505                         this._setDate(inst, date);
506                         this._updateDatepicker(inst);
507                         this._updateAlternate(inst);
508                 }
509         },
511         /* Get the date(s) for the first entry in a jQuery selection.
512            @param  target     element - the target input field or division or span
513            @param  noDefault  boolean - true if no default date is to be used
514            @return Date - the current date */
515         _getDateDatepicker: function(target, noDefault) {
516                 var inst = this._getInst(target);
517                 if (inst && !inst.inline)
518                         this._setDateFromField(inst, noDefault);
519                 return (inst ? this._getDate(inst) : null);
520         },
522         /* Handle keystrokes. */
523         _doKeyDown: function(event) {
524                 var inst = $.datepicker._getInst(event.target);
525                 var handled = true;
526                 var isRTL = inst.dpDiv.is('.ui-datepicker-rtl');
527                 inst._keyEvent = true;
528                 if ($.datepicker._datepickerShowing)
529                         switch (event.keyCode) {
530                                 case 9: $.datepicker._hideDatepicker();
531                                                 handled = false;
532                                                 break; // hide on tab out
533                                 case 13: var sel = $('td.' + $.datepicker._dayOverClass + ':not(.' + 
534                                                                         $.datepicker._currentClass + ')', inst.dpDiv);
535                                                 if (sel[0])
536                                                         $.datepicker._selectDay(event.target, inst.selectedMonth, inst.selectedYear, sel[0]);
537                                                         var onSelect = $.datepicker._get(inst, 'onSelect');
538                                                         if (onSelect) {
539                                                                 var dateStr = $.datepicker._formatDate(inst);
541                                                                 // trigger custom callback
542                                                                 onSelect.apply((inst.input ? inst.input[0] : null), [dateStr, inst]);
543                                                         }
544                                                 else
545                                                         $.datepicker._hideDatepicker();
546                                                 return false; // don't submit the form
547                                                 break; // select the value on enter
548                                 case 27: $.datepicker._hideDatepicker();
549                                                 break; // hide on escape
550                                 case 33: $.datepicker._adjustDate(event.target, (event.ctrlKey ?
551                                                         -$.datepicker._get(inst, 'stepBigMonths') :
552                                                         -$.datepicker._get(inst, 'stepMonths')), 'M');
553                                                 break; // previous month/year on page up/+ ctrl
554                                 case 34: $.datepicker._adjustDate(event.target, (event.ctrlKey ?
555                                                         +$.datepicker._get(inst, 'stepBigMonths') :
556                                                         +$.datepicker._get(inst, 'stepMonths')), 'M');
557                                                 break; // next month/year on page down/+ ctrl
558                                 case 35: if (event.ctrlKey || event.metaKey) $.datepicker._clearDate(event.target);
559                                                 handled = event.ctrlKey || event.metaKey;
560                                                 break; // clear on ctrl or command +end
561                                 case 36: if (event.ctrlKey || event.metaKey) $.datepicker._gotoToday(event.target);
562                                                 handled = event.ctrlKey || event.metaKey;
563                                                 break; // current on ctrl or command +home
564                                 case 37: if (event.ctrlKey || event.metaKey) $.datepicker._adjustDate(event.target, (isRTL ? +1 : -1), 'D');
565                                                 handled = event.ctrlKey || event.metaKey;
566                                                 // -1 day on ctrl or command +left
567                                                 if (event.originalEvent.altKey) $.datepicker._adjustDate(event.target, (event.ctrlKey ?
568                                                                         -$.datepicker._get(inst, 'stepBigMonths') :
569                                                                         -$.datepicker._get(inst, 'stepMonths')), 'M');
570                                                 // next month/year on alt +left on Mac
571                                                 break;
572                                 case 38: if (event.ctrlKey || event.metaKey) $.datepicker._adjustDate(event.target, -7, 'D');
573                                                 handled = event.ctrlKey || event.metaKey;
574                                                 break; // -1 week on ctrl or command +up
575                                 case 39: if (event.ctrlKey || event.metaKey) $.datepicker._adjustDate(event.target, (isRTL ? -1 : +1), 'D');
576                                                 handled = event.ctrlKey || event.metaKey;
577                                                 // +1 day on ctrl or command +right
578                                                 if (event.originalEvent.altKey) $.datepicker._adjustDate(event.target, (event.ctrlKey ?
579                                                                         +$.datepicker._get(inst, 'stepBigMonths') :
580                                                                         +$.datepicker._get(inst, 'stepMonths')), 'M');
581                                                 // next month/year on alt +right
582                                                 break;
583                                 case 40: if (event.ctrlKey || event.metaKey) $.datepicker._adjustDate(event.target, +7, 'D');
584                                                 handled = event.ctrlKey || event.metaKey;
585                                                 break; // +1 week on ctrl or command +down
586                                 default: handled = false;
587                         }
588                 else if (event.keyCode == 36 && event.ctrlKey) // display the date picker on ctrl+home
589                         $.datepicker._showDatepicker(this);
590                 else {
591                         handled = false;
592                 }
593                 if (handled) {
594                         event.preventDefault();
595                         event.stopPropagation();
596                 }
597         },
599         /* Filter entered characters - based on date format. */
600         _doKeyPress: function(event) {
601                 var inst = $.datepicker._getInst(event.target);
602                 if ($.datepicker._get(inst, 'constrainInput')) {
603                         var chars = $.datepicker._possibleChars($.datepicker._get(inst, 'dateFormat'));
604                         var chr = String.fromCharCode(event.charCode == undefined ? event.keyCode : event.charCode);
605                         return event.ctrlKey || event.metaKey || (chr < ' ' || !chars || chars.indexOf(chr) > -1);
606                 }
607         },
609         /* Synchronise manual entry and field/alternate field. */
610         _doKeyUp: function(event) {
611                 var inst = $.datepicker._getInst(event.target);
612                 if (inst.input.val() != inst.lastVal) {
613                         try {
614                                 var date = $.datepicker.parseDate($.datepicker._get(inst, 'dateFormat'),
615                                         (inst.input ? inst.input.val() : null),
616                                         $.datepicker._getFormatConfig(inst));
617                                 if (date) { // only if valid
618                                         $.datepicker._setDateFromField(inst);
619                                         $.datepicker._updateAlternate(inst);
620                                         $.datepicker._updateDatepicker(inst);
621                                 }
622                         }
623                         catch (err) {
624                                 $.datepicker.log(err);
625                         }
626                 }
627                 return true;
628         },
630         /* Pop-up the date picker for a given input field.
631        If false returned from beforeShow event handler do not show. 
632            @param  input  element - the input field attached to the date picker or
633                           event - if triggered by focus */
634         _showDatepicker: function(input) {
635                 input = input.target || input;
636                 if (input.nodeName.toLowerCase() != 'input') // find from button/image trigger
637                         input = $('input', input.parentNode)[0];
638                 if ($.datepicker._isDisabledDatepicker(input) || $.datepicker._lastInput == input) // already here
639                         return;
640                 var inst = $.datepicker._getInst(input);
641                 if ($.datepicker._curInst && $.datepicker._curInst != inst) {
642                         $.datepicker._curInst.dpDiv.stop(true, true);
643                         if ( inst && $.datepicker._datepickerShowing ) {
644                                 $.datepicker._hideDatepicker( $.datepicker._curInst.input[0] );
645                         }
646                 }
647                 var beforeShow = $.datepicker._get(inst, 'beforeShow');
648                 var beforeShowSettings = beforeShow ? beforeShow.apply(input, [input, inst]) : {};
649                 if(beforeShowSettings === false){
650             //false
651                         return;
652                 }
653                 extendRemove(inst.settings, beforeShowSettings);
654                 inst.lastVal = null;
655                 $.datepicker._lastInput = input;
656                 $.datepicker._setDateFromField(inst);
657                 if ($.datepicker._inDialog) // hide cursor
658                         input.value = '';
659                 if (!$.datepicker._pos) { // position below input
660                         $.datepicker._pos = $.datepicker._findPos(input);
661                         $.datepicker._pos[1] += input.offsetHeight; // add the height
662                 }
663                 var isFixed = false;
664                 $(input).parents().each(function() {
665                         isFixed |= $(this).css('position') == 'fixed';
666                         return !isFixed;
667                 });
668                 if (isFixed && $.browser.opera) { // correction for Opera when fixed and scrolled
669                         $.datepicker._pos[0] -= document.documentElement.scrollLeft;
670                         $.datepicker._pos[1] -= document.documentElement.scrollTop;
671                 }
672                 var offset = {left: $.datepicker._pos[0], top: $.datepicker._pos[1]};
673                 $.datepicker._pos = null;
674                 //to avoid flashes on Firefox
675                 inst.dpDiv.empty();
676                 // determine sizing offscreen
677                 inst.dpDiv.css({position: 'absolute', display: 'block', top: '-1000px'});
678                 $.datepicker._updateDatepicker(inst);
679                 // fix width for dynamic number of date pickers
680                 // and adjust position before showing
681                 offset = $.datepicker._checkOffset(inst, offset, isFixed);
682                 inst.dpDiv.css({position: ($.datepicker._inDialog && $.blockUI ?
683                         'static' : (isFixed ? 'fixed' : 'absolute')), display: 'none',
684                         left: offset.left + 'px', top: offset.top + 'px'});
685                 if (!inst.inline) {
686                         var showAnim = $.datepicker._get(inst, 'showAnim');
687                         var duration = $.datepicker._get(inst, 'duration');
688                         var postProcess = function() {
689                                 var cover = inst.dpDiv.find('iframe.ui-datepicker-cover'); // IE6- only
690                                 if( !! cover.length ){
691                                         var borders = $.datepicker._getBorders(inst.dpDiv);
692                                         cover.css({left: -borders[0], top: -borders[1],
693                                                 width: inst.dpDiv.outerWidth(), height: inst.dpDiv.outerHeight()});
694                                 }
695                         };
696                         inst.dpDiv.zIndex($(input).zIndex()+1);
697                         $.datepicker._datepickerShowing = true;
698                         if ($.effects && $.effects[showAnim])
699                                 inst.dpDiv.show(showAnim, $.datepicker._get(inst, 'showOptions'), duration, postProcess);
700                         else
701                                 inst.dpDiv[showAnim || 'show']((showAnim ? duration : null), postProcess);
702                         if (!showAnim || !duration)
703                                 postProcess();
704                         if (inst.input.is(':visible') && !inst.input.is(':disabled'))
705                                 inst.input.focus();
706                         $.datepicker._curInst = inst;
707                 }
708         },
710         /* Generate the date picker content. */
711         _updateDatepicker: function(inst) {
712                 var self = this;
713                 self.maxRows = 4; //Reset the max number of rows being displayed (see #7043)
714                 var borders = $.datepicker._getBorders(inst.dpDiv);
715                 instActive = inst; // for delegate hover events
716                 inst.dpDiv.empty().append(this._generateHTML(inst));
717                 this._attachHandlers(inst);
718                 var cover = inst.dpDiv.find('iframe.ui-datepicker-cover'); // IE6- only
719                 if( !!cover.length ){ //avoid call to outerXXXX() when not in IE6
720                         cover.css({left: -borders[0], top: -borders[1], width: inst.dpDiv.outerWidth(), height: inst.dpDiv.outerHeight()})
721                 }
722                 inst.dpDiv.find('.' + this._dayOverClass + ' a').mouseover();
723                 var numMonths = this._getNumberOfMonths(inst);
724                 var cols = numMonths[1];
725                 var width = 17;
726                 inst.dpDiv.removeClass('ui-datepicker-multi-2 ui-datepicker-multi-3 ui-datepicker-multi-4').width('');
727                 if (cols > 1)
728                         inst.dpDiv.addClass('ui-datepicker-multi-' + cols).css('width', (width * cols) + 'em');
729                 inst.dpDiv[(numMonths[0] != 1 || numMonths[1] != 1 ? 'add' : 'remove') +
730                         'Class']('ui-datepicker-multi');
731                 inst.dpDiv[(this._get(inst, 'isRTL') ? 'add' : 'remove') +
732                         'Class']('ui-datepicker-rtl');
733                 if (inst == $.datepicker._curInst && $.datepicker._datepickerShowing && inst.input &&
734                                 // #6694 - don't focus the input if it's already focused
735                                 // this breaks the change event in IE
736                                 inst.input.is(':visible') && !inst.input.is(':disabled') && inst.input[0] != document.activeElement)
737                         inst.input.focus();
738                 // deffered render of the years select (to avoid flashes on Firefox) 
739                 if( inst.yearshtml ){
740                         var origyearshtml = inst.yearshtml;
741                         setTimeout(function(){
742                                 //assure that inst.yearshtml didn't change.
743                                 if( origyearshtml === inst.yearshtml && inst.yearshtml ){
744                                         inst.dpDiv.find('select.ui-datepicker-year:first').replaceWith(inst.yearshtml);
745                                 }
746                                 origyearshtml = inst.yearshtml = null;
747                         }, 0);
748                 }
749         },
751         /* Retrieve the size of left and top borders for an element.
752            @param  elem  (jQuery object) the element of interest
753            @return  (number[2]) the left and top borders */
754         _getBorders: function(elem) {
755                 var convert = function(value) {
756                         return {thin: 1, medium: 2, thick: 3}[value] || value;
757                 };
758                 return [parseFloat(convert(elem.css('border-left-width'))),
759                         parseFloat(convert(elem.css('border-top-width')))];
760         },
762         /* Check positioning to remain on screen. */
763         _checkOffset: function(inst, offset, isFixed) {
764                 var dpWidth = inst.dpDiv.outerWidth();
765                 var dpHeight = inst.dpDiv.outerHeight();
766                 var inputWidth = inst.input ? inst.input.outerWidth() : 0;
767                 var inputHeight = inst.input ? inst.input.outerHeight() : 0;
768                 var viewWidth = document.documentElement.clientWidth + (isFixed ? 0 : $(document).scrollLeft());
769                 var viewHeight = document.documentElement.clientHeight + (isFixed ? 0 : $(document).scrollTop());
771                 offset.left -= (this._get(inst, 'isRTL') ? (dpWidth - inputWidth) : 0);
772                 offset.left -= (isFixed && offset.left == inst.input.offset().left) ? $(document).scrollLeft() : 0;
773                 offset.top -= (isFixed && offset.top == (inst.input.offset().top + inputHeight)) ? $(document).scrollTop() : 0;
775                 // now check if datepicker is showing outside window viewport - move to a better place if so.
776                 offset.left -= Math.min(offset.left, (offset.left + dpWidth > viewWidth && viewWidth > dpWidth) ?
777                         Math.abs(offset.left + dpWidth - viewWidth) : 0);
778                 offset.top -= Math.min(offset.top, (offset.top + dpHeight > viewHeight && viewHeight > dpHeight) ?
779                         Math.abs(dpHeight + inputHeight) : 0);
781                 return offset;
782         },
784         /* Find an object's position on the screen. */
785         _findPos: function(obj) {
786                 var inst = this._getInst(obj);
787                 var isRTL = this._get(inst, 'isRTL');
788         while (obj && (obj.type == 'hidden' || obj.nodeType != 1 || $.expr.filters.hidden(obj))) {
789             obj = obj[isRTL ? 'previousSibling' : 'nextSibling'];
790         }
791         var position = $(obj).offset();
792             return [position.left, position.top];
793         },
795         /* Hide the date picker from view.
796            @param  input  element - the input field attached to the date picker */
797         _hideDatepicker: function(input) {
798                 var inst = this._curInst;
799                 if (!inst || (input && inst != $.data(input, PROP_NAME)))
800                         return;
801                 if (this._datepickerShowing) {
802                         var showAnim = this._get(inst, 'showAnim');
803                         var duration = this._get(inst, 'duration');
804                         var postProcess = function() {
805                                 $.datepicker._tidyDialog(inst);
806                         };
807                         if ($.effects && $.effects[showAnim])
808                                 inst.dpDiv.hide(showAnim, $.datepicker._get(inst, 'showOptions'), duration, postProcess);
809                         else
810                                 inst.dpDiv[(showAnim == 'slideDown' ? 'slideUp' :
811                                         (showAnim == 'fadeIn' ? 'fadeOut' : 'hide'))]((showAnim ? duration : null), postProcess);
812                         if (!showAnim)
813                                 postProcess();
814                         this._datepickerShowing = false;
815                         var onClose = this._get(inst, 'onClose');
816                         if (onClose)
817                                 onClose.apply((inst.input ? inst.input[0] : null),
818                                         [(inst.input ? inst.input.val() : ''), inst]);
819                         this._lastInput = null;
820                         if (this._inDialog) {
821                                 this._dialogInput.css({ position: 'absolute', left: '0', top: '-100px' });
822                                 if ($.blockUI) {
823                                         $.unblockUI();
824                                         $('body').append(this.dpDiv);
825                                 }
826                         }
827                         this._inDialog = false;
828                 }
829         },
831         /* Tidy up after a dialog display. */
832         _tidyDialog: function(inst) {
833                 inst.dpDiv.removeClass(this._dialogClass).unbind('.ui-datepicker-calendar');
834         },
836         /* Close date picker if clicked elsewhere. */
837         _checkExternalClick: function(event) {
838                 if (!$.datepicker._curInst)
839                         return;
841                 var $target = $(event.target),
842                         inst = $.datepicker._getInst($target[0]);
844                 if ( ( ( $target[0].id != $.datepicker._mainDivId &&
845                                 $target.parents('#' + $.datepicker._mainDivId).length == 0 &&
846                                 !$target.hasClass($.datepicker.markerClassName) &&
847                                 !$target.closest("." + $.datepicker._triggerClass).length &&
848                                 $.datepicker._datepickerShowing && !($.datepicker._inDialog && $.blockUI) ) ) ||
849                         ( $target.hasClass($.datepicker.markerClassName) && $.datepicker._curInst != inst ) )
850                         $.datepicker._hideDatepicker();
851         },
853         /* Adjust one of the date sub-fields. */
854         _adjustDate: function(id, offset, period) {
855                 var target = $(id);
856                 var inst = this._getInst(target[0]);
857                 if (this._isDisabledDatepicker(target[0])) {
858                         return;
859                 }
860                 this._adjustInstDate(inst, offset +
861                         (period == 'M' ? this._get(inst, 'showCurrentAtPos') : 0), // undo positioning
862                         period);
863                 this._updateDatepicker(inst);
864         },
866         /* Action for current link. */
867         _gotoToday: function(id) {
868                 var target = $(id);
869                 var inst = this._getInst(target[0]);
870                 if (this._get(inst, 'gotoCurrent') && inst.currentDay) {
871                         inst.selectedDay = inst.currentDay;
872                         inst.drawMonth = inst.selectedMonth = inst.currentMonth;
873                         inst.drawYear = inst.selectedYear = inst.currentYear;
874                 }
875                 else {
876                         var date = new Date();
877                         inst.selectedDay = date.getDate();
878                         inst.drawMonth = inst.selectedMonth = date.getMonth();
879                         inst.drawYear = inst.selectedYear = date.getFullYear();
880                 }
881                 this._notifyChange(inst);
882                 this._adjustDate(target);
883         },
885         /* Action for selecting a new month/year. */
886         _selectMonthYear: function(id, select, period) {
887                 var target = $(id);
888                 var inst = this._getInst(target[0]);
889                 inst['selected' + (period == 'M' ? 'Month' : 'Year')] =
890                 inst['draw' + (period == 'M' ? 'Month' : 'Year')] =
891                         parseInt(select.options[select.selectedIndex].value,10);
892                 this._notifyChange(inst);
893                 this._adjustDate(target);
894         },
896         /* Action for selecting a day. */
897         _selectDay: function(id, month, year, td) {
898                 var target = $(id);
899                 if ($(td).hasClass(this._unselectableClass) || this._isDisabledDatepicker(target[0])) {
900                         return;
901                 }
902                 var inst = this._getInst(target[0]);
903                 inst.selectedDay = inst.currentDay = $('a', td).html();
904                 inst.selectedMonth = inst.currentMonth = month;
905                 inst.selectedYear = inst.currentYear = year;
906                 this._selectDate(id, this._formatDate(inst,
907                         inst.currentDay, inst.currentMonth, inst.currentYear));
908         },
910         /* Erase the input field and hide the date picker. */
911         _clearDate: function(id) {
912                 var target = $(id);
913                 var inst = this._getInst(target[0]);
914                 this._selectDate(target, '');
915         },
917         /* Update the input field with the selected date. */
918         _selectDate: function(id, dateStr) {
919                 var target = $(id);
920                 var inst = this._getInst(target[0]);
921                 dateStr = (dateStr != null ? dateStr : this._formatDate(inst));
922                 if (inst.input)
923                         inst.input.val(dateStr);
924                 this._updateAlternate(inst);
925                 var onSelect = this._get(inst, 'onSelect');
926                 if (onSelect)
927                         onSelect.apply((inst.input ? inst.input[0] : null), [dateStr, inst]);  // trigger custom callback
928                 else if (inst.input)
929                         inst.input.trigger('change'); // fire the change event
930                 if (inst.inline)
931                         this._updateDatepicker(inst);
932                 else {
933                         this._hideDatepicker();
934                         this._lastInput = inst.input[0];
935                         if (typeof(inst.input[0]) != 'object')
936                                 inst.input.focus(); // restore focus
937                         this._lastInput = null;
938                 }
939         },
941         /* Update any alternate field to synchronise with the main field. */
942         _updateAlternate: function(inst) {
943                 var altField = this._get(inst, 'altField');
944                 if (altField) { // update alternate field too
945                         var altFormat = this._get(inst, 'altFormat') || this._get(inst, 'dateFormat');
946                         var date = this._getDate(inst);
947                         var dateStr = this.formatDate(altFormat, date, this._getFormatConfig(inst));
948                         $(altField).each(function() { $(this).val(dateStr); });
949                 }
950         },
952         /* Set as beforeShowDay function to prevent selection of weekends.
953            @param  date  Date - the date to customise
954            @return [boolean, string] - is this date selectable?, what is its CSS class? */
955         noWeekends: function(date) {
956                 var day = date.getDay();
957                 return [(day > 0 && day < 6), ''];
958         },
960         /* Set as calculateWeek to determine the week of the year based on the ISO 8601 definition.
961            @param  date  Date - the date to get the week for
962            @return  number - the number of the week within the year that contains this date */
963         iso8601Week: function(date) {
964                 var checkDate = new Date(date.getTime());
965                 // Find Thursday of this week starting on Monday
966                 checkDate.setDate(checkDate.getDate() + 4 - (checkDate.getDay() || 7));
967                 var time = checkDate.getTime();
968                 checkDate.setMonth(0); // Compare with Jan 1
969                 checkDate.setDate(1);
970                 return Math.floor(Math.round((time - checkDate) / 86400000) / 7) + 1;
971         },
973         /* Parse a string value into a date object.
974            See formatDate below for the possible formats.
976            @param  format    string - the expected format of the date
977            @param  value     string - the date in the above format
978            @param  settings  Object - attributes include:
979                              shortYearCutoff  number - the cutoff year for determining the century (optional)
980                              dayNamesShort    string[7] - abbreviated names of the days from Sunday (optional)
981                              dayNames         string[7] - names of the days from Sunday (optional)
982                              monthNamesShort  string[12] - abbreviated names of the months (optional)
983                              monthNames       string[12] - names of the months (optional)
984            @return  Date - the extracted date value or null if value is blank */
985         parseDate: function (format, value, settings) {
986                 if (format == null || value == null)
987                         throw 'Invalid arguments';
988                 value = (typeof value == 'object' ? value.toString() : value + '');
989                 if (value == '')
990                         return null;
991                 var shortYearCutoff = (settings ? settings.shortYearCutoff : null) || this._defaults.shortYearCutoff;
992                 shortYearCutoff = (typeof shortYearCutoff != 'string' ? shortYearCutoff :
993                                 new Date().getFullYear() % 100 + parseInt(shortYearCutoff, 10));
994                 var dayNamesShort = (settings ? settings.dayNamesShort : null) || this._defaults.dayNamesShort;
995                 var dayNames = (settings ? settings.dayNames : null) || this._defaults.dayNames;
996                 var monthNamesShort = (settings ? settings.monthNamesShort : null) || this._defaults.monthNamesShort;
997                 var monthNames = (settings ? settings.monthNames : null) || this._defaults.monthNames;
998                 var year = -1;
999                 var month = -1;
1000                 var day = -1;
1001                 var doy = -1;
1002                 var literal = false;
1003                 // Check whether a format character is doubled
1004                 var lookAhead = function(match) {
1005                         var matches = (iFormat + 1 < format.length && format.charAt(iFormat + 1) == match);
1006                         if (matches)
1007                                 iFormat++;
1008                         return matches;
1009                 };
1010                 // Extract a number from the string value
1011                 var getNumber = function(match) {
1012                         var isDoubled = lookAhead(match);
1013                         var size = (match == '@' ? 14 : (match == '!' ? 20 :
1014                                 (match == 'y' && isDoubled ? 4 : (match == 'o' ? 3 : 2))));
1015                         var digits = new RegExp('^\\d{1,' + size + '}');
1016                         var num = value.substring(iValue).match(digits);
1017                         if (!num)
1018                                 throw 'Missing number at position ' + iValue;
1019                         iValue += num[0].length;
1020                         return parseInt(num[0], 10);
1021                 };
1022                 // Extract a name from the string value and convert to an index
1023                 var getName = function(match, shortNames, longNames) {
1024                         var names = $.map(lookAhead(match) ? longNames : shortNames, function (v, k) {
1025                                 return [ [k, v] ];
1026                         }).sort(function (a, b) {
1027                                 return -(a[1].length - b[1].length);
1028                         });
1029                         var index = -1;
1030                         $.each(names, function (i, pair) {
1031                                 var name = pair[1];
1032                                 if (value.substr(iValue, name.length).toLowerCase() == name.toLowerCase()) {
1033                                         index = pair[0];
1034                                         iValue += name.length;
1035                                         return false;
1036                                 }
1037                         });
1038                         if (index != -1)
1039                                 return index + 1;
1040                         else
1041                                 throw 'Unknown name at position ' + iValue;
1042                 };
1043                 // Confirm that a literal character matches the string value
1044                 var checkLiteral = function() {
1045                         if (value.charAt(iValue) != format.charAt(iFormat))
1046                                 throw 'Unexpected literal at position ' + iValue;
1047                         iValue++;
1048                 };
1049                 var iValue = 0;
1050                 for (var iFormat = 0; iFormat < format.length; iFormat++) {
1051                         if (literal)
1052                                 if (format.charAt(iFormat) == "'" && !lookAhead("'"))
1053                                         literal = false;
1054                                 else
1055                                         checkLiteral();
1056                         else
1057                                 switch (format.charAt(iFormat)) {
1058                                         case 'd':
1059                                                 day = getNumber('d');
1060                                                 break;
1061                                         case 'D':
1062                                                 getName('D', dayNamesShort, dayNames);
1063                                                 break;
1064                                         case 'o':
1065                                                 doy = getNumber('o');
1066                                                 break;
1067                                         case 'm':
1068                                                 month = getNumber('m');
1069                                                 break;
1070                                         case 'M':
1071                                                 month = getName('M', monthNamesShort, monthNames);
1072                                                 break;
1073                                         case 'y':
1074                                                 year = getNumber('y');
1075                                                 break;
1076                                         case '@':
1077                                                 var date = new Date(getNumber('@'));
1078                                                 year = date.getFullYear();
1079                                                 month = date.getMonth() + 1;
1080                                                 day = date.getDate();
1081                                                 break;
1082                                         case '!':
1083                                                 var date = new Date((getNumber('!') - this._ticksTo1970) / 10000);
1084                                                 year = date.getFullYear();
1085                                                 month = date.getMonth() + 1;
1086                                                 day = date.getDate();
1087                                                 break;
1088                                         case "'":
1089                                                 if (lookAhead("'"))
1090                                                         checkLiteral();
1091                                                 else
1092                                                         literal = true;
1093                                                 break;
1094                                         default:
1095                                                 checkLiteral();
1096                                 }
1097                 }
1098                 if (iValue < value.length){
1099                         throw "Extra/unparsed characters found in date: " + value.substring(iValue);
1100                 }
1101                 if (year == -1)
1102                         year = new Date().getFullYear();
1103                 else if (year < 100)
1104                         year += new Date().getFullYear() - new Date().getFullYear() % 100 +
1105                                 (year <= shortYearCutoff ? 0 : -100);
1106                 if (doy > -1) {
1107                         month = 1;
1108                         day = doy;
1109                         do {
1110                                 var dim = this._getDaysInMonth(year, month - 1);
1111                                 if (day <= dim)
1112                                         break;
1113                                 month++;
1114                                 day -= dim;
1115                         } while (true);
1116                 }
1117                 var date = this._daylightSavingAdjust(new Date(year, month - 1, day));
1118                 if (date.getFullYear() != year || date.getMonth() + 1 != month || date.getDate() != day)
1119                         throw 'Invalid date'; // E.g. 31/02/00
1120                 return date;
1121         },
1123         /* Standard date formats. */
1124         ATOM: 'yy-mm-dd', // RFC 3339 (ISO 8601)
1125         COOKIE: 'D, dd M yy',
1126         ISO_8601: 'yy-mm-dd',
1127         RFC_822: 'D, d M y',
1128         RFC_850: 'DD, dd-M-y',
1129         RFC_1036: 'D, d M y',
1130         RFC_1123: 'D, d M yy',
1131         RFC_2822: 'D, d M yy',
1132         RSS: 'D, d M y', // RFC 822
1133         TICKS: '!',
1134         TIMESTAMP: '@',
1135         W3C: 'yy-mm-dd', // ISO 8601
1137         _ticksTo1970: (((1970 - 1) * 365 + Math.floor(1970 / 4) - Math.floor(1970 / 100) +
1138                 Math.floor(1970 / 400)) * 24 * 60 * 60 * 10000000),
1140         /* Format a date object into a string value.
1141            The format can be combinations of the following:
1142            d  - day of month (no leading zero)
1143            dd - day of month (two digit)
1144            o  - day of year (no leading zeros)
1145            oo - day of year (three digit)
1146            D  - day name short
1147            DD - day name long
1148            m  - month of year (no leading zero)
1149            mm - month of year (two digit)
1150            M  - month name short
1151            MM - month name long
1152            y  - year (two digit)
1153            yy - year (four digit)
1154            @ - Unix timestamp (ms since 01/01/1970)
1155            ! - Windows ticks (100ns since 01/01/0001)
1156            '...' - literal text
1157            '' - single quote
1159            @param  format    string - the desired format of the date
1160            @param  date      Date - the date value to format
1161            @param  settings  Object - attributes include:
1162                              dayNamesShort    string[7] - abbreviated names of the days from Sunday (optional)
1163                              dayNames         string[7] - names of the days from Sunday (optional)
1164                              monthNamesShort  string[12] - abbreviated names of the months (optional)
1165                              monthNames       string[12] - names of the months (optional)
1166            @return  string - the date in the above format */
1167         formatDate: function (format, date, settings) {
1168                 if (!date)
1169                         return '';
1170                 var dayNamesShort = (settings ? settings.dayNamesShort : null) || this._defaults.dayNamesShort;
1171                 var dayNames = (settings ? settings.dayNames : null) || this._defaults.dayNames;
1172                 var monthNamesShort = (settings ? settings.monthNamesShort : null) || this._defaults.monthNamesShort;
1173                 var monthNames = (settings ? settings.monthNames : null) || this._defaults.monthNames;
1174                 // Check whether a format character is doubled
1175                 var lookAhead = function(match) {
1176                         var matches = (iFormat + 1 < format.length && format.charAt(iFormat + 1) == match);
1177                         if (matches)
1178                                 iFormat++;
1179                         return matches;
1180                 };
1181                 // Format a number, with leading zero if necessary
1182                 var formatNumber = function(match, value, len) {
1183                         var num = '' + value;
1184                         if (lookAhead(match))
1185                                 while (num.length < len)
1186                                         num = '0' + num;
1187                         return num;
1188                 };
1189                 // Format a name, short or long as requested
1190                 var formatName = function(match, value, shortNames, longNames) {
1191                         return (lookAhead(match) ? longNames[value] : shortNames[value]);
1192                 };
1193                 var output = '';
1194                 var literal = false;
1195                 if (date)
1196                         for (var iFormat = 0; iFormat < format.length; iFormat++) {
1197                                 if (literal)
1198                                         if (format.charAt(iFormat) == "'" && !lookAhead("'"))
1199                                                 literal = false;
1200                                         else
1201                                                 output += format.charAt(iFormat);
1202                                 else
1203                                         switch (format.charAt(iFormat)) {
1204                                                 case 'd':
1205                                                         output += formatNumber('d', date.getDate(), 2);
1206                                                         break;
1207                                                 case 'D':
1208                                                         output += formatName('D', date.getDay(), dayNamesShort, dayNames);
1209                                                         break;
1210                                                 case 'o':
1211                                                         output += formatNumber('o',
1212                                                                 Math.round((new Date(date.getFullYear(), date.getMonth(), date.getDate()).getTime() - new Date(date.getFullYear(), 0, 0).getTime()) / 86400000), 3);
1213                                                         break;
1214                                                 case 'm':
1215                                                         output += formatNumber('m', date.getMonth() + 1, 2);
1216                                                         break;
1217                                                 case 'M':
1218                                                         output += formatName('M', date.getMonth(), monthNamesShort, monthNames);
1219                                                         break;
1220                                                 case 'y':
1221                                                         output += (lookAhead('y') ? date.getFullYear() :
1222                                                                 (date.getYear() % 100 < 10 ? '0' : '') + date.getYear() % 100);
1223                                                         break;
1224                                                 case '@':
1225                                                         output += date.getTime();
1226                                                         break;
1227                                                 case '!':
1228                                                         output += date.getTime() * 10000 + this._ticksTo1970;
1229                                                         break;
1230                                                 case "'":
1231                                                         if (lookAhead("'"))
1232                                                                 output += "'";
1233                                                         else
1234                                                                 literal = true;
1235                                                         break;
1236                                                 default:
1237                                                         output += format.charAt(iFormat);
1238                                         }
1239                         }
1240                 return output;
1241         },
1243         /* Extract all possible characters from the date format. */
1244         _possibleChars: function (format) {
1245                 var chars = '';
1246                 var literal = false;
1247                 // Check whether a format character is doubled
1248                 var lookAhead = function(match) {
1249                         var matches = (iFormat + 1 < format.length && format.charAt(iFormat + 1) == match);
1250                         if (matches)
1251                                 iFormat++;
1252                         return matches;
1253                 };
1254                 for (var iFormat = 0; iFormat < format.length; iFormat++)
1255                         if (literal)
1256                                 if (format.charAt(iFormat) == "'" && !lookAhead("'"))
1257                                         literal = false;
1258                                 else
1259                                         chars += format.charAt(iFormat);
1260                         else
1261                                 switch (format.charAt(iFormat)) {
1262                                         case 'd': case 'm': case 'y': case '@':
1263                                                 chars += '0123456789';
1264                                                 break;
1265                                         case 'D': case 'M':
1266                                                 return null; // Accept anything
1267                                         case "'":
1268                                                 if (lookAhead("'"))
1269                                                         chars += "'";
1270                                                 else
1271                                                         literal = true;
1272                                                 break;
1273                                         default:
1274                                                 chars += format.charAt(iFormat);
1275                                 }
1276                 return chars;
1277         },
1279         /* Get a setting value, defaulting if necessary. */
1280         _get: function(inst, name) {
1281                 return inst.settings[name] !== undefined ?
1282                         inst.settings[name] : this._defaults[name];
1283         },
1285         /* Parse existing date and initialise date picker. */
1286         _setDateFromField: function(inst, noDefault) {
1287                 if (inst.input.val() == inst.lastVal) {
1288                         return;
1289                 }
1290                 var dateFormat = this._get(inst, 'dateFormat');
1291                 var dates = inst.lastVal = inst.input ? inst.input.val() : null;
1292                 var date, defaultDate;
1293                 date = defaultDate = this._getDefaultDate(inst);
1294                 var settings = this._getFormatConfig(inst);
1295                 try {
1296                         date = this.parseDate(dateFormat, dates, settings) || defaultDate;
1297                 } catch (event) {
1298                         this.log(event);
1299                         dates = (noDefault ? '' : dates);
1300                 }
1301                 inst.selectedDay = date.getDate();
1302                 inst.drawMonth = inst.selectedMonth = date.getMonth();
1303                 inst.drawYear = inst.selectedYear = date.getFullYear();
1304                 inst.currentDay = (dates ? date.getDate() : 0);
1305                 inst.currentMonth = (dates ? date.getMonth() : 0);
1306                 inst.currentYear = (dates ? date.getFullYear() : 0);
1307                 this._adjustInstDate(inst);
1308         },
1310         /* Retrieve the default date shown on opening. */
1311         _getDefaultDate: function(inst) {
1312                 return this._restrictMinMax(inst,
1313                         this._determineDate(inst, this._get(inst, 'defaultDate'), new Date()));
1314         },
1316         /* A date may be specified as an exact value or a relative one. */
1317         _determineDate: function(inst, date, defaultDate) {
1318                 var offsetNumeric = function(offset) {
1319                         var date = new Date();
1320                         date.setDate(date.getDate() + offset);
1321                         return date;
1322                 };
1323                 var offsetString = function(offset) {
1324                         try {
1325                                 return $.datepicker.parseDate($.datepicker._get(inst, 'dateFormat'),
1326                                         offset, $.datepicker._getFormatConfig(inst));
1327                         }
1328                         catch (e) {
1329                                 // Ignore
1330                         }
1331                         var date = (offset.toLowerCase().match(/^c/) ?
1332                                 $.datepicker._getDate(inst) : null) || new Date();
1333                         var year = date.getFullYear();
1334                         var month = date.getMonth();
1335                         var day = date.getDate();
1336                         var pattern = /([+-]?[0-9]+)\s*(d|D|w|W|m|M|y|Y)?/g;
1337                         var matches = pattern.exec(offset);
1338                         while (matches) {
1339                                 switch (matches[2] || 'd') {
1340                                         case 'd' : case 'D' :
1341                                                 day += parseInt(matches[1],10); break;
1342                                         case 'w' : case 'W' :
1343                                                 day += parseInt(matches[1],10) * 7; break;
1344                                         case 'm' : case 'M' :
1345                                                 month += parseInt(matches[1],10);
1346                                                 day = Math.min(day, $.datepicker._getDaysInMonth(year, month));
1347                                                 break;
1348                                         case 'y': case 'Y' :
1349                                                 year += parseInt(matches[1],10);
1350                                                 day = Math.min(day, $.datepicker._getDaysInMonth(year, month));
1351                                                 break;
1352                                 }
1353                                 matches = pattern.exec(offset);
1354                         }
1355                         return new Date(year, month, day);
1356                 };
1357                 var newDate = (date == null || date === '' ? defaultDate : (typeof date == 'string' ? offsetString(date) :
1358                         (typeof date == 'number' ? (isNaN(date) ? defaultDate : offsetNumeric(date)) : new Date(date.getTime()))));
1359                 newDate = (newDate && newDate.toString() == 'Invalid Date' ? defaultDate : newDate);
1360                 if (newDate) {
1361                         newDate.setHours(0);
1362                         newDate.setMinutes(0);
1363                         newDate.setSeconds(0);
1364                         newDate.setMilliseconds(0);
1365                 }
1366                 return this._daylightSavingAdjust(newDate);
1367         },
1369         /* Handle switch to/from daylight saving.
1370            Hours may be non-zero on daylight saving cut-over:
1371            > 12 when midnight changeover, but then cannot generate
1372            midnight datetime, so jump to 1AM, otherwise reset.
1373            @param  date  (Date) the date to check
1374            @return  (Date) the corrected date */
1375         _daylightSavingAdjust: function(date) {
1376                 if (!date) return null;
1377                 date.setHours(date.getHours() > 12 ? date.getHours() + 2 : 0);
1378                 return date;
1379         },
1381         /* Set the date(s) directly. */
1382         _setDate: function(inst, date, noChange) {
1383                 var clear = !date;
1384                 var origMonth = inst.selectedMonth;
1385                 var origYear = inst.selectedYear;
1386                 var newDate = this._restrictMinMax(inst, this._determineDate(inst, date, new Date()));
1387                 inst.selectedDay = inst.currentDay = newDate.getDate();
1388                 inst.drawMonth = inst.selectedMonth = inst.currentMonth = newDate.getMonth();
1389                 inst.drawYear = inst.selectedYear = inst.currentYear = newDate.getFullYear();
1390                 if ((origMonth != inst.selectedMonth || origYear != inst.selectedYear) && !noChange)
1391                         this._notifyChange(inst);
1392                 this._adjustInstDate(inst);
1393                 if (inst.input) {
1394                         inst.input.val(clear ? '' : this._formatDate(inst));
1395                 }
1396         },
1398         /* Retrieve the date(s) directly. */
1399         _getDate: function(inst) {
1400                 var startDate = (!inst.currentYear || (inst.input && inst.input.val() == '') ? null :
1401                         this._daylightSavingAdjust(new Date(
1402                         inst.currentYear, inst.currentMonth, inst.currentDay)));
1403                         return startDate;
1404         },
1406         /* Attach the onxxx handlers.  These are declared statically so
1407          * they work with static code transformers like Caja.
1408          */
1409         _attachHandlers: function(inst) {
1410                 var stepMonths = this._get(inst, 'stepMonths');
1411                 var id = '#' + inst.id.replace( /\\\\/g, "\\" );
1412                 inst.dpDiv.find('[data-handler]').map(function () {
1413                         var handler = {
1414                                 prev: function () {
1415                                         window['DP_jQuery_' + dpuuid].datepicker._adjustDate(id, -stepMonths, 'M');
1416                                 },
1417                                 next: function () {
1418                                         window['DP_jQuery_' + dpuuid].datepicker._adjustDate(id, +stepMonths, 'M');
1419                                 },
1420                                 hide: function () {
1421                                         window['DP_jQuery_' + dpuuid].datepicker._hideDatepicker();
1422                                 },
1423                                 today: function () {
1424                                         window['DP_jQuery_' + dpuuid].datepicker._gotoToday(id);
1425                                 },
1426                                 selectDay: function () {
1427                                         window['DP_jQuery_' + dpuuid].datepicker._selectDay(id, +this.getAttribute('data-month'), +this.getAttribute('data-year'), this);
1428                                         return false;
1429                                 },
1430                                 selectMonth: function () {
1431                                         window['DP_jQuery_' + dpuuid].datepicker._selectMonthYear(id, this, 'M');
1432                                         return false;
1433                                 },
1434                                 selectYear: function () {
1435                                         window['DP_jQuery_' + dpuuid].datepicker._selectMonthYear(id, this, 'Y');
1436                                         return false;
1437                                 }
1438                         };
1439                         $(this).bind(this.getAttribute('data-event'), handler[this.getAttribute('data-handler')]);
1440                 });
1441         },
1442         
1443         /* Generate the HTML for the current state of the date picker. */
1444         _generateHTML: function(inst) {
1445                 var today = new Date();
1446                 today = this._daylightSavingAdjust(
1447                         new Date(today.getFullYear(), today.getMonth(), today.getDate())); // clear time
1448                 var isRTL = this._get(inst, 'isRTL');
1449                 var showButtonPanel = this._get(inst, 'showButtonPanel');
1450                 var hideIfNoPrevNext = this._get(inst, 'hideIfNoPrevNext');
1451                 var navigationAsDateFormat = this._get(inst, 'navigationAsDateFormat');
1452                 var numMonths = this._getNumberOfMonths(inst);
1453                 var showCurrentAtPos = this._get(inst, 'showCurrentAtPos');
1454                 var stepMonths = this._get(inst, 'stepMonths');
1455                 var isMultiMonth = (numMonths[0] != 1 || numMonths[1] != 1);
1456                 var currentDate = this._daylightSavingAdjust((!inst.currentDay ? new Date(9999, 9, 9) :
1457                         new Date(inst.currentYear, inst.currentMonth, inst.currentDay)));
1458                 var minDate = this._getMinMaxDate(inst, 'min');
1459                 var maxDate = this._getMinMaxDate(inst, 'max');
1460                 var drawMonth = inst.drawMonth - showCurrentAtPos;
1461                 var drawYear = inst.drawYear;
1462                 if (drawMonth < 0) {
1463                         drawMonth += 12;
1464                         drawYear--;
1465                 }
1466                 if (maxDate) {
1467                         var maxDraw = this._daylightSavingAdjust(new Date(maxDate.getFullYear(),
1468                                 maxDate.getMonth() - (numMonths[0] * numMonths[1]) + 1, maxDate.getDate()));
1469                         maxDraw = (minDate && maxDraw < minDate ? minDate : maxDraw);
1470                         while (this._daylightSavingAdjust(new Date(drawYear, drawMonth, 1)) > maxDraw) {
1471                                 drawMonth--;
1472                                 if (drawMonth < 0) {
1473                                         drawMonth = 11;
1474                                         drawYear--;
1475                                 }
1476                         }
1477                 }
1478                 inst.drawMonth = drawMonth;
1479                 inst.drawYear = drawYear;
1480                 var prevText = this._get(inst, 'prevText');
1481                 prevText = (!navigationAsDateFormat ? prevText : this.formatDate(prevText,
1482                         this._daylightSavingAdjust(new Date(drawYear, drawMonth - stepMonths, 1)),
1483                         this._getFormatConfig(inst)));
1484                 var prev = (this._canAdjustMonth(inst, -1, drawYear, drawMonth) ?
1485                         '<a class="ui-datepicker-prev ui-corner-all" data-handler="prev" data-event="click"' +
1486                         ' title="' + prevText + '"><span class="ui-icon ui-icon-circle-triangle-' + ( isRTL ? 'e' : 'w') + '">' + prevText + '</span></a>' :
1487                         (hideIfNoPrevNext ? '' : '<a class="ui-datepicker-prev ui-corner-all ui-state-disabled" title="'+ prevText +'"><span class="ui-icon ui-icon-circle-triangle-' + ( isRTL ? 'e' : 'w') + '">' + prevText + '</span></a>'));
1488                 var nextText = this._get(inst, 'nextText');
1489                 nextText = (!navigationAsDateFormat ? nextText : this.formatDate(nextText,
1490                         this._daylightSavingAdjust(new Date(drawYear, drawMonth + stepMonths, 1)),
1491                         this._getFormatConfig(inst)));
1492                 var next = (this._canAdjustMonth(inst, +1, drawYear, drawMonth) ?
1493                         '<a class="ui-datepicker-next ui-corner-all" data-handler="next" data-event="click"' +
1494                         ' title="' + nextText + '"><span class="ui-icon ui-icon-circle-triangle-' + ( isRTL ? 'w' : 'e') + '">' + nextText + '</span></a>' :
1495                         (hideIfNoPrevNext ? '' : '<a class="ui-datepicker-next ui-corner-all ui-state-disabled" title="'+ nextText + '"><span class="ui-icon ui-icon-circle-triangle-' + ( isRTL ? 'w' : 'e') + '">' + nextText + '</span></a>'));
1496                 var currentText = this._get(inst, 'currentText');
1497                 var gotoDate = (this._get(inst, 'gotoCurrent') && inst.currentDay ? currentDate : today);
1498                 currentText = (!navigationAsDateFormat ? currentText :
1499                         this.formatDate(currentText, gotoDate, this._getFormatConfig(inst)));
1500                 var controls = (!inst.inline ? '<button type="button" class="ui-datepicker-close ui-state-default ui-priority-primary ui-corner-all" data-handler="hide" data-event="click">' +
1501                         this._get(inst, 'closeText') + '</button>' : '');
1502                 var buttonPanel = (showButtonPanel) ? '<div class="ui-datepicker-buttonpane ui-widget-content">' + (isRTL ? controls : '') +
1503                         (this._isInRange(inst, gotoDate) ? '<button type="button" class="ui-datepicker-current ui-state-default ui-priority-secondary ui-corner-all" data-handler="today" data-event="click"' +
1504                         '>' + currentText + '</button>' : '') + (isRTL ? '' : controls) + '</div>' : '';
1505                 var firstDay = parseInt(this._get(inst, 'firstDay'),10);
1506                 firstDay = (isNaN(firstDay) ? 0 : firstDay);
1507                 var showWeek = this._get(inst, 'showWeek');
1508                 var dayNames = this._get(inst, 'dayNames');
1509                 var dayNamesShort = this._get(inst, 'dayNamesShort');
1510                 var dayNamesMin = this._get(inst, 'dayNamesMin');
1511                 var monthNames = this._get(inst, 'monthNames');
1512                 var monthNamesShort = this._get(inst, 'monthNamesShort');
1513                 var beforeShowDay = this._get(inst, 'beforeShowDay');
1514                 var showOtherMonths = this._get(inst, 'showOtherMonths');
1515                 var selectOtherMonths = this._get(inst, 'selectOtherMonths');
1516                 var calculateWeek = this._get(inst, 'calculateWeek') || this.iso8601Week;
1517                 var defaultDate = this._getDefaultDate(inst);
1518                 var html = '';
1519                 for (var row = 0; row < numMonths[0]; row++) {
1520                         var group = '';
1521                         this.maxRows = 4;
1522                         for (var col = 0; col < numMonths[1]; col++) {
1523                                 var selectedDate = this._daylightSavingAdjust(new Date(drawYear, drawMonth, inst.selectedDay));
1524                                 var cornerClass = ' ui-corner-all';
1525                                 var calender = '';
1526                                 if (isMultiMonth) {
1527                                         calender += '<div class="ui-datepicker-group';
1528                                         if (numMonths[1] > 1)
1529                                                 switch (col) {
1530                                                         case 0: calender += ' ui-datepicker-group-first';
1531                                                                 cornerClass = ' ui-corner-' + (isRTL ? 'right' : 'left'); break;
1532                                                         case numMonths[1]-1: calender += ' ui-datepicker-group-last';
1533                                                                 cornerClass = ' ui-corner-' + (isRTL ? 'left' : 'right'); break;
1534                                                         default: calender += ' ui-datepicker-group-middle'; cornerClass = ''; break;
1535                                                 }
1536                                         calender += '">';
1537                                 }
1538                                 calender += '<div class="ui-datepicker-header ui-widget-header ui-helper-clearfix' + cornerClass + '">' +
1539                                         (/all|left/.test(cornerClass) && row == 0 ? (isRTL ? next : prev) : '') +
1540                                         (/all|right/.test(cornerClass) && row == 0 ? (isRTL ? prev : next) : '') +
1541                                         this._generateMonthYearHeader(inst, drawMonth, drawYear, minDate, maxDate,
1542                                         row > 0 || col > 0, monthNames, monthNamesShort) + // draw month headers
1543                                         '</div><table class="ui-datepicker-calendar"><thead>' +
1544                                         '<tr>';
1545                                 var thead = (showWeek ? '<th class="ui-datepicker-week-col">' + this._get(inst, 'weekHeader') + '</th>' : '');
1546                                 for (var dow = 0; dow < 7; dow++) { // days of the week
1547                                         var day = (dow + firstDay) % 7;
1548                                         thead += '<th' + ((dow + firstDay + 6) % 7 >= 5 ? ' class="ui-datepicker-week-end"' : '') + '>' +
1549                                                 '<span title="' + dayNames[day] + '">' + dayNamesMin[day] + '</span></th>';
1550                                 }
1551                                 calender += thead + '</tr></thead><tbody>';
1552                                 var daysInMonth = this._getDaysInMonth(drawYear, drawMonth);
1553                                 if (drawYear == inst.selectedYear && drawMonth == inst.selectedMonth)
1554                                         inst.selectedDay = Math.min(inst.selectedDay, daysInMonth);
1555                                 var leadDays = (this._getFirstDayOfMonth(drawYear, drawMonth) - firstDay + 7) % 7;
1556                                 var curRows = Math.ceil((leadDays + daysInMonth) / 7); // calculate the number of rows to generate
1557                                 var numRows = (isMultiMonth ? this.maxRows > curRows ? this.maxRows : curRows : curRows); //If multiple months, use the higher number of rows (see #7043)
1558                                 this.maxRows = numRows;
1559                                 var printDate = this._daylightSavingAdjust(new Date(drawYear, drawMonth, 1 - leadDays));
1560                                 for (var dRow = 0; dRow < numRows; dRow++) { // create date picker rows
1561                                         calender += '<tr>';
1562                                         var tbody = (!showWeek ? '' : '<td class="ui-datepicker-week-col">' +
1563                                                 this._get(inst, 'calculateWeek')(printDate) + '</td>');
1564                                         for (var dow = 0; dow < 7; dow++) { // create date picker days
1565                                                 var daySettings = (beforeShowDay ?
1566                                                         beforeShowDay.apply((inst.input ? inst.input[0] : null), [printDate]) : [true, '']);
1567                                                 var otherMonth = (printDate.getMonth() != drawMonth);
1568                                                 var unselectable = (otherMonth && !selectOtherMonths) || !daySettings[0] ||
1569                                                         (minDate && printDate < minDate) || (maxDate && printDate > maxDate);
1570                                                 tbody += '<td class="' +
1571                                                         ((dow + firstDay + 6) % 7 >= 5 ? ' ui-datepicker-week-end' : '') + // highlight weekends
1572                                                         (otherMonth ? ' ui-datepicker-other-month' : '') + // highlight days from other months
1573                                                         ((printDate.getTime() == selectedDate.getTime() && drawMonth == inst.selectedMonth && inst._keyEvent) || // user pressed key
1574                                                         (defaultDate.getTime() == printDate.getTime() && defaultDate.getTime() == selectedDate.getTime()) ?
1575                                                         // or defaultDate is current printedDate and defaultDate is selectedDate
1576                                                         ' ' + this._dayOverClass : '') + // highlight selected day
1577                                                         (unselectable ? ' ' + this._unselectableClass + ' ui-state-disabled': '') +  // highlight unselectable days
1578                                                         (otherMonth && !showOtherMonths ? '' : ' ' + daySettings[1] + // highlight custom dates
1579                                                         (printDate.getTime() == currentDate.getTime() ? ' ' + this._currentClass : '') + // highlight selected day
1580                                                         (printDate.getTime() == today.getTime() ? ' ui-datepicker-today' : '')) + '"' + // highlight today (if different)
1581                                                         ((!otherMonth || showOtherMonths) && daySettings[2] ? ' title="' + daySettings[2] + '"' : '') + // cell title
1582                                                         (unselectable ? '' : ' data-handler="selectDay" data-event="click" data-month="' + printDate.getMonth() + '" data-year="' + printDate.getFullYear() + '"') + '>' + // actions
1583                                                         (otherMonth && !showOtherMonths ? '&#xa0;' : // display for other months
1584                                                         (unselectable ? '<span class="ui-state-default">' + printDate.getDate() + '</span>' : '<a class="ui-state-default' +
1585                                                         (printDate.getTime() == today.getTime() ? ' ui-state-highlight' : '') +
1586                                                         (printDate.getTime() == currentDate.getTime() ? ' ui-state-active' : '') + // highlight selected day
1587                                                         (otherMonth ? ' ui-priority-secondary' : '') + // distinguish dates from other months
1588                                                         '" href="#">' + printDate.getDate() + '</a>')) + '</td>'; // display selectable date
1589                                                 printDate.setDate(printDate.getDate() + 1);
1590                                                 printDate = this._daylightSavingAdjust(printDate);
1591                                         }
1592                                         calender += tbody + '</tr>';
1593                                 }
1594                                 drawMonth++;
1595                                 if (drawMonth > 11) {
1596                                         drawMonth = 0;
1597                                         drawYear++;
1598                                 }
1599                                 calender += '</tbody></table>' + (isMultiMonth ? '</div>' + 
1600                                                         ((numMonths[0] > 0 && col == numMonths[1]-1) ? '<div class="ui-datepicker-row-break"></div>' : '') : '');
1601                                 group += calender;
1602                         }
1603                         html += group;
1604                 }
1605                 html += buttonPanel + ($.browser.msie && parseInt($.browser.version,10) < 7 && !inst.inline ?
1606                         '<iframe src="javascript:false;" class="ui-datepicker-cover" frameborder="0"></iframe>' : '');
1607                 inst._keyEvent = false;
1608                 return html;
1609         },
1611         /* Generate the month and year header. */
1612         _generateMonthYearHeader: function(inst, drawMonth, drawYear, minDate, maxDate,
1613                         secondary, monthNames, monthNamesShort) {
1614                 var changeMonth = this._get(inst, 'changeMonth');
1615                 var changeYear = this._get(inst, 'changeYear');
1616                 var showMonthAfterYear = this._get(inst, 'showMonthAfterYear');
1617                 var html = '<div class="ui-datepicker-title">';
1618                 var monthHtml = '';
1619                 // month selection
1620                 if (secondary || !changeMonth)
1621                         monthHtml += '<span class="ui-datepicker-month">' + monthNames[drawMonth] + '</span>';
1622                 else {
1623                         var inMinYear = (minDate && minDate.getFullYear() == drawYear);
1624                         var inMaxYear = (maxDate && maxDate.getFullYear() == drawYear);
1625                         monthHtml += '<select class="ui-datepicker-month" data-handler="selectMonth" data-event="change">';
1626                         for (var month = 0; month < 12; month++) {
1627                                 if ((!inMinYear || month >= minDate.getMonth()) &&
1628                                                 (!inMaxYear || month <= maxDate.getMonth()))
1629                                         monthHtml += '<option value="' + month + '"' +
1630                                                 (month == drawMonth ? ' selected="selected"' : '') +
1631                                                 '>' + monthNamesShort[month] + '</option>';
1632                         }
1633                         monthHtml += '</select>';
1634                 }
1635                 if (!showMonthAfterYear)
1636                         html += monthHtml + (secondary || !(changeMonth && changeYear) ? '&#xa0;' : '');
1637                 // year selection
1638                 if ( !inst.yearshtml ) {
1639                         inst.yearshtml = '';
1640                         if (secondary || !changeYear)
1641                                 html += '<span class="ui-datepicker-year">' + drawYear + '</span>';
1642                         else {
1643                                 // determine range of years to display
1644                                 var years = this._get(inst, 'yearRange').split(':');
1645                                 var thisYear = new Date().getFullYear();
1646                                 var determineYear = function(value) {
1647                                         var year = (value.match(/c[+-].*/) ? drawYear + parseInt(value.substring(1), 10) :
1648                                                 (value.match(/[+-].*/) ? thisYear + parseInt(value, 10) :
1649                                                 parseInt(value, 10)));
1650                                         return (isNaN(year) ? thisYear : year);
1651                                 };
1652                                 var year = determineYear(years[0]);
1653                                 var endYear = Math.max(year, determineYear(years[1] || ''));
1654                                 year = (minDate ? Math.max(year, minDate.getFullYear()) : year);
1655                                 endYear = (maxDate ? Math.min(endYear, maxDate.getFullYear()) : endYear);
1656                                 inst.yearshtml += '<select class="ui-datepicker-year" data-handler="selectYear" data-event="change">';
1657                                 for (; year <= endYear; year++) {
1658                                         inst.yearshtml += '<option value="' + year + '"' +
1659                                                 (year == drawYear ? ' selected="selected"' : '') +
1660                                                 '>' + year + '</option>';
1661                                 }
1662                                 inst.yearshtml += '</select>';
1663                                 
1664                                 html += inst.yearshtml;
1665                                 inst.yearshtml = null;
1666                         }
1667                 }
1668                 html += this._get(inst, 'yearSuffix');
1669                 if (showMonthAfterYear)
1670                         html += (secondary || !(changeMonth && changeYear) ? '&#xa0;' : '') + monthHtml;
1671                 html += '</div>'; // Close datepicker_header
1672                 return html;
1673         },
1675         /* Adjust one of the date sub-fields. */
1676         _adjustInstDate: function(inst, offset, period) {
1677                 var year = inst.drawYear + (period == 'Y' ? offset : 0);
1678                 var month = inst.drawMonth + (period == 'M' ? offset : 0);
1679                 var day = Math.min(inst.selectedDay, this._getDaysInMonth(year, month)) +
1680                         (period == 'D' ? offset : 0);
1681                 var date = this._restrictMinMax(inst,
1682                         this._daylightSavingAdjust(new Date(year, month, day)));
1683                 inst.selectedDay = date.getDate();
1684                 inst.drawMonth = inst.selectedMonth = date.getMonth();
1685                 inst.drawYear = inst.selectedYear = date.getFullYear();
1686                 if (period == 'M' || period == 'Y')
1687                         this._notifyChange(inst);
1688         },
1690         /* Ensure a date is within any min/max bounds. */
1691         _restrictMinMax: function(inst, date) {
1692                 var minDate = this._getMinMaxDate(inst, 'min');
1693                 var maxDate = this._getMinMaxDate(inst, 'max');
1694                 var newDate = (minDate && date < minDate ? minDate : date);
1695                 newDate = (maxDate && newDate > maxDate ? maxDate : newDate);
1696                 return newDate;
1697         },
1699         /* Notify change of month/year. */
1700         _notifyChange: function(inst) {
1701                 var onChange = this._get(inst, 'onChangeMonthYear');
1702                 if (onChange)
1703                         onChange.apply((inst.input ? inst.input[0] : null),
1704                                 [inst.selectedYear, inst.selectedMonth + 1, inst]);
1705         },
1707         /* Determine the number of months to show. */
1708         _getNumberOfMonths: function(inst) {
1709                 var numMonths = this._get(inst, 'numberOfMonths');
1710                 return (numMonths == null ? [1, 1] : (typeof numMonths == 'number' ? [1, numMonths] : numMonths));
1711         },
1713         /* Determine the current maximum date - ensure no time components are set. */
1714         _getMinMaxDate: function(inst, minMax) {
1715                 return this._determineDate(inst, this._get(inst, minMax + 'Date'), null);
1716         },
1718         /* Find the number of days in a given month. */
1719         _getDaysInMonth: function(year, month) {
1720                 return 32 - this._daylightSavingAdjust(new Date(year, month, 32)).getDate();
1721         },
1723         /* Find the day of the week of the first of a month. */
1724         _getFirstDayOfMonth: function(year, month) {
1725                 return new Date(year, month, 1).getDay();
1726         },
1728         /* Determines if we should allow a "next/prev" month display change. */
1729         _canAdjustMonth: function(inst, offset, curYear, curMonth) {
1730                 var numMonths = this._getNumberOfMonths(inst);
1731                 var date = this._daylightSavingAdjust(new Date(curYear,
1732                         curMonth + (offset < 0 ? offset : numMonths[0] * numMonths[1]), 1));
1733                 if (offset < 0)
1734                         date.setDate(this._getDaysInMonth(date.getFullYear(), date.getMonth()));
1735                 return this._isInRange(inst, date);
1736         },
1738         /* Is the given date in the accepted range? */
1739         _isInRange: function(inst, date) {
1740                 var minDate = this._getMinMaxDate(inst, 'min');
1741                 var maxDate = this._getMinMaxDate(inst, 'max');
1742                 return ((!minDate || date.getTime() >= minDate.getTime()) &&
1743                         (!maxDate || date.getTime() <= maxDate.getTime()));
1744         },
1746         /* Provide the configuration settings for formatting/parsing. */
1747         _getFormatConfig: function(inst) {
1748                 var shortYearCutoff = this._get(inst, 'shortYearCutoff');
1749                 shortYearCutoff = (typeof shortYearCutoff != 'string' ? shortYearCutoff :
1750                         new Date().getFullYear() % 100 + parseInt(shortYearCutoff, 10));
1751                 return {shortYearCutoff: shortYearCutoff,
1752                         dayNamesShort: this._get(inst, 'dayNamesShort'), dayNames: this._get(inst, 'dayNames'),
1753                         monthNamesShort: this._get(inst, 'monthNamesShort'), monthNames: this._get(inst, 'monthNames')};
1754         },
1756         /* Format the given date for display. */
1757         _formatDate: function(inst, day, month, year) {
1758                 if (!day) {
1759                         inst.currentDay = inst.selectedDay;
1760                         inst.currentMonth = inst.selectedMonth;
1761                         inst.currentYear = inst.selectedYear;
1762                 }
1763                 var date = (day ? (typeof day == 'object' ? day :
1764                         this._daylightSavingAdjust(new Date(year, month, day))) :
1765                         this._daylightSavingAdjust(new Date(inst.currentYear, inst.currentMonth, inst.currentDay)));
1766                 return this.formatDate(this._get(inst, 'dateFormat'), date, this._getFormatConfig(inst));
1767         }
1771  * Bind hover events for datepicker elements.
1772  * Done via delegate so the binding only occurs once in the lifetime of the parent div.
1773  * Global instActive, set by _updateDatepicker allows the handlers to find their way back to the active picker.
1774  */ 
1775 function bindHover(dpDiv) {
1776         var selector = 'button, .ui-datepicker-prev, .ui-datepicker-next, .ui-datepicker-calendar td a';
1777         return dpDiv.bind('mouseout', function(event) {
1778                         var elem = $( event.target ).closest( selector );
1779                         if ( !elem.length ) {
1780                                 return;
1781                         }
1782                         elem.removeClass( "ui-state-hover ui-datepicker-prev-hover ui-datepicker-next-hover" );
1783                 })
1784                 .bind('mouseover', function(event) {
1785                         var elem = $( event.target ).closest( selector );
1786                         if ($.datepicker._isDisabledDatepicker( instActive.inline ? dpDiv.parent()[0] : instActive.input[0]) ||
1787                                         !elem.length ) {
1788                                 return;
1789                         }
1790                         elem.parents('.ui-datepicker-calendar').find('a').removeClass('ui-state-hover');
1791                         elem.addClass('ui-state-hover');
1792                         if (elem.hasClass('ui-datepicker-prev')) elem.addClass('ui-datepicker-prev-hover');
1793                         if (elem.hasClass('ui-datepicker-next')) elem.addClass('ui-datepicker-next-hover');
1794                 });
1797 /* jQuery extend now ignores nulls! */
1798 function extendRemove(target, props) {
1799         $.extend(target, props);
1800         for (var name in props)
1801                 if (props[name] == null || props[name] == undefined)
1802                         target[name] = props[name];
1803         return target;
1806 /* Determine whether an object is an array. */
1807 function isArray(a) {
1808         return (a && (($.browser.safari && typeof a == 'object' && a.length) ||
1809                 (a.constructor && a.constructor.toString().match(/\Array\(\)/))));
1812 /* Invoke the datepicker functionality.
1813    @param  options  string - a command, optionally followed by additional parameters or
1814                     Object - settings for attaching new datepicker functionality
1815    @return  jQuery object */
1816 $.fn.datepicker = function(options){
1817         
1818         /* Verify an empty collection wasn't passed - Fixes #6976 */
1819         if ( !this.length ) {
1820                 return this;
1821         }
1822         
1823         /* Initialise the date picker. */
1824         if (!$.datepicker.initialized) {
1825                 $(document).mousedown($.datepicker._checkExternalClick).
1826                         find('body').append($.datepicker.dpDiv);
1827                 $.datepicker.initialized = true;
1828         }
1830         var otherArgs = Array.prototype.slice.call(arguments, 1);
1831         if (typeof options == 'string' && (options == 'isDisabled' || options == 'getDate' || options == 'widget'))
1832                 return $.datepicker['_' + options + 'Datepicker'].
1833                         apply($.datepicker, [this[0]].concat(otherArgs));
1834         if (options == 'option' && arguments.length == 2 && typeof arguments[1] == 'string')
1835                 return $.datepicker['_' + options + 'Datepicker'].
1836                         apply($.datepicker, [this[0]].concat(otherArgs));
1837         return this.each(function() {
1838                 typeof options == 'string' ?
1839                         $.datepicker['_' + options + 'Datepicker'].
1840                                 apply($.datepicker, [this].concat(otherArgs)) :
1841                         $.datepicker._attachDatepicker(this, options);
1842         });
1845 $.datepicker = new Datepicker(); // singleton instance
1846 $.datepicker.initialized = false;
1847 $.datepicker.uuid = new Date().getTime();
1848 $.datepicker.version = "1.8.24";
1850 // Workaround for #4055
1851 // Add another global to avoid noConflict issues with inline event handlers
1852 window['DP_jQuery_' + dpuuid] = $;
1854 })(jQuery);