function getXhr(){
	var xhr = null; 
	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
}



/* Chargement des coups de coeur */
function chargeCoupCoeur(position){
	var xhr=getXhr();
    xhr.onreadystatechange = function() { 
		if (xhr.readyState==4 && xhr.status == 200) 
    	{
			var html = xhr.responseText;	
			if(html.substring(0,6)!="Erreur"){
				document.getElementById("coeurbox").style.display="none";
				document.getElementById("coeurbox").innerHTML = html;	
				if(html!=""){ document.getElementById("coeurbox").style.display="block"; }
			}
			else{
				alert(html);
			}
   		}
	};

	xhr.open("POST","coupcoeur.php",true);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr.send("position="+position);
}

/* Chargement des photos */
function chargePhoto(id_prod,position, callback){
	var xhr=getXhr();
    xhr.onreadystatechange = function() { 
		if (xhr.readyState==4 && xhr.status == 200) 
    	{
			var html = xhr.responseText;	
			if(html.substring(0,6)!="Erreur"){
				document.getElementById("photobox").style.display="none";
				document.getElementById("photobox").innerHTML = html;	
				if(html!=""){ document.getElementById("photobox").style.display="block"; }
				
				if (callback!=null) {callback();}
				
			}
			else{
				alert(html);
			}
   		}
	};

	xhr.open("POST","photo.php",true);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr.send("id_prod="+id_prod+"&position="+position);
}



/* Chargement des coups de coeur espagnol */
function chargeCoupCoeur_es(position){
	var xhr=getXhr();
    xhr.onreadystatechange = function() { 
		if (xhr.readyState==4 && xhr.status == 200) 
    	{
			var html = xhr.responseText;	
			if(html.substring(0,6)!="Erreur"){
				document.getElementById("coeurbox_es").style.display="none";
				document.getElementById("coeurbox_es").innerHTML = html;	
				if(html!=""){ document.getElementById("coeurbox_es").style.display="block"; }
			}
			else{
				alert(html);
			}
   		}
	};

	xhr.open("POST","coupcoeur_es.php",true);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr.send("position="+position);
}

/* Chargement des photos espagnol */
function chargePhoto_es(id_prod,position, callback){
	var xhr=getXhr();
    xhr.onreadystatechange = function() { 
		if (xhr.readyState==4 && xhr.status == 200) 
    	{
			var html = xhr.responseText;	
			if(html.substring(0,6)!="Erreur"){
				document.getElementById("photobox_es").style.display="none";
				document.getElementById("photobox_es").innerHTML = html;	
				if(html!=""){ document.getElementById("photobox_es").style.display="block"; }
				callback();
			}
			else{
				alert(html);
			}
   		}
	};

	xhr.open("POST","photo_es.php",true);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr.send("id_prod="+id_prod+"&position="+position);
}


/* Traduire en français */
function TransFr(){
	var page = window.location.pathname;
	var arg = window.location.search;
	var reg1=new RegExp("_es","g");
	if(reg1.test(page)){
		page = page.substring(0,page.length-7);
	}
	else{
		page = page.substring(0,page.length-4);
	}
	if(page==""){ page = "index"; }
	window.location = page+".php"+arg;
}

/* Traduire en espagnol */
function TransEs(){
	var page = window.location.pathname;
	var arg = window.location.search;
	var reg1=new RegExp("_es","g");
	if(reg1.test(page)){
		page = page.substring(0,page.length-7);
	}
	else{
		page = page.substring(0,page.length-4);
	}
	if(page==""){ page = "index"; }
	window.location = page+"_es.php"+arg;
}

/* Envoi à un ami */
function EnvoiAmi(){
	window.location = "contact2.php?lien="+window.location.href;
}

function EnvoiAmi_es(){
	window.location = "contact2_es.php?lien="+window.location.href;
}