var opeHoursStartPrev = 0;
var opeHoursEndPrev = 0;
var opeHoursStartNext = 0;
var opeHoursEndNext = 0;
var prmStartDateTimeOrg = new Date();
var selectDateTimeStart = null;
var selectDateTimeEnd = null;

function setRsvDateTime() {

  selectFlg = pageDiv;

  startDateTime = adjustDateTime1(startDateTime);

  prmDispDateTime = new Date();
  prmDispDateTime.setTime(startDateTime.getTime());

  if (selectStartYear != 9999 && selectStartMonth != 99 && selectStartDate != 99 && selectStartHours != 99 && selectStartMinutes != 99) {

    selectDateTimeStart = new Date(selectStartYear, selectStartMonth - 1, selectStartDate, selectStartHours, selectStartMinutes, 0);

    if (prmDispDateTime.getTime() > selectDateTimeStart.getTime()) {

      selectStartYear = parseInt(prmDispDateTime.getFullYear());
      selectStartMonth = parseInt(prmDispDateTime.getMonth()) + 1;
      selectStartDate = prmDispDateTime.getDate();
      selectStartHours = parseInt(prmDispDateTime.getHours());
      selectStartMinutes = parseInt(prmDispDateTime.getMinutes());

    }

    selectDateTimeStart = new Date(selectStartYear, selectStartMonth - 1, selectStartDate, selectStartHours, selectStartMinutes, 0);

  }

  if (selectEndYear != 9999 && selectEndMonth != 99 && selectEndDate != 99 && selectEndHours != 99 && selectEndMinutes != 99) {

    selectDateTimeEnd = new Date(selectEndYear, selectEndMonth - 1, selectEndDate, selectEndHours, selectEndMinutes, 0);

    if (prmDispDateTime.getTime() > selectDateTimeEnd.getTime()) {

      selectEndYear = parseInt(prmDispDateTime.getFullYear());
      selectEndMonth = parseInt(prmDispDateTime.getMonth()) + 1;
      selectEndDate = prmDispDateTime.getDate();
      selectEndHours = parseInt(prmDispDateTime.getHours());
      selectEndMinutes = parseInt(prmDispDateTime.getMinutes());

    }

    selectDateTimeEnd = new Date(selectEndYear, selectEndMonth - 1, selectEndDate, selectEndHours, selectEndMinutes, 0);

  }

  if (prmStartDateTimeOrg.getHours() == 0 && prmStartDateTimeOrg.getMinutes() == 0) {

    if (selectDateTimeStart) {

      prmDispDateTimeOrgStart = new Date(selectStartYear, selectStartMonth - 1, selectStartDate, 0, 0, 0);

    } else {

      prmDispDateTimeOrgStart = new Date(prmDispDateTime.getFullYear(), prmDispDateTime.getMonth(), prmDispDateTime.getDate(), 0, 0, 0);

    }

    if (selectDateTimeEnd) {

      prmDispDateTimeOrgEnd = new Date(selectEndYear, selectEndMonth - 1, selectEndDate, 0, 0, 0);

    } else {

      prmDispDateTimeOrgEnd = new Date(prmDispDateTime.getFullYear(), prmDispDateTime.getMonth(), prmDispDateTime.getDate(), 0, 0, 0);

    }

  } else {

    prmDispDateTimeOrgStart = new Date();
    prmDispDateTimeOrgStart.setTime(prmDispDateTime.getTime());
    prmDispDateTimeOrgEnd = new Date();
    prmDispDateTimeOrgEnd.setTime(prmDispDateTime.getTime());

  }

  prmDispDateTime = setRsvYear(0, prmDispDateTime);
  prmDispDateTime = setRsvMonth(0, prmDispDateTime);
  prmDispDateTime = setRsvDate(0, prmDispDateTime);
  prmDispDateTime = setRsvHours(0, prmDispDateTime, prmDispDateTimeOrgStart);
  setRsvMinutes(0, prmDispDateTime);

  prmDispDateTime.setTime(startDateTime.getTime());

  prmDispDateTime = setRsvYear(1, prmDispDateTime);
  prmDispDateTime = setRsvMonth(1, prmDispDateTime);
  prmDispDateTime = setRsvDate(1, prmDispDateTime);
  prmDispDateTime = setRsvHours(1, prmDispDateTime, prmDispDateTimeOrgEnd);
  setRsvMinutes(1, prmDispDateTime);
}

