var strTargetDiv;
var curmonth;
var curyear;
var entryType;

function previousMonth()
    {
        var todaydate = new Date()
        curmonth -= 1 //get previous month (1-12)        
        if (curmonth < 1)
            {
                curmonth = 12;
                curyear = curyear-1;
            }
        LoadCalendar(curmonth, curyear, "calendarMain", "calendarMonth", "calendarDaysOfWeek", "calendarDays", 0);
    }

function nextMonth()
    {
        var todaydate = new Date()
        curmonth += 1 //get next month (1-12)
        if (curmonth > 12)
            {
                curmonth = 1;
                curyear = curyear+1;
            }        
        LoadCalendar(curmonth, curyear, "calendarMain", "calendarMonth", "calendarDaysOfWeek", "calendarDays", 0);
    }

function buildCalendar(m, y, cM, cH, cDW, cD, brdr)
    {
        var mn = ['January','February','March','April','May','June','July','August','September','October','November','December'];
        var dim = [31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

        var oD = new Date(y, m - 1, 1); //DD replaced line to fix date bug when current day is 31st
        oD.od=oD.getDay()+1; //DD replaced line to fix date bug when current day is 31st

        var todaydate = new Date() //DD added
        var scanfortoday = (y == todaydate.getFullYear() && m == todaydate.getMonth() + 1) ? todaydate.getDate() : 0 //DD added

        dim[1] = (((oD.getFullYear() % 100 != 0) && (oD.getFullYear() % 4 == 0)) || (oD.getFullYear() % 400 == 0)) ? 29 : 28;
        var t = '<div><table class="' + cM + '" cols="7" cellpadding="0" border="' + brdr + '" cellspacing="0"><tr align="center">';
        t += '<td colspan="1" valign="bottom" class="' + cH + '">' + '<a href="javascript:void(0);" onclick="javascript:previousMonth();" title="Go to the previous month"><img src="/Images/Blog/arrowPrevious.gif" /></a>' + '</td>';
        if (EntryMonthList.indexOf(m + '/' + y) >= 0)
            t += '<td colspan="5" align="center" class="' + cH + '">' + '<a href="/' + entryType + '/' + y + '/' + m + '.aspx">' + mn[m - 1] + ' ' + y + '</a></td>';
        else
            t += '<td colspan="5" align="center" class="' + cH + '">' + mn[m - 1] + ' ' + y + '</td>';
        t += '<td colspan="1" valign="bottom" class="' + cH + '">' + '<a href="javascript:void(0);" onclick="javascript:nextMonth();" title="Go to the next month" title="Go to the next month"><img src="/Images/Blog/arrowNext.gif" /></a>' + '</tr><tr align="center"></tr><tr align="center">';
        
        for(s = 0; s < 7; s++)
            t += '<td class="' + cDW + '">' + "SMTWTFS".substr(s, 1) + '</td>';
            
        t += '</tr><tr align="center">';
        
        for(i = 1; i <= 42; i++)
            {
                var x = ((i - oD.od >= 0)&&(i - oD.od < dim[m - 1]))? i - oD.od + 1 : '&nbsp;';                 
                
                if (x == scanfortoday) //DD added
                    {
                        if (EntryDayList.indexOf(m + '/' + x + '/' + y) >= 0)
                            x = '<span id="today"><a href="/' + entryType + '/' + y + '/' + m + '/' + x + '.aspx">' + x + '</a></span>';
                        else
                            x = '<span id="today">' + x + '</span>' //DD added
                    }
                if (EntryDayList.indexOf(m + '/' + x + '/' + y) >= 0)
                    t += '<td class="' + cD + '"><a href="/' + entryType + '/' + y + '/' + m + '/' + x + '.aspx">' + x + '</a></td>';
                else
                    t += '<td class="' + cD + '">' + x + '</td>';
                if(((i) % 7 == 0) && (i < 36))
                    t += '</tr><tr align="center">';
            }
            
        return t += '</tr></table></div>';
    }

function LoadCalendar(m, y, cM, cH, cDW, cD, brdr)
    {
        document.getElementById(strTargetDiv).innerHTML = buildCalendar(m, y, cM, cH, cDW, cD, brdr);
    }


