//Calendar in WWW WebLender Version 2.01
//By Tatsuhiko Syoji(Tatsu) 1999,2000,2001

	var Week_str,Week_col,Week_BGcol;
	var Holidays,Holiday_data; //祝日関連
	var Schedules,Schedule_data,Schedule_color,Schedule_col; //スケジュール関連
	var Today_col,Defbg_col,Border,Cellspacing;
	//スケジュールボード関連
	var SB_border,SB_Cellspacing,SB_bgcolor,SB_countdown;
	var dsp,class_str;

function schedule(year,month,date,desc,link,kind)
{
	this.year = year;
	this.month = month;
	this.date = date;
	this.desc = desc;
	this.link = link;
	this.kind = kind;
}

function Holiday(year,month,date,name)
{
	var	p,len;
	
	len = year.length;
	if (len != 0){
		p = year.indexOf('-');
		if (p == -1){
			this.s_year = parseInt(year,10);
			this.e_year = -1;
		}else{

			if (p != 0){ // Start year
				this.s_year = parseInt(year.substring(0,p),10);
			}else{
				this.s_year = -1;
			}
			if (p == (len - 1)){ //End year
				this.e_year = -1;
			}else{
				this.e_year = parseInt(year.substring(p+1,len),10);
			}
		}
	}else{
		this.s_year = -1;
		this.e_year = -1;
	}
	
	this.month = month;
	this.date = date;
	this.name = name;

}

function sc_comp(a,b)
{
	if (a.year < b.year){
		return(-1);
	}
	if (a.year > b.year){
		return(1);
	}

	if (a.month < b.month){
		return(-1);
	}
	if (a.month > b.month){
		return(1);
	}

	if (a.date < b.date){
		return(-1);
	}
	if (a.date > b.date){
		return(1);
	}
	return(0);
}

	class_str = new Array("SUN","MON","TUE","WED","THU","FRI","SAT");

//共通データ
//ここからの内容はカスタマイズして結構です。

//スケジュール関係
//スケジュールの数
	Schedules = 0;
//ここはいじらないで下さい。
	Schedule_data = new Array(Schedules);
//ここまで

//スケジュールを記述する際は、注釈に従って記述し、[]内の番号を
//(スケジュールの数-1)の範囲内で、重複しないようにして下さい。
//ここからをコピーします。
	Schedule_data[0] = new schedule(
	0,
	5,
	8,
	"作者の誕生日", //スケジュールの内容
	"http://www.geocities.co.jp/SiliconValley/7512/", //スケジュールに関するリンク
	1 //スケジュールの種類(標準では0-4)
	);
//ここまでをコピーします。

//各曜日の名前
//	Week_str = new Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat");
	Week_str = new Array("日","月","火","水","木","金","土");

//祝日関係(春分の日、秋分の日は自動計算しますので除きます。)
//祝日の数
	Holidays = 16;
	
	Holiday_data = new Array(Holidays);

	//年,月,日,祝日名の順で記述して下さい。

	//年は"開始年-最後の年"のフォーマットで書いてください。
	//開始年と最後の年のうち片方は省略できます。
	//両方ともない場合は空文字列にして下さい。

	//月は普通に月を書きますが、高速化のため配列の最初に1月が来て
	//2,3,...11,12月の順に並べるようにして下さい。

	//普通の祝日は日をそのまま書いて下さい。
	//第n週のx曜日(日曜日:0 - 土曜日 6)の場合は1nxと書いてください。

	Holiday_data[0] = new Holiday("1949-",1,1,"元日");
	Holiday_data[1] = new Holiday("1949-1999",1,15,"成人の日");
	Holiday_data[2] = new Holiday("2000-",1,121,"成人の日");
	Holiday_data[3] = new Holiday("1967-",2,11,"建国記念日");
	Holiday_data[4] = new Holiday("1949-1988",4,29,"天皇誕生日");
	Holiday_data[5] = new Holiday("1989-",4,29,"みどりの日");
//	Holiday_data[6] = new Holiday("2001-",4,29,"昭和の日");
	Holiday_data[6] = new Holiday("1949-",5,3,"憲法記念日");
	Holiday_data[7] = new Holiday("1986-",5,4,"国民の休日");
//	Holiday_data[9] = new Holiday("2001-",5,4,"みどりの日");
	Holiday_data[8] = new Holiday("1949-",5,5,"こどもの日");
	Holiday_data[9] = new Holiday("1996-",7,20,"海の日");
	Holiday_data[10] = new Holiday("1966-",9,15,"敬老の日");
	Holiday_data[11] = new Holiday("1966-1999",10,10,"体育の日");
	Holiday_data[12] = new Holiday("2000-",10,121,"体育の日");
	Holiday_data[13] = new Holiday("1948-",11,3,"文化の日");
	Holiday_data[14] = new Holiday("1948-",11,23,"勤労感謝の日");
	Holiday_data[15] = new Holiday("1989-",12,23,"天皇誕生日");

