function getXMLHttpRequest() {
	var xhr = null;
	
	if (window.XMLHttpRequest || window.ActiveXObject) {
		if (window.ActiveXObject) {
			try {
				xhr = new ActiveXObject("Msxml2.XMLHTTP");
			} catch(e) {
				xhr = new ActiveXObject("Microsoft.XMLHTTP");
			}
		} else {
			xhr = new XMLHttpRequest(); 
		}
	} else {
		alert("Votre navigateur ne supporte pas l'objet XMLHTTPRequest...");
		return null;
	}
	
	return xhr;
}

function openAnnonce(reference){
	window.location.href = "index.php?page=annonce&reference="+reference;
}
/*
function openAnnonce(reference){
	var xhr = getXMLHttpRequest();
	
	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4 && xhr.status==200) {
			_openAnnonce(xhr.responseXML);
		}
	};
	
	xhr.open("POST", "./ajax/ajax.php", false);
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.send("action=listeAnnonces&reference="+reference);
}

function _openAnnonce(Obj){
	var TblAnnonces = Obj.getElementsByTagName("annonce");
	
	if( TblAnnonces.length > 0 ){
		//Affichage du popup contenant la présentation de l'annonce
		popup("popUpDiv");
		
		//pour chaque annonce
		var annonce = new Object();
		var elmt = TblAnnonces[0].getElementsByTagName('*')
		for(var j=0; j<elmt.length; j++){
			var Name = elmt[j].tagName;
			var Content = (typeof(elmt[j].textContent)=="undefined"?elmt[j].text:elmt[j].textContent);
			
			if( elmt[j].tagName == "images" ){
				eval('annonce.'+Name+' = new Array("'+(unescape(Content)).replace(new RegExp("(,)", "g"),'","')+'")');
			}
			else{
				eval('annonce.'+Name+' = "'+unescape(Content)+'"');
			}
		}
		
		var contenu = "";
		contenu += "<table style='width: 850px; height: 550px; text-align: center; border: 2px groove #000000;' border='0' cellpadding='0' cellspacing='2'>" +
				"<tbody>" +
					"<tr>" +
						"<td colspan='3' style='text-align: right;'>" +
							"<img style='width: 24px; height: 24px; cursor: pointer;' title='Fermer' onclick='popup(\"popUpDiv\");' src='imgs/close.png' />" +
						"</td>" +
					"</tr>" +
					"<tr>" +
						"<td style='width: 420px;' colspan='2'>" +
							"<img style='width: 400px; height: 300px; border: 1px solid #888888;' id='popupGrandeImage' src='"+annonce.images[0]+"' />" +
						"</td>" +
						"<td style='vertical-align: top;' rowspan='2'>" +
							"<table style='margin: auto; width: 350px; text-align: left; border: 1px solid #AAAAAA; font-size: 13px;' border='0' cellpadding='2' cellspacing='2'>" +		
								"<thead style='font-weight: bold; background-color: #CCCCCC;'>" +
									"<tr>" +
										"<td colspan='2'>" +
											"<img style='width: 16px; height: 16px;' src='imgs/fleche_rouge.gif' />   " +
											"OFFRE IMMOBILIERE "+annonce.reference +
										"</td>" +
									"</tr>" +
								"</thead>" +
								"<tbody style='background-color: #FFFFFF;'>" +
									"<tr style='border-top: 1px dotted #DDDDDD'>" +
										"<td>" +
											"<ul>" +
												"<li><b>Type : </b>"+annonce.type+"</li>" +
												"<li><b>Ville : </b>"+annonce.ville+"</li>" +
												"<li><b>Surface Habitable : </b>"+annonce.surface+" m²</li>" +
											"</ul>" +
										"</td>" +
										"<td>" +
											"<ul>" +
												"<li><b>Pièces : </b>"+annonce.pieces+"</li>" +
												"<li><b>Chambre(s) : </b>"+annonce.chambres+"</li>" +
											"</ul>" +
										"</td>" +
									"</tr>" +
								"</tbody>" +
								"<tfoot style='background-color: #FFFFFF;'>" +
									"<tr style='border-top: 1px dotted #DDDDDD'>" +
										"<td colspan='2'>" +
											"<ul>" +
												"<li>"+(parseInt(annonce.typebiens)==0?"Prix":"Loyer")+" : "+format(annonce.prix,0,' ')+" € HC</li>" +
												"<li>Charges mensuelles : "+annonce.charges+" €</li>" +
											"<ul>" +
										"</td>" +
									"</tr>" +
								"</tfoot>" +
							"</table>";
							if( annonce.description.length > 0){
								contenu += "<br/>" +
								"<table style='margin: auto; width: 350px; text-align: left; border: 1px solid #AAAAAA;' border='0' cellpadding='2' cellspacing='2'>" +		
									"<thead style='font-weight: bold; background-color: #CCCCCC;geight: 30px;'>" +
										"<tr>" +
											"<td>" +
												"<img style='width: 16px; height: 16px;' src='imgs/fleche_rouge.gif' />   " +
												"Description" +
											"</td>" +
										"</tr>" +
									"</thead>" +
									"<tbody style='background-color: #FFFFFF;'>" +
										"<tr style='border-top: 1px dotted #DDDDDD; font-size: 12px;'>" +
											"<td>" +
												annonce.description +
											"</td>" +
										"</tr>" +
									"</tbody>" +
								"</table>";
							}
							if( annonce.particularites.length > 0){
								contenu += "<br/>" +
								"<table style='margin: auto; width: 350px; text-align: left; border: 1px solid #AAAAAA;' border='0' cellpadding='2' cellspacing='2'>" +		
									"<thead style='font-weight: bold; background-color: #CCCCCC;geight: 30px;'>" +
										"<tr>" +
											"<td>" +
												"<img style='width: 16px; height: 16px;' src='imgs/fleche_rouge.gif' />   " +
												"Particularités" +
											"</td>" +
										"</tr>" +
									"</thead>" +
									"<tbody style='background-color: #FFFFFF;'>" +
										"<tr style='border-top: 1px dotted #DDDDDD; font-size: 12px;'>" +
											"<td>" +
												annonce.particularites +
											"</td>" +
										"</tr>" +
									"</tbody>" +
								"</table>";
							}
						contenu += "</td>" +
					"</tr>" +
					"<tr>" +
						"<td style='text-align: center; background-color: #EEEEEE;width: 40%;'>" +
							"<div style='height:200px;width:100%;overflow:auto;'>";
							if(annonce.images.length > 1){
								for(var k=1; k<annonce.images.length; k++){
									contenu += "<img style='width: 70px; height: 70px; cursor: pointer;' onclick='chargeImage(this)' src='"+annonce.images[k]+"' /> ";
									if((k%3)==0){
										contenu += "<br style='height:2px;'/>";
									}
								}
							}
							else{
								contenu += "Pas d'autres photos disponibles actuellement.";
							}
						contenu += "</div>" +
						"</td>" +
						"<td style='text-align: center; background-color: #EEEEEE;'>" +
							"<img style='width: 110px; height: 120px; cursor: pointer;' src='imgs/dpe/dpe_"+annonce.electricite+".jpg' />" +
							"<img style='width: 110px; height: 120px; cursor: pointer;' src='imgs/dpe/ges_"+annonce.gaz+".jpg' />" +
						"</td>" +
					"</tr>" +
				"</tbody>" +
			"</table>";
		
		removeAllChildNodes("popUpDiv");
		document.getElementById("popUpDiv").innerHTML = contenu;
	}
}*/
