function setCalendar(_year, _month)
 {
  var _Date = new Date();
  var _currentDate = new Date();

  var _dates = [];
  var _week = 0;
  var _date = 1;
  
  _Date.setFullYear(_year);
  _Date.setMonth(_month);
  _Date.setDate(1);
  
  for(var i = 0; i < 42; i++)
   {
    var _day = (_Date.getDay() == 0)? 6:_Date.getDay()-1;
    if(((_week*7+_day*1) == i) && _Date.getMonth() == _month)
     {
      if(_day == 6) _week++;
      
      if(((_Date.getMonth() == 2)? (_Date.getDate() < 19):false) || ((_Date.getMonth() == _currentDate.getMonth())? (_Date.getDate() >= _currentDate.getDate()):false))
       {
        if((_Date.getMonth() == _currentDate.getMonth()) && (_Date.getDate() == _currentDate.getDate()))
         {
          _data = [_date, 'current'];
         }
        else
         {
          _data = [_date, ''];
         }
       }
      else
       {
        //_data = [_date, 'javascript: alert("/?year='+_year+'&month='+_month+'&date='+_date+'")'];
		_data = [_date, '/spisok_publikacij?year='+_year+'&month='+(_month*1+1*1)+'&day='+_date];
       }

      _dates.push(_data);
      _date++;
      _Date.setDate(_date);
     }
    else
     {
      _dates.push(['.','']);
     }
   }
  
  var calendar_block = document.getElementById('calendar_body');
  
  for(var i = 0; i < 42; i++)
   {
    calendar_block.childNodes[i].innerHTML = _dates[i][0];
    
    calendar_block.childNodes[i].style.backgroundColor = '#f8f8f8';
    if(!((i-6)%7)) calendar_block.childNodes[i].style.backgroundColor = '#ddd';
    if(!((i-5)%7)) calendar_block.childNodes[i].style.backgroundColor = '#ddd';
    
    if((_dates[i][1] != 'current') && _dates[i][1])
     {
      calendar_block.childNodes[i].setAttribute('href', _dates[i][1]);
      calendar_block.childNodes[i].style.color = '#000';
     }
    else
     {
      if(_dates[i][1] == 'current')
       {
        calendar_block.childNodes[i].removeAttribute('href');
        calendar_block.childNodes[i].style.color = '#fff';
        calendar_block.childNodes[i].style.backgroundColor = '#ff5d00';
       }
      else
       {
        if(_dates[i][0] == '.')
         {
          calendar_block.childNodes[i].removeAttribute('href');
          calendar_block.childNodes[i].style.color = '#fff';
          calendar_block.childNodes[i].style.backgroundColor = '#fff';
         }
        else
         {
          calendar_block.childNodes[i].removeAttribute('href');
          calendar_block.childNodes[i].style.color = '#aaa';
         }
       }
     }
   }
 }

function createCalendar(_year, _month)
 {
  var calendar_block = document.getElementById('calendar_body');
  
  for(var i = 0; i < 42; i++)
   {
    var datecell = document.createElement('a');
    datecell.className = 'date';
    datecell.appendChild(document.createTextNode('.'));
    datecell_style = 
     {
      position: 'relative', 
      display: 'inline', 
      cssFloat: 'left', 
      top: '0px', 
      left: '0px', 
      width: '33px', 
      height: '27px', 
      margin: '0px 2px 2px 0px', 
      backgroundColor: '#fff',
      textDecoration: 'none'
     };

    if(!(i%7)) datecell_style.width = '26px';
    if(!((i-6)%7)) {datecell_style.backgroundColor = '#ddd'; datecell_style.margin = '0px 0px 2px 0px';};
    if(!((i-5)%7)) datecell_style.backgroundColor = '#ddd';
     
    setNodeStyle(datecell, datecell_style);
    
    calendar_block.appendChild(datecell);
   }
  setCalendar(_year, _month);
 }

function setNodeStyle(node, style)
 {
  for(p in style) node.style[p] = style[p];
 }
