function reward_yourself_onCalendarChooseAir(theElement)
{
  if(  theElement.id == 'rtDepartureDateStrSpan')
  {
    //  Move focus to the departure time field when the user has chosen a date
    document.AirSearchForm.rtDepartureTime.focus();
    
    
    // If the return date is earlier than the departure date,
    // set it to the same as the return date
    var departureDate = new Date(document.AirSearchForm.rtDepartureYear.value, document.AirSearchForm.rtDepartureMonth.value - 1, document.AirSearchForm.rtDepartureDay.value);
    var returnDate = new Date(document.AirSearchForm.rtReturnYear.value, document.AirSearchForm.rtReturnMonth.value - 1, document.AirSearchForm.rtReturnDay.value);
    
    if(returnDate.getTime() - departureDate.getTime() < 0)
    {
      returnDate.setTime(departureDate.getTime());
      document.AirSearchForm.rtReturnDateStr.value = strftime(date_format,returnDate);
      document.AirSearchForm.rtReturnYear.value = returnDate.getFullYear();
      document.AirSearchForm.rtReturnMonth.value = returnDate.getMonth() + 1;
      document.AirSearchForm.rtReturnDay.value = returnDate.getDate();
      document.AirSearchForm.rtReturnDate.value = returnDate.getFullYear() + "-" + zeroPad((returnDate.getMonth() + 1)) + "-" + zeroPad(returnDate.getDate());
    }
  }
  else
  {
    document.AirSearchForm.rtReturnTime.focus();
  }
}


function reward_yourself_onCalendarChooseHotel(theElement) {
  if (theElement.id == 'HotelCheckInDateStrSpan') {
    // If the check-out date is on the same day or earlier than the check-in date,
    // set it to one day later than the check-in date
    var HotelCheckInDate = new Date(document.HotelSearchForm.HotelCheckInYear.value, document.HotelSearchForm.HotelCheckInMonth.value - 1, document.HotelSearchForm.HotelCheckInDay.value);
    var HotelCheckOutDate = new Date(document.HotelSearchForm.HotelCheckOutYear.value, document.HotelSearchForm.HotelCheckOutMonth.value - 1, document.HotelSearchForm.HotelCheckOutDay.value);
    var ONE_DAY_MILLIS = 24 * 60 * 60 * 1000;
    
    if (HotelCheckOutDate.getTime() - HotelCheckInDate.getTime() < ONE_DAY_MILLIS) {
      HotelCheckOutDate.setTime(HotelCheckInDate.getTime() + ONE_DAY_MILLIS);
      document.HotelSearchForm.HotelCheckOutDateStr.value = strftime(date_format,HotelCheckOutDate);
      document.HotelSearchForm.HotelCheckOutYear.value = HotelCheckOutDate.getFullYear();
      document.HotelSearchForm.HotelCheckOutMonth.value = HotelCheckOutDate.getMonth() + 1;
      document.HotelSearchForm.HotelCheckOutDay.value = HotelCheckOutDate.getDate();
      document.HotelSearchForm.HotelCheckOutDate.value = HotelCheckOutDate.getFullYear() + "-" + zeroPad((HotelCheckOutDate.getMonth() + 1)) + "-" + zeroPad(HotelCheckOutDate.getDate());
    }
	} else if (theElement.id == 'HotelCheckOutDateStrSpan') {
    // If the check-out date is on the same day or earlier than the check-in date,
    // set it to one day later than the check-in date
    var HotelCheckInDate = new Date(document.HotelSearchForm.HotelCheckInYear.value, document.HotelSearchForm.HotelCheckInMonth.value - 1, document.HotelSearchForm.HotelCheckInDay.value);
    var HotelCheckOutDate = new Date(document.HotelSearchForm.HotelCheckOutYear.value, document.HotelSearchForm.HotelCheckOutMonth.value - 1, document.HotelSearchForm.HotelCheckOutDay.value);
    var ONE_DAY_MILLIS = 24 * 60 * 60 * 1000;
    
    if (HotelCheckOutDate.getTime() - HotelCheckInDate.getTime() <= ONE_DAY_MILLIS) {
      HotelCheckInDate.setTime(HotelCheckOutDate.getTime() - ONE_DAY_MILLIS);
      document.HotelSearchForm.HotelCheckInDateStr.value = strftime(date_format,HotelCheckInDate);
      document.HotelSearchForm.HotelCheckInYear.value = HotelCheckInDate.getFullYear();
      document.HotelSearchForm.HotelCheckInMonth.value = HotelCheckInDate.getMonth() + 1;
      document.HotelSearchForm.HotelCheckInDay.value = HotelCheckInDate.getDate();
      document.HotelSearchForm.HotelCheckInDate.value = HotelCheckInDate.getFullYear() + "-" + zeroPad((HotelCheckInDate.getMonth() + 1)) + "-" + zeroPad(HotelCheckInDate.getDate());
    }
  }
}

function reward_yourself_onCalendarChooseCar(theElement)
{
  if(  theElement.id == 'PickupDateStrSpan')
  {
    //  Move focus to the pick up time field when the user has chosen a date
    document.CarSearchForm.PickupHour.focus();
    
    
    // If the dropoff date is on the same day or earlier than the pickup date,
    // set it to one day later than the pickup date
    var pickupDate = new Date(document.CarSearchForm.PickupYear.value, document.CarSearchForm.PickupMonth.value - 1, document.CarSearchForm.PickupDay.value);
    var dropoffDate = new Date(document.CarSearchForm.DropoffYear.value, document.CarSearchForm.DropoffMonth.value - 1, document.CarSearchForm.DropoffDay.value);
    
    var ONE_DAY_MILLIS = 24 * 60 * 60 * 1000;
    if(dropoffDate.getTime() - pickupDate.getTime() < ONE_DAY_MILLIS)
    {
      dropoffDate.setTime(pickupDate.getTime() + ONE_DAY_MILLIS);
      document.CarSearchForm.DropoffDateStr.value = strftime(date_format,dropoffDate);
      document.CarSearchForm.DropoffYear.value = dropoffDate.getFullYear();
      document.CarSearchForm.DropoffMonth.value = dropoffDate.getMonth() + 1;
      document.CarSearchForm.DropoffDay.value = dropoffDate.getDate();
      document.CarSearchForm.DropoffDate.value = dropoffDate.getFullYear() + "-" + zeroPad((dropoffDate.getMonth() + 1)) + "-" + zeroPad(dropoffDate.getDate());
    }
  }
  else
  {
    document.CarSearchForm.DropoffHour.focus();
  }
}


function zeroPad(intValue)
{
  var intStr = "" + intValue;
  if(intStr.length == 1)
    intStr = "0" + intStr;
  
  return intStr;
}