// 日時整形･･････初期表示
function adjustDateTime1(prmStartDateTime) {

  years = parseInt(prmStartDateTime.getFullYear());
  months = parseInt(prmStartDateTime.getMonth()) + 1;
  dates = prmStartDateTime.getDate();
  hours = parseInt(prmStartDateTime.getHours());
  minutes = parseInt(prmStartDateTime.getMinutes());
  day = parseInt(prmStartDateTime.getDay());

  addMinutes = (minutes % timeSpan > 0) ? timeSpan - (minutes % timeSpan) : 0;

  opeTimeArray = new Array();
  opeTimeArray = getOpeTime(day);

  opeHoursStartPrev = opeTimeArray['OpeHoursStartPrev'];
  opeHoursEndPrev = opeTimeArray['OpeHoursEndPrev'];
  opeHoursStartNext = opeTimeArray['OpeHoursStartNext'];
  opeHoursEndNext = opeTimeArray['OpeHoursEndNext'];

  prmStartDateTime = new Date(years, months - 1, dates, hours + intervalHours, minutes + intervalMinutes + addMinutes, 0);
  startDateTime = new Date(years, months - 1, dates, hours, minutes + addMinutes, 0);

  prmStartDateTimeOrg.setTime(prmStartDateTime.getTime());

  openDateTimeToday = new Date(years, months - 1, dates, opeTimeArray['OpeHoursStart'], opeTimeArray['OpeMinutesStart'], 0);
  closeDateTimeToday = new Date(years, months - 1, dates, opeTimeArray['OpeHoursEnd'], opeTimeArray['OpeMinutesEnd'], 0);
  openDateTimeNext  = new Date(years, months - 1, dates + 1, opeTimeArray['OpeHoursStartNext'], opeTimeArray['OpeMinutesStartNext'], 0);
  closeDateTimeNext  = new Date(years, months - 1, dates + 1, opeTimeArray['OpeHoursEndNext'], opeTimeArray['OpeMinutesEndNext'], 0);
  closeDateTimePrev = new Date(years, months - 1, dates - 1, opeTimeArray['OpeHoursEndPrev'], opeTimeArray['OpeMinutesEndPrev'], 0);

  if (prmStartDateTime.getTime() < openDateTimeToday.getTime()) {

    // 開店前(営業時間外)
    prmStartDateTime = new Date(parseInt(openDateTimeToday.getFullYear()), parseInt(openDateTimeToday.getMonth()), parseInt(openDateTimeToday.getDate()), parseInt(openDateTimeToday.getHours()) + invalidHours, parseInt(openDateTimeToday.getMinutes()) + invalidMinutes, 0);

  } else if (prmStartDateTime.getTime() > closeDateTimeToday.getTime()) {

    if (startDateTime.getTime() < openDateTimeToday.getTime()) {

      // インターバルを含めないと現在時刻が開店前
      subTime = openDateTimeToday.getTime() - startDateTime.getTime();

      subDate1 = new Date(years, months - 1, dates, 0, 0, 0);
      subDate2 = new Date(years, months - 1, dates, intervalHours, intervalMinutes, 0);

      restIntervalTime = subDate2.getTime() - subDate1.getTime() - subTime;

      while (restIntervalTime > closeDateTimeToday.getTime() - openDateTimeToday.getTime()) {

        restIntervalTime -= (closeDateTimeToday.getTime() - openDateTimeToday.getTime());

        if (restIntervalTime > closeDateTimeNext.getTime() - openDateTimeNext.getTime()) {

          openDateTimeToday.setTime(openDateTimeNext.getTime());
          closeDateTimeToday.setTime(closeDateTimeNext.getTime())
          tmpOpeTimeArray = getOpeTime(openDateTimeToday.getDay());
          openDateTimeNext  = new Date(openDateTimeToday.getFullYear(), openDateTimeToday.getMonth(), openDateTimeToday.getDate() + 1, tmpOpeTimeArray['OpeHoursStartNext'], tmpOpeTimeArray['OpeMinutesStartNext'], 0);
          closeDateTimeNext  = new Date(openDateTimeToday.getFullYear(), openDateTimeToday.getMonth(), openDateTimeToday.getDate() + 1, tmpOpeTimeArray['OpeHoursEndNext'], tmpOpeTimeArray['OpeMinutesEndNext'], 0);

        }

      }

      subDate1 = new Date(years, months - 1, dates, 0, 0, 0);
      subDate2 = new Date(years, months - 1, dates, invalidHours, invalidMinutes, 0);

      addTime = (restIntervalTime > subDate2.getTime() - subDate1.getTime()) ? restIntervalTime : subDate2.getTime() - subDate1.getTime();

      prmStartDateTime.setTime(openDateTimeNext.getTime() + addTime);

    } else if (startDateTime.getTime() > closeDateTimeToday.getTime()) {

      // インターバルを含めなくても現在時刻が閉店後
      subTime = openDateTimeNext.getTime() - startDateTime.getTime();

      subDate1 = new Date(years, months - 1, dates, 0, 0, 0);
      subDate2 = new Date(years, months - 1, dates, intervalHours, intervalMinutes, 0);

      restIntervalTime = subDate2.getTime() - subDate1.getTime();

      while (restIntervalTime > closeDateTimeNext.getTime() - openDateTimeNext.getTime()) {

        openDateTimeToday.setTime(openDateTimeNext.getTime());
        closeDateTimeToday.setTime(closeDateTimeNext.getTime())
        tmpOpeTimeArray = getOpeTime(openDateTimeToday.getDay());
        openDateTimeNext  = new Date(openDateTimeToday.getFullYear(), openDateTimeToday.getMonth(), openDateTimeToday.getDate() + 1, tmpOpeTimeArray['OpeHoursStartNext'], tmpOpeTimeArray['OpeMinutesStartNext'], 0);
        closeDateTimeNext  = new Date(openDateTimeToday.getFullYear(), openDateTimeToday.getMonth(), openDateTimeToday.getDate() + 1, tmpOpeTimeArray['OpeHoursEndNext'], tmpOpeTimeArray['OpeMinutesEndNext'], 0);

        restIntervalTime -= (closeDateTimeToday.getTime() - openDateTimeToday.getTime());

      }

      subDate1 = new Date(years, months - 1, dates, 0, 0, 0);
      subDate2 = new Date(years, months - 1, dates, invalidHours, invalidMinutes, 0);

      if (intervalCarryOverFlg) {

        addTime = (restIntervalTime > subDate2.getTime() - subDate1.getTime()) ? restIntervalTime : subDate2.getTime() - subDate1.getTime();

      } else {

        addTime = subDate2.getTime() - subDate1.getTime();

      }

      prmStartDateTime.setTime(openDateTimeNext.getTime() + addTime);

    } else {

      // インターバル込みで閉店後(当日の場合)
      subTime = closeDateTimeToday.getTime() - startDateTime.getTime();

      subDate1 = new Date(years, months - 1, dates, 0, 0, 0);
      subDate2 = new Date(years, months - 1, dates, intervalHours, intervalMinutes, 0);

      restIntervalTime = (intervalCarryOverFlg) ? subDate2.getTime() - subDate1.getTime() - subTime : 0;

      while (restIntervalTime > closeDateTimeNext.getTime() - openDateTimeNext.getTime()) {

        openDateTimeToday.setTime(openDateTimeNext.getTime());
        closeDateTimeToday.setTime(closeDateTimeNext.getTime())
        tmpOpeTimeArray = getOpeTime(openDateTimeToday.getDay());
        openDateTimeNext  = new Date(openDateTimeToday.getFullYear(), openDateTimeToday.getMonth(), openDateTimeToday.getDate() + 1, tmpOpeTimeArray['OpeHoursStartNext'], tmpOpeTimeArray['OpeMinutesStartNext'], 0);
        closeDateTimeNext  = new Date(openDateTimeToday.getFullYear(), openDateTimeToday.getMonth(), openDateTimeToday.getDate() + 1, tmpOpeTimeArray['OpeHoursEndNext'], tmpOpeTimeArray['OpeMinutesEndNext'], 0);

        restIntervalTime -= (closeDateTimeToday.getTime() - openDateTimeToday.getTime());

      }

      prmStartDateTime.setTime(openDateTimeNext.getTime() + restIntervalTime);

    }

  } else {

    if (startDateTime.getTime() < openDateTimeToday.getTime()) {

      if (opeTimeArray['OpeHoursStart'] == 0 && opeTimeArray['OpeHoursEnd'] == 24) {

        // 24時間営業のため無効時間が発生しない
        prmStartDateTime.setTime(prmStartDateTime.getTime());

      } else {

        // インターバルを含めないと現在時刻が開店前

        subTime = openDateTimeToday.getTime() - startDateTime.getTime();

        subDate1 = new Date(years, months - 1, dates, 0, 0, 0);
        subDate2 = new Date(years, months - 1, dates, intervalHours, intervalMinutes, 0);

        restIntervalTime = subDate2.getTime() - subDate1.getTime() - subTime;

        subDate1 = new Date(years, months - 1, dates, 0, 0, 0);
        subDate2 = new Date(years, months - 1, dates, invalidHours, invalidMinutes, 0);

        addTime = (restIntervalTime > subDate2.getTime() - subDate1.getTime()) ? restIntervalTime : subDate2.getTime() - subDate1.getTime();

        prmStartDateTime.setTime(openDateTimeToday.getTime() + addTime);

      }

    } else {

      // 営業中またはインターバル・無効時間適用範囲外
      prmStartDateTime.setTime(prmStartDateTime.getTime());

    }

  }

  day = prmStartDateTime.getDay();

  opeTimeArray = getOpeTime(day);

  return prmStartDateTime;

}

