var valid=false, div_selector, team_selector, div_index, team_index;

if (
	(typeof Prototype != 'undefined') &&
	(typeof Prototype.Version != 'undefined') &&
	(typeof base_url != 'undefined')
) {
	var version = parseFloat(Prototype.Version.substring(0,3));
	if (version >= 1.6)
	{
		valid = true;

		var selector;
		if (selector = $('DivisionTeamDivisionId'))
		{
			div_selector = selector;
			selector.observe('change', update);
			selector.observe('keyup', update);
			selector.observe('mouseup', update);
			div_index = div_selector.options[div_selector.selectedIndex].value;
		}
		else
		{
			valid = false;
		}

		if (selector = $('DivisionTeamTeamId'))
		{
			team_selector = selector;
			selector.observe('change', update);
			selector.observe('keyup', update);
			selector.observe('mouseup', update);
			team_index = team_selector.options[team_selector.selectedIndex].value;
		}
		else
		{
			valid = false;
		}
	}
}

function update()
{
	var new_div_index, new_team_index;

	if (valid)
	{
		new_div_index = div_selector.options[div_selector.selectedIndex].value;
		new_team_index = team_selector.options[team_selector.selectedIndex].value;

		var url = false;
		if (new_div_index != div_index)
		{
			url = base_url + new_div_index;
		}
		else if (new_team_index != team_index)
		{
			if (new_team_index !== '')
			{
				url = base_url + div_index + '/' + new_team_index;
			}
			else
			{
				url = base_url + div_index;
			}
		}

		if (url !== false)
		{
			window.location = url;
		}

		div_index = new_div_index;
		team_index = new_team_index;
	}
}

