//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 = 107;
//ここはいじらないで下さい。
	Schedule_data = new Array(Schedules);
//ここまで

//スケジュールを記述する際は、注釈に従って記述し、[]内の番号を
//(スケジュールの数-1)の範囲内で、重複しないようにして下さい。
//会社の休日>>ここから>>
	Schedule_data[0] = new schedule(0,1,1,"","",1);
	Schedule_data[1] = new schedule(0,1,2,"","",1);
	Schedule_data[2] = new schedule(0,1,3,"","",1);
	Schedule_data[3] = new schedule(0,1,4,"","",1);
	Schedule_data[4] = new schedule(0,1,8,"","",1);
	Schedule_data[5] = new schedule(0,1,9,"","",1);
	Schedule_data[6] = new schedule(0,1,14,"","",1);
	Schedule_data[7] = new schedule(0,1,15,"","",1);
	Schedule_data[8] = new schedule(0,1,21,"","",1);
	Schedule_data[9] = new schedule(0,1,22,"","",1);
	Schedule_data[10] = new schedule(0,1,29,"","",1);
	Schedule_data[11] = new schedule(0,2,4,"","",1);
	Schedule_data[12] = new schedule(0,2,5,"","",1);
	Schedule_data[13] = new schedule(0,2,11,"","",1);
	Schedule_data[14] = new schedule(0,2,12,"","",1);
	Schedule_data[15] = new schedule(0,2,18,"","",1);
	Schedule_data[16] = new schedule(0,2,19,"","",1);
	Schedule_data[17] = new schedule(0,2,26,"","",1);
	Schedule_data[18] = new schedule(0,3,3,"","",1);
	Schedule_data[19] = new schedule(0,3,4,"","",1);
	Schedule_data[20] = new schedule(0,3,10,"","",1);
	Schedule_data[21] = new schedule(0,3,11,"","",1);
	Schedule_data[22] = new schedule(0,3,17,"","",1);
	Schedule_data[23] = new schedule(0,3,18,"","",1);
	Schedule_data[24] = new schedule(0,3,25,"","",1);
	Schedule_data[25] = new schedule(0,3,31,"","",1);
	Schedule_data[26] = new schedule(0,4,1,"","",1);
	Schedule_data[27] = new schedule(0,4,7,"","",1);
	Schedule_data[28] = new schedule(0,4,8,"","",1);
	Schedule_data[29] = new schedule(0,4,15,"","",1);
	Schedule_data[30] = new schedule(0,4,21,"","",1);
	Schedule_data[31] = new schedule(0,4,22,"","",1);
	Schedule_data[32] = new schedule(0,4,29,"","",1);
	Schedule_data[33] = new schedule(0,5,3,"","",1);
	Schedule_data[34] = new schedule(0,5,4,"","",1);
	Schedule_data[35] = new schedule(0,5,5,"","",1);
	Schedule_data[36] = new schedule(0,5,6,"","",1);
	Schedule_data[37] = new schedule(0,5,12,"","",1);
	Schedule_data[38] = new schedule(0,5,13,"","",1);
	Schedule_data[39] = new schedule(0,5,19,"","",1);
	Schedule_data[40] = new schedule(0,5,20,"","",1);
	Schedule_data[41] = new schedule(0,5,27,"","",1);
	Schedule_data[42] = new schedule(0,6,2,"","",1);
	Schedule_data[43] = new schedule(0,6,3,"","",1);
	Schedule_data[44] = new schedule(0,6,9,"","",1);
	Schedule_data[45] = new schedule(0,6,10,"","",1);
	Schedule_data[46] = new schedule(0,6,16,"","",1);
	Schedule_data[47] = new schedule(0,6,17,"","",1);
	Schedule_data[48] = new schedule(0,6,23,"","",1);
	Schedule_data[49] = new schedule(0,6,24,"","",1);
	Schedule_data[50] = new schedule(0,6,30,"","",1);
	Schedule_data[51] = new schedule(0,7,1,"","",1);
	Schedule_data[52] = new schedule(0,7,7,"","",1);
	Schedule_data[53] = new schedule(0,7,8,"","",1);
	Schedule_data[54] = new schedule(0,7,15,"","",1);
	Schedule_data[55] = new schedule(0,7,16,"","",1);
	Schedule_data[56] = new schedule(0,7,21,"","",1);
	Schedule_data[57] = new schedule(0,7,22,"","",1);
	Schedule_data[58] = new schedule(0,7,29,"","",1);
	Schedule_data[59] = new schedule(0,8,4,"","",1);
	Schedule_data[60] = new schedule(0,8,5,"","",1);
	Schedule_data[61] = new schedule(0,8,11,"","",1);
	Schedule_data[62] = new schedule(0,8,12,"","",1);
	Schedule_data[63] = new schedule(0,8,13,"","",1);
	Schedule_data[64] = new schedule(0,8,14,"","",1);
	Schedule_data[65] = new schedule(0,8,15,"","",1);
	Schedule_data[66] = new schedule(0,8,18,"","",1);
	Schedule_data[67] = new schedule(0,8,19,"","",1);
	Schedule_data[68] = new schedule(0,8,26,"","",1);
	Schedule_data[69] = new schedule(0,9,1,"","",1);
	Schedule_data[70] = new schedule(0,9,2,"","",1);
	Schedule_data[71] = new schedule(0,9,8,"","",1);
	Schedule_data[72] = new schedule(0,9,9,"","",1);
	Schedule_data[73] = new schedule(0,9,16,"","",1);
	Schedule_data[74] = new schedule(0,9,17,"","",1);
	Schedule_data[75] = new schedule(0,9,22,"","",1);
	Schedule_data[76] = new schedule(0,9,23,"","",1);
	Schedule_data[77] = new schedule(0,9,29,"","",1);
	Schedule_data[78] = new schedule(0,9,30,"","",1);
	Schedule_data[79] = new schedule(0,10,6,"","",1);
	Schedule_data[80] = new schedule(0,10,7,"","",1);
	Schedule_data[81] = new schedule(0,10,8,"","",1);
	Schedule_data[82] = new schedule(0,10,13,"","",1);
	Schedule_data[83] = new schedule(0,10,14,"","",1);
	Schedule_data[84] = new schedule(0,10,20,"","",1);
	Schedule_data[85] = new schedule(0,10,21,"","",1);
	Schedule_data[86] = new schedule(0,10,28,"","",1);
	Schedule_data[87] = new schedule(0,11,3,"","",1);
	Schedule_data[88] = new schedule(0,11,4,"","",1);
	Schedule_data[89] = new schedule(0,11,10,"","",1);
	Schedule_data[90] = new schedule(0,11,11,"","",1);
	Schedule_data[91] = new schedule(0,11,17,"","",1);
	Schedule_data[92] = new schedule(0,11,18,"","",1);
	Schedule_data[93] = new schedule(0,11,23,"","",1);
	Schedule_data[94] = new schedule(0,11,24,"","",1);
	Schedule_data[95] = new schedule(0,11,25,"","",1);
	Schedule_data[96] = new schedule(0,12,1,"","",1);
	Schedule_data[97] = new schedule(0,12,2,"","",1);
	Schedule_data[98] = new schedule(0,12,8,"","",1);
	Schedule_data[99] = new schedule(0,12,9,"","",1);
	Schedule_data[100] = new schedule(0,12,15,"","",1);
	Schedule_data[101] = new schedule(0,12,16,"","",1);
	Schedule_data[102] = new schedule(0,12,23,"","",1);
	Schedule_data[103] = new schedule(0,12,24,"","",1);
	Schedule_data[104] = new schedule(0,12,29,"","",1);
	Schedule_data[105] = new schedule(0,12,30,"","",1);
	Schedule_data[106] = new schedule(0,12,31,"","",1);
