var now    = new Date()
var Opera=!!window.opera
var winflg=1
var calendarwin
var minmonth=0 // 最大表示過去月（xヶ月前 0：当月）
var maxmonth=11 // 最大表示未来月（xヶ月後）

function wrtCalendar(oj,arg1){

  if(Opera)return
//  oj.blur()

  if(!arguments[1])arg1=0
  if(arguments[1]||arguments[1]==0)winflg=0

  if(arg1==0){
    now = new Date()
    monthcnt = 0
  }
 
  // 表示月判定用
  monthcnt+=  arg1 

  // 年月日取得
  nowdate  = now.getDate()
  nowmonth = now.getMonth()
  nowyear  = now.getFullYear()

  // 月移動処理
  if(nowmonth==11 && arg1 > 0){        //12月でarg1が+なら
    nowmonth = -1 + arg1 ; nowyear++   //月はarg1-1;1年加算
  } else if(nowmonth==0 && arg1 < 0){  //1月でarg1が-なら
    nowmonth = 12 + arg1 ; nowyear--   //月はarg1+12;1年減算
  } else {
    nowmonth +=  arg1                  //2-11月なら月は+arg1
  }

  // 現在月を確定
  now   = new Date(nowyear,nowmonth,1)

  // YYYYMM作成
  nowyyyymm=nowyear*100+nowmonth

  //-カレンダー構築用基準日の取得
  fstday   = now                                           //今月の1日
  startday = fstday - ( fstday.getDay() * 1000*60*60*24 )  //最初の日曜日
  startday = new Date(startday)

  //-カレンダー構築用HTML
  ddata = ''
  ddata += '<HTML>\n'
  ddata += '<HEAD>'
  ddata += '<meta http-equiv="Content-Type" content="text/html;charset=SHIFT_JIS">\n'
  ddata += '<TITLE>ANA SKY WEB</TITLE>\n'
  ddata += '<style type=text/css>\n'
  ddata += '<!--\n'

  ddata += ' .sun{font-size:12px;color:#333333;background:#FFCECF}\n'
  ddata += ' .sat{font-size:12px;color:#333333;background:#CEE1FF}\n'
  ddata += ' .wek{font-size:12px;color:#333333;background:#ffffff}\n'
  ddata += ' a{text-decoration:none; color:#000000;}\n'
  ddata += ' body {color:#000000;font-size:x-small;}\n'
  ddata += ' td {color:#000000;font-size:x-small;font-family:"ＭＳ Ｐゴシック","Osaka";}\n'

  ddata += '//-->\n'
  ddata += '</style>\n'
  ddata += '</HEAD>\n'
  ddata += '<BODY>\n'

  ddata += '<center>\n'
  ddata += '<table width=170 height=56 border=0 cellspacing=2>\n'
  ddata += '<tr>\n'

  if(monthcnt == minmonth){
    // 過去月遷移制御
    ddata += ' <td height=20 width=20 align=left><font color=#CCCCCC>&lt;&lt;</font></td>\n'
  } else {
    ddata += ' <td height=20 width=20 align=left><a href="javascript:self.opener.wrtCalendar(self.opener.document.'+oj.form.name+'.'+oj.name+',-1);">&lt;&lt;</a></td>\n'
  }
  ddata += ' <td colspan=5></td>\n'
  
  if(monthcnt == maxmonth){
    // 未来月遷移制御
    ddata += ' <td height=20 width=20 align=right><font color=#CCCCCC>&gt;&gt;</font></a></td>\n'
  } else {
    ddata += ' <td height=20 width=20 align=right><a href="javascript:self.opener.wrtCalendar(self.opener.document.'+oj.form.name+'.'+oj.name+',1);">&gt;&gt;</a></td>\n'
  }

  ddata += '</tr>\n'
  ddata += '<tr align=center>\n'
  ddata += ' <td width=170 height=16 colspan=7 bgcolor=#999999><font color=#FFFFFF> '+nowyear+' 年 '+(nowmonth + 1)+' 月 </font></td>\n'
  ddata += '</tr>\n'

  ddata += '<tr align=center>\n'
  ddata += ' <td width=20 height=20 class=sun>日</td>\n'
  ddata += ' <td width=20 height=20 class=wek>月</td>\n'
  ddata += ' <td width=20 height=20 class=wek>火</td>\n'
  ddata += ' <td width=20 height=20 class=wek>水</td>\n'
  ddata += ' <td width=20 height=20 class=wek>木</td>\n'
  ddata += ' <td width=20 height=20 class=wek>金</td>\n'
  ddata += ' <td width=20 height=20 class=sat>土</td>\n'
  ddata += '</tr>\n'

  ddata += '<tr height=1 bgcolor=#999999>\n'
  ddata += ' <td colspan=7></td>\n'
  ddata += '</tr>\n'
  ddata += '</table>\n'

  ddata += '<table width=170 height=130 border=0 cellspacing=2>\n'

  for(j=0;j<6;j++){
    ddata += '<tr align=center>\n'
    for(i=0;i<7;i++){
      nextday = startday.getTime() + (i * 1000*60*60*24)
      wrtday  = new Date(nextday)

      wrtdate = wrtday.getDate()
      wrtmonth= wrtday.getMonth()
      wrtyear = wrtday.getYear()
      if(wrtyear < 1900)wrtyear=1900 + wrtyear
      wrtyyyymm = wrtyear * 100 + wrtmonth
      wrtyyyymmdd= ''+wrtyear +'/'+ (wrtmonth+1) +'/'+wrtdate

      // 祝日チェック
      getholiday  = ktHolidayName(wrtyyyymmdd)

      if(wrtyyyymm != nowyyyymm){
        // 対象月以外
        ddata += ' <td width=20 height=24></td>\n'
      } else {
        if(getholiday == ''){ 
          switch(i){
            case 0: 
              ddata += ' <td width=20 height=24 class=sun>\n'
              break
            case 6: 
              ddata += ' <td width=20 height=24 class=sat>\n'
              break
            default: ddata += ' <td width=20 height=24 class=wek>\n'
          }
        } else {
          // 祝日表示
          ddata += ' <td width=20 height=24 class=sun>\n'
        }

        ddata += '  <a href="javascript:opener.setDateFromCal('+(wrtmonth+1)+','+wrtdate+');window.close();"> '+wrtdate+' </a>\n'
        ddata += ' </td>\n'
      } 
    }
    ddata += '</tr>\n'

    startday = new Date(nextday)
    startday = startday.getTime() + (1000*60*60*24)
    startday = new Date(startday)
  }

  ddata += '<tr height=1 bgcolor=#999999>\n'
  ddata += ' <td colspan=7></td>\n'
  ddata += '</tr>\n'
  ddata += '<tr>\n'
  ddata += ' <td colspan=7 align=center valign=middle>\n'
  ddata += '   <input type=button value="閉じる ×" onClick="self.close()">\n'
  ddata += ' </td>\n'
  ddata += '</tr>\n'
  ddata += '</table>\n'
  ddata += '</center>\n'
  ddata += '</BODY>\n'
  ddata += '</HTML>\n'

  // ウインドウOPEN
  calendarwin=window.open('','calendar','width=200,height=280,status=no,scrollbars=no,resizable=yes');
  calendarwin.document.write(ddata)
  calendarwin.document.close()
  calendarwin.focus()

  winflg=1
}


