PageRenderTime 113ms CodeModel.GetById 9ms app.highlight 90ms RepoModel.GetById 1ms app.codeStats 0ms

/www/ui/ui.datepicker.js

http://cupsfilter.googlecode.com/
JavaScript | 1490 lines | 1252 code | 61 blank | 177 comment | 402 complexity | 0e1ca3081e893ad40b86d100bb24d64e MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1/*
   2 * jQuery UI Datepicker 1.7.1
   3 *
   4 * Copyright (c) 2009 AUTHORS.txt (http://jqueryui.com/about)
   5 * Dual licensed under the MIT (MIT-LICENSE.txt)
   6 * and GPL (GPL-LICENSE.txt) licenses.
   7 *
   8 * http://docs.jquery.com/UI/Datepicker
   9 *
  10 * Depends:
  11 *	ui.core.js
  12 */
  13
  14(function($) { // hide the namespace
  15
  16$.extend($.ui, { datepicker: { version: "1.7.1" } });
  17
  18var PROP_NAME = 'datepicker';
  19
  20/* Date picker manager.
  21   Use the singleton instance of this class, $.datepicker, to interact with the date picker.
  22   Settings for (groups of) date pickers are maintained in an instance object,
  23   allowing multiple different settings on the same page. */
  24
  25function Datepicker() {
  26	this.debug = false; // Change this to true to start debugging
  27	this._curInst = null; // The current instance in use
  28	this._keyEvent = false; // If the last event was a key event
  29	this._disabledInputs = []; // List of date picker inputs that have been disabled
  30	this._datepickerShowing = false; // True if the popup picker is showing , false if not
  31	this._inDialog = false; // True if showing within a "dialog", false if not
  32	this._mainDivId = 'ui-datepicker-div'; // The ID of the main datepicker division
  33	this._inlineClass = 'ui-datepicker-inline'; // The name of the inline marker class
  34	this._appendClass = 'ui-datepicker-append'; // The name of the append marker class
  35	this._triggerClass = 'ui-datepicker-trigger'; // The name of the trigger marker class
  36	this._dialogClass = 'ui-datepicker-dialog'; // The name of the dialog marker class
  37	this._disableClass = 'ui-datepicker-disabled'; // The name of the disabled covering marker class
  38	this._unselectableClass = 'ui-datepicker-unselectable'; // The name of the unselectable cell marker class
  39	this._currentClass = 'ui-datepicker-current-day'; // The name of the current day marker class
  40	this._dayOverClass = 'ui-datepicker-days-cell-over'; // The name of the day hover marker class
  41	this.regional = []; // Available regional settings, indexed by language code
  42	this.regional[''] = { // Default regional settings
  43		closeText: 'Done', // Display text for close link
  44		prevText: 'Prev', // Display text for previous month link
  45		nextText: 'Next', // Display text for next month link
  46		currentText: 'Today', // Display text for current month link
  47		monthNames: ['January','February','March','April','May','June',
  48			'July','August','September','October','November','December'], // Names of months for drop-down and formatting
  49		monthNamesShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], // For formatting
  50		dayNames: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'], // For formatting
  51		dayNamesShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'], // For formatting
  52		dayNamesMin: ['Su','Mo','Tu','We','Th','Fr','Sa'], // Column headings for days starting at Sunday
  53		dateFormat: 'mm/dd/yy', // See format options on parseDate
  54		firstDay: 0, // The first day of the week, Sun = 0, Mon = 1, ...
  55		isRTL: false // True if right-to-left language, false if left-to-right
  56	};
  57	this._defaults = { // Global defaults for all the date picker instances
  58		showOn: 'focus', // 'focus' for popup on focus,
  59			// 'button' for trigger button, or 'both' for either
  60		showAnim: 'show', // Name of jQuery animation for popup
  61		showOptions: {}, // Options for enhanced animations
  62		defaultDate: null, // Used when field is blank: actual date,
  63			// +/-number for offset from today, null for today
  64		appendText: '', // Display text following the input box, e.g. showing the format
  65		buttonText: '...', // Text for trigger button
  66		buttonImage: '', // URL for trigger button image
  67		buttonImageOnly: false, // True if the image appears alone, false if it appears on a button
  68		hideIfNoPrevNext: false, // True to hide next/previous month links
  69			// if not applicable, false to just disable them
  70		navigationAsDateFormat: false, // True if date formatting applied to prev/today/next links
  71		gotoCurrent: false, // True if today link goes back to current selection instead
  72		changeMonth: false, // True if month can be selected directly, false if only prev/next
  73		changeYear: false, // True if year can be selected directly, false if only prev/next
  74		showMonthAfterYear: false, // True if the year select precedes month, false for month then year
  75		yearRange: '-10:+10', // Range of years to display in drop-down,
  76			// either relative to current year (-nn:+nn) or absolute (nnnn:nnnn)
  77		showOtherMonths: false, // True to show dates in other months, false to leave blank
  78		calculateWeek: this.iso8601Week, // How to calculate the week of the year,
  79			// takes a Date and returns the number of the week for it
  80		shortYearCutoff: '+10', // Short year values < this are in the current century,
  81			// > this are in the previous century,
  82			// string value starting with '+' for current year + value
  83		minDate: null, // The earliest selectable date, or null for no limit
  84		maxDate: null, // The latest selectable date, or null for no limit
  85		duration: 'normal', // Duration of display/closure
  86		beforeShowDay: null, // Function that takes a date and returns an array with
  87			// [0] = true if selectable, false if not, [1] = custom CSS class name(s) or '',
  88			// [2] = cell title (optional), e.g. $.datepicker.noWeekends
  89		beforeShow: null, // Function that takes an input field and
  90			// returns a set of custom settings for the date picker
  91		onSelect: null, // Define a callback function when a date is selected
  92		onChangeMonthYear: null, // Define a callback function when the month or year is changed
  93		onClose: null, // Define a callback function when the datepicker is closed
  94		numberOfMonths: 1, // Number of months to show at a time
  95		showCurrentAtPos: 0, // The position in multipe months at which to show the current month (starting at 0)
  96		stepMonths: 1, // Number of months to step back/forward
  97		stepBigMonths: 12, // Number of months to step back/forward for the big links
  98		altField: '', // Selector for an alternate field to store selected dates into
  99		altFormat: '', // The date format to use for the alternate field
 100		constrainInput: true, // The input is constrained by the current date format
 101		showButtonPanel: false // True to show button panel, false to not show it
 102	};
 103	$.extend(this._defaults, this.regional['']);
 104	this.dpDiv = $('<div id="' + this._mainDivId + '" class="ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all ui-helper-hidden-accessible"></div>');
 105}
 106
 107$.extend(Datepicker.prototype, {
 108	/* Class name added to elements to indicate already configured with a date picker. */
 109	markerClassName: 'hasDatepicker',
 110
 111	/* Debug logging (if enabled). */
 112	log: function () {
 113		if (this.debug)
 114			console.log.apply('', arguments);
 115	},
 116
 117	/* Override the default settings for all instances of the date picker.
 118	   @param  settings  object - the new settings to use as defaults (anonymous object)
 119	   @return the manager object */
 120	setDefaults: function(settings) {
 121		extendRemove(this._defaults, settings || {});
 122		return this;
 123	},
 124
 125	/* Attach the date picker to a jQuery selection.
 126	   @param  target    element - the target input field or division or span
 127	   @param  settings  object - the new settings to use for this date picker instance (anonymous) */
 128	_attachDatepicker: function(target, settings) {
 129		// check for settings on the control itself - in namespace 'date:'
 130		var inlineSettings = null;
 131		for (var attrName in this._defaults) {
 132			var attrValue = target.getAttribute('date:' + attrName);
 133			if (attrValue) {
 134				inlineSettings = inlineSettings || {};
 135				try {
 136					inlineSettings[attrName] = eval(attrValue);
 137				} catch (err) {
 138					inlineSettings[attrName] = attrValue;
 139				}
 140			}
 141		}
 142		var nodeName = target.nodeName.toLowerCase();
 143		var inline = (nodeName == 'div' || nodeName == 'span');
 144		if (!target.id)
 145			target.id = 'dp' + (++this.uuid);
 146		var inst = this._newInst($(target), inline);
 147		inst.settings = $.extend({}, settings || {}, inlineSettings || {});
 148		if (nodeName == 'input') {
 149			this._connectDatepicker(target, inst);
 150		} else if (inline) {
 151			this._inlineDatepicker(target, inst);
 152		}
 153	},
 154
 155	/* Create a new instance object. */
 156	_newInst: function(target, inline) {
 157		var id = target[0].id.replace(/([:\[\]\.])/g, '\\\\$1'); // escape jQuery meta chars
 158		return {id: id, input: target, // associated target
 159			selectedDay: 0, selectedMonth: 0, selectedYear: 0, // current selection
 160			drawMonth: 0, drawYear: 0, // month being drawn
 161			inline: inline, // is datepicker inline or not
 162			dpDiv: (!inline ? this.dpDiv : // presentation div
 163			$('<div class="' + this._inlineClass + ' ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all"></div>'))};
 164	},
 165
 166	/* Attach the date picker to an input field. */
 167	_connectDatepicker: function(target, inst) {
 168		var input = $(target);
 169		inst.trigger = $([]);
 170		if (input.hasClass(this.markerClassName))
 171			return;
 172		var appendText = this._get(inst, 'appendText');
 173		var isRTL = this._get(inst, 'isRTL');
 174		if (appendText)
 175			input[isRTL ? 'before' : 'after']('<span class="' + this._appendClass + '">' + appendText + '</span>');
 176		var showOn = this._get(inst, 'showOn');
 177		if (showOn == 'focus' || showOn == 'both') // pop-up date picker when in the marked field
 178			input.focus(this._showDatepicker);
 179		if (showOn == 'button' || showOn == 'both') { // pop-up date picker when button clicked
 180			var buttonText = this._get(inst, 'buttonText');
 181			var buttonImage = this._get(inst, 'buttonImage');
 182			inst.trigger = $(this._get(inst, 'buttonImageOnly') ?
 183				$('<img/>').addClass(this._triggerClass).
 184					attr({ src: buttonImage, alt: buttonText, title: buttonText }) :
 185				$('<button type="button"></button>').addClass(this._triggerClass).
 186					html(buttonImage == '' ? buttonText : $('<img/>').attr(
 187					{ src:buttonImage, alt:buttonText, title:buttonText })));
 188			input[isRTL ? 'before' : 'after'](inst.trigger);
 189			inst.trigger.click(function() {
 190				if ($.datepicker._datepickerShowing && $.datepicker._lastInput == target)
 191					$.datepicker._hideDatepicker();
 192				else
 193					$.datepicker._showDatepicker(target);
 194				return false;
 195			});
 196		}
 197		input.addClass(this.markerClassName).keydown(this._doKeyDown).keypress(this._doKeyPress).
 198			bind("setData.datepicker", function(event, key, value) {
 199				inst.settings[key] = value;
 200			}).bind("getData.datepicker", function(event, key) {
 201				return this._get(inst, key);
 202			});
 203		$.data(target, PROP_NAME, inst);
 204	},
 205
 206	/* Attach an inline date picker to a div. */
 207	_inlineDatepicker: function(target, inst) {
 208		var divSpan = $(target);
 209		if (divSpan.hasClass(this.markerClassName))
 210			return;
 211		divSpan.addClass(this.markerClassName).append(inst.dpDiv).
 212			bind("setData.datepicker", function(event, key, value){
 213				inst.settings[key] = value;
 214			}).bind("getData.datepicker", function(event, key){
 215				return this._get(inst, key);
 216			});
 217		$.data(target, PROP_NAME, inst);
 218		this._setDate(inst, this._getDefaultDate(inst));
 219		this._updateDatepicker(inst);
 220		this._updateAlternate(inst);
 221	},
 222
 223	/* Pop-up the date picker in a "dialog" box.
 224	   @param  input     element - ignored
 225	   @param  dateText  string - the initial date to display (in the current format)
 226	   @param  onSelect  function - the function(dateText) to call when a date is selected
 227	   @param  settings  object - update the dialog date picker instance's settings (anonymous object)
 228	   @param  pos       int[2] - coordinates for the dialog's position within the screen or
 229	                     event - with x/y coordinates or
 230	                     leave empty for default (screen centre)
 231	   @return the manager object */
 232	_dialogDatepicker: function(input, dateText, onSelect, settings, pos) {
 233		var inst = this._dialogInst; // internal instance
 234		if (!inst) {
 235			var id = 'dp' + (++this.uuid);
 236			this._dialogInput = $('<input type="text" id="' + id +
 237				'" size="1" style="position: absolute; top: -100px;"/>');
 238			this._dialogInput.keydown(this._doKeyDown);
 239			$('body').append(this._dialogInput);
 240			inst = this._dialogInst = this._newInst(this._dialogInput, false);
 241			inst.settings = {};
 242			$.data(this._dialogInput[0], PROP_NAME, inst);
 243		}
 244		extendRemove(inst.settings, settings || {});
 245		this._dialogInput.val(dateText);
 246
 247		this._pos = (pos ? (pos.length ? pos : [pos.pageX, pos.pageY]) : null);
 248		if (!this._pos) {
 249			var browserWidth = window.innerWidth || document.documentElement.clientWidth ||	document.body.clientWidth;
 250			var browserHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
 251			var scrollX = document.documentElement.scrollLeft || document.body.scrollLeft;
 252			var scrollY = document.documentElement.scrollTop || document.body.scrollTop;
 253			this._pos = // should use actual width/height below
 254				[(browserWidth / 2) - 100 + scrollX, (browserHeight / 2) - 150 + scrollY];
 255		}
 256
 257		// move input on screen for focus, but hidden behind dialog
 258		this._dialogInput.css('left', this._pos[0] + 'px').css('top', this._pos[1] + 'px');
 259		inst.settings.onSelect = onSelect;
 260		this._inDialog = true;
 261		this.dpDiv.addClass(this._dialogClass);
 262		this._showDatepicker(this._dialogInput[0]);
 263		if ($.blockUI)
 264			$.blockUI(this.dpDiv);
 265		$.data(this._dialogInput[0], PROP_NAME, inst);
 266		return this;
 267	},
 268
 269	/* Detach a datepicker from its control.
 270	   @param  target    element - the target input field or division or span */
 271	_destroyDatepicker: function(target) {
 272		var $target = $(target);
 273		var inst = $.data(target, PROP_NAME);
 274		if (!$target.hasClass(this.markerClassName)) {
 275			return;
 276		}
 277		var nodeName = target.nodeName.toLowerCase();
 278		$.removeData(target, PROP_NAME);
 279		if (nodeName == 'input') {
 280			inst.trigger.remove();
 281			$target.siblings('.' + this._appendClass).remove().end().
 282				removeClass(this.markerClassName).
 283				unbind('focus', this._showDatepicker).
 284				unbind('keydown', this._doKeyDown).
 285				unbind('keypress', this._doKeyPress);
 286		} else if (nodeName == 'div' || nodeName == 'span')
 287			$target.removeClass(this.markerClassName).empty();
 288	},
 289
 290	/* Enable the date picker to a jQuery selection.
 291	   @param  target    element - the target input field or division or span */
 292	_enableDatepicker: function(target) {
 293		var $target = $(target);
 294		var inst = $.data(target, PROP_NAME);
 295		if (!$target.hasClass(this.markerClassName)) {
 296			return;
 297		}
 298		var nodeName = target.nodeName.toLowerCase();
 299		if (nodeName == 'input') {
 300		target.disabled = false;
 301			inst.trigger.filter("button").
 302			each(function() { this.disabled = false; }).end().
 303				filter("img").
 304				css({opacity: '1.0', cursor: ''});
 305		}
 306		else if (nodeName == 'div' || nodeName == 'span') {
 307			var inline = $target.children('.' + this._inlineClass);
 308			inline.children().removeClass('ui-state-disabled');
 309		}
 310		this._disabledInputs = $.map(this._disabledInputs,
 311			function(value) { return (value == target ? null : value); }); // delete entry
 312	},
 313
 314	/* Disable the date picker to a jQuery selection.
 315	   @param  target    element - the target input field or division or span */
 316	_disableDatepicker: function(target) {
 317		var $target = $(target);
 318		var inst = $.data(target, PROP_NAME);
 319		if (!$target.hasClass(this.markerClassName)) {
 320			return;
 321		}
 322		var nodeName = target.nodeName.toLowerCase();
 323		if (nodeName == 'input') {
 324		target.disabled = true;
 325			inst.trigger.filter("button").
 326			each(function() { this.disabled = true; }).end().
 327				filter("img").
 328				css({opacity: '0.5', cursor: 'default'});
 329		}
 330		else if (nodeName == 'div' || nodeName == 'span') {
 331			var inline = $target.children('.' + this._inlineClass);
 332			inline.children().addClass('ui-state-disabled');
 333		}
 334		this._disabledInputs = $.map(this._disabledInputs,
 335			function(value) { return (value == target ? null : value); }); // delete entry
 336		this._disabledInputs[this._disabledInputs.length] = target;
 337	},
 338
 339	/* Is the first field in a jQuery collection disabled as a datepicker?
 340	   @param  target    element - the target input field or division or span
 341	   @return boolean - true if disabled, false if enabled */
 342	_isDisabledDatepicker: function(target) {
 343		if (!target) {
 344			return false;
 345		}
 346		for (var i = 0; i < this._disabledInputs.length; i++) {
 347			if (this._disabledInputs[i] == target)
 348				return true;
 349		}
 350		return false;
 351	},
 352
 353	/* Retrieve the instance data for the target control.
 354	   @param  target  element - the target input field or division or span
 355	   @return  object - the associated instance data
 356	   @throws  error if a jQuery problem getting data */
 357	_getInst: function(target) {
 358		try {
 359			return $.data(target, PROP_NAME);
 360		}
 361		catch (err) {
 362			throw 'Missing instance data for this datepicker';
 363		}
 364	},
 365
 366	/* Update the settings for a date picker attached to an input field or division.
 367	   @param  target  element - the target input field or division or span
 368	   @param  name    object - the new settings to update or
 369	                   string - the name of the setting to change or
 370	   @param  value   any - the new value for the setting (omit if above is an object) */
 371	_optionDatepicker: function(target, name, value) {
 372		var settings = name || {};
 373		if (typeof name == 'string') {
 374			settings = {};
 375			settings[name] = value;
 376		}
 377		var inst = this._getInst(target);
 378		if (inst) {
 379			if (this._curInst == inst) {
 380				this._hideDatepicker(null);
 381			}
 382			extendRemove(inst.settings, settings);
 383			var date = new Date();
 384			extendRemove(inst, {rangeStart: null, // start of range
 385				endDay: null, endMonth: null, endYear: null, // end of range
 386				selectedDay: date.getDate(), selectedMonth: date.getMonth(),
 387				selectedYear: date.getFullYear(), // starting point
 388				currentDay: date.getDate(), currentMonth: date.getMonth(),
 389				currentYear: date.getFullYear(), // current selection
 390				drawMonth: date.getMonth(), drawYear: date.getFullYear()}); // month being drawn
 391			this._updateDatepicker(inst);
 392		}
 393	},
 394
 395	// change method deprecated
 396	_changeDatepicker: function(target, name, value) {
 397		this._optionDatepicker(target, name, value);
 398	},
 399
 400	/* Redraw the date picker attached to an input field or division.
 401	   @param  target  element - the target input field or division or span */
 402	_refreshDatepicker: function(target) {
 403		var inst = this._getInst(target);
 404		if (inst) {
 405			this._updateDatepicker(inst);
 406		}
 407	},
 408
 409	/* Set the dates for a jQuery selection.
 410	   @param  target   element - the target input field or division or span
 411	   @param  date     Date - the new date
 412	   @param  endDate  Date - the new end date for a range (optional) */
 413	_setDateDatepicker: function(target, date, endDate) {
 414		var inst = this._getInst(target);
 415		if (inst) {
 416			this._setDate(inst, date, endDate);
 417			this._updateDatepicker(inst);
 418			this._updateAlternate(inst);
 419		}
 420	},
 421
 422	/* Get the date(s) for the first entry in a jQuery selection.
 423	   @param  target  element - the target input field or division or span
 424	   @return Date - the current date or
 425	           Date[2] - the current dates for a range */
 426	_getDateDatepicker: function(target) {
 427		var inst = this._getInst(target);
 428		if (inst && !inst.inline)
 429			this._setDateFromField(inst);
 430		return (inst ? this._getDate(inst) : null);
 431	},
 432
 433	/* Handle keystrokes. */
 434	_doKeyDown: function(event) {
 435		var inst = $.datepicker._getInst(event.target);
 436		var handled = true;
 437		var isRTL = inst.dpDiv.is('.ui-datepicker-rtl');
 438		inst._keyEvent = true;
 439		if ($.datepicker._datepickerShowing)
 440			switch (event.keyCode) {
 441				case 9:  $.datepicker._hideDatepicker(null, '');
 442						break; // hide on tab out
 443				case 13: var sel = $('td.' + $.datepicker._dayOverClass +
 444							', td.' + $.datepicker._currentClass, inst.dpDiv);
 445						if (sel[0])
 446							$.datepicker._selectDay(event.target, inst.selectedMonth, inst.selectedYear, sel[0]);
 447						else
 448							$.datepicker._hideDatepicker(null, $.datepicker._get(inst, 'duration'));
 449						return false; // don't submit the form
 450						break; // select the value on enter
 451				case 27: $.datepicker._hideDatepicker(null, $.datepicker._get(inst, 'duration'));
 452						break; // hide on escape
 453				case 33: $.datepicker._adjustDate(event.target, (event.ctrlKey ?
 454							-$.datepicker._get(inst, 'stepBigMonths') :
 455							-$.datepicker._get(inst, 'stepMonths')), 'M');
 456						break; // previous month/year on page up/+ ctrl
 457				case 34: $.datepicker._adjustDate(event.target, (event.ctrlKey ?
 458							+$.datepicker._get(inst, 'stepBigMonths') :
 459							+$.datepicker._get(inst, 'stepMonths')), 'M');
 460						break; // next month/year on page down/+ ctrl
 461				case 35: if (event.ctrlKey || event.metaKey) $.datepicker._clearDate(event.target);
 462						handled = event.ctrlKey || event.metaKey;
 463						break; // clear on ctrl or command +end
 464				case 36: if (event.ctrlKey || event.metaKey) $.datepicker._gotoToday(event.target);
 465						handled = event.ctrlKey || event.metaKey;
 466						break; // current on ctrl or command +home
 467				case 37: if (event.ctrlKey || event.metaKey) $.datepicker._adjustDate(event.target, (isRTL ? +1 : -1), 'D');
 468						handled = event.ctrlKey || event.metaKey;
 469						// -1 day on ctrl or command +left
 470						if (event.originalEvent.altKey) $.datepicker._adjustDate(event.target, (event.ctrlKey ?
 471									-$.datepicker._get(inst, 'stepBigMonths') :
 472									-$.datepicker._get(inst, 'stepMonths')), 'M');
 473						// next month/year on alt +left on Mac
 474						break;
 475				case 38: if (event.ctrlKey || event.metaKey) $.datepicker._adjustDate(event.target, -7, 'D');
 476						handled = event.ctrlKey || event.metaKey;
 477						break; // -1 week on ctrl or command +up
 478				case 39: if (event.ctrlKey || event.metaKey) $.datepicker._adjustDate(event.target, (isRTL ? -1 : +1), 'D');
 479						handled = event.ctrlKey || event.metaKey;
 480						// +1 day on ctrl or command +right
 481						if (event.originalEvent.altKey) $.datepicker._adjustDate(event.target, (event.ctrlKey ?
 482									+$.datepicker._get(inst, 'stepBigMonths') :
 483									+$.datepicker._get(inst, 'stepMonths')), 'M');
 484						// next month/year on alt +right
 485						break;
 486				case 40: if (event.ctrlKey || event.metaKey) $.datepicker._adjustDate(event.target, +7, 'D');
 487						handled = event.ctrlKey || event.metaKey;
 488						break; // +1 week on ctrl or command +down
 489				default: handled = false;
 490			}
 491		else if (event.keyCode == 36 && event.ctrlKey) // display the date picker on ctrl+home
 492			$.datepicker._showDatepicker(this);
 493		else {
 494			handled = false;
 495		}
 496		if (handled) {
 497			event.preventDefault();
 498			event.stopPropagation();
 499		}
 500	},
 501
 502	/* Filter entered characters - based on date format. */
 503	_doKeyPress: function(event) {
 504		var inst = $.datepicker._getInst(event.target);
 505		if ($.datepicker._get(inst, 'constrainInput')) {
 506			var chars = $.datepicker._possibleChars($.datepicker._get(inst, 'dateFormat'));
 507			var chr = String.fromCharCode(event.charCode == undefined ? event.keyCode : event.charCode);
 508			return event.ctrlKey || (chr < ' ' || !chars || chars.indexOf(chr) > -1);
 509		}
 510	},
 511
 512	/* Pop-up the date picker for a given input field.
 513	   @param  input  element - the input field attached to the date picker or
 514	                  event - if triggered by focus */
 515	_showDatepicker: function(input) {
 516		input = input.target || input;
 517		if (input.nodeName.toLowerCase() != 'input') // find from button/image trigger
 518			input = $('input', input.parentNode)[0];
 519		if ($.datepicker._isDisabledDatepicker(input) || $.datepicker._lastInput == input) // already here
 520			return;
 521		var inst = $.datepicker._getInst(input);
 522		var beforeShow = $.datepicker._get(inst, 'beforeShow');
 523		extendRemove(inst.settings, (beforeShow ? beforeShow.apply(input, [input, inst]) : {}));
 524		$.datepicker._hideDatepicker(null, '');
 525		$.datepicker._lastInput = input;
 526		$.datepicker._setDateFromField(inst);
 527		if ($.datepicker._inDialog) // hide cursor
 528			input.value = '';
 529		if (!$.datepicker._pos) { // position below input
 530			$.datepicker._pos = $.datepicker._findPos(input);
 531			$.datepicker._pos[1] += input.offsetHeight; // add the height
 532		}
 533		var isFixed = false;
 534		$(input).parents().each(function() {
 535			isFixed |= $(this).css('position') == 'fixed';
 536			return !isFixed;
 537		});
 538		if (isFixed && $.browser.opera) { // correction for Opera when fixed and scrolled
 539			$.datepicker._pos[0] -= document.documentElement.scrollLeft;
 540			$.datepicker._pos[1] -= document.documentElement.scrollTop;
 541		}
 542		var offset = {left: $.datepicker._pos[0], top: $.datepicker._pos[1]};
 543		$.datepicker._pos = null;
 544		inst.rangeStart = null;
 545		// determine sizing offscreen
 546		inst.dpDiv.css({position: 'absolute', display: 'block', top: '-1000px'});
 547		$.datepicker._updateDatepicker(inst);
 548		// fix width for dynamic number of date pickers
 549		// and adjust position before showing
 550		offset = $.datepicker._checkOffset(inst, offset, isFixed);
 551		inst.dpDiv.css({position: ($.datepicker._inDialog && $.blockUI ?
 552			'static' : (isFixed ? 'fixed' : 'absolute')), display: 'none',
 553			left: offset.left + 'px', top: offset.top + 'px'});
 554		if (!inst.inline) {
 555			var showAnim = $.datepicker._get(inst, 'showAnim') || 'show';
 556			var duration = $.datepicker._get(inst, 'duration');
 557			var postProcess = function() {
 558				$.datepicker._datepickerShowing = true;
 559				if ($.browser.msie && parseInt($.browser.version,10) < 7) // fix IE < 7 select problems
 560					$('iframe.ui-datepicker-cover').css({width: inst.dpDiv.width() + 4,
 561						height: inst.dpDiv.height() + 4});
 562			};
 563			if ($.effects && $.effects[showAnim])
 564				inst.dpDiv.show(showAnim, $.datepicker._get(inst, 'showOptions'), duration, postProcess);
 565			else
 566				inst.dpDiv[showAnim](duration, postProcess);
 567			if (duration == '')
 568				postProcess();
 569			if (inst.input[0].type != 'hidden')
 570				inst.input[0].focus();
 571			$.datepicker._curInst = inst;
 572		}
 573	},
 574
 575	/* Generate the date picker content. */
 576	_updateDatepicker: function(inst) {
 577		var dims = {width: inst.dpDiv.width() + 4,
 578			height: inst.dpDiv.height() + 4};
 579		var self = this;
 580		inst.dpDiv.empty().append(this._generateHTML(inst))
 581			.find('iframe.ui-datepicker-cover').
 582				css({width: dims.width, height: dims.height})
 583			.end()
 584			.find('button, .ui-datepicker-prev, .ui-datepicker-next, .ui-datepicker-calendar td a')
 585				.bind('mouseout', function(){
 586					$(this).removeClass('ui-state-hover');
 587					if(this.className.indexOf('ui-datepicker-prev') != -1) $(this).removeClass('ui-datepicker-prev-hover');
 588					if(this.className.indexOf('ui-datepicker-next') != -1) $(this).removeClass('ui-datepicker-next-hover');
 589				})
 590				.bind('mouseover', function(){
 591					if (!self._isDisabledDatepicker( inst.inline ? inst.dpDiv.parent()[0] : inst.input[0])) {
 592						$(this).parents('.ui-datepicker-calendar').find('a').removeClass('ui-state-hover');
 593						$(this).addClass('ui-state-hover');
 594						if(this.className.indexOf('ui-datepicker-prev') != -1) $(this).addClass('ui-datepicker-prev-hover');
 595						if(this.className.indexOf('ui-datepicker-next') != -1) $(this).addClass('ui-datepicker-next-hover');
 596					}
 597				})
 598			.end()
 599			.find('.' + this._dayOverClass + ' a')
 600				.trigger('mouseover')
 601			.end();
 602		var numMonths = this._getNumberOfMonths(inst);
 603		var cols = numMonths[1];
 604		var width = 17;
 605		if (cols > 1) {
 606			inst.dpDiv.addClass('ui-datepicker-multi-' + cols).css('width', (width * cols) + 'em');
 607		} else {
 608			inst.dpDiv.removeClass('ui-datepicker-multi-2 ui-datepicker-multi-3 ui-datepicker-multi-4').width('');
 609		}
 610		inst.dpDiv[(numMonths[0] != 1 || numMonths[1] != 1 ? 'add' : 'remove') +
 611			'Class']('ui-datepicker-multi');
 612		inst.dpDiv[(this._get(inst, 'isRTL') ? 'add' : 'remove') +
 613			'Class']('ui-datepicker-rtl');
 614		if (inst.input && inst.input[0].type != 'hidden' && inst == $.datepicker._curInst)
 615			$(inst.input[0]).focus();
 616	},
 617
 618	/* Check positioning to remain on screen. */
 619	_checkOffset: function(inst, offset, isFixed) {
 620		var dpWidth = inst.dpDiv.outerWidth();
 621		var dpHeight = inst.dpDiv.outerHeight();
 622		var inputWidth = inst.input ? inst.input.outerWidth() : 0;
 623		var inputHeight = inst.input ? inst.input.outerHeight() : 0;
 624		var viewWidth = (window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth) + $(document).scrollLeft();
 625		var viewHeight = (window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight) + $(document).scrollTop();
 626
 627		offset.left -= (this._get(inst, 'isRTL') ? (dpWidth - inputWidth) : 0);
 628		offset.left -= (isFixed && offset.left == inst.input.offset().left) ? $(document).scrollLeft() : 0;
 629		offset.top -= (isFixed && offset.top == (inst.input.offset().top + inputHeight)) ? $(document).scrollTop() : 0;
 630
 631		// now check if datepicker is showing outside window viewport - move to a better place if so.
 632		offset.left -= (offset.left + dpWidth > viewWidth && viewWidth > dpWidth) ? Math.abs(offset.left + dpWidth - viewWidth) : 0;
 633		offset.top -= (offset.top + dpHeight > viewHeight && viewHeight > dpHeight) ? Math.abs(offset.top + dpHeight + inputHeight*2 - viewHeight) : 0;
 634
 635		return offset;
 636	},
 637
 638	/* Find an object's position on the screen. */
 639	_findPos: function(obj) {
 640        while (obj && (obj.type == 'hidden' || obj.nodeType != 1)) {
 641            obj = obj.nextSibling;
 642        }
 643        var position = $(obj).offset();
 644	    return [position.left, position.top];
 645	},
 646
 647	/* Hide the date picker from view.
 648	   @param  input  element - the input field attached to the date picker
 649	   @param  duration  string - the duration over which to close the date picker */
 650	_hideDatepicker: function(input, duration) {
 651		var inst = this._curInst;
 652		if (!inst || (input && inst != $.data(input, PROP_NAME)))
 653			return;
 654		if (inst.stayOpen)
 655			this._selectDate('#' + inst.id, this._formatDate(inst,
 656				inst.currentDay, inst.currentMonth, inst.currentYear));
 657		inst.stayOpen = false;
 658		if (this._datepickerShowing) {
 659			duration = (duration != null ? duration : this._get(inst, 'duration'));
 660			var showAnim = this._get(inst, 'showAnim');
 661			var postProcess = function() {
 662				$.datepicker._tidyDialog(inst);
 663			};
 664			if (duration != '' && $.effects && $.effects[showAnim])
 665				inst.dpDiv.hide(showAnim, $.datepicker._get(inst, 'showOptions'),
 666					duration, postProcess);
 667			else
 668				inst.dpDiv[(duration == '' ? 'hide' : (showAnim == 'slideDown' ? 'slideUp' :
 669					(showAnim == 'fadeIn' ? 'fadeOut' : 'hide')))](duration, postProcess);
 670			if (duration == '')
 671				this._tidyDialog(inst);
 672			var onClose = this._get(inst, 'onClose');
 673			if (onClose)
 674				onClose.apply((inst.input ? inst.input[0] : null),
 675					[(inst.input ? inst.input.val() : ''), inst]);  // trigger custom callback
 676			this._datepickerShowing = false;
 677			this._lastInput = null;
 678			if (this._inDialog) {
 679				this._dialogInput.css({ position: 'absolute', left: '0', top: '-100px' });
 680				if ($.blockUI) {
 681					$.unblockUI();
 682					$('body').append(this.dpDiv);
 683				}
 684			}
 685			this._inDialog = false;
 686		}
 687		this._curInst = null;
 688	},
 689
 690	/* Tidy up after a dialog display. */
 691	_tidyDialog: function(inst) {
 692		inst.dpDiv.removeClass(this._dialogClass).unbind('.ui-datepicker-calendar');
 693	},
 694
 695	/* Close date picker if clicked elsewhere. */
 696	_checkExternalClick: function(event) {
 697		if (!$.datepicker._curInst)
 698			return;
 699		var $target = $(event.target);
 700		if (($target.parents('#' + $.datepicker._mainDivId).length == 0) &&
 701				!$target.hasClass($.datepicker.markerClassName) &&
 702				!$target.hasClass($.datepicker._triggerClass) &&
 703				$.datepicker._datepickerShowing && !($.datepicker._inDialog && $.blockUI))
 704			$.datepicker._hideDatepicker(null, '');
 705	},
 706
 707	/* Adjust one of the date sub-fields. */
 708	_adjustDate: function(id, offset, period) {
 709		var target = $(id);
 710		var inst = this._getInst(target[0]);
 711		if (this._isDisabledDatepicker(target[0])) {
 712			return;
 713		}
 714		this._adjustInstDate(inst, offset +
 715			(period == 'M' ? this._get(inst, 'showCurrentAtPos') : 0), // undo positioning
 716			period);
 717		this._updateDatepicker(inst);
 718	},
 719
 720	/* Action for current link. */
 721	_gotoToday: function(id) {
 722		var target = $(id);
 723		var inst = this._getInst(target[0]);
 724		if (this._get(inst, 'gotoCurrent') && inst.currentDay) {
 725			inst.selectedDay = inst.currentDay;
 726			inst.drawMonth = inst.selectedMonth = inst.currentMonth;
 727			inst.drawYear = inst.selectedYear = inst.currentYear;
 728		}
 729		else {
 730		var date = new Date();
 731		inst.selectedDay = date.getDate();
 732		inst.drawMonth = inst.selectedMonth = date.getMonth();
 733		inst.drawYear = inst.selectedYear = date.getFullYear();
 734		}
 735		this._notifyChange(inst);
 736		this._adjustDate(target);
 737	},
 738
 739	/* Action for selecting a new month/year. */
 740	_selectMonthYear: function(id, select, period) {
 741		var target = $(id);
 742		var inst = this._getInst(target[0]);
 743		inst._selectingMonthYear = false;
 744		inst['selected' + (period == 'M' ? 'Month' : 'Year')] =
 745		inst['draw' + (period == 'M' ? 'Month' : 'Year')] =
 746			parseInt(select.options[select.selectedIndex].value,10);
 747		this._notifyChange(inst);
 748		this._adjustDate(target);
 749	},
 750
 751	/* Restore input focus after not changing month/year. */
 752	_clickMonthYear: function(id) {
 753		var target = $(id);
 754		var inst = this._getInst(target[0]);
 755		if (inst.input && inst._selectingMonthYear && !$.browser.msie)
 756			inst.input[0].focus();
 757		inst._selectingMonthYear = !inst._selectingMonthYear;
 758	},
 759
 760	/* Action for selecting a day. */
 761	_selectDay: function(id, month, year, td) {
 762		var target = $(id);
 763		if ($(td).hasClass(this._unselectableClass) || this._isDisabledDatepicker(target[0])) {
 764			return;
 765		}
 766		var inst = this._getInst(target[0]);
 767		inst.selectedDay = inst.currentDay = $('a', td).html();
 768		inst.selectedMonth = inst.currentMonth = month;
 769		inst.selectedYear = inst.currentYear = year;
 770		if (inst.stayOpen) {
 771			inst.endDay = inst.endMonth = inst.endYear = null;
 772		}
 773		this._selectDate(id, this._formatDate(inst,
 774			inst.currentDay, inst.currentMonth, inst.currentYear));
 775		if (inst.stayOpen) {
 776			inst.rangeStart = this._daylightSavingAdjust(
 777				new Date(inst.currentYear, inst.currentMonth, inst.currentDay));
 778			this._updateDatepicker(inst);
 779		}
 780	},
 781
 782	/* Erase the input field and hide the date picker. */
 783	_clearDate: function(id) {
 784		var target = $(id);
 785		var inst = this._getInst(target[0]);
 786		inst.stayOpen = false;
 787		inst.endDay = inst.endMonth = inst.endYear = inst.rangeStart = null;
 788		this._selectDate(target, '');
 789	},
 790
 791	/* Update the input field with the selected date. */
 792	_selectDate: function(id, dateStr) {
 793		var target = $(id);
 794		var inst = this._getInst(target[0]);
 795		dateStr = (dateStr != null ? dateStr : this._formatDate(inst));
 796		if (inst.input)
 797			inst.input.val(dateStr);
 798		this._updateAlternate(inst);
 799		var onSelect = this._get(inst, 'onSelect');
 800		if (onSelect)
 801			onSelect.apply((inst.input ? inst.input[0] : null), [dateStr, inst]);  // trigger custom callback
 802		else if (inst.input)
 803			inst.input.trigger('change'); // fire the change event
 804		if (inst.inline)
 805			this._updateDatepicker(inst);
 806		else if (!inst.stayOpen) {
 807			this._hideDatepicker(null, this._get(inst, 'duration'));
 808			this._lastInput = inst.input[0];
 809			if (typeof(inst.input[0]) != 'object')
 810				inst.input[0].focus(); // restore focus
 811			this._lastInput = null;
 812		}
 813	},
 814
 815	/* Update any alternate field to synchronise with the main field. */
 816	_updateAlternate: function(inst) {
 817		var altField = this._get(inst, 'altField');
 818		if (altField) { // update alternate field too
 819			var altFormat = this._get(inst, 'altFormat') || this._get(inst, 'dateFormat');
 820			var date = this._getDate(inst);
 821			dateStr = this.formatDate(altFormat, date, this._getFormatConfig(inst));
 822			$(altField).each(function() { $(this).val(dateStr); });
 823		}
 824	},
 825
 826	/* Set as beforeShowDay function to prevent selection of weekends.
 827	   @param  date  Date - the date to customise
 828	   @return [boolean, string] - is this date selectable?, what is its CSS class? */
 829	noWeekends: function(date) {
 830		var day = date.getDay();
 831		return [(day > 0 && day < 6), ''];
 832	},
 833
 834	/* Set as calculateWeek to determine the week of the year based on the ISO 8601 definition.
 835	   @param  date  Date - the date to get the week for
 836	   @return  number - the number of the week within the year that contains this date */
 837	iso8601Week: function(date) {
 838		var checkDate = new Date(date.getFullYear(), date.getMonth(), date.getDate());
 839		var firstMon = new Date(checkDate.getFullYear(), 1 - 1, 4); // First week always contains 4 Jan
 840		var firstDay = firstMon.getDay() || 7; // Day of week: Mon = 1, ..., Sun = 7
 841		firstMon.setDate(firstMon.getDate() + 1 - firstDay); // Preceding Monday
 842		if (firstDay < 4 && checkDate < firstMon) { // Adjust first three days in year if necessary
 843			checkDate.setDate(checkDate.getDate() - 3); // Generate for previous year
 844			return $.datepicker.iso8601Week(checkDate);
 845		} else if (checkDate > new Date(checkDate.getFullYear(), 12 - 1, 28)) { // Check last three days in year
 846			firstDay = new Date(checkDate.getFullYear() + 1, 1 - 1, 4).getDay() || 7;
 847			if (firstDay > 4 && (checkDate.getDay() || 7) < firstDay - 3) { // Adjust if necessary
 848				return 1;
 849			}
 850		}
 851		return Math.floor(((checkDate - firstMon) / 86400000) / 7) + 1; // Weeks to given date
 852	},
 853
 854	/* Parse a string value into a date object.
 855	   See formatDate below for the possible formats.
 856
 857	   @param  format    string - the expected format of the date
 858	   @param  value     string - the date in the above format
 859	   @param  settings  Object - attributes include:
 860	                     shortYearCutoff  number - the cutoff year for determining the century (optional)
 861	                     dayNamesShort    string[7] - abbreviated names of the days from Sunday (optional)
 862	                     dayNames         string[7] - names of the days from Sunday (optional)
 863	                     monthNamesShort  string[12] - abbreviated names of the months (optional)
 864	                     monthNames       string[12] - names of the months (optional)
 865	   @return  Date - the extracted date value or null if value is blank */
 866	parseDate: function (format, value, settings) {
 867		if (format == null || value == null)
 868			throw 'Invalid arguments';
 869		value = (typeof value == 'object' ? value.toString() : value + '');
 870		if (value == '')
 871			return null;
 872		var shortYearCutoff = (settings ? settings.shortYearCutoff : null) || this._defaults.shortYearCutoff;
 873		var dayNamesShort = (settings ? settings.dayNamesShort : null) || this._defaults.dayNamesShort;
 874		var dayNames = (settings ? settings.dayNames : null) || this._defaults.dayNames;
 875		var monthNamesShort = (settings ? settings.monthNamesShort : null) || this._defaults.monthNamesShort;
 876		var monthNames = (settings ? settings.monthNames : null) || this._defaults.monthNames;
 877		var year = -1;
 878		var month = -1;
 879		var day = -1;
 880		var doy = -1;
 881		var literal = false;
 882		// Check whether a format character is doubled
 883		var lookAhead = function(match) {
 884			var matches = (iFormat + 1 < format.length && format.charAt(iFormat + 1) == match);
 885			if (matches)
 886				iFormat++;
 887			return matches;
 888		};
 889		// Extract a number from the string value
 890		var getNumber = function(match) {
 891			lookAhead(match);
 892			var origSize = (match == '@' ? 14 : (match == 'y' ? 4 : (match == 'o' ? 3 : 2)));
 893			var size = origSize;
 894			var num = 0;
 895			while (size > 0 && iValue < value.length &&
 896					value.charAt(iValue) >= '0' && value.charAt(iValue) <= '9') {
 897				num = num * 10 + parseInt(value.charAt(iValue++),10);
 898				size--;
 899			}
 900			if (size == origSize)
 901				throw 'Missing number at position ' + iValue;
 902			return num;
 903		};
 904		// Extract a name from the string value and convert to an index
 905		var getName = function(match, shortNames, longNames) {
 906			var names = (lookAhead(match) ? longNames : shortNames);
 907			var size = 0;
 908			for (var j = 0; j < names.length; j++)
 909				size = Math.max(size, names[j].length);
 910			var name = '';
 911			var iInit = iValue;
 912			while (size > 0 && iValue < value.length) {
 913				name += value.charAt(iValue++);
 914				for (var i = 0; i < names.length; i++)
 915					if (name == names[i])
 916						return i + 1;
 917				size--;
 918			}
 919			throw 'Unknown name at position ' + iInit;
 920		};
 921		// Confirm that a literal character matches the string value
 922		var checkLiteral = function() {
 923			if (value.charAt(iValue) != format.charAt(iFormat))
 924				throw 'Unexpected literal at position ' + iValue;
 925			iValue++;
 926		};
 927		var iValue = 0;
 928		for (var iFormat = 0; iFormat < format.length; iFormat++) {
 929			if (literal)
 930				if (format.charAt(iFormat) == "'" && !lookAhead("'"))
 931					literal = false;
 932				else
 933					checkLiteral();
 934			else
 935				switch (format.charAt(iFormat)) {
 936					case 'd':
 937						day = getNumber('d');
 938						break;
 939					case 'D':
 940						getName('D', dayNamesShort, dayNames);
 941						break;
 942					case 'o':
 943						doy = getNumber('o');
 944						break;
 945					case 'm':
 946						month = getNumber('m');
 947						break;
 948					case 'M':
 949						month = getName('M', monthNamesShort, monthNames);
 950						break;
 951					case 'y':
 952						year = getNumber('y');
 953						break;
 954					case '@':
 955						var date = new Date(getNumber('@'));
 956						year = date.getFullYear();
 957						month = date.getMonth() + 1;
 958						day = date.getDate();
 959						break;
 960					case "'":
 961						if (lookAhead("'"))
 962							checkLiteral();
 963						else
 964							literal = true;
 965						break;
 966					default:
 967						checkLiteral();
 968				}
 969		}
 970		if (year == -1)
 971			year = new Date().getFullYear();
 972		else if (year < 100)
 973			year += new Date().getFullYear() - new Date().getFullYear() % 100 +
 974				(year <= shortYearCutoff ? 0 : -100);
 975		if (doy > -1) {
 976			month = 1;
 977			day = doy;
 978			do {
 979				var dim = this._getDaysInMonth(year, month - 1);
 980				if (day <= dim)
 981					break;
 982				month++;
 983				day -= dim;
 984			} while (true);
 985		}
 986		var date = this._daylightSavingAdjust(new Date(year, month - 1, day));
 987		if (date.getFullYear() != year || date.getMonth() + 1 != month || date.getDate() != day)
 988			throw 'Invalid date'; // E.g. 31/02/*
 989		return date;
 990	},
 991
 992	/* Standard date formats. */
 993	ATOM: 'yy-mm-dd', // RFC 3339 (ISO 8601)
 994	COOKIE: 'D, dd M yy',
 995	ISO_8601: 'yy-mm-dd',
 996	RFC_822: 'D, d M y',
 997	RFC_850: 'DD, dd-M-y',
 998	RFC_1036: 'D, d M y',
 999	RFC_1123: 'D, d M yy',
1000	RFC_2822: 'D, d M yy',
1001	RSS: 'D, d M y', // RFC 822
1002	TIMESTAMP: '@',
1003	W3C: 'yy-mm-dd', // ISO 8601
1004
1005	/* Format a date object into a string value.
1006	   The format can be combinations of the following:
1007	   d  - day of month (no leading zero)
1008	   dd - day of month (two digit)
1009	   o  - day of year (no leading zeros)
1010	   oo - day of year (three digit)
1011	   D  - day name short
1012	   DD - day name long
1013	   m  - month of year (no leading zero)
1014	   mm - month of year (two digit)
1015	   M  - month name short
1016	   MM - month name long
1017	   y  - year (two digit)
1018	   yy - year (four digit)
1019	   @ - Unix timestamp (ms since 01/01/1970)
1020	   '...' - literal text
1021	   '' - single quote
1022
1023	   @param  format    string - the desired format of the date
1024	   @param  date      Date - the date value to format
1025	   @param  settings  Object - attributes include:
1026	                     dayNamesShort    string[7] - abbreviated names of the days from Sunday (optional)
1027	                     dayNames         string[7] - names of the days from Sunday (optional)
1028	                     monthNamesShort  string[12] - abbreviated names of the months (optional)
1029	                     monthNames       string[12] - names of the months (optional)
1030	   @return  string - the date in the above format */
1031	formatDate: function (format, date, settings) {
1032		if (!date)
1033			return '';
1034		var dayNamesShort = (settings ? settings.dayNamesShort : null) || this._defaults.dayNamesShort;
1035		var dayNames = (settings ? settings.dayNames : null) || this._defaults.dayNames;
1036		var monthNamesShort = (settings ? settings.monthNamesShort : null) || this._defaults.monthNamesShort;
1037		var monthNames = (settings ? settings.monthNames : null) || this._defaults.monthNames;
1038		// Check whether a format character is doubled
1039		var lookAhead = function(match) {
1040			var matches = (iFormat + 1 < format.length && format.charAt(iFormat + 1) == match);
1041			if (matches)
1042				iFormat++;
1043			return matches;
1044		};
1045		// Format a number, with leading zero if necessary
1046		var formatNumber = function(match, value, len) {
1047			var num = '' + value;
1048			if (lookAhead(match))
1049				while (num.length < len)
1050					num = '0' + num;
1051			return num;
1052		};
1053		// Format a name, short or long as requested
1054		var formatName = function(match, value, shortNames, longNames) {
1055			return (lookAhead(match) ? longNames[value] : shortNames[value]);
1056		};
1057		var output = '';
1058		var literal = false;
1059		if (date)
1060			for (var iFormat = 0; iFormat < format.length; iFormat++) {
1061				if (literal)
1062					if (format.charAt(iFormat) == "'" && !lookAhead("'"))
1063						literal = false;
1064					else
1065						output += format.charAt(iFormat);
1066				else
1067					switch (format.charAt(iFormat)) {
1068						case 'd':
1069							output += formatNumber('d', date.getDate(), 2);
1070							break;
1071						case 'D':
1072							output += formatName('D', date.getDay(), dayNamesShort, dayNames);
1073							break;
1074						case 'o':
1075							var doy = date.getDate();
1076							for (var m = date.getMonth() - 1; m >= 0; m--)
1077								doy += this._getDaysInMonth(date.getFullYear(), m);
1078							output += formatNumber('o', doy, 3);
1079							break;
1080						case 'm':
1081							output += formatNumber('m', date.getMonth() + 1, 2);
1082							break;
1083						case 'M':
1084							output += formatName('M', date.getMonth(), monthNamesShort, monthNames);
1085							break;
1086						case 'y':
1087							output += (lookAhead('y') ? date.getFullYear() :
1088								(date.getYear() % 100 < 10 ? '0' : '') + date.getYear() % 100);
1089							break;
1090						case '@':
1091							output += date.getTime();
1092							break;
1093						case "'":
1094							if (lookAhead("'"))
1095								output += "'";
1096							else
1097								literal = true;
1098							break;
1099						default:
1100							output += format.charAt(iFormat);
1101					}
1102			}
1103		return output;
1104	},
1105
1106	/* Extract all possible characters from the date format. */
1107	_possibleChars: function (format) {
1108		var chars = '';
1109		var literal = false;
1110		for (var iFormat = 0; iFormat < format.length; iFormat++)
1111			if (literal)
1112				if (format.charAt(iFormat) == "'" && !lookAhead("'"))
1113					literal = false;
1114				else
1115					chars += format.charAt(iFormat);
1116			else
1117				switch (format.charAt(iFormat)) {
1118					case 'd': case 'm': case 'y': case '@':
1119						chars += '0123456789';
1120						break;
1121					case 'D': case 'M':
1122						return null; // Accept anything
1123					case "'":
1124						if (lookAhead("'"))
1125							chars += "'";
1126						else
1127							literal = true;
1128						break;
1129					default:
1130						chars += format.charAt(iFormat);
1131				}
1132		return chars;
1133	},
1134
1135	/* Get a setting value, defaulting if necessary. */
1136	_get: function(inst, name) {
1137		return inst.settings[name] !== undefined ?
1138			inst.settings[name] : this._defaults[name];
1139	},
1140
1141	/* Parse existing date and initialise date picker. */
1142	_setDateFromField: function(inst) {
1143		var dateFormat = this._get(inst, 'dateFormat');
1144		var dates = inst.input ? inst.input.val() : null;
1145		inst.endDay = inst.endMonth = inst.endYear = null;
1146		var date = defaultDate = this._getDefaultDate(inst);
1147		var settings = this._getFormatConfig(inst);
1148		try {
1149			date = this.parseDate(dateFormat, dates, settings) || defaultDate;
1150		} catch (event) {
1151			this.log(event);
1152			date = defaultDate;
1153		}
1154		inst.selectedDay = date.getDate();
1155		inst.drawMonth = inst.selectedMonth = date.getMonth();
1156		inst.drawYear = inst.selectedYear = date.getFullYear();
1157		inst.currentDay = (dates ? date.getDate() : 0);
1158		inst.currentMonth = (dates ? date.getMonth() : 0);
1159		inst.currentYear = (dates ? date.getFullYear() : 0);
1160		this._adjustInstDate(inst);
1161	},
1162
1163	/* Retrieve the default date shown on opening. */
1164	_getDefaultDate: function(inst) {
1165		var date = this._determineDate(this._get(inst, 'defaultDate'), new Date());
1166		var minDate = this._getMinMaxDate(inst, 'min', true);
1167		var maxDate = this._getMinMaxDate(inst, 'max');
1168		date = (minDate && date < minDate ? minDate : date);
1169		date = (maxDate && date > maxDate ? maxDate : date);
1170		return date;
1171	},
1172
1173	/* A date may be specified as an exact value or a relative one. */
1174	_determineDate: function(date, defaultDate) {
1175		var offsetNumeric = function(offset) {
1176			var date = new Date();
1177			date.setDate(date.getDate() + offset);
1178			return date;
1179		};
1180		var offsetString = function(offset, getDaysInMonth) {
1181			var date = new Date();
1182			var year = date.getFullYear();
1183			var month = date.getMonth();
1184			var day = date.getDate();
1185			var pattern = /([+-]?[0-9]+)\s*(d|D|w|W|m|M|y|Y)?/g;
1186			var matches = pattern.exec(offset);
1187			while (matches) {
1188				switch (matches[2] || 'd') {
1189					case 'd' : case 'D' :
1190						day += parseInt(matches[1],10); break;
1191					case 'w' : case 'W' :
1192						day += parseInt(matches[1],10) * 7; break;
1193					case 'm' : case 'M' :
1194						month += parseInt(matches[1],10);
1195						day = Math.min(day, getDaysInMonth(year, month));
1196						break;
1197					case 'y': case 'Y' :
1198						year += parseInt(matches[1],10);
1199						day = Math.min(day, getDaysInMonth(year, month));
1200						break;
1201				}
1202				matches = pattern.exec(offset);
1203			}
1204			return new Date(year,

Large files files are truncated, but you can click here to view the full file