sub window_onload()
  setCalendarBody now()
end sub

function setCalendarBody(theDate)
if not isdate(thedate) then theDate=now()
dim NowYear,NowMonth,NowDay,MonthEndDay,FirstDaysWeek,calendarIndex1,calendarIndex2,calendarIndex3
  NowYear=year(theDate): NowMonth=month(theDate): NowDay=day(theDate)
  select case NowMonth
    case 2 MonthEndDay=28: if NowYear mod 4 = 0 then MonthEndDay=29
    case 4,6,9,11 MonthEndDay=30
    case 1,3,5,7,8,10,12 MonthEndDay=31
  end select
FirstDaysWeek=weekday(NowYear & "-" & NowMonth & "-" & "1")
dim calendarBody
calendarBody = "<table class=""calendar"" width=""100%"" cellpadding=""0"" cellspacing=""0"" border=""0"" style=""border-bottom:1px dashed #CCCCBB;""><tr><td width=""21"" align=""center"">" & vbcrlf
calendarBody = calendarBody & "<img src=""images/calendar/sider_calendar.gif"" width=""21"" height=""14"" style=""margin-left:3px;cursor:hand;"" title=""返回今日"" onClick=""vbscript:setCalendarBody now"">" & vbcrlf
calendarBody = calendarBody & "</td><td style=""color:black;"" align=""center"">" & vbcrlf
calendarBody = calendarBody & "<img id=""beforeYear0"" onmouseover=""javascript:this.style.display='none';beforeYear1.style.display='';"" src=""images/calendar/beforeYear0.gif"" title=""上一年"" style=""border:none;width:9px;height:9px;cursor:hand;margin-right:3px;"">"
calendarBody = calendarBody & "<img id=""beforeYear1"" onclick=""vbscript:goBeforeYear '" & NowYear & "-" & NowMonth & "-" & NowDay & "'"" onmouseout=""javascript:this.style.display='none';beforeYear0.style.display='';"" src=""images/calendar/beforeYear1.gif"" title=""上一年"" style=""border:none;width:9px;height:9px;cursor:hand;display:none;margin-right:3px;"">"
calendarBody = calendarBody & "<img id=""beforeMonth0"" onmouseover=""javascript:this.style.display='none';beforeMonth1.style.display='';"" src=""images/calendar/beforeMonth0.gif"" title=""上一月"" style=""border:none;width:5px;height:9px;cursor:hand;"">"
calendarBody = calendarBody & "<img id=""beforeMonth1"" onclick=""vbscript:goBeforeMonth '" & NowYear & "-" & NowMonth & "-" & NowDay & "'"" onmouseout=""javascript:this.style.display='none';beforeMonth0.style.display='';"" src=""images/calendar/beforeMonth1.gif"" title=""上一月"" style=""border:none;width:5px;height:9px;cursor:hand;display:none;"">" & vbcrlf
calendarBody = calendarBody & "<b>" & NowYear & "年" & NowMonth & "月" & NowDay & "日</b>" & vbcrlf
calendarBody = calendarBody & "<img id=""nextMonth0"" onmouseover=""javascript:this.style.display='none';nextMonth1.style.display='';"" src=""images/calendar/nextMonth0.gif"" title=""下一月"" style=""border:none;width:5px;height:9px;cursor:hand;"">"
calendarBody = calendarBody & "<img id=""nextMonth1"" onclick=""vbscript:goNextMonth '" & NowYear & "-" & NowMonth & "-" & NowDay & "'"" onmouseout=""javascript:this.style.display='none';nextMonth0.style.display='';"" src=""images/calendar/nextMonth1.gif"" title=""下一月"" style=""border:none;width:5px;height:9px;cursor:hand;display:none;"">"
calendarBody = calendarBody & "<img id=""nextYear0"" onmouseover=""javascript:this.style.display='none';nextYear1.style.display='';"" src=""images/calendar/nextYear0.gif"" title=""下一年"" style=""border:none;width:9px;height:9px;cursor:hand;margin-left:3px;"">"
calendarBody = calendarBody & "<img id=""nextYear1"" onclick=""vbscript:goNextYear '" & NowYear & "-" & NowMonth & "-" & NowDay & "'"" onmouseout=""javascript:this.style.display='none';nextYear0.style.display='';"" src=""images/calendar/nextYear1.gif"" title=""下一年"" style=""border:none;width:9px;height:9px;cursor:hand;display:none;margin-left:3px;"">" & vbcrlf
calendarBody = calendarBody & "</td></tr></table>" & vbcrlf
calendarBody = calendarBody & "</td></tr>" & vbcrlf
calendarBody = calendarBody & "<tr><td background=""images/bg_16.gif"" bgcolor=""white"" style=""padding:3px;"">" & vbcrlf

