﻿function montharr(m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11) {
this[0] = m0;
this[1] = m1;
this[2] = m2;
this[3] = m3;
this[4] = m4;
this[5] = m5;
this[6] = m6;
this[7] = m7;
this[8] = m8;
this[9] = m9;
this[10] = m10;
this[11] = m11;
}

function calendar() {
var monthNames = "JanFebMarAprMayJunJulAugSepOctNovDec";
var today = new Date();
var thisDay;
var monthDays = new montharr(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

year = today.getYear() ;
thisDay = today.getDate();


if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) monthDays[1] = 29;

nDays = monthDays[today.getMonth()];
firstDay = today;
firstDay.setDate(1); // works fine for most systems
testMe = firstDay.getDate();
if (testMe == 2) firstDay.setDate(0);
startDay = firstDay.getDay();

var dayNames = new Array("星期日","星期一","星期二","星期三","星期四","星期五","星期六");
var monthNames = new Array("01","02","03","04","05","06","07","08","09","10","11","12");
var now = new Date();
var myYears = ( now.getYear() < 1900 ) ? ( 1900 + now.getYear() ) : now.getYear();


c_body='<table width="100%" border="0" cellpadding="0" cellspacing="0" class="calendarsmall"><tr height="19" align="right" valign="top"><td><strong>' + myYears +' // '+ monthNames[now.getMonth()] +'</strong></td></tr></table>'


c_body=c_body+'<table width="100%" border="0" cellpadding="0" cellspacing="0"><tr valign="top" align="center" class="calendarweek"><td>日</td><td>一</td><td>二</td><td>三</td><td>四</td><td>五</td><td>六</td></tr><tr><td class="calendarline" colspan="7"></td></tr></table>';
c_body=c_body+'<table width="100%" border="0" cellpadding="0" cellspacing="0" class="calendarsmall"><tr align="center">';

column = 0;
if(startDay>0){
c_body=c_body+'<td colspan="'+ startDay +'"></td>';
}
column+=startDay;
for (i=1; i<=nDays; i++) {
if (i == thisDay) {
c_body=c_body+'</td><td class="calendarover">';
}
else {
c_body=c_body+'</td><td>';
}
c_body=c_body+i;
if (i == thisDay) c_body=c_body+'</td>';
column++;
if (column == 7) {
c_body=c_body+'</tr><tr align="center">';
column = 0;
}
} 
if(column<7){
c_body=c_body+'<td colspan="'+ (7-column) +'"></td>';
}
c_body=c_body+'</tr></table>';
document.write (c_body);
}


calendar();