function selected(os_num, data)
{
	/* Unselect other items */
	try
	{
		for (i = 0; i < stable.platforms.length; i++)
		{
			document.getElementById("stable_td" + i).style.removeProperty("background");
			document.getElementById("stable_td" + i).style.removeProperty("border");
		}
		for (i = 0; i < supported.platforms.length; i++)
		{
			document.getElementById("supported_td" + i).style.removeProperty("background");
			document.getElementById("supported_td" + i).style.removeProperty("border");
		}
	}
	catch (ex) {}
	/* Highlight and select the chosen item */
	document.getElementById(data.data + "_td" + os_num).style.border = "1px solid #888";
	document.getElementById(data.data + "_td" + os_num).style.background = "#fff";
	
	// Clean out the html for steps after 1
	document.getElementById("step2").innerHTML = "";
	document.getElementById("step3").innerHTML = "";
	document.getElementById("step4").innerHTML = "";

	if (data.platforms[os_num].name != "Other")
	{
		if ((data.platforms[os_num].version.length == 1) &&
		    (data.platforms[os_num].version[0].arch.length == 1))
		{
			download_step("2", os_num, 0, 0, data);
		}
		else
		{
			version_step(os_num, data);
		}
	}
	else
	{
		unsupported_step(os_num, data);
	}
}

function unsupported_step(os_num, data)
{
	var html = "<h2>2. Mono for Unsupported or Community-Supported Distribution</h2>";
	html += "<p>A number of distributions are supported by their own communities. Please select your platform below:</p><table class=\"os\"><tr>";

	for(i=0;i<data.platforms[os_num].version.length;i++)
	{
		html += "<td class='os' id='unsuptd"+i+"'>";
		html += "<div class='os' onClick='location.href=\""+data.platforms[os_num].version[i].url+"\"'>";
		html += "<div class='os-rd'><input type='radio' name='os' id='unsuprb"+i+"' onClick='location.href=\""+data.platforms[os_num].version[i].url+"\"'></div>";
		html += "<div class='os-id'><img alt='"+data.platforms[os_num].version[i].name+"' src='"+data.platforms[os_num].version[i].icon+"'><br />"+data.platforms[os_num].version[i].name+"</div>";
		html += "</div></td>";
	}

	html += "</tr></table>";
	document.getElementById("step4").innerHTML = html;
}

function version_step(os_num, data)
{
	document.getElementById("step3").innerHTML = "";

	var html = "<h2>2. " + data.platforms[os_num].name  + " Version</h2>";
	html += "<br><select size='4' onchange=\"arch_step(" + os_num + ", this.options[this.options.selectedIndex].value, " + data.data + ")\">";

	for (i=0; i <  data.platforms[os_num].version.length; i++)
	{
		html += "<option value='" + i + "' style='cursor: pointer;'>" + data.platforms[os_num].version[i].name  + "</option>";
	}

	html += "</select><br><br>";
	document.getElementById("step2").innerHTML = html;
}

function arch_step(os_num, os_version, data)
{
	document.getElementById("step4").innerHTML = "";

	var html = "<h2>3. Processor Architecture</h2>";
	html += "<br><select size='4' onchange='download_step(\"4\", \"" + os_num + "\",\"" + os_version + "\", this.options[this.options.selectedIndex].value, " + data.data + ")'>";

	for (i=0; i <  data.platforms[os_num].version[os_version].arch.length; i++)
	{
		html += "<option value='" + i + "' style='cursor: pointer;'>" + data.platforms[os_num].version[os_version].arch[i].name + "</option>";
	}

	html += "</select>";
	document.getElementById("step3").innerHTML = html;
}

function download_step(step_number, os_num, ver_num, arch_num, data)
{
	if (data.platforms[os_num].name == "LiveCD")
		html = "<h2>" + step_number + ". Download Mono "+ data.platforms[os_num].name + "</h2>";
	else
		html = "<h2>" + step_number + ". Download Mono for "+ data.platforms[os_num].name + "</h2>";

	html += "<br><table>";
	if (data.platforms[os_num].version[ver_num].arch[arch_num].desc != "")
	{
		html += "<tr><td colspan='2'>" + data.platforms[os_num].version[ver_num].arch[arch_num].desc + "</tr>";
	}
	html += "<tr><td class='osicon'><img class='osicon' src='" + data.platforms[os_num].dlicon + "'></td><td>";
	html +=  data.platforms[os_num].version[ver_num].arch[arch_num].downloadText;
	//html += "<td>Mono for Windows, Gtk#, and XSP";
	//html += "<ul><li><a href='ftp://www.go-mono.com/archive/1.2.6/windows-installer/4/mono-1.2.6-gtksharp-2.10.2-win32-4.exe'>Mono 1.2.6_4 Setup</a></ul>";
	//html += "Only Gtk# for .NET: <ul><li><a href=' http://forge.novell.com/modules/xfmod/project/?gtks-inst4win'>SDK and Runtime</a></ul>";
	//html += "Mono Migration Analyzer: <ul><li><a href='http://mono-project.com/MoMA'>See the Mono Migration Analyzer page</a></ul>";
	html += "</td></tr></table>";

	document.getElementById("step" + step_number).innerHTML = html;
}

