function checkHomeSearch()
{
	errortext = "Please do the following before continuing...\n";
	errorcheck = 0;
	f = document.form;
	c = f.city.length;

	/*checkcity = 0;
	for (i=0; i<c; i++)
	{
		if (f.city[i].checked==true)
			checkcity = 1;
	}
	if (checkcity==0)
	{
		errortext = errortext + "- Select a city\n";
		errorcheck = 1;
	}*/
	if (f.city.value == '')
	{
		errortext = errortext + "- Select a city\n";
		errorcheck = 1;
	}
	checkdate = 0;
	checkdate = validDate(f.arrivedate.options[f.arrivedate.selectedIndex].value, f.arrivedate2.options[f.arrivedate2.selectedIndex].value);
	if (checkdate==1)
	{
		errortext = errortext + "- Enter a valid arrival date\n";
		errorcheck = 1;
		setSunday();
	}
	checkdate = 0;
	checkdate = checkArrivalDate();
	if (checkdate<0)
	{
		errortext = errortext + "- Enter a valid arrival date\n";
		errorcheck = 1;
		setSunday();
	}
	checkdate = 0;
	checkdate = compareDates();
	if (checkdate==1)
	{
		errortext = errortext + "- Enter a departure date that is after the arrival date\n";
		errorcheck = 1;
		f.nights.selectedIndex = 0;
		f.nights.length = 20;
		setEndDate(f.nights.options[f.nights.selectedIndex].value);
	}
	checkdate = 0;
	checkdate = validDate(f.departdate.options[f.departdate.selectedIndex].value, f.departdate2.options[f.departdate2.selectedIndex].value);
	if (checkdate==1)
	{
		errortext = errortext + "- Enter a valid departure date\n";
		errorcheck = 1;
		f.nights.selectedIndex = 0;
		f.nights.length = 20;
		setEndDate(f.nights.options[f.nights.selectedIndex].value);
	}
	if (f.nights.options[f.nights.selectedIndex].value>20)
	{
		errortext = errortext + "- Please select a shorter period or tel. 08700 550 550 - or +44 1872 261 100\n";
		errorcheck = 1;
		f.nights.selectedIndex = 0;
		f.nights.length = 20;
		setEndDate(f.nights.options[f.nights.selectedIndex].value);
	}
	roomnum = f.rooms.options[f.rooms.selectedIndex].value;
	for (i=1; i<=roomnum; i++)
	{
		if (f['roomtype'+i].selectedIndex==0)
		{
			errortext = errortext + "- Select a room type for room " + i +"\n";
			errorcheck = 1;
		}
	}
	/*r1 = f.roomtype1.options[f.roomtype1.selectedIndex].value;
	r2 = f.roomtype2.options[f.roomtype2.selectedIndex].value;
	r3 = f.roomtype3.options[f.roomtype3.selectedIndex].value;
	r4 = f.roomtype4.options[f.roomtype4.selectedIndex].value;
	r5 = f.roomtype5.options[f.roomtype5.selectedIndex].value;
	kids = f.kidsage.value;
	if ((kids=='') && ((r1.indexOf('family1')>-1) || (r2.indexOf('family1')>-1) || (r3.indexOf('family1')>-1) || (r4.indexOf('family1')>-1) || (r5.indexOf('family1')>-1) || (r1.indexOf('family2')>-1) || (r2.indexOf('family2')>-1) || (r3.indexOf('family2')>-1) || (r4.indexOf('family2')>-1) || (r5.indexOf('family2')>-1)))
	{
		errortext = errortext + "- Please enter the child age(s)\n";
		errorcheck = 1;
	}
	if ((kids!='') && ((r1.indexOf('family1')==-1) && (r2.indexOf('family1')==-1) && (r3.indexOf('family1')==-1) && (r4.indexOf('family1')==-1) && (r5.indexOf('family1')==-1) && (r1.indexOf('family2')==-1) && (r2.indexOf('family2')==-1) && (r3.indexOf('family2')==-1) && (r4.indexOf('family2')==-1) && (r5.indexOf('family2')==-1)))
	{
		f.kidsage.value='';
	}
	if ((kids!='') && ((r1.indexOf('family1')>-1) || (r2.indexOf('family1')>-1) || (r3.indexOf('family1')>-1) || (r4.indexOf('family1')>-1) || (r5.indexOf('family1')>-1) || (r1.indexOf('family2')>-1) || (r2.indexOf('family2')>-1) || (r3.indexOf('family2')>-1) || (r4.indexOf('family2')>-1) || (r5.indexOf('family2')>-1)))
	{
		var totalchildren=0,childrenfound=1;
		if (r1.indexOf('family1')>-1) totalchildren=totalchildren+1;
		if (r2.indexOf('family1')>-1) totalchildren=totalchildren+1;
		if (r3.indexOf('family1')>-1) totalchildren=totalchildren+1;
		if (r4.indexOf('family1')>-1) totalchildren=totalchildren+1;
		if (r5.indexOf('family1')>-1) totalchildren=totalchildren+1;
		if (r1.indexOf('family2')>-1) totalchildren=totalchildren+2;
		if (r2.indexOf('family2')>-1) totalchildren=totalchildren+2;
		if (r3.indexOf('family2')>-1) totalchildren=totalchildren+2;
		if (r4.indexOf('family2')>-1) totalchildren=totalchildren+2;
		if (r5.indexOf('family2')>-1) totalchildren=totalchildren+2;

		var valid = "0123456789,";
		ok = 1;
		var temp;
		for (var i=0; i<kids.length; i++)
		{
			temp = "" + kids.substring(i, i+1);
			if (valid.indexOf(temp) == "-1")
				ok = 0;
			if (temp==',') childrenfound++;
		}
		if (ok==0)
		{
  		   errortext = errortext + "- Please enter only numbers, separated by commas if applicable (no spaces)\n";
		   errorcheck = 1;
                }
		else if (childrenfound>totalchildren)
		{
  		   if (totalchildren==1) errortext = errortext + "- Please enter ages only for 1 child\n";
		   else errortext = errortext + "- Please enter ages only for "+totalchildren+", separated by commas if applicable (no spaces)\n";
		   errorcheck = 1;
		}
	}*/
	var kidsage_error = 0;
	$('select.kidsage').each(function(){
		if ($(this).is(':visible') && $(this).val() == '')
		{
			kidsage_error = 1;
		}
	});
	if (kidsage_error == 1)
	{
		errortext = errortext + "- Please select the child age(s)\n";
		errorcheck = 1;
	}
	if (errorcheck==1)
	{
		alert(errortext);
		return false;
	}
	f.arrivemonth.value = getMonthValue(f.arrivedate2.options[f.arrivedate2.selectedIndex].value);
	f.arriveyear.value = getYearValue(f.arrivedate2.options[f.arrivedate2.selectedIndex].value);
	f.departmonth.value = getMonthValue(f.departdate2.options[f.departdate2.selectedIndex].value);
	f.departyear.value = getYearValue(f.departdate2.options[f.departdate2.selectedIndex].value);
	setDayName2('arrive', f.arrivedate.selectedIndex, f.arrivedate2.options[f.arrivedate2.selectedIndex].value);
	setDayName2('depart', f.departdate.selectedIndex, f.departdate2.options[f.departdate2.selectedIndex].value);
	
	if ($('select[name="attraction_2"]').val() != '')
	{
		$('input[name="attraction"]').val($('select[name="attraction_2"]').val())
	}
	if ($('select[name="location_2"]').val() != '%%')
	{
		$('input[name="location"]').val($('select[name="location_2"]').val())
	}
	
	populateRooms();
	setGuests(2);
	setCookieDates();
}

