// Copyrights Hebergimmo, tous droits réservés.


function onload_functions(){ // déclenche les fonctions au chargement de la page
	set_footer_ypos();
	set_separateur_pointille_height();
	}

// roll over buttons a/b
function roll(id){
	tmp=document.getElementById(id)
	if(tmp.src.substr(tmp.src.length-5,1)=="b"){tmp.src=tmp.src.replace("b.","a.")}
	else{tmp.src=tmp.src.replace("a.","b.")}
	}


// affiche une popup de diaporama
// ex photos_popup('123457','123456,123457,123458','400x300,400,300,400x300','image 1#image2#image3')
function photos_popup(first_photo_id,photos_ids,sizes,titles){
	photos_liste=photos_ids.split(",")
	titles_liste=titles.split("#")
	sizes_liste=get_photos_sizes(sizes)
	actual_photo=get_first_photo_liste_position(first_photo_id,photos_liste)
	// création du contenu
	photos_HTML=""
	+"<div align='center'>"
	+"<a href='javascript:popup_etat(0)'><img id='photo_slide_show' src='img/"+var_id_client+"/photos/big/"+photos_liste[actual_photo]+".jpg' width='"+sizes_liste[actual_photo][0]+"' height='"+sizes_liste[actual_photo][1]+"' class='contour_1' " 
	if(navigator.appName=="Microsoft Internet Explorer"){photos_HTML+=" style='filter:blendTrans(duration=.5)'"}
	photos_HTML+="></a>"
	+"<br><br><a href='javascript:slide_show(-1)'><img src='"+var_skin_path+"bt_small_previous.gif' align='absmiddle'></a>"
	+"&nbsp;&nbsp;&nbsp;&nbsp;<span id='compteur_slide_show' class='popup_nb_pages'>Photo "+(actual_photo+1)+" / "+photos_liste.length+"</span>&nbsp;&nbsp;&nbsp;&nbsp;"
	+"<a href='javascript:slide_show(1)'><img src='"+var_skin_path+"bt_small_next.gif' align='absmiddle'></a></div>"
	+"<div><img src='"+var_skin_path+"pixel.gif' width='1' height='3'></div>"
	
	popup(titles_liste[actual_photo],photos_HTML,xpos,findPosY('photo_'+photos_liste[actual_photo])-100)
	}
	
// récupère la position de la photo dans la liste
function get_first_photo_liste_position(first_photo_id,photos_liste){
		for(pos=0;pos<photos_liste.length;pos++){
			if(first_photo_id==photos_liste[pos]){break}
			}
		return pos
	}

// crée le tableau des dimension des photos du slideshow
function get_photos_sizes(sizes){
	sizes=sizes.split(",")
	for(i=0;i<sizes.length;i++){
		tmp=sizes[i].split("x")
		sizes[i]=new Array(tmp[0],tmp[1])
		}
	return sizes
	}
	

// slideshow
function slide_show(direction){
	if(direction==-1){if(actual_photo+direction>=0){actual_photo--}else{actual_photo=photos_liste.length-1}}
	if(direction==1){if(actual_photo+direction<=photos_liste.length-1){actual_photo++}else{actual_photo=0}}
	document.getElementById("compteur_slide_show").innerHTML="Photo "+(actual_photo+1)+" / "+photos_liste.length
	document.getElementById("popup_title").innerHTML=titles_liste[actual_photo]
	tmp=document.getElementById("photo_slide_show")
	if(navigator.appName=="Microsoft Internet Explorer"){
		document.getElementById("popup").filters.blendTrans.apply()
		tmp.src="img/"+var_id_client+"/photos/big/"+(photos_liste[actual_photo])+".jpg"
		tmp.width=sizes_liste[actual_photo][0]
		tmp.height=sizes_liste[actual_photo][1]
		document.getElementById("popup").filters.blendTrans.play()
		}else{
			tmp.src="img/"+var_id_client+"/photos/big/"+(photos_liste[actual_photo])+".jpg"
			tmp.width=sizes_liste[actual_photo][0]
			tmp.height=sizes_liste[actual_photo][1]
			}
	}


