// JavaScript Document
function sendRequest(url, conteneur, postData) {
	
	window.document.getElementById(conteneur).innerHTML = '<IMG src="/gestion/images/loading.gif" width="32" height="32">';
	setTimeout ("sendXMLHTTP('"+url+"', '"+conteneur+"', '"+postData+"');", 100);
}

function getRequest(url, postData){
	if (postData != '') postData += "&";
	postData += ('sessionid=' + window.document.body.getAttribute('sessionid') + '&rnd=' + Math.random( ));

	var xmlhttp = createXMLHTTPObject();
	xmlhttp.open("POST", url, false);
	xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlhttp.send(postData);

	return xmlhttp.responseText;
	
	xmlhttp.abort;
}

function sendXMLHTTP(url, conteneur, postData) {
		
	var req = createXMLHTTPObject();
	if (!req) return;
	
	if (postData != '') postData += "&";
	
	var method = (postData) ? "POST" : "GET";
	req.open(method,url,true);
	req.setRequestHeader('Content-type','application/x-www-form-urlencoded');
	
	if (postData)
		
		req.onreadystatechange = function () {
		
		if (req.readyState != 4)  return;
		if (req.status != 200 && req.status != 304 && req.status != 0) {
			alert('HTTP error ' + req.status);
		}
		handleRequest(req, conteneur);		
	}
	if (req.readyState == 4) return;
	req.send(postData);
}

var XMLHttpFactories = [
	function () {return new XMLHttpRequest()},
	function () {return new ActiveXObject("Msxml2.XMLHTTP")},
	function () {return new ActiveXObject("Msxml3.XMLHTTP")},
	function () {return new ActiveXObject("Microsoft.XMLHTTP")}
];

function createXMLHTTPObject() {

	var xmlhttp = false;
	for (var i=0;i<XMLHttpFactories.length;i++) {
		try {
			xmlhttp = XMLHttpFactories[i]();
		}
		catch (e) {
			continue;
		}
		break;
	}
	return xmlhttp;
}

function handleRequest(req, conteneur) {
	var writeroot = window.document.getElementById(conteneur);
	if (req.responseText.substring(0,9) == "<!--LOGIN") top.window.location = "login.asp";
	writeroot.innerHTML = req.responseText;
}

function gotoURL(myUrl){
	var sep = '?';
	if (myUrl.indexOf('?') > 0) sep = "&";
	//window.location.replace(myUrl);
	window.location = myUrl;
}
