// JavaScript Document ...
var $jz = jQuery.noConflict();
$jz(function()
			{
				
				// initialise the "Select date" link
				$jz('#date-pick')
					.datePicker(
						// associate the link with a date picker
						{
							createButton:false,
							startDate:'01/01/2005',
							endDate:'01/01/2011'
						}
					).bind(
						// when the link is clicked display the date picker
						'click',
						function()
						{
							updateSelects($jz(this).dpGetSelected()[0]);
							$jz(this).dpDisplay();
							return false;
						}
					).bind(
						// when a date is selected update the SELECTs
						'dateSelected',
						function(e, selectedDate, $td, state)
						{
							updateSelects(selectedDate);
						}
					).bind(
						'dpClosed',
						function(e, selected)
						{
							updateSelects(selected[0]);
						}
					);
					
				// initialise the "Select date" link
				$jz('#date-pick2')
					.datePicker(
						// associate the link with a date picker
						{
							createButton:false,
							startDate:'01/01/2005',
							endDate:'01/01/2011'
						}
					).bind(
						// when the link is clicked display the date picker
						'click',
						function()
						{
							updateSelects2($jz(this).dpGetSelected()[0]);
							$jz(this).dpDisplay();
							return false;
						}
					).bind(
						// when a date is selected update the SELECTs
						'dateSelected',
						function(e, selectedDate, $td, state)
						{
							updateSelects2(selectedDate);
						}
					).bind(
						'dpClosed',
						function(e, selected)
						{
							updateSelects2(selected[0]);
						}
					);
					
				var updateSelects = function (selectedDate)
				{
					var selectedDate = new Date(selectedDate);
					$jz('#check-in-d option[value=' + selectedDate.getDate() + ']').attr('selected', 'selected');
					$jz('#check-in-m option[value=' + (selectedDate.getMonth()+1) + ']').attr('selected', 'selected');
					$jz('#check-in-y option[value=' + (selectedDate.getFullYear()) + ']').attr('selected', 'selected');
				}
				
				var updateSelects2 = function (selectedDate)
				{
					var selectedDate = new Date(selectedDate);
					$jz('#check-out-d option[value=' + selectedDate.getDate() + ']').attr('selected', 'selected');
					$jz('#check-out-m option[value=' + (selectedDate.getMonth()+1) + ']').attr('selected', 'selected');
					$jz('#check-out-y option[value=' + (selectedDate.getFullYear()) + ']').attr('selected', 'selected');
				}
				
				// listen for when the selects are changed and update the picker
				$jz('#check-in-d, #check-in-m, #check-in-y')
					.bind(
						'change',
						function()
						{
							var d = new Date(
										$jz('#check-in-y').val(),
										$jz('#check-in-m').val()-1,
										$jz('#check-in-d').val()
									);
							$jz('#date-pick').dpSetSelected(d.asString());
						}
					);
				// listen for when the selects are changed and update the picker
				$jz('#check-out-d, #check-out-m, #check-out-y')
					.bind(
						'change',
						function()
						{
							var d = new Date(
										$jz('#check-out-y').val(),
										$jz('#check-out-m').val()-1,
										$jz('#check-out-d').val()
									);
							$jz('#date-pick2').dpSetSelected(d.asString());
						}
					);
				
				// default the position of the selects to today
				var today = new Date();
				updateSelects(today.getTime());
				updateSelects2(today.getTime());
				
				// and update the datePicker to reflect it...
				$jz('#check-in-d').trigger('change');
				$jz('#check-out-d').trigger('change');
				
			});