function getXhr(){
	if(window.XMLHttpRequest){ // Firefox et autres
		xhr = new XMLHttpRequest();  
	}else if(window.ActiveXObject){ // Internet Explorer 
			try {
				xhr = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
			    xhr = new ActiveXObject("Microsoft.XMLHTTP");
			}
		}
	else { // XMLHttpRequest non supporté par le navigateur 
		 alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
		 xhr = false; 
	} 
	return xhr;
}

//Fonction d'update d'une page via AJAX dans une popup
function goPopup(path,params){
	var xhr=getXhr();
	xhr.abort();
	var varToSend
	xhr.onreadystatechange = function(){
		if(xhr.readyState == 4 && xhr.status == 200){
			leselect = xhr.responseText;
			showMyPopup();
			updateMyPopup(leselect);
		}
	}
	
	xhr.open("POST",path,true);
	
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	
	//On mets en forme le resultat du tableau pour le passer au path correctement : 
	//params.join('&') => valeur1=resultat1&valeur2=resultat2
	xhr.send(params.join('&'));
}


function showMyPopup()
{
	//Affichage du calque de fond noir
	$('ajaxbox-overlay').style.display = 'block';
}

function hideMyPopup()
{
	var box = $('ajaxbox');
	var overlay = $('ajaxbox-overlay');
	box.style.display = 'none';
	overlay.style.display = 'none';
	box.innerHTML = '';
}
	
//Ajout de la reponse html (data) dans la box
function updateMyPopup(data)
{
	var box = $('ajaxbox');
	box.style.visibility = 'hidden';
	box.style.display = 'block';
	if (data) box.innerHTML = data;
	//Resize et centrage de la box
	box.style.marginTop = '-'+Math.round(box.offsetHeight/2)+'px';
	box.style.marginLeft = '-'+Math.round(box.offsetWidth/2)+'px';
	box.style.visibility = 'visible';
}