function populateRooms()
{
	f=document.form;
	f.doubleroom.value=0;
	f.single.value=0;
	f.twin.value=0;
	f.triple.value=0;
	f.family1.value=0;
	f.family2.value=0;
	f.family3.value=0;

	for (i=1; i<=f.rooms.options[f.rooms.selectedIndex].value; i++)
	{
		room = f['roomtype'+i].options[f['roomtype'+i].selectedIndex].value;
		if (room=='doubleroom')
			f.doubleroom.value++;
		else if (room=='single')
			f.single.value++;
		else if (room=='twin')
			f.twin.value++;
		else if (room=='triple')
			f.triple.value++;
		else if (room=='family1')
			f.family1.value++;
		else if (room=='family2')
			f.family2.value++;
		else if (room=='family3')
			f.family3.value++;
	}
}

function checkCitySearch()
{
	var new_kids = true;
	if ($('input[name="kidsage"]').is(':text'))
	{
		new_kids = false;
	}
	
	errortext = "Please do the following before continuing...\n";
	errorcheck = 0;
	f = document.form;
	checkdate = 0;
	checkdate = validDate(f.arrivedate.options[f.arrivedate.selectedIndex].value, f.arrivedate2.options[f.arrivedate2.selectedIndex].value);
	if (checkdate==1)
	{
		errortext = errortext + "- Enter a valid arrival date\n";
		errorcheck = 1;
		setSunday();
	}
	checkdate = 0;
	checkdate = checkArrivalDate();
	if (checkdate<0)
	{
		errortext = errortext + "- Enter a valid arrival date\n";
		errorcheck = 1;
		setSunday();
	}
	checkdate = 0;
	checkdate = compareDates();
	if (checkdate==1)
	{
		errortext = errortext + "- Enter a departure date that is after the arrival date\n";
		errorcheck = 1;
		f.nights.selectedIndex = 0;
		f.nights.length = 20;
		setEndDate(f.nights.options[f.nights.selectedIndex].value);
	}
	checkdate = 0;
	checkdate = validDate(f.departdate.options[f.departdate.selectedIndex].value, f.departdate2.options[f.departdate2.selectedIndex].value);
	if (checkdate==1)
	{
		errortext = errortext + "- Enter a valid departure date\n";
		errorcheck = 1;
		f.nights.selectedIndex = 0;
		f.nights.length = 20;
		setEndDate(f.nights.options[f.nights.selectedIndex].value);
	}
	if (f.nights.options[f.nights.selectedIndex].value>20)
	{
		errortext = errortext + "- Please select a shorter period or tel. 08700 550 550 - or +44 1872 261 100\n";
		errorcheck = 1;
		f.nights.selectedIndex = 0;
		f.nights.length = 20;
		setEndDate(f.nights.options[f.nights.selectedIndex].value);
	}
	roomnum = f.rooms.options[f.rooms.selectedIndex].value;
	for (i=1; i<=roomnum; i++)
	{
		if (f['roomtype'+i].selectedIndex==0)
		{
			errortext = errortext + "- Select a room type for room " + i +"\n";
			errorcheck = 1;
		}
	}
	
	if (new_kids === false)
	{
		r1 = f.roomtype1.options[f.roomtype1.selectedIndex].value;
		r2 = f.roomtype2.options[f.roomtype2.selectedIndex].value;
		r3 = f.roomtype3.options[f.roomtype3.selectedIndex].value;
		r4 = f.roomtype4.options[f.roomtype4.selectedIndex].value;
		r5 = f.roomtype5.options[f.roomtype5.selectedIndex].value;
		kids = f.kidsage.value;
		if ((kids=='') && ((r1.indexOf('family1')>-1) || (r2.indexOf('family1')>-1) || (r3.indexOf('family1')>-1) || (r4.indexOf('family1')>-1) || (r5.indexOf('family1')>-1) || (r1.indexOf('family2')>-1) || (r2.indexOf('family2')>-1) || (r3.indexOf('family2')>-1) || (r4.indexOf('family2')>-1) || (r5.indexOf('family2')>-1)))
		{
			errortext = errortext + "- Please enter the child age(s)\n";
			errorcheck = 1;
		}
		if ((kids!='') && ((r1.indexOf('family1')==-1) && (r2.indexOf('family1')==-1) && (r3.indexOf('family1')==-1) && (r4.indexOf('family1')==-1) && (r5.indexOf('family1')==-1) && (r1.indexOf('family2')==-1) && (r2.indexOf('family2')==-1) && (r3.indexOf('family2')==-1) && (r4.indexOf('family2')==-1) && (r5.indexOf('family2')==-1)))
	
		{
			f.kidsage.value='';
		}
		if ((kids!='') && ((r1.indexOf('family1')>-1) || (r2.indexOf('family1')>-1) || (r3.indexOf('family1')>-1) || (r4.indexOf('family1')>-1) || (r5.indexOf('family1')>-1) || (r1.indexOf('family2')>-1) || (r2.indexOf('family2')>-1) || (r3.indexOf('family2')>-1) || (r4.indexOf('family2')>-1) || (r5.indexOf('family2')>-1)))
		{
			var totalchildren=0,childrenfound=1;
			if (r1.indexOf('family1')>-1) totalchildren=totalchildren+1;
			if (r2.indexOf('family1')>-1) totalchildren=totalchildren+1;
			if (r3.indexOf('family1')>-1) totalchildren=totalchildren+1;
			if (r4.indexOf('family1')>-1) totalchildren=totalchildren+1;
			if (r5.indexOf('family1')>-1) totalchildren=totalchildren+1;
			if (r1.indexOf('family2')>-1) totalchildren=totalchildren+2;
			if (r2.indexOf('family2')>-1) totalchildren=totalchildren+2;
			if (r3.indexOf('family2')>-1) totalchildren=totalchildren+2;
			if (r4.indexOf('family2')>-1) totalchildren=totalchildren+2;
			if (r5.indexOf('family2')>-1) totalchildren=totalchildren+2;
			//if (r1.indexOf('family3')>-1) totalchildren=totalchildren+3;
			//if (r2.indexOf('family3')>-1) totalchildren=totalchildren+3;
			//if (r3.indexOf('family3')>-1) totalchildren=totalchildren+3;
			//if (r4.indexOf('family3')>-1) totalchildren=totalchildren+3;
			//if (r5.indexOf('family3')>-1) totalchildren=totalchildren+3;
	
			var valid = "0123456789,";
			ok = 1;
			var temp;
			for (var i=0; i<kids.length; i++)
			{
				temp = "" + kids.substring(i, i+1);
				if (valid.indexOf(temp) == "-1")
					ok = 0;
				if (temp==',') childrenfound++;
			}
			if (ok==0)
			{
			   errortext = errortext + "- Please enter only numbers, separated by commas if applicable (no spaces)\n";
			   errorcheck = 1;
					}
			else if (childrenfound>totalchildren)
			{
			   if (totalchildren==1) errortext = errortext + "- Please enter the age of 1 child only\n";
			   else errortext = errortext + "- Please enter ages only for "+totalchildren+" children, separated by commas if applicable (no spaces)\n";
			   errorcheck = 1;
			}
		}
	}
	else
	{
		var kidsage_error = 0;
		$('select.kidsage').each(function(){
			if ($(this).is(':visible') && $(this).val() == '')
			{
				kidsage_error = 1;
			}
		});
		if (kidsage_error == 1)
		{
			errortext = errortext + "- Please select the child age(s)\n";
			errorcheck = 1;
		}
	}
	if (errorcheck==1)
	{
		alert(errortext);
		return false;
	}
	
	f.arrivemonth.value = getMonthValue(f.arrivedate2.options[f.arrivedate2.selectedIndex].value);
	f.arriveyear.value = getYearValue(f.arrivedate2.options[f.arrivedate2.selectedIndex].value);
	f.departmonth.value = getMonthValue(f.departdate2.options[f.departdate2.selectedIndex].value);
	f.departyear.value = getYearValue(f.departdate2.options[f.departdate2.selectedIndex].value);
	setDayName2('arrive', f.arrivedate.selectedIndex, f.arrivedate2.options[f.arrivedate2.selectedIndex].value);
	setDayName2('depart', f.departdate.selectedIndex, f.departdate2.options[f.departdate2.selectedIndex].value);
	populateRooms();
	setGuests(2);
	setCookieDates();
}

