
// カレンダー生成関数
function w_calender(target_month) {

// 各月の日数定義
	var maxdays = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30 ,31);

// 今日の日付取得
	var presday = new Date();
	var presyear = presday.getYear();
	var presmonth = presday.getMonth() + 1 + target_month;
	var presdate = presday.getDate();

	if ( presmonth == 13 ) {
		presmonth = 1;
		presyear += 1;
	}

//■テスト用変数
//presmonth = 12;
//presyear += 1;


// 今年今月１日の曜日を取得 0 が日曜
	var firstday = (new Date(presyear, presmonth - 1, 1, 0, 0, 0)).getDay();

// うるう年の判定
	if ( presyear % 4 == 0 ) { maxdays[1] = 29; }
	if ( presyear % 100 == 0 ) { maxdays[1] = 28; }
	if ( presyear % 400 == 0 ) { maxdays[1] = 29; }

	var daycounter = 1;

//カレンダーテーブル生成
document.write("<table><tr><th colspan=\"7\" class=\"eigyou\">" + presyear + "年" + presmonth + "月" + "</th></tr>");
document.write("<tr><th class=\"indays_sn\">日</th><th class=\"indays\">月</th><th class=\"indays\">火</th>");
document.write("<th class=\"indays\">水</th><th class=\"indays\">木</th><th class=\"indays\">金</th><th class=\"indays_st\">土</th></tr>");

//第１週目
	document.write("<tr>");
	for (i = 0; i < firstday; i++) {
		document.write("<td class=\"empday\">　</td>");
	}
	for (i = 0; i < (7 - firstday); i++) {
		document.write("<td class=\"" + classjudge(presmonth, presdate, firstday, daycounter, target_month) + "\">" + daycounter + "</td>")
		daycounter++;
	}
	document.write("</tr>");

//第２, ３, ４週目

	for (j = 0; j < 3; j++) {
		document.write("<tr>");
		for (i = 0; i < 7; i++) {
			document.write("<td class=\"" + classjudge(presmonth, presdate, firstday, daycounter, target_month) + "\">" + daycounter + "</td>")
			daycounter++;
		}
		document.write("</tr>");
	}

//第５週目
	document.write("<tr>");
	for (i = 0; i < 7; i++) {
		if ( maxdays[presmonth - 1] - daycounter >= 0) {
			document.write("<td class=\"" + classjudge(presmonth, presdate, firstday, daycounter, target_month) + "\">" + daycounter + "</td>")
			daycounter++;
		} else {
			document.write("<td class=\"empday\">　</td>");
		}
	}
	document.write("</tr>");

//第６週目

	if ( maxdays[presmonth - 1 ] - daycounter >= 0) {
		document.write("<tr>");
		for (i = 0; i < 7; i++) {
			if ( maxdays[presmonth - 1] - daycounter >= 0) {
				document.write("<td class=\"" + classjudge(presmonth, presdate, firstday, daycounter, target_month) + "\">" + daycounter + "</td>")
				daycounter++;
			} else {
				document.write("<td class=\"empday\">　</td>");
			}
		}
		document.write("</tr>");
	}



document.write("</table>")




}


//クラス判定関数
function classjudge(j_month, p_date, fday, j_date, t_month) {

	var youbi = ( j_date + fday + 6 ) % 7;
	var result;
	var futei = new Array();
	var rinji = new Array();
	var shuku = new Array();


//●最終更新 2012年02月09日●
//●2012年08月分まで更新済み


// ■不定休業日の設定■
// ▼2012年
	futei[101] = 1;
	futei[103] = 1;
	futei[505] = 1;
	futei[506] = 1;
	futei[821] = 1;

// ■臨時営業日の設定■
// ▼2012年
	rinji[110] = 1;



// ■祝日の設定■
// ▼2012年
	shuku[102] = 1;
	shuku[109] = 1;
	shuku[211] = 1;
	shuku[320] = 1;
	shuku[430] = 1;
	shuku[503] = 1;
	shuku[504] = 1;
	shuku[505] = 1;
	shuku[716] = 1;
	shuku[917] = 1;
	shuku[922] = 1;
	shuku[1008] = 1;
	shuku[1103] = 1;
	shuku[1123] = 1;
	shuku[1224] = 1;



	// 日曜日の判定
	if ( youbi == 0) {
		//第３日曜日の判定
		if ( (j_date > 14)&&( j_date < 22 ) ) {
			result = "off_sn";
			if ( (p_date == j_date)&&(t_month == 0) ) { result = "off_sn_td"; }
		} else {
			result = "on_sn";
			if ( (p_date == j_date)&&(t_month == 0) ) { result = "on_sn_td"; }
		}
	}
	// 月曜 定休日
	if ( youbi == 1) {
		result = "off_wd";
		if ( (p_date == j_date)&&(t_month == 0) ) { result = "off_wd_td"; }
	}
	// 火曜日の判定
	if ( youbi == 2) {
		//第２火曜日の判定
		if ( (j_date > 7)&&( j_date < 15 ) ) {
			result = "off_wd";
			if ( (p_date == j_date)&&(t_month == 0) ) { result = "off_wd_td"; }
		} else {
			result = "on_wd";
			if ( (p_date == j_date)&&(t_month == 0) ) { result = "on_wd_td"; }
		}
	}
	// 水、木、金
	if ( (youbi > 2)&&(youbi < 6) ) {
		result = "on_wd";
		if ( (p_date == j_date)&&(t_month == 0) ) { result = "on_wd_td"; }
	}
	// 土
	if ( youbi == 6 ) {
		result = "on_st";
		if ( (p_date == j_date)&&(t_month == 0) ) { result = "on_st_td"; }
	}

// 不定休判定

	if ( futei[ j_month * 100 + j_date ] == 1 ) {
		if ( youbi == 0 ) {
			result = "off_sn";
			if ( (p_date == j_date)&&(t_month == 0) ) { result = "off_sn_td"; }
		}
		if ( (youbi > 0)&&(youbi < 6) ) {
			result = "off_wd";
			if ( (p_date == j_date)&&(t_month == 0) ) { result = "off_wd_td"; }
		}
		if ( youbi == 6 ) {
			result = "off_st";
			if ( (p_date == j_date)&&(t_month == 0) ) { result = "off_st_td"; }
		}
	}


// 臨時営業日判定

	if ( rinji[ j_month * 100 + j_date ] == 1 ) {
		if ( youbi == 0 ) {
			result = "on_sn";
			if ( (p_date == j_date)&&(t_month == 0) ) { result = "on_sn_td"; }
		}
		if ( (youbi > 0)&&(youbi < 6) ) {
			result = "on_wd";
			if ( (p_date == j_date)&&(t_month == 0) ) { result = "on_wd_td"; }
		}
		if ( youbi == 6 ) {
			result = "on_st";
			if ( (p_date == j_date)&&(t_month == 0) ) { result = "on_st_td"; }
		}
	}



// 祝日判定

	if ( shuku[ j_month * 100 + j_date ] == 1 ) {
		if ( (youbi > 0)&&(youbi <= 6) ) {
			switch (result) {
				case "on_wd":
					result = "on_sn";
					break;
				case "on_st":
					result = "on_sn";
					break;
				case "off_wd":
					result = "off_sn";
					break;
				case "off_st":
					result = "off_sn";
					break;
				case "on_wd_td":
					result = "on_sn_td";
					break;
				case "on_st_td":
					result = "on_sn_td";
					break;
				case "off_wd_td":
					result = "off_sn_td";
					break;
				case "off_st_td":
					result = "off_sn_td";
					break;
				default:
					break;
			}
		}
	}



	return result;
}