// crée la structure de la popup
function popup(titre,contenu,popup_xpos,popup_ypos){

if(!popup_xpos){popup_xpos=xpos}
if(!popup_ypos){popup_ypos=ypos-160}

popup_HTML=""
+"<table border='0' cellpadding='0' cellspacing='0'>"
		+"<tr>"
			+"<td>"
				+"<table width='100%'>"
				+"<tr>"
                +"<td class='popup_corner_left'><img src='"+var_skin_path+"popup_icone.gif'></td>"
                +"<td class='popup_barre' width='100%' id='popup_title'>"+titre+"</td>"
                +"<td class='popup_corner_right'>"
				+"<a href='javascript:popup_etat(0)'><img src='"+var_skin_path+"popup_close.gif' border='0'></a></td>"
				+"</table>"
				+"<table class='popup_bg_color' width='100%'>"
				+"<tr>"
				+"<td class='popup_content'>"+contenu+"</td>"
				+"</tr>"
				+"</table>"
				+"<table width='100%'>"
				+"<tr>"
				+"<td width='7' class='popup_corner_left'><img src='"+var_skin_path+"popup_corner_left.gif' width='9' height='9'></td>"
				+"<td class='popup_bg_color popup_bottom'><img src='"+var_skin_path+"pixel.gif' width='1' height='1'></td>"
				+"<td width='10' class='popup_corner_right'><img src='"+var_skin_path+"popup_corner_right.gif' width='9' height='9'></td>"
				+"</tr>"
				+"</table>"
			+"</td>"
		+"</tr>"
+"</table>"
	
	tmp=document.getElementById("popup")
	tmp.innerHTML=popup_HTML
	if(navigator.appName=="Microsoft Internet Explorer"){tmp.style.left=popup_xpos+"px"}else{
		if(window.innerWidth>770){marge=(window.innerWidth-770)/2}else{marge=0}
			tmp.style.left=(popup_xpos-marge)+"px"
			}
	tmp.style.top=popup_ypos+"px";
	popup_etat(1)
	}
	

// gére l'affichage on/off de la popup avec transition animée si MSIE
function popup_etat(etat){
	tmp=document.getElementById("popup")
	if(etat==1){
		if(navigator.appName=="Microsoft Internet Explorer"){
			document.getElementById("popup").filters.blendTrans.apply()
			tmp.style.visibility="visible"
			document.getElementById("popup").filters.blendTrans.play()
				}else{tmp.style.visibility="visible"}
		}else{tmp.style.visibility="hidden"}
	}


// change la langue principale
function change_language_to(new_language){
	get_data_from_server("change_language.php","language="+new_language)
	}


// vérifie les champs
function verif_champs_obligatoires(intitules,values,formulaire,action_formulaire,tmp_xpos,tmp_ypos){
	
	
	values=values.split(";")
	intitules=intitules.split(";")
	tmp=""
		for(i=0;i<values.length;i++){
			if(values[i]==""){tmp+="<image src='"+var_skin_path+"puce_carre_s1.gif'> &nbsp;"+intitules[i]+"<br>"}
			}
		if(tmp==""){
			eval("document."+formulaire+".action=\""+action_formulaire+"\"")
			eval("document."+formulaire+".submit()")
			}
			else{popup(jtext["A_0"],"<b>"+jtext["A_1"]+" :</b><table><tr><td class='vesp7'></td></tr></table>"+tmp,tmp_xpos,tmp_ypos)}
	}


// saisie en chiffre uniquement
function numbers_only(e){
code=""
if(!e){e=window.event}
if(e.keyCode){code=e.keyCode}else{code=e.which}
if(code< 46 || code>57 || code==46){return false}else{return true}
}


// recherche rapide sur la gauche
function recherche_rapide(){
	tmp_prix_min=document.getElementById("prix_min").value
	tmp_prix_max=document.getElementById("prix_max").value
	type_recherche_rapide=document.getElementById("select_recherche_rapide").value
	type_bien_recherche_rapide=document.getElementById("select_type_bien_rapide").value
	
	if(type_recherche_rapide=="1"){tmp="annonces-ventes.htm";}
	if(type_recherche_rapide=="2"){tmp="annonces-locations.htm";}
	
parent.location.href=tmp+"?type_bien="+type_bien_recherche_rapide+"&prix1="+document.getElementById("prix_min").value+"&prix2="+document.getElementById("prix_max").value
	}


// extrait le code d'erreur
function search_error(){
	temp=location.href+""
	if(temp.indexOf("error=")!=-1){ // si une ereur est déclarée
		car=temp.substr(temp.indexOf("error=")+6,temp.length-temp.indexOf("error=")+6)
		
			if(car.length==1){err=car}else{
						temp=car
						car=""
						for(i=0;i<temp.length;i++){
							if(temp.substr(i,1)!="&"){car+=temp.substr(i,1)}else{break}
							}
				}
			
			if(!isNaN(car)){show_error(car)}
		}
}


