
var xhr = new Array(); // ARRAY OF XML-HTTP REQUESTS
var xi = new Array(0); // ARRAY OF XML-HTTP REQUEST INDEXES
xi[0] = 1; // FIRST INDEX SET TO 1 MAKING IT AVAILABLE

function xhrRequest(type) {
	if (!type) {
	type = 'html';
	}
	// xhrsend IS THE xi POSITION THAT GETS PASSED BACK
	// INITIALIZED TO THE LENGTH OF THE ARRAY(LAST POSITION + 1)
	// IN CASE A FREE RESOURCE ISN'T FOUND IN THE LOOP
	var xhrsend = xi.length;
	// GO THROUGH AVAILABLE xi VALUES
	for (var i=0; i<xi.length; i++) {
	// IF IT'S 1 (AVAILABLE), ALLOCATE IT FOR USE AND BREAK
		if (xi[i] == 1) {
		xi[i] = 0;
		xhrsend = i;
		break;
		}
	}

	// SET TO 0 SINCE IT'S NOW ALLOCATED FOR USE
	xi[xhrsend] = 0;

// SET UP THE REQUEST
if (window.ActiveXObject) {
	try {
	xhr[xhrsend] = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
		xhr[xhrsend] = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) {}
	}
} else if (window.XMLHttpRequest) {
xhr[xhrsend] = new XMLHttpRequest();

	if (xhr[xhrsend].overrideMimeType) {
	xhr[xhrsend].overrideMimeType('text/' + type);
	}
}
return (xhrsend);
}


function ajaxRequest(proc, mode, url, query, target_id, status_id, loading_size) {

var xhri = xhrRequest('html');
xhr[xhri].open('POST', url+'?proc='+proc, true);
xhr[xhri].setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr[xhri].setRequestHeader("Connection", "close");

	xhr[xhri].onreadystatechange = function() {
	if (xhr[xhri].readyState == 1) {
	document.getElementById(status_id).innerHTML = '<img src="img/loading.gif" width="'+loading_size+'" height="'+loading_size+'" border="0" alt="loading...">';
	}
	if (xhr[xhri].readyState == 4 && xhr[xhri].status == 200) {
		if (mode =='form') {
		document.getElementById(target_id).value = xhr[xhri].responseText;
		} else {
		document.getElementById(target_id).innerHTML = xhr[xhri].responseText;
		}
	 // alert(xhr[xhri].responseText);	// debug
	
	xi[xhri] = 1;
	xhr[xhri] = null;
	}
	};
xhr[xhri].send(query);
}


//ajaxRequest('test', 'div', 'ajax/content.php', query, target_id, status_id);


