var isDragging = false;
var objectToDrag;
var obj;
var ecartX;
var ecartY;
var curX;
var curY;
var regex = new RegExp("[A-Za-z0-9._-]{1,}@[A-Za-z0-9._-]{1,}[.][A-Za-z]{2,}", "gi");
var regex2 = new RegExp("[0-9]{4,}", "gi");
var euro = new RegExp("[0-9]{4,}", "gi");

var ouvert = 0;

function positionne(p_id, p_posX, p_pos_Y){
	document.getElementById(p_id).style.left = p_posX;
	document.getElementById(p_id).style.top = p_pos_Y;
}

function getPositionCurseur(e){
	//ie
	if(document.all){
		curX = event.clientX;
		curY = event.clientY;
	}
	
	//netscape 4
	if(document.layers){
		curX = e.pageX;
		curY = e.pageY;
	}
	
	//mozilla
	if(document.getElementById){
		curX = e.clientX;
		curY = e.clientY;
	}
}

function beginDrag(p_obj,e){
	isDragging = true;
	objectToDrag = p_obj;
	getPositionCurseur(e);
	ecartX = curX - parseInt(objectToDrag.style.left);
	ecartY = curY - parseInt(objectToDrag.style.top);
}

function drag(e){
	var newPosX;
	var newPosY;
	if(isDragging == true){
		
		getPositionCurseur(e);
		newPosX = curX - ecartX;
		newPosY = curY - ecartY;

		objectToDrag.style.left = newPosX + 'px';
		objectToDrag.style.top = newPosY + 'px';
		
	}
	
}

function endDrag(){
	isDragging = false;
}

function afficher(ladiv) {
	$('#'+ladiv).fadeIn('fast');
}

function fermer(ladiv) {
	$('#'+ladiv).fadeOut('fast');
}

var req = null;
var n=0;
function Xhr(){
	if(window.XMLHttpRequest){
	   req = new XMLHttpRequest();
   }else if(window.ActiveXObject){
	  req = new ActiveXObject("Microsoft.XMLHTTP");
	 }else{
		alert("Le navigateur ne supporte pas les objets XMLHTTPRequest...");
		req = false;
	 }
}

function chercher(lien)
{ 
	if (lien == null) {
		type_annonce = escape(document.rech.type_annonce.value);
		type_produit = escape(document.rech.type_produit.value);
		region = escape(document.rech.region.value);
		for (i=0;i<4;i++) {
			if (document.forms.rech.periode[i].checked==true) {
				periode1 = i;
				break;
			}
		}
	} else {
		type_annonce = escape(document.rech.type_annonce.value);
		type_produit = escape(document.rech.type_produit.value);
		region = escape(document.rech.region.value);
		var periode1 = 0;
		for (i=0;i<4;i++) {
			if (document.forms.rech.periode[i].checked==true) {
				periode1 = i; 
				break;
			}
		}

		d = lien;
	}
	Xhr();
	req.open("POST","ajax_recherche.php?type_annonce="+type_annonce+"&type_produit="+type_produit+"&region="+region+"&"+lien+"&periode="+periode1,true);
	req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	req.onreadystatechange = function(){
		if(req.readyState == 4 && req.status == 200) {
			document.getElementById('resultat').style.display = "block";
			document.getElementById('resultat').innerHTML=req.responseText;
			document.getElementById('chargement').style.display = "none";
		}
		else { 
			document.getElementById('resultat').style.display = "none";
			document.getElementById('chargement').style.display = "block";
			document.getElementById('chargement').innerHTML="<img src=images/attente.gif> En traitement ...";
		}
	}		
	req.send(null);
}

function changer_choix(_id)
{		
	if (_id != '') {
		Xhr();		
		fichier = "ajax_form_choix.php?c="+_id;
		req.open("GET",fichier,true);
		req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		req.onreadystatechange = function(){
			if(req.readyState == 4 && req.status == 200) {
				document.getElementById('type').style.display = "block";
				document.getElementById('type').innerHTML=req.responseText;
				document.getElementById('ch_cat1').style.display = "none";
			}
			else { 
				document.getElementById('type').style.display = "none";
				document.getElementById('ch_cat1').style.display = "block";
				document.getElementById('ch_cat1').innerHTML="<img src=images/tourne.gif>";
			}
		}		
		req.send(null);
	} else fermer('type');
	fermer('sous_cat');
}

