$(function()
			{
				var dateNow = new Date();
				var startDay = dateNow.getDate();
				var startMonth = dateNow.getMonth() + 1;
				var startYear = dateNow.getFullYear();
				var endYear = startYear + 2;
				var msecsInADay = 86400000;
				
				// initialise arrival link
				$('#arrivalChooser')
					.datePicker(
						// associate the link with a date picker
						{
							
							createButton:false,
							startDate: startDay + '/' + startMonth + '/' + startYear,
							endDate: '31/12/' + endYear
						}
					).bind(
						// when the link is clicked display the date picker
						'click',
						function()
						{
							updateArrivalSelects($(this).dpGetSelected()[0]);
							$(this).dpDisplay();
							return false;
						}
					).bind(
						// when a date is selected update the SELECTs
						'dateSelected',
						function(e, selectedDate, $td, state)
						{
							updateArrivalSelects(selectedDate);
						}
					).bind(
						'dpClosed',
						function(e, selected)
						{
							updateArrivalSelects(selected[0]);
						}
					);
					
				var updateArrivalSelects = function (selectedDate)
				{
					var selectedDate = new Date(selectedDate);
					$('#frm_arrival_day option[value=' + selectedDate.getDate() + ']').attr('selected', 'selected');
					$('#frm_arrival_month option[value=' + (selectedDate.getMonth()+1) + ']').attr('selected', 'selected');
					$('#frm_arrival_year option[value=' + (selectedDate.getFullYear()) + ']').attr('selected', 'selected');
					updateDepartSelects(selectedDate.getTime() + msecsInADay);
					$('#frm_departure_day').trigger('change');
				}
				
				// initialise departure link
				$('#departureChooser')
					.datePicker(
						// associate the link with a date picker
						{
							
							createButton:false,
							startDate: startDay + '/' + startMonth + '/' + startYear,
							endDate: '31/12/' + endYear
						}
					).bind(
						// when the link is clicked display the date picker
						'click',
						function()
						{
							updateDepartSelects($(this).dpGetSelected()[0]);
							$(this).dpDisplay();
							return false;
						}
					).bind(
						// when a date is selected update the SELECTs
						'dateSelected',
						function(e, selectedDate, $td, state)
						{
							updateDepartSelects(selectedDate);
						}
					).bind(
						'dpClosed',
						function(e, selected)
						{
							updateDepartSelects(selected[0]);
						}
					);
					
				var updateDepartSelects = function (selectedDate)
				{
					var selectedDate = new Date(selectedDate);
					$('#frm_departure_day option[value=' + selectedDate.getDate() + ']').attr('selected', 'selected');
					$('#frm_departure_month option[value=' + (selectedDate.getMonth()+1) + ']').attr('selected', 'selected');
					$('#frm_departure_year option[value=' + (selectedDate.getFullYear()) + ']').attr('selected', 'selected');
				}
				
				// listen for when the selects are changed and update the picker
				$('#frm_arrival_day, #frm_arrival_month, #frm_arrival_year')
					.bind(
						'change',
						function()
						{
							var d = new Date(
										$('#frm_arrival_year').val(),
										$('#frm_arrival_month').val()-1,
										$('#frm_arrival_day').val()
									);
							$('#arrivalChooser').dpSetSelected(d.asString());
						}
					);
					
				$('#frm_departure_day, #frm_departure_month, #frm_departure_year')
					.bind(
						'change',
						function()
						{
							var d = new Date(
										$('#frm_departure_year').val(),
										$('#frm_departure_month').val()-1,
										$('#frm_departure_day').val()
									);
							$('#departureChooser').dpSetSelected(d.asString());
						}
					);
				
				// set the selects to today
				var today = new Date();
				updateArrivalSelects(today.getTime());
				updateDepartSelects(today.getTime() + msecsInADay);
				
				// update the datePicker to reflect it.
				$('#frm_arrival_day').trigger('change');
				$('#frm_departure_day').trigger('change');
				
			});
