function DarkCalendar(id)
{
    this.id = id;
    this.onfieldclick = null;
    this.onrecordclick = null; 
    
    this.init = function()
    {
        master = $('cal_'+this.id);
        tds = master.getElementsByTagName('td');
        for (i=0; i<tds.length; i++) {
            if ((tds[i].className.match(/field/))||(tds[i].className.match(/record/))) {
                a = tds[i].id.match(/day_([0-9-]+)_hour_([0-9.]+)/);
                tds[i].day = a[1];
                tds[i].hour = a[2];
            }
        }
    };
    
    this.mouseenter = function(event, obj)
    {
        if (obj.className.match(/^field/)) {
            obj.className = 'field selected';
        }
        $('cal_'+this.id+'_day_'+obj.day).className = 'day selected';
        $('cal_'+this.id+'_hour_'+Math.floor(obj.hour)).className = 'hour selected';
        $('cal_'+this.id+'_minute_'+obj.hour).className = 'minute selected';
    };

    this.mouseout = function(event, obj)
    {
        if (obj.className.match(/^field/)) {
            obj.className = 'field';
        }
        $('cal_'+this.id+'_day_'+obj.day).className = 'day';
        $('cal_'+this.id+'_hour_'+Math.floor(obj.hour)).className = 'hour';
        $('cal_'+this.id+'_minute_'+obj.hour).className = 'minute';
    };
    
    this.showPopup = function(obj, text)
    {
        var pos = Element.positionedOffset(obj);
        var p = $('cal_'+this.id+'_popup');
        var pt = $('cal_'+this.id+'_popup_text');
        var pa = $('cal_'+this.id+'_popup_arrow');
        pt.innerHTML = text;
        p.show();        

        pa.style.marginLeft = (p.getWidth() / 2 - 10) + 'px';
        p.style.left = ((pos[0] + Element.getWidth(obj) / 2) - p.getWidth() / 2) + 'px';
        p.style.top = (pos[1] - p.getHeight()) + 'px';
        
    };

    this.hidePopup = function(obj, text)
    {
        var p = $('cal_'+this.id+'_popup');
        p.hide();
    };
        
    this.click = function(event, obj)
    {
        if (obj.className.match(/field/)) {
            if (this.onfieldclick!=null) {
                return this.onfieldclick(obj.day, obj.hour);
            }
        }
        if (obj.tagName=='A') {
            obj.blur();
            if (this.onrecordclick!=null) {
                return this.onrecordclick(0, 0, obj);
            }
        }
        //alert(obj.day + ' ' + obj.hour);
    };
    
    this.init();
    $('cal_'+this.id).calendar = this;
}