function changer_sous_cat(_id)
{		
	if (_id != '') {
		Xhr();		
		fichier = "ajax_form_choix.php?sc="+_id;
		req.open("GET",fichier,true);
		req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		req.onreadystatechange = function(){
			if(req.readyState == 4 && req.status == 200) {
				document.getElementById('sous_cat').style.display = "block";
				document.getElementById('sous_cat').innerHTML=req.responseText;
				document.getElementById('ch_cat2').style.display = "none";
				document.getElementById('test_annonce').value = "1";
			}
			else { 
				document.getElementById('sous_cat').style.display = "none";
				document.getElementById('ch_cat2').style.display = "block";
				document.getElementById('ch_cat2').innerHTML="<img src=images/tourne.gif>";
			}
		}		
		req.send(null);
	}
}

function envoyer_annonce() {
			
	if (document.poster.choix_annonce.value==1) {			
		type_annonce1 = escape(document.poster.annonce.value);
		type_produit1 = escape(document.poster.type_produit.value);
		nom1 = escape(document.poster.nom.value);
		adresse1 = escape(document.poster.adresse.value);
		codepostal1 = escape(document.poster.codepostal.value);
		localite1 = escape(document.poster.localite.value);
		titre1 = escape(document.poster.titre.value);
		email1 = escape(document.poster.email.value);
		tele1 = escape(document.poster.tele.value);
		message1 = escape(document.poster.message.value);
		if (document.forms.poster.adressevisible[0].checked==true) var adresse_visible1 = '1';
		else if (document.forms.poster.adressevisible[1].checked==true) adresse_visible1 = '0';

		if (document.poster.prix.value == null) prix1 = 0.0;
		else prix1 = escape(document.poster.prix.value);
		
		var fichier = "type_annonce="+type_annonce1+"&type_produit="+type_produit1+"&titre="+titre1+"&detail="+message1+"&tel="+tele1+"&nom="+nom1+"&adresse="+adresse1+"&cp="+codepostal1+"&localite="+localite1+"&email="+email1+"&prix="+prix1+"&adresse_visible="+adresse_visible1;

	}
	else if (document.poster.choix_annonce.value==2) {			
		type_annonce1 = escape(document.poster.annonce.value);
		type_service1 = escape(document.poster.type_service.value);
		nom1 = escape(document.poster.nom.value);
		adresse1 = escape(document.poster.adresse.value);
		codepostal1 = escape(document.poster.codepostal.value);
		localite1 = escape(document.poster.localite.value);
		titre1 = escape(document.poster.titre.value);
		email1 = escape(document.poster.email.value);
		tele1 = escape(document.poster.tele.value);
		message1 = escape(document.poster.message.value);
		if (document.forms.poster.adressevisible[0].checked==true) var adresse_visible1 = '1';
		else if (document.forms.poster.adressevisible[1].checked==true) adresse_visible1 = '0';
		
		if (document.poster.prix.value == null) prix1 = 0.0;
		else prix1 = escape(document.poster.prix.value);
		
		var fichier = "type_annonce="+type_annonce1+"&type_service="+type_service1+"&titre="+titre1+"&detail="+message1+"&tel="+tele1+"&nom="+nom1+"&adresse="+adresse1+"&cp="+codepostal1+"&localite="+localite1+"&email="+email1+"&prix="+prix1+"&adresse_visible="+adresse_visible1;
		}

	else if (document.poster.choix_annonce.value==3) {			
		activite1 = escape(document.poster.activite.value);
		nom1 = escape(document.poster.nom.value);
		adresse1 = escape(document.poster.adresse.value);
		codepostal1 = escape(document.poster.codepostal.value);
		localite1 = escape(document.poster.localite.value);
		titre1 = escape(document.poster.titre.value);
		email1 = escape(document.poster.email.value);
		tele1 = escape(document.poster.tele.value);
		message1 = escape(document.poster.message.value);
		
		jd = escape(document.poster.j_d.value);
		md = escape(document.poster.m_d.value);
		ad = escape(document.poster.a_d.value);
		
		jf = escape(document.poster.j_f.value);
		mf = escape(document.poster.m_f.value);
		af = escape(document.poster.a_f.value);
		
		if (document.forms.poster.adressevisible[0].checked==true) var adresse_visible1 = '1';
		else if (document.forms.poster.adressevisible[1].checked==true) adresse_visible1 = '0';
		
		var fichier = "activite="+activite1+"&titre="+titre1+"&detail="+message1+"&tel="+tele1+"&nom="+nom1+"&adresse="+adresse1+"&cp="+codepostal1+"&localite="+localite1+"&email="+email1+"&adresse_visible="+adresse_visible1+"&jd="+jd+"&md="+md+"&ad="+ad+"&jf="+jf+"&mf="+mf+"&af="+af;
	}
	
	else if (document.poster.choix_annonce.value==4) {			
		nounou = escape(document.poster.annonce.value);
		type_service2 = escape(document.poster.type_service.value);
		nom1 = escape(document.poster.nom.value);
		adresse1 = escape(document.poster.adresse.value);
		codepostal1 = escape(document.poster.codepostal.value);
		localite1 = escape(document.poster.localite.value);
		titre1 = escape(document.poster.titre.value);
		email1 = escape(document.poster.email.value);
		tele1 = escape(document.poster.tele.value);
		message1 = escape(document.poster.message.value);
		if (document.forms.poster.adressevisible[0].checked==true) var adresse_visible1 = '1';
		else if (document.forms.poster.adressevisible[1].checked==true) adresse_visible1 = '0';
		
		var fichier = "nounou="+nounou+"&type_service2="+type_service2+"&titre="+titre1+"&detail="+message1+"&tel="+tele1+"&nom="+nom1+"&adresse="+adresse1+"&cp="+codepostal1+"&localite="+localite1+"&email="+email1+"&adresse_visible="+adresse_visible1; 

	} 
		Xhr();
		req.open("GET","ajax_poster_annonce.php?"+fichier,true);
		req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		
		req.onreadystatechange = function(){
			if(req.readyState == 4 && req.status == 200) {
				document.getElementById('resultat').style.display = "block";
				document.getElementById('resultat').innerHTML=req.responseText;
				document.getElementById('chargement').style.display = "none";
			}
			else { 
				document.getElementById('chargement').style.display = "block";
				document.getElementById('chargement').innerHTML="<img src=images/attente.gif> En traitement ...";
			}		
		}		
		req.send(null);
}

