var now = new Date();
var nowyear = (now.getYear()+543);
var month_array = new Array("January", "February", "March", "April", "May", "June","July", "August", "September", "October", "November", "December");
var show_date = new Date();

function show_cal()
{
document.write('<form name=date_list><table cellspacing=1 cellpadding=1 border=0 width=100%><tr class=text1><td>');
document.write("<select name=month onchange=change_month(this.options.selectedIndex) class=text1>");
for(i=0;i<month_array.length;i++)
{
	if (now.getMonth() != i)
	{document.write ("<option value="+i+">"+month_array[i]);}
	else
	{document.write ("<option value="+i+" selected style=\"background-color:#FFFFCC;\">"+month_array[i]);}
}
document.write("</select>");
document.write("</td><td>");
document.write ("<select name=year onchange=change_year(this.options[this.options.selectedIndex]) class=text1>");
for(i=2004;i<=(now.getYear()+5);i++)
{
	b = i + 543;
	if (now.getYear() != i)
	{document.write("<option value="+i+">"+b);}
	else
	{document.write("<option value="+i+" selected style=\"background-color:#FFFFCC;\">"+b);}
}
document.write("</select></td></tr><tr><td colspan=2><center>");

document.write("<table bgcolor=#f5f5ff border=0 cellspacing = 0 cellpading = 0 width=98%><tr bgcolor=#f5f5f5 align=center >");
document.write("<td class=text><font color=#333300>Sun</font></td><td class=text><font color=333300>Mon</td><td class=text><font color=333300>Tue</td><td class=text><font color=333300>Wed</td><td class=text><font color=333300>Thu</td><td  class=text><font color=333300>Fri</td><td  class=text><font color=333300>Sat</td>");
document.write("</tr><tr class=text1>");
for(j=0;j<6;j++)
{
	for(i=0;i<7;i++)
	{
		document.write("<td align=center class=text1 id=d"+i+"r"+j+"></td>")
	}
	document.write("</tr>");
}

document.write("</table>");
document.write("</center></from></td></tr></table>");

set_cal(show_date);
}

function set_cal(show_date)
{
	begin_day = new Date (show_date.getYear(),show_date.getMonth(),1);
	begin_day_date = begin_day.getDay();
	end_day = new Date (show_date.getYear(),show_date.getMonth()+1,1);
	count_day = (end_day - begin_day)/1000/60/60/24;
	input_table(begin_day_date,count_day);
}

function input_table(begin,count)
{
	init();
	j=0;
	if (begin!=0){i=begin-1;}else{i=6}
	for (c=1;c<count+1;c++)
	{
		colum_name = eval("d"+i+"r"+j);
		if ((now.getDate() == c)&&(show_date.getMonth() == now.getMonth())&&(show_date.getYear() == now.getYear())) {
			colum_name.style.backgroundColor = "orange";
			colum_name.style.color = "white";
			}

		//var value = c+"/"+show_date.getMonth()+"/"+show_date.getYear();
		var value = show_date.getYear()+"-"+show_date.getMonth()+"-"+c;
		colum_name.innerHTML = '<a href="javascript:show_cal_list('+c+','+(show_date.getMonth()+1)+','+show_date.getYear()+')" class=text111 title=\"'+c+' '+month_array[show_date.getMonth()]+' '+nowyear+'"><font color=#330000>'+c+'</font></a>';

		i++;
		if (i==7){i=0;j++;}
	}
}

function init()
{
	for(j=0;j<6;j++)
	{
		for(i=0;i<7;i++)
		{
			colum_name = eval("d"+i+"r"+j);
			colum_name.innerHTML = "&nbsp;";
			colum_name.style.backgroundColor ="";
			colum_name.style.color ="";
		}
	}
}

function change_month(sel_month)
{
	show_date = new Date(show_date.getYear(),sel_month,1);
	set_cal(show_date);
}

function change_year(sel_year)
{
	sel_year = sel_year.value;
	show_date = new Date(sel_year,show_date.getMonth(),1);
	set_cal(show_date);
}

function show_cal_list(dd,mm,yy)
{
	var wincal =  null
	var ww = 450;
	var hh = 500;
	ll = (screen.availWidth-ww)/2;
	tt = (screen.availHeight-hh)/2;
//	alert(ll);
	wincal = window.open("callist.php?d="+dd+"&m="+mm+"&y="+yy, "wincal", "left="+ll+",top="+tt+",width="+ww+",height="+hh+",status=no,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes");
	wincal.focus();

}
