function allDay()
{
   var wrtMonth = new Array(0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
   
   if (((theYear % 4 == 0) && (theYear % 100 != 0)) || (theYear % 400 == 0)) wrtMonth[2]++;

   return wrtMonth[theMonth];
}

function showCalendar(j)
{

    theMonth += j;

    if (theMonth == 0)
    {
        theYear  -= 1;
        theMonth =  12;
    }
  
    if (theMonth == 13)
    {
        theYear  += 1;
        theMonth =  1;
    }

    theDate.setYear(theYear);
    theDate.setMonth(theMonth-1);
    theDate.setDate(1);
    theCalendar(theDate.getDay());
    
}

function theCalendar(week)
{
var Calendar = new Date();
var year = Calendar.getYear();	    // Returns year
var month = Calendar.getMonth();    // Returns month (0-11)
var today = Calendar.getDate();    // Returns day (1-31)
    var wrtDate  = new Array("日", "一", "二", "三", "四", "五", "六");
    var Dispstr;
    Dispstr =  "<table border='0' width='35%' cellspacing='0'  align='center'><tr><td width='15%' bgcolor='#C0C0C0' align='center'><a href='#'><span lang='EN-US' style='font-size: 12.0pt; font-family: Wingdings 3' onmouseover='' onclick='JavaScript: showCalendar(-1);'>t</span></a></td>";
    Dispstr = Dispstr + "<td width='70%' bgcolor='#C0C0C0' colspan='5' align='center'>" + theYear + " 年 " + theMonth + " 月</td>";
    Dispstr = Dispstr + "<td width='15%' bgcolor='#C0C0C0' align='center'><a href='#'><span lang='EN-US' style='font-size: 12.0pt; font-family: Wingdings 3' onclick='JavaScript: showCalendar(1);'>u</span></a></td><tr>";
      
    for (i=0; i<=6; i++) Dispstr = Dispstr + "<td align='center'>" + wrtDate[i] + "</td>";
    
    Dispstr += "</tr><tr><td width='100%' colspan='7'><hr></td></tr><tr>";

    for (i=1; i<=allDay()+week; i++)
    {
        if (i<=week)
        {
            Dispstr += "<td></td>";
            
        }       
         else {


                Dispstr = Dispstr + "<td align='center'><a href='/asp/entry_db.asp?c_date=" + theYear;
            
                if (theMonth < 10)  Dispstr += "0";
            
                Dispstr += theMonth;
            
                if ((i-week) < 10)  Dispstr += "0";
		if (((i-week)==today) && (theYear==year) && (theMonth==month+1) )
		{
                Dispstr = Dispstr + (i-week) + "' target='twstockboard'><div id='c" + (i-week) + "' style='font:20;color:red' onclick=setFont('c" + (i-week) + "')>" + (i-week) + "</div></a></td>";
		}
		else{
                Dispstr = Dispstr + (i-week) + "' target='twstockboard'><div id='c" + (i-week) + "' style='font:12' onclick=setFont('c" + (i-week) + "')>" + (i-week) + "</div></a></td>";
                }
          
            if ((i+7)%7==0)      Dispstr += "</tr><tr>";
        }    
    
    }
    
    Dispstr += "</tr></table>";
    
    Display.innerHTML = Dispstr
}


function setFont(obj)
{
   for (i=1; i<=allDay(); i++)
   {
       j = "c" + i;
       
       document.all(j).style.fontSize = "12";
       document.all(j).style.color    = "";
   }
   
   document.all(obj).style.fontSize = "20";
   document.all(obj).style.color    = "#FF0000";
}