function cacher(div) {
	basculer(div, false);
}

function basculer(i, flag) {
	document.getElementById(i).style.display = (flag) ? "block" : "none";
}

function trouver_cp(cp) {	
	
		Xhr();	
		req.open("GET","ajax_cp.php?cp="+cp,true);
		req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		req.onreadystatechange = function() { 
			if(req.readyState == 4 && req.status == 200) {
				if (document.all) document.getElementById('localite').outerHTML="<select name='localite' id='localite'>"+req.responseText+"</select>";
				else document.getElementById('localite').innerHTML=req.responseText;			 
				
				if(req.responseText == "")
					 return false;
				return true;
				
			}		
		}		
		req.send(null);
}

function valide(evt) {
	var keyCode = evt.which ? evt.which : evt.keyCode;
	var interdit = '€';
	var euro = 'Euro';
	if (interdit.indexOf(String.fromCharCode(keyCode)) >= 0) {
		return false;
	}
}

function contacter_annonceur(_id) {	
		Xhr();	
		email_ann = escape(document.contact_annonce.email_ann.value);
		nom = escape(document.contact_annonce.nom.value);
		email = escape(document.contact_annonce.email.value);
		msg = escape(document.contact_annonce.reponse.value);
		
		if ((email != '' && document.contact_annonce.email.value.search(regex) != -1) && nom != '' && msg != '') {
			req.open("GET","ajax_contact_annonceur.php?id="+_id+"&email_ann="+email_ann+"&email="+email+"&nom="+nom+"&message="+msg,true);
			req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			req.onreadystatechange = function() {
				if(req.readyState == 4 && req.status == 200) {
					document.getElementById('reponses').style.display = "block";
					document.getElementById('reponses').innerHTML=req.responseText;
				}
				else { 
					document.getElementById('reponses').style.display = "Block";
					document.getElementById('reponses').value = "Erreur contenu";
				}
			
			}		
			req.send(null);
		}
		else {
			if (email == '' || document.contact_annonce.email.value.search(regex) == -1) document.contact_annonce.email.style.border = '1px solid #CC0000'; 
			else document.contact_annonce.email.style.border = '1px solid #CCCCCC'; 
			
			if (msg == '') document.contact_annonce.reponse.style.border = '1px solid #CC0000'; 
			else document.contact_annonce.reponse.style.border = '1px solid #CCCCCC'; 
			
			if (nom == '') document.contact_annonce.nom.style.border = '1px solid #CC0000'; 
			else document.contact_annonce.nom.style.border = '1px solid #CCCCCC';                         
		}		
		
}

