#!/usr/bin/perl

print
    "<table style=\"border-collapse: collapse\">",
    "<tr style=\"background-color: #aaaaff\">",
    "<th style=\"width: 40px\">Date</th>",
    "<th style=\"width: 100px\">Topic</th>",
    "<th style=\"width: 225px\">Reading Assignments</th>",
    "<th style=\"width: 200px\">Writing Assignments, etc.</th>",
    "</tr>\n";

while (<>) {
    s/^\#.*//;
    if (/[a-zA-Z\|\*\+]/) {
	$buffer .=$_;
    } else {
	&print_buffer;
	$buffer = "";
	next;
    }
    
}

print "</table>";

sub print_buffer {
    return unless $buffer;
    my ($date,$topic,$readings,$events) = split(/\|/,$buffer);
    
    my $bgcolor = '#ffffff';
    if ($date =~ /week/i) {
	$bgcolor = '#eeeedd';
	print
	    "<tr style=\"background-color: $bgcolor\">",
	    "<th colspan=\"4\" style=\"text-align: left; font-weight: bold\">",
	    $date,
	    "</th></tr>";
    } else {
	
	
	print
	    "<tr style=\"background-color: $bgcolor;font-size:12px\">",
	    "<th valign=\"top\" align=\"left\">$date</th>",
	    "<td valign=\"top\">$topic</td>",
	    "<td valign=\"top\">$readings</td>",
	    "<td valign=\"top\">$events</td>",
	    "</tr>\n";
    }
}
