		$j(function()
		{
			
			// initialise the "Select date" link
			$j('#date_pick')
				.datePicker(
					// associate the link with a date picker
					{
						createButton:false
					}
				).bind(
					// when the link is clicked display the date picker
					'click',
					function()
					{
						updateSelects($j(this).dpGetSelected()[0]);
						$j(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]);
					}
				);

			$j('#dd_pick')
				.datePicker(
					// associate the link with a date picker
					{
						createButton:false
					}
				).bind(
					// when the link is clicked display the date picker
					'click',
					function()
					{
						updateDeparture($j(this).dpGetSelected()[0]);
						$j(this).dpDisplay();
						return false;
					}
				).bind(
					// when a date is selected update the SELECTs
					'dateSelected',
					function(e, selectedDate, $td, state)
					{
						updateDeparture(selectedDate);
					}
				).bind(
					'dpClosed',
					function(e, selected)
					{
						updateDeparture(selected[0]);
					}
				);
				
			var updateSelects = function (selectedDate)
			{
				selectedDate = new Date(selectedDate);
				var d = selectedDate.getDate();
				var m = selectedDate.getMonth();
				var y = selectedDate.getFullYear();
				($j('#ad')[0]).selectedIndex = d-1;
				($j('#am')[0]).selectedIndex = m;
				($j('#dd')[0]).selectedIndex = d;
				($j('#dm')[0]).selectedIndex = m;
			}

			var updateDeparture = function (selectedDate)
			{
				selectedDate = new Date(selectedDate);
				var d = selectedDate.getDate();
				var m = selectedDate.getMonth();
				var y = selectedDate.getFullYear();
				($j('#dd')[0]).selectedIndex = d-1;
				($j('#dm')[0]).selectedIndex = m;
			}
			// listen for when the selects are changed and update the picker
			$j('#ad, #am')
				.bind(
					'change',
					function()
					{
						var d = new Date(
									$j('#am').val(),
									$j('#ad').val()
								);
						$j('#date_pick').dpSetSelected(d.asString());
					}
				);
			
			// default the position of the selects to today
			var today = new Date();
			var tomorrow = new Date(); 
			tomorrow.setDate(today.getDate() + 1); 
			($j('#ad')[0]).selectedIndex = today.getDate()-1;
			($j('#am')[0]).selectedIndex = today.getMonth();
			($j('#dd')[0]).selectedIndex = tomorrow.getDate() - 1;
			($j('#dm')[0]).selectedIndex = tomorrow.getMonth();
			
			// and update the datePicker to reflect it...
			$j('#ad').trigger('change');

		});

		function change() {

			window.location='?d=' + document.getElementById('ad').value + '&m=' + document.getElementById('am').value;
		
		}