var o = new Object();


o['20100828'] = 1;

o['20090622'] = 1;

o['20090412'] = 1;

o['20090307'] = 1;

o['20090102'] = 1;

o['20081126'] = 1;

o['20081117'] = 1;

o['20081004'] = 1;

o['20080903'] = 1;

o['20080730'] = 1;

o['20080727'] = 1;

o['20080708'] = 1;

o['20080602'] = 1;

o['20071119'] = 1;

o['20070914'] = 1;

o['20070809'] = 1;

o['20070707'] = 1;

o['20070624'] = 1;

o['20070610'] = 1;

o['20070419'] = 1;

o['20070213'] = 1;

o['20070202'] = 1;

o['20070118'] = 1;

o['20070110'] = 1;

o['20061204'] = 1;

o['20061107'] = 1;

o['20060929'] = 1;

o['20060906'] = 1;

o['20060808'] = 1;

o['20060728'] = 1;

o['20060717'] = 1;

o['20060710'] = 1;

o['20060705'] = 1;

o['20060510'] = 1;

o['20060504'] = 1;

o['20060501'] = 1;

o['20060313'] = 1;

o['20060312'] = 1;

o['20060222'] = 1;

o['20060118'] = 1;

o['20060110'] = 1;

o['20060105'] = 1;

o['20051227'] = 1;

o['20051223'] = 1;

o['20051220'] = 1;

o['20051219'] = 1;

o['20051207'] = 1;

o['20051130'] = 1;

o['20051121'] = 1;

o['20051114'] = 1;

o['20051101'] = 1;

o['20051027'] = 1;

o['20051021'] = 1;

o['20051014'] = 1;



function pad(num,digits) {
    var ret = num.toString();
    while (ret.length < digits) { ret = '0' + ret; }
    return ret;
}

function make_calendar(mo,yr) {
    var caldiv = document.getElementById('calendar');
    caldiv.innerHTML = '';
    var caldate, txt, thism, thisy;
    var days= Array(31,28,31,30,31,30,31,31,30,31,30,31);
    var monthnames = Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
    var item,tmpString,mindate,maxdate;

    mindate = ''; maxdate = '';
    for (item in o) {  // check all dates for min/max
        var tmpString = item.substring(0,6);
        if (mindate == '' || tmpString < mindate) { mindate = tmpString; }
        if (maxdate == '' || tmpString > maxdate) { maxdate = tmpString; }
    }
        

    if (mo == 0 || yr == 0) {
        var thisdate = new Date();
        thism = thisdate.getMonth();
        thisy = thisdate.getYear();
        if (thisy < 2005) { thisy += 1900; }
    } else {
        thism = mo - 1;
        thisy = yr;
    }
    if (thisy % 4 == 0 && (thisy % 100 != 0 || thisy % 400 == 0)) {  // leap year check
        ++days[1];
    }
    
    caldate = new Date(thisy+'/'+(thism+1)+'/01');

    txt = '<table><tr><td>';
    if (pad(thisy - 1,4) + pad(thism + 1,2) >= mindate) {
        txt = txt + '<a href="javascript:void(0)" onclick="make_calendar(' + (thism + 1) + ',' + (thisy - 1) + ')">&#171;</a>';
    } else {
        txt = txt + ' &#171; ';
    }
    txt = txt + '</td> <td>';
    if (thism == 0) {
        if ((thisy-1).toString() + '12' >= mindate) {
            txt = txt + '<a href="javascript:void(0)" onclick="make_calendar(12,'+(thisy-1)+')">&lt;</a>';
        } else {
            txt = txt + '&lt; ';
        }
    } else {
        if (pad(thisy,4) + pad(thism,2) >= mindate) {
            txt = txt + '<a href="javascript:void(0)" onclick="make_calendar('+thism+','+thisy+')">&lt;</a>';
        } else {
            txt = txt + '&lt; ';
        }
    }
    txt = txt + '</td> <td colspan="3"> ' + monthnames[thism] + ' ' + thisy + ' </td> ';
    txt = txt + '<td> ';
    if (thism == 11) {
        if (pad(thisy+1,4)+'01' <= maxdate) {
            txt = txt + '<a href="javascript:void(0)" onclick="make_calendar(1,'+(thisy+1)+')">&gt;</a>';
        } else {
            txt = txt + '&gt; ';
        }
    } else {
        if (pad(thisy,4) + pad(thism + 2, 2) <= maxdate) {
            txt = txt + '<a href="javascript:void(0)" onclick="make_calendar('+(thism+2)+','+thisy+')">&gt;</a>';
        } else {
            txt = txt + '&gt; ';
        }
    }
    
    txt = txt + '</td> <td> ';
    if (pad(thisy + 1,4) + pad(thism+1,2) <= maxdate) {
        txt = txt + '<a href="javascript:void(0)" onclick="make_calendar('+(thism+1)+','+(thisy + 1) + ')">&#187</a>';
    } else {
        txt = txt + '&#187; ';
    }
    txt = txt + '</td> </tr> ' +
        '<tr><th> Su </th> <th> Mo </th> <th> Tu </th> <th> We </th> <th> Th </th> <th> Fr </th> <th> Sa </th> </tr> <tr> ';

    col = 1;
    rows = 1;
    for (d = 1; d <= caldate.getDay(); ++d) { txt = txt + ' <td> </td> '; ++col; }
    
    for (d = 1; d <= days[thism]; ++d) {
        if (col > 7) {
            txt = txt + ' </tr> <tr> ';
            col = 1;
            ++rows;
        }
        txt = txt + ' <td> ';
        if (o[thisy + pad(thism + 1,2) + pad(d,2)]) { txt = txt + '<a href="/archive/'+thisy+'/'+pad(thism+1,2)+'/'+pad(d,2)+'/">'+d+'</a>'; } else { txt = txt + d; }
        txt = txt + ' </td> ';
        ++col;
    }
    if (col <= 7) {
        for (d = col; d <= 7; ++d) {
            txt = txt + ' <td> </td> ';
        }
    }
    txt = txt + ' </tr> ';
    while (rows < 6) { txt = txt + '<tr> <td colspan="7"> &nbsp; </td> </tr> '; ++rows; }
    txt = txt + '</table>';

    caldiv.innerHTML = txt;
    
    return true;
}