// 日時整形･･････日時変更時
function adjustDateTime2(prmStartDateTime) {

  if (prmStartDateTime.getTime() < startDateTime.getTime()) {

    prmStartDateTime.setTime(startDateTime.getTime());

  }

  years = startDateTime.getFullYear();
  months = startDateTime.getMonth() + 1;
  dates = startDateTime.getDate();
  hours = startDateTime.getHours();
  minutes = startDateTime.getMinutes();
  day = startDateTime.getDay();

  opeTimeArray = new Array();
  opeTimeArray = getOpeTime(day);

  prmYear = parseInt(prmStartDateTime.getFullYear());
  prmMonth = parseInt(prmStartDateTime.getMonth()) + 1;
  prmDate = parseInt(prmStartDateTime.getDate());
  prmHours = parseInt(prmStartDateTime.getHours());
  prmMinutes = parseInt(prmStartDateTime.getMinutes());
  prmDay = parseInt(prmStartDateTime.getDay());

  opeTimePrmArray = new Array();
  opeTimePrmArray = getOpeTime(prmDay);

  openDateTimeToday = new Date(years, months - 1, dates, opeTimeArray['OpeHoursStart'], opeTimeArray['OpeMinutesStart'], 0);
  closeDateTimeToday = new Date(years, months - 1, dates, opeTimeArray['OpeHoursEnd'], opeTimeArray['OpeMinutesEnd'], 0);
  openDateTimeNext  = new Date(years, months - 1, dates + 1, opeTimeArray['OpeHoursStartNext'], opeTimeArray['OpeMinutesStartNext'], 0);

  openDateTimePrm = new Date(prmYear, prmMonth - 1, prmDate, opeTimePrmArray['OpeHoursStart'], opeTimePrmArray['OpeMinutesStart'], 0);
  closeDateTimePrm = new Date(prmYear, prmMonth - 1, prmDate, opeTimePrmArray['OpeHoursEnd'], opeTimePrmArray['OpeMinutesEnd'], 0);
  openDateTimePrmNext  = new Date(prmYear, prmMonth - 1, prmDate + 1, opeTimePrmArray['OpeHoursStartNext'], opeTimePrmArray['OpeMinutesStartNext'], 0);

  if (prmStartDateTime.getTime() < openDateTimePrm.getTime()) {

    // 開店前(営業時間外)
    if (openDateTimePrm.getTime() == openDateTimeToday.getTime()) {

      // 無効時間有り
      prmStartDateTime = new Date(parseInt(openDateTimePrm.getFullYear()), parseInt(openDateTimePrm.getMonth()), parseInt(openDateTimePrm.getDate()), parseInt(openDateTimePrm.getHours()) + invalidHours, parseInt(openDateTimePrm.getMinutes()) + invalidMinutes, 0);

    } else {

      // 無効時間無し
      prmStartDateTime = new Date(parseInt(openDateTimePrm.getFullYear()), parseInt(openDateTimePrm.getMonth()), parseInt(openDateTimePrm.getDate()), parseInt(openDateTimePrm.getHours()), parseInt(openDateTimePrm.getMinutes()), 0);

    }

  } else {

    // インターバル・無効時間適用範囲外
    prmStartDateTime.setTime(prmStartDateTime.getTime());

  }

  day = prmStartDateTime.getDay();

  opeTimeArray = getOpeTime(day);

  return prmStartDateTime;

}

