// This script assumes you also have the popcalendar loaded
function update_checkout_date(last_night_control) {
  if (last_night_control.form.checkout_date) {
    var last_night_date = new Date(getUTC(last_night_control.value,'dd mmm yyyy'));
    last_night_date.setDate(last_night_date.getDate()+1);
		last_night_control.form.checkout_date.value =	constructDate(last_night_date.getDate(),last_night_date.getMonth(),last_night_date.getFullYear());
  }
	return true;
}

// function called by double clicking on the calendar
function updatefirstnight(epoch) {
  var f_n = new sbm_getObj('first_night');
  var l_n = new sbm_getObj('last_night');

  if (f_n.obj) {
    f_n.obj.value = epoch;

    if (l_n.obj) {
      if (getUTC(epoch,'dd mmm yyyy') > getUTC(l_n.obj.value,'dd mmm yyyy')) {
        l_n.obj.value = epoch;
        // And fire the checkout date update if we changed last night
        update_checkout_date(l_n.obj);
      }
    }
  }
}