function contacter_visiteur(_id) {	
		Xhr();	
		msg = escape(document.contact_reponse.message.value);
		req.open("GET","ajax_envoi_reponse.php?id="+_id+"&message="+msg,true);
		req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		req.onreadystatechange = function() {
			if(req.readyState == 4 && req.status == 200) {
				document.getElementById(_id).innerHTML=req.responseText;
			}
			else { 
				document.getElementById(_id).style.display = "Block";
				document.getElementById(_id).innerHTML="<img src=images/attente.gif> En traitement ...";
			}
		}		
		req.send(null);
}

function envoyer_abus(_id) {	
		Xhr();	
		email_ann = escape(document.abus.email.value);
		nom = escape(document.abus.nom.value);
		email = escape(document.abus.email.value);
		texte = escape(document.abus.texte.value);
		
		if ((email != '' && document.abus.email.value.search(regex) != -1) && nom != '' && texte != '') {    		
			req.open("GET","ajax_abus.php?id="+_id+"&email="+email+"&nom="+nom+"&texte="+texte,true);
			req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			req.onreadystatechange = function() {
				if(req.readyState == 4 && req.status == 200) {
					document.getElementById('envoi_abus').style.display = "block";
					document.getElementById('envoi_abus').innerHTML=req.responseText;
				}
				else { 
					document.getElementById('envoi_abus').style.display = "Block";
					document.getElementById('envoi_abus').value = "Erreur contenu";
				}
			
			}		
			req.send(null);
		}
		else {
			if (email == '' || document.abus.email.value.search(regex) == -1) document.abus.email.style.border = '1px solid #CC0000'; 
			else document.abus.email.style.border = '1px solid #CCCCCC'; 
			
			if (texte == '') document.abus.texte.style.border = '1px solid #CC0000'; 
			else document.abus.texte.style.border = '1px solid #CCCCCC'; 
			
			if (nom == '') document.abus.nom.style.border = '1px solid #CC0000'; 
			else document.abus.nom.style.border = '1px solid #CCCCCC';                         
		}		
		
}

function affiche_form_rep(_id, _email) {	
		Xhr();	
		req.open("GET","ajax_form_rep.php?id="+_id+"&email="+_email,true);
		req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		req.onreadystatechange = function() {
			if(req.readyState == 4 && req.status == 200) {
				document.getElementById(_id).style.display = "block";
				document.getElementById(_id).innerHTML=req.responseText;
			}
			else { 
				document.getElementById(_id).style.display = "Block";
				document.getElementById(_id).innerHTML="<img src=images/attente.gif> En traitement ...";
			}
		
		}		
		req.send(null);
}


function repondre_visiteur(_id) {	
		Xhr();	
		email_ann = escape(document.contact_annonce.email_ann.value);
		nom = escape(document.contact_annonce.nom.value);
		email = escape(document.contact_annonce.email.value);
		msg = escape(document.contact_annonce.message.value);
		
		if (email != '' && nom != '' && msg != '') {
			req.open("GET","ajax_contact_visiteur.php?id="+_id+"&email_ann="+email_ann+"&email="+email+"&nom="+nom+"&message="+msg,true);
			req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			req.onreadystatechange = function() {
				if(req.readyState == 4 && req.status == 200) {
					document.getElementById('reponses').style.display = "block";
					document.getElementById('reponses').innerHTML=req.responseText;
				}
				else { 
					document.getElementById('reponses').style.display = "Block";
					document.getElementById('reponses').value = "Erreur contenu";
				}
			
			}		
			req.send(null);
		}
		else {
			if (email == '') document.contact_annonce.email.style.border = '1px solid #CC0000'; 
			else document.contact_annonce.email.style.border = '1px solid #CCCCCC'; 
			
			if (msg == '') document.contact_annonce.msg.style.border = '1px solid #CC0000'; 
			else document.contact_annonce.msg.style.border = '1px solid #CCCCCC'; 
			
			if (nom == '') document.contact_annonce.nom.style.border = '1px solid #CC0000'; 
			else document.contact_annonce.nom.style.border = '1px solid #CCCCCC';                         
		}
}


function contact_web() {	
		Xhr();	
		nom = escape(document.contact_annonce.nom.value);
		email = escape(document.contact_annonce.email.value);
		msg = escape(document.contact_annonce.message.value);
		req.open("GET","ajax_contact_web.php?email="+email+"&nom="+nom+"&message="+msg,true);
		req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		req.onreadystatechange = function() {
			if(req.readyState == 4 && req.status == 200) {
				document.getElementById('reponses').style.display = "block";
				document.getElementById('reponses').innerHTML=req.responseText;
			}
			else { 
				document.getElementById('reponses').style.display = "Block";
				document.getElementById('reponses').value = "Erreur contenu";
			}
		
		}		
		req.send(null);
}

