'---------------------------------------------------------------------------------------------------
' ¿ë    µµ : ½ÃÀå ÄÚ¸àÆ® ´Þ·Â ÃÊ±âÈ­
' ÆÄ¶ó¹ÌÅÍ : strDate - ³¯Â¥
' ¸®    ÅÏ : ¾øÀ½
'---------------------------------------------------------------------------------------------------
Sub fnSetCalendar(strDate)
  Dim strBuff      'ÀÓ½Ã ¹®ÀÚ¿­ º¯¼ö
  Dim strLastDay   'ÆÄ¶ó¹ÌÅÍ·Î ³Ñ¾î¿Â ¿ùÀÇ ¸¶Áö¸· ÀÏ
  Dim nDifference  'ÀÏ¿äÀÏ°ú ÆÄ¶ó¹ÌÅÍ·Î ³Ñ¾î¿Â ¿ùÀÇ 1ÀÏ¿¡ ÇØ´çµÇ´Â ¿äÀÏ°úÀÇ Â÷ÀÌ
  Dim i            'Loop º¯¼ö
  
  '// ÆÄ¶ó¹ÌÅÍ·Î ³Ñ¾î¿Â ³¯Â¥¸¦ "YYYY/MM/01" Çü½ÄÀ¸·Î ¸¸µç´Ù
  strDate = Left(strDate, 4) & "/" & Mid(strDate, 5, 2) & "/01"
  
  '// ÆÄ¶ó¹ÌÅÍ·Î ³Ñ¾î¿Â ¿ùÀÇ ¸¶Áö¸· ÀÏÀÚ¸¦ ¾ò´Â´Ù
  strBuff = Left(DateAdd("m", 1, strDate), 7) & "/01"  '´ÙÀ½´ÞÀÇ Ã¹³¯À» ±¸ÇÑ´Ù
  strBuff = DateAdd("d", -1, strBuff)  'ÇÏ·çÀü ³¯Â¥¸¦ ±¸ÇÑ´Ù
  strLastDay = Right(strBuff, 2)  '±¸ÇÑ ³¯Â¥´Â ÆÄ¶ó¹ÌÅÍ·Î ³Ñ¾î¿Â ¿ùÀÇ ¸¶Áö¸· ³¯Â¥ÀÎµ¥
                                  '¿ùÀÇ ÀÏ¼ö¸¦ ¾ò±âÀ§ÇØ ÀÏ µÎÀÚ¸® ¸¸À» ¾ò´Â´Ù
  
  '// ÀÏ¿äÀÏ°ú ÆÄ¶ó¹ÌÅÍ·Î ³Ñ¾î¿Â ¿ùÀÇ 1ÀÏ¿¡ ÇØ´çµÇ´Â ¿äÀÏ°úÀÇ Â÷ÀÌ¸¦ ±¸ÇÑ´Ù
  nDifference = Weekday(strDate) - 1
  
  '// ***** ÆÄ¶ó¹ÌÅÍ·Î ³Ñ¾î¿Â ³âµµ¿Í ¿ù¿¡ ÇØ´çµÇ´Â ´Þ·ÂÀ» ¸¸µç´Ù **************************************
  '// ´Þ·Â¿¡ ÇØ´ç ³âµµ¿Í ¿ùÀ» Ç¥½ÃÇÑ´Ù
  tdDate.innerText = " " & Left(strDate, 4) & "³â " & Mid(strDate, 6, 2) & "¿ù"
  
  '// ÀÏÀÚ¸¦ Ãâ·ÂÇÑ´Ù
  For i = 1 To CInt(strLastDay)
    tdDay(nDifference + i - 1).innerText = CStr(i)
    
    If (nDifference + i - 1) Mod 7 <> 0 And (nDifference + i - 1) Mod 7 <> 6 Then
      tdDay(nDifference + i - 1).style.cursor = "hand"
    End If
  Next
End Sub

'---------------------------------------------------------------------------------------------------
' ¿ë    µµ : ÇöÀç¿ù¿¡¼­ ¿ù Áõ°¡Ä¡ ¸¸Å­ ´õÇØÁø ´ÞÀÇ Ã¹ ³¯Â¥¸¦ ±¸ÇÑ´Ù
' ÆÄ¶ó¹ÌÅÍ : strDate - ³¯Â¥, nDifference - ¿ù Áõ°¡Ä¡
' ¸®    ÅÏ : ¾øÀ½
'---------------------------------------------------------------------------------------------------
Function fnGetAddedDate(strDate, nDifference)
  '// ÆÄ¶ó¹ÌÅÍ·Î ³Ñ¾î¿Â ³¯Â¥¸¦ "YYYY/MM/01" Çü½ÄÀ¸·Î ¸¸µç´Ù
  strDate = Left(strDate, 4) & "/" & Mid(strDate, 5, 2) & "/01"
  
  '// ¿ù Áõ°¡Ä¡¿¡ ÇØ´çµÇ´Â ³¯Â¥(YYYYMM01)¸¦ ¸¸µç´Ù
  strDate = Left(DateAdd("m", nDifference, strDate), 7) & "01"
  strDate = Left(strDate, 4) & Mid(strDate, 6, 2) & "01"
  
  fnGetAddedDate = strDate
End Function

'---------------------------------------------------------------------------------------------------
' ¿ë    µµ : ÇöÀç¿ù¿¡¼­ ¿ù Áõ°¡Ä¡ ¸¸Å­ ´õÇØÁø ³¯Â¥¸¦ ±¸ÇÑ´Ù
' ÆÄ¶ó¹ÌÅÍ : strDate - ³¯Â¥, nDifference - ¿ù Áõ°¡Ä¡
' ¸®    ÅÏ : ¾øÀ½
'---------------------------------------------------------------------------------------------------
Function fnAddMonth(strDate, nDifference)
  '// ÆÄ¶ó¹ÌÅÍ·Î ³Ñ¾î¿Â ³¯Â¥¸¦ "YYYY/MM/DD" Çü½ÄÀ¸·Î ¸¸µç´Ù
  strDate = Left(strDate, 4) & "/" & Mid(strDate, 5, 2) & "/" & Right(strDate, 2)
  
  '// ¿ù Áõ°¡Ä¡¿¡ ÇØ´çµÇ´Â ³¯Â¥(YYYYMMDD)¸¦ ¸¸µç´Ù
  strDate = DateAdd("m", nDifference, strDate)
  strDate = DateAdd("d", 1, strDate)
  strDate = Left(strDate, 4) & Mid(strDate, 6, 2) & Right(strDate, 2)
  
  fnAddMonth = strDate
End Function

