app/jquery/jquery-ui.datetimepicker.js
author Lennard de Rijk <ljvderijk@gmail.com>
Fri, 23 Jan 2009 16:23:01 +0000
changeset 925 a85719e94570
parent 843 a086ff3888d3
child 1451 ef134d062b83
permissions -rwxr-xr-x
Removed club property from club_admin model. Patch by: Lennard de Rijk Reviewed by: to-be-reviewed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
843
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
     1
/* jQuery UI Date Picker v3.4.3 (previously jQuery Calendar)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
     2
   Written by Marc Grabanski (m@marcgrabanski.com) and Keith Wood (kbwood@virginbroadband.com.au).
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
     3
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
     4
   Copyright (c) 2007 Marc Grabanski (http://marcgrabanski.com/code/ui-datetimepicker)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
     5
   Dual licensed under the MIT (MIT-LICENSE.txt)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
     6
   and GPL (GPL-LICENSE.txt) licenses.
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
     7
   Date: 09-03-2007  */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
     8
/*
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
     9
 * Time functionality added by Stanislav Dobry (stanislav.dobry@datesoft.cz)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    10
 * Date: 2008-06-04
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    11
 */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    12
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    13
;(function($) { // hide the namespace
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    14
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    15
/* Date picker manager.
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    16
   Use the singleton instance of this class, $.datetimepicker, to interact with the date picker.
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    17
   Settings for (groups of) date pickers are maintained in an instance object
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    18
   (DatepickerInstance), allowing multiple different settings on the same page. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    19
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    20
function DateTimepicker() {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    21
	this.debug = false; // Change this to true to start debugging
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    22
	this._nextId = 0; // Next ID for a date picker instance
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    23
	this._inst = []; // List of instances indexed by ID
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    24
	this._curInst = null; // The current instance in use
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    25
	this._disabledInputs = []; // List of date picker inputs that have been disabled
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    26
	this._datetimepickerShowing = false; // True if the popup picker is showing , false if not
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    27
	this._inDialog = false; // True if showing within a "dialog", false if not
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    28
	this.regional = []; // Available regional settings, indexed by language code
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    29
	this.regional[''] = { // Default regional settings
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    30
		clearText: 'Clear', // Display text for clear link
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    31
		clearStatus: 'Erase the current date', // Status text for clear link
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    32
		closeText: 'Close', // Display text for close link
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    33
		closeStatus: 'Close without change', // Status text for close link
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    34
		prevText: '&#x3c;Prev', // Display text for previous month link
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    35
		prevStatus: 'Show the previous month', // Status text for previous month link
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    36
		nextText: 'Next&#x3e;', // Display text for next month link
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    37
		nextStatus: 'Show the next month', // Status text for next month link
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    38
		currentText: 'Today', // Display text for current month link
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    39
		currentStatus: 'Show the current month', // Status text for current month link
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    40
		monthNames: ['January','February','March','April','May','June',
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    41
			'July','August','September','October','November','December'], // Names of months for drop-down and formatting
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    42
		monthNamesShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], // For formatting
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    43
		monthStatus: 'Show a different month', // Status text for selecting a month
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    44
		yearStatus: 'Show a different year', // Status text for selecting a year
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    45
		weekHeader: 'Wk', // Header for the week of the year column
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    46
		weekStatus: 'Week of the year', // Status text for the week of the year column
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    47
		dayNames: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'], // For formatting
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    48
		dayNamesShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'], // For formatting
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    49
		dayNamesMin: ['Su','Mo','Tu','We','Th','Fr','Sa'], // Column headings for days starting at Sunday
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    50
		dayStatus: 'Set DD as first week day', // Status text for the day of the week selection
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    51
		dateStatus: 'Select DD, M d', // Status text for the date selection
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    52
		dateFormat: 'mm/dd/yy', // See format options on parseDate
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    53
		timeFormat: 'hh:ii',
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    54
		firstDay: 0, // The first day of the week, Sun = 0, Mon = 1, ...
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    55
		initStatus: 'Select a date', // Initial Status text on opening
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    56
		isRTL: false // True if right-to-left language, false if left-to-right
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    57
	};
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    58
	this._defaults = { // Global defaults for all the date picker instances
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    59
		showOn: 'focus', // 'focus' for popup on focus,
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    60
			// 'button' for trigger button, or 'both' for either
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    61
		showAnim: 'show', // Name of jQuery animation for popup
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    62
		defaultDate: null, // Used when field is blank: actual date,
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    63
			// +/-number for offset from today, null for today
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    64
		appendText: '', // Display text following the input box, e.g. showing the format
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    65
		buttonText: '...', // Text for trigger button
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    66
		buttonImage: '', // URL for trigger button image
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    67
		buttonImageOnly: false, // True if the image appears alone, false if it appears on a button
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    68
		closeAtTop: true, // True to have the clear/close at the top,
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    69
			// false to have them at the bottom
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    70
		mandatory: false, // True to hide the Clear link, false to include it
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    71
		hideIfNoPrevNext: false, // True to hide next/previous month links
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    72
			// if not applicable, false to just disable them
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    73
		changeMonth: true, // True if month can be selected directly, false if only prev/next
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    74
		changeYear: true, // True if year can be selected directly, false if only prev/next
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    75
		yearRange: '-10:+10', // Range of years to display in drop-down,
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    76
			// either relative to current year (-nn:+nn) or absolute (nnnn:nnnn)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    77
		changeFirstDay: true, // True to click on day name to change, false to remain as set
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    78
		showOtherMonths: false, // True to show dates in other months, false to leave blank
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    79
		showWeeks: false, // True to show week of the year, false to omit
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    80
		calculateWeek: this.iso8601Week, // How to calculate the week of the year,
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    81
			// takes a Date and returns the number of the week for it
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    82
		shortYearCutoff: '+10', // Short year values < this are in the current century,
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    83
			// > this are in the previous century,
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    84
			// string value starting with '+' for current year + value
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    85
		showStatus: false, // True to show status bar at bottom, false to not show it
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    86
		statusForDate: this.dateStatus, // Function to provide status text for a date -
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    87
			// takes date and instance as parameters, returns display text
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    88
		minDate: null, // The earliest selectable date, or null for no limit
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    89
		maxDate: null, // The latest selectable date, or null for no limit
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    90
		speed: 'normal', // Speed of display/closure
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    91
		beforeShowDay: null, // Function that takes a date and returns an array with
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    92
			// [0] = true if selectable, false if not,
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    93
			// [1] = custom CSS class name(s) or '', e.g. $.datetimepicker.noWeekends
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    94
		beforeShow: null, // Function that takes an input field and
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    95
			// returns a set of custom settings for the date picker
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    96
		onSelect: null, // Define a callback function when a date is selected
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    97
		onClose: null, // Define a callback function when the datetimepicker is closed
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    98
		numberOfMonths: 1, // Number of months to show at a time
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
    99
		stepMonths: 1, // Number of months to step back/forward
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   100
		rangeSelect: false, // Allows for selecting a date range on one date picker
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   101
		rangeSeparator: ' - ' // Text between two dates in a range
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   102
	};
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   103
	$.extend(this._defaults, this.regional['']);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   104
	this._datetimepickerDiv = $('<div id="datetimepicker_div"></div>');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   105
}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   106
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   107
$.extend(DateTimepicker.prototype, {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   108
	/* Class name added to elements to indicate already configured with a date picker. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   109
	markerClassName: 'hasDatepicker',
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   110
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   111
	/* Debug logging (if enabled). */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   112
	log: function () {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   113
		if (this.debug)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   114
			console.log.apply('', arguments);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   115
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   116
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   117
	/* Register a new date picker instance - with custom settings. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   118
	_register: function(inst) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   119
		var id = this._nextId++;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   120
		this._inst[id] = inst;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   121
		return id;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   122
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   123
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   124
	/* Retrieve a particular date picker instance based on its ID. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   125
	_getInst: function(id) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   126
		return this._inst[id] || id;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   127
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   128
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   129
	/* Override the default settings for all instances of the date picker.
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   130
	   @param  settings  object - the new settings to use as defaults (anonymous object)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   131
	   @return the manager object */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   132
	setDefaults: function(settings) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   133
		extendRemove(this._defaults, settings || {});
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   134
		return this;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   135
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   136
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   137
	/* Attach the date picker to a jQuery selection.
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   138
	   @param  target    element - the target input field or division or span
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   139
	   @param  settings  object - the new settings to use for this date picker instance (anonymous) */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   140
	_attachDatepicker: function(target, settings) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   141
		// check for settings on the control itself - in namespace 'date:'
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   142
		var inlineSettings = null;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   143
		for (attrName in this._defaults) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   144
			var attrValue = target.getAttribute('date:' + attrName);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   145
			if (attrValue) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   146
				inlineSettings = inlineSettings || {};
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   147
				try {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   148
					inlineSettings[attrName] = eval(attrValue);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   149
				} catch (err) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   150
					inlineSettings[attrName] = attrValue;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   151
				}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   152
			}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   153
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   154
		var nodeName = target.nodeName.toLowerCase();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   155
		var instSettings = (inlineSettings ?
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   156
			$.extend(settings || {}, inlineSettings || {}) : settings);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   157
		if (nodeName == 'input') {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   158
			var inst = (inst && !inlineSettings ? inst :
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   159
				new DateTimepickerInstance(instSettings, false));
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   160
			this._connectDatepicker(target, inst);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   161
		} else if (nodeName == 'div' || nodeName == 'span') {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   162
			var inst = new DateTimepickerInstance(instSettings, true);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   163
			this._inlineDatepicker(target, inst);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   164
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   165
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   166
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   167
	/* Detach a datetimepicker from its control.
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   168
	   @param  target    element - the target input field or division or span */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   169
	_destroyDatepicker: function(target) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   170
		var nodeName = target.nodeName.toLowerCase();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   171
		var calId = target._calId;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   172
		target._calId = null;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   173
		var $target = $(target);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   174
		if (nodeName == 'input') {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   175
			$target.siblings('.datetimepicker_append').replaceWith('').end()
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   176
				.siblings('.datetimepicker_trigger').replaceWith('').end()
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   177
				.removeClass(this.markerClassName)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   178
				.unbind('focus', this._showDatepicker)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   179
				.unbind('keydown', this._doKeyDown)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   180
				.unbind('keypress', this._doKeyPress);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   181
			var wrapper = $target.parents('.datetimepicker_wrap');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   182
			if (wrapper)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   183
				wrapper.replaceWith(wrapper.html());
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   184
		} else if (nodeName == 'div' || nodeName == 'span')
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   185
			$target.removeClass(this.markerClassName).empty();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   186
		if ($('input[_calId=' + calId + ']').length == 0)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   187
			// clean up if last for this ID
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   188
			this._inst[calId] = null;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   189
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   190
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   191
	/* Enable the date picker to a jQuery selection.
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   192
	   @param  target    element - the target input field or division or span */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   193
	_enableDatepicker: function(target) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   194
		target.disabled = false;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   195
		$(target).siblings('button.datetimepicker_trigger').each(function() { this.disabled = false; }).end()
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   196
			.siblings('img.datetimepicker_trigger').css({opacity: '1.0', cursor: ''});
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   197
		this._disabledInputs = $.map(this._disabledInputs,
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   198
			function(value) { return (value == target ? null : value); }); // delete entry
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   199
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   200
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   201
	/* Disable the date picker to a jQuery selection.
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   202
	   @param  target    element - the target input field or division or span */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   203
	_disableDatepicker: function(target) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   204
		target.disabled = true;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   205
		$(target).siblings('button.datetimepicker_trigger').each(function() { this.disabled = true; }).end()
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   206
			.siblings('img.datetimepicker_trigger').css({opacity: '0.5', cursor: 'default'});
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   207
		this._disabledInputs = $.map($.datetimepicker._disabledInputs,
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   208
			function(value) { return (value == target ? null : value); }); // delete entry
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   209
		this._disabledInputs[$.datetimepicker._disabledInputs.length] = target;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   210
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   211
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   212
	/* Is the first field in a jQuery collection disabled as a datetimepicker?
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   213
	   @param  target    element - the target input field or division or span
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   214
	   @return boolean - true if disabled, false if enabled */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   215
	_isDisabledDatepicker: function(target) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   216
		if (!target)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   217
			return false;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   218
		for (var i = 0; i < this._disabledInputs.length; i++) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   219
			if (this._disabledInputs[i] == target)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   220
				return true;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   221
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   222
		return false;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   223
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   224
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   225
	/* Update the settings for a date picker attached to an input field or division.
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   226
	   @param  target  element - the target input field or division or span
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   227
	   @param  name    string - the name of the setting to change or
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   228
	                   object - the new settings to update
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   229
	   @param  value   any - the new value for the setting (omit if above is an object) */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   230
	_changeDatepicker: function(target, name, value) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   231
		var settings = name || {};
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   232
		if (typeof name == 'string') {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   233
			settings = {};
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   234
			settings[name] = value;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   235
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   236
		if (inst = this._getInst(target._calId)) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   237
			extendRemove(inst._settings, settings);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   238
			this._updateDatepicker(inst);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   239
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   240
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   241
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   242
	/* Set the dates for a jQuery selection.
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   243
	   @param  target   element - the target input field or division or span
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   244
	   @param  date     Date - the new date
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   245
	   @param  endDate  Date - the new end date for a range (optional) */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   246
	_setDateDatepicker: function(target, date, endDate) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   247
		if (inst = this._getInst(target._calId)) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   248
			inst._setDate(date, endDate);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   249
			this._updateDatepicker(inst);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   250
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   251
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   252
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   253
	/* Get the date(s) for the first entry in a jQuery selection.
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   254
	   @param  target  element - the target input field or division or span
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   255
	   @return Date - the current date or
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   256
	           Date[2] - the current dates for a range */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   257
	_getDateDatepicker: function(target) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   258
		var inst = this._getInst(target._calId);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   259
		return (inst ? inst._getDate() : null);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   260
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   261
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   262
	/* Handle keystrokes. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   263
	_doKeyDown: function(e) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   264
		var inst = $.datetimepicker._getInst(this._calId);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   265
		if ($.datetimepicker._datetimepickerShowing)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   266
			switch (e.keyCode) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   267
				case 9:  $.datetimepicker._hideDatepicker(null, '');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   268
						break; // hide on tab out
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   269
				case 13: $.datetimepicker._selectDay(inst, inst._selectedMonth, inst._selectedYear,
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   270
							$('td.datetimepicker_daysCellOver', inst._datetimepickerDiv)[0]);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   271
						return false; // don't submit the form
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   272
						break; // select the value on enter
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   273
				case 27: $.datetimepicker._hideDatepicker(null, inst._get('speed'));
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   274
						break; // hide on escape
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   275
				case 33: $.datetimepicker._adjustDate(inst,
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   276
							(e.ctrlKey ? -1 : -inst._get('stepMonths')), (e.ctrlKey ? 'Y' : 'M'));
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   277
						break; // previous month/year on page up/+ ctrl
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   278
				case 34: $.datetimepicker._adjustDate(inst,
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   279
							(e.ctrlKey ? +1 : +inst._get('stepMonths')), (e.ctrlKey ? 'Y' : 'M'));
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   280
						break; // next month/year on page down/+ ctrl
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   281
				case 35: if (e.ctrlKey) $.datetimepicker._clearDate(inst);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   282
						break; // clear on ctrl+end
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   283
				case 36: if (e.ctrlKey) $.datetimepicker._gotoToday(inst);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   284
						break; // current on ctrl+home
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   285
				case 37: if (e.ctrlKey) $.datetimepicker._adjustDate(inst, -1, 'D');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   286
						break; // -1 day on ctrl+left
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   287
				case 38: if (e.ctrlKey) $.datetimepicker._adjustDate(inst, -7, 'D');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   288
						break; // -1 week on ctrl+up
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   289
				case 39: if (e.ctrlKey) $.datetimepicker._adjustDate(inst, +1, 'D');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   290
						break; // +1 day on ctrl+right
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   291
				case 40: if (e.ctrlKey) $.datetimepicker._adjustDate(inst, +7, 'D');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   292
						break; // +1 week on ctrl+down
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   293
			}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   294
		else if (e.keyCode == 36 && e.ctrlKey) // display the date picker on ctrl+home
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   295
			$.datetimepicker._showDatepicker(this);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   296
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   297
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   298
	/* Filter entered characters - based on date format. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   299
	_doKeyPress: function(e) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   300
		var inst = $.datetimepicker._getInst(this._calId);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   301
		var chars = $.datetimepicker._possibleChars(inst._get('dateFormat')+' '+inst._get('timeFormat'));
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   302
		var chr = String.fromCharCode(e.charCode == undefined ? e.keyCode : e.charCode);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   303
		return e.ctrlKey || (chr < ' ' || !chars || chars.indexOf(chr) > -1);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   304
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   305
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   306
	/* Attach the date picker to an input field. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   307
	_connectDatepicker: function(target, inst) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   308
		var input = $(target);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   309
		if (input.is('.' + this.markerClassName))
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   310
			return;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   311
		var appendText = inst._get('appendText');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   312
		var isRTL = inst._get('isRTL');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   313
		if (appendText) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   314
			if (isRTL)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   315
				input.before('<span class="datetimepicker_append">' + appendText);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   316
			else
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   317
				input.after('<span class="datetimepicker_append">' + appendText);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   318
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   319
		var showOn = inst._get('showOn');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   320
		if (showOn == 'focus' || showOn == 'both') // pop-up date picker when in the marked field
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   321
			input.focus(this._showDatepicker);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   322
		if (showOn == 'button' || showOn == 'both') { // pop-up date picker when button clicked
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   323
			input.wrap('<span class="datetimepicker_wrap">');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   324
			var buttonText = inst._get('buttonText');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   325
			var buttonImage = inst._get('buttonImage');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   326
			var trigger = $(inst._get('buttonImageOnly') ?
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   327
				$('<img>').addClass('datetimepicker_trigger').attr({ src: buttonImage, alt: buttonText, title: buttonText }) :
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   328
				$('<button>').addClass('datetimepicker_trigger').attr({ type: 'button' }).html(buttonImage != '' ?
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   329
						$('<img>').attr({ src:buttonImage, alt:buttonText, title:buttonText }) : buttonText));
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   330
			if (isRTL)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   331
				input.before(trigger);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   332
			else
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   333
				input.after(trigger);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   334
			trigger.click(function() {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   335
				if ($.datetimepicker._datetimepickerShowing && $.datetimepicker._lastInput == target)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   336
					$.datetimepicker._hideDatepicker();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   337
				else
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   338
					$.datetimepicker._showDatepicker(target);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   339
			});
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   340
        }
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   341
		input.addClass(this.markerClassName).keydown(this._doKeyDown).keypress(this._doKeyPress)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   342
			.bind("setData.datetimepicker", function(event, key, value) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   343
				inst._settings[key] = value;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   344
			}).bind("getData.datetimepicker", function(event, key) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   345
				return inst._get(key);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   346
			});
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   347
		input[0]._calId = inst._id;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   348
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   349
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   350
	/* Attach an inline date picker to a div. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   351
	_inlineDatepicker: function(target, inst) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   352
		var input = $(target);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   353
		if (input.is('.' + this.markerClassName))
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   354
			return;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   355
		input.addClass(this.markerClassName).append(inst._datetimepickerDiv)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   356
			.bind("setData.datetimepicker", function(event, key, value){
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   357
				inst._settings[key] = value;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   358
			}).bind("getData.datetimepicker", function(event, key){
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   359
				return inst._get(key);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   360
			});
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   361
		input[0]._calId = inst._id;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   362
		this._updateDatepicker(inst);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   363
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   364
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   365
	/* Tidy up after displaying the date picker. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   366
	_inlineShow: function(inst) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   367
		var numMonths = inst._getNumberOfMonths(); // fix width for dynamic number of date pickers
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   368
		inst._datetimepickerDiv.width(numMonths[1] * $('.datetimepicker', inst._datetimepickerDiv[0]).width());
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   369
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   370
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   371
	/* Pop-up the date picker in a "dialog" box.
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   372
	   @param  input     element - ignored
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   373
	   @param  dateText  string - the initial date to display (in the current format)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   374
	   @param  onSelect  function - the function(dateText) to call when a date is selected
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   375
	   @param  settings  object - update the dialog date picker instance's settings (anonymous object)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   376
	   @param  pos       int[2] - coordinates for the dialog's position within the screen or
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   377
	                     event - with x/y coordinates or
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   378
	                     leave empty for default (screen centre)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   379
	   @return the manager object */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   380
	_dialogDatepicker: function(input, dateText, onSelect, settings, pos) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   381
		var inst = this._dialogInst; // internal instance
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   382
		if (!inst) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   383
			inst = this._dialogInst = new DateTimepickerInstance({}, false);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   384
			this._dialogInput = $('<input type="text" size="1" style="position: absolute; top: -100px;"/>');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   385
			this._dialogInput.keydown(this._doKeyDown);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   386
			$('body').append(this._dialogInput);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   387
			this._dialogInput[0]._calId = inst._id;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   388
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   389
		extendRemove(inst._settings, settings || {});
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   390
		this._dialogInput.val(dateText);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   391
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   392
		this._pos = (pos ? (pos.length ? pos : [pos.pageX, pos.pageY]) : null);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   393
		if (!this._pos) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   394
			var browserWidth = window.innerWidth || document.documentElement.clientWidth ||	document.body.clientWidth;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   395
			var browserHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   396
			var scrollX = document.documentElement.scrollLeft || document.body.scrollLeft;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   397
			var scrollY = document.documentElement.scrollTop || document.body.scrollTop;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   398
			this._pos = // should use actual width/height below
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   399
				[(browserWidth / 2) - 100 + scrollX, (browserHeight / 2) - 150 + scrollY];
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   400
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   401
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   402
		// move input on screen for focus, but hidden behind dialog
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   403
		this._dialogInput.css('left', this._pos[0] + 'px').css('top', this._pos[1] + 'px');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   404
		inst._settings.onSelect = onSelect;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   405
		this._inDialog = true;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   406
		this._datetimepickerDiv.addClass('datetimepicker_dialog');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   407
		this._showDatepicker(this._dialogInput[0]);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   408
		if ($.blockUI)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   409
			$.blockUI(this._datetimepickerDiv);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   410
		return this;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   411
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   412
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   413
	/* Pop-up the date picker for a given input field.
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   414
	   @param  input  element - the input field attached to the date picker or
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   415
	                  event - if triggered by focus */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   416
	_showDatepicker: function(input) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   417
		input = input.target || input;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   418
		if (input.nodeName.toLowerCase() != 'input') // find from button/image trigger
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   419
			input = $('input', input.parentNode)[0];
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   420
		if ($.datetimepicker._isDisabledDatepicker(input) || $.datetimepicker._lastInput == input) // already here
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   421
			return;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   422
		var inst = $.datetimepicker._getInst(input._calId);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   423
		var beforeShow = inst._get('beforeShow');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   424
		extendRemove(inst._settings, (beforeShow ? beforeShow.apply(input, [input, inst]) : {}));
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   425
		$.datetimepicker._hideDatepicker(null, '');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   426
		$.datetimepicker._lastInput = input;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   427
		inst._setDateFromField(input);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   428
		if ($.datetimepicker._inDialog) // hide cursor
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   429
			input.value = '';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   430
		if (!$.datetimepicker._pos) { // position below input
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   431
			$.datetimepicker._pos = $.datetimepicker._findPos(input);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   432
			$.datetimepicker._pos[1] += input.offsetHeight; // add the height
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   433
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   434
		var isFixed = false;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   435
		$(input).parents().each(function() {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   436
			isFixed |= $(this).css('position') == 'fixed';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   437
		});
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   438
		if (isFixed && $.browser.opera) { // correction for Opera when fixed and scrolled
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   439
			$.datetimepicker._pos[0] -= document.documentElement.scrollLeft;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   440
			$.datetimepicker._pos[1] -= document.documentElement.scrollTop;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   441
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   442
		inst._datetimepickerDiv.css('position', ($.datetimepicker._inDialog && $.blockUI ?
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   443
			'static' : (isFixed ? 'fixed' : 'absolute')))
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   444
			.css({ left: $.datetimepicker._pos[0] + 'px', top: $.datetimepicker._pos[1] + 'px' });
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   445
		$.datetimepicker._pos = null;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   446
		inst._rangeStart = null;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   447
		$.datetimepicker._updateDatepicker(inst);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   448
		if (!inst._inline) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   449
			var speed = inst._get('speed');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   450
			var postProcess = function() {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   451
				$.datetimepicker._datetimepickerShowing = true;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   452
				$.datetimepicker._afterShow(inst);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   453
			};
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   454
			var showAnim = inst._get('showAnim') || 'show';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   455
			inst._datetimepickerDiv[showAnim](speed, postProcess);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   456
			if (speed == '')
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   457
				postProcess();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   458
			if (inst._input[0].type != 'hidden')
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   459
				inst._input[0].focus();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   460
			$.datetimepicker._curInst = inst;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   461
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   462
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   463
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   464
	/* Generate the date picker content. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   465
	_updateDatepicker: function(inst) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   466
		inst._datetimepickerDiv.empty().append(inst._generateDatepicker());
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   467
		var numMonths = inst._getNumberOfMonths();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   468
		if (numMonths[0] != 1 || numMonths[1] != 1)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   469
			inst._datetimepickerDiv.addClass('datetimepicker_multi');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   470
		else
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   471
			inst._datetimepickerDiv.removeClass('datetimepicker_multi');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   472
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   473
		if (inst._get('isRTL'))
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   474
			inst._datetimepickerDiv.addClass('datetimepicker_rtl');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   475
		else
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   476
			inst._datetimepickerDiv.removeClass('datetimepicker_rtl');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   477
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   478
		if (inst._input && inst._input[0].type != 'hidden')
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   479
			$(inst._input[0]).focus();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   480
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   481
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   482
	/* Tidy up after displaying the date picker. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   483
	_afterShow: function(inst) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   484
		var numMonths = inst._getNumberOfMonths(); // fix width for dynamic number of date pickers
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   485
		inst._datetimepickerDiv.width(numMonths[1] * $('.datetimepicker', inst._datetimepickerDiv[0])[0].offsetWidth);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   486
		if ($.browser.msie && parseInt($.browser.version) < 7) { // fix IE < 7 select problems
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   487
			$('iframe.datetimepicker_cover').css({width: inst._datetimepickerDiv.width() + 4,
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   488
				height: inst._datetimepickerDiv.height() + 4});
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   489
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   490
		// re-position on screen if necessary
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   491
		var isFixed = inst._datetimepickerDiv.css('position') == 'fixed';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   492
		var pos = inst._input ? $.datetimepicker._findPos(inst._input[0]) : null;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   493
		var browserWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   494
		var browserHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   495
		var scrollX = (isFixed ? 0 : document.documentElement.scrollLeft || document.body.scrollLeft);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   496
		var scrollY = (isFixed ? 0 : document.documentElement.scrollTop || document.body.scrollTop);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   497
		// reposition date picker horizontally if outside the browser window
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   498
		if ((inst._datetimepickerDiv.offset().left + inst._datetimepickerDiv.width() -
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   499
				(isFixed && $.browser.msie ? document.documentElement.scrollLeft : 0)) >
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   500
				(browserWidth + scrollX)) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   501
			inst._datetimepickerDiv.css('left', Math.max(scrollX,
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   502
				pos[0] + (inst._input ? $(inst._input[0]).width() : null) - inst._datetimepickerDiv.width() -
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   503
				(isFixed && $.browser.opera ? document.documentElement.scrollLeft : 0)) + 'px');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   504
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   505
		// reposition date picker vertically if outside the browser window
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   506
		if ((inst._datetimepickerDiv.offset().top + inst._datetimepickerDiv.height() -
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   507
				(isFixed && $.browser.msie ? document.documentElement.scrollTop : 0)) >
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   508
				(browserHeight + scrollY) ) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   509
			inst._datetimepickerDiv.css('top', Math.max(scrollY,
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   510
				pos[1] - (this._inDialog ? 0 : inst._datetimepickerDiv.height()) -
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   511
				(isFixed && $.browser.opera ? document.documentElement.scrollTop : 0)) + 'px');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   512
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   513
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   514
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   515
	/* Find an object's position on the screen. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   516
	_findPos: function(obj) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   517
        while (obj && (obj.type == 'hidden' || obj.nodeType != 1)) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   518
            obj = obj.nextSibling;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   519
        }
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   520
        var position = $(obj).offset();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   521
	    return [position.left, position.top];
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   522
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   523
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   524
	/* Hide the date picker from view.
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   525
	   @param  input  element - the input field attached to the date picker
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   526
	   @param  speed  string - the speed at which to close the date picker */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   527
	_hideDatepicker: function(input, speed) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   528
		var inst = this._curInst;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   529
		if (!inst)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   530
			return;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   531
		var rangeSelect = inst._get('rangeSelect');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   532
		if (rangeSelect && this._stayOpen) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   533
			this._selectDate(inst, inst._formatDateTime(
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   534
				inst._currentDay, inst._currentMonth, inst._currentYear, inst._currentHour, inst.currentMinute));
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   535
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   536
		this._stayOpen = false;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   537
		if (this._datetimepickerShowing) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   538
			speed = (speed != null ? speed : inst._get('speed'));
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   539
			var showAnim = inst._get('showAnim');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   540
			inst._datetimepickerDiv[(showAnim == 'slideDown' ? 'slideUp' :
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   541
				(showAnim == 'fadeIn' ? 'fadeOut' : 'hide'))](speed, function() {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   542
				$.datetimepicker._tidyDialog(inst);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   543
			});
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   544
			if (speed == '')
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   545
				this._tidyDialog(inst);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   546
			var onClose = inst._get('onClose');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   547
			if (onClose) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   548
				onClose.apply((inst._input ? inst._input[0] : null),
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   549
					[inst._getDate(), inst]);  // trigger custom callback
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   550
			}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   551
			this._datetimepickerShowing = false;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   552
			this._lastInput = null;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   553
			inst._settings.prompt = null;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   554
			if (this._inDialog) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   555
				this._dialogInput.css({ position: 'absolute', left: '0', top: '-100px' });
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   556
				if ($.blockUI) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   557
					$.unblockUI();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   558
					$('body').append(this._datetimepickerDiv);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   559
				}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   560
			}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   561
			this._inDialog = false;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   562
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   563
		this._curInst = null;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   564
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   565
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   566
	/* Tidy up after a dialog display. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   567
	_tidyDialog: function(inst) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   568
		inst._datetimepickerDiv.removeClass('datetimepicker_dialog').unbind('.datetimepicker');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   569
		$('.datetimepicker_prompt', inst._datetimepickerDiv).remove();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   570
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   571
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   572
	/* Close date picker if clicked elsewhere. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   573
	_checkExternalClick: function(event) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   574
		if (!$.datetimepicker._curInst)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   575
			return;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   576
		var $target = $(event.target);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   577
		if (($target.parents("#datetimepicker_div").length == 0) &&
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   578
				($target.attr('class') != 'datetimepicker_trigger') &&
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   579
				$.datetimepicker._datetimepickerShowing && !($.datetimepicker._inDialog && $.blockUI)) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   580
			$.datetimepicker._hideDatepicker(null, '');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   581
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   582
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   583
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   584
	/* Adjust one of the date sub-fields. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   585
	_adjustDate: function(id, offset, period) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   586
		var inst = this._getInst(id);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   587
		inst._adjustDate(offset, period);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   588
		this._updateDatepicker(inst);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   589
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   590
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   591
	/* Action for current link. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   592
	_gotoToday: function(id) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   593
		var date = new Date();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   594
		var inst = this._getInst(id);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   595
		inst._selectedDay = date.getDate();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   596
		inst._drawMonth = inst._selectedMonth = date.getMonth();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   597
		inst._drawYear = inst._selectedYear = date.getFullYear();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   598
		inst._drawHour = inst._selectedHour = date.getHours();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   599
		inst._drawMinute = inst._selectedMinute = date.getMinutes();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   600
		this._adjustDate(inst);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   601
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   602
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   603
	/* Action for selecting a new month/year. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   604
	_selectMonthYear: function(id, select, period) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   605
		var inst = this._getInst(id);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   606
		inst._selectingMonthYear = false;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   607
		inst[period == 'M' ? '_drawMonth' : '_drawYear'] =
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   608
			select.options[select.selectedIndex].value - 0;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   609
		this._adjustDate(inst);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   610
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   611
	_selectTime: function(id, select, period) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   612
		var inst = this._getInst(id);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   613
		inst._selectingMonthYear = false;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   614
		inst[period == 'M' ? '_drawMinute' : '_drawHour'] =
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   615
			select.options[select.selectedIndex].value - 0;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   616
		this._adjustDate(inst);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   617
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   618
		this._doNotHide = true;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   619
		$('td.datetimepicker_currentDay').each(function(){
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   620
			$.datetimepicker._selectDay(inst, inst._selectedMonth, inst._selectedYear,$(this));
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   621
		});
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   622
		this._doNotHide = false;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   623
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   624
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   625
	/* Restore input focus after not changing month/year. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   626
	_clickMonthYear: function(id) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   627
		var inst = this._getInst(id);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   628
		if (inst._input && inst._selectingMonthYear && !$.browser.msie)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   629
			inst._input[0].focus();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   630
		inst._selectingMonthYear = !inst._selectingMonthYear;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   631
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   632
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   633
	_clickTime: function(id) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   634
		var inst = this._getInst(id);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   635
		if (inst._input && inst._selectingTime && !$.browser.msie)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   636
			inst._input[0].focus();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   637
		inst._selectingTime = !inst._selectingTime;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   638
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   639
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   640
	/* Action for changing the first week day. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   641
	_changeFirstDay: function(id, day) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   642
		var inst = this._getInst(id);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   643
		inst._settings.firstDay = day;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   644
		this._updateDatepicker(inst);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   645
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   646
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   647
	/* Action for selecting a day. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   648
	_selectDay: function(id, month, year, td) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   649
		if ($(td).is('.datetimepicker_unselectable'))
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   650
			return;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   651
		var inst = this._getInst(id);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   652
		var rangeSelect = inst._get('rangeSelect');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   653
		if (rangeSelect) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   654
			if (!this._stayOpen) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   655
				$('.datetimepicker td').removeClass('datetimepicker_currentDay');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   656
				$(td).addClass('datetimepicker_currentDay');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   657
			}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   658
			this._stayOpen = !this._stayOpen;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   659
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   660
		inst._selectedDay = inst._currentDay = $('a', td).html();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   661
		inst._selectedMonth = inst._currentMonth = month;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   662
		inst._selectedYear = inst._currentYear = year;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   663
		inst._selectedHour = inst._currentHour = $('select.datetimepicker_newHour option:selected').val();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   664
		inst._selectedMinute = inst._currentMinute = $('select.datetimepicker_newMinute option:selected').val();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   665
		this._selectDate(id, inst._formatDateTime(
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   666
			inst._currentDay, inst._currentMonth, inst._currentYear, inst._currentHour, inst._currentMinute));
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   667
		if (this._stayOpen) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   668
			inst._endDay = inst._endMonth = inst._endYear = null;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   669
			inst._rangeStart = new Date(inst._currentYear, inst._currentMonth, inst._currentDay);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   670
			this._updateDatepicker(inst);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   671
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   672
		else if (rangeSelect) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   673
			inst._endDay = inst._currentDay;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   674
			inst._endMonth = inst._currentMonth;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   675
			inst._endYear = inst._currentYear;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   676
			inst._selectedDay = inst._currentDay = inst._rangeStart.getDate();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   677
			inst._selectedMonth = inst._currentMonth = inst._rangeStart.getMonth();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   678
			inst._selectedYear = inst._currentYear = inst._rangeStart.getFullYear();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   679
			inst._rangeStart = null;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   680
			if (inst._inline)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   681
				this._updateDatepicker(inst);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   682
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   683
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   684
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   685
	/* Erase the input field and hide the date picker. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   686
	_clearDate: function(id) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   687
		var inst = this._getInst(id);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   688
		if (inst._get('mandatory'))
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   689
			return;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   690
		this._stayOpen = false;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   691
		inst._endDay = inst._endMonth = inst._endYear = inst._rangeStart = null;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   692
		this._selectDate(inst, '');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   693
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   694
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   695
	/* Update the input field with the selected date. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   696
	_selectDate: function(id, dateStr) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   697
		var inst = this._getInst(id);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   698
		dateStr = (dateStr != null ? dateStr : inst._formatDateTime());
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   699
		if (inst._rangeStart)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   700
			dateStr = inst._formatDateTime(inst._rangeStart) + inst._get('rangeSeparator') + dateStr;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   701
		if (inst._input)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   702
			inst._input.val(dateStr);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   703
		var onSelect = inst._get('onSelect');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   704
		if (onSelect)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   705
			onSelect.apply((inst._input ? inst._input[0] : null), [dateStr, inst]);  // trigger custom callback
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   706
		else if (inst._input)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   707
			inst._input.trigger('change'); // fire the change event
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   708
		if (inst._inline)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   709
			this._updateDatepicker(inst);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   710
		else if (!this._stayOpen) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   711
			if (! this._doNotHide) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   712
				this._hideDatepicker(null, inst._get('speed'));
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   713
				this._lastInput = inst._input[0];
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   714
				if (typeof(inst._input[0]) != 'object')
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   715
					inst._input[0].focus(); // restore focus
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   716
				this._lastInput = null;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   717
			}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   718
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   719
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   720
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   721
	/* Set as beforeShowDay function to prevent selection of weekends.
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   722
	   @param  date  Date - the date to customise
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   723
	   @return [boolean, string] - is this date selectable?, what is its CSS class? */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   724
	noWeekends: function(date) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   725
		var day = date.getDay();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   726
		return [(day > 0 && day < 6), ''];
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   727
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   728
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   729
	/* Set as calculateWeek to determine the week of the year based on the ISO 8601 definition.
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   730
	   @param  date  Date - the date to get the week for
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   731
	   @return  number - the number of the week within the year that contains this date */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   732
	iso8601Week: function(date) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   733
		var checkDate = new Date(date.getFullYear(), date.getMonth(), date.getDate(), (date.getTimezoneOffset() / -60));
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   734
		var firstMon = new Date(checkDate.getFullYear(), 1 - 1, 4); // First week always contains 4 Jan
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   735
		var firstDay = firstMon.getDay() || 7; // Day of week: Mon = 1, ..., Sun = 7
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   736
		firstMon.setDate(firstMon.getDate() + 1 - firstDay); // Preceding Monday
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   737
		if (firstDay < 4 && checkDate < firstMon) { // Adjust first three days in year if necessary
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   738
			checkDate.setDate(checkDate.getDate() - 3); // Generate for previous year
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   739
			return $.datetimepicker.iso8601Week(checkDate);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   740
		} else if (checkDate > new Date(checkDate.getFullYear(), 12 - 1, 28)) { // Check last three days in year
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   741
			firstDay = new Date(checkDate.getFullYear() + 1, 1 - 1, 4).getDay() || 7;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   742
			if (firstDay > 4 && (checkDate.getDay() || 7) < firstDay - 3) { // Adjust if necessary
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   743
				checkDate.setDate(checkDate.getDate() + 3); // Generate for next year
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   744
				return $.datetimepicker.iso8601Week(checkDate);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   745
			}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   746
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   747
		return Math.floor(((checkDate - firstMon) / 86400000) / 7) + 1; // Weeks to given date
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   748
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   749
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   750
	/* Provide status text for a particular date.
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   751
	   @param  date  the date to get the status for
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   752
	   @param  inst  the current datetimepicker instance
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   753
	   @return  the status display text for this date */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   754
	dateStatus: function(date, inst) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   755
		return $.datetimepicker.formatDate(inst._get('dateStatus'), date, inst._getFormatConfig());
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   756
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   757
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   758
	/* Parse a string value into a date object.
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   759
	   The format can be combinations of the following:
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   760
	   d  - day of month (no leading zero)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   761
	   dd - day of month (two digit)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   762
	   D  - day name short
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   763
	   DD - day name long
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   764
	   m  - month of year (no leading zero)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   765
	   mm - month of year (two digit)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   766
	   M  - month name short
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   767
	   MM - month name long
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   768
	   y  - year (two digit)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   769
	   yy - year (four digit)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   770
	   '...' - literal text
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   771
	   '' - single quote
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   772
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   773
	   @param  format           String - the expected format of the date
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   774
	   @param  value            String - the date in the above format
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   775
	   @param  settings  Object - attributes include:
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   776
	                     shortYearCutoff  Number - the cutoff year for determining the century (optional)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   777
	                     dayNamesShort    String[7] - abbreviated names of the days from Sunday (optional)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   778
	                     dayNames         String[7] - names of the days from Sunday (optional)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   779
	                     monthNamesShort  String[12] - abbreviated names of the months (optional)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   780
	                     monthNames       String[12] - names of the months (optional)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   781
	   @return  Date - the extracted date value or null if value is blank */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   782
	parseDate: function (format, value, settings) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   783
		if (format == null || value == null)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   784
			throw 'Invalid arguments';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   785
		value = (typeof value == 'object' ? value.toString() : value + '');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   786
		if (value == '')
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   787
			return null;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   788
		var shortYearCutoff = (settings ? settings.shortYearCutoff : null) || this._defaults.shortYearCutoff;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   789
		var dayNamesShort = (settings ? settings.dayNamesShort : null) || this._defaults.dayNamesShort;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   790
		var dayNames = (settings ? settings.dayNames : null) || this._defaults.dayNames;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   791
		var monthNamesShort = (settings ? settings.monthNamesShort : null) || this._defaults.monthNamesShort;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   792
		var monthNames = (settings ? settings.monthNames : null) || this._defaults.monthNames;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   793
		var year = -1;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   794
		var month = -1;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   795
		var day = -1;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   796
		var hour = -1;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   797
		var minute = -1;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   798
		var literal = false;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   799
		// Check whether a format character is doubled
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   800
		var lookAhead = function(match) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   801
			var matches = (iFormat + 1 < format.length && format.charAt(iFormat + 1) == match);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   802
			if (matches)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   803
				iFormat++;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   804
			return matches;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   805
		};
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   806
		// Extract a number from the string value
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   807
		var getNumber = function(match) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   808
			lookAhead(match);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   809
			var size = (match == 'y' ? 4 : 2);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   810
			var num = 0;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   811
			while (size > 0 && iValue < value.length &&
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   812
					value.charAt(iValue) >= '0' && value.charAt(iValue) <= '9') {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   813
				num = num * 10 + (value.charAt(iValue++) - 0);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   814
				size--;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   815
			}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   816
			if (size == (match == 'y' ? 4 : 2))
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   817
				throw 'Missing number at position ' + iValue;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   818
			return num;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   819
		};
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   820
		// Extract a name from the string value and convert to an index
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   821
		var getName = function(match, shortNames, longNames) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   822
			var names = (lookAhead(match) ? longNames : shortNames);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   823
			var size = 0;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   824
			for (var j = 0; j < names.length; j++)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   825
				size = Math.max(size, names[j].length);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   826
			var name = '';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   827
			var iInit = iValue;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   828
			while (size > 0 && iValue < value.length) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   829
				name += value.charAt(iValue++);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   830
				for (var i = 0; i < names.length; i++)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   831
					if (name == names[i])
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   832
						return i + 1;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   833
				size--;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   834
			}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   835
			throw 'Unknown name at position ' + iInit;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   836
		};
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   837
		// Confirm that a literal character matches the string value
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   838
		var checkLiteral = function() {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   839
			if (value.charAt(iValue) != format.charAt(iFormat))
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   840
				throw 'Unexpected literal at position ' + iValue;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   841
			iValue++;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   842
		};
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   843
		var iValue = 0;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   844
		for (var iFormat = 0; iFormat < format.length; iFormat++) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   845
			if (literal)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   846
				if (format.charAt(iFormat) == "'" && !lookAhead("'"))
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   847
					literal = false;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   848
				else
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   849
					checkLiteral();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   850
			else
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   851
				switch (format.charAt(iFormat)) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   852
					case 'h':
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   853
						hour = getNumber('h');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   854
						break;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   855
					case 'i':
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   856
						minute = getNumber('i');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   857
						break;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   858
					case 'd':
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   859
						day = getNumber('d');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   860
						break;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   861
					case 'D':
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   862
						getName('D', dayNamesShort, dayNames);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   863
						break;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   864
					case 'm':
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   865
						month = getNumber('m');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   866
						break;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   867
					case 'M':
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   868
						month = getName('M', monthNamesShort, monthNames);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   869
						break;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   870
					case 'y':
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   871
						year = getNumber('y');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   872
						break;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   873
					case "'":
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   874
						if (lookAhead("'"))
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   875
							checkLiteral();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   876
						else
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   877
							literal = true;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   878
						break;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   879
					default:
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   880
						checkLiteral();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   881
				}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   882
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   883
		if (year < 100) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   884
			year += new Date().getFullYear() - new Date().getFullYear() % 100 +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   885
				(year <= shortYearCutoff ? 0 : -100);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   886
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   887
		var date = new Date(year, month - 1, day,hour,minute);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   888
		if (date.getFullYear() != year || date.getMonth() + 1 != month || date.getDate() != day) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   889
			throw 'Invalid date'; // E.g. 31/02/*
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   890
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   891
		return date;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   892
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   893
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   894
	/* Format a date object into a string value.
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   895
	   The format can be combinations of the following:
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   896
	   d  - day of month (no leading zero)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   897
	   dd - day of month (two digit)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   898
	   D  - day name short
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   899
	   DD - day name long
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   900
	   m  - month of year (no leading zero)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   901
	   mm - month of year (two digit)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   902
	   M  - month name short
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   903
	   MM - month name long
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   904
	   y  - year (two digit)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   905
	   yy - year (four digit)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   906
	   '...' - literal text
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   907
	   '' - single quote
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   908
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   909
	   @param  format    String - the desired format of the date
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   910
	   @param  date      Date - the date value to format
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   911
	   @param  settings  Object - attributes include:
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   912
	                     dayNamesShort    String[7] - abbreviated names of the days from Sunday (optional)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   913
	                     dayNames         String[7] - names of the days from Sunday (optional)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   914
	                     monthNamesShort  String[12] - abbreviated names of the months (optional)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   915
	                     monthNames       String[12] - names of the months (optional)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   916
	   @return  String - the date in the above format */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   917
	formatDate: function (format, date, settings) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   918
		if (!date)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   919
			return '';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   920
		var dayNamesShort = (settings ? settings.dayNamesShort : null) || this._defaults.dayNamesShort;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   921
		var dayNames = (settings ? settings.dayNames : null) || this._defaults.dayNames;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   922
		var monthNamesShort = (settings ? settings.monthNamesShort : null) || this._defaults.monthNamesShort;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   923
		var monthNames = (settings ? settings.monthNames : null) || this._defaults.monthNames;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   924
		// Check whether a format character is doubled
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   925
		var lookAhead = function(match) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   926
			var matches = (iFormat + 1 < format.length && format.charAt(iFormat + 1) == match);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   927
			if (matches)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   928
				iFormat++;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   929
			return matches;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   930
		};
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   931
		// Format a number, with leading zero if necessary
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   932
		var formatNumber = function(match, value) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   933
			return (lookAhead(match) && value < 10 ? '0' : '') + value;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   934
		};
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   935
		// Format a name, short or long as requested
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   936
		var formatName = function(match, value, shortNames, longNames) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   937
			return (lookAhead(match) ? longNames[value] : shortNames[value]);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   938
		};
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   939
		var output = '';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   940
		var literal = false;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   941
		if (date) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   942
			for (var iFormat = 0; iFormat < format.length; iFormat++) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   943
				if (literal)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   944
					if (format.charAt(iFormat) == "'" && !lookAhead("'"))
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   945
						literal = false;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   946
					else
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   947
						output += format.charAt(iFormat);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   948
				else
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   949
					switch (format.charAt(iFormat)) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   950
						case 'h':
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   951
							output += formatNumber('h', date.getHours());
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   952
							break;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   953
						case 'i':
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   954
							output += formatNumber('i', date.getMinutes());
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   955
							break;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   956
						case 'd':
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   957
							output += formatNumber('d', date.getDate());
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   958
							break;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   959
						case 'D':
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   960
							output += formatName('D', date.getDay(), dayNamesShort, dayNames);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   961
							break;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   962
						case 'm':
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   963
							output += formatNumber('m', date.getMonth() + 1);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   964
							break;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   965
						case 'M':
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   966
							output += formatName('M', date.getMonth(), monthNamesShort, monthNames);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   967
							break;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   968
						case 'y':
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   969
							output += (lookAhead('y') ? date.getFullYear() :
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   970
								(date.getYear() % 100 < 10 ? '0' : '') + date.getYear() % 100);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   971
							break;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   972
						case "'":
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   973
							if (lookAhead("'"))
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   974
								output += "'";
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   975
							else
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   976
								literal = true;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   977
							break;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   978
						default:
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   979
							output += format.charAt(iFormat);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   980
					}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   981
			}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   982
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   983
		return output;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   984
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   985
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   986
	/* Extract all possible characters from the date format. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   987
	_possibleChars: function (format) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   988
		var chars = '';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   989
		var literal = false;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   990
		for (var iFormat = 0; iFormat < format.length; iFormat++)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   991
			if (literal)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   992
				if (format.charAt(iFormat) == "'" && !lookAhead("'"))
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   993
					literal = false;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   994
				else
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   995
					chars += format.charAt(iFormat);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   996
			else
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   997
				switch (format.charAt(iFormat)) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   998
					case 'd' || 'm' || 'y':
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
   999
						chars += '0123456789';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1000
						break;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1001
					case 'D' || 'M':
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1002
						return null; // Accept anything
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1003
					case "'":
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1004
						if (lookAhead("'"))
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1005
							chars += "'";
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1006
						else
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1007
							literal = true;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1008
						break;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1009
					default:
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1010
						chars += format.charAt(iFormat);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1011
				}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1012
		return chars;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1013
	}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1014
});
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1015
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1016
/* Individualised settings for date picker functionality applied to one or more related inputs.
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1017
   Instances are managed and manipulated through the Datepicker manager. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1018
function DateTimepickerInstance(settings, inline) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1019
	this._id = $.datetimepicker._register(this);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1020
	this._selectedDay = 0; // Current date for selection
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1021
	this._selectedMonth = 0; // 0-11
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1022
	this._selectedYear = 0; // 4-digit year
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1023
	this._drawMonth = 0; // Current month at start of datetimepicker
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1024
	this._drawYear = 0;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1025
	this._drawHour = 0;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1026
	this._drawMinute = 0;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1027
	this._input = null; // The attached input field
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1028
	this._inline = inline; // True if showing inline, false if used in a popup
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1029
	this._datetimepickerDiv = (!inline ? $.datetimepicker._datetimepickerDiv :
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1030
		$('<div id="datetimepicker_div_' + this._id + '" class="datetimepicker_inline">'));
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1031
	// customise the date picker object - uses manager defaults if not overridden
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1032
	this._settings = extendRemove(settings || {}); // clone
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1033
	if (inline)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1034
		this._setDate(this._getDefaultDate());
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1035
}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1036
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1037
$.extend(DateTimepickerInstance.prototype, {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1038
	/* Get a setting value, defaulting if necessary. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1039
	_get: function(name) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1040
		return this._settings[name] !== undefined ? this._settings[name] : $.datetimepicker._defaults[name];
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1041
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1042
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1043
	/* Parse existing date and initialise date picker. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1044
	_setDateFromField: function(input) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1045
		this._input = $(input);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1046
		var dateFormat = this._get('dateFormat')+' '+this._get('timeFormat');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1047
		var dates = this._input ? this._input.val().split(this._get('rangeSeparator')) : null;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1048
		this._endDay = this._endMonth = this._endYear = null;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1049
		var date = defaultDate = this._getDefaultDate();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1050
		if (dates.length > 0) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1051
			var settings = this._getFormatConfig();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1052
			if (dates.length > 1) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1053
				date = $.datetimepicker.parseDate(dateFormat, dates[1], settings) || defaultDate;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1054
				this._endDay = date.getDate();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1055
				this._endMonth = date.getMonth();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1056
				this._endYear = date.getFullYear();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1057
			}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1058
			try {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1059
				date = $.datetimepicker.parseDate(dateFormat, dates[0], settings) || defaultDate;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1060
			} catch (e) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1061
				$.datetimepicker.log(e);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1062
				date = defaultDate;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1063
			}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1064
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1065
		this._selectedDay = date.getDate();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1066
		this._drawMonth = this._selectedMonth = date.getMonth();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1067
		this._drawYear = this._selectedYear = date.getFullYear();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1068
		this._drawHour = this._selectedHour = date.getHours();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1069
		this._drawMinute = this._selectedMinute = date.getMinutes();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1070
		this._currentDay = (dates[0] ? date.getDate() : 0);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1071
		this._currentMonth = (dates[0] ? date.getMonth() : 0);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1072
		this._currentYear = (dates[0] ? date.getFullYear() : 0);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1073
		this._adjustDate();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1074
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1075
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1076
	/* Retrieve the default date shown on opening. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1077
	_getDefaultDate: function() {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1078
		var date = this._determineDate('defaultDate', new Date());
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1079
		var minDate = this._getMinMaxDate('min', true);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1080
		var maxDate = this._getMinMaxDate('max');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1081
		date = (minDate && date < minDate ? minDate : date);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1082
		date = (maxDate && date > maxDate ? maxDate : date);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1083
		return date;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1084
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1085
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1086
	/* A date may be specified as an exact value or a relative one. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1087
	_determineDate: function(name, defaultDate) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1088
		var offsetNumeric = function(offset) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1089
			var date = new Date();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1090
			date.setDate(date.getDate() + offset);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1091
			return date;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1092
		};
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1093
		var offsetString = function(offset, getDaysInMonth) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1094
			var date = new Date();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1095
			var matches = /^([+-]?[0-9]+)\s*(d|D|w|W|m|M|y|Y)?$/.exec(offset);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1096
			if (matches) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1097
				var year = date.getFullYear();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1098
				var month = date.getMonth();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1099
				var day = date.getDate();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1100
				switch (matches[2] || 'd') {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1101
					case 'd' : case 'D' :
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1102
						day += (matches[1] - 0); break;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1103
					case 'w' : case 'W' :
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1104
						day += (matches[1] * 7); break;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1105
					case 'm' : case 'M' :
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1106
						month += (matches[1] - 0);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1107
						day = Math.min(day, getDaysInMonth(year, month));
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1108
						break;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1109
					case 'y': case 'Y' :
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1110
						year += (matches[1] - 0);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1111
						day = Math.min(day, getDaysInMonth(year, month));
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1112
						break;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1113
				}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1114
				date = new Date(year, month, day);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1115
			}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1116
			return date;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1117
		};
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1118
		var date = this._get(name);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1119
		return (date == null ? defaultDate :
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1120
			(typeof date == 'string' ? offsetString(date, this._getDaysInMonth) :
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1121
			(typeof date == 'number' ? offsetNumeric(date) : date)));
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1122
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1123
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1124
	/* Set the date(s) directly. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1125
	_setDate: function(date, endDate) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1126
		this._selectedDay = this._currentDay = date.getDate();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1127
		this._drawMonth = this._selectedMonth = this._currentMonth = date.getMonth();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1128
		this._drawYear = this._selectedYear = this._currentYear = date.getFullYear();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1129
		this._drawHour = this._selectedHour = this._currentHour = date.getHours();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1130
		this._drawMinute = this._selectedMinute = this._currentMinute = date.getMinutes();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1131
		if (this._get('rangeSelect')) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1132
			if (endDate) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1133
				this._endDay = endDate.getDate();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1134
				this._endMonth = endDate.getMonth();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1135
				this._endYear = endDate.getFullYear();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1136
			} else {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1137
				this._endDay = this._currentDay;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1138
				this._endMonth = this._currentMonth;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1139
				this._endYear = this._currentYear;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1140
			}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1141
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1142
		this._adjustDate();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1143
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1144
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1145
	/* Retrieve the date(s) directly. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1146
	_getDate: function() {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1147
		var startDate = (!this._currentYear || (this._input && this._input.val() == '') ? null :
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1148
			new Date(this._currentYear, this._currentMonth, this._currentDay));
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1149
		if (this._get('rangeSelect')) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1150
			return [startDate, (!this._endYear ? null :
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1151
				new Date(this._endYear, this._endMonth, this._endDay))];
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1152
		} else
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1153
			return startDate;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1154
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1155
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1156
	/* Generate the HTML for the current state of the date picker. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1157
	_generateDatepicker: function() {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1158
		var today = new Date();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1159
		today = new Date(today.getFullYear(), today.getMonth(), today.getDate()); // clear time
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1160
		var showStatus = this._get('showStatus');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1161
		var isRTL = this._get('isRTL');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1162
		// build the date picker HTML
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1163
		var clear = (this._get('mandatory') ? '' :
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1164
			'<div class="datetimepicker_clear"><a onclick="jQuery.datetimepicker._clearDate(' + this._id + ');"' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1165
			(showStatus ? this._addStatus(this._get('clearStatus') || '&#xa0;') : '') + '>' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1166
			this._get('clearText') + '</a></div>');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1167
		var controls = '<div class="datetimepicker_control">' + (isRTL ? '' : clear) +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1168
			'<div class="datetimepicker_close"><a onclick="jQuery.datetimepicker._hideDatepicker();"' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1169
			(showStatus ? this._addStatus(this._get('closeStatus') || '&#xa0;') : '') + '>' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1170
			this._get('closeText') + '</a></div>' + (isRTL ? clear : '')  + '</div>';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1171
		var prompt = this._get('prompt');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1172
		var closeAtTop = this._get('closeAtTop');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1173
		var hideIfNoPrevNext = this._get('hideIfNoPrevNext');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1174
		var numMonths = this._getNumberOfMonths();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1175
		var stepMonths = this._get('stepMonths');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1176
		var isMultiMonth = (numMonths[0] != 1 || numMonths[1] != 1);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1177
		var minDate = this._getMinMaxDate('min', true);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1178
		var maxDate = this._getMinMaxDate('max');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1179
		var drawMonth = this._drawMonth;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1180
		var drawYear = this._drawYear;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1181
		var drawHour = this._drawHour;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1182
		var drawMinute = this._drawMinute;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1183
		if (maxDate) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1184
			var maxDraw = new Date(maxDate.getFullYear(),
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1185
				maxDate.getMonth() - numMonths[1] + 1, maxDate.getDate());
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1186
			maxDraw = (minDate && maxDraw < minDate ? minDate : maxDraw);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1187
			while (new Date(drawYear, drawMonth, 1) > maxDraw) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1188
				drawMonth--;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1189
				if (drawMonth < 0) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1190
					drawMonth = 11;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1191
					drawYear--;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1192
				}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1193
			}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1194
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1195
		// controls and links
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1196
		var prev = '<div class="datetimepicker_prev">' + (this._canAdjustMonth(-1, drawYear, drawMonth) ?
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1197
			'<a onclick="jQuery.datetimepicker._adjustDate(' + this._id + ', -' + stepMonths + ', \'M\');"' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1198
			(showStatus ? this._addStatus(this._get('prevStatus') || '&#xa0;') : '') + '>' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1199
			this._get('prevText') + '</a>' :
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1200
			(hideIfNoPrevNext ? '' : '<label>' + this._get('prevText') + '</label>')) + '</div>';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1201
		var next = '<div class="datetimepicker_next">' + (this._canAdjustMonth(+1, drawYear, drawMonth) ?
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1202
			'<a onclick="jQuery.datetimepicker._adjustDate(' + this._id + ', +' + stepMonths + ', \'M\');"' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1203
			(showStatus ? this._addStatus(this._get('nextStatus') || '&#xa0;') : '') + '>' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1204
			this._get('nextText') + '</a>' :
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1205
			(hideIfNoPrevNext ? '>' : '<label>' + this._get('nextText') + '</label>')) + '</div>';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1206
		var html = (prompt ? '<div class="datetimepicker_prompt">' + prompt + '</div>' : '') +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1207
			(closeAtTop && !this._inline ? controls : '') +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1208
			'<div class="datetimepicker_links">' + (isRTL ? next : prev) +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1209
			(this._isInRange(today) ? '<div class="datetimepicker_current">' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1210
			'<a onclick="jQuery.datetimepicker._gotoToday(' + this._id + ');"' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1211
			(showStatus ? this._addStatus(this._get('currentStatus') || '&#xa0;') : '') + '>' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1212
			this._get('currentText') + '</a></div>' : '') + (isRTL ? prev : next) + '</div>';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1213
		var showWeeks = this._get('showWeeks');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1214
		for (var row = 0; row < numMonths[0]; row++)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1215
			for (var col = 0; col < numMonths[1]; col++) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1216
				var selectedDate = new Date(drawYear, drawMonth, this._selectedDay, drawHour, drawMinute);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1217
				html += '<div class="datetimepicker_oneMonth' + (col == 0 ? ' datetimepicker_newRow' : '') + '">' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1218
					this._generateMonthYearHeader(drawMinute,drawHour,drawMonth, drawYear, minDate, maxDate,
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1219
					selectedDate, row > 0 || col > 0) + // draw month headers
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1220
					'<table class="datetimepicker" cellpadding="0" cellspacing="0"><thead>' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1221
					'<tr class="datetimepicker_titleRow">' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1222
					(showWeeks ? '<td>' + this._get('weekHeader') + '</td>' : '');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1223
				var firstDay = this._get('firstDay');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1224
				var changeFirstDay = this._get('changeFirstDay');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1225
				var dayNames = this._get('dayNames');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1226
				var dayNamesShort = this._get('dayNamesShort');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1227
				var dayNamesMin = this._get('dayNamesMin');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1228
				for (var dow = 0; dow < 7; dow++) { // days of the week
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1229
					var day = (dow + firstDay) % 7;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1230
					var status = this._get('dayStatus') || '&#xa0;';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1231
					status = (status.indexOf('DD') > -1 ? status.replace(/DD/, dayNames[day]) :
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1232
						status.replace(/D/, dayNamesShort[day]));
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1233
					html += '<td' + ((dow + firstDay + 6) % 7 >= 5 ? ' class="datetimepicker_weekEndCell"' : '') + '>' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1234
						(!changeFirstDay ? '<span' :
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1235
						'<a onclick="jQuery.datetimepicker._changeFirstDay(' + this._id + ', ' + day + ');"') +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1236
						(showStatus ? this._addStatus(status) : '') + ' title="' + dayNames[day] + '">' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1237
						dayNamesMin[day] + (changeFirstDay ? '</a>' : '</span>') + '</td>';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1238
				}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1239
				html += '</tr></thead><tbody>';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1240
				var daysInMonth = this._getDaysInMonth(drawYear, drawMonth);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1241
				if (drawYear == this._selectedYear && drawMonth == this._selectedMonth) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1242
					this._selectedDay = Math.min(this._selectedDay, daysInMonth);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1243
				}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1244
				var leadDays = (this._getFirstDayOfMonth(drawYear, drawMonth) - firstDay + 7) % 7;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1245
				var currentDate = (!this._currentDay ? new Date(9999, 9, 9) :
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1246
					new Date(this._currentYear, this._currentMonth, this._currentDay));
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1247
				var endDate = this._endDay ? new Date(this._endYear, this._endMonth, this._endDay) : currentDate;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1248
				var printDate = new Date(drawYear, drawMonth, 1 - leadDays);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1249
				var numRows = (isMultiMonth ? 6 : Math.ceil((leadDays + daysInMonth) / 7)); // calculate the number of rows to generate
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1250
				var beforeShowDay = this._get('beforeShowDay');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1251
				var showOtherMonths = this._get('showOtherMonths');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1252
				var calculateWeek = this._get('calculateWeek') || $.datetimepicker.iso8601Week;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1253
				var dateStatus = this._get('statusForDate') || $.datetimepicker.dateStatus;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1254
				for (var dRow = 0; dRow < numRows; dRow++) { // create date picker rows
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1255
					html += '<tr class="datetimepicker_daysRow">' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1256
						(showWeeks ? '<td class="datetimepicker_weekCol">' + calculateWeek(printDate) + '</td>' : '');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1257
					for (var dow = 0; dow < 7; dow++) { // create date picker days
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1258
						var daySettings = (beforeShowDay ?
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1259
							beforeShowDay.apply((this._input ? this._input[0] : null), [printDate]) : [true, '']);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1260
						var otherMonth = (printDate.getMonth() != drawMonth);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1261
						var unselectable = otherMonth || !daySettings[0] ||
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1262
							(minDate && printDate < minDate) || (maxDate && printDate > maxDate);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1263
						html += '<td class="datetimepicker_daysCell' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1264
							((dow + firstDay + 6) % 7 >= 5 ? ' datetimepicker_weekEndCell' : '') + // highlight weekends
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1265
							(otherMonth ? ' datetimepicker_otherMonth' : '') + // highlight days from other months
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1266
							(printDate.getTime() == selectedDate.getTime() && drawMonth == this._selectedMonth ?
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1267
							' datetimepicker_daysCellOver' : '') + // highlight selected day
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1268
							(unselectable ? ' datetimepicker_unselectable' : '') +  // highlight unselectable days
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1269
							(otherMonth && !showOtherMonths ? '' : ' ' + daySettings[1] + // highlight custom dates
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1270
							(printDate.getTime() >= currentDate.getTime() && printDate.getTime() <= endDate.getTime() ?  // in current range
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1271
							' datetimepicker_currentDay' : '') + // highlight selected day
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1272
							(printDate.getTime() == today.getTime() ? ' datetimepicker_today' : '')) + '"' + // highlight today (if different)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1273
							(unselectable ? '' : ' onmouseover="jQuery(this).addClass(\'datetimepicker_daysCellOver\');' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1274
							(!showStatus || (otherMonth && !showOtherMonths) ? '' : 'jQuery(\'#datetimepicker_status_' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1275
							this._id + '\').html(\'' + (dateStatus.apply((this._input ? this._input[0] : null),
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1276
							[printDate, this]) || '&#xa0;') +'\');') + '"' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1277
							' onmouseout="jQuery(this).removeClass(\'datetimepicker_daysCellOver\');' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1278
							(!showStatus || (otherMonth && !showOtherMonths) ? '' : 'jQuery(\'#datetimepicker_status_' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1279
							this._id + '\').html(\'&#xa0;\');') + '" onclick="jQuery.datetimepicker._selectDay(' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1280
							this._id + ',' + drawMonth + ',' + drawYear + ', this);"') + '>' + // actions
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1281
							(otherMonth ? (showOtherMonths ? printDate.getDate() : '&#xa0;') : // display for other months
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1282
							(unselectable ? printDate.getDate() : '<a>' + printDate.getDate() + '</a>')) + '</td>'; // display for this month
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1283
						printDate.setDate(printDate.getDate() + 1);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1284
					}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1285
					html += '</tr>';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1286
				}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1287
				drawMonth++;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1288
				if (drawMonth > 11) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1289
					drawMonth = 0;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1290
					drawYear++;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1291
				}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1292
				html += '</tbody></table></div>';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1293
			}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1294
		html += (showStatus ? '<div style="clear: both;"></div><div id="datetimepicker_status_' + this._id +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1295
			'" class="datetimepicker_status">' + (this._get('initStatus') || '&#xa0;') + '</div>' : '') +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1296
			(!closeAtTop && !this._inline ? controls : '') +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1297
			'<div style="clear: both;"></div>' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1298
			($.browser.msie && parseInt($.browser.version) < 7 && !this._inline ?
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1299
			'<iframe src="javascript:false;" class="datetimepicker_cover"></iframe>' : '');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1300
		return html;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1301
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1302
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1303
	/* Generate the month and year header. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1304
	_generateMonthYearHeader: function(drawMinute,drawHour,drawMonth, drawYear, minDate, maxDate, selectedDate, secondary) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1305
		minDate = (this._rangeStart && minDate && selectedDate < minDate ? selectedDate : minDate);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1306
		var showStatus = this._get('showStatus');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1307
		var html = '<div class="datetimepicker_header">';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1308
		// month selection
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1309
		var monthNames = this._get('monthNames');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1310
		if (secondary || !this._get('changeMonth'))
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1311
			html += monthNames[drawMonth] + '&#xa0;';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1312
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1313
		else {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1314
			var inMinYear = (minDate && minDate.getFullYear() == drawYear);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1315
			var inMaxYear = (maxDate && maxDate.getFullYear() == drawYear);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1316
			html += '<select class="datetimepicker_newMonth" ' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1317
				'onchange="jQuery.datetimepicker._selectMonthYear(' + this._id + ', this, \'M\');" ' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1318
				'onclick="jQuery.datetimepicker._clickMonthYear(' + this._id + ');"' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1319
				(showStatus ? this._addStatus(this._get('monthStatus') || '&#xa0;') : '') + '>';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1320
			for (var month = 0; month < 12; month++) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1321
				if ((!inMinYear || month >= minDate.getMonth()) &&
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1322
						(!inMaxYear || month <= maxDate.getMonth())) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1323
					html += '<option value="' + month + '"' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1324
						(month == drawMonth ? ' selected="selected"' : '') +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1325
						'>' + monthNames[month] + '</option>';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1326
				}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1327
			}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1328
			html += '</select>';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1329
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1330
		// year selection
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1331
		if (secondary || !this._get('changeYear'))
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1332
			html += drawYear;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1333
		else {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1334
			// determine range of years to display
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1335
			var years = this._get('yearRange').split(':');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1336
			var year = 0;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1337
			var endYear = 0;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1338
			if (years.length != 2) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1339
				year = drawYear - 10;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1340
				endYear = drawYear + 10;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1341
			} else if (years[0].charAt(0) == '+' || years[0].charAt(0) == '-') {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1342
				year = drawYear + parseInt(years[0], 10);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1343
				endYear = drawYear + parseInt(years[1], 10);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1344
			} else {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1345
				year = parseInt(years[0], 10);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1346
				endYear = parseInt(years[1], 10);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1347
			}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1348
			year = (minDate ? Math.max(year, minDate.getFullYear()) : year);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1349
			endYear = (maxDate ? Math.min(endYear, maxDate.getFullYear()) : endYear);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1350
			html += '<select class="datetimepicker_newYear" ' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1351
				'onchange="jQuery.datetimepicker._selectMonthYear(' + this._id + ', this, \'Y\');" ' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1352
				'onclick="jQuery.datetimepicker._clickMonthYear(' + this._id + ');"' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1353
				(showStatus ? this._addStatus(this._get('yearStatus') || '&#xa0;') : '') + '>';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1354
			for (; year <= endYear; year++) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1355
				html += '<option value="' + year + '"' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1356
					(year == drawYear ? ' selected="selected"' : '') +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1357
					'>' + year + '</option>';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1358
			}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1359
			html += '</select>';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1360
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1361
		// if (this._get('changeTime'))
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1362
		{
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1363
			html += '<br />';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1364
			html += '<select class="datetimepicker_newHour" ' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1365
				'onchange="jQuery.datetimepicker._selectTime(' + this._id + ', this, \'H\');" ' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1366
				'onclick="jQuery.datetimepicker._clickMonthYear(' + this._id + ');"' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1367
				(showStatus ? this._addStatus(this._get('hourStatus') || '&#xa0;') : '') + '>';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1368
			for (hour=0; hour < 24; hour++) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1369
				html += '<option value="' + hour + '"' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1370
					(hour == drawHour ? ' selected="selected"' : '') +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1371
					'>' + ((hour<10)?'0'+hour:hour) + '</option>';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1372
			}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1373
			html += '</select>';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1374
			html += '&nbsp;:&nbsp;';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1375
			html += '<select class="datetimepicker_newMinute" ' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1376
				'onchange="jQuery.datetimepicker._selectTime(' + this._id + ', this, \'M\');" ' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1377
				'onclick="jQuery.datetimepicker._clickMonthYear(' + this._id + ');"' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1378
				(showStatus ? this._addStatus(this._get('minuteStatus') || '&#xa0;') : '') + '>';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1379
			for (minute=0; minute < 60; minute++) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1380
				html += '<option value="' + minute + '"' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1381
					(minute == drawMinute ? ' selected="selected"' : '') +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1382
					'>' + ((minute<10)?'0'+minute:minute) + '</option>';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1383
			}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1384
			html += '</select>';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1385
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1386
		html += '</div>'; // Close datetimepicker_header
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1387
		return html;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1388
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1389
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1390
	/* Provide code to set and clear the status panel. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1391
	_addStatus: function(text) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1392
		return ' onmouseover="jQuery(\'#datetimepicker_status_' + this._id + '\').html(\'' + text + '\');" ' +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1393
			'onmouseout="jQuery(\'#datetimepicker_status_' + this._id + '\').html(\'&#xa0;\');"';
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1394
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1395
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1396
	/* Adjust one of the date sub-fields. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1397
	_adjustDate: function(offset, period) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1398
		var year = this._drawYear + (period == 'Y' ? offset : 0);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1399
		var month = this._drawMonth + (period == 'M' ? offset : 0);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1400
		var day = Math.min(this._selectedDay, this._getDaysInMonth(year, month)) +
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1401
			(period == 'D' ? offset : 0);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1402
		var hour = this._drawHour + (period == 'H' ? offset : 0);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1403
		var minute = this._drawMinute + (period == 'I' ? offset : 0);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1404
		var date = new Date(year, month, day, hour, minute);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1405
		// ensure it is within the bounds set
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1406
		var minDate = this._getMinMaxDate('min', true);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1407
		var maxDate = this._getMinMaxDate('max');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1408
		date = (minDate && date < minDate ? minDate : date);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1409
		date = (maxDate && date > maxDate ? maxDate : date);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1410
		this._selectedDay = date.getDate();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1411
		this._drawMonth = this._selectedMonth = date.getMonth();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1412
		this._drawYear = this._selectedYear = date.getFullYear();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1413
		this._drawHour = this._selectedHour = date.getHours();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1414
		this._drawMinute = this._selectedMinute = date.getMinutes();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1415
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1416
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1417
	/* Determine the number of months to show. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1418
	_getNumberOfMonths: function() {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1419
		var numMonths = this._get('numberOfMonths');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1420
		return (numMonths == null ? [1, 1] : (typeof numMonths == 'number' ? [1, numMonths] : numMonths));
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1421
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1422
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1423
	/* Determine the current maximum date - ensure no time components are set - may be overridden for a range. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1424
	_getMinMaxDate: function(minMax, checkRange) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1425
		var date = this._determineDate(minMax + 'Date', null);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1426
		if (date) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1427
			date.setHours(0);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1428
			date.setMinutes(0);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1429
			date.setSeconds(0);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1430
			date.setMilliseconds(0);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1431
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1432
		return date || (checkRange ? this._rangeStart : null);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1433
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1434
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1435
	/* Find the number of days in a given month. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1436
	_getDaysInMonth: function(year, month) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1437
		return 32 - new Date(year, month, 32).getDate();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1438
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1439
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1440
	/* Find the day of the week of the first of a month. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1441
	_getFirstDayOfMonth: function(year, month) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1442
		return new Date(year, month, 1).getDay();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1443
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1444
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1445
	/* Determines if we should allow a "next/prev" month display change. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1446
	_canAdjustMonth: function(offset, curYear, curMonth) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1447
		var numMonths = this._getNumberOfMonths();
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1448
		var date = new Date(curYear, curMonth + (offset < 0 ? offset : numMonths[1]), 1);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1449
		if (offset < 0)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1450
			date.setDate(this._getDaysInMonth(date.getFullYear(), date.getMonth()));
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1451
		return this._isInRange(date);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1452
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1453
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1454
	/* Is the given date in the accepted range? */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1455
	_isInRange: function(date) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1456
		// during range selection, use minimum of selected date and range start
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1457
		var newMinDate = (!this._rangeStart ? null :
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1458
			new Date(this._selectedYear, this._selectedMonth, this._selectedDay));
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1459
		newMinDate = (newMinDate && this._rangeStart < newMinDate ? this._rangeStart : newMinDate);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1460
		var minDate = newMinDate || this._getMinMaxDate('min');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1461
		var maxDate = this._getMinMaxDate('max');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1462
		return ((!minDate || date >= minDate) && (!maxDate || date <= maxDate));
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1463
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1464
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1465
	/* Provide the configuration settings for formatting/parsing. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1466
	_getFormatConfig: function() {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1467
		var shortYearCutoff = this._get('shortYearCutoff');
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1468
		shortYearCutoff = (typeof shortYearCutoff != 'string' ? shortYearCutoff :
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1469
			new Date().getFullYear() % 100 + parseInt(shortYearCutoff, 10));
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1470
		return {shortYearCutoff: shortYearCutoff,
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1471
			dayNamesShort: this._get('dayNamesShort'), dayNames: this._get('dayNames'),
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1472
			monthNamesShort: this._get('monthNamesShort'), monthNames: this._get('monthNames')};
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1473
	},
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1474
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1475
	/* Format the given date for display. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1476
	_formatDateTime: function(day, month, year, hour, minute) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1477
		if (!day) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1478
			this._currentDay = this._selectedDay;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1479
			this._currentMonth = this._selectedMonth;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1480
			this._currentYear = this._selectedYear;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1481
			this._currentHour = this._selectedHour;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1482
			this._currentMinute = this._selectedMinute;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1483
		}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1484
		var date = (day ? (typeof day == 'object' ? day : new Date(year, month, day, hour, minute)) :
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1485
			new Date(this._currentYear, this._currentMonth, this._currentDay, this._currentHour, this._currentMinute));
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1486
		return $.datetimepicker.formatDate(this._get('dateFormat')+' '+this._get('timeFormat'), date, this._getFormatConfig());
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1487
	}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1488
});
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1489
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1490
/* jQuery extend now ignores nulls! */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1491
function extendRemove(target, props) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1492
	$.extend(target, props);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1493
	for (var name in props)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1494
		if (props[name] == null)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1495
			target[name] = null;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1496
	return target;
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1497
};
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1498
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1499
/* Invoke the datetimepicker functionality.
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1500
   @param  options  String - a command, optionally followed by additional parameters or
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1501
                    Object - settings for attaching new datetimepicker functionality
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1502
   @return  jQuery object */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1503
