


//Check for valid arrival date, and update departure and calendar fields
function onChangeArrivalDate(form) {

    var arrival = form.arrival.value.split("-");

    today = new Date();

    //latest booking time is 6:00 pm today
    booking_date =
	new Date(arrival[0], arrival[1]-1,arrival[2],18,0,0);

   //check booking date
    if ( booking_date.getTime() < today.getTime() ) {
	alert("It is too late to book for that arrival date.");
	return false;
    }

    too_far = new Date(today.getFullYear(),today.getMonth(),today.getDate());
    too_far.setMonth(parseInt(today.getMonth())+9);
    if(booking_date.getTime() >= too_far.getTime() ){
	alert('For bookings more than 9 months in the future please contact our central reservations team on 0800 917 3085');
	return false;
    }
    CalendarSetArrivalDate(form);

}

//called when calendar has a new date
function ArrivalCalendarCallback(cal) {

    form=document.getElementById("booking-form");
    if (cal.dateClicked) {
	var arr = cal.date.print("%Y-%m-%d");
	form.arrival.value=arr;
    }
    cal.hide();
    onChangeArrivalDate(form);
}


//set new date for calendar to start with
function CalendarSetArrivalDate(form) {
	form.arrival_cal.value = form.arrival.value;
}


//check total of rooms selected is correct
function checkRooms(form,count,max){

    var i;
    var tot;
    var sel;
    tot=0;
    for(i=1;i<=count;i++){
	sel = document.getElementById('room_'+i);
	tot += sel.selectedIndex;
    }
    
    if( tot != max ){
	alert('Warning: You have selected '+tot+' rooms to book.\nPlease ensure you have selected '+max+' rooms before proceeding.');
	return false;
    } else
	return true;

}

