function highlightField(field) {
	field.style.border = '1px solid #ee0000';
	field.focus();
}

function isValidEmail(address) {
	if (address.indexOf('@')==-1 || address.indexOf(' ')>=0 || address.length<8) {
		alert("Please enter a valid email address");
		return false;
	}
	return true;
}


function checkEnquiryForm(enquiryForm) {
	

	try{
		document.getElementById('email').style.border = '1px solid #ccc';
		document.getElementById('title').style.border = '1px solid #ccc';
		document.getElementById('firstname').style.border = '1px solid #ccc';
		document.getElementById('lastname').style.border = '1px solid #ccc';
		document.getElementById('phone').style.border = '1px solid #ccc';

	}catch (e){}
	
	if (!isValidEmail(document.getElementById('email').value)) {
		highlightField(document.getElementById('email'));
		return false;
	}

	if (document.getElementById('title').selectedIndex == 0) {
		alert("Please enter your title.");
		highlightField(document.getElementById('title'));
		return false;
	}

	if (document.getElementById('firstname').value.length == 0) {
		alert("Please enter your first name.");
		highlightField(document.getElementById('firstname'));
		return false;
	}

	if (document.getElementById('lastname').value.length == 0) {
		alert("Please enter your lastname.");
		highlightField(document.getElementById('lastname'));
		return false;
	}
	
	
	if (document.getElementById('phone').value.length == 0) {
		alert("Please enter your daytime phone number.");
		highlightField(document.getElementById('phone'));
		return false;
	}


	// Assume that month and year will be a string in the format of MM/yyyy
	// Also remember that months range from 0..11
	month = new Number(document.getElementById('departure_month').value.substring(0,2))-1;
	year = document.getElementById('departure_month').value.substring(3,7);

	// Assume that day is an integer in the form of a string
	day = document.getElementById('departure_day').value;
	if (!isValidDate(year, month, day)) {
		highlightField(document.getElementById('departure_day'));
		highlightField(document.getElementById('departure_month'));
		return false;
	}
	
	departureDate = new Date(year, month, day, 11, 59, 59);

	// Departure date must be after today.
	var todaysDate = stringToDate(document.getElementById('todays_date').value);
	
	
	if (departureDate <= todaysDate) {
		alert('The departure date must be after today.');
		highlightField(document.getElementById('departure_day'));
		highlightField(document.getElementById('departure_month'));
		return false;
	}

	// If a return date has been given, check its validity.
	if (document.getElementById('return_month').value != null) {

		// Assume that month and year will be a string in the format of MM/yyyy
		// Also remember that months range from 0..11
		month = new Number(document.getElementById('return_month').value.substring(0,2))-1;
		year = document.getElementById('return_month').value.substring(3,7);

		// Assume that day is an integer in the form of a string
		day = document.getElementById('return_day').value;
		if (!isValidDate(year, month, day)) {
			highlightField(document.getElementById('return_day'));
			highlightField(document.getElementById('return_month'));
			return false;
		}
		
		returnDate = new Date(year, month, day, 11, 59, 59);


		// Return date must be AFTER departure date
		if (returnDate <= departureDate) {
			alert('The return date must be after the departure date.');
			highlightField(document.getElementById('return_day'));
			highlightField(document.getElementById('return_month'));
			return false;
		}
	}
	
	
	return true;
}