function getOpeTime(dayNum) {

  switch (dayNum) {

    case 0 :

      opeHoursStartPrev = opeHoursStartSat;
      opeHoursEndPrev = opeHoursEndSat;
      opeMinutesStartPrev = opeMinutesStartSat;
      opeMinutesEndPrev = opeMinutesEndSat;

      opeHoursStart = opeHoursStartSun;
      opeHoursEnd = opeHoursEndSun;
      opeMinutesStart = opeMinutesStartSun;
      opeMinutesEnd = opeMinutesEndSun;

      opeHoursStartNext = opeHoursStartUsal;
      opeHoursEndNext = opeHoursEndUsal;
      opeMinutesStartNext = opeMinutesStartUsal;
      opeMinutesEndNext = opeMinutesEndUsal;

      break;

    case 6 :

      opeHoursStartPrev = opeHoursStartUsal;
      opeHoursEndPrev = opeHoursEndUsal;
      opeMinutesStartPrev = opeMinutesStartUsal;
      opeMinutesEndPrev = opeMinutesEndUsal;

      opeHoursStart = opeHoursStartSat;
      opeHoursEnd = opeHoursEndSat;
      opeMinutesStart = opeMinutesStartSat;
      opeMinutesEnd = opeMinutesEndSat;

      opeHoursStartNext = opeHoursStartSun;
      opeHoursEndNext = opeHoursEndSun;
      opeMinutesStartNext = opeMinutesStartSun;
      opeMinutesEndNext = opeMinutesEndSun;

      break;

    default :

      if (dayNum == 1) {

        opeHoursStartPrev = opeHoursStartSun;
        opeHoursEndPrev = opeHoursEndSun;
        opeMinutesStartPrev = opeMinutesStartSun;
        opeMinutesEndPrev = opeMinutesEndSun;

      } else {

        opeHoursStartPrev = opeHoursStartUsal;
        opeHoursEndPrev = opeHoursEndUsal;
        opeMinutesStartPrev = opeMinutesStartUsal;
        opeMinutesEndPrev = opeMinutesEndUsal;

      }

      opeHoursStart = opeHoursStartUsal;
      opeHoursEnd = opeHoursEndUsal;
      opeMinutesStart = opeMinutesStartUsal;
      opeMinutesEnd = opeMinutesEndUsal;

      if (dayNum == 5) {

        opeHoursStartNext = opeHoursStartSat;
        opeHoursEndNext = opeHoursEndSat;
        opeMinutesStartNext = opeMinutesStartSat;
        opeMinutesEndNext = opeMinutesEndSat;

      } else {

        opeHoursStartNext = opeHoursStartUsal;
        opeHoursEndNext = opeHoursEndUsal;
        opeMinutesStartNext = opeMinutesStartUsal;
        opeMinutesEndNext = opeMinutesEndUsal;

      }

      break;

  }

  opeTimeArray = new Array();
  opeTimeArray['OpeHoursStart'] = opeHoursStart;
  opeTimeArray['OpeHoursEnd'] = opeHoursEnd;
  opeTimeArray['OpeMinutesStart'] = opeMinutesStart;
  opeTimeArray['OpeMinutesEnd'] = opeMinutesEnd;
  opeTimeArray['OpeHoursStartNext'] = opeHoursStartNext;
  opeTimeArray['OpeHoursEndNext'] = opeHoursEndNext;
  opeTimeArray['OpeMinutesStartNext'] = opeMinutesStartNext;
  opeTimeArray['OpeMinutesEndNext'] = opeMinutesEndNext;
  opeTimeArray['OpeHoursStartPrev'] = opeHoursStartPrev;
  opeTimeArray['OpeHoursEndPrev'] = opeHoursEndPrev;
  opeTimeArray['OpeMinutesStartPrev'] = opeMinutesStartPrev;
  opeTimeArray['OpeMinutesEndPrev'] = opeMinutesEndPrev;

  return opeTimeArray;

}

