function DateSelectHelper( selectDay, selectMonth, initialDate, startDate, endDate  )
{
	var _arguments = arguments;
	
	//Default display format - change as you wish
	var _dayTextFormat = 'dd ddd';
	var _monthTextFormat = 'MMM yyyy';
	
	//Do not change
	var _dayValueFormat = 'dd';
	var _monthValueFormat = 'MM yyyy';
	
	var _startDate;
	var _endDate; 
	var _initialDate;
	
	//the select boxes
	var _selectDay;
	var _selectMonth;
	
	initialize();
	
	//Expose public methods
	this.setDayTextFormat = setDayTextFormat;
	this.setMonthTextFormat = setMonthTextFormat;
	this.getSelectedDate = getSelectedDate;
	this.populate = populate;
	this.refreshDay = refreshDay;

	function initialize()
	{	
		var i;
		for( i = 0; i < _arguments.length; i++ )
		{
			switch( i )
			{
				case 0:
					_selectDay =  _arguments[i];
					break;
				case 1:
					_selectMonth = _arguments[i];
					break;
				case 2:
					_initialDate = new Date( _arguments[i] );
					break;
				case 3:
					setStartDate( _arguments[i] );
					break;
				case 4:
					setEndDate( _arguments[i] );
					break;
				
			}
		}
		
		if( _arguments.length < 2 )
		{
			throw 'Drop down lists must be set in constructor';
		}
		if( _arguments.length < 3 )
		{
			//If not supplied set _initialDate to current date
			_initialDate = new Date();
		}
		if( _arguments.length < 4 )
		{
			//If not supplied set _startDate to _initialDate
			_startDate = new Date( _initialDate );
		}
		if( _arguments.length < 5 )
		{
			//If not supplied set _endDate to whichever is greater of 
			//( _startDate + 1 year ) or (end of _initialDate month)
			_endDate = new Date( _startDate.getFullYear() + 1, _startDate.getMonth(), 1 );
			_endDate = _endDate - 1; 
			
			if( _endDate < _initialDate )
			{
				_endDate = new Date( _initialDate.getFullYear(), _initialDate.getMonth() + 1, 1 );
				_endDate = _endDate - 1; 
			}	
		}
	}

	function setDayTextFormat( newValue )
	{
		_dayTextFormat = newValue;
	}
	
	function setMonthTextFormat( newValue )
	{
		_monthTextFormat = newValue;
	}
	
	function populate()
	{
		populateDdlDay( _initialDate );
		populateDdlMonth( _initialDate );
	}
	
	function getSelectedDate()
	{
		var year = parseInt( _selectMonth.options[_selectMonth.options.selectedIndex].value.substr(3,4) ,10);
		var month =  parseInt( _selectMonth.options[_selectMonth.options.selectedIndex].value.substr(0,2),10 ) - 1;
		var day =  parseInt( _selectDay.options[_selectDay.options.selectedIndex].value,10 );
		var cleaner = new DateTimeCleaner( year, month, day );
		var selectedDate = cleaner.getCleanDate();
		delete cleaner;
		
		if( selectedDate < _startDate ) selectedDate = _startDate;
		if( selectedDate > _endDate ) selectedDate = _endDate;
		return selectedDate;
	}
	
	function refreshDay()
	{
		var selectedDate = getSelectedDate();
		populateDdlDay( selectedDate );
	}
	
	function populateDdlDay(_selectedDate)
	{
		_selectDay.length = 0;
		var format = new DateTime();
		var dateCounter;
		var i = 0;
		
		if( _startDate.getMonth() == _selectedDate.getMonth() && _startDate.getFullYear() == _selectedDate.getFullYear() )
		{
			dateCounter = new Date( _startDate );
		}
		else
		{
			dateCounter = new Date( _selectedDate.getFullYear(), _selectedDate.getMonth(), 1 );	
		}
		
		while( dateCounter.getMonth() == _selectedDate.getMonth())
		{
			if(dateCounter > _endDate) break;
			format.setDateTime( dateCounter ); 
			_selectDay[ _selectDay.length ] = new Option( format.format( _dayTextFormat ), format.format( _dayValueFormat ));
			if( dateCounter.getDate() == _selectedDate.getDate() && dateCounter.getMonth() == _selectedDate.getMonth() && dateCounter.getFullYear() == _selectedDate.getFullYear() )
			{
				_selectDay.selectedIndex = _selectDay.length - 1;
			}
			dateCounter.setDate( dateCounter.getDate() + 1 );
		} 
		delete format;
		delete dateCounter;
	}
	
	function populateDdlMonth(_selectedDate)
	{
		_selectMonth.length = 0;
		var format = new DateTime();
		var dateCounter = new Date( _startDate.getFullYear(), _startDate.getMonth(), 1 );
		var i;
		
		while( dateCounter <= _endDate )
		{
			format.setDateTime( dateCounter ); 
			_selectMonth[ _selectMonth.length ] = new Option( format.format( _monthTextFormat ), format.format( _monthValueFormat ));
			if( dateCounter.getMonth() == _selectedDate.getMonth() && dateCounter.getFullYear() == _selectedDate.getFullYear() )
			{
				_selectMonth.selectedIndex = _selectMonth.length - 1;
			}
			dateCounter.setMonth( dateCounter.getMonth() + 1 );
		} 
		delete format;
		delete dateCounter;
	}
	
	function setStartDate( newValue )
	{
		_startDate = new Date( newValue );
		if( _startDate > _initialDate ) throw 'startDate cannot be set after initialDate'; 
		if( _startDate > _endDate ) throw 'startDate cannot be set after endDate'; 
	}
	
	function setEndDate( newValue )
	{
		_endDate = new Date( newValue );
		if( _endDate < _initialDate ) throw 'endDate cannot be set before initialDate'; 
		if( _endDate < _startDate ) throw 'endDate cannot be set before startDate';
	}
}