//===============================================================
// 祝日判定
//===============================================================
<!--

MONDAY = 1;
TUESDAY = 2;
WEDNESDAY = 3;

cstShowaTaiso = new Date("1989/2/24");                // 昭和天皇大喪の礼
cstNorihitoKekkon = new Date("1993/6/9");            // 徳仁親王の結婚の儀
cstSokuireiseiden = new Date("1990/11/12");          // 即位礼正殿の儀
cstImplementHoliday = new Date("1973/4/12");        // 振替休日施行

// [prmDate]には "yyyy/m/d"形式の日付文字列を渡す
function ktHolidayName(prmDate)
{
  MyDate = new Date(prmDate);
  HolidayName = prvHolidayChk(MyDate);
  if (HolidayName == "") {
      if (MyDate.getDay() == MONDAY) {
          // 月曜以外は振替休日判定不要
          // 5/6(火,水)の判定はprvHolidayChkで処理済
          // 5/6(月)はここで判定する
          if (MyDate.getTime() >= cstImplementHoliday.getTime()) {
              YesterDay = new Date(MyDate.getFullYear(),
                                     MyDate.getMonth(),(MyDate.getDate()-1));
              HolidayName = prvHolidayChk(YesterDay);
              if (HolidayName != "") {
                  HolidayName_ret = "振替休日";
              } else {
                  HolidayName_ret = "";
              }
          } else {
              HolidayName_ret = "";
          }
      } else {
          HolidayName_ret = "";
      }
  } else {
      HolidayName_ret = HolidayName;
  }

  return HolidayName_ret;
}