function setRsvYear(mode, prmDispDateTime) {

  obj = (mode == 0) ? document.getElementById(startYearId) : document.getElementById(endYearId);
  dispYearMltFlg = (mode == 0) ? dispYearMltFlgStart : dispYearMltFlgEnd;
  dateTimeLimit = (mode == 0) ? startDateTimeLimit : endDateTimeLimit;
  selectYear = (mode == 0) ? selectStartYear : selectEndYear;

  if (dispYearMltFlg) {

    while (obj.hasChildNodes()) {

      obj.removeChild(obj.firstChild);

    }

    for (i = parseInt(prmDispDateTime.getFullYear()); i <= parseInt(dateTimeLimit.getFullYear()); i++) {

      obj.options[i - parseInt(prmDispDateTime.getFullYear())] = new Option(i + '年', i);

      if (selectYear == obj.options[i - parseInt(prmDispDateTime.getFullYear())].value) {

        obj.options[i - parseInt(prmDispDateTime.getFullYear())].selected = true;

      }

    }

    if (selectYear != 9999) {

      prmDispDateTime = new Date(parseInt(obj.options[obj.selectedIndex].value), 0, 1, 0, 0, 0);
      prmDispDateTime = adjustDateTime2(prmDispDateTime);

    }

  } else {

    obj.value = prmDispDateTime.getFullYear();

  }

  return prmDispDateTime;

}

  function setRsvMonth(mode, prmDispDateTime) {

    obj = (mode == 0) ? document.getElementById(startMonthId) : document.getElementById(endMonthId);
    dateTimeLimit = (mode == 0) ? startDateTimeLimit : endDateTimeLimit;
    selectMonth = (mode == 0) ? selectStartMonth : selectEndMonth;

    while(obj.hasChildNodes())  {

      obj.removeChild(obj.firstChild);

    }

    loopLimitMonth = (prmDispDateTime.getFullYear() < dateTimeLimit.getFullYear()) ? 12 : parseInt(dateTimeLimit.getMonth()) + 1;

    for (i = parseInt(prmDispDateTime.getMonth()) + 1; i <= loopLimitMonth; i++) {

      obj.options[i - (parseInt(prmDispDateTime.getMonth()) + 1)] = new Option(addZero(i) + '月', i);

      if (selectMonth == obj.options[i - (parseInt(prmDispDateTime.getMonth()) + 1)].value) {

        obj.options[i - (parseInt(prmDispDateTime.getMonth()) + 1)].selected = true;

      }

    }

    if (selectMonth != 99) {

      prmDispDateTime = new Date(parseInt(prmDispDateTime.getFullYear()), obj.options[obj.selectedIndex].value - 1, 1, 0, 0, 0);
      prmDispDateTime = adjustDateTime2(prmDispDateTime);

    }

    return prmDispDateTime;

  }

  function setRsvDate(mode, prmDispDateTime) {

    obj = (mode == 0) ? document.getElementById(startDateId) : document.getElementById(endDateId);
    objYear = (mode == 0) ? document.getElementById(startYearId) : document.getElementById(endYearId);
    objMonth = (mode == 0) ? document.getElementById(startMonthId) : document.getElementById(endMonthId);
    dateTimeLimit = (mode == 0) ? startDateTimeLimit : endDateTimeLimit;
    selectDate = (mode == 0) ? selectStartDate : selectEndDate;

    while(obj.hasChildNodes())  {

      obj.removeChild(obj.firstChild);

    }

    if (objYear.value == parseInt(dateTimeLimit.getFullYear()) && objMonth.value == parseInt(dateTimeLimit.getMonth()) + 1) {

      startDateTimeLast = dateTimeLimit;

    } else {

      startDateTimeLast = new Date(parseInt(prmDispDateTime.getFullYear()), parseInt(prmDispDateTime.getMonth()) + 1, 0, 0, 0, 0);

    }

    for (i = parseInt(prmDispDateTime.getDate()); i <= parseInt(startDateTimeLast.getDate()); i++) {

      dateTimeForGetStrDay = new Date(prmDispDateTime.getFullYear(), prmDispDateTime.getMonth(), i, 0, 0, 0);

      strDay = getStrDay(dateTimeForGetStrDay.getDay());

      obj.options[i - parseInt(prmDispDateTime.getDate())] = new Option(addZero(i) + '日(' + strDay + ')', i);

      if (selectDate == obj.options[i - parseInt(prmDispDateTime.getDate())].value) {

        obj.options[i - parseInt(prmDispDateTime.getDate())].selected = true;

      }

    }

    if (selectDate != 99) {

      prmDispDateTime = new Date(parseInt(prmDispDateTime.getFullYear()), parseInt(prmDispDateTime.getMonth()), obj.options[obj.selectedIndex].value, 0, 0, 0);
      prmDispDateTime = adjustDateTime2(prmDispDateTime);

    }

    return prmDispDateTime;

  }

  function getStrDay(dayNum) {

    strDay = ['日', '月', '火', '水', '木', '金', '土'];

    return strDay[dayNum];

  }

  function setRsvHours(mode, prmDispDateTime, prmDispDateTimeOrg) {

    obj = (mode == 0) ? document.getElementById(startHoursId) : document.getElementById(endHoursId);
    selectHours = (mode == 0) ? selectStartHours : selectEndHours;

    while(obj.hasChildNodes())  {

      obj.removeChild(obj.firstChild);

    }

    j = 0;

    datePrev24 = new Date(prmDispDateTime.getFullYear(), prmDispDateTime.getMonth(), prmDispDateTime.getDate(), 0, 0, 0);

    if (opeHoursStart != 0 && opeHoursEndPrev == 24 && prmDispDateTimeOrg.getTime() <= datePrev24.getTime() && prmDispDateTimeOrg.getTime() >= startDateTime.getTime()) {

      obj.options[j] = new Option(addZero(j) + '時', j);
      j++;

    }

    for (i = parseInt(prmDispDateTime.getHours()); i <= opeHoursEnd; i++) {

      if (i != 24) {

        obj.options[i - parseInt(prmDispDateTime.getHours()) + j] = new Option(addZero(i) + '時', i);

        if (selectHours == obj.options[i - parseInt(prmDispDateTime.getHours()) + j].value) {

          obj.options[i - parseInt(prmDispDateTime.getHours()) + j].selected = true;

        }

      }

    }

    if (selectHours != 99) {

      prmDispDateTime = new Date(parseInt(prmDispDateTime.getFullYear()), parseInt(prmDispDateTime.getMonth()), parseInt(prmDispDateTime.getDate()), obj.options[obj.selectedIndex].value, 0, 0);
      prmDispDateTime = adjustDateTime2(prmDispDateTime);

    }

    return prmDispDateTime;

  }

  function setRsvMinutes(mode, prmDispDateTime) {

    obj = (mode == 0) ? document.getElementById(startMinutesId) : document.getElementById(endMinutesId);
    objHours = (mode == 0) ? document.getElementById(startHoursId) : document.getElementById(endHoursId);
    selectMinutes = (mode == 0) ? selectStartMinutes : selectEndMinutes;

    while (obj.hasChildNodes()) {

      obj.removeChild(obj.firstChild);

    }

    j = 0;

    if (parseInt(prmDispDateTime.getMinutes()) == 1) {

      startMinutes = 0;

    } else {

      startMinutes = parseInt(prmDispDateTime.getMinutes());

    }

    for (i = startMinutes; i < 60; i = i + timeSpan) {

      if (i == 0) {

        obj.options[j] = new Option(addZero(i) + '分', i);

        if (selectMinutes == obj.options[j].value) {

          obj.options[j].selected = true;

        }

        j++;

      } else {

        if (prmDispDateTime.getHours() == opeHoursEnd || (opeHoursEndPrev == 24 && opeHoursStart != 0 && objHours.value == 0)) {

          if (i <= opeMinutesEnd) {

            obj.options[j] = new Option(addZero(i) + '分', i);

            if (selectMinutes == obj.options[j].value) {

              obj.options[j].selected = true;

            }

            j++;

          }

        } else {

          obj.options[j] = new Option(addZero(i) + '分', i);

          if (selectMinutes == obj.options[j].value) {

            obj.options[j].selected = true;

          }

          j++;

        }

      }

    }

  }

  function chgRsvDateTime(mode, chgMode, prmStartDateTimeChg) {

    prmStartDateTimeChgOrg = new Date(prmStartDateTimeChg.getFullYear(), prmStartDateTimeChg.getMonth(), prmStartDateTimeChg.getDate(), 0, 0, 0);

    prmStartDateTime = adjustDateTime2(prmStartDateTimeChg);

    prmStartDateTimePrev24 = new Date(prmStartDateTime.getFullYear(), prmStartDateTime.getMonth(), prmStartDateTime.getDate(), 0, 0, 0);

    if (prmStartDateTimePrev24.getTime() == prmStartDateTimeOrg.getTime()) {

      prmStartDateTimeChgOrg.setTime(prmStartDateTimeOrg.getTime());

    }

    switch (chgMode) {

      case 0:

        setRsvMonth(mode, prmStartDateTime);
        setRsvDate(mode, prmStartDateTime);
        setRsvHours(mode, prmStartDateTime, prmStartDateTimeChgOrg);
        setRsvMinutes(mode, prmStartDateTime);
        break;

      case 1:

        prmStartDateTime = setRsvDate(mode, prmStartDateTime);
        prmStartDateTime = setRsvHours(mode, prmStartDateTime, prmStartDateTimeChgOrg);
        setRsvMinutes(mode, prmStartDateTime);
        break;

      case 2:

        prmStartDateTime = setRsvHours(mode, prmStartDateTime, prmStartDateTimeChgOrg);
        setRsvMinutes(mode, prmStartDateTime);
        break;

      case 3:

        setRsvMinutes(mode, prmStartDateTime);
        break;

      default:

        return false;
        break;

    }

  }

  function chgRsvYear(mode) {

    obj = (mode == 0) ? document.getElementById(startYearId) : document.getElementById(endYearId);
    dateTimeLimit = (mode == 0) ? startDateTimeLimit : endDateTimeLimit;

    startDateTimeChg = new Date(obj.value, 0, 1, 0, 0, 0);

    day = startDateTimeChg.getDay();

    opeTimePrmArray = new Array();
    opeTimePrmArray = getOpeTime(day);

    if (mode == 0) {

      selectStartYear = parseInt(startDateTimeChg.getFullYear());
      selectStartMonth = parseInt(startDateTimeChg.getMonth()) + 1;
      selectStartDate = parseInt(startDateTimeChg.getDate());
      selectStartHours = parseInt(startDateTimeChg.getHours());
      selectStartMinutes = parseInt(startDateTimeChg.getMinutes());

    } else {

      selectEndYear = parseInt(startDateTimeChg.getFullYear());
      selectEndMonth = parseInt(startDateTimeChg.getMonth()) + 1;
      selectEndDate = parseInt(startDateTimeChg.getDate());
      selectEndHours = parseInt(startDateTimeChg.getHours());
      selectEndMinutes = parseInt(startDateTimeChg.getMinutes());

    }

    chgRsvDateTime(mode, 0, startDateTimeChg);

  }

  function chgRsvMonth(mode) {

    obj = (mode == 0) ? document.getElementById(startMonthId) : document.getElementById(endMonthId);
    objYear = (mode == 0) ? document.getElementById(startYearId) : document.getElementById(endYearId);
    dateTimeLimit = (mode == 0) ? startDateTimeLimit : endDateTimeLimit;

    startDateTimeChg = new Date(objYear.value, obj.value - 1, 1, 0, 0, 0);

    day = startDateTimeChg.getDay();

    opeTimePrmArray = new Array();
    opeTimePrmArray = getOpeTime(day);

    if (mode == 0) {

      selectStartYear = parseInt(startDateTimeChg.getFullYear());
      selectStartMonth = parseInt(startDateTimeChg.getMonth()) + 1;
      selectStartDate = parseInt(startDateTimeChg.getDate());
      selectStartHours = parseInt(startDateTimeChg.getHours());
      selectStartMinutes = parseInt(startDateTimeChg.getMinutes());

    } else {

      selectEndYear = parseInt(startDateTimeChg.getFullYear());
      selectEndMonth = parseInt(startDateTimeChg.getMonth()) + 1;
      selectEndDate = parseInt(startDateTimeChg.getDate());
      selectEndHours = parseInt(startDateTimeChg.getHours());
      selectEndMinutes = parseInt(startDateTimeChg.getMinutes());

    }

    chgRsvDateTime(mode, 1, startDateTimeChg);

  }

  function chgRsvDate(mode) {

    obj = (mode == 0) ? document.getElementById(startDateId) : document.getElementById(endDateId);
    objYear = (mode == 0) ? document.getElementById(startYearId) : document.getElementById(endYearId);
    objMonth = (mode == 0) ? document.getElementById(startMonthId) : document.getElementById(endMonthId);
    dateTimeLimit = (mode == 0) ? startDateTimeLimit : endDateTimeLimit;

    startDateTimeChg = new Date(objYear.value, objMonth.value - 1, obj.value, 0, 0, 0);

    day = startDateTimeChg.getDay();

    opeTimePrmArray = new Array();
    opeTimePrmArray = getOpeTime(day);

    if (mode == 0) {

      selectStartYear = parseInt(startDateTimeChg.getFullYear());
      selectStartMonth = parseInt(startDateTimeChg.getMonth()) + 1;
      selectStartDate = parseInt(startDateTimeChg.getDate());
      selectStartHours = parseInt(startDateTimeChg.getHours());
      selectStartMinutes = parseInt(startDateTimeChg.getMinutes());

    } else {

      selectEndYear = parseInt(startDateTimeChg.getFullYear());
      selectEndMonth = parseInt(startDateTimeChg.getMonth()) + 1;
      selectEndDate = parseInt(startDateTimeChg.getDate());
      selectEndHours = parseInt(startDateTimeChg.getHours());
      selectEndMinutes = parseInt(startDateTimeChg.getMinutes());

    }

    chgRsvDateTime(mode, 2, startDateTimeChg);

  }

  function chgRsvHours(mode) {

    obj = (mode == 0) ? document.getElementById(startHoursId) : document.getElementById(endHoursId);
    objYear = (mode == 0) ? document.getElementById(startYearId) : document.getElementById(endYearId);
    objMonth = (mode == 0) ? document.getElementById(startMonthId) : document.getElementById(endMonthId);
    objDate = (mode == 0) ? document.getElementById(startDateId) : document.getElementById(endDateId);
    dateTimeLimit = (mode == 0) ? startDateTimeLimit : endDateTimeLimit;

    startDateTimeChg = new Date(objYear.value, objMonth.value - 1, objDate.value, obj.value, 0, 0);

    day = startDateTimeChg.getDay();

    opeTimePrmArray = new Array();
    opeTimePrmArray = getOpeTime(day);

    if (mode == 0) {

      selectStartYear = parseInt(startDateTimeChg.getFullYear());
      selectStartMonth = parseInt(startDateTimeChg.getMonth()) + 1;
      selectStartDate = parseInt(startDateTimeChg.getDate());
      selectStartHours = parseInt(startDateTimeChg.getHours());
      selectStartMinutes = parseInt(startDateTimeChg.getMinutes());

    } else {

      selectEndYear = parseInt(startDateTimeChg.getFullYear());
      selectEndMonth = parseInt(startDateTimeChg.getMonth()) + 1;
      selectEndDate = parseInt(startDateTimeChg.getDate());
      selectEndHours = parseInt(startDateTimeChg.getHours());
      selectEndMinutes = parseInt(startDateTimeChg.getMinutes());

    }

    chgRsvDateTime(mode, 3, startDateTimeChg);

  }

  function addZero(tgtNum) {

    tgtNum = '0' + tgtNum.toString();
    tgtNum = tgtNum.substr(tgtNum.length - 2, 2);
    return tgtNum;

  }

