﻿function ajaxFunction()
{
	var xmlHttp;
	var season;
	var matchType;
	var combo = document.getElementById('MatchList');

	try
	{  // Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
	}
	catch (e)
	{  // Internet Explorer
		try
		{
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	
	combo.disabled = true;

	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
		{
			setOutput(xmlHttp, combo);
		}
	}
	
	season = document.getElementById('MatchSeason').value;
	matchType = document.getElementById('MatchType').value;

	var and = String.fromCharCode(38);
	var ajaxUrl = "http://" + window.location.hostname + "/AjaxHandler.aspx" + "?mode=getmffmatches" + and + "season=" + season + and + "matchtype=" + matchType;

	xmlHttp.open("GET", ajaxUrl,true);
	xmlHttp.send(null);
}

function setOutput(xmlHttp) {
	
	var combo = document.getElementById('MatchList');
	combo.options.length = 0;
	var response = xmlHttp.responseText;
	var items = response.split(";");
	var count = items.length - 1;
	
	if (count > 0) {
	    combo.disabled = false;
		for (var i = 0; i < count; i++) {
			var options = items[i].split("|");
			combo.options[i] = new Option(options[0], options[1]);
		}
	}
}

function Toggle_wait(combo)
{
}

function MatchList_SelectedIndexChanged(matchSelector)
{
	if(matchSelector.options[matchSelector.selectedIndex].value != '-1')
	{
		window.location.href = matchSelector.options[matchSelector.selectedIndex].value;
	}
}
