

function display_yes(id){
document.getElementById(id).style.display = 'block';
}
function display_none(id){
document.getElementById(id).style.display = 'none';
}

function photo_index(annonce,ope){
	
	var image = document.getElementById('hid_photo_index').value;
	var text = document.getElementById('text_index').value;
	if(image == "") {
    alert("Il faut sélectionner une image");
    return false;
  }
		$.ajax({
							type : "POST",
							url : "ajax/image_index.php",
							data : "image="+image+"&text="+text+"&annonce="+annonce+"&ope="+ope,
							send : $('#image_index').html("<img src='../images/load.gif' />"),
							error :function(msg){
									alert( "Erreur ajax : " + msg ); 
								},
							success : function(data){
				
								$('#image_index').html(data);
						}});
			
	
	}



function annonce_index(ok,ope){
	if(ope=="vente"){
		var annonce = document.getElementById('annonce_vente').value;
	}
	if(ope=="location"){
		var annonce = document.getElementById('annonce_location').value;
	}
	if(annonce == "") {
    alert("Saisissez un numéro d'annonce");
    return false;
  }
		$.ajax({
							type : "POST",
							url : "ajax/annonce_index.php",
							data : "annonce="+annonce+"&ok="+ok+"&ope="+ope,
							send : $('#annonce_index').html("<img src='../images/load.gif' />"),
							error :function(msg){
									alert( "Erreur ajax : " + msg ); 
								},
							success : function(data){
				
								$('#annonce_index').html(data);
						}});
			
	
	}

function map(x,y,x2,y2){
		$.ajax({
							type : "POST",
							url : "ajax/map.php",
							data : "x="+x+"&y="+y+"&x2="+x2+"&y2="+y2,
							send : $('#map').html("<img src='../images/load.gif' />"),
							error :function(msg){
									alert( "Erreur ajax : " + msg ); 
								},
							success : function(data){
				
								$('#map').html(data);
						}});
			
	
	}
function image(){
		$.ajax({
							type : "POST",
							url : "ajax/image.php",
							data : "",
							send : $('#boxcontent').html("<img src='../images/load.gif' />"),
							error :function(msg){
									alert( "Erreur ajax : " + msg ); 
								},
							success : function(data){
				
								$('#boxcontent').html(data);
						}});
			
	
	}

function confirmer(annonce){
	
	if(confirm("Etes-vous certain de vouloir supprimer l'annonce "+annonce)){
	document.location.href="index.php?v=suppr&annonce="+annonce;
	return true ;
	}else{
	return false ;
	}
}

function statut(statut,annonce){
		$.ajax({
							type : "POST",
							url : "ajax/changer_statut.php",
							data : "statut="+statut+"&annonce="+annonce,
							send : $('#statut').html("<img src='../images/load.gif' />"),
							error :function(msg){
									alert( "Erreur ajax : " + msg ); 
								},
							success : function(data){
				
								$('#statut').html(data);
						}});
			
	
	}

function suppr_image(annonce,image){
	if(confirm("Etes-vous certain de vouloir supprimer l'image "+image)){
	
		$.ajax({
							type : "POST",
							url : "ajax/suppr_image.php",
							data : "annonce="+annonce+"&image="+image,
							send : $('#suppr_image').html("<img src='../images/load.gif' />"),
							error :function(msg){
									alert( "Erreur ajax : " + msg ); 
								},
							success : function(data){
				
								$('#suppr_image').html(data);
						}});
			
		}
	}


function valider(){
	
	if(document.getElementById('operation1').checked == false && document.getElementById('operation2').checked == false){
    alert("Vente ou location ?");
    return false;
  	}
	if(document.getElementById('type13').checked == false 
	&& document.getElementById('type11').checked == false
	&& document.getElementById('type1').checked == false
	&& document.getElementById('type2').checked == false
	&& document.getElementById('type5').checked == false
	&& document.getElementById('type10').checked == false
	&& document.getElementById('type6').checked == false){
    alert("Quel type de bien ?");
    return false;
  	}

  if(document.formSaisie.q9_Surface.value == "") {
    alert("Saisissez une surface");
    return false;
  }
  
  if(document.formSaisie.q8_Prix.value == "") {
    alert("Saisissez un prix");
    return false;
  }
  
   if(document.formSaisie.q3_Description.value == "") {
    alert("la description du bien est vide");
    return false;
  }
   if(document.formSaisie.accroche.value == "") {
    alert("Il faut une accroche !");
    return false;
  }
  if(document.formSaisie.codepost.value == "00" && !document.formSaisie.hville )  {
    alert("Aucune ville sélèctionnée");
    return false;
  }
  
    if(document.formSaisie.ville.value == "00") {
    alert("Aucune ville sélèctionnée");
    return false;
  }
  
   
  
  
}

