var req = Array ();
var divs = Array ();
var funs = Array ();
var ends = Array ();
var sends = Array();

var content;
var divToWrite;
var fun_exec;
var instid = 0;

function loadXMLDoc(url, div, fun, sendid) 
{
    instid++;
    divs[instid] = ''+div;
    sends[instid] = (sendid == null) ? false : sendid;
    ends[instid] = false;
    
    if(fun=='') {
        fun_exec = '';
    } else {
	fun_exec = ''+fun; 
    }

    funs[instid] = fun_exec;

    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
	req[instid] = new XMLHttpRequest();
	req[instid].open("GET", url, true);
	req[instid].send(null);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        req[instid] = new ActiveXObject("Microsoft.XMLHTTP");
	if (req[instid]) {
	    req[instid].open("GET", url, true);
	    req[instid].send();
	}
    }

    req[instid].onreadystatechange = function() {
    // only if req shows "complete"

    for(i=1;i<=instid;i++) {
    if (req[i].readyState == 4 && !ends[i]) {
	// only if "OK"
	if(divs[i] == '') {
	    if(funs[i] == '') {
	    } else {
	    	if(sends[i] == true) {
            	    eval(funs[i] +'(' + i + ')');
	    	} else {
	      	    eval(funs[i] +'()');
		}
	    } 
	    ends[i] = true;
    	} else {
    	    document.getElementById(''+divs[i]).innerHTML = req[i].responseText;
	    if(funs[i] != '') {
	      if(sends[i] == true ) {
		eval(funs[i] +'(' + i + ')');
	      } else {
		eval(funs[i] + '()');
	      }
	      ends[i] = true;
	    }
    	}
    	//alert("FINISH!");
    	//if (req[i].status == 200) {
    	    // ...processing statements go here...
    	//} else {
	    //alert("There was a problem retrieving the XML data:\n" + req.statusText);
    	//}
    }
    }
  }
}
