
function DaysInMonth(Y, M) {
    with (new Date(Y, M, 1, 12)) {
        setDate(0);
        return getDate();
    }
}

function getNowMonth(mon,yea)
{
	mon=mon+1;
	var D = new Date(mon+"/01/"+yea);
		
	var ar = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
	var df = ar[mon-1];
	df = df+", "+D.getFullYear();
	return df;
}

function getDate(num, mon, yea)
{
	//mon=mon+1;
	var current_day = exd.getDate();
	var days = DaysInMonth(yea,mon);
	var D = new Date(mon+"/01/"+yea);
	var day = D.getDay();
	var res = "<td class=\"pad\" colspan=\"1\">&nbsp;</td>";
	
	var ss = 1;
	num = num - 1;
	if (num == current_day)
	res = "<td id=\"now\">" + current_day + "</td>";
	else
	for(var xx=day; xx<day+days; xx++){
		if (xx == num)
			res = "<td>" + ss + "</td>";
		ss++;
	}
	
	return res;
}

var exd = new Date();
var monthe = exd.getMonth();
var yeare = exd.getFullYear();

function prev()
{
	monthe = monthe-1;
	if(monthe < 0)
	{
		yeare = yeare-1;	
		monthe = 11;
	}
	setcal(monthe, yeare);
	return false;
}

function next()
{
	monthe = monthe+1;
	if(monthe > 11)
	{
		yeare = yeare+1;	
		monthe = 0;
	}
	setcal(monthe, yeare);
	return false;
}

document.write("<table id=\"calendar2\" summary=\"Calendar\"><caption>"+getNowMonth(monthe, yeare)+
						"</caption>\
						<thead>\
							<tr>\
								<th abbr=\"Monday\" scope=\"col\" title=\"Monday\">M</th>\
								<th abbr=\"Tuesday\" scope=\"col\" title=\"Tuesday\">T</th>\
								<th abbr=\"Wednesday\" scope=\"col\" title=\"Wednesday\">W</th>\
								<th abbr=\"Thursday\" scope=\"col\" title=\"Thursday\">T</th>\
								<th abbr=\"Friday\" scope=\"col\" title=\"Friday\">F</th>\
								<th abbr=\"Saturday\" scope=\"col\" title=\"Saturday\">S</th>\
								<th abbr=\"Sunday\" scope=\"col\" title=\"Sunday\">S</th>\
							</tr>\
						</thead>\
						<tbody>");
for(var xx=0; xx<6; xx++)
{
	document.write("<tr>");
	for(var cc=0; cc<7; cc++){
		var dd = xx*7+cc;
		document.write(getDate(dd, monthe, yeare));
	}
	document.write("</tr>");
}

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