function test_champs() {
	compte = 0;
	if (document.poster.email.value.search(regex) == -1) {
		document.poster.email.style.background = "#ffcccc";
		compte++;
	} else document.poster.email.style.background = "";
	
	if (document.poster.nom.value.search(/\w/) == -1) {
		document.poster.nom.style.background = "#ffcccc";
		compte++;
	} else document.poster.nom.style.background = "";
	
	if (document.poster.choix.value.search(/\w/) == -1) {
		document.poster.choix.style.background = "#ffcccc";
		compte++;
	} else document.poster.choix.style.background = "";
	
	if (document.poster.test_annonce.value == null || document.poster.test_annonce.value == '') {
		alert('Vueillez choisir une catégorie pour votre annonce!');
		compte++;
	} else document.poster.annonce.style.background = "";

	
	if (document.poster.titre.value.search(/\w/) == -1) {
		document.poster.titre.style.background = "#ffcccc";
		compte++;
	} else document.poster.titre.style.background = "";
	
	if (document.poster.message.value == '' || document.poster.message.value == null) {
		document.poster.message.style.background = "#ffcccc";
		compte++;
	} else document.poster.message.style.background = "";
	
	if (document.poster.codepostal.value.search(regex2) == -1) {
		document.poster.codepostal.style.background = "#ffcccc";
		compte++;
	} else document.poster.codepostal.style.background = "";
	
	if (document.poster.localite.value == '' && document.poster.localite.value != null) {
		document.poster.localite.style.background = "#ffcccc";
		compte++;
	} else document.poster.localite.style.background = "";
	
	/*if (document.poster.date_debut.value == '' && document.poster.date_debut.value != null && document.poster.choix.value == 6) {
		document.poster.date_debut.style.background = "#ffcccc";
		compte++;
	} else document.poster.date_debut.style.background = "";
	
	if (document.poster.date_fin.value == '' && document.poster.date_fin.value != null && document.poster.choix.value == 6) {
		document.poster.date_fin.style.background = "#ffcccc"; 
		compte++;
	} else document.poster.date_fin.style.background = "";  */
		
	if (compte > 0) return false;
	else return true;
}

function test_vente() {
	if ((document.forms.poster.choix.value == 1 || document.forms.poster.choix.value == 2) && document.forms.poster.choix.value != null) {
		//document.getElementById('prix').style.display = "block";
		document.getElementById('agenda').style.display = "none"; 
		return true;
	} 
	else if (document.forms.poster.choix.value == 6 && document.forms.poster.choix.value != null) {
		document.getElementById('agenda').style.display = "block";
		//document.getElementById('prix').style.display = "none"; 
		return true;
	}
	else { 
		//document.getElementById('prix').style.display = "none"; 
		document.getElementById('agenda').style.display = "none"; 
		return true;
	}
}

function test_vacances() {
	if ((document.forms.poster.annonce.value == 149 || document.forms.poster.annonce.value == 150) && document.forms.poster.annonce.value != null) {
		//document.getElementById('vacances').style.display = "block";
		//document.getElementById('prix').style.display = "none"; 
		//document.getElementById('agenda').style.display = "none"; 
		return true;
	} 
	else { 
		//document.getElementById('vacances').style.display = "none"; 
		//document.getElementById('prix').style.display = "none"; 
		//document.getElementById('agenda').style.display = "none"; 
		return true;
	}
}


function favoris(id_ann, type) {
	Xhr();
	req.open("GET","ajax_favoris.php?id="+id_ann+"&type="+type,true);
	req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	req.onreadystatechange = function(){
		if(req.readyState == 4 && req.status == 200) {
			document.getElementById('reponses').style.display = "block";
			document.getElementById('reponses').innerHTML=req.responseText;
			document.getElementById('chargement').style.display = "none";
		}
		else { 
			document.getElementById('chargement').style.display = "block";
			document.getElementById('chargement').innerHTML="<img src=images/attente.gif> En traitement ...";
		}
	}		
	req.send(null);
}

function affiche_favoris() {
	Xhr();
	req.open("GET","ajax_liste_favoris.php",true);
	req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	req.onreadystatechange = function(){
		if(req.readyState == 4 && req.status == 200) {
			document.getElementById('resultat').style.display = "block";
			document.getElementById('resultat').innerHTML=req.responseText;
			document.getElementById('chargement').style.display = "none";
		}
		else { 
			document.getElementById('chargement').style.display = "block";
			document.getElementById('chargement').innerHTML="<img src=images/attente.gif> En traitement ...";
		}
	}		
	req.send(null);
}

