function event_ArriveDateUpdated(calendar){
   	if (calendar.dateClicked) {
     	// A date was clicked in the calendar. Update the select lists with choosen dates.
     	var y = calendar.date.getFullYear();
     	var m = calendar.date.getMonth();     // integer, 0..11
     	var d = calendar.date.getDate();      // integer, 1..31
		
		//m = (m + 1); // We want to have months in the numbers 1..12 instead.

		var oArrivalDay = document.getElementById("arrivalDay");
		oArrivalDay.selectedIndex = d;
		changeOfMonth(oArrivalDay);
   	
		var oArrivalMonthYear = document.getElementById("arrivalMonthYear");
		
		// We need the month in two digits, example: "7" should be "07", "11" should be "11", "3" should be "03" and so on.
		if (m.toString().length == 1) m = "0" + m.toString();

		// Get the index in list that matches the year and day value and select the matching option.
		oArrivalMonthYear.selectedIndex = findIndexInList(oArrivalMonthYear, y.toString() + m.toString());
		
		changeOfMonth(oArrivalMonthYear);
	}
}

function event_DepartureDateUpdated(calendar){
   	if (calendar.dateClicked) {
     	// A date was clicked in the calendar. Update the select lists with choosen dates.
     	var y = calendar.date.getFullYear();
     	var m = calendar.date.getMonth();     // integer, 0..11
     	var d = calendar.date.getDate();      // integer, 1..31
		
		//m = (m + 1); // We want to have months in the numbers 1..12 instead.

		// -----------
		// Set departure month
		var oDepartureMonthYear = document.getElementById("departureMonthYear");
		
		// We need the month in two digits, example: "7" should be "07", "11" should be "11", "3" should be "03" and so on.
		if (m.toString().length == 1) m = "0" + m.toString();

		// Get the index in list that matches the year and day value and select the matching option.
		oDepartureMonthYear.selectedIndex = findIndexInList(oDepartureMonthYear, y.toString() + m.toString());
		
		changeOfMonth(oDepartureMonthYear);
		
		// -----------
		// Set departure day (must be set after departure month. if not, then the day will be changed to the day after the arrival day if a later month is choosen)
		var oDepartureDay = document.getElementById("departureDay");
		oDepartureDay.selectedIndex = d;
		changeOfMonth(oDepartureDay);
	}
}

function findIndexInList(oList, value){
	var intIndex;
	
	for (var i=0; i <= (oList.options.length - 1); i++) {
		if (oList.options[i].value == value){
			intIndex = i;
			break;
		}
	}
	
	return intIndex;
}

var global_bw_MaxYear;
var global_bw_MaxMonth;
var global_bw_MinYear;
var global_bw_MinMonth;
// this is the actual date status handler.  Note that it receives the
// date object as well as separate values of year, month and date.
function event_CheckDateStatus(date, y, m, d) {
    var oArrivalMonthYear = document.getElementById("arrivalMonthYear");
	
	//m = (m + 1); // Month is in format "0..12" We want to have months in the format "1..12" instead.
	
	if (oArrivalMonthYear.value != "-1") {
		if (!global_bw_MaxYear){
			intListLength = (oArrivalMonthYear.options.length);
			
			global_bw_MinYear = oArrivalMonthYear.options[1].value.substr(0, 4);
			global_bw_MinMonth = oArrivalMonthYear.options[1].value.substr(5, 6);
			global_bw_MaxYear = oArrivalMonthYear.options[intListLength-1].value.substr(0, 4);
			global_bw_MaxMonth = oArrivalMonthYear.options[intListLength-1].value.substr(5, 6);
		}

		if (y < global_bw_MinYear) return true;
		else if(y > global_bw_MaxYear) return true;
		else if (y == global_bw_MinYear && m < global_bw_MinMonth) return true;
		else if (y == global_bw_MaxYear && m > global_bw_MaxMonth) return true;
		
	    else return false;
	    // return true above if you want to disable other dates
	}
}

// Validates so departure month isnt before arrival month.
function validateDepartureMonth() {
    var arrival = document.getElementById("arrivalMonthYear").value;
    var departure = document.getElementById("departureMonthYear").value;

    if (departure < arrival) {
        // Set departure month to the same as arrival.
        document.getElementById("departureMonthYear").value = arrival;
    }
}

// Validates so arrival month isnt after departure month.
function validateArrivalMonth() {
    var arrival = document.getElementById("arrivalMonthYear").value;
    var departure = document.getElementById("departureMonthYear").value;

    if (arrival > departure) {
        // Set arrival month to the same as departure.
        document.getElementById("arrivalMonthYear").value = departure;
    }
}