var now = new Date;
var MyYear = now.getFullYear();
var Days = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
var DaysinWeek = 7;
var Today = now.getDate();
var ThisMonth = now.getMonth();
var MonthStart = now.setDate(1);
var AddDays = now.getDate();
var DayofWeek = now.getDay();
var DaysinMonth = Days[now.getMonth()];
 
function CreateCurrMonth(){
var ddate;
// Checks Leap Year
if ((((MyYear % 4)==0) && ((MyYear % 100)!=0) || ((MyYear % 400)==0)) && (DaysinMonth == 28)) 
	{DaysinMonth = 29;}
else{DaysinMonth = Days[now.getMonth()];}
 
document.write ("<table class=\"tableMain\" cellspacing=\"0\" cellpadding=\"0\"><tr><td><table class=\"tablexMain\" cellspacing=\"0\" cellpadding=\"0\">"+
"<tr>"+
"<td colspan=\"7\" class=\"monthTd\">"+monthNames[now.getMonth()] + " " + now.getFullYear() +"</td>"+
"</tr>");
document.write("<tr>");
         // Build rows in a month
for (i = 0; AddDays < DaysinMonth + 1; i++){
	if (i < DayofWeek){document.write ("<td></td>");
	} else {
	if ((AddDays == Today) && (now.getMonth() == ThisMonth))
	
	{
ddate = AddDays + ' ' + now.getMonth() + ' ' + now.getFullYear() ;

if ((i % 7) == 0){document.write ("</tr><tr>");}


if(eventsArr.exists(ddate))
{document.write("<td class=\"todayTdBold\" onclick=\"onDateSelected('"+ddate+"')\">" + AddDays + "</td>");}
else
{document.write("<td class=\"todayTd\">" + AddDays + "</td>");}
AddDays = AddDays + 1 ;
                    }
                    else 
                	{
	                	if ((i % 7) == 0){document.write ("</tr><tr>");}
						ddate = AddDays + ' ' + (now.getMonth()+1) + ' ' + now.getFullYear() ;
						if(eventsArr.exists(ddate))
							{
							document.write ("<td class=\"dayBoldTd\" onclick=\"onDateSelected('"+ddate+"')\">" + AddDays + "</td>");						}
						else
							{
							document.write ("<td class=\"dayTd\">" + AddDays + "</td>");
							}
    	               	            
    	            
	                AddDays = AddDays + 1
                }
	}
}
 
        document.write ("</tr></table></tr></td></table>");
 
    }
 
function AddCalendar(addmonth){
	var NewMonth = ThisMonth + addmonth
	if (NewMonth > 11){NewMonth=(NewMonth-12);now.setYear(MyYear + 1);}
	now.setMonth(NewMonth);
	DayofWeek = now.getDay();
	AddDays = now.getDate();
	DaysinMonth = Days[now.getMonth()];
	CreateCurrMonth();
}
function onDateSelected(fdate) {
    fdate = fdate.split(' ').join('.');
    var loca = document.location.pathname + '?sd=' + fdate;
    document.location.href = loca;
}