horus.cspot.eventdata={};


horus.cspot.dateselector=
  function ( chunkid ) {
    var data=horus.cspot.eventdata[chunkid];

    if (!data.selector) {
      data.selector=horus.getElement('dateselector'+chunkid);
      data.selectorbox=horus.getElement('dateselectorbox'+chunkid);
      data.selyear=data.year;
      data.selmonth=data.month;
    }

    return data;
  };


horus.cspot.toggleselector=
  function ( chunkid ) {
    var data=horus.cspot.dateselector(chunkid);
    var hide=data.selector.style.display=='';
    horus.visible(data.selector, !hide);
    data.selectorbox.src='/common/resources/'+(hide ? 'open' : 'close')+'box.gif';
  };


horus.cspot.monthsel=
  function ( chunkid, m ) {
    var data=horus.cspot.dateselector(chunkid);

    if (m!=data.selmonth) {
      horus.setClass('m'+data.selmonth+chunkid);
      horus.setClass('m'+m+chunkid, 'selected');
      data.selmonth=m;
    }
  };


horus.cspot.yearsel=
  function ( chunkid, y ) {
    var data=horus.cspot.dateselector(chunkid);

    if (y!=data.selyear) {
      horus.setClass('y'+data.selyear+chunkid);
      horus.setClass('y'+y+chunkid, 'selected');
      data.selyear=y;
    }
  };


horus.cspot.gotomonth=
  function ( chunkid, sel ) {
    var data=horus.cspot.dateselector(chunkid);
    horus.cspot.toggleselector(chunkid);

    if (sel==2) {
      var today=new Date;
      horus.cspot.monthsel(chunkid, today.getMonth()+1);
      horus.cspot.yearsel(chunkid, today.getFullYear());
    }

    if (data.selmonth!=data.month || data.selyear!=data.year)
      if (sel>0)
	horus.linkTo('?date='+data.selyear+'-'+data.selmonth);
      else {
	horus.cspot.monthsel(chunkid, data.month);
	horus.cspot.yearsel(chunkid, data.year);
      }

    return false;
  };
