function Recalculate(objectName){

	display("notesDisplay", "");
//resForm
	var f = document.resForm;
	
	var lastCalendarDay = new Date(parseInt(Years[Years.length-1],10),11,31);

	if (objectName == "arrDate") {
		// If we change the arrival date we adjust the depDate
		if (objArr.getCalendarDate()<Today){
			// If in the past, we reset to day
			display("notesDisplay", "Note: Arrival date must start from today.");
			objArr.changeDate(new Date());
			objArr.refresh();
		}
		if (objArr.getCalendarDate().valueOf() == lastCalendarDay.valueOf()){
			// If in the past, we reset to day
			display("notesDisplay", "Note: Arrival date must before the last day of the year.");
			objArr.changeDate(DaysAdd(lastCalendarDay,-1));
			objArr.refresh();
			f.nights.selectedIndex = 0;
			objDep.changeDate(lastCalendarDay);
			objDep.refresh();
			
		}
		var dep = DaysAdd(objArr.getCalendarDate(),parseInt(f.nights.options[f.nights.selectedIndex].value,10));
		if (dep>lastCalendarDay){
			// If Depart beyond our calendar, change the nights stay
			display("notesDisplay", "Note: Last departure date is the end of the year.");
			objDep.changeDate(lastCalendarDay);
			objDep.refresh() ;
			f.nights.selectedIndex = Math.max(0,DaysDiff(objArr.getCalendarDate(),objDep.getCalendarDate())-1);
		}
		else {
			objDep.changeDate(dep);
			objDep.refresh() ;
		}
	}
	if (objectName == "nights") {
		// If we change the Nights stay we adjust the depDate
		var dep = DaysAdd(objArr.getCalendarDate(),parseInt(f.nights.options[f.nights.selectedIndex].value,10));
		if (dep>lastCalendarDay){
			display("notesDisplay", "Note: Last departure date is the end of the year.");
			arr = DaysAdd(lastCalendarDay,-parseInt(f.nights.options[f.nights.selectedIndex].value,10));
			objArr.changeDate(arr);
			objArr.refresh() ;
			objDep.changeDate(lastCalendarDay);
			objDep.refresh() ;
		}
		else {
			objDep.changeDate(dep);
			objDep.refresh() ;
		}
	}
	if (objectName == "depDate") {
		// If we change the Departure date we adjust the Nights stay
		var daysDiff;
		daysDiff = DaysDiffText(f.arrDate.value, f.depDate.value, "DD-MON-YYYY");
		if (daysDiff <=0) {
			//alert('here');
			display("notesDisplay", "Note: Departure must be after Arrival date plus 1 night.");
			arr = DaysAdd(objDep.getCalendarDate(),-parseInt(f.nights.options[f.nights.selectedIndex].value,10));
			objArr.changeDate(arr);
			objArr.refresh() ;
			//f.nights.selectedIndex = 0;
			//var dep = DaysAdd(objArr.getCalendarDate(),parseInt(f.nights.options[f.nights.selectedIndex].value,10));
			//objDep.changeDate(dep);
			//objDep.refresh() ;
		}
		else {
			if (daysDiff>parseInt(f.maxNights.value,10)){
				// Date is outside the maximum number of nights stay
				display("notesDisplay","Note: Maximum stay is " + f.maxNights.value + " nights.");
				var dep = DaysAdd(objArr.getCalendarDate(),parseInt(f.maxNights.value,10));
				objDep.changeDate(dep);
				objDep.refresh() ;
				f.nights.selectedIndex = f.nights.length-1;		
				//f.nights.options[Math.min(f.maxNights.value,f.nights.length)] = new Option( daysDiff, daysDiff );
				f.nights.selectedIndex = f.nights.length-1;		
			}
			else {
				f.nights.selectedIndex = 0;
				for (var n = 0; n<f.nights.length; n++) {
					if (parseInt(daysDiff,10) == parseInt(f.nights.options[n].value,10)) {
					f.nights.selectedIndex = n;
					}
				}
			}
		}
	}
}
function display(id, str) {
  if (!document.all[id]) {
    with (document[id].document) {
      open();
      write(str);
      close();
    }
  } else {
    document.all[id].innerHTML = str;
  }
}

