simpleCalendar.prototype = {
  week:         ['Пн','Вт','Ср','Чт','Пт','Сб','Вс'], 
  months:       ['Январь','Февраль','Март','Апрель','Май','Июнь','Июль','Август','Сентябрь','Октябрь','Ноябрь','Декабрь'],
  setClassies:  function(day, sunday, notday)
                {
                  with(this)
                  {
                    dayClass = day;
                    sundayClass = sunday;
                    notdayClass = notday;
                  }
                },
  setHolydays: function(h, c)
                {
                  var i, len, arr, dt, l; 
                  if(h instanceof Array && (len = h.length))
                  {
                    for(i = 0; i < len; i++)
                    {
                      arr = h[i].split('.');
                      dt = (arr[0] - 0)+'.'+(arr[1] - 1);
                      l = this.holydays.length;
                      this.holydays[l] = dt;
                      this.holydayClass[l] = c;
                    }
                  }
                },
  holyday:     function(dt)
                {
                  var output = false;
                  var h = this.holydays, len;
                  dt = dt.getDate()+'.'+dt.getMonth();
                  
                  if(h && (len = h.length))
                  {
                    for(var i = 0; i < len; i++)
                    {
                      if(h[i] == dt)
                      {
                        output = this.holydayClass[i] ? this.holydayClass[i] : '';
                        break;
                      }
                    }
                  }
                  
                  return output;
                },
  drawCalendar: function()
                {
	                var dt = this.date, week = this.week, months = this.month, y = dt.getFullYear(), m = dt.getMonth(), dd, cd, cm, hc, fcode, hcode, ccode;
	                var day = this.dayClass || '', sunday = this.sundayClass || '', notday = this.notdayClass || '', func = this.func, href = this.href; 
	                var t = '<table><tr>';
                  for(var i = 0; i < 7; i++) 
                  { t += '<th>'+week[i]+'</th>'; }
                  //{ t += '<th'+(i==6?' class="'+sunday+'"':'')+'>'+week[i]+'</th>'; }
	                t += '</tr>';
	
                  var from = 2 - ((new Date(y,m,1)).getDay() || 7), to = (new Date(y,m+1,0)).getDate() + (7 - ((new Date(y,m+1,0)).getDay() || 7));
	              for(i = from; i <= to; i++)
                  {
                    dd = new Date(y,m,i);
                    cd = dd.getDay() || 7;
                    cdt = dd.getDate();
                    cm = dd.getMonth();
                    toDay = dt.getDate();
                    if(cd == 1) { t += '<tr>'; }
		            if(cm != m) 
                    { t += '<td'+' class="'+notday+'"></td>'; }
//                     { t += '<td'+' class="'+notday+'"'+'"></td>'; }
                    else
                    {
                      hc = this.holyday(dd);
                      ccode = day+(hc ? ' '+hc : '');
                      fcode = (func ? ' onclick="'+func+'(new Date('+y+','+m+','+i+'))"' : '');
                      t += '<td ' + ((m == cm && i == toDay) ? 'class="hdl"' : '') + '>' + cdt + '</td>';
/*                      hcode = href != undefined && hc ? '<a href="'+href+(cm+1)+'/'+cdt+'/"'+func+'>'+cdt+'</a>' : cdt;
                      t += '<td class="'+ccode+'"'+fcode+'>'+hcode+'</td>';*/
                    }
		                if(cd == 7) t += '</tr>';
	              }
	              
                  this.obj.innerHTML = t+'</table>';
                },
  redrawCalendar:function(dt)
                {
                  this.date = dt;
                  this.drawCalendar();
                }
}

function simpleCalendar(id, href, dt, func)
{
  this.obj = document.getElementById(id) || null;
  this.func = func;
  this.href = href;
  this.date = dt || new Date();
  this.dayClass = null;
  this.sundayClass = null;
  this.notdayClass = null;
  this.holydays = new Array();
  this.holydayClass = new Array();
}