///////////////////////////////////////////////////////////////////////////////
//	カレンダー表記関数
//
function writeCalendar(append) {
	// 毎月の含まれる日数の配列を宣言する。
	//(2月は28日とし、うるう年チェックする)
	var calendars = new Array(0,31,28,31,30,31,30,31,31,30,31,30,31);
	// 本日の情報を取得する
	var today = new Date();
	// 西暦年と月を取得する
	var year = today.getYear();
	var month = 1 + today.getMonth();
	// 表示する月と現在の月の差、来月ならば+1(1), 先月ならば-1,当月は0。
	var add = 0;
	// うるう年での2月の加算日数(28日なら０、29日なら１)
	var feb = 0;
	// 西暦年の取得情報の修正
	if (year < 1900) {
		year += 1900;
	}
	if (!isNaN(append)) {
		add = append - 0;
	}
	// 表示月の算出
	month += add;
	// 表示年/月の修正
	if (month < 1) {
		year -= 1;
		month += 12;
	} else if (month > 12) {
		year += 1;
		month -= 12;
	}
	// うるう年チェックによる2月の加算日数の算出
	if (year % 100 == 0 || year % 4 != 0) {
		if (year % 400 != 0) {
			feb = 0;
		} else {
			feb = 1;
		}
	} else if (year % 4 == 0) {
		feb = 1;
	} else {
		feb = 0;
	}
	// 2月の日数の修正
	calendars[2] += feb;
	// 表示月の初日の曜日を取得
	first = new Date(year,(month-1),1);
	start = first.getDay();		// 0:日曜日〜6:土曜日
	
	with(document) {
		write("<ul class='calendar'>");
		write("<li class='title'>" + year + "年" + month + "月</li>");
		write("<li class='sun'>日</li>");
		write("<li class='mon'>月</li>");
		write("<li class='mon'>火</li>");
		write("<li class='mon'>水</li>");
		write("<li class='mon'>木</li>");
		write("<li class='mon'>金</li>");
		write("<li class='sun'>土</li>");
		// 表示月の初日までの空白を出力
		for(var i=0; i<start; i++) {
			write("<li class='noneday'>&nbsp;</li>");
		}
		// 表示月のカレンダーを出力
		t = start + calendars[month];
		a = 7 - (t % 7);
		m = t + a;
		n = m - start;
		for(var i=1; i<=n; i++) {
			if (i<=calendars[month]) {
				chk = year + "/" + month + "/" + i;
				b = (start + i - 1) % 7;
				if ((b == 0) || (b == 6)) {
					// 土日で例外的な営業日のチェック
					cls = "holiday";
					if (special_days[chk]) {
						if (special_days[chk] == "workday") {
							cls = "workday";
						}
					}
				} else {
					// 平日で祝日などの休業日のチェック
					cls = "workday";
					if (special_days[chk]) {
						if (special_days[chk] == "holiday") {
							cls = "holiday";
						}
					}
				}
				write("<li class='" + cls + "'>" + i + "</li>");
			} else {
				write("<li class='noneday'>&nbsp;</li>");
			}
		}
		// liタグのfloat設定のクリア
		write("<li class='clear'>&nbsp;</li>");
		write("</ul>");
	}
}