function checkReservation()
{
	if ($('input#copy_address').is(':checked'))
	{
		sameAddress();
	}
	blackText();
	color_error = "#CC0000";
	errortext = "Please complete the following fields before continuing...\n";
	errorcheck = 0;
	f = document.form;
	f.email.value=trimCookie(f.email.value);
	f.email2.value=trimCookie(f.email2.value);

	if (f.surname.value=='')
	{
		errortext = errortext + "\t- Full name\n";
		errorcheck = 1;
		document.getElementById('surnameText').style.color = color_error;
		document.getElementById('firstnameText').style.color = color_error;
	}
	if (f.address.value=='')
	{
		errortext = errortext + "\t- Address\n";
		errorcheck = 1;
		document.getElementById('addressText').style.color = color_error;
	}
	if (f.postcode.value=='' && (f.country.value=='UK|United Kingdom' || f.country.value=='US|USA'))
	{
		errortext = errortext + "\t- Postcode\n";
		errorcheck = 1;
		document.getElementById('postcodeText').style.color = color_error;
	}
	if (f.country.selectedIndex==0)
	{
		errortext = errortext + "\t- Country\n";
		errorcheck = 1;
		document.getElementById('countryText').style.color = color_error;
	}
	if (f.telephoneam.value=='')
	{
		errortext = errortext + "\t- Telephone number\n";
		errorcheck = 1;
		document.getElementById('teldayText').style.color = color_error;
	}
	if (f.email.value=='')
	{
		errortext = errortext + "\t- Email address\n";
		errorcheck = 1;
		document.getElementById('emailText').style.color = color_error;
	}
	if (f.email.value!=f.email2.value)
	{
		errortext = errortext + "\t- Correct email address\n";
		errorcheck = 1;
		document.getElementById('emailText').style.color = color_error;
		document.getElementById('emailText2').style.color = color_error;
	}
	else
	{
		var str = f.email.value;
		var supported = 0;
		if (window.RegExp)
		{
			var tempStr = "a";
			var tempReg = new RegExp(tempStr);
			if (tempReg.test(tempStr)) supported = 1;
		}
		if (!supported) 
			return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
		var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
		var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,4})(\\]?)$");
		if ((!r1.test(str)==true)&&(r2.test(str)==false))
		{
			errortext = errortext + "\t- A real email address\n";
			errorcheck = 1;
			document.getElementById('emailText').style.color = color_error;
		}
	}
	if (f.cctype.selectedIndex==0)
	{
		errortext = errortext + "\t- Card type\n";
		errorcheck = 1;
		document.getElementById('cardTypeText').style.color = color_error;
	}
	if (!$('input#copy_address').is(':checked') && !$('input#different_address').is(':checked'))
	{
		errortext = errortext + "\t- Choose billing address\n";
		errorcheck = 1;
		document.getElementById('billingAddressText').style.color = color_error;
	}
	if (f.ccaddress.value=='')
	{
		errortext = errortext + "\t- Billing address\n";
		errorcheck = 1;
		document.getElementById('cardAddressText').style.color = color_error;
	}
	if (f.ccpostcode.value=='' && (f.cccountry.value=='UK|United Kingdom' || f.cccountry.value=='US|USA'))
	{
		errortext = errortext + "\t- Billing postcode\n";
		errorcheck = 1;
		document.getElementById('cardPostcodeText').style.color = color_error;
	}
	if (f.cccountry.selectedIndex==0)
	{
		errortext = errortext + "\t- Billing country\n";
		errorcheck = 1;
		document.getElementById('cardCountryText').style.color = color_error;
	}
	/*if (f.heardabout.selectedIndex==0)
	{
		errortext = errortext + "\t- Where you heard about Hotel Direct\n";
		errorcheck = 1;
		document.getElementById('heardText').style.color = color_error;
	}*/
	if (f.terms.checked==false)
	{
		errortext = errortext + "\t- Agree to Hotel Direct`s terms & conditions\n";
		errorcheck = 1;
		document.getElementById('termText').style.color = color_error;
	}

	if (errorcheck==1)
	{
		alert(errortext);
		return false;
	}
}