calendarBody = calendarBody & "<table class=""calendar"" height=""16"" border=""0""><tr>" & vbcrlf
calendarBody = calendarBody & "<td class=""calendarWeek"" style=""color:red;"">日</td>" & vbcrlf
calendarBody = calendarBody & "<td class=""calendarWeek"">一</td>" & vbcrlf
calendarBody = calendarBody & "<td class=""calendarWeek"">二</td>" & vbcrlf
calendarBody = calendarBody & "<td class=""calendarWeek"">三</td>" & vbcrlf
calendarBody = calendarBody & "<td class=""calendarWeek"">四</td>" & vbcrlf
calendarBody = calendarBody & "<td class=""calendarWeek"">五</td>" & vbcrlf
calendarBody = calendarBody & "<td class=""calendarWeek"">六</td>" & vbcrlf
calendarBody = calendarBody & "</tr></table>" & vbcrlf

calendarBody = calendarBody & "<table class=""calendarTab"" onselectstart=""return false;"" background=""images/calendar/" & month(theDate) & ".gif"">" & vbcrlf
calendarIndex1=0
do while calendarIndex1<MonthEndDay
  calendarBody = calendarBody & "<tr>" & vbcrlf
  for calendarIndex2 = 1 to 7
    calendarIndex3=calendarIndex3+1
    if calendarIndex3>=FirstDaysWeek then
      if calendarIndex1<MonthEndDay then
         calendarIndex1=calendarIndex1+1
        if calendarIndex1=NowDay then
          calendarBody = calendarBody & "<td class=""calendarDay"" style=""color:green;background-image:url(images/calendar/bg_today.gif);"">" & calendarIndex1 & "</td>" & vbcrlf
        elseif calendarIndex2 = 1 then
          calendarBody = calendarBody & "<td class=""calendarDay"" style=""color:red;"">" & calendarIndex1 & "</td>" & vbcrlf
        else
          calendarBody = calendarBody & "<td class=""calendarDay"">" & calendarIndex1 & "</td>" & vbcrlf
        end if
      else
      calendarBody = calendarBody & "<td class=""calendarDay""></td>" & vbcrlf
      end if
    else
      calendarBody = calendarBody & "<td class=""calendarDay""></td>" & vbcrlf
    end if
  next
  calendarBody = calendarBody & "</tr>" & vbcrlf
loop
calendarBody = calendarBody & "</table>"
calendarBox.innerHTML = calendarBody
end function

sub goBeforeYear(theDate)
dim tDate
  tDate=cstr(year(theDate)-1) & "-" & month(theDate) & "-" & day(theDate)
  if isdate(tDate) then
    setCalendarBody tDate
  end if
end sub
sub goNextYear(theDate)
dim tDate
  tDate=cstr(year(theDate)+1) & "-" & month(theDate) & "-" & day(theDate)
  if isdate(tDate) then
    setCalendarBody tDate
  end if
end sub

sub goBeforeMonth(theDate)
dim tDate,tDateYear,tDateMonth
  if month(theDate)=1 then
    tDateMonth=12
    tDateYear=year(theDate)-1
  else
    tDateMonth=month(theDate)-1
    tDateYear=year(theDate)
  end if
  select case tDateMonth
  case 2
    if tDateYear mod 4 > 0 then
      if day(theDate)>28 then
       tDate=tDateYear & "-" & tDateMonth & "-" & "28"
      else
        tDate=tDateYear & "-" & tDateMonth & "-" & day(theDate)
      end if
    else
      if day(theDate)>29 then
        tDate=tDateYear & "-" & tDateMonth & "-" & "29"
      else
        tDate=tDateYear & "-" & tDateMonth & "-" & day(theDate)
      end if
    end if
  case 4,6,9,11
    if day(theDate)>30 then
      tDate=tDateYear & "-" & tDateMonth & "-" & "30"
    else
      tDate=tDateYear & "-" & tDateMonth & "-" & day(theDate)
    end if
  case 1,3,5,7,8,10
    tDate=tDateYear & "-" & tDateMonth & "-" & day(theDate)
  case 12
    tDate=tDateYear & "-12-" & day(theDate)
  end select
  if isdate(tDate) then setCalendarBody tDate
end sub

sub goNextMonth(theDate)
dim tDate,tDateYear,tDateMonth
  if month(theDate)=12 then
    tDateMonth=1
    tDateYear=year(theDate)+1
  else
    tDateMonth=month(theDate)+1
    tDateYear=year(theDate)
  end if
  select case tDateMonth
  case 2
    if tDateYear mod 4 > 0 then
      if day(theDate)>28 then
       tDate=tDateYear & "-" & tDateMonth & "-" & "28"
      else
        tDate=tDateYear & "-" & tDateMonth & "-" & day(theDate)
      end if
    else
      if day(theDate)>29 then
        tDate=tDateYear & "-" & tDateMonth & "-" & "29"
      else
        tDate=tDateYear & "-" & tDateMonth & "-" & day(theDate)
      end if
    end if
  case 4,6,9,11
    if day(theDate)>30 then
      tDate=tDateYear & "-" & tDateMonth & "-" & "30"
    else
      tDate=tDateYear & "-" & tDateMonth & "-" & day(theDate)
    end if
  case 1,3,5,7,8,10
    tDate=tDateYear & "-" & tDateMonth & "-" & day(theDate)
  case 12
    tDate=tDateYear & "-12-" & day(theDate)
  end select
  if isdate(tDate) then setCalendarBody tDate
end sub