function go(c){
	if(!c.data.replace(/\s/g,''))
	c.parentNode.removeChild(c);
}

function clean(d){
	var bal=d.getElementsByTagName('*');
	
	for(i=0;i<bal.length;i++){
		a=bal[i].previousSibling;
		if(a && a.nodeType==3) 
			go(a);
		b=bal[i].nextSibling;
		if(b && b.nodeType==3)
			go(b);
	}
	return d;
} 

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;
}

function changeMarque(id){
	var xhr = getXhr();
	xhr.onreadystatechange = function(){
		if(xhr.readyState == 4 && xhr.status == 200){
			reponse = clean(xhr.responseXML.documentElement);
			var models=reponse.getElementsByTagName("model");
			var model_id;
			var model_libelle;
			var html="<option value=\"0\">- Choisir un model</option>";
			for(var u=0;u<models.length;u++) {
				model_id=reponse.getElementsByTagName("model")[u].getAttribute("id");
				model_libelle=models[u].firstChild.nodeValue;
				html+="<option value=\""+model_id+"\">"+model_libelle+"</option>";
			}
			
			document.getElementById('model').innerHTML = html;
		}
	}
	
	xhr.open("POST","plugins/annonces/scripts/ajax_change_marque.php",true);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr.send("m="+id);
}

function ficheAnnonceur(id){
	var xhr = getXhr();
	xhr.onreadystatechange = function(){
		if(xhr.readyState == 4 && xhr.status == 200){
			reponse = clean(xhr.responseXML.documentElement);
			var nom=reponse.getElementsByTagName("nom")[0].firstChild.nodeValue;
			var prenom=reponse.getElementsByTagName("prenom")[0].firstChild.nodeValue;
			var telephone=reponse.getElementsByTagName("telephone")[0].firstChild.nodeValue;
			var email=reponse.getElementsByTagName("email")[0].firstChild.nodeValue;
			var departement=reponse.getElementsByTagName("departement")[0].firstChild.nodeValue;
			var html='<table><tr class="on"><td align="right" width="150"><b>Nom</b></td><td align="left">'+nom+'</td></tr><tr class="off"><td align="right"><b>Pr&eacute;nom</b></td><td align="left">'+prenom+'</td></tr><tr class="on"><td align="right"><b>Email</b></td><td align="left"><a href="mailto:'+email+'">'+email+'</a></td></tr><tr class="off"><td align="right"><b>T&eacute;l&eacute;phone</b></td><td align="left">'+telephone+'</td></tr><tr class="on"><td align="right"><b>D&eacute;partement</b></td><td align="left">'+departement+'</td></tr></table>'; 
			document.getElementById('ficheVendeur').innerHTML = html;
		}
	}
	
	xhr.open("POST","plugins/annonces/scripts/ajax_fiche_vendeur.php",true);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr.send("m="+id);
}
