// ************** affichage des miniatures *************
function afficherMinis(gal,lang,deb,nbre){
	// gal == id de la galerie sélectionnée
	// lang == langue courante
	// deb == indice du premier enregistrement à récupérer
	// nbre == nbre total d'enregistrements
	// nbre_minis == nombre de miniatures à afficher
	var xhr=null;
	if (window.XMLHttpRequest){ 
		xhr = new XMLHttpRequest();
	}else if (window.ActiveXObject){
		xhr = new ActiveXObject("Microsoft.XMLHTTP");
	}
	if(xhr != null){
		xhr.onreadystatechange = function() { resultAfficherMinis(xhr);};
		xhr.open("GET", "afficher-minis.php?gal="+gal+"&lang="+lang+"&deb="+deb+"&nbre="+nbre, true);
		xhr.send(null);
	}
}

function resultAfficherMinis(xhr){
	if (xhr.readyState == 4  && xhr.status == 200){
		document.getElementById('minis').innerHTML = xhr.responseText;
	}
}

// ************** affichage des données d'une photo ************
function afficherPhoto(num,lang){
	// num == identifiant de la photo
	// lang == langue courante
	var xhr=null;
	if (window.XMLHttpRequest){ 
		xhr = new XMLHttpRequest();
	}else if (window.ActiveXObject){
		xhr = new ActiveXObject("Microsoft.XMLHTTP");
	}
	if(xhr != null){
		xhr.onreadystatechange = function() { resultAfficherPhoto(xhr);};
		xhr.open("GET", "afficher-photo.php?id="+num+"&lang="+lang, true);
		xhr.send(null);
	}
}

function resultAfficherPhoto(xhr){
	if (xhr.readyState == 4  && xhr.status == 200){
		if(xhr.responseXML.documentElement){
			function ouvrir(){ win=window.open(this.href,'_blank'); if(win) return false;}
			var doc = xhr.responseXML.documentElement;
			if(doc.getElementsByTagName('descriptif').length != 0) document.getElementById('descriptif_photo').innerHTML = doc.getElementsByTagName('descriptif')[0].firstChild.nodeValue;
			else document.getElementById('descriptif_photo').innerHTML = "";
			document.getElementById('titre_photo').firstChild.nodeValue = doc.getElementsByTagName('titre')[0].firstChild.nodeValue;
			document.getElementById('apercu_photo').src = doc.getElementsByTagName('url')[0].firstChild.nodeValue;
			if(doc.getElementsByTagName('alt').length != 0) document.getElementById('apercu_photo').alt = doc.getElementsByTagName('alt')[0].firstChild.nodeValue;
			else document.getElementById('apercu_photo').alt = "";
			document.getElementById('commander_photo').innerHTML = "";
			if(doc.getElementsByTagName('envente')[0].firstChild.nodeValue == "1"){
				var cmd = document.createElement("a");
				cmd.setAttribute("href","bon-commande.pdf");
				cmd.setAttribute("target","_blank");
				cmd.innerHTML = "Commander cette oeuvre";
				document.getElementById('commander_photo').appendChild(cmd); 
			}
		}
	}
}
