// JavaScript Document

var youbi = new Array("日","月","火","水","木","金","土");

// 今日のいちご電車
function ichigo_timetable() {
//	ichigo_LinkTodayTomorrow();
//	ichigo_Calendar(2008,6,0,0);
//	ichigo_Calendar(2008,7,0,0);
//	ichigo_Calendar(2008,8,0,0);
}

// 今日のいちご電車・今日明日のリンク
function ichigo_LinkTodayTomorrow() {
	// 今日
	var myDate = new Date();
	ichigo_LinkWrite(myDate, "今日");
	// 明日
	myDate.setDate(myDate.getDate()+1);
	ichigo_LinkWrite(myDate, "明日");
}

// TAG出力(SUB)
function ichigo_LinkWrite(date, str)
{
	var YYYY = date.getFullYear();
	var MM = date.getMonth() + 1;		if (MM<10) MM = "0"+MM;
	var DD = date.getDate();			if (DD<10) DD = "0"+DD;
	var DAY = youbi[date.getDay()];
	
	str += " "+YYYY+"-"+MM+"-"+DD+"("+DAY+")";
	var url = "http://kishigawa-sen.com/timetable/ichigo_ec/tt.php?dd="+YYYY+MM+DD;
	
//	document.write("<a href=\"timetable/ichigo_ec/tt.php?dd=", YYYY, MM, DD, "\" target=\"ichigo_tt\">", str, " ", YYYY,"-",MM,"-",DD,"(",DAY,")</a><br>");
//	document.write("<a href=\""+url+"\" target=\"ichigo_tt\">"+str+"</a><br>");
	document.write("<a href=\"javascript:ichigo_open('"+url+"')\">"+str+"</a><br>");
}

//	カレンダー出力
//	引数	yyyy:西暦, mm:月, dd0:リンク開始日(0で無効), dd1:リンク終了日(0で無効)
function ichigo_Calendar(yyyy, mm, dd0, dd1)
{
	var myDate = new Date(yyyy, mm-1, 1);
	var firstDay = myDate.getDay();
	var lastDate = ichigo_getLastDate(myDate);
	
	document.write("<table class=\"cal\" align=\"center\"><tr class=\"cap\"><th colspan=\"7\">", yyyy, "年 ", mm, "月</th></tr><tr><th>日</th><th>月</th><th>火</th><th>水</th><th>木</th><th>金</th><th>土</th></tr>\n");
	
	var date, day=0;

	document.write("<tr>");
	
	// 月の始まりまり1日まで空白
	while(firstDay){	document.write("<td>&nbsp;</td>");	day++;	firstDay--;	}

	for (date=1; date<=lastDate; date++){
		if (day==0)	document.write("<tr>");
		document.write("<td>");
		if (dd1==0||date<=dd1){
//			document.write("<a href=\"timetable/ichigo_ec/tt.php?dd=");
//			var link = yyyy;
//			if (mm<10)		link += "0";
//			link += ""+mm;	
//			if (date<10)	link += "0";
//			link += ""+date;
//			document.write(link);
//			document.write("\" target=\"ichigo_tt\">", date,"</a>");
			
			var url = "http://kishigawa-sen.com/timetable/ichigo_ec/tt.php?dd="+yyyy;
			if (mm<10)		url += "0";
			url += ""+mm;	
			if (date<10)	url += "0";
			url += ""+date;
			document.write("<a href=\"javascript:ichigo_open('"+url+"')\">"+date+"</a>");
		}else{
			document.write(date+"");
		}
		document.write("</td>");
		day++;	if (day==7){	day=0;	document.write("</tr>\n");	}
	}
	while(day==7){	document.write("<td>&nbsp;</td>");	day++;	}
	document.write("</tr>\n</table>");
}

// 月の最終日を取得
function ichigo_getLastDate(date)
{
	date.setMonth(date.getMonth()+1);
	date.setDate(date.getDate()-1);
	return date.getDate();	
}

//	OpenLinkWindow
function ichigo_open(url)
{
	window.open(url,"ichigo_tt", "toolbar=no,status=no,scrollbars=yes,resizable=yes,width=280");
}
