﻿<!-- Begin
var now = new Date();
var month_array = new Array("มกราคม","กุมภาพันธ์","มีนาคม","เมษายน","พฤษภาคม","มิถุนายน","กรกฎาคม","สิงหาคม","กันยายน","ตุลาคม","พฤศจิกายน","ธันวาคม");
document.write("<form name=date_list><table width=237  height=181 border=0 cellspacing=8  cellpadding=0 class=txtblack12  style='background:url(/images/calendar_bg.jpg) top left no-repeat'><tr><td bgcolor=#83dbdf align=left style='padding:5px'>");
document.write("<b>เดือน</b> <select name=month onchange=change_month(this.options.selectedIndex) class=txtblack12>");
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>"+month_array[i]);}

}
document.write("</select>");
document.write("</td><td bgcolor=#83dbdf style='padding:5px'>");
document.write ("<b>ปี</b> <select name=year onchange=change_year(this.options[this.options.selectedIndex]) class=txtblack12>");
for(i=1950;i<3000;i++)
{
 YearNow = now.getYear();
 if(YearNow < 1900){
	YearNow += 1900; 
 }
 if (YearNow != i)
 {document.write("<option value="+i+">"+i);}
 else
 {document.write("<option value="+i+" selected>"+i);}
}
document.write("</select></td></tr><tr><td colspan=2 align=left><center>");

document.write("<table border=0 cellspacing = 0 cellpading = 0 width=100%><tr  align=center>");
document.write("<td><b>จ</b></td><td><b>อ</b></td><td><b>พ</b></td><td><b>พฤ</b></td><td><b>ศ</b></td><td><b>ส</b></td><td ><b>อา</b></td>");
document.write("</tr><tr>");
for(j=0;j<6;j++)
{
 for(i=0;i<7;i++)
 {
   document.write("<td align=center id=d"+i+"r"+j+"></td>")
 }
 document.write("</tr>");
}

document.write("</table>");

document.write("</center></form></td></tr></table>");

var show_date = new Date();

function GetYear(date){
	var year = date.getYear();
	if(year < 1900){
		year += 1900; 
	}
	return year;
}
function set_cal(show_date)
{
begin_year = GetYear(show_date);
if(begin_year < 1900){
	begin_year += 1900; 
}
begin_day = new Date (begin_year,show_date.getMonth(),1);
begin_day_date = begin_day.getDay();
end_day = new Date (begin_year,show_date.getMonth()+1,1);
count_day = (end_day - begin_day)/1000/60/60/24;
input_table(begin_day_date,count_day);
}
set_cal(show_date);

function input_table(begin,count)
{
init();
j=0;
if (begin!=0){i=begin-1;}else{i=6}
for (c=1;c<count+1;c++)
{
 id = "d"+i+"r"+j;
 colum_name = document.getElementById(id);
 if ((now.getDate() == c)&&(show_date.getMonth() == now.getMonth())&&(GetYear(show_date) == GetYear(now))) {colum_name.style.backgroundColor = "#83dbdf";colum_name.style.color = "white";};
 colum_name.innerHTML =  c;
 i++;
 if (i==7){i=0;j++;}
}
}

function init()
{
for(j=0;j<6;j++)
{
 for(i=0;i<7;i++)
 {
 id = "d"+i+"r"+j;
 colum_name = document.getElementById(id);
 colum_name.innerHTML =  "-";
 colum_name.style.backgroundColor ="";
 colum_name.style.color ="";
 }
}
}

function change_month(sel_month)
{
show_date = new Date(GetYear(show_date),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);
}
//  End -->

