//
//
//  JavaScript Refactoring for safer, faster, better AJAX.
//
//  Copyright 2005, Pavel Simakov, 
//  http://www.softwaresecretweapons.com
//
//

var req;
var ready = false;
 
function loadXMLDoc(url) {
    ready = false;

    // branch for browser specific code
    if (window.XMLHttpRequest) {

	// non-IE 
        req = new XMLHttpRequest();
        req.onreadystatechange = processStateChange;
        req.open("GET", url, true);
        req.send(null);

    } else {
    
		if (window.ActiveXObject) {

		// IE
	        req = new ActiveXObject("Microsoft.XMLHTTP");
        	if (req) {
	            req.onreadystatechange = processStateChange; 
        	    req.open("GET", url, true);
			    req.setrequestheader("Pragma","no-cache");
   			    req.setrequestheader("Cache-control","no-cache");
        	    req.send();
	        } else {
				alert("This browser does not support XMLHttpRequest.");
			}
		}
	}
}


function processStateChange() {
	if (req.readyState == 4) {
   		if (req.status == 200) {			
			processXML(req.responseXML);
			processText(req.responseText);		
			ready = true;
			alert("Done");
		} else {
			alert("There was a problem retrieving the XML data:\n status code " + req.status);
		}
	} else {
		// do nothing and keep waiting - request is not ready yet
	}

}

function processXML(xml){
	// here we parse XML document
}

function processText(text){
	document.getElementById('outputText').value = text;	
}