function blackText()
{
	color = "";
	document.getElementById('titleText').style.color = color;
	document.getElementById('surnameText').style.color = color;
	document.getElementById('firstnameText').style.color = color;
	document.getElementById('addressText').style.color = color;
	document.getElementById('postcodeText').style.color = color;
	document.getElementById('countryText').style.color = color;
	document.getElementById('teldayText').style.color = color;
	document.getElementById('emailText').style.color = color;
	document.getElementById('emailText2').style.color = color;
	document.getElementById('cardTypeText').style.color = color;
	document.getElementById('billingAddressText').style.color = color;
	document.getElementById('cardAddressText').style.color = color;
	document.getElementById('cardPostcodeText').style.color = color;
	document.getElementById('cardCountryText').style.color = color;
	document.getElementById('termText').style.color = color;
}

function blackText2()
{
	color = "";
	document.getElementById('titleText').style.color = color;
	document.getElementById('surnameText').style.color = color;
	document.getElementById('firstnameText').style.color = color;
	document.getElementById('addressText').style.color = color;
	document.getElementById('postcodeText').style.color = color;
	document.getElementById('countryText').style.color = color;
	document.getElementById('teldayText').style.color = color;
	document.getElementById('televeText').style.color = color;
	document.getElementById('emailText').style.color = color;
	document.getElementById('emailText2').style.color = color;
	document.getElementById('cardTypeText').style.color = color;
	document.getElementById('cardAddressText').style.color = color;
	document.getElementById('cardPostcodeText').style.color = color;
	document.getElementById('cardCountryText').style.color = color;
	//document.getElementById('heardText').style.color = color;
	document.getElementById('termText').style.color = color;

	//document.getElementById('cardTitle').style.color = color;
	//document.getElementById('cardInitial').style.color = color;
	//document.getElementById('cardSurname').style.color = color;
	//document.getElementById('valid').style.color = color;
	//document.getElementById('issue').style.color = color;
	//document.getElementById('cardNumber').style.color = color;
	//document.getElementById('cardExpiry').style.color = color;
	//document.getElementById('cardCode').style.color = color;
}

