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