Event.addBehavior(
{
	'#resortDrop:change': function(event)
	{
		var hotels = {
			'Portugal': ['Tivoli Lagos 4*', 'Marina Apartments 4*', 'Quinta Paraiso da Mia Retreat', 'Vila Gale Albacora 4*', 'Casa da Calma', 'Quinta da Cebola Vermelha'],
			'Tenerife': ['Costa Adeje Gran 5*', 'Roca Nivaria Grand 5*', 'Villa Cortes 5*', 'Mar Y Sol 3*'],
			'Madeira': ['Quinta Santo Antonio da Serra', 'Quinta Sao Goncalo', 'Quinta da Penha de Franca', 'Choupana Hills Resort and Spa', 'Quinta da Bela Vista'],
			'Porto Santo': ['Pestana Porto Santo', 'Hotel Porto Santo Geomedicine Centre']
		};

		var resort = this.options[this.selectedIndex].value;
		if (!resort || !hotels[resort]) { return;}
		
		var drop = $('hotelDrop');
		drop.options.length = 0;
		drop.options[0] = new Option('Accommodation', '');
		hotels[resort].each(function(hotel) {
			drop.options[drop.options.length] = new Option(hotel, hotel);
		});		
	},
	
	'#enquiryForm:submit': function(event)
	{
		var required = this.select('.required');
		var ok = true;
		var value;
		required.each(function(e) {
			if (e.nodeName == 'SELECT')
			{
				value = e.options[e.selectedIndex].value;
			}
			else if (e.nodeName == 'INPUT' && e.type == 'text')
			{
				value = e.value;
			}

			//alert(e.name+' - '+e.nodeName+' = '+value);

			if (!value)
			{
				ok = false;
			}
		});
		
		// nights
		if ($('nightsDrop').options[$('nightsDrop').selectedIndex].value == 'Other' && $('nightsOther').value == '')
		{
			alert('Please specify the number of nights you require');
			return false;
		}
		
		
		// inc flights
		var f = $('includeFlightsDrop').options[$('includeFlightsDrop').selectedIndex].value;		
		
		if (f == 'Yes' && $('preferredAirport').value == '')
		{
			alert('Please specify your preferred airport');
			return false;
		}
		
		
		// check date
		if ($('departureDate').value == 'dd/mm/yyyy')
		{
			alert('Please enter a departure date');
			return false;
		}
		
		var d = $('departureDate').value;
		var tmp = d.split('/');
		if (tmp.length != 3) 
		{
			alert('please enter a valid date');
			return false;
		}
		var departure = new Date();
		departure.setFullYear(parseInt(tmp[2], 10), parseInt(tmp[1], 10) - 1, parseInt(tmp[0], 10));
		var today = new Date();

		//alert(departure+' '+today);
		
		if (departure == 'Invalid Date')
		{
			alert('Please enter a valid departure date');
			return false;
		}
		
		if (departure <= today)
		{
			alert('Sorry, you must select a departure date in the future');
			return false;
		}
		
		var day = departure.getDate();
		if (day != parseInt(tmp[0]))
		{
			alert('Sorry, the day you have entered appears to be incorrect');
			return false;
		}

		if (!ok)
		{
			alert('Please complete all of the required fields.');
			return false;
		}

		return true;
	}
});