//外枠線の太さ(0でなし)
	Border = 1;
//枠線の太さ
	Cellspacing = 0;
//スケジュールボードの外枠線の太さ(0でなし)
	SB_Border = 1;
//スケジュールボードの枠線の太さ
	SB_Cellspacing = 0;
//スケジュールボード上のカウントダウン表示の有無(0:なし)
	SB_countdown = 0;

//表示色
//背景色は""を指定すると透明になります。
//各曜日の色
	Week_col = new Array("red","black","black","black","black","black","blue");
//曜日表示部分の背景色
//	Daybg_col = "White";
	Daybg_col = "";
//各曜日の背景色(日曜/祝日,月曜,...,金曜,土曜の順)
//	Week_BGcol = new Array("#FFB6C1","white","white","white","white","white","Aqua");
	Week_BGcol = new Array("","","","","","","");
//各曜日名の背景色(日曜/祝日,月曜,...,金曜,土曜の順)
//	WeekName_BGcol = new Array("#FFB6C1","white","white","white","white","white","Aqua");
	WeekName_BGcol = new Array("","","","","","","");
//(先月もしくは来月の表示部分の背景色)
	Defbg_col = "";
//祝日の表示色
	Holiday_col = "Red";
//祝日の背景色
//	Holiday_BGcol = "#FFB6C1";
	Holiday_BGcol = "";
//今日の表示の背景色
//	Today_col = "lime";
	Today_col = "";
//スケジュールが入っている日の背景色
	Schedule_col = "Yellow";
//	Schedule_col = "";
//スケジュール表示部分の背景色
	SB_bgcolor = "White";
//スケジュールの種類に対応するスケジュールの色。基本16色にピンクはないのね。
	Schedule_color = new Array("red","black","blue","yellow","Fuchsia");

//ここまでの内容はカスタマイズして結構です。

//ここからはJavaScriptの知識のない方はいじらないで下さい。

//スケジュールをソートする
	Schedule_data.sort(sc_comp);

//春分の日計算
function CalcSyunbun(Year)
{
	var syunbun;
	
	if (Year < 2100){
		syunbun = Math.floor(20.8431+0.242194*(Year-1980)-Math.floor((Year-1980)/4));
	}else if (Year < 2150){
		syunbun = Math.floor(21.8510+0.242194*(Year-1980)-Math.floor((Year-1980)/4));
	}
	return(syunbun);
}

//秋分の日計算
function CalcSyubun(Year)
{
	var syubun;
	
	if (Year < 2100){
		syubun = Math.floor(23.2488+0.242194*(Year-1980)-Math.floor((Year-1980)/4));
	}else if (Year < 2150){
		syubun = Math.floor(24.2488+0.242194*(Year-1980)-Math.floor((Year-1980)/4))
	}
	return(syubun);
}

//祝日判定
// >=0 祝日である
// -1  祝日ではない
// -2  振替休日
function Holiday_check(year,month,date,day)
{
	var i,xw,xd;
	
	for (i = 0;i < Holidays;i++){
		if (Holiday_data[i].month == month){
			if (Holiday_data[i].date > 31){ //第n週型祝日判定
				xw = Math.floor((Holiday_data[i].date % 100) / 10);
				xd = Holiday_data[i].date % 10;
				if ((xd != day) || (Math.floor((date-1)/7) != (xw-1))){
					continue;
				}
			}else{
				if (Holiday_data[i].date != date){
					continue;
				}
			}
		}else{
			if (Holiday_data[i].month > month){
				break;
			}else{
				continue;
			}
		}
		if (Holiday_data[i].s_year != -1){
			if (year < Holiday_data[i].s_year){
				continue;
			}
		}
		if (Holiday_data[i].e_year != -1){
			if (year > Holiday_data[i].e_year){
				continue;
			}
		}
		return(i);
	}
	
	//昭和の日法案対応だったのだが...。似たような法案が施行された際の
	//サンプルにでもして下さい。
/*
	if (year > 2000){
		if (month == 5){
			if ((date == 6) && (day == 3)){ // 5/3(日)の振り替え休日
				return(-2);
			}
			if ((date == 6) && (day == 2)){ // 5/4(日)の振り替え休日
				return(-2);
			}
		}
	}
*/

	return(-1);
}