// affiche la popup d'erreur
function show_error(car){
	if(error_code[eval(car)]){	
		temp=error_code[eval(car)].split("###")
		popup(temp[0],temp[1],400,400)
		}
}


// appelle une page via iframe masquée
function ask_helper(url){
	document.getElementById("helper").innerHTML="<iframe src='"+url+"'></iframe>"
	}


// vide le helper
function flush_helper(){parent.document.getElementById("helper").innerHTML=""};


// gestion du panier des selections d'annonces
function gestion_panier_selection(id_annonce,choix){
	switch(choix){
		case "ajouter":ask_helper("ajoutselection.php?id_annonce="+id_annonce);document.getElementById("sel_lnk_"+id_annonce).className='add_selection_color';break;
		case "delete":ask_helper("delete_selection.php?id_annonce="+id_annonce);break
		// case "delete_all":ask_helper("delete_all_selections.php");break;
		}

	}

// consulter la page des selections d'annonces
function acces_selections(){
	tmp=eval(document.getElementById('advert_count').innerHTML)
	if(tmp>0){location.href='annonces.php?listeselection='+tmp}
		else{popup(jtext["A_2"],"<div align='center' class='popup_texte'>"+jtext["A_3"]+"</div>","550","50")} // pas d'annonces selectionnées.
	}


// gestion de l'alerte
function inscription_alerte(){
	tmp=document.getElementById("alerte_box")
	tmp2=document.getElementById("inscription_alerte")
	if(tmp.checked==true){
		tmp2.style.display="";tmp.value="yes"
	
			if(navigator.appName=="Microsoft Internet Explorer"){
			document.getElementById("inscription_alerte").filters.blendTrans.apply()
			document.getElementById("inscription_alerte").filters.blendTrans.play()
			}
	
		}
		else{tmp2.style.display="none"}
	onload_functions()
	}
	

// verif champs obligatoires
function verif_recherche(){
	tmp=document.getElementById("alerte_box")
	
	tmp2=location.href+""
	target="annonces-ventes.htm";
	if(tmp2.indexOf("rechercher-locations.htm")!=-1){target="annonces-locations.htm";}
	if(tmp2.indexOf("rechercher-locations-saisonnieres.htm")!=-1){target="annonces-locations-saisonnieres.htm";}
	
	if(tmp.checked==true){
		// la vérif porte sur la recherche et sur les champs de l'alerte
		verif_champs_obligatoires(jtext["A_4"]+";"+jtext["A_5"]+";"+jtext["A_6"]+";"+jtext["A_7"],document.getElementById('type_bien').value+";"+document.getElementById('nom').value+";"+document.getElementById('prenom').value+";"+document.getElementById('email').value,'form_recherche',target,400,480)
		}
		else{ // la vérif ne porte que sur la racherche
			verif_champs_obligatoires(jtext["A_4"],document.getElementById('type_bien').value,'form_recherche',target,400,315)
			}
	
	}


// limite le nb de car par champs
function limit_char(id,id_char_count,max_chars){
	tmp=document.getElementById(id)
	if(tmp.value.length > max_chars){tmp.value=tmp.value.substr(0,max_chars);}
	document.getElementById(id_char_count).innerHTML=max_chars-tmp.value.length
	}


// gestion de l'impression d'annonces (séparer les ids annonce par des ;)
function print_annonce(ids_annonce){
	// on donne le choix concernant les photos
	HTML_print="<table cellpadding='0' cellspacing='0' border='0' style='width:180px;'>"
	+"<tr><td colspan='2' style='height:23px;' valign='top'><b>"+jtext["A_14"]+"</b></td></tr>"
	+"<tr><td style='width:15px;'><input type='radio' name='print_photo' id='print_with_photo' checked></td><td>&nbsp;"+jtext["A_15"]+"</td></tr>"
	+"<tr><td align='left'><input type='radio' name='print_photo'></td><td style='width:165px;'>&nbsp;"+jtext["A_16"]+"</td></tr>"
	+"<tr><td colspan='2' style='height:32px;' valign='middle' align='center'><img src='"+var_skin_path+"puce_lien_a.gif' border='0' align='absmiddle'> &nbsp;<a href=\"javascript:print_annonce_now('"+ids_annonce+"');\"><b>"+jtext["A_17"]+"</b></a>&nbsp;&nbsp;&nbsp;&nbsp;<img align='absmiddle' src='"+var_skin_path+"puce_lien_a.gif' border='0'> &nbsp;<a href='javascript:popup_etat(0)'><b>"+jtext["A_18"]+"</b></a></td></tr>"
	+"</table>"
	popup(jtext["A_19"],HTML_print,xpos,ypos)
	}
	