function supprimer_favoris(id_ann) {
	Xhr();
	req.open("GET","ajax_supprimer_favoris.php?id="+id_ann,true);
	req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	req.onreadystatechange = function(){
		if(req.readyState == 4 && req.status == 200) {
			document.getElementById('resultat').style.display = "block";
			document.getElementById('resultat').innerHTML=req.responseText;
			document.getElementById('chargement').style.display = "none";
		}
		else { 
			document.getElementById('chargement').style.display = "block";
			document.getElementById('chargement').innerHTML="<img src=images/attente.gif> En traitement ...";
		}
	}		
	req.send(null);
	document.location.href="liste_favoris.php";
}

function supprimer_reponse(id_msg, id_ann) {
	Xhr();
	req.open("GET","ajax_supprimer_reponse.php?id="+id_msg,true);
	req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	req.onreadystatechange = function(){
		if(req.readyState == 4 && req.status == 200) {
			document.getElementById('resultat').style.display = "block";
			document.getElementById('resultat').innerHTML=req.responseText;
			document.getElementById('chargement').style.display = "none";
		}
		else { 
			document.getElementById('chargement').style.display = "block";
			document.getElementById('chargement').innerHTML="<img src=images/attente.gif> En traitement ...";
		}
	}		
	req.send(null);
	document.location.href="reponses.php?id="+id_ann;
}

function affiche_mes_annonces() {
	Xhr();
	req.open("GET","ajax_mes_annonces.php",true);
	req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	req.onreadystatechange = function(){
		if(req.readyState == 4 && req.status == 200) {
			document.getElementById('resultat').style.display = "block";
			document.getElementById('resultat').innerHTML=req.responseText;
			document.getElementById('chargement').style.display = "none";
		}
		else { 
			document.getElementById('chargement').style.display = "block";
			document.getElementById('chargement').innerHTML="<img src=images/attente.gif> En traitement ...";
		}
	}		
	req.send(null);
}

function supprimer_annonce(id_ann, pages) {
	Xhr();
	req.open("GET","ajax_supprimer_annonce.php?id="+id_ann,true);
	req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	req.onreadystatechange = function(){
		if(req.readyState == 4 && req.status == 200) {
			document.getElementById('resultat').style.display = "block";
			document.getElementById('resultat').innerHTML=req.responseText;
			document.getElementById('chargement').style.display = "none";
		}
		else { 
			document.getElementById('chargement').style.display = "block";
			document.getElementById('chargement').innerHTML="<img src=images/attente.gif> En traitement ...";
		}
	}		
	req.send(null);
	document.location.href=pages;
}

function modifier_annonce_form(id_ann, type) {
	Xhr();
	req.open("GET","ajax_modifier_annonce_form.php?id="+id_ann+"&type="+type,true);
	req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	req.onreadystatechange = function(){
		if(req.readyState == 4 && req.status == 200) {
			document.getElementById('detail'+id_ann).style.display = "block";
			document.getElementById('detail'+id_ann).innerHTML=req.responseText;
			document.getElementById('chargement').style.display = "none";
		}
		else { 
			document.getElementById('chargement').style.display = "block";
			document.getElementById('chargement').innerHTML="<img src=images/attente.gif> En traitement ...";
		}
	}		
	req.send(null);
}

function modif_annonce(id_ann) {
	Xhr();
	
	nom1 = escape(document.modifier_ann.nom.value);
	adresse1 = escape(document.modifier_ann.adresse.value);
	codepost1 = escape(document.modifier_ann.codepostal.value);
	localite1 = escape(document.modifier_ann.localite.value);
	titre1 = escape(document.modifier_ann.titre.value);
	email1 = escape(document.modifier_ann.email.value);
	tele1 = escape(document.modifier_ann.tele.value);
	message1 = escape(document.modifier_ann.message.value);
	
	if (type != 'agenda' && type != 'nounou') {
		if (document.forms['modifier_ann'].elements['prix'].value == null || document.forms['modifier_ann'].elements['prix'].value == '') prix1 = '0';
		else prix1 = escape(document.forms['modifier_ann'].elements['prix'].value);
	} else prix1 = '';
	
	req.open("GET","ajax_modifier_annonce.php?id="+id_ann+"&type="+type+"&titre="+titre1+"&detail="+message1+"&tel="+tele1+"&nom="+nom1+"&adresse="+adresse1+"&cp="+codepost1+"&localite="+localite1+"&email="+email1+"&prix="+prix1,true);
	req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	req.onreadystatechange = function(){
		if(req.readyState == 4 && req.status == 200) {
			document.getElementById('detail'+id_ann).style.display = "block";
			document.getElementById('detail'+id_ann).innerHTML=req.responseText;
			document.getElementById('chargement').style.display = "none";
		}
		else { 
			document.getElementById('chargement').style.display = "block";
			document.getElementById('chargement').innerHTML="<img src=images/attente.gif> En traitement ...";
		}
	}		
	req.send(null);
	modifier_annonce_form(id_ann, type);
}