function checkFreeSearch()
{
	errortext = "Please do the following before continuing...\n";
	errorcheck = 0;
	f = document.form;
	checkdate = 0;
	checkdate = validDate(f.arrivedate.options[f.arrivedate.selectedIndex].value, f.arrivedate2.options[f.arrivedate2.selectedIndex].value);
	if (checkdate==1)
	{
		errortext = errortext + "- Enter a valid arrival date\n";
		errorcheck = 1;
		setSunday();
	}
	checkdate = 0;
	checkdate = checkArrivalDate();
	if (checkdate<0)
	{
		errortext = errortext + "- Enter a valid arrival date\n";
		errorcheck = 1;
		setSunday();
	}
	checkdate = 0;
	checkdate = compareDates();
	if (checkdate==1)
	{
		errortext = errortext + "- Enter a departure date that is after the arrival date\n";
		errorcheck = 1;
		f.nights.selectedIndex = 0;
		f.nights.length = 20;
		setEndDate(f.nights.options[f.nights.selectedIndex].value);
	}
	checkdate = 0;
	checkdate = validDate(f.departdate.options[f.departdate.selectedIndex].value, f.departdate2.options[f.departdate2.selectedIndex].value);
	if (checkdate==1)
	{
		errortext = errortext + "- Enter a valid departure date\n";
		errorcheck = 1;
		f.nights.selectedIndex = 0;
		f.nights.length = 20;
		setEndDate(f.nights.options[f.nights.selectedIndex].value);
	}
	if (f.nights.options[f.nights.selectedIndex].value>20)
	{
		errortext = errortext + "- Please select a shorter period or tel. 08700 550 550 - or +44 1872 261 100\n";
		errorcheck = 1;
		f.nights.selectedIndex = 0;
		f.nights.length = 20;
		setEndDate(f.nights.options[f.nights.selectedIndex].value);
	}
	if (($('select#family1').val() == 0) && ($('select#family2').val() == 0))
	{
		errortext = errortext + "- Select a room type\n";
		errorcheck = 1;
	}
	if ((f.children.value>0)&&(f.kidsage.value==''))
	{
		errortext = errortext + "- Please enter the age(s) of the children\n";
		errorcheck = 1;
	}
	if (errorcheck==1)
	{
		alert(errortext);
		return false;
	}
	f.arrivemonth.value = getMonthValue(f.arrivedate2.options[f.arrivedate2.selectedIndex].value);
	f.arriveyear.value = getYearValue(f.arrivedate2.options[f.arrivedate2.selectedIndex].value);
	f.departmonth.value = getMonthValue(f.departdate2.options[f.departdate2.selectedIndex].value);
	f.departyear.value = getYearValue(f.departdate2.options[f.departdate2.selectedIndex].value);
	setDayName2('arrive', f.arrivedate.selectedIndex, f.arrivedate2.options[f.arrivedate2.selectedIndex].value);
	setDayName2('depart', f.departdate.selectedIndex, f.departdate2.options[f.departdate2.selectedIndex].value);
	setCookieDatesFree();
}

