function DateSelector(yearId, monthId, dayId)
{
  this.set = function (year, month, day)
  {
    var yearElem = document.getElementById(yearId);
    var monthElem = document.getElementById(monthId);
    var dayElem = document.getElementById(dayId);

    for(var i=0; i<yearElem.options.length; i++)
    {
      yearElem.options.item(i).selected = yearElem.options.item(i).value == year ? true : false;
    }

    for(var i=0; i<monthElem.options.length; i++)
    {
      monthElem.options.item(i).selected = monthElem.options.item(i).value == month ? true : false;
    }

    this.onChangeFunction();

    for(var i=0; i<dayElem.options.length; i++)
    {
      dayElem.options.item(i).selected = dayElem.options.item(i).value == day ? true : false;
    }
  }

  this.onChangeFunction = function ()
  {
    var year = document.getElementById(yearId).value;
    var month = document.getElementById(monthId).value;
    var dayElem = document.getElementById(dayId);
    var optionElem;
    if(month == 2)
    {
      if(year%4 && (!(year%100) || year%400))
      {
        days=28;
      }
      else
      {
        days= 29;
      }
    }
    else
    {
      days = 30 + (month > 7 ? !(month % 2) : month % 2);
    }
    while(dayElem.hasChildNodes())
    {
      dayElem.removeChild(dayElem.firstChild);
    }
    for(var i=1; i<=days; i++)
    {
      optionElem = document.createElement('option');
      optionElem.setAttribute('value', (i<10 ? '0' : '') + i);
      optionElem.appendChild(document.createTextNode((i<10 ? '0' : '') + i + '  '));
      dayElem.appendChild(optionElem);
    }
  }

  document.getElementById(yearId).onchange =  document.getElementById(monthId).onchange = this.onChangeFunction;
}
