DateChooser = function() 
{
	this.calendar;
}
                    
// This function shows the calendar
DateChooser.prototype.display = function() 
{
	if (_dynarch_popupCalendar != null) 
	{
    	// we already have some calendar created
        _dynarch_popupCalendar.hide(); // so we hide it first.
    } else {
       	// first-time call, create the calendar.
       	this.calendar = new Calendar(1, 
								null, 
								DateChooser.handleSelected, 
								DateChooser.hide
		);
		this.calendar.firstDayOfWeek = 0;
        this.calendar.weekNumbers = false;
        this.calendar.showsTime = false;
        this.calendar.showsOtherMonths = true;
        this.calendar.singleClick = true;
        this.calendar.showOthers = false;
        today = new Date();
                    
        //calendar.setRange(today.getYear()-1, today.getYear()+1);  
        this.calendar.setDisabledHandler(DateChooser._isDisabled);
        _dynarch_popupCalendar = this.calendar;     // remember it in the global var
        this.calendar.create();
	}
    dateElement = $('date');
    _dynarch_popupCalendar.setDateFormat('%Y-%m-%d');    // set the specified date format
    _dynarch_popupCalendar.parseDate(dateElement.value);      // try to parse the text in field
    _dynarch_popupCalendar.sel = dateElement;                 // inform it what input field we use
    
    // the reference element that we pass to showAtElement is the button that
    // triggers the calendar.  In this example we align the calendar bottom-right
    // to the button.
					  
	// ie hack (fix this):
	x = $('channel_header_container').cumulativeOffset()[0] + (($('channel_header_container').getWidth()/3)/2);
	//
    _dynarch_popupCalendar.showAt(x, $('change_date').cumulativeOffset()[1]);        // show the calendar
                      
    //	_dynarch_popupCalendar.showAtElement($('change_date'));
    return false;
}

DateChooser.prototype.hide = function()
{
	this.calendar.hide();
}

// class methods

// Called when the user clicks on a date in the calendar.
DateChooser.handleSelected = function(calendar, theDate) 
{
	if (calendar.dateClicked) 
	{
		schedule.displayScheduleForDate(theDate);
		calendar.hide();
    }
}

// Called when the end-user clicks on the _selected_ date,
// or clicks on the "Close" button.  It just hides the calendar without
// destroying it.
DateChooser.hide = function(calendar) 
{
	calendar.hide();                        
    _dynarch_popupCalendar = null;
}

//private                    
DateChooser._isDisabled = function(date) 
{
    return !date.isAcceptableForSchedule();
}