function print_annonce_now(ids_annonce){
	if(document.getElementById("print_with_photo").checked==true){with_photo=1}else{with_photo=0}
	popup_etat(0)
	//ask_helper("print_annonce.php?ids_annonce="+ids_annonce)
	window.open('print_annonce.php?photos='+with_photo+'&ids_annonce='+ids_annonce)
	}


// envoyer des fiches à un ami
function send_annonces(ids_annonce){
	html="<table cellpadding='0' cellspacing='0' border='0'>"
		
		+"<tr><td class='vesp5' colspan='3'></td></tr>"
		
		+"<tr  class='popup_texte'><td colspan='3' class='popup_texte'><b>"+jtext["A_13"]+" :</b></td></tr>"
		
		+"<tr><td class='vesp7' colspan='3'></td></tr>"
		
		+"<tr><td style='height:24px;' class='popup_texte'>"+jtext["A_9"]+"</td><td style='width:15px;' align='center' class='popup_texte'>:</td><td><input type='text' value='' name='from_nom' id='from_nom' class='input_2' style='width:150px;' maxlength='128'></td></tr>"
		
		+"<tr><td style='height:24px;' class='popup_texte'>"+jtext["A_10"]+"</td><td align='center' class='popup_texte'>:</td><td><input type='text' value='' name='from_prenom' id='from_prenom' class='input_2' style='width:150px;' maxlength='128'></td></tr>"
		
		+"<tr><td style='height:24px;' class='popup_texte'>"+jtext["A_11"]+"</td><td align='center' class='popup_texte'>:</td><td><input type='text' value='' name='from_email' id='from_email' class='input_2' style='width:150px;' maxlength='256'></td></tr>"
		
		+"<tr><td class='vesp7' colspan='3'></td></tr>"
		+"<tr><td class='popup_separateur' colspan='3'></td></tr>"
		+"<tr><td class='vesp7' colspan='3'></td></tr>"
		
		+"<tr><td class='popup_texte'>"+jtext["A_12"]+"</td><td align='center' class='popup_texte'>:</td><td><input type='text' value='' name='to_email' id='to_email' class='input_2' style='width:150px;' maxlength='256'></td></tr>"
		+"<tr><td class='vesp7' colspan='3'></td></tr>"
		+"<tr><td class='vesp40' colspan='3' align='center' style='width:300px;'><a href='javascript:send_annonces_now(\""+ids_annonce+"\",document.getElementById(\"from_nom\").value,document.getElementById(\"from_prenom\").value,document.getElementById(\"from_email\").value,document.getElementById(\"to_email\").value)'><img src='"+var_skin_path+"bt_envoyer_a_un_ami.gif' border='0'></a></td></tr>"
		
		+"</table>" 
		
	popup(jtext["A_8"],html,xpos-250,ypos+25)

	}
	
	
// envoyer fiches à un ami
function send_annonces_now(ids_annonce,from_nom,from_prenom,from_email,to_email){
	
	popup_etat(0)
		
	ask_helper("send_annonce.php?ids_annonce="+ids_annonce+"&from_nom="+from_nom+"&from_prenom="+from_prenom+"&from_email="+from_email+"&to_email="+to_email)
	}
	
	
	
	
// positionne le footer en bas de page
function set_footer_ypos(){
	
	h_menu2=getObjectHeight("menu2")+20
	h_contenu_page=getObjectHeight("contenu_page")+20
	
	if(h_menu2>=h_contenu_page){footer_posy=h_menu2}else{footer_posy=h_contenu_page}
	
	footer_posy=footer_posy+findPosY("menu2")
	
	document.getElementById("footer").style.top=footer_posy
	document.getElementById("footer").style.display="inline"
	}
	

// définie la hauteur du separateur en pointillés
function set_separateur_pointille_height(){
	tmp=getObjectHeight("contenu_page")
	tmp2=getObjectHeight("menu2")
	if(tmp2>tmp){tmp=tmp2}
	document.getElementById("separateur_pointille").style.height=tmp
	}


// Chargement des fonctions d'après chargement
if(navigator.appName.indexOf("Microsoft")!=-1){
	window.onload = onload_functions;}else{
	window.addEventListener('load', onload_functions, false);
	}