// JavaScript Document

function change_months( offset )
	{	
	var month_selector = document.getElementById( "Calendar_Month" );
	var new_month_index = month_selector.selectedIndex + offset;
	var year_offset=0;
	if ( new_month_index <0 ) 
		{
		new_month_index = new_month_index + 12;
		year_offset = year_offset - 1;
		} 
	if ( new_month_index > 11 ) 
		{
		new_month_index = new_month_index - 12;
		year_offset = year_offset + 1;
		} 
		
	var year_selector = document.getElementById( "Calendar_Year" );
	var new_year_index = year_selector.selectedIndex + year_offset;
	var	max_year_index = year_selector.length-1;
	if (new_year_index <0 )
		{
 		new_year_index =0;
		}	
	if (new_year_index > max_year_index )
		{
 		new_year_index = max_year_index;
		}	
	
	if ( month_selector.selectedIndex != new_month_index || year_selector.selectedIndex != new_year_index )
		{
		month_selector.selectedIndex = new_month_index;	
		year_selector.selectedIndex = new_year_index;
		
		document.getElementById("calendar").submit();
		}
}

function disable_selectors()
{
	var year_selector = document.getElementById( "Calendar_Year" );
	var prev_year = document.getElementById("prevyear");
	var next_year = document.getElementById("nextyear");
	var month_selector = document.getElementById( "Calendar_Month" );
	var prev_month = document.getElementById("prevmonth");
	var next_month = document.getElementById("nextmonth");

	prev_year.disabled = year_selector.selectedIndex <=0;
	prev_month.disabled = prev_year.disabled && month_selector.selectedIndex <=0;
	
	next_year.disabled = year_selector.selectedIndex >= year_selector.length-1;
	next_month.disabled = next_year.disabled && month_selector.selectedIndex >=11;
}