$.fn.datetimepicker = function(options){
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1504
	var otherArgs = Array.prototype.slice.call(arguments, 1);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1505
	if (typeof options == 'string' && (options == 'isDisabled' || options == 'getDate')) {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1506
		return $.datetimepicker['_' + options + 'Datepicker'].apply($.datetimepicker, [this[0]].concat(otherArgs));
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1507
	}
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1508
	return this.each(function() {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1509
		typeof options == 'string' ?
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1510
			$.datetimepicker['_' + options + 'Datepicker'].apply($.datetimepicker, [this].concat(otherArgs)) :
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1511
			$.datetimepicker._attachDatepicker(this, options);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1512
	});
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1513
};
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1514
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1515
$.datetimepicker = new DateTimepicker(); // singleton instance
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1516
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1517
/* Initialise the date picker. */
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1518
$(document).ready(function() {
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1519
	$(document.body).append($.datetimepicker._datetimepickerDiv)
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1520
		.mousedown($.datetimepicker._checkExternalClick);
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1521
});
a086ff3888d3 Fixed EOL and whitespace damage
Sverre Rabbelier <srabbelier@gmail.com>
parents: 839
diff changeset
  1522
839
3e50c012a4a8 Add datetimepicker javascript widget files and css file.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
diff changeset
  1523
})(jQuery);