now = new Date();
year = now.getYear();
month = now.getMonth();
date = now.getDate();
day = now.getDay();


tomonth = new Array(12);
tomonth[0] = 4;
tomonth[1] = 0;
tomonth[2] = 0;
tomonth[3] = 3;
tomonth[4] = 5;
tomonth[5] = 1;
tomonth[6] = 3;
tomonth[7] = 6;
tomonth[8] = 2;
tomonth[9] = 4;
tomonth[10] = 0;
tomonth[11] = 2;


monthend = new Array(12);
monthend[0] = 31;
monthend[1] = 28;
monthend[2] = 31;
monthend[3] = 30;
monthend[4] = 31;
monthend[5] = 30;
monthend[6] = 31;
monthend[7] = 31;
monthend[8] = 30;
monthend[9] = 31;
monthend[10] = 30;
monthend[11] = 31;

honev = new Array(12);
honev[0] = 'Січень';
honev[1] = 'Лютий';
honev[2] = 'Березень';
honev[3] = 'Квітень';
honev[4] = 'Травень';
honev[5] = 'Червень';
honev[6] = 'Липень';
honev[7] = 'Серпень';
honev[8] = 'Вересень';
honev[9] = 'Жовтень';
honev[10] = 'Листопад';
honev[11] = 'Грудень';




function initCalendar( n )
{
if( n != undefined )
{
	month += n;
}
var nap = 1;

var str = "";

str += '<table class="calendar" cellpadding="0" cellspacing="2" > <tr>';
str += '<td colspan="7" class="cal">';
str +=  "<span style='cursor: pointer' onclick='initCalendar( -1 )'> < </span>" + honev[month] + "<span style='cursor: pointer' onclick='initCalendar( 1 )'> > </span>" ;
str +=  '</td></tr><tr>';
str +=  '<td class="not_today">Пн</td>';
str +=  '<td class="not_today">Вт</td>';
str +=  '<td class="not_today">Ср</td>';
str +=  '<td class="not_today">Чт</td>';
str +=  '<td class="not_today">Пт</td>';
str +=  '<td class="not_today">Сб</td>';
str +=  '<td class="not_today">Нд</td></tr><tr>';
for(o=0;o<tomonth[month];o++) { str +=  '<td class="not_today" align="center">&nbsp;</td>' };
for(i=0;i<(7-tomonth[month]);i++){
				 if (nap == date) {
				  str +=  '<td class="today">';
				  str +=  (nap++);
				  str +=  '</td>';
				 }
				else {
				  str += ('<td class="not_today">');
			      str += (nap++);
		    	  str += ('</td>');
				 } 
				}
str += ('</tr>');
str += ('<tr>');
for(i=0;i<7;i++){
				if (nap <= monthend[month]) {
						if (nap == date) {
						 str +=  ('<td class="today">');
						 str +=  (nap++);
						 str +=  ('</td>');
						                 }
						else {
						 str += ('<td class="not_today">');
					     str += (nap++);
		 		   	     str += ('</td>');
						 }
						}
				else {str += ('<td class="not_today">&nbsp;</td>'); }
				}
str += ('</tr>');
str += ('<tr>');
for(i=0;i<7;i++){
				if (nap <= monthend[month]) {
						if (nap == date) {
						 str +=  ('<td class="today">');
						 str +=  (nap++);
						 str +=  ('</td>');
						                 }
						else {
						 str += ('<td class="not_today">');
					     str += (nap++);
		 		   	     str += ('</td>');
						 }
						}
				else {str += ('<td class="not_today">&nbsp;</td>'); }
				}
str += ('</tr>');
str += ('<tr>');
for(i=0;i<7;i++){
				if (nap <= monthend[month]) {
						if (nap == date) {
						 str +=  ('<td class="today">');
						 str +=  (nap++);
						 str +=  ('</td>');
						                 }
						else {
						 str += ('<td class="not_today">');
					     str += (nap++);
		 		   	     str += ('</td>');
						 }
						}
				else {str += ('<td class="not_today">&nbsp;</td>'); }
				}
str += ('</tr>');
str += ('<tr>');
for(i=0;i<7;i++){
				if (nap <= monthend[month]) {
						if (nap == date) {
						 str +=  ('<td class="today">');
						 str +=  (nap++);
						 str +=  ('</td>');
						                 }
						else {
						 str += ('<td class="not_today">');
					     str += (nap++);
		 		   	     str += ('</td>');
						 }
						}
				else {str += ('<td class="not_today">&nbsp;</td>'); }
				}
str += ('</tr>');
str += ('<tr>');
for(i=0;i<7;i++){
				if (nap <= monthend[month]) {
						if (nap == date) {
						 str +=  ('<td class="today">');
						 str +=  (nap++);
						 str +=  ('</td>');
						                 }
						else {
						 str += ('<td class="not_today">');
					     str += (nap++);
		 		   	     str += ('</td>');
						 }
						}
				else {str += ('<td class="not_today">&nbsp;</td>'); }
				}
str += ('</tr>');
str += ('</table>');

 document.getElementById('calendar').innerHTML = str;

}

initCalendar();
