// Include Scriptaculous
document.write('<script src="/js/scriptaculous/prototype.js" type="text/javascript"></script><script src="/js/scriptaculous/scriptaculous.js" type="text/javascript"></script>');

var years = new Array()

function addYear(year) {
	years[years.length] = year;	
}

/**
* Hide group of MONTH or DAY
*/
function hideAllMonths() {
	for (counter=0; counter<years.length; counter++)
		Element.hide('months_'+years[counter]);
}
function hideAllDays() {
	Element.hide('days_28');
	Element.hide('days_29');
	Element.hide('days_30');
	Element.hide('days_31');
}

/**
* Update Selections
*/
function updateSelectedYear() {
	currentYear = $('selectedYear').value;
	//$('selectedYear').value = 0
	
	if(currentYear > 0)
		$('year_'+currentYear).removeClassName('selected');		

	updateSelectedMonth();
	updateSelectedDay();
	hideAllMonths();
}
function updateSelectedMonth() {
	currentMonth = $('selectedMonth').value;
	currentYear = $('selectedYear').value;
	$('selectedMonth').value = 0;
	if(currentMonth > 0)
		$('month_'+currentYear+'_'+currentMonth).removeClassName('selected');
	
	updateSelectedDay();
	hideAllDays();
}
function updateSelectedDay() {
	day = $('selectedDay').value;
	$('selectedDay').value=0;
	
	if(day > 0) {
		if($('days_28_' + day)!=null)
			$('days_28_' + day).removeClassName('selected');
		//Element.setStyle('days_28_' + day, {color:'#22447A'} );
		if($('days_29_' + day)!=null)
			$('days_29_' + day).removeClassName('selected');
		//Element.setStyle('days_29_' + day, {color:'#22447A'} );
		if($('days_30_' + day)!=null)
			$('days_30_' + day).removeClassName('selected');
		//Element.setStyle('days_30_' + day, {color:'#22447A'} );
		if($('days_31_' + day)!=null)
			$('days_31_' + day).removeClassName('selected');
		//Element.setStyle('days_31_' + day, {color:'#22447A'} );
	}
	hideVoteButton();
}
function hideVoteButton() {
	if($('hiddenArea')!=null)
		Element.hide('hiddenArea');
	//Element.hide('sayWhenSubmitDiv');
	//Element.hide('emailForm');
}


/**
* Show Selected Options
*/
function showMonthsForSelectedYear(year) {
	Element.show('months_'+year);
    $('year_'+year).addClassName('selected');
	$('selectedYear').value = year;
	$('selectedMonth').value = 0;
	$('selectedDay').value = 0;	
}

function showDaysForSelectedMonth(month) {
	//previousMonth = $('selectedMonth').value;
	year = $('selectedYear').value;
	$('selectedMonth').value = month;
		
	// Set Style on Currently selected MONTH
	//Element.setStyle('month_'+year+'_'+month, {fontWeight:'bold'} );
	$('month_'+year+'_'+month).addClassName('selected');
	
	// Show the DAYS for the selected MONTH
	if(month == 2) {
		if( (year % 4) == 0)
			Element.show('days_29');
		else 
			Element.show('days_28');
	}
	else if( month < 8) {
		if(month % 2 == 0 )
			Element.show('days_30');
		else
			Element.show('days_31');
	}
	else if( month >= 8) {
		if(month % 2 == 0 )
			Element.show('days_31');
		else
			Element.show('days_30');
	}
}

function showSubmit(day, idPrefix) {
	$('selectedDay').value = day;
	$(idPrefix + '_' + day).addClassName('selected');
	//Element.setStyle(idPrefix + '_' + day, {color:'#FF0066'} );
	
	//Element.show('sayWhenSubmitDiv');
	//Element.show('emailForm');
	Element.show('hiddenArea');
}

// When YEAR is selected display the MONTHS 
//function showMonths(year) {
function updateYearSelection(year) {
	// Clear any preivously selected YEAR in YEARS
	updateSelectedYear();
	
	//Show the months for the selected year
	showMonthsForSelectedYear(year);
}

// When a MONTH is selected display the DAYS
//function showDays(month, year) {
function updateMonthSelection(month) {
	// Clear any preivously selected MONTH in MONTHS
	updateSelectedMonth();
	
	//Show the months for the selected year
	showDaysForSelectedMonth(month);


}

//function showVoteButton(idPrefix, day) {
function updateDaySelection(idPrefix, day) {
	updateSelectedDay();
	
	showSubmit(day, idPrefix);
}