function list_annonce_admin(operation){
				var type = document.getElementById('type').options[document.getElementById('type').selectedIndex].value;
				var piece = document.getElementById('piece').options[document.getElementById('piece').selectedIndex].value;
				if(document.getElementById('ville')){
					var ville = document.getElementById('ville').value; 
				}else{
					var ville = '0' ;
				}
				var cp = document.getElementById('codepost0').value;
				var surface0 = document.getElementById('surface0').value;
				var surface1 = document.getElementById('surface1').value;
				var prix = document.getElementById('prix').value;
				
				$.ajax({
						type : "POST",
							url : "ajax/filtreAjax.php",
							data : "type="+type+"&operation="+operation+"&surface0="+surface0+"&surface1="+surface1+"&prix="+prix+"&piece="+piece+"&cp="+cp+"&ville="+ville,
							send : $('#list_annonce').html("<img src='images/load.gif' />"),
							error :function(msg){
									alert( "Erreur ajax : " + msg ); 
								},
							success : function(data){
				
								$('#list_annonce').html(data);
						}});
			
		}

function list_annonce(operation){
				var x = document.getElementById('x').value;
				var y = document.getElementById('y').value;
				var x2 = document.getElementById('x2').value;
				var y2 = document.getElementById('y2').value;
				var type = document.getElementById('type').options[document.getElementById('type').selectedIndex].value;
				var piece = document.getElementById('piece').options[document.getElementById('piece').selectedIndex].value;
				var surface0 = document.getElementById('surface0').value;
				var surface1 = document.getElementById('surface1').value;
				var prix = document.getElementById('prix').value;
				
				if(document.getElementById('tri')){
				var tri = document.getElementById('tri').options[document.getElementById('tri').selectedIndex].value;
				}else{
				var tri = 'prix';
				}
				document.getElementById('estim').style.display = 'none';
				document.getElementById('box').style.display='none';
				document.getElementById('filter').style.display='none';
				$.ajax({
						type : "POST",
							url : "ajax/filtreAjax.php",
							data : "type="+type+"&operation="+operation+"&surface0="+surface0+"&surface1="+surface1+"&prix="+prix+"&piece="+piece+"&x="+x+"&y="+y+"&x2="+x2+"&y2="+y2+"&sort="+tri,
							send : $('#list_annonce').html("<img src='images/load.gif' />"),
							error :function(msg){
									alert( "Erreur ajax : " + msg ); 
								},
							success : function(data){
				
								$('#list_annonce').html(data);
						}});
			
		}
		
		
function close_map(){
	document.getElementById('box').style.display='none';
	document.getElementById('filter').style.display='none';
}


function codepos(i){

var codepos = document.getElementById('codepost'+i).options[document.getElementById('codepost'+i).selectedIndex].value;

$.ajax({
							type : "POST",
							url : "ajax/codeposAjax.php",
							data : "codepos="+codepos+"&i="+i ,
							send : $('#affVille').html("<img src='../images/load.gif' />"),
							error :function(msg){
									alert( "Erreur ajax : " + msg ); 
								},
							success : function(data){
				
								$('#affVille'+i).html(data);
						}});
			
		}
		
		
		function codepos2(){

var codepos = document.getElementById('codepost').options[document.getElementById('codepost').selectedIndex].value;

$.ajax({
							type : "POST",
							url : "ajax/codeposAjax.php",
							data : "codepos="+codepos ,
							send : $('#affVille').html("<img src='../images/load.gif' />"),
							error :function(msg){
									alert( "Erreur ajax : " + msg ); 
								},
							success : function(data){
				
								$('#affVille').html(data);
						}});
			
		}
		

function ajaxTest(annonce){
	var upload = document.getElementById('upload').options[document.getElementById('upload').selectedIndex].value;
	$.ajax({
				type : "POST",
				url : "ajax/pageAjax.php",
				data : "upload="+upload+"&annonce="+annonce ,
				send : $('#divTest').html("<img src='../images/load_image.gif' /><br />Le chargement peut-être long, merci de patienter."),
				error :function(msg){
    					// alert( "Erreur ajax : " + msg ); 
						 document.getElementById('erreur').innerHTML = "<span style='color:red'>Aie aie aie !</span>";
					},
   				success : function(data){
   	
					$('#divTest').html(data);
				}});
	
}

	var Car_Image_Width=300;
	var Car_Image_Height=133;
	var Car_Border=true;		// true or false
	var Car_Border_Color="#303030";
	var Car_Speed=1;
	var Car_Direction=true;		// true or false
	var Car_NoOfSides=8;		// must be 4, 6, 8 or 12

	Car_Image_Sources=new Array(
		"images/tar1.jpg","",
		"images/tar2.jpg","",
		"images/tar1.jpg","", //this slide isn't linked
		"images/tar2.jpg","" // NOTE No comma after last line
		);

