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 && f.city2.selectedIndex==0)
	{
		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=='' || kids=='0') && ((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!='' || kids!='0') && ((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!='' && kids!='0') && ((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;
		}
	}
	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);
	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()
{
	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;
		}
	}
	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=='' || kids=='0') && ((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!='' || kids!='0') && ((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!='' && kids!='0') && ((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;
		}
	}
	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);
	populateRooms();
	setGuests(2);
	setCookieDates();
}

function checkReservation()
{
	blackText();
	color_error = "#CC0000";
	errortext = "Please complete the following fields before continuing...\n";
	errorcheck = 0;
	f = document.form;

	if (f.title.selectedIndex==0)
	{
		errortext = errortext + "\t- Title\n";
		errorcheck = 1;
		document.getElementById('titleText').style.color = color_error;
	}
	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=='')&&(f.telephonepm.value==''))
	{
		errortext = errortext + "\t- Telephone number\n";
		errorcheck = 1;
		document.getElementById('teldayText').style.color = color_error;
		document.getElementById('televeText').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 (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('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;
}

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 ((f.family1.selectedIndex==0)&&(f.family2.selectedIndex==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);
	setCookieDatesFree();
}