//カレンダー作成
function MakeCalendar(Year,Month){
	var int_date,Da,We,first_week,today; //,Year,Month
	var day_of_month_table;
	var i,tw,day_of_month,isHoliday;
	var j,bg_col,fg_col,syunbun,syubun;
	var Sch_str,isSchedule,isToday;
	var xd,xw;
	var t_year,t_month,t_date;
	var col,cls;

	dsp = "";
	day_of_month_table = new Array(31,28,31,30,31,30,31,31,30,31,30,31);

//春分の日と秋分の日を計算する。
	syunbun = CalcSyunbun(Year);
	syubun = CalcSyubun(Year);

//求める月の1日にして曜日を求める。
	int_date = new Date(Year,Month,1);

	today = new Date();
	t_year = today.getYear();
	if (t_year < 1900){
		t_year = t_year + 1900;
	}
	t_month = today.getMonth();
	t_date = today.getDate();

	first_week = int_date.getDay();
	
//表を書きこむ
	dsp = dsp + '\n<table rules=all class="WLBASE"  border=' + Border;
	if (Defbg_col != ""){
		dsp = " bgcolor=" + Defbg_col;
	}
	dsp = dsp + " cellspacing="+Cellspacing+">\n<tr";
	if (Daybg_col != ""){
		dsp = dsp + " bgcolor=\"" + Daybg_col + "\"";
	}
	dsp = dsp + ">\n";
//曜日表示
	for (i = 0;i < 7;i++){
		cls = "WLNAME" + class_str[i];

		bg_col = WeekName_BGcol[i];
		dsp = dsp + "<td" + ' class="' + cls +'"';
		if (bg_col != ""){
			 dsp = dsp + " bgcolor=" + bg_col;
		}
		dsp = dsp + ">";

		fg_col = Week_col[i];
		dsp = dsp + "<font size=2>";
		dsp = dsp + "<font color=" + fg_col +">";
		dsp = dsp + '<span class="' + cls + '">';
		dsp = dsp + Week_str[i];
		dsp = dsp + "<\/span>";
		dsp = dsp + "<\/font>"
		dsp = dsp + "<\/font>"
		dsp = dsp + "<\/td>";
	}
	dsp = dsp + "\n<\/tr>\n<tr>\n";

	cols = 0;
//最初の余白
	for (i = 0;i < first_week;i++){
		bg_col = Week_BGcol[i];
		dsp = dsp + "<td";
		if (bg_col != ""){
			dsp = dsp + " bgcolor=" + bg_col;
		}
		dsp = dsp + ">&nbsp;";
		dsp = dsp + "<\/td>";
		//dsp = dsp + "<td> <\/td>";	//Version 1.52 and older
	}
//1-終わりの日まで
	tw = first_week;
//うるう年対策
	day_of_month = day_of_month_table[Month];
	if (Month == 1){
		if (((Year % 4 == 0) && (Year % 100 != 0)) || (Year % 400 == 0)){
			day_of_month++;
		}
	}

	isHoliday = 0;
	//カレンダー描画ループ
	fg_col = Week_col[tw];
	bg_col = Week_BGcol[tw];
	for (i = 1;i <= day_of_month;i++){
		isSchedule = 0;
		Sch_str = "";
		
		cls = "WLDAY" + class_str[tw];

		if (Holiday_check(Year,Month+1,i,tw) != -1){
			isHoliday = 1;
		}

		if (Month == 2){ //3月・春分の日?
			if (i == syunbun){
				isHoliday = 1;
				cls = "WLHOLIDAY";
			}
		}else if (Month == 8){ //9月・秋分の日?
			if (i == syubun){
				isHoliday = 1;
				cls = "WLHOLIDAY";
			}
		}
		if (isHoliday == 1){
			fg_col = Holiday_col;
			bg_col = Holiday_BGcol;
			cls = "WLHOLIDAY";
		}

		for (j = 0;j < Schedules;j++){ //スケジュール判定
			if ((Year == Schedule_data[j].year || Schedule_data[j].year == 0) && ((Month+1) == Schedule_data[j].month || Schedule_data[j].month == 0) && (i == Schedule_data[j].date || Schedule_data[j].date == 0)){
				bg_col = Schedule_col;
				Sch_str = Sch_str + " " + Schedule_data[j].desc;
				isSchedule = 1;
			}
		}

		isToday = 0;
		if ((t_year == Year) && (t_month == Month) && (t_date == i)){ //今日かどうか?
			bg_col = Today_col;
			isToday = 1;
			cls = "WLTODAY";
		}

		dsp = dsp + "<td align=\"right\"";
		if (bg_col != ""){
			dsp = dsp + " bgcolor=" + bg_col;
		}
		
		if (Sch_str != ""){
			dsp = dsp + " title=\"" + Sch_str + "\"";
		}
		dsp = dsp + ' class="' + cls +  '">';
		
		if (isSchedule){
			dsp = dsp + "<u>";
		}
		
		if (isToday){	//2.00以降
			dsp = dsp + "<b>";
		}
		dsp = dsp + "<font size=2>";
		dsp = dsp + "<font color=" + fg_col +">";
		dsp = dsp + "<span class=" + cls +">";
		dsp = dsp + i;
		dsp = dsp + "<\/span>";
		dsp = dsp + "<\/font>";
		dsp = dsp + "<\/font>";
		if (isToday){	//2.00以降
			dsp = dsp + "</b>";
		}

		if (isSchedule){
			dsp = dsp + "<\/u>";
		}

		dsp = dsp + "<\/td>";

		
		tw++;
		if (tw > 6 && i < day_of_month){ //土曜日で月末でないか調べる。
			tw = 0;
			dsp = dsp + "<\/tr>\n<tr>\n";
			cols++;
		}
		if (isHoliday != 1 || tw != 1){ //振替休日のときは色を戻さない。
			fg_col = Week_col[tw];
			bg_col = Week_BGcol[tw];
			isHoliday = 0;
		}
	}
//終わりの空白
	for (i = tw;i < 7;i++){
		cls = "WLDAY" + class_str[i];
		bg_col = Week_BGcol[tw];
		dsp = dsp + "<td ";
		if (bg_col != ""){
			dsp = dsp + " bgcolor=" + bg_col;
		}
		dsp = dsp + ' class="' + cls + '">&nbsp;<\/td>';
		tw++;
		//dsp = dsp + "<td> <\/td>";	//Version 1.52 and older
	}
	cols++;
	if (cols < 6){
		dsp = dsp  + "<\/tr>\n<tr>\n";
		for (i = 0;i < 7;i++){
			cls = "WLDAY" + class_str[i];
			bg_col = Week_BGcol[i];
			dsp = dsp + "<td ";
			if (bg_col != ""){
				dsp = dsp + " bgcolor=" + bg_col;
			}
			dsp = dsp + ' class="' + cls + '">&nbsp;<\/td>';
			//dsp = dsp + "<td> <\/td>";	//Version 1.52 and older
		}
	}
	dsp = dsp + "<\/tr>\n<\/table>\n";
	return(dsp);

}

