function validate(theform) {

	var requiredFields = new Array();
	var intCounter = 0;
	var strWarningMessage = "Please enter the following mandatory fields:\n";
	var bgColour = "#E9CDD0";

	if(theform.form_title != null) {
		if(theform.form_title.value.length < 1) {
			intCounter = intCounter + 1;
			requiredFields[intCounter] = "Title";
			document.getElementById("form_title").style.backgroundColor = bgColour;
		}
	}

	if(theform.form_first_name != null) {
		if(theform.form_first_name.value.length < 1) {
			intCounter = intCounter + 1;
			requiredFields[intCounter] = "First name";
			document.getElementById("form_first_name").style.backgroundColor = bgColour;
		}
	}

	if(theform.form_last_name != null) {
		if(theform.form_last_name.value.length < 1) {
			intCounter = intCounter + 1;
			requiredFields[intCounter] = "Last name";
			document.getElementById("form_last_name").style.backgroundColor = bgColour;
		}
	}

	if (theform.form_email != null) {
		var strEmail = theform.form_email.value;
		var isEmail = ((strEmail.indexOf("@") != -1) && (strEmail.indexOf(".") != -1));
		
		if (theform.form_email.value.length < 1) {
			intCounter = intCounter + 1;
			requiredFields[intCounter] = "Email address";
			document.getElementById("form_email").style.backgroundColor = bgColour;
		}
		if (!isEmail && theform.form_email.value.length > 1) {
			intCounter = intCounter + 1;
			requiredFields[intCounter] = "A valid email address";
			document.getElementById("form_email").style.backgroundColor = bgColour;
		}
	}
	
	if (theform.Email != null) {
		var strEmail = theform.Email.value;
		var isEmail = ((strEmail.indexOf("@") != -1) && (strEmail.indexOf(".") != -1));
		
		if (theform.Email.value.length < 1) {
			intCounter = intCounter + 1;
			requiredFields[intCounter] = "Email address";
			document.getElementById("Email").style.backgroundColor = bgColour;
		}
		if (!isEmail && theform.Email.value.length > 1) {
			intCounter = intCounter + 1;
			requiredFields[intCounter] = "A valid email address";
			document.getElementById("Email").style.backgroundColor = bgColour;
		}
	}
	
	if(theform.form_day_no != null) {
		if(theform.form_day_no.value.length < 1) {
			intCounter = intCounter + 1;
			requiredFields[intCounter] = "Telephone number";
			document.getElementById("form_day_no").style.backgroundColor = bgColour;
		}
	}

	if(theform.form_contact_method != null) {
		if(theform.form_contact_method.selectedIndex == 0) {
			intCounter = intCounter + 1;
			requiredFields[intCounter] = "Contact method";
			document.getElementById("form_contact_method").style.backgroundColor = bgColour;
		}
		if(theform.form_contact_method.value == 'Post') {
			if(theform.form_address_1 != null) {
				if(theform.form_address_1.value.length < 1) {
					intCounter = intCounter + 1;
					requiredFields[intCounter] = "Address line 1";
					document.getElementById("form_address_1").style.backgroundColor = bgColour;
				}
			}
			if(theform.form_post_code != null) {
				if(theform.form_post_code.value.length < 1) {
					intCounter = intCounter + 1;
					requiredFields[intCounter] = "Post code";
					document.getElementById("form_post_code").style.backgroundColor = bgColour;
				}
			}
		}
		/*if(theform.form_contact_method.value == 'Phone') {
			if(theform.form_day_no != null || theform.form_mobile_no != null) {
				if(theform.form_day_no.value.length < 1 || theform.form_mobile_no.value.length < 1) {
					intCounter = intCounter + 1;
					requiredFields[intCounter] = "Day or mobile number";
					document.getElementById("form_day_no").style.backgroundColor = bgColour;
					document.getElementById("form_mobile_no").style.backgroundColor = bgColour;
				}
			}
		}*/
	}

	if(theform.form_hear_about != null) {
		
		if(theform.form_hear_about.value == '' && theform.form_hear_about_press.value == '')
		{
			intCounter = intCounter + 1;
			requiredFields[intCounter] = "Hear about us";
			document.getElementById("form_hear_about").style.backgroundColor = bgColour;
			document.getElementById("form_hear_about_press").style.backgroundColor = bgColour;
		}
	}
	
	if(theform.form_day_no_2 != null) {
		if(theform.form_day_no_2.value.length < 1) {
			intCounter = intCounter + 1;
			requiredFields[intCounter] = "Telephone number";
			document.getElementById("form_day_no_2").style.backgroundColor = bgColour;
		}
	}

	if(theform.minprice != null & theform.minprice != null) {
		if (theform.minprice.value != '' & theform.maxprice.value != '') {
			if (Number(theform.minprice.value) >= Number(theform.maxprice.value)) {
				intCounter = intCounter + 1;
				requiredFields[intCounter] = "Please enter a greater maximum price than the minimum price";
				document.getElementById("maxprice").style.backgroundColor = bgColour;
			}
		}
	}

	//Display warning message
	if (intCounter > 0) {
		for (i = 1; i <= intCounter; i++) {
			strWarningMessage = strWarningMessage + "\n" + requiredFields[i];
		}
		alert(strWarningMessage);
		return false;
	}

	return true;
}

function validatesearchcriteria(frmsearch,frmdestinationdropdowns) {
	if (frmdestinationdropdowns.selResort.value != '') {
		frmsearch.destination.name = 'resortid';
		frmsearch.destination.value = frmdestinationdropdowns.selResort.value;
	} 
	else {
		if (frmdestinationdropdowns.selRegion.value != '') {
			frmsearch.destination.name = 'regionid';
			frmsearch.destination.value = frmdestinationdropdowns.selRegion.value;
		} 
		else {
			if(frmdestinationdropdowns.selCountry.value != '') {
				frmsearch.destination.name = 'countryid';
				frmsearch.destination.value = frmdestinationdropdowns.selCountry.value;
			}
			else {
				frmsearch.destination.name = 'destination';
			}
		}
	}
}

function displaySecondList()
{
	if(document.contact_us.form_hear_about.value == 'Press')
	{
		document.getElementById("press-list").style.display = 'block';
	}
	else
	{
		document.getElementById("press-list").style.display = 'none';
	}
}

function displaySecondList2()
{
	if(document.property_enquiry.form_hear_about.value == 'Press')
	{
		document.getElementById("press-list").style.display = 'block';
	}
	else
	{
		document.getElementById("press-list").style.display = 'none';
	}
}

function displaySecondList3()
{
	if(document.Ski_business_enquiry.form_hear_about.value == 'Press')
	{
		document.getElementById("press-list").style.display = 'block';
	}
	else
	{
		document.getElementById("press-list").style.display = 'none';
	}
}

function displaySecondList4()
{
	if(document.newsletter.form_hear_about.value == 'Press')
	{
		document.getElementById("press-list").style.display = 'block';
	}
	else
	{
		document.getElementById("press-list").style.display = 'none';
	}
}
