var cals = new Array();

function writeCalendar(num){
	if(obj = document.getElementById("calObj")){
		obj.innerHTML = cals[num];
	}
}

function changeCalender(sel){
	var index = sel.selectedIndex
	if(index >= 0){
		writeCalendar(index);
	}
}

function calendar(){
	var now = new Date();
	var year = 2012;
	var month = 02;
	var date = now.getDate();
	var day = now.getDay();
	var last_date = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
	if(month==2){
		if(year%4==0){
			if((year%100==0) && (year%400!=0)){
			}else{
				last_date[1] = 29;
			}
		}
	}

	var calhead001 =
		'<table class="cal" id="cal0" cellpadding="0" cellspacing="0" border="0" summary="図書館カレンダー">' +
		'<caption>中央：' + year + '年' + month + '月</caption>' +
		'<colgroup>' +
		'<col width="14%" span="7">' +
		'</colgroup>' +
		'<thead>'
	;
	var calstr001 =
		'<tr><th scope="col" abbr="日">日</th><th scope="col" abbr="月">月</th><th scope="col" abbr="火">火</th><th scope="col" abbr="水">水</th><th scope="col" abbr="木">木</th><th scope="col" abbr="金">金</th><th scope="col" abbr="土">土</th></tr>' +
		'</thead>' +
		'<tbody><tr>'
	;
	for(dayIndex=0; dayIndex<(new Date(year,month-1,1)).getDay(); dayIndex++){
		calstr001 += defTD("","blank");
	}
	for(i=1; i<=last_date[month-1]; i++){
		if(i!=1 && dayIndex == 0){
			calstr001 += "<tr>";
		}
		if(i==""){
			
		} else if ((i==01)||(i==03)||(i==10)||(i==17)||(i==24)) {	// CLOSED
			if(i==date){
				calstr001 += defTD(i,"close");
			} else {
				calstr001 += defTD(i,"close");
			}
		} else if ((i==08)||(i==08)||(i==11)||(i==15)||(i==15)||(i==22)||(i==22)||(i==25)||(i==29)) {	// EVENT
			if(i==date){
				calstr001 += defTD(i,"event");
			} else {
				calstr001 += defTD(i,"event");
			}
		} else {
			switch(dayIndex){
			case 0:						// SUNDAY
				calstr001 += defTD(i,"sunday");
				break;
			case 6:						// SATURDAY
				calstr001 += defTD(i,"saturday");
				calstr001 += "</tr>";
				break;
			default:					// Normal
				calstr001 += defTD(i,"white");
				break;
			}
		}
		dayIndex++;
		dayIndex%=7;
	}

	if(dayIndex!=7){
		calstr001 += "</TR>";
	}
	calstr001 += "</TABLE>";

	cals.push(calhead001 + calstr001);

	var calhead003 =
		'<table class="cal" id="cal0" cellpadding="0" cellspacing="0" border="0" summary="図書館カレンダー">' +
		'<caption>吉祥寺：' + year + '年' + month + '月</caption>' +
		'<colgroup>' +
		'<col width="14%" span="7">' +
		'</colgroup>' +
		'<thead>'
	;
	var calstr003 =
		'<tr><th scope="col" abbr="日">日</th><th scope="col" abbr="月">月</th><th scope="col" abbr="火">火</th><th scope="col" abbr="水">水</th><th scope="col" abbr="木">木</th><th scope="col" abbr="金">金</th><th scope="col" abbr="土">土</th></tr>' +
		'</thead>' +
		'<tbody><tr>'
	;
	for(dayIndex=0; dayIndex<(new Date(year,month-1,1)).getDay(); dayIndex++){
		calstr003 += defTD("","blank");
	}
	for(i=1; i<=last_date[month-1]; i++){
		if(i!=1 && dayIndex == 0){
			calstr003 += "<tr>";
		}
		if(i==""){
			
		} else if ((i==01)||(i==03)||(i==10)||(i==17)||(i==24)) {	// CLOSED
			if(i==date){
				calstr003 += defTD(i,"close");
			} else {
				calstr003 += defTD(i,"close");
			}
		} else if ((i==08)||(i==08)||(i==09)||(i==15)||(i==22)||(i==22)||(i==29)) {	// EVENT
			if(i==date){
				calstr003 += defTD(i,"event");
			} else {
				calstr003 += defTD(i,"event");
			}
		} else {
			switch(dayIndex){
			case 0:						// SUNDAY
				calstr003 += defTD(i,"sunday");
				break;
			case 6:						// SATURDAY
				calstr003 += defTD(i,"saturday");
				calstr003 += "</tr>";
				break;
			default:					// Normal
				calstr003 += defTD(i,"white");
				break;
			}
		}
		dayIndex++;
		dayIndex%=7;
	}

	if(dayIndex!=7){
		calstr003 += "</TR>";
	}
	calstr003 += "</TABLE>";

	cals.push(calhead003 + calstr003);

	var calhead006 =
		'<table class="cal" id="cal0" cellpadding="0" cellspacing="0" border="0" summary="図書館カレンダー">' +
		'<caption>プレイス：' + year + '年' + month + '月</caption>' +
		'<colgroup>' +
		'<col width="14%" span="7">' +
		'</colgroup>' +
		'<thead>'
	;
	var calstr006 =
		'<tr><th scope="col" abbr="日">日</th><th scope="col" abbr="月">月</th><th scope="col" abbr="火">火</th><th scope="col" abbr="水">水</th><th scope="col" abbr="木">木</th><th scope="col" abbr="金">金</th><th scope="col" abbr="土">土</th></tr>' +
		'</thead>' +
		'<tbody><tr>'
	;
	for(dayIndex=0; dayIndex<(new Date(year,month-1,1)).getDay(); dayIndex++){
		calstr006 += defTD("","blank");
	}
	for(i=1; i<=last_date[month-1]; i++){
		if(i!=1 && dayIndex == 0){
			calstr006 += "<tr>";
		}
		if(i==""){
			
		} else if ((i==01)||(i==08)||(i==17)||(i==22)||(i==29)) {	// CLOSED
			if(i==date){
				calstr006 += defTD(i,"close");
			} else {
				calstr006 += defTD(i,"close");
			}
		} else if ((i==03)||(i==10)||(i==10)||(i==24)||(i==24)) {	// EVENT
			if(i==date){
				calstr006 += defTD(i,"event");
			} else {
				calstr006 += defTD(i,"event");
			}
		} else {
			switch(dayIndex){
			case 0:						// SUNDAY
				calstr006 += defTD(i,"sunday");
				break;
			case 6:						// SATURDAY
				calstr006 += defTD(i,"saturday");
				calstr006 += "</tr>";
				break;
			default:					// Normal
				calstr006 += defTD(i,"white");
				break;
			}
		}
		dayIndex++;
		dayIndex%=7;
	}

	if(dayIndex!=7){
		calstr006 += "</TR>";
	}
	calstr006 += "</TABLE>";

	cals.push(calhead006 + calstr006);

}

function defTD(str, iro){
	return "<td class='" + iro + "'>" + str + "</td>";
}

function defBTD(str, iro){
	return "<td class='" + iro + "'><B>" + str + "</B></td>";
}

function calendar_select(){
	document.write(
/* 2011.10.04 mod 
		'<div id="calObj"></div>' +
		'切替<select tabindex="30" name="selectLib" id="selectLib" onchange="changeCalender(this);changeCalender2(this);" style="width:120px;">' +
		'<option value="001">中央</option>' +
		'<option value="003">吉祥寺</option>' +
		'<option value="006">プレイス</option>' +
		'</select>'
*/ 
		'<div id="calObj"></div>' 
	);
}

calendar();
calendar_select();
writeCalendar(0);