//カレンダー作成(1.xx互換)
function dispCalender(Year,Month){
	var	cal;

	cal = MakeCalendar(Year,Month);
	document.write(dsp);
}

function Schedule_check(sc)
{
	var today,y;
	today = new Date();

	if (sc.year == 0){
		return(1);
	}
	y = today.getYear();
	if (y < 1900){
		y = y + 1900;
	}
	if (sc.year < y){
		return(0);
	}else if (sc.year > y){
		return(1);
	}

	if (sc.month == 0){
		return(1);
	}
	if (sc.month < (today.getMonth()+1)){
		return(0);
	}else if (sc.month > (today.getMonth()+1)){
		return(1);
	}

	if (sc.date == 0){
		return(1);
	}
	if (sc.date < today.getDate()){
		return(0);
	}
	return(1);
}

function countdown(sc)
{
	var today,xday,count;

	today = new Date();
	xday = new Date(sc.year,sc.month-1,sc.date);

	count = Math.ceil( (xday.getTime() - today.getTime()) / (24*60*60*1000) );
	return(count);
}

//スケジュールパネル作成
function MakeSchedulePanel(){
	var i,l,cd,cls;
	var Dispdata;

	Dispdata = '\n<table rules=all border="' + SB_Border + '" bgcolor="' + SB_bgcolor + '" cellspacing="' + SB_Cellspacing + '" class="WLSPBASE">\n';

	Dispdata =  Dispdata + "<tbody>\n";
	for (i = 0;i < Schedules;i++){

		if (Schedule_check(Schedule_data[i])){
			Dispdata = Dispdata + "<tr>\n";
			
			cls = "WLSPDAY" + Schedule_data[i].kind;
			
			Dispdata = Dispdata + '<td class="' + cls + '">';
			Dispdata = Dispdata + "<font color=\"" + Schedule_color[Schedule_data[i].kind] + "\">";
			Dispdata = Dispdata + '<span class="' + cls + '">';
			if (Schedule_data[i].year == 0){
				Dispdata = Dispdata + "毎年";
			}else{
				Dispdata = Dispdata + Schedule_data[i].year;
			}
			Dispdata = Dispdata + "/";
			if (Schedule_data[i].month == 0){
				Dispdata = Dispdata + "毎月";
			}else{
				Dispdata = Dispdata + Schedule_data[i].month;
			}
			Dispdata = Dispdata + "/";
			if (Schedule_data[i].date == 0){
				Dispdata = Dispdata + "毎日";
			}else{
				Dispdata = Dispdata + Schedule_data[i].date;
			}

			if (SB_countdown != 0){
				if ((Schedule_data[i].year != 0) && (Schedule_data[i].month != 0) &&  (Schedule_data[i].date != 0)){
					cd = countdown(Schedule_data[i]);
					if (cd > 0){
						Dispdata = Dispdata + "(あと"+cd+"日)";
					}else if (cd == 0){
						Dispdata = Dispdata + "(今日)";
					}else{
						Dispdata = Dispdata + "(終了)";
					}
				}else{
					Dispdata = Dispdata + " ";
				}
			}
			Dispdata = Dispdata + "<\/span>";
			Dispdata = Dispdata + "<\/font>";
			Dispdata = Dispdata + "<\/td>";

			cls = "WLSPDESC" + Schedule_data[i].kind;

			Dispdata = Dispdata + '<td class="' + cls + '">';
			Dispdata = Dispdata + "<font color=\"" + Schedule_color[Schedule_data[i].kind] + "\">";
			Dispdata = Dispdata + '<span class="' + cls + '">';
			Dispdata = Dispdata + " " + Schedule_data[i].desc + " ";
			if (Schedule_data[i].link.length > 0){
				Dispdata = Dispdata + "Link".link(Schedule_data[i].link);
			}
			Dispdata = Dispdata + "<br>";
			Dispdata = Dispdata + "<\/span>";
			Dispdata = Dispdata + "<\/font>";
			Dispdata = Dispdata + "<\/td>\n";
			Dispdata = Dispdata + "<\/tr>\n";
		}
	}
	Dispdata = Dispdata + "<\/tbody>\n<\/table>\n";

	return(Dispdata);
}