function prvHolidayChk(MyDate)
{
  MyYear = MyDate.getFullYear();
  MyMonth = MyDate.getMonth() + 1;    // MyMonth:1～12
  MyDay = MyDate.getDate();

  Result = "";
  switch (MyMonth) {
// １月 //
  case 1:
      if (MyDay == 1) {
          Result = "元日";
      } else {
          if (MyYear >= 2000) {
              NumberOfWeek = Math.floor((MyDay - 1) / 7) + 1;
              if ((NumberOfWeek == 2) && (MyDate.getDay() == MONDAY)) {
                  Result = "成人の日";
              } else;
          } else {
              if (MyDay == 15) {
                  Result = "成人の日";
              } else;
          }
      }
      break;
// ２月 //
  case 2:
      if (MyDay == 11) {
          if (MyYear >= 1967) {
              Result = "建国記念の日";
          } else;
      } else {
          if (MyDate.getTime() == cstShowaTaiso.getTime()) {
              Result = "昭和天皇の大喪の礼";
          } else;
      }
      break;
// ３月 //
  case 3:
      if (MyYear <= 1979) {
          SpringEquinox = Math.floor(20.8357 + 
            (0.242194 * (MyYear - 1980)) - Math.floor((MyYear - 1980) / 4));
      } else {
          if (MyYear <= 2099) {
              SpringEquinox = Math.floor(20.8431 + 
                (0.242194 * (MyYear - 1980)) - Math.floor((MyYear - 1980) / 4));
          } else {
              SpringEquinox = Math.floor(21.851 + 
                (0.242194 * (MyYear - 1980)) - Math.floor((MyYear - 1980) / 4));
          }
      }
      if (MyDay == SpringEquinox) {  
          Result = "春分の日"; 
      } else;
      break;
// ４月 //
  case 4:
      if (MyDay == 29) {
          if (MyYear >= 2007) {
              Result = "昭和の日";
          } else {
              if (MyYear >= 1989) {
                  Result = "みどりの日";
              } else {
                Result = "天皇誕生日";
              }
          }
      } 
      break;
// ５月 //
  case 5:
      switch ( MyDay ) {
        case 3:  // ５月３日
          Result = "憲法記念日";
          break;
        case 4:  // ５月４日
          if (MyYear >= 2007) {
              Result = "みどりの日";
          } else {
              if (MyYear >= 1986) {
                  if (MyDate.getDay() > MONDAY) {
                  // 5/4が日曜日は『只の日曜』､月曜日は『憲法記念日の振替休日』(～2006年)
                      Result = "国民の休日";
                  } else;
              } else;
          }
          break;
        case 5:  // ５月５日
          Result = "こどもの日";
          break;
        case 6:  // ５月６日
          if (MyYear >= 2007) {
              if ((MyDate.getDay() == TUESDAY) || (MyDate.getDay() == WEDNESDAY)) {
                  Result = "振替休日";    // [5/3,5/4が日曜]ケースのみ、ここで判定
              } else;
          } else;
          break;
      }
      break;
// ６月 //
  case 6:
      if (MyDate.getTime() == cstNorihitoKekkon.getTime()) {
          Result = "皇太子徳仁親王の結婚の儀";
      } else;
      break;
// ７月 //
  case 7:
      if (MyYear >= 2003) {
          NumberOfWeek = Math.floor((MyDay - 1) / 7) + 1;
          if ((NumberOfWeek == 3) && (MyDate.getDay() == MONDAY)) {
              Result = "海の日";
          } else;
      } else {
          if (MyYear >= 1996) {
              if (MyDay == 20) {
                  Result = "海の日";
              } else;
          } else;
      }
      break;
// ９月 //
  case 9:
      //第３月曜日(15～21)と秋分日(22～24)が重なる事はない
      if (MyYear <= 1979) {
          MyAutumnEquinox = Math.floor(23.2588 + 
            (0.242194 * (MyYear - 1980)) - Math.floor((MyYear - 1980) / 4));
      } else {
          if (MyYear <= 2099) {
              MyAutumnEquinox = Math.floor(23.2488 + 
                (0.242194 * (MyYear - 1980)) - Math.floor((MyYear - 1980) / 4));
          } else {
              MyAutumnEquinox = Math.floor(24.2488 + 
                (0.242194 * (MyYear - 1980)) - Math.floor((MyYear - 1980) / 4));
          }
      }
      if (MyDay == MyAutumnEquinox) {    
          Result = "秋分の日";           

      } else {
          if (MyYear >= 2003) {
              NumberOfWeek = Math.floor((MyDay - 1) / 7) + 1;
              if ((NumberOfWeek == 3) && (MyDate.getDay() == MONDAY)) {
                  Result = "敬老の日";
              } else {
                  if (MyDate.getDay() == TUESDAY) {
                      if (MyDay == (MyAutumnEquinox - 1)) {
                          Result = "国民の休日";
                      } else;
                  } else;
              }
          } else {
              if (MyYear >= 1966) {
                  if (MyDay == 15) {
                      Result = "敬老の日";
                  } else;
              } else;
          }
      }
      break;
// １０月 //
  case 10:
      if (MyYear >= 2000) {
          NumberOfWeek = Math.floor(( MyDay - 1) / 7) + 1;
          if ((NumberOfWeek == 2) && (MyDate.getDay() == MONDAY)) {
              Result = "体育の日";
          } else;
      } else {
          if (MyYear >= 1966) {
              if (MyDay == 10) {
                  Result = "体育の日";
              } else;
          } else;
      }
      break;
// １１月 //
  case 11:
      if (MyDay == 3) {
          Result = "文化の日";
      } else {
          if (MyDay == 23) {
              Result = "勤労感謝の日";
          } else {
              if (MyDate.getTime() == cstSokuireiseiden.getTime()) {
                  Result = "即位礼正殿の儀";
              } else;
          }
      }
      break;
// １２月 //
  case 12:
      if (MyDay == 23) {
          if (MyYear >= 1989) {
              Result = "天皇誕生日";
          } else;
      } else;
      break;
  }

  return Result;
}
//-->


