// 閏年かどうかを調べる
function isLeapYear(year){
	if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)){
		return true;
	} else {
		return false;
	}
}
// 月の最初の曜日を求める
function  calcFirstDay(date) {
	var tmpDate = new Date();
	tmpDate.setTime(date.getTime());
	tmpDate.setDate(1);
	return tmpDate.getDay();
}
// 月の日数を計算
function calcMonthDays(date) {
	var monthDays = new Array (31, 28, 31, 30, 31, 30, 31, 31, 30,
	31, 30, 31);
	if (isLeapYear (date.getYear() + 1900)) {
		monthDays[1] = 29;
	}
	return monthDays[date.getMonth()];
}
// カレンダーを表示する
function display(today, month, firstDay, Days) {
	document.write("<br>");
	document.write(today.getYear(), " 年 ");
	document.write(month+1, " 月<br>");
	document.write("<table>");
	document.write("<tr><th>");
	document.write(" 日 <th> 月 <th> 火 <th> 水 <th> 木 <th> 金 <th> 土 ");
	document.write("</tr>");
	document.write("<tr>");
	var col = 0;
	//最初の日まで列をとばす
	for (var i=0; i<firstDay; i++)
	{
		document.write("<td></td>");
	col++;
	}
	for (var i=1; i<=Days; i++)
	{
		document.write("<td>");
		//今日の日付は赤で表示
		if (i == today.getDate()) {
			var iStr = i.toString().fontcolor("red");
			document.write(iStr + "</td>");
		}else {
			document.write(i+"</td>");
		}
		col++;
		if (col == 7)
		{
			document.write("</tr><tr>"); 
			col = 0;
		}
	}
	document.write("</tr></table>");
}

