  function showCalendar(element, formfield) {
    showCalendarOnDate(element, formfield, '*', '*');
  }

  function showCalendarOnDate(element, formfield, month, year) {
    days = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
    months = ["January", "February", "March", "April", "May", "June", "July",
    "August", "September", "October", "November", "December"]
    today = new Date();
    // Note - months > 11 (december in 0 based months) will advance the year by
    // 1 - hence the apparant weirdness of the method below.
    if (year != '*') today.setYear(year);
    if (month != '*') today.setMonth(month);
    year = today.getYear();
    if (year < 2000) { year += 1900; }
    month = today.getMonth();
    /* Nice trick to get number of days in the month
    */
    daysinmonth = 32 - new Date(year, month, 32).getDate();
    output = "<table class=\"calendartable\">";

    // Month header
    output += "<tr><th colspan=\"1\"><a href=\"javascript:showCalendarOnDate('"
    + element + "','" + formfield + "'," + (month - 1) + "," + year + ")\">" +
    "&lt;</a></th>" +
    "<th colspan=\"5\">" + months[month] + " " + year + "</th>" +
    "<th colspan=\"1\"><a href=\"javascript:showCalendarOnDate('" +
    element + "','" + formfield + "'," + (month + 1) + "," + year + ")\">" +
    "&gt;</a></th></tr>";

    // Days of the week header
    output += "<tr>";
    for (d = 0; d< 7; d++) {
        output += "<th>" + days[d] + "</th>";
    }
    output += "</tr>"

    // Pad the beginning of the month with blank cells
    daymonthstarts = new Date(year, month, 1).getDay();
    if (daymonthstarts != 0) {
        output += "<tr>";
        for (d = 0; d< daymonthstarts; d++) {
            output += "<td>&nbsp;</td>";
        }
    }

    // Now put the actual dates in
    currentday = daymonthstarts;
    for (d = 0; d < daysinmonth; d++) {
        if (currentday == 0) output += "<tr>";
        // TODO - generate table here
        output += "<td><a href=\"javascript:writeDate('" + element + "','" +
        formfield + "','" + (d + 1) + "/" + (month + 1)+ "/" + year + "')\">"
        + (d + 1) + "</a></td>";
        if (currentday == 6) {
            output += "</tr>";
            currentday = 0;
        } else {
            currentday++;
        }
    }

    // Pad the end of the month
    if (currentday != 0) {
        for (d = currentday; d<7; d++) {
            output += "<td>&nbsp;</td>";
        }
    }
    output += "</tr>";
    output += "</table>";
    document.getElementById(element).innerHTML = output
    document.getElementById(element).style.visibility = "visible";
  }

  function writeDate(element, formelement, date) {
        document.getElementById(formelement).value = date;
        document.getElementById(element).style.visibility = "hidden";
  }
