//顯示月曆
function calendar(){
today = new Date()
outDiv=""
dayNames = new Array("星期日","星期一","星期二","星期三","星期四","星期五","星期六")
monthDays = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
if (((today.getFullYear() % 4 == 0) && (today.getFullYear() % 100 != 0)) || (today.getFullYear() % 400 == 0)) monthDays[1] = 29
nDays = monthDays[today.getMonth()]
firstDay = new Date()
firstDay.setDate(1)
testMe = firstDay.getDate()
if (testMe == 2) firstDay.setDate(0)
startDay = firstDay.getDay();
outDiv='<table class="mtable" id="myTable" border="1" cellspacing="1" cellpadding="2" >'
outDiv+='<tr id="tr1" class="tr1"><th colspan="7">'
outDiv+="西元" + " " + today.getFullYear() + "年" + " " + (today.getMonth()+1) + "月 " + today.getDate() + "日" + " " + dayNames[today.getDay()] 
outDiv+='</TH></tr><tr id="tr2" class="tr2"><TH>日</TH>'
outDiv+='<th>一</th>'
outDiv+='<th>二</th>'
outDiv+='<th>三</th>'
outDiv+='<th>四</th>'
outDiv+='<th>五</th>'
outDiv+='<th>六</th>'
outDiv+="</tr><tr id='tr3' class='tr3'>"
column = 0;
for (i=0; i<startDay; i++){
outDiv+="<td> </td>"
column++
}
for (i=1; i<=nDays; i++){
if (i == today.getDate()){
outDiv+="</td><td align='center' id='td1' class='td1'>"
}else{
outDiv+="</td><td ALIGN='center'>"
}
outDiv+=i
if (i == today.getDate()) outDiv+="</td>"
column++;
if (column == 7){
outDiv+="<tr id='tr3' class='tr3'>"
column = 0
}
}
outDiv+='</tr></table>'
calendarArea.innerHTML=outDiv
}

//顯示目前時間
function showTime(){
nowDateTime = new Date()
taiwanHours = nowDateTime.getHours()
taiwanMinutes = nowDateTime.getMinutes()
taiwanSeconds = nowDateTime.getSeconds()
nowTime.innerHTML="<font><img src='today_icon.gif'>現在時間(TW): " + 
taiwanHours + "時" + taiwanMinutes + "分" + taiwanSeconds + "秒</font>"
setTimeout("showTime()",1000)
}

//日曆配設選擇
function chgColor(num){
switch(num){
case 0:
tr1.style.backgroundColor="#666666"
tr2.style.backgroundColor="#c5c5c5"
tr3[0].style.backgroundColor="#efefef"
tr3[1].style.backgroundColor="#efefef"
tr3[2].style.backgroundColor="#efefef"
tr3[3].style.backgroundColor="#efefef"
tr3[4].style.backgroundColor="#efefef"
td1.style.backgroundColor="#666666"
break;
case 1:
tr1.style.backgroundColor="#000099"
tr2.style.backgroundColor="#3333ff"
tr3[0].style.backgroundColor="#ccffff"
tr3[1].style.backgroundColor="#ccffff"
tr3[2].style.backgroundColor="#ccffff"
tr3[3].style.backgroundColor="#ccffff"
tr3[4].style.backgroundColor="#ccffff"
td1.style.backgroundColor="#000099"
break; 
case 2:
tr1.style.backgroundColor="#800000"
tr2.style.backgroundColor="#cc3300"
tr3[0].style.backgroundColor="#ff9900"
tr3[1].style.backgroundColor="#ff9900"
tr3[2].style.backgroundColor="#ff9900"
tr3[3].style.backgroundColor="#ff9900"
tr3[4].style.backgroundColor="#ff9900"
td1.style.backgroundColor="#800000"
break;
case 3:
tr1.style.backgroundColor="#006600"
tr2.style.backgroundColor="#339933"
tr3[0].style.backgroundColor="#ccff99"
tr3[1].style.backgroundColor="#ccff99"
tr3[2].style.backgroundColor="#ccff99"
tr3[3].style.backgroundColor="#ccff99"
tr3[4].style.backgroundColor="#ccff99"
td1.style.backgroundColor="#006600"
break;
case 4:
tr1.style.backgroundColor="#660066"
tr2.style.backgroundColor="#9900ff"
tr3[0].style.backgroundColor="#ffacff"
tr3[1].style.backgroundColor="#ffacff"
tr3[2].style.backgroundColor="#ffacff"
tr3[3].style.backgroundColor="#ffacff"
tr3[4].style.backgroundColor="#ffacff"
td1.style.backgroundColor="#660066"
break;
}
}