function updateFromDateSelect() {
	var form = document.form1;
	if (form.List_DateFrom.selectedIndex > form.List_DateTo.selectedIndex) {
		form.List_DateTo.selectedIndex = form.List_DateFrom.selectedIndex;
	}
}
function updateToDateSelect() {
	var form = document.form1;
	if (form.List_DateTo.selectedIndex < form.List_DateFrom.selectedIndex) {
		form.List_DateFrom.selectedIndex = form.List_DateTo.selectedIndex;
	}
}
function updateAccommodationSelect() {
	var form = document.form1;
	if (form.Accomtype.selectedIndex == 5) form.holidayflights.selectedIndex = 1;
	else form.holidayflights.selectedIndex = 0;
}
function updateFlightSelect() {
	var form = document.form1;
	if (form.holidayflights.selectedIndex == 1) form.Accomtype.selectedIndex = 5;
	else if (form.Accomtype.selectedIndex == 5) form.Accomtype.selectedIndex = 0;
}
function popUpWaitingScreen(theURL, width, height) {
	closePopUpWindow();
	var screenWidth = 800;
	var screenHeight = 600;
	if (window.screen){
		screenWidth = screen.width;
		screenHeight = screen.height;
	}
	var positionX = Math.round((screenWidth-width)/2);
	var positionY = Math.round((screenHeight-height)/2);
	openedWindow = open(theURL,"waiting","width="+width+",height="+height+",left="+positionX+",top="+positionY+",screenX="+positionX+",screenY="+positionY+"");
	//openedWindow.onunload = confirmClosed; //commented for netscape problem
	onunload = closePopUpWindow;
	windowOpen = true;
	return true;
}
function closePopUpWindow(){
	// Closes a window's child window
	if (window.windowOpen&&window.openedWindow){
		openedWindow.close();
		confirmClosed();
	}
}
function confirmClosed(){
	// Used to confirm when the child window is closed
	windowOpen = false;
}
function validateForm() {
	
	var form = document.form1;
	/*if (form.country.selectedIndex == 0){
	 	alert("Please select a Country.");
		form.country.focus();
		return false;
	}*/
	if (form.deptair.selectedIndex == 0){
		alert("Please select a departure airport.");
		form.deptair.focus();
		return false;
	}
	if (form.price.selectedIndex == 0){
		alert("Please select a price range.");
		form.price.focus();
		return false;
	}
		
	var dt = form.List_DateFrom.options[form.List_DateFrom.selectedIndex].value
	var mn = form.List_MYrFrom.options[form.List_MYrFrom.selectedIndex].text.split(" ")[0]
	var yr = form.List_MYrFrom.options[form.List_MYrFrom.selectedIndex].text.split(" ")[1]
	
	if (validDate(dt,mn,yr)) {
		if (! validFutureDate(dt,mn,yr)) {
			alert("Departure date should be on or after 7th December.") //("Departure date should be a future date.")
			return false;
		}
	}
	else {
		alert("Please select a valid date.")
		return false;
	}

	/* Number of adults was removed from the search form for Ski 2003 but this code has been
	   left in but commented out in case they are re-introduced.
	if (! checkNumOfAdults(form)){
		var msg="Please contact our call centre if you wish to book for more than 9 passengers."
		alert(msg)
		return false;
	}
    */
    
	form.countryName.value = form.country.options[form.country.selectedIndex].text;
	if (form.resort.selectedIndex > 0) {
		form.resortName.value = form.resort.options[form.resort.selectedIndex].text;
	}
	else {
		form.resortName.value = "";
	}
	return popUpWaitingScreen('/skiHolidays/waitingscreen.asp',420,410)
}

function validDate(day,month,year){
	// Returns true if the day, month and year are possible (i.e. not 30/2/2000)
	var monthsArray = new Array("january","february","march","april","may","june","july","august","september","october","november","december");
	if (typeof(month)=="string"){
		month = month.toLowerCase();
		for (var i=0;i<monthsArray.length;i++){
			if (month==monthsArray[i]) month = i;
			if (month==monthsArray[i].substring(0,3)) month = i;
		}
	}
	else{
		month--;
	}
	year = "20" + year;
	
	var dt = new Date(year,month,day);
	
	if (dt.getDate()==day && dt.getMonth()==month && dt.getFullYear()==year) return true;
	else return false;
}