//<<ここまで

//各曜日の名前
	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[5] = new Holiday("2007-",4,29,"昭和の日");
	Holiday_data[6] = new Holiday("1949-",5,3,"憲法記念日");
	Holiday_data[7] = new Holiday("1986-",5,4,"国民の休日");
	Holiday_data[8] = new Holiday("2007-",5,4,"みどりの日");
//	Holiday_data[8] = new Holiday("1949-",5,5,"こどもの日");
	Holiday_data[9] = new Holiday("1996-2002",7,20,"海の日");
	Holiday_data[9] = new Holiday("2003-",7,131,"海の日");
	Holiday_data[10] = new Holiday("1966-2002",9,15,"敬老の日");
	Holiday_data[10] = new Holiday("2003-",9,131,"敬老の日");
	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 = 1;
//枠線の表示形式 none:なし rows:横列の境界のみ cols:縦列の境界のみ
	rules="";


//表示色(スタイルシートで指定している場合はスタイルシートが優先されます。)
//背景色は""を指定すると透明になります。
//各曜日の色
	Week_col = new Array("red","black","black","black","black","black","blue");
//曜日表示部分の背景色
//	Daybg_col = "White";
	Daybg_col = "#99CCCC";
//各曜日の背景色(日曜/祝日,月曜,...,金曜,土曜の順)
//	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 = "#FF99FF";
//	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 width="150" border="0" cellpadding="0" cellspacing="1"  bgcolor="#999999">\n';

//曜日表示
	for (i = 0;i < 7;i++){
		cls = "WLNAME" + class_str[i];

		bg_col = WeekName_BGcol[i];
		dsp = dsp + '<td align="center" bgcolor="#99CC99">';

		fg_col = Week_col[i];
		dsp = dsp + "<font color=" + fg_col +">";
		dsp = dsp + '<span class="' + cls + '">';
		dsp = dsp + Week_str[i];
		dsp = dsp + "<\/span>";
		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 bgcolor="#FFFFFF">&nbsp<\/td>';
	}
//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;
		}
	
		dsp = dsp + ' bgcolor="#FFFFFF" class="' + cls +  '">';
		
		if (isToday){	//2.00以降
			dsp = dsp + "<b>";
		}
		dsp = dsp + "<font color=" + fg_col +">";
		dsp = dsp + "<span class=" + cls +">";
		dsp = dsp + i;
		dsp = dsp + "<\/span>";
		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++){
		dsp = dsp + '<td bgcolor="#FFFFFF">&nbsp<\/td>';
		tw++;
	}
	cols++;
	if (cols < 6){
		dsp = dsp  + "<\/tr>\n<tr>\n";
		for (i = 0;i < 7;i++){
			dsp = dsp + '<td bgcolor="#FFFFFF">&nbsp<\/td>';
		}
	}
	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);
}
