#!/usr/bin/perl
@month = ( "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug",
    "Sep", "Oct", "Nov", "Dec" );
@days = ( 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 );
@day = ( "S", "M", "T", "W", "T", "F", "S" );


sub days
{
	local ($ndays) = @_;

	print "  <TR><TH>\n";
	for (my $i = 1; $i <= $ndays; $i++) {
		print "    <TH bgcolor=\"#2020c0\"><FONT color=\"#ffffff\">",
		    $i, "\n";
	}
}


sub month
{
	local ($month, $ndays, $first_sunday) = @_;

	if ($month & 1) {
		print "  <TR bgcolor=\"#ffffff\">\n";
	} else {
		print "  <TR bgcolor=\"#f2f2f2\">\n";
	}
	print "    <TH bgcolor=\"#208020\"><FONT color=\"#ffffff\">",
	    $month[$month], "\n";
	my $i;
	for ($i = 1; $i <= $ndays; $i++) {
		my $dow = ($i-1-$first_sunday) % 7;

		print "\t<TD align=\"center\" width=\"16\">";
		if ($dow) {
			print "<FONT color=\"#000000\" face=\"sans\">";
		} else {
			print "<FONT color=\"#ff0000\" face=\"sans\">";
		}
		print $day[$dow], "</TD>\n";
	}
	while ($i++ <= 31) {
		print "\t<TD></TD>\n";
	}
	print "\t</TR>\n";
}

print "<TABLE>\n";
&days(31);
$sunday = 0;
for ($i = 0; $i != 6; $i++) {
	&month($i, $days[$i], $sunday);
	$sunday = ($sunday-$days[$i]) % 7;
}
&days(31);
for (; $i != 12; $i++) {
	&month($i, $days[$i], $sunday);
	$sunday = ($sunday-$days[$i]) % 7;
}
&days(31);