function validFutureDate(day,month,year){
	var monthsArray = new Array("january","february","march","april","may","june","july","august","september","october","november","december");
	if (typeof(month)=="string"){
		month = month.toLowerCase();
		for (var i=0;i<monthsArray.length;i++){
			if (month==monthsArray[i]) month = i;
			if (month==monthsArray[i].substring(0,3)) month = i;
		}
	}
	else{
		month--;
	}
	if(year.length==1){year='0'+year; }
	if(year.length==2){year='20'+year;}
	//var currentdt = new Date(2002,11,7) //Date()   Changed to make the selectable date beyond 7th december.
	var currentdt = Date()
	var supplieddt = new Date(year,month,day)
	if (Date.parse(supplieddt) >= Date.parse(currentdt))
		return true;
	else
		return false;
}

function checkNumOfAdults(form){
	var numOfAdults = form.adult.options[form.adult.selectedIndex].value
	var numOfChildren = form.child.options[form.child.selectedIndex].value
	var numOfInfants = form.infant.options[form.infant.selectedIndex].value
	if ((parseInt(numOfAdults) + parseInt(numOfChildren) + parseInt(numOfInfants)) > 9)
		return false;
	else
		return true;
}

function popUpHelpWindow(){
	// Pops up a help window
	popUpWindow("/QASPTemplates/html/firstresort/LateDeals3/help.html","_blank","width=300,height=400,scrollbars");
}
function popUpHelpWindow1(){
	// Pops up a help window
	popUpWindow("/QASPTemplates/html/firstresort/branded/freeserve/Holidays/help.html","_blank","width=300,height=400,scrollbars");}
function popUpHelpWindow2(){
	// Pops up a help window
	popUpWindow("/QASPTemplates/html/firstresort/branded/AA/Holidays/help.html","_blank","width=300,height=400,scrollbars");}
function popUpHelpWindow3(){
	// Pops up a help window
	popUpWindow("/QASPTemplates/html/firstresort/branded/virgin/Holidays/help.html","_blank","width=300,height=400,scrollbars");}	
function popUpHelpWindow4(){
	// Pops up a help window
	window.open("/QASPTemplates/html/firstresort/branded/sky/skiholidays/help.html","_blank","width=280,height=370,scrollbars=0,top=0,left=0");
	}	
	
function validateForm1() {
	var form = document.form1;
	if (form.destair.selectedIndex == 0){
	 	alert("Please select a destination.");
		form.destair.focus();
		return false;
	}
	if (form.price.selectedIndex == 0){
		alert("Please select a price range.");
		form.price.focus();
		return false;
	}
	
	if (form.deptair.selectedIndex == 0){
		alert("Please select a departure airport.");
		form.deptair.focus();
		return false;
	}
	
	
	var dt = form.List_DateFrom.options[form.List_DateFrom.selectedIndex].value
	var mn = form.List_MYrFrom.options[form.List_MYrFrom.selectedIndex].text.split(" ")[0]
	var yr = form.List_MYrFrom.options[form.List_MYrFrom.selectedIndex].text.split(" ")[1]

	if (validDate(dt,mn,yr)) {
		if (! validFutureDate(dt,mn,yr)) {
			alert("Departure date should be on or after 7th December.") //("Departure date should be a future date.")
			return false;
		}
	}
	else {
		alert("Please select a valid date.")
		return false;
	}
	
	/* Number of adults was removed from the search form for Ski 2003 but this code has been
	   left in but commented out in case they are re-introduced.
	if (! checkNumOfAdults(form)){
		var msg="Please contact our call centre if you wish to book for more than 9 passengers."
		alert(msg)
		return false;
	}
	*/
	return popUpWaitingScreen('/latedeals3/waitingscreen.asp',370,260)
}

function validateFormNoPop() {
	var form = document.form1;

	if (form.deptair.selectedIndex == 0){
		alert("Please select a departure airport.");
		form.deptair.focus();
		return false;
	}
	if (form.price.selectedIndex == 0){
		alert("Please select a price range.");
		form.price.focus();
		return false;
	}
		
	var dt = form.List_DateFrom.options[form.List_DateFrom.selectedIndex].value
	var mn = form.List_MYrFrom.options[form.List_MYrFrom.selectedIndex].text.split(" ")[0]
	var yr = form.List_MYrFrom.options[form.List_MYrFrom.selectedIndex].text.split(" ")[1]

	if (validDate(dt,mn,yr)) {
		if (! validFutureDate(dt,mn,yr)) {
			//alert("Departure date should be on or after 7th December.")
			alert("Departure date should be a future date.")
			return false;
		}
	}
	else {
		alert("Please select a valid date.")
		return false;
	}
}
