$(document).ready(function(){
	var loc = window.location.protocol + "//" + window.location.host + "/";
	if (window.location.host == "localhost") { loc += "betscout/html/" };

	var page = "goals";
	
	// Hide all but sport select
	$('#goals_select_country').hide();
	$('#goals_select_league').hide();
	
	// Add options to sport and time
	$("#goals_select_sport").ajaxAddOption(loc+"ajax/boxvalues/"+page+"/not_set/not_set/not_set/1",{},false);
	
	$('#goals_select_sport').change(function(){
		var sport_id = ($("select#goals_select_sport").val() != "") ? $("select#goals_select_sport").val() : "not_set";
		// var country_id = ($("select#goals_select_country").val() != "") ? $("select#goals_select_country").val() : "not_set";
		// var league_id = ($("select#goals_select_league").val() != "") ? $("select#goals_select_league").val() : "not_set";
		var country_id = "not_set";
		var league_id = "not_set";
		var string = page+'/'+sport_id+'/'+country_id+'/'+league_id;
		
		$(".tableloading").show();
		
		// Hide all but sport select
		$('#goals_select_country').hide();
		$('#goals_select_league').hide();

		$("#goals_select_country").removeOption(/./);
		$("#goals_select_league").removeOption(/./);
		$("#goals_select_country").ajaxAddOption(loc+"ajax/boxvalues/"+string,{},false);
		
		$("#goalstable").load(loc+"ajax/tablevalues/"+string, '', function() {
			$(".tableloading").hide();
			
			if (sport_id != 'not_set') {
				// Show the next select
				$("#goals_select_country").show();
			};
		});
	});
	
	$('#goals_select_country').change(function(){
		var sport_id = ($("select#goals_select_sport").val() != "") ? $("select#goals_select_sport").val() : "not_set";
		var country_id = ($("select#goals_select_country").val() != "") ? $("select#goals_select_country").val() : "not_set";
		// var league_id = ($("select#goals_select_league").val() != "") ? $("select#goals_select_league").val() : "not_set";
		var league_id = "not_set";
		var string = page+'/'+sport_id+'/'+country_id+'/'+league_id;
		
		$(".tableloading").show();
		
		// Hide all but sport select
		$('#goals_select_league').hide();
		
		$("#goals_select_league").removeOption(/./);
		$("#goals_select_league").ajaxAddOption(loc+"ajax/boxvalues/"+string,{},false);
		
		$("#goalstable").load(loc+"ajax/tablevalues/"+string, '', function() {
			$(".tableloading").hide();
			
			// Show the next select
			$("#goals_select_league").show();
		});
	});
	
	$('#goals_select_league').change(function(){
		var sport_id = ($("select#goals_select_sport").val() != "") ? $("select#goals_select_sport").val() : "not_set";
		var country_id = ($("select#goals_select_country").val() != "") ? $("select#goals_select_country").val() : "not_set";
		var league_id = ($("select#goals_select_league").val() != "") ? $("select#goals_select_league").val() : "not_set";
		var string = page+'/'+sport_id+'/'+country_id+'/'+league_id;
		
		$(".tableloading").show();
		
		$("#goalstable").load(loc+"ajax/tablevalues/"+string, '', function() {
			$(".tableloading").hide();
		});
	});
});
