var cals2 = new Array();

function writeCalendar2(num){
	if(obj = document.getElementById("calObj2")){
		obj.innerHTML = cals2[num];
	}
}

function changeCalender2(sel){
	var index = sel.selectedIndex
	if(index >= 0){
		writeCalendar2(index);
	}
}

function calendar2(){
	var now = new Date();
	var year = 2012;
	var month = 03;
	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==02)||(i==07)||(i==09)||(i==16)||(i==23)||(i==30)) {	// CLOSED
			if(i==false){
			} else {
				calstr001 += defTD(i,"close");
			}
		} else if ((i==14)||(i==14)||(i==21)||(i==21)||(i==24)||(i==28)||(i==28)) {	// EVENT
			if(i==false){
			} 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>";

	cals2.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==02)||(i==07)||(i==09)||(i==16)||(i==23)||(i==30)) {	// CLOSED
			if(i==false){
			} else {
				calstr003 += defTD(i,"close");
			}
		} else if ((i==10)||(i==14)||(i==14)||(i==21)||(i==28)||(i==28)) {	// EVENT
			if(i==false){
			} 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>";

	cals2.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==07)||(i==16)||(i==21)||(i==28)) {	// CLOSED
			if(i==false){
			} else {
				calstr006 += defTD(i,"close");
			}
		} 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>";

	cals2.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_select2(){
	document.write(
		'<div id="calObj2"></div>' 
	);
}

calendar2();
calendar_select2();
writeCalendar2(0);

