//<!--
function fnChangeCities(sRegionName)
{
	var oLocationSelect = document.getElementById("location");
	oLocationSelect.options.length = 0;

	if (sRegionName == '')
	{
		for(i=0; i<arrAllLocations['All'].length; i++)
		{
		    oLocationSelect.options[i] = new Option(arrAllLocations['All'][i], arrAllLocations['All'][i], false, false);
		}
	}
	else if (arrLocation[sRegionName])
	{
		var sAllRegionLocations = '';
		for(i=0; i<arrLocation[sRegionName].length; i++)
		{
		    oLocationSelect.options[i+1] = new Option(arrLocation[sRegionName][i], arrLocation[sRegionName][i], false, false);
			sAllRegionLocations += "^" + arrLocation[sRegionName][i];
		}
		oLocationSelect.options[0] = new Option("All " + sRegionName + " locations", sAllRegionLocations, true, true);
	}
}


// ##### CALENDAR CODE

function fnPopWin(mypage, myname, w, h)
{
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+'toolbar=no, status=no, scrollbars=no, location=no, menubar=no, directories=no, resizable=no'
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

var sCalTargetInput;
function fnShowCal(sTargetInput)
{
	sCalTargetInput = sTargetInput;
	document.getElementById("CalendarHolder").style.visibility = 'visible';
	window.parent.document.getElementById("CalendarHolder").style.display = 'block';
}

function fnSetDate(iDay,iMon,iYear,iDateString)
{
	if (document.getElementById('Display_' + sCalTargetInput)) 
	{
		document.getElementById('Display_' + sCalTargetInput).value = iDateString;
	}
	if (iDay < 10) iDay = "0" + iDay;
	if (iMon < 10) iMon = "0" + iMon;

	document.getElementById(sCalTargetInput).value = iDay+"-"+iMon+"-"+iYear;
}

function fnSelectYear(iYear)
{
	if (isNaN(iYear)) {iYear = prompt('Please choose a year:','');}
	if (iYear > 0)
	{
		document.getElementById("calForm").dYear.value = iYear;
		document.getElementById("calForm").submit();	
	}
	else
	{
		document.getElementById("calForm").Display_Year.selectedIndex = 5;
	}
}

// ##### END CALENDAR CODE	

// ##### Validation Code

function ValidateForm()
{
	var sErrors = '';
	var oRegion = document.getElementById('region');
	var oLocation = document.getElementById('location');
	var oAccommodation = document.getElementById('sProductName');
	var oCheckInDate = document.getElementById('checkInDate');
	var oStayLength = document.getElementById('numNights');

	var bRegionSelected = (oRegion.value == '' || oRegion.value == null ? false : true);
	var bLocationSelected = (oLocation.value == '' || oLocation.value == null ? false : true);
	var bAccommodationEntered = (oAccommodation.value == '' || oAccommodation.value == null ? false : true);
	var bCheckInDate = (oCheckInDate.value == '' || oCheckInDate.value == null ? false : true);

	//must choose one of the following
	if (!bRegionSelected && !bLocationSelected && !bAccommodationEntered)
		sErrors += "Please select a County/Area, or select a City/Town or enter Name of accommodation\n";
	else if (bAccommodationEntered &&oAccommodation.value.length < 3)
		sErrors += "The Name of Accommodation must be at least 3 characters in length\n";
	else if (!bRegionSelected && !bLocationSelected && bAccommodationEntered)
	{
		// if only productname typed, choose all location
		for (var i = 0; i < oLocation.options.length; i++)
		{
			oLocation.options[i].selected = true;
		}
	}

	//Date Checks
	if (!bCheckInDate)
		sErrors += "Please enter a Check-in date\n";
	else
	{
		var dToday = new Date();
		var aSelectedDate = oCheckInDate.value.split("-");
		var dSelectedDate = new Date();
		dSelectedDate.setFullYear(aSelectedDate[2],aSelectedDate[1] - 1,aSelectedDate[0])
		if (dSelectedDate < dToday) sErrors += "Please select a valid Check-in date\n";
	}
	
	//Check Accommodation Types
	var aInputs = document.getElementById("AccommodationTypeHolder").getElementsByTagName("input");
	var bAccommodationTypeChosen = false;
	for (i=0; i<aInputs.length; i++)
	{
		if (aInputs[i].checked) bAccommodationTypeChosen = true;
	}

	if (!bAccommodationTypeChosen) sErrors += "You must select at least one accommodation type\n";

	//this bit checks to see if Self catering is selected
	if (document.getElementById("subcat_4").checked && oStayLength.options[oStayLength.selectedIndex].value < 2) sErrors += "You must select at least 2 nights for Self Catering\n";


	//See if there are any errors or submit form	
	if (sErrors != '')
	{
		alert(sErrors);
		return false;
	}
	else
	{
		document.BookingForm.submit();
		return true;
	}
}

//-->