function EmitCalendarItemHeader(sItemHeaderText, sWidth)
{
  document.writeln("    <td class='clsTableTopHeader' width='" + sWidth + "'>");
  document.write("      ");
  document.writeln(sItemHeaderText);
  document.writeln("    </td>");
}

function EmitCalendarHeader()
{
  document.writeln("<table width='100%' border='1'>");
  document.writeln("  <tr>");
  EmitCalendarItemHeader("Date", "20%");
  EmitCalendarItemHeader("Time", "20%");
  EmitCalendarItemHeader("Event", "20%");
  EmitCalendarItemHeader("Location", "40%");
  document.writeln("  </tr>");
}

function EmitCalendarFooter()
{
  document.writeln("</table>");
}

function WriteCellContent(strCellContent, strCellLink)
{
  if (strCellContent.length == 0)
  {
    document.writeln("&nbsp;");
  }
  else if (strCellLink.length == 0)
  {
    document.writeln(strCellContent);
  }
  else
  {
    document.writeln("<a href='" + strCellLink + "'>" + strCellContent + "</a>");
  }
}

function EmitCalendarItem(lCalItem)
{
  document.writeln("  <tr>");

  // Date
  document.writeln("    <td class='clsCalendarCell'>");
  document.write("      ");
  
  WriteCellContent(lCalItem[0], "");
  document.writeln("    </td>");

  // Time
  document.writeln("    <td class='clsCalendarCell'>");
  document.write("      ");
  WriteCellContent(lCalItem[1], "");
  document.writeln("    </td>");

  // Event
  document.writeln("    <td class='clsCalendarCell'>");
  document.write("      ");
  WriteCellContent(lCalItem[2], lCalItem[4]);
  document.writeln("    </td>");

  // Location
  document.writeln("    <td class='clsCalendarCell'>");
  document.write("      ");
  WriteCellContent(lCalItem[3], "");
  document.writeln("    </td>");
}

function EmitCalendar()
{
  var iCalItem;

  EmitCalendarHeader();

  for (iCalItem in lCalContent)
  {
    EmitCalendarItem(lCalContent[iCalItem]);
  }

  EmitCalendarFooter();
}

