2.Создайте файл calendar.js и вставте туда это:
Code
function getDays(month, year)
{
if (month == 1)
return (year % 4 == 0) ? 29 : 28;
else if (month == 3 || month == 5 || month == 8 || month == 10)
return 30;
else
return 31;
}
function getMonthName(month)
{
var nameMonth = new Array("Январь", "Февраль", "Март", "Апрель",
"Май", "Июнь", "Июль", "Август",
"Сентябрь", "Октябрь", "Ноябрь", "Декабрь");
return nameMonth[month];
}
function replaceAnchor(sReference, sDay, sMonth, sYear)
{
sReference = sReference.replace("%D%", sDay);
sReference = sReference.replace("%M%", sMonth);
return sReference.replace("%Y%", sYear);
}
function generateCalendar(sSetting, now)
{
var year = now.getYear();
var month = now.getMonth();
var monthName = getMonthName(month);
var date = now.getDate();
now = null;
var firstDayInstance = new Date(year, month, 1);
var firstDay = firstDayInstance.getDay();
if (firstDay == 0)
firstDay = 7;
firstDayInstance = null;
var days = getDays(month, year);
return drawCalendar(firstDay, days, date, month, monthName, year, sSetting);
}
function drawCalendar(firstDay, lastDate, date, month, monthName, year, sSetting)
{
var text = "";
text += '<table ' + sSetting[0] + '>';
text += ' <tr><td colspan="7" ' + sSetting[1] + '>';
text += monthName + ' ' + year;
text += ' </td></tr>';
var weekDay = sSetting[12].split(';');
var openCol = '<td ' + sSetting[2] + '>';
var closeCol = '</td>';
text += '<tr>';
for (var dayNum = 0; dayNum < 7; ++dayNum)
text += openCol + weekDay[dayNum] + closeCol;
text += '</tr>';
var digit = 1;
var curCell = 1;
for (var row = 1; row <= Math.ceil((lastDate + firstDay - 1) / 7); ++row)
{
text += '<tr ' + sSetting[3] + '>';
for (var col = 1; col <= 7; ++col)
{
text += '<td ';
if (digit > lastDate)
text += sSetting[5] + '>';
else if (curCell < firstDay)
{
text += sSetting[6] + '>';
curCell++;
}
else
{
if (digit == date)
{
text += sSetting[7];
text += '>';
if (sSetting[11] != "")
{
text += '<a href="' + replaceAnchor(sSetting[11], digit, month, year) + '" ' + sSetting[9] + '>';
text += digit;
text += '</a>';
}
else
text += digit;
}
else
{
text += sSetting[4];
text += '>';
if (sSetting[10] != "")
{
text += '<a href="' + replaceAnchor(sSetting[10], digit, month, year) + '" ' + sSetting[8] + '>';
text += digit;
text += '</a>';
}
else
text += digit;
}
digit++;
}
text += '</td>';
}
text += '</tr>';
}
text += '</table>';
return text;
}
Сохраните файл!
читайте далее...