// Generate month heading.
function MonthHeading(nYear, nMonth, nPosInList) {
    var sCurrent, sPrev, sNext;

    sCurrent = nYear + "-" + nMonth;
    if(nMonth == 1) {
        sPrev = "#" + (nYear - 1) + "-12";
        sNext = "#" + nYear + "-2";
    } else if(nMonth == 12) {
        sPrev = "#" + nYear + "-11";
        sNext = "#" + (nYear + 1) + "-1";
    } else {
        sPrev = "#" + nYear + "-" + (nMonth - 1);
        sNext = "#" + nYear + "-" + (nMonth + 1);
    }

    if(nPosInList == 1) { // top of archive
        sPrev = "#Top";
    } else if(nPosInList == 2) { // bottom of archive
        sNext = "events.html" + sNext;
    } else if(nPosInList == 3) { // top of current
        sPrev = "eventsarchive.html" + sPrev;
    } else if(nPosInList == 4) { // bottom of current
        sNext = "#RegularEvents";
    }

    document.write("<a name='" + sCurrent + "'>" + MonthName(nMonth) + " " + nYear + "</a>");
    document.write("&nbsp;&nbsp;");
    document.write("&nbsp;<a href='#Top'><img src='images/ArrowTop.gif' alt='Top' border='0' width='25' height='16' align='middle'></a>");
    document.write("&nbsp;<a href='" + sPrev + "'><img src='images/ArrowPrev.gif' alt='Previous' border='0' width='25' height='16' align='middle'></a>");
    document.write("&nbsp;<a href='" + sNext + "'><img src='images/ArrowNext.gif' alt='Next' border='0' width='25' height='16' align='middle'></a>");
}

// Generate month link.
function MonthLink(nYear, nMonth) {
    var sCurrent;

    sCurrent = "#" + nYear + "-" + nMonth;

    document.write("<a href='" + sCurrent + "'>" + MonthName(nMonth) + "</a>");
}

// Jump to the current month heading after the page is loaded (requires at least IE4 to work).
function JumpToCurrentMonth() {
    var dtCurrent = new Date();

    if(location.hash == "") {
        location.href = "#" + dtCurrent.getUTCFullYear() + "-" + (dtCurrent.getUTCMonth() + 1);
    }
}

// Generate an ordinal number.
function Ord(nNumber) {
    document.write(nNumber);

    switch(nNumber) {
    case 1:
    case 21:
    case 31:
        document.write("<sup>st</sup>");
        break;
    case 2:
    case 22:
        document.write("<sup>nd</sup>");
        break;
    case 3:
    case 23:
        document.write("<sup>rd</sup>");
        break;
    default:
        document.write("<sup>th</sup>");
        break;
    }
}

// Generate the name of a given month.
function MonthName(nMonth) {

    switch(nMonth) {
    case 1:
        return "January";
    case 2:
        return "February";
    case 3:
        return "March";
    case 4:
        return "April";
    case 5:
        return "May";
    case 6:
        return "June";
    case 7:
        return "July";
    case 8:
        return "August";
    case 9:
        return "September";
    case 10:
        return "October";
    case 11:
        return "November";
    case 12:
        return "December";
    default:
        return "";
    }
}

// Generate street mapping hyperlinks for a given postcode.
function PostCode(sPC1, sPC2) {
    document.write(sPC1 + " " + sPC2 + " (");
    document.write("<a href='http://www.streetmap.co.uk/streetmap.dll?postcode2map?code=" + sPC1 + "+" + sPC2 + "' target='_blank'>StreetMap</a>");
    document.write("/");
    document.write("<a href='http://uk.multimap.com/p/browse.cgi?pc=" + sPC1 + sPC2 + "' target='_blank'>MultiMap</a>");
    document.write(")");
}
