var $J	= jQuery.noConflict();

function jsjemdebug( showme, ret ) {
	var msg	= "";
	ret		= ( ret == 'undefined' ) ? false: ret;
	if (typeof showme == 'object') {
		var z = 0;
		for ( key in showme ) {
			msg     += "KEY: " + key + " VAL: "+ showme[key] + "\n";
		}
	} else {
		msg     += "VARTYPE: " + (typeof showme) + " VARVAL: " + showme + "\n";
	}
	if ( ret ) {
		return msg;
	} else {
		alert(msg);
	}
	//document.write("<textarea rows='50' cols='200'>" + msg + "</textarea>");
	//document.close();
}

function fetch_scores() {
	var season		= $J("#current_season").val();
	var district	= $J("#current_district").val();
	var year		= $J("#current_year").val();
	var month		= $J("#current_month").val();
	var day			= $J("#current_day").val();
	$J("#school_name").val("");
	var params		= {
		op: 				"fetch_scores",
		current_season: 	season,
		current_district:	district,
		current_year:		year,
		current_month:		month,
		current_day:		day
	};
	clearTimeout(t);
	$J(target_container).load("/scoreboardlive/scoreboard_ajax.php", params, function () {
		var num_seconds	= 30;
		var timeout		= num_seconds * 1000;
		t				= setTimeout("fetch_scores()",timeout);
		timer_on		= 1;
	});

var showme	= target_container;
var ret		= false;
//jsjemdebug( showme, ret );
}

function search_scores() {
var showme	= "hello";
var ret		= false;
//jsjemdebug( showme, ret );
	var season		= $J("#current_season").val();
	var school_name	= $J("#school_name").val();
	var params		= {
		op: 				"search_scores",
		current_season: 	season,
		school_name:		school_name
	};
	if ( school_name.length > 3 ) {
		$J(target_container).load("/scoreboardlive/scoreboard_ajax.php", params, function () {
			var num_seconds	= 30;
			var timeout		= num_seconds * 1000;
			t				= setTimeout("search_scores()",timeout);
			timer_on		= 1;
		});
	}
}

var timer_on	= 0;
var t;
$J(document).ready( function () {
	if ( $J("#school_name").length ) {
		$J("#school_name").bind( 'keyup', function() {
			clearTimeout(t);
			search_scores();
		});
	}
	if ( $J("#target_container").length ) {
		$J("#current_district").bind( 'change', function() {
			clearTimeout(t);
			fetch_scores();
		});
		fetch_scores();
	}
});

