jQuery.fn.exists = function() {return this.length>0;}

function urlencode(str) {
	return escape(str).replace('+', '%2B').replace('%20', '+').replace('*', '%2A').replace('/', '%2F').replace('@', '%40');
}

function urldecode(str) {
	return unescape(str.replace('+', ' '));
}

function TableChanged() {
    var league = $('#league_selector').val();
    var url = location.protocol + '//' + location.host + location.pathname + 
    		"?eID=handball_infobox_request&infotype=league&league="+urlencode(league);
    $("#league_overview_container").load(url);
}

function MatchDayChanged() {
    var league = $('#league_selector').val();
    var matchDay = "";
	if ($('#match_day_selector').exists()) {
		matchDay =  $('#match_day_selector').val();
	}
    var url = location.protocol + '//' + location.host + location.pathname + 
    		"?eID=handball_infobox_request&infotype=results&league="+urlencode(league)+"&match_day="+urlencode(matchDay);
    $("#league_overview_container").load(url);	
}

function LeagueChanged() {
    var league = $('#league_selector').val();
    var matchDay = "";
    var url = location.protocol + '//' + location.host + location.pathname + 
    		"?eID=handball_infobox_request&infotype=results&league="+urlencode(league)+"&match_day=";
    $("#league_overview_container").load(url);	
}