function afficher_image(_id)
{ 
		Xhr();
		var t = new Date();
		req.open("GET","ajax_afficher_image.php?id="+_id+"&"+t.getTime(),true);
		req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		req.onreadystatechange = function(){
			if(req.readyState == 4 && req.status == 200) {
				document.getElementById('image').style.display = "block";
				document.getElementById('image').innerHTML=req.responseText;
			}
			else { 
				document.getElementById('image').style.display = "block";
				document.getElementById('image_attente').innerHTML="<img src=images/attente.gif> En traitement ...";
			}
		}		
		req.send(null);
}

function vendu(_id)
{ 
		Xhr();
		var t = new Date();
		req.open("GET","ajax_vendu.php?id="+_id+"&"+t.getTime(),true);
		req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		req.onreadystatechange = function(){
			if(req.readyState == 4 && req.status == 200) {
				document.getElementById(_id).innerHTML=req.responseText;
			}
			else { 
				document.getElementById(_id).innerHTML="<img src=images/attente.gif> En traitement ...";
			}
		}		
		req.send(null);
}

function annule(_id)
{ 
		Xhr();
		var t = new Date();
		req.open("GET","ajax_annule.php?id="+_id+"&"+t.getTime(),true);
		req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		req.onreadystatechange = function(){
			if(req.readyState == 4 && req.status == 200) {
				document.getElementById('an'+_id).innerHTML=req.responseText;
			}
			else { 
				document.getElementById('an'+_id).innerHTML="<img src=images/attente.gif> En traitement ...";
			}
		}		
		req.send(null);
}


function ajouter_img(_id_ann) {	
		Xhr();	
		req.open("GET","ajax_post_img.php?id_ann="+_id_ann,true);
		req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		req.onreadystatechange = function() {
			if(req.readyState == 4 && req.status == 200) {
				document.getElementById('pop_img').style.display = "block";
				document.getElementById('pop_img').innerHTML=req.responseText;
				document.getElementById('chargement').style.display = "none";
			}
			else { 
				document.getElementById('chargement').style.display = "block";
				document.getElementById('chargement').innerHTML="<img src=images/attente.gif> chargement ...";
			}
		
		}		
		req.send(null);
} 

tab_img = new Array(".gif", ".jpg", ".png");
function verification_img(formulaire, fichier) {
	soumission = false;
	if (!fichier) return;
	while (fichier.indexOf("&&") != -1)
	   fichier = fichier.slice(fichier.indexOf("&&") + 1);
	ext = fichier.slice(fichier.indexOf(".")).toLowerCase();
	for (var i = 0; i < tab_img.length; i++)
	{
	   if (tab_img[i] == ext)
	   {
		 soumission = true; break; 
	   }
	}
	if (soumission) formulaire.submit();
	else
	   alert("Vous ne pouvez uploader que ces types d'images : " + "(" + tab_img.join("  ") + ")");
}

function test_recherche() {
	compte = 0;
	if (document.recherche.mots.value.search(/\w/) == -1 || document.recherche.mots.value == "Que cherchez-vous?") {
		document.recherche.mots.style.background = "#ffcccc";
		document.recherche.mots.value = "Que cherchez-vous?";
		compte++;
	} else {
		document.recherche.mots.style.background = "";
		document.recherche.submit();
	}

	if (compte > 0) return false;
	else return true;
}

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

