var xhr = new Array();
var xi = new Array(0);

xi[0] = 1; 

function xhrRequest(type) {
	
	if (!type) {
		type = 'html';
	}

	var xhrsend = xi.length; 
	
	for (var i=0; i<xi.length; i++) {
		if (xi[i] == 1) {
			xi[i] = 0;
			xhrsend = i;
			break;
		}
	}
	
	xi[xhrsend] = 0;
	
	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 ajax_get(url, res_id) {
	
	var xhri = xhrRequest('html');
	
	xhr[xhri].open('GET', url, true);
	
	xhr[xhri].onreadystatechange = function() {
		if (xhr[xhri].readyState == 4 && xhr[xhri].status == 200) {
			document.getElementById(res_id).innerHTML = xhr[xhri].responseText;
			xi[xhri] = 1;
			xhr[xhri] = null;
		}
	};
	
	xhr[xhri].send(null);
}

function ajax_post(url, parameters, res_id) {
	
	var xhri = xhrRequest('html');	
	
	xhr[xhri].open('POST', url, true);
    params = parameters;
    xhr[xhri].setRequestHeader("Content-type", "application/x-www-form-urlencoded")
    xhr[xhri].send(parameters)
	
	xhr[xhri].onreadystatechange = function() {
		if (xhr[xhri].readyState == 4 && xhr[xhri].status == 200) {
			document.getElementById(res_id).innerHTML = xhr[xhri].responseText;
			xi[xhri] = 1;
			xhr[xhri] = null;
		}
	};
	
	xhr[xhri].send(null);
}