//<!--
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("Todas localidades de " + sRegionName, 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;
	}
	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 += "Por favor, seleccione un País/Zona, seleccione una Ciudad/Población o introduzca el Nombre del alojamiento.\n";
	else if (bAccommodationEntered &&oAccommodation.value.length < 3)
		sErrors += "El nombre del alojamiento debe ser por lo menos 3 caracteres en longitud\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 += "Incorpore por favor una fecha de los registros\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 += "Por favor, seleccione una fecha de entrada válida.\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 += "Debe seleccionar al menos 1 tipo de alojamiento.\n";

	//this bit checks to see if Self catering is selected
	if (document.getElementById("subcat_4").checked && oStayLength.options[oStayLength.selectedIndex].value < 2) sErrors += "Para los Apartamentos debe reservar un mínimo de 2 noches.\n";


	//See if there are any errors or submit form	
	if (sErrors != '')
	{
		alert(sErrors);
		return false;
	}
	else
	{
		document.BookingForm.submit();
		return true;
	}
}

//-->