function checkReservationExt()
{
	if ($('input#copy_address').is(':checked'))
	{
		sameAddress();
	}
	blackText();
	color_error = "#CC0000";
	errortext = "Please complete the following fields before continuing...\n";
	errorcheck = 0;
	f = document.form;
	f.email.value=trimCookie(f.email.value);
	f.email2.value=trimCookie(f.email2.value);

	var error_room = '';
	var error_lead = '';
	$('p.room').each(function(){
		$('label:eq(0)', this).css({'color':'#000'});
		$('label:eq(1)', this).css({'color':'#000'});
		if ($('select', this).val() == '0')
		{
			error_room = '\t- Room set-up\n';
			errorcheck = 1;
			$('label:eq(0)', this).css({'color':'#c00'});
		}
		if (($('input:eq(0)', this).val() == '' || $('input:eq(0)', this).val() == 'First name') || ($('input:eq(1)', this).val() == '' || $('input:eq(1)', this).val() == 'Surname'))
		{
			error_lead = '\t- Lead guest name\n';
			errorcheck = 1;
			$('label:eq(1)', this).css({'color':'#c00'});
		}
	});
	
	errortext += error_room + error_lead;

	var error_names = '';
	if (error_lead == '')
	{
		$('p.room').each(function(){
			var name_check = checkRoomName($('input:eq(0)', this).val());
			if (name_check == 1)
			{
				error_names = "\t- Guest names must be different\n";
				errorcheck = 1;
				$('label:eq(1)', this).css({'color':'#c00'});
			}
		});
	}
	
	errortext += error_names;

	if (f.surname.value=='')
	{
		errortext = errortext + "\t- Full name\n";
		errorcheck = 1;
		document.getElementById('surnameText').style.color = color_error;
		document.getElementById('firstnameText').style.color = color_error;
	}
	var surname_check = checkSurname(f.surname.value);
	if (surname_check == 1)
	{
		errortext = errortext + "\t- Card holder must be one of the lead guests\n";
		errorcheck = 1;
		document.getElementById('surnameText').style.color = color_error;
		document.getElementById('firstnameText').style.color = color_error;
	}
	if (f.address.value=='')
	{
		errortext = errortext + "\t- Address\n";
		errorcheck = 1;
		document.getElementById('addressText').style.color = color_error;
	}
	if (f.postcode.value=='' && (f.country.value=='UK|United Kingdom' || f.country.value=='US|USA'))
	{
		errortext = errortext + "\t- Postcode\n";
		errorcheck = 1;
		document.getElementById('postcodeText').style.color = color_error;
	}
	if (f.country.selectedIndex==0)
	{
		errortext = errortext + "\t- Country\n";
		errorcheck = 1;
		document.getElementById('countryText').style.color = color_error;
	}
	if (f.telephoneam.value=='')
	{
		errortext = errortext + "\t- Telephone number\n";
		errorcheck = 1;
		document.getElementById('teldayText').style.color = color_error;
	}
	if (f.email.value=='')
	{
		errortext = errortext + "\t- Email address\n";
		errorcheck = 1;
		document.getElementById('emailText').style.color = color_error;
	}
	if (f.email.value!=f.email2.value)
	{
		errortext = errortext + "\t- Correct email address\n";
		errorcheck = 1;
		document.getElementById('emailText').style.color = color_error;
		document.getElementById('emailText2').style.color = color_error;
	}
	else
	{
		var str = f.email.value;
		var supported = 0;
		if (window.RegExp)
		{
			var tempStr = "a";
			var tempReg = new RegExp(tempStr);
			if (tempReg.test(tempStr)) supported = 1;
		}
		if (!supported) 
			return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
		var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
		var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,4})(\\]?)$");
		if ((!r1.test(str)==true)&&(r2.test(str)==false))
		{
			errortext = errortext + "\t- A real email address\n";
			errorcheck = 1;
			document.getElementById('emailText').style.color = color_error;
		}
	}
	if (f.cctype.selectedIndex==0)
	{
		errortext = errortext + "\t- Card type\n";
		errorcheck = 1;
		document.getElementById('cardTypeText').style.color = color_error;
	}
	if (!$('input#copy_address').is(':checked') && !$('input#different_address').is(':checked'))
	{
		errortext = errortext + "\t- Choose billing address\n";
		errorcheck = 1;
		document.getElementById('billingAddressText').style.color = color_error;
	}
	if (f.ccaddress.value=='')
	{
		errortext = errortext + "\t- Billing address\n";
		errorcheck = 1;
		document.getElementById('cardAddressText').style.color = color_error;
	}
	if (f.ccpostcode.value=='' && (f.cccountry.value=='UK|United Kingdom' || f.cccountry.value=='US|USA'))
	{
		errortext = errortext + "\t- Billing postcode\n";
		errorcheck = 1;
		document.getElementById('cardPostcodeText').style.color = color_error;
	}
	if (f.cccountry.selectedIndex==0)
	{
		errortext = errortext + "\t- Billing country\n";
		errorcheck = 1;
		document.getElementById('cardCountryText').style.color = color_error;
	}
	/*if (f.heardabout.selectedIndex==0)
	{
		errortext = errortext + "\t- Where you heard about Hotel Direct\n";
		errorcheck = 1;
		document.getElementById('heardText').style.color = color_error;
	}*/
	if (f.terms.checked==false)
	{
		errortext = errortext + "\t- Agree to Hotel Direct`s terms & conditions\n";
		errorcheck = 1;
		document.getElementById('termText').style.color = color_error;
	}

	if (errorcheck==1)
	{
		alert(errortext);
		return false;
	}
}

function checkRoomName(name)
{
	var error = 0;
	var name_count = 0;
	$('p.room').each(function(){
		if ($('input:eq(0)', this).val() == name)
		{
			name_count++;
		}
	});
	
	if (name_count > 1)
	{
		error = 1;
	}
	
	return error;
}

function checkSurname(surname)
{
	var error = 1;
	$('p.room').each(function(){
		if ($('input:eq(1)', this).val() == surname)
		{
			error = 0;
		}
	});
	return error;
}
