/* ========================================================================== */
/*                                 Modify Search                              */
/* ========================================================================== */
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 zeroPad(intValue)
{
  var intStr = "" + intValue;
  if(intStr.length == 1)
    intStr = "0" + intStr;
  
  return intStr;
}

function resetForm(){
	window.location.href="/use_your_miles/travel/hotels.do";
}