/***************** DO NOT EDIT BELOW **********************************/
	CW_I=new Array(Car_NoOfSides/2+1);C_ClcW=new Array(Car_NoOfSides/2);
	C_Coef=new Array(
		3*Math.PI/2,0,3*Math.PI/2,11*Math.PI/6,Math.PI/6,3*Math.PI/2,7*Math.PI/4,	0,
		Math.PI/4,3*Math.PI/2,5*Math.PI/3,11*Math.PI/6,0,Math.PI/6,Math.PI/3);
	var C_CoefOf=Car_NoOfSides==4?0:Car_NoOfSides==6?2:Car_NoOfSides==8?5:9;
	C_Pre_Img=new Array(Car_Image_Sources.length);
	var C_Angle=Car_Direction?Math.PI/(Car_NoOfSides/2):0,C_CrImg=Car_NoOfSides,C_MaxW,C_TotalW,
	C_Stppd=false,i,C_LeftOffset,C_HalfNo=Car_NoOfSides/2;

	function Carousel(){
		if(document.getElementById){
			for(i=0;i<Car_Image_Sources.length;i+=2){
				C_Pre_Img[i]=new Image();C_Pre_Img[i].src=Car_Image_Sources[i]}
			C_MaxW=Car_Image_Width/Math.sin(Math.PI/Car_NoOfSides)+C_HalfNo+1;
			Car_Div=document.getElementById("Carousel");
			for(i=0;i<C_HalfNo;i++){
				CW_I[i]=document.createElement("img");Car_Div.appendChild(CW_I[i]);	
				CW_I[i].style.position="absolute";
				CW_I[i].style.top=0+"px";
				CW_I[i].style.height=Car_Image_Height+"px";
				if(Car_Border){
					CW_I[i].style.borderStyle="solid";
					CW_I[i].style.borderWidth=1+"px";
					CW_I[i].style.borderColor=Car_Border_Color}
				CW_I[i].src=Car_Image_Sources[2*i];
				CW_I[i].lnk=Car_Image_Sources[2*i+1];
				CW_I[i].onclick=C_LdLnk;
				CW_I[i].onmouseover=C_Stp;
				CW_I[i].onmouseout=C_Rstrt}
			CarImages()}}

	function CarImages(){
		if(!C_Stppd){
			C_TotalW=0;
			for(i=0;i<C_HalfNo;i++){
				C_ClcW[i]=Math.round(Math.cos(Math.abs(C_Coef[C_CoefOf+i]+C_Angle))*Car_Image_Width);
				C_TotalW+=C_ClcW[i]}
			C_LeftOffset=(C_MaxW-C_TotalW)/2;
			for(i=0;i<C_HalfNo;i++){
				CW_I[i].style.left=C_LeftOffset+"px";
				CW_I[i].style.width=C_ClcW[i]+"px";
				C_LeftOffset+=C_ClcW[i]}
			C_Angle+=Car_Speed/720*Math.PI*(Car_Direction?-1:1);
			if((Car_Direction&&C_Angle<=0)||(!Car_Direction&&C_Angle>=Math.PI/C_HalfNo)){
				if(C_CrImg==Car_Image_Sources.length)C_CrImg=0;
				if(Car_Direction){
					CW_I[C_HalfNo]=CW_I[0];
					for(i=0;i<C_HalfNo;i++)CW_I[i]=CW_I[i+1];
					CW_I[C_HalfNo-1].src=Car_Image_Sources[C_CrImg];
					CW_I[C_HalfNo-1].lnk=Car_Image_Sources[C_CrImg+1]}
				else{	for(i=C_HalfNo;i>0;i--)CW_I[i]=CW_I[i-1];
					CW_I[0]=CW_I[C_HalfNo];
					CW_I[0].src=Car_Image_Sources[C_CrImg];
					CW_I[0].lnk=Car_Image_Sources[C_CrImg+1]}
				C_Angle=Car_Direction?Math.PI/C_HalfNo:0;C_CrImg+=2}}
		setTimeout("CarImages()",50)}

	function C_LdLnk(){if(this.lnk)window.location.href=this.lnk}
	function C_Stp(){this.style.cursor=this.lnk?"pointer":"default";C_Stppd=true;}
	function C_Rstrt(){C_Stppd=false}