//スケジュールパネル表示(V1.xx互換)
function Schedule_panel(){
	var Dispdata;

	Dispdata = MakeSchedulePanel();

	document.write(Dispdata);
}

// 今日の表示文字列作成
function MakeTodayString(){

	var d,i,Year,Month,Da,Day,xw,xd,hol_name,Holiday_num;
	var Dispdata;
	var cls;
	
	cls = new Array("WLTDSUN","WLTDMON","WLTDTUE","WLTDWED","WLTDTHU","WLTDFRI","WLTDSAT","WLTDHOL");

	d = new Date();

	Year = d.getYear();
	if (Year < 1900){
		Year += 1900;
	}

	Month = d.getMonth() + 1;
	Da = d.getDate();
	Day = d.getDay();

	hol_name = "";

	Holiday_num = Holiday_check(Year,Month,Da,Day);

	if (Holiday_num != -1){
		if (Holiday_num == -2){
			hol_name = "振替休日";
		}else{
			hol_name = Holiday_data[Holiday_num].name;
		}
	}else{
		if (Day == 1){ //振替休日
			Holiday_num = Holiday_check(Year,Month,Da - 1,0);
			if (Holiday_num != -1){
				hol_name = "振替休日" + "(" + Holiday_data[Holiday_num].name + ")";
			}
		}
	}

	//Netscape Navigator3にswitchがあったらswitchなのに(;;
	if (Month == 3){
		if (CalcSyunbun(Year) == Da){
			hol_name = "春分の日";
		}
		if (Day == 1){
			if (CalcSyunbun(Year) == (Da-1)){
				hol_name = "振替休日(春分の日)";
			}
		}
	}

	if (Month == 9){
		if (CalcSyubun(Year) == Da){
			hol_name = "秋分の日";
		}
		if (Day == 1){
			if (CalcSyubun(Year) == (Da-1)){
				hol_name = "振替休日(秋分の日)";
			}
		}
	}
	Dispdata ="<font color=\"";

	if (hol_name != ""){
		Dispdata = Dispdata + Holiday_col + '" class="' + cls[7] + '">';
	}else{
		Dispdata = Dispdata + Week_col[Day] + '" class="' + cls[Day] + '">';
	}
	Dispdata = Dispdata + Year + "/"+ Month +"/" + Da +"(" + Week_str[Day] +") ";
	Dispdata = Dispdata + hol_name;
	Dispdata = Dispdata + "<\/font>";
	Dispdata = Dispdata + "<br>";

	return(Dispdata);
}

// 今日の表示(V1.xx互換)
function Today_disp(){
	var Dispdata;

	Dispdata = MakeTodayString();

	document.write(Dispdata);
}
