function clearoutclasses(id, tag){
	for (i=0; (a = document.getElementById(id).getElementsByTagName(tag)[i]); i++) {
		a.className = "";
	}
}


function loadXMLDoc(url){
	req = false;
	if (typeof XMLHttpRequest != "undefined"){
		req = new XMLHttpRequest();
	}
	else if (typeof window.ActiveXObject != "undefined"){
		try{
			req = new ActiveXObject("Msxml2.XMLHTTP.4.0");
		}
		catch(e){
			try {
				req = new ActiveXObject("MSXML2.XMLHTTP");
			}
			catch(e){
				try{
					req = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch(e){
					req = null;
					document.getElementById("example").innerHTML = "Your browser can\'t handle this script\n";
					return;
				}
			}
		}
	}
	if (req) {
		req.onreadystatechange = processReqChange;
		req.open("GET", url, true);
		req.send("");
	}
}


function processReqChange(){
	if (req.readyState == 4) {
		if (req.status == 200) {
			doc = req.responseText;
			build(doc);
		}
		else {
			document.getElementById("example").innerHTML = "There was a problem retrieving the XML data:\n" + req.statusText;
		}
	}
}


function build(node){
	var output = document.getElementById("example");
	output.innerHTML = node;
}


var req;


window.onload = function(){
	var i, a;
	if (document.getElementById("examples")) {
		for (i=0; (a = document.getElementById("examples").getElementsByTagName("a")[i]); i++) {
			if (i==0) {
					document.getElementById("example").innerHTML = "<img src=\"/loading.gif\" alt=\"loading...\"/>";
					loadXMLDoc(a.getAttribute("href"));
					clearoutclasses("examples", "a");
					a.className = "selected";
			}
			a.onclick = function(){
				document.getElementById("example").innerHTML = "<img src=\"/loading.gif\" alt=\"loading...\"/>";
				loadXMLDoc(this.getAttribute("href"));
				clearoutclasses("examples", "a");
				this.className = "selected";
				return false;
			}
		}
	}
}
