// (c) 2004, taker (http://www.taker.ru)

var dayNames = new Array("Пн", "Вт", "Ср", "Чт", "Пт", "Сб", "Вс");
var monthNames = new Array("январь", "февраль", "март", "апрель", "май", "июнь", "июль", "август", "сентябрь", "октябрь", "ноябрь", "декабрь");
var activeDates = new Array();

function addDays(myDate, days) {
	myDate.setDate(myDate.getDate() + days);
	return myDate; 
}

function y2k(year) {
	return (year < 1000)? year + 1900 : year;
}

function writeDays() {
	document.write('<tr>');
	for (var i = 0; i < dayNames.length; i++) {
		document.write('<td align="center" bgcolor="#7796B1" class="small"><img src="/img/void.gif" alt="" width="27" height="2" border="0"><br><strong>' + dayNames[i] + '</strong><br><img src="/img/void.gif" alt="" width="27" height="2" border="0"></td>');
	}
	document.writeln('</tr>');
}

function calendar(month, year) {

	var todayDate = new Date();
	var startDate = new Date(year, --month, 1);
	
	while (startDate.getDay() != 1) {
		startDate = addDays(startDate, -1);
	}

	document.writeln('<img src="/img/void.gif" width="202" height="2" alt="" border="0"><br>');
	
	document.writeln('<table bgcolor="#9C283B" width="200" border="0" cellspacing="0" cellpadding="0">');
	document.writeln('<tr>');
	document.writeln('<td width="14"><img src="/img/void.gif" width="14" height="30" alt="" border="0"></td>');
	document.writeln('<td width="186" class="subTitle">' + monthNames[month] + ' ' + year + '</td>');
	document.writeln('</tr>');
	document.writeln('</table>');
	
	document.writeln('<table border="0" width="200" cellpadding="0" cellspacing="0">');
	document.writeln('<tr>');
	document.writeln('<td width="200" bgcolor="#F4F7F9">');
	document.writeln('<table border=0 width="200" cellpadding="0" cellspacing="1">');
	writeDays();

	var calendarEnd = false;

	while (!calendarEnd) {
		document.write('<tr align="center">');
		for (var col = 0; col < 7; col++) {
			if (startDate.getMonth() == month) {
				dateText = startDate.getDate();
				var checkDate = year + '-' + (month+1) + '-' + dateText;
				if (todayDate.getMonth() == month && startDate.getDate() == todayDate.getDate()) {
					cellColor = ' bgcolor="#E9D990"';
					dateText = '<strong>' + dateText + '</strong>';
				} else {
					cellColor = ' bgcolor="#E1EAF2"';
				}
				if (activeDates[checkDate]) {
					dateText = '<a href="/events/?date=' + checkDate + '" class="dateLink">' + dateText + '</a>';
				} else {
					dateText = '<span class="dateNoLink">' + dateText + '</span>';
				}
			} else {
				dateText = '&nbsp;';
				cellColor = '';
			}
			document.write('<td class="small" align="center"' + cellColor + '>');
			document.write('<img src="/img/void.gif" alt="" width="27" height="2" border="0"><br>');
			document.write(dateText + '<br>');
			document.write('<img src="/img/void.gif" alt="" width="27" height="2" border="0"><br>');
			document.write('</td>');
			startDate = addDays(startDate, 1);
		}
		document.writeln('</tr>');
		calendarEnd = startDate.getMonth() != month;
	}

	document.writeln('</table>');
	document.writeln('</td></tr></table>');

}

