// Cross-browser XMLHttpRequest instantiation.
if (typeof XMLHttpRequest == 'undefined') {
	XMLHttpRequest = function () {
		var msxmls = ['MSXML3', 'MSXML2', 'Microsoft']
		for (var i=0; i < msxmls.length; i++) {
			try {
				req = new ActiveXObject(msxmls[i]+'.XMLHTTP')
				if (req) {
					return req
				}
			} catch (e) { }
		}
		throw alert("No XML component installed!")
	}
}

function echoDelay(input){
	document.getElementById("AjaxLogEcho").innerHTML = "&nbsp;&nbsp;&nbsp;Loading (echoDealy) ...&nbsp;&nbsp;&nbsp;";
	url_xml = '/ajax/examples/xmlEcho.php?echo=' + input;
	loadXMLDocEcho(url_xml);
}

function loadXMLDocEcho(url_xml)
{
	//document.getElementById("AjaxLogEcho").innerHTML = url_xml;
	req = new XMLHttpRequest();
	req.onreadystatechange = processReqChangeEcho;
	req.open("GET", url_xml, true);
	req.send(null);
}

function processReqChangeEcho()
{
	// only if req shows "complete"
	if (req.readyState == 4) {
		// only if "OK"
		if (req.status == 200) {
			try {
				//alert(req.responseText);
				document.getElementById("AjaxEcho").innerHTML = req.responseText;
				
				document.getElementById("AjaxLogEcho").innerHTML = "";
			}
			catch (e) {
				document.getElementById("AjaxLogEcho").innerHTML = "&nbsp;&nbsp;&nbsp;There was a problem parsing the data: " + response.responseText + "&nbsp;&nbsp;&nbsp;";
				alert("There was a problem parsing the data:\n" + req.responseText);
			}
		} 
		else {
			document.getElementById("AjaxLogEcho").innerHTML = "&nbsp;&nbsp;&nbsp;There was a problem retrieving the data: " + req.statusText + "&nbsp;&nbsp;&nbsp;";
			alert("There was a problem retrieving the data:\n" + req.statusText);
		}
	}
}
