// JavaScript Document
function init()
{
	if ( $('league_city') )
	{
		var sel = $('league_city');
		sel.options.length = 0;
		sel.options[0] = new Option( "Please select a state...",'-',null,false );
		sel.disable();
		var sel = $('league_name');
		sel.options.length = 0;
		sel.options[0] = new Option( "Please select a state...",'-',null,false );
		sel.disable();
		Effect.SlideUp('newleague', { duration: 0.05 });
	}
}

function json_decode(txt){
	try{ /*$('notices').update( txt ); */
	return eval('('+txt+')'); }catch(ex){ $('notice').insert("error evaluating:<br>" + txt);}
}

function showCities( val )
{
	new Ajax.Request('/php.classes/class.LeagueListCity.php?val='+val, {
		method: 'get',
		onSuccess: function(xhr,json) {
			var sel = $('league_city');
			sel.enable();
			var obj = (json && json.options ? json : json_decode(xhr.responseText));
			if(!obj.options){ return false; }
			var opts = obj.options;
			sel.options.length = 0;
			sel.options[0] = new Option( "Please select","-",null,false );
			for( var i=0; i<opts.length; i++ ){
				sel.options[i+1] = new Option(opts[i].text,opts[i].text,null,(sel&&sel==opts[i].value?true:false));
			}
		},
		onFailure: function( transport ) {
			$('notice').update( "Sorry - problem." );
		},
		onLoading: function () {
			var sel = $('league_city');
			sel.options.length = 0;
			sel.options[0] = new Option( "Loading...",'-',null,false );
			sel.disable();
		}
	});
}

function showLeagues( val )
{
	var val2 = $('league_state').options[ $('league_state').options.selectedIndex ].value;
	new Ajax.Request('/php.classes/class.LeagueListName.php?val='+val+'&val2='+val2, {
		method: 'get',
		onSuccess: function(xhr,json) {
			var sel = $('league_name');
			sel.enable();
			var obj = (json && json.options ? json : json_decode(xhr.responseText));
			if(!obj.options){ return false; }
			var opts = obj.options;
			sel.options.length = 0;
			sel.options[0] = new Option( "Please select","-",null,false );
			for( var i=0; i<opts.length; i++ ){
				sel.options[i+1] = new Option(opts[i].text,opts[i].value,null,(sel&&sel==opts[i].value?true:false));
			}
		},
		onFailure: function( transport ) {
			$('notice').update( "Sorry - problem." );
		},
		onLoading: function () {
			var sel = $('league_name');
			sel.options.length = 0;
			sel.options[0] = new Option( "Loading...",'-',null,false );
			sel.disable();
		}
	});
}

function showNew( v )
{
	if ( v.checked == true )
		Effect.SlideDown('newleague', {duration: 1.0});
	else
		Effect.SlideUp('newleague', {duration: 1.0});
}

function checkmatch()
{
	var t = $('sprytextfield3').childElements();
	if ( $('pword2').getValue() != $('pwd').getValue() )
	{
		t[0].setStyle({'background-color': '#FF9F9F'});
		t[1].setStyle({display: 'inline', border: '1px solid #CC3333', color: '#CC3333'});
		return false;
	}
	t[0].setStyle({'background-color': '#B8F5B1'});
	t[1].setStyle({display: 'none', border: '', color: ''});
	return true;
}