var preloadFlag = false;
function preloadImages() {
	if (document.images) {
		carte_france350_mel1_01_Carte_image_01_over = newImage("carte_france/carte-france350_mel1_01-Car.gif");
		carte_france350_mel1_01_Carte_image_02_over = newImage("carte_france/carte-france350_mel1_01--03.gif");
		carte_france350_mel1_01_Carte_image_03_over = newImage("carte_france/carte-france350_mel1_01--04.gif");
		carte_france350_mel1_01_Carte_image_04_over = newImage("carte_france/carte-france350_mel1_01--05.gif");
		carte_france350_mel1_01_Carte_image_05_over = newImage("carte_france/carte-france350_mel1_01--06.gif");
		carte_france350_mel1_01_Carte_image_06_over = newImage("carte_france/carte-france350_mel1_01--07.gif");
		carte_france350_mel1_01_Carte_image_07_over = newImage("carte_france/carte-france350_mel1_01--08.gif");
		carte_france350_mel1_01_Carte_image_08_over = newImage("carte_france/carte-france350_mel1_01--09.gif");
		carte_france350_mel1_01_Carte_image_09_over = newImage("carte_france/carte-france350_mel1_01--10.gif");
		carte_france350_mel1_01_Carte_image_10_over = newImage("carte_france/carte-france350_mel1_01--11.gif");
		carte_france350_mel1_01_Carte_image_11_over = newImage("carte_france/carte-france350_mel1_01--12.gif");
		carte_france350_mel1_01_Carte_image_12_over = newImage("carte_france/carte-france350_mel1_01--13.gif");
		carte_france350_mel1_01_Carte_image_13_over = newImage("carte_france/carte-france350_mel1_01--14.gif");
		carte_france350_mel1_01_Carte_image_14_over = newImage("carte_france/carte-france350_mel1_01--15.gif");
		carte_france350_mel1_01_Carte_image_15_over = newImage("carte_france/carte-france350_mel1_01--16.gif");
		carte_france350_mel1_01_Carte_image_16_over = newImage("carte_france/carte-france350_mel1_01--17.gif");
		carte_france350_mel1_01_Carte_image_17_over = newImage("carte_france/carte-france350_mel1_01--18.gif");
		carte_france350_mel1_01_Carte_image_18_over = newImage("carte_france/carte-france350_mel1_01--19.gif");
		carte_france350_mel1_01_Carte_image_19_over = newImage("carte_france/carte-france350_mel1_01--20.gif");
		carte_france350_mel1_01_Carte_image_20_over = newImage("carte_france/carte-france350_mel1_01--21.gif");
		carte_france350_mel1_01_Carte_image_21_over = newImage("carte_france/carte-france350_mel1_01--22.gif");
		carte_france350_mel1_01_Carte_image_22_over = newImage("carte_france/carte-france350_mel1_01--23.gif");
		preloadFlag = true;
	}
}



function changeClass(obj,classe)
{
  if (document.all) obj.setAttribute("className",classe);
  else obj.setAttribute("class",classe);
}

function Lien() {
	i = document.Choix.Liste.selectedIndex;
	if (i == 0) return;
	url = document.Choix.Liste.options[i].value;
	parent.location.href = url;
}


function annule(_id)
{ 
		Xhr();
		var t = new Date();
		req.open("GET","ajax_annule.php?id="+_id+"&"+t.getTime(),true);
		req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		req.onreadystatechange = function(){
			if(req.readyState == 4 && req.status == 200) {
				document.getElementById('an'+_id).innerHTML=req.responseText;
			}
			else { 
				document.getElementById('an'+_id).innerHTML="<img src=images/attente.gif> En traitement ...";
			}
		}		
		req.send(null);
}

function carte() {    
	$.get(
		"ajax_carte.php" , 
		{ } , 
		function(data){ $("#carte").html(data).fadeIn('fast'); }
	); 
}

var actualUser = 0;

function infoBullAnnonce(_idAnnonce, _titre) {
	
	if (actualUser > 0) 
		$("#userProfil_"+actualUser).fadeOut('fast');

	$("#userProfil_"+_idAnnonce).fadeIn("fast");
	
	actualUser = _idAnnonce;  
	
	$.ajax({
	  type: "GET",
	  url: "./ajax_infosBulle.php",
	  cache: true,
	  data: "idAnnonce="+_idAnnonce,
	  success: function(data){
		$("#userProfil_"+_idAnnonce).html(data);
	  }
	});    

}




function changer_choix_modif(_id)
{        
	if (_id != '') {
		Xhr();        
		fichier = "admin/ajax_form_choix.php?c="+_id;
		req.open("GET",fichier,true);
		req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		req.onreadystatechange = function(){
			if(req.readyState == 4 && req.status == 200) {
				$('#scat').html(req.responseText);
			}
		}        
		req.send(null);
	} else fermer('type');
	fermer('sous_cat');
}

function changer_sous_cat_modif(_id)
{        
	if (_id != '') {
		Xhr();        
		fichier = "admin/ajax_form_choix.php?sc="+_id;
		req.open("GET",fichier,true);
		req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		req.onreadystatechange = function(){
			if(req.readyState == 4 && req.status == 200) {
				$('#scat2').html(req.responseText);
			}
		}        
		req.send(null);
	}
}