// JavaScript Document

function check_radio(input){
	document.getElementById(input).checked=true;
};

function check_radio2(input){
	document.getElementById(input).checked=true;
	verif_pays();
};

function verif_loc(){
	cle=document.getElementById("type_loc_choix").options[document.getElementById("type_loc_choix").selectedIndex].value;
	recup=tab_type_location_etage[cle];
	if(recup==1){
		document.getElementById('etage_titre').className='visible';
		document.getElementById('etage_contenu').className='visible';
	}else{
		document.getElementById('etage_titre').className='cache';
		document.getElementById('etage_contenu').className='cache';
	};
};

function getXMLHTTP(){
	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) {
		  try {
			xhr = new ActiveXObject("Microsoft.XMLHTTP");
		  } catch (e1) {
			xhr = null;
		  }
		}
	  }
	  else { // XMLHttpRequest non supporté par le navigateur
		alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
	  }
	  return xhr;
};

function confirmation(page,text){
	rep=confirm(text);
	if(rep==true){
		window.document.location.href=page;
	};
};

function cocher_toutes(frm,cases,bouton){
	objet=document.getElementById(frm).elements[cases];
	nb_cases=objet.length;
	if(!nb_cases){
		nb_cases=1;
	};
	valeur_bouton=document.getElementById(frm).elements[bouton].checked;
	for(i=0;i<=nb_cases;i++){
		document.getElementById(frm).elements[i].checked = valeur_bouton;
	};
};

function modif_tarif(saison){
	objet=document.getElementById('tab_modif');
	valeur=objet.value;
	chaine=valeur+","+saison;
	valeur=chaine;
	objet.value=chaine;
};

function set_periode(tps,loc){
	saison=document.getElementById('num_saison').value;
	_xmlhttp=getXMLHTTP();
	chaine="module_periodes_maj.php?tps="+tps+"&saison="+saison+"&location="+loc;
	_xmlhttp.open("GET",chaine,true);
	_xmlhttp.onreadystatechange=function(){
		if (_xmlhttp.readyState == 4){ /* 4 : état "complete" */
			recup=_xmlhttp.responseText;
			if(recup==1){
				nom_td="td_"+tps;
				nom_classe="td_"+saison;
				document.getElementById(nom_td).className=nom_classe;
			}else{
				alert(recup);
			};
		};
	};
	_xmlhttp.send(null);
};

function set_periode_all(loc,tps_deb,tps_fin){
	saison=document.getElementById('num_saison').value;
	_xmlhttp=getXMLHTTP();
	chaine="module_periodes_maj_all.php?tps_debut="+tps_deb+"&tps_fin="+tps_fin+"&location="+loc+"&saison="+saison;
	_xmlhttp.open("GET",chaine,true);
	_xmlhttp.onreadystatechange=function(){
		if(_xmlhttp.readyState == 4){ /* 4 : état "complete" */
			recup=_xmlhttp.responseText;
			if(recup==1){
				var datefin=new Date(tps_fin*1000);
				var mois=datefin.getMonth();
				var annee=datefin.getFullYear();
				var jourpremier=1;
				var jourdernier=datefin.getDate();
				var tps_mili=0;
				var tps=0;
				var datenow='';
				var chaine='';
				for(i=jourpremier;i<=jourdernier;i++){
					datenow=new Date(annee,mois,i,4,0,0,0);
					tps_mili=datenow.getTime();
					tps=parseInt(tps_mili/1000);
					nom_td="td_"+tps;
					nom_classe="td_"+saison;
					document.getElementById(nom_td).className=nom_classe;
				};
			}else{
				alert(recup);
			};
		};
	};
	_xmlhttp.send(null);
};

function navig_mois(adr,loc,mois,annee){
	chaine_adr=adr+"?location="+loc+"&mois="+mois+"&annee="+annee+"&check="+document.getElementById('num_saison').value;
	window.document.location.href=chaine_adr;
};

function select_periode(adr,loc,dieze){
	select_mois=document.getElementById('mois_select');
	mois=select_mois.options[select_mois.selectedIndex].value;
	
	select_annee=document.getElementById('annee_select');
	annee=select_annee.options[select_annee.selectedIndex].value;
	
	chaine_adr=adr+"?location="+loc+"&mois="+mois+"&annee="+annee;
	if(dieze){
		chaine_adr+=dieze;
	};
	window.document.location.href=chaine_adr;
};

function select_periode_module(adr,loc){
	select_mois=document.getElementById('mois_select');
	mois=select_mois.options[select_mois.selectedIndex].value;
	
	select_annee=document.getElementById('annee_select');
	annee=select_annee.options[select_annee.selectedIndex].value;
	
	chaine_adr=adr+"?location="+loc+"&mois="+mois+"&annee="+annee+"&check="+document.getElementById('num_saison').value;
	window.document.location.href=chaine_adr;
};




function check_saison(cle){
	for(i=0;i<5;i++){
		document.getElementById('check_'+i).checked=false;
	};
	document.getElementById('check_'+cle).checked=true;
	document.getElementById('num_saison').value=cle;
};

function set_reservation(tps,loc){
	etat=document.getElementById('num_saison').value;
	_xmlhttp=getXMLHTTP();
	chaine="module_reservations_maj.php?tps="+tps+"&location="+loc+"&etat="+etat;
	_xmlhttp.open("GET",chaine,true);
	_xmlhttp.onreadystatechange=function(){
		if (_xmlhttp.readyState == 4){
			recup=_xmlhttp.responseText;
			if(recup==1){
				nom_td="td_"+tps;
				nom_classe="td2_"+etat;
				document.getElementById(nom_td).className=nom_classe;
			}else{
				alert(recup);
			};
		};
	};
	_xmlhttp.send(null);
};

function set_reservation_all(loc,tps_deb,tps_fin){
	etat=document.getElementById('num_saison').value;
	_xmlhttp=getXMLHTTP();
	chaine="module_reservations_maj_all.php?tps_debut="+tps_deb+"&tps_fin="+tps_fin+"&location="+loc+"&etat="+etat;
	_xmlhttp.open("GET",chaine,true);
	_xmlhttp.onreadystatechange=function(){
		if(_xmlhttp.readyState == 4){ /* 4 : état "complete" */
			recup=_xmlhttp.responseText;
			if(recup==1){
				var datefin=new Date(tps_fin*1000);
				var mois=datefin.getMonth();
				var annee=datefin.getFullYear();
				var jourpremier=1;
				var jourdernier=datefin.getDate();
				var tps_mili=0;
				var tps=0;
				var datenow='';
				var chaine='';
				for(i=jourpremier;i<=jourdernier;i++){
					datenow=new Date(annee,mois,i,4,0,0,0);
					tps_mili=datenow.getTime();
					tps=parseInt(tps_mili/1000);
					nom_td="td_"+tps;
					nom_classe="td_"+saison;
					document.getElementById(nom_td).className=nom_classe;
				};
			}else{
				alert(recup);
			};
		};
	};
	_xmlhttp.send(null);
};

// POP UP //////////
var popup;

function popup_open(adresse,width,height){
	popup_close();
	popup=window.open(adresse,'popup','width='+width+',height='+height+',directories=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=no')
};

function popup_close(){
	 if (popup != null){
		if(!popup.closed){
			popup.close();
		};
	};
};

function popup_affiche(){
	window.focus();
	var le = window.screen.availWidth;
	var he = window.screen.availHeight;;
	var xf = le/2 - 300;
	var yf = he/2 - 300;
	window.moveTo(xf, yf);
};
///////////////////

function search_ville(cp,autre_nom,vil,quart,dep){
	document.getElementById('liste_quartier').className='cache';
	document.getElementById('liste_quartier2').className='cache';
	select_ville=document.getElementById('ville');
	while(select_ville.length>0){
		select_ville.length--;
	};
	_xmlhttp=getXMLHTTP();
	chaine="module_location_search_ville.php?cp="+cp+"&dep="+dep;
	_xmlhttp.open("GET",chaine,true);
	_xmlhttp.onreadystatechange=function(){
		if (_xmlhttp.readyState == 4){ /* 4 : état "complete" */
			chaine=_xmlhttp.responseText;
			//alert(chaine);
			if(chaine!='0'){
				tab_ville=chaine.split("$");
				for(i=0;i<tab_ville.length;i++){
					tab_vi=tab_ville[i].split(";");
					ville_id=tab_vi[0];
					ville_nom=tab_vi[1];
					ville_nom=unescape(ville_nom);
					ville_nom=ville_nom.replace("+"," ");
					ville_nom=ville_nom.replace("+"," ");
					ville_nom=ville_nom.replace("+"," ");
					if(vil==ville_id){
						select_ville.options[select_ville.length]=new Option(ville_nom,ville_id,false,true);
					}else{
						select_ville.options[select_ville.length]=new Option(ville_nom,ville_id,false,false);
					};
				};
				document.getElementById('liste_ville').className='visible';
				document.getElementById('liste_ville2').className='visible';
			}else{
				document.getElementById('liste_ville').className='cache';
				document.getElementById('liste_ville2').className='cache';
			};
			search_quartier(autre_nom,quart);
		};
	};
	_xmlhttp.send(null);
};

function search_quartier(autre_nom,quart){
	document.getElementById('liste_quartier3').className='cache';
	document.getElementById('liste_quartier4').className='cache';
	document.getElementById('liste_quartier5').className='cache';
	document.getElementById('liste_quartier6').className='cache';
	select_ville=document.getElementById('ville');
	if(select_ville.length>0){
		cle=select_ville.options[select_ville.selectedIndex].value;
		select_qua=document.getElementById('quartier');
		while(select_qua.length>0){
			select_qua.length--;
		};
		_xmlhttp=getXMLHTTP();
		chaine="module_location_search_quartier.php?ville="+cle;
		_xmlhttp.open("GET",chaine,true);
		_xmlhttp.onreadystatechange=function(){
			if (_xmlhttp.readyState == 4){ /* 4 : état "complete" */
				chaine=_xmlhttp.responseText;
				if(chaine!='0'){
					tab_quartier=chaine.split("$");
					for(i=0;i<tab_quartier.length;i++){
						tab_qua=tab_quartier[i].split(";");
						qua_id=tab_qua[0];
						qua_nom=tab_qua[1];
						qua_nom=unescape(qua_nom);
						qua_nom=qua_nom.replace("+"," ");
						qua_nom=qua_nom.replace("+"," ");
						qua_nom=qua_nom.replace("+"," ");
						if(quart==qua_id){
							select_qua.options[select_qua.length]=new Option(qua_nom,qua_id,false,true);
						}else{
							select_qua.options[select_qua.length]=new Option(qua_nom,qua_id,false,false);
						};
					};
					autre_nom="AUTRE (Définir)";
					select_qua.options[select_qua.length]=new Option(autre_nom,0,false,false);
					document.getElementById('liste_quartier').className='visible';
					document.getElementById('liste_quartier2').className='visible';
				}else{
					document.getElementById('liste_quartier').className='cache';
					document.getElementById('liste_quartier2').className='cache';
					document.getElementById('liste_quartier5').className='visible';
					document.getElementById('liste_quartier6').className='visible';
				};
			};
		};
		_xmlhttp.send(null);
	};
};

function modif_quartier(){
	cle=document.getElementById("quartier").options[document.getElementById("quartier").selectedIndex].value;
	if(cle==0){
		document.getElementById('liste_quartier3').className='visible';
		document.getElementById('liste_quartier4').className='visible';
		document.getElementById('quartier_autre').focus();
	}else{
		document.getElementById('liste_quartier3').className='cache';
		document.getElementById('liste_quartier4').className='cache';
	};
};

function location_navig_delete(){
	document.getElementById('partie1').className='cache';
	document.getElementById('partie2').className='cache';
	document.getElementById('partie3').className='cache';
	document.getElementById('partie4').className='cache';
	document.getElementById('partie5').className='cache';
	document.getElementById('partie6').className='cache';
};


function location_navig_precedent(){
	if(navig_num>1){
		location_navig_delete();
		navig_num--;
		nom_div="partie"+navig_num;
		document.getElementById(nom_div).className='visible';
		/*if(navig_num==1){
			document.getElementById('precedent').className='cache';
			document.getElementById('precedent2').className='cache';
		}else{
			document.getElementById('precedent').className='visible';
			document.getElementById('precedent2').className='visible';
		};
		document.getElementById('suivant').className='visible';
		document.getElementById('suivant2').className='visible';*/
	};
};

function location_navig_suivant(){
	if(navig_num<6){
		location_navig_delete();
		navig_num++;
		nom_div="partie"+navig_num;
		document.getElementById(nom_div).className='visible';
		/*if(navig_num==6){
			document.getElementById('suivant').className='cache';
			document.getElementById('suivant2').className='cache';
		}else{
			document.getElementById('suivant').className='visible';
			document.getElementById('suivant2').className='visible';
		};
		document.getElementById('precedent').className='visible';
		document.getElementById('precedent2').className='visible';*/
	};
};

function search_departement(tous_nom){
	select_region=document.getElementById('region');
	region=select_region.options[select_region.selectedIndex].value
	select_dep=document.getElementById('departement');
	while(select_dep.length>0){
		select_dep.length--;
	};
	if(region>0){
		_xmlhttp=getXMLHTTP();
		chaine="index_search_departement.php?region="+region;
		_xmlhttp.open("GET",chaine,true);
		_xmlhttp.onreadystatechange=function(){
			if (_xmlhttp.readyState == 4){ /* 4 : état "complete" */
				chaine=_xmlhttp.responseText;
				if(chaine!='0'){
					tab_dep=chaine.split("$");
					if(tab_dep.length>1){
						select_dep.options[select_dep.length]=new Option(tous_nom,0,0);
					};
					for(i=0;i<tab_dep.length;i++){
						tab_d=tab_dep[i].split(";");
						dep_id=tab_d[0];
						dep_nom=tab_d[2]+' - '+tab_d[1];
						dep_nom=unescape(dep_nom);
						dep_nom=dep_nom.replace("+"," ");
						dep_nom=dep_nom.replace("+"," ");
						dep_nom=dep_nom.replace("+"," ");
						select_dep.options[select_dep.length]=new Option(dep_nom,dep_id,0);
					};
				}else{
					select_dep.options[select_dep.length]=new Option(tous_nom,0,0);
				};
			};
		};
		_xmlhttp.send(null);
	}else{
		select_dep.options[select_dep.length]=new Option(tous_nom,0,0);
	};
};

function search_result(){
	ville_location=document.getElementById('ville_location').value;
	nb_pers_location=document.getElementById('nb_pers_location').value;
	region=1;
	departement=1;
	_xmlhttp=getXMLHTTP();
	chaine="index_search_result.php?ville_location="+ville_location+"&nb_pers_location="+nb_pers_location;
	_xmlhttp.open("GET",chaine,true);
	_xmlhttp.onreadystatechange=function(){
		if (_xmlhttp.readyState == 4){ /* 4 : état "complete" */
			chaine=_xmlhttp.responseText;
			if(chaine!='0'){
				window.document.location.href=chaine;
			}else{
				document.getElementById('noresult').className='visible';
			};
		};
	};
	_xmlhttp.send(null);
};

function search_result_advanced(){
	ville_location=document.getElementById('ville_location').value;
	nb_pers_location=document.getElementById('nb_pers_location').value;
	tarif=document.getElementById('tarif').value;
	jardin=document.getElementById('check0').checked;
	vue_mer=document.getElementById('check1').checked;
	internet=document.getElementById('check2').checked;
	lave_vaisselle=document.getElementById('check3').checked;
	mobilite_reduite=document.getElementById('check4').checked;
	
	_xmlhttp=getXMLHTTP();
	chaine="index_search_result_advanced.php?ville_location="+ville_location+"&nb_pers_location="+nb_pers_location+"&tarif="+tarif+"&jardin="+jardin+"&vue_mer="+vue_mer+"&internet="+internet+"&lave_vaisselle="+lave_vaisselle+"&mobilite_reduite="+mobilite_reduite;
	_xmlhttp.open("GET",chaine,true);
	_xmlhttp.onreadystatechange=function(){
		if (_xmlhttp.readyState == 4){ /* 4 : état "complete" */
			chaine=_xmlhttp.responseText;
			if(chaine!='0'){
				window.document.location.href=chaine;
			}else{
				document.getElementById('noresult').className='visible';
			};
		};
	};
	_xmlhttp.send(null);
};

function search_result_advanced2(){
	ville_location=document.getElementById('ville_location2').value;
	nb_pers_location=document.getElementById('nb_pers_location2').value;
	date_debut=document.getElementById('date_debut').value;
	date_fin=document.getElementById('date_fin').value;
	
	_xmlhttp=getXMLHTTP();
	chaine="index_search_result_advanced2.php?ville_location="+ville_location+"&nb_pers_location="+nb_pers_location+"&date_debut="+date_debut+"&date_fin="+date_fin;
	_xmlhttp.open("GET",chaine,true);
	_xmlhttp.onreadystatechange=function(){
		if (_xmlhttp.readyState == 4){ /* 4 : état "complete" */
			chaine=_xmlhttp.responseText;
			if(chaine!='0'){
				window.document.location.href=chaine;
			}else{
				document.getElementById('noresult2').className='visible';
			};
		};
	};
	_xmlhttp.send(null);
};

function string_replace(string){
	separator="-";
	tofind="àáâãäåòóôõöøèéêëçìíîïùúûüÿñ";
	replac="aaaaaaooooooeeeeciiiiuuuuyn";
	string=string.toLowerCase();
	string=string.replace(tofind,replac);
	tofind2="[^a-z0-9]";
	string=string.replace(tofind2,separator);
	while(string.search(separator+separator)!=-1){
		string=string.replace(separator+separator,separator);
	};
	return string;
};

// Survol cartes
function carte_regions_over(region,region_nom,text_annonces,text_no_annonces,text_annonce){
	_xmlhttp=getXMLHTTP();
	chaine="carte-de-france-search.php?region="+region;
	_xmlhttp.open("GET",chaine,true);
	_xmlhttp.onreadystatechange=function(){
		if (_xmlhttp.readyState == 4){ /* 4 : état "complete" */
			chaine=_xmlhttp.responseText;
			text='<p style="font-size:11px;font-weight:bold;">'+region_nom+'</p><p style="font-size:10px;color:#00A0C6;">';
			if(chaine!='0'){
				if(chaine==1){
					text+=chaine+' '+text_annonce;
				}else{
					text+=chaine+' '+text_annonces;
				};
			}else{
				text+=text_no_annonces;
			};
			text+='</p>';
			BulleWrite(text);
		};
	};
	_xmlhttp.send(null);
};

function carte_dep_over(region,region_nom,text_annonces,text_no_annonces,text_annonce){
	_xmlhttp=getXMLHTTP();
	chaine="recherche-carte-region-search.php?departement="+region;
	_xmlhttp.open("GET",chaine,true);
	_xmlhttp.onreadystatechange=function(){
		if (_xmlhttp.readyState == 4){ /* 4 : état "complete" */
			chaine=_xmlhttp.responseText;
			text='<p style="font-size:11px;font-weight:bold;">'+region_nom+'</p><p style="font-size:10px;color:#00A0C6;">';
			if(chaine!='0'){
				if(chaine==1){
					text+=chaine+' '+text_annonce;
				}else{
					text+=chaine+' '+text_annonces;
				};
			}else{
				text+=text_no_annonces;
			};
			text+='</p>';
			BulleWrite(text);
		};
	};
	_xmlhttp.send(null);
};

function carte_ville_over(region,region_nom,text_annonces,text_no_annonces,text_annonce){
	_xmlhttp=getXMLHTTP();
	chaine="carte-du-finistere-search.php?ville="+region;
	_xmlhttp.open("GET",chaine,true);
	_xmlhttp.onreadystatechange=function(){
		if (_xmlhttp.readyState == 4){ /* 4 : état "complete" */
			chaine=_xmlhttp.responseText;
			text='<p style="font-size:11px;font-weight:bold;">'+region_nom+'</p><p style="font-size:10px;color:#00A0C6;">';
			if(chaine!='0'){
				if(chaine==1){
					text+=chaine+' '+text_annonce;
				}else{
					text+=chaine+' '+text_annonces;
				};
			}else{
				text+=text_no_annonces;
			};
			text+='</p>';
			BulleWrite(text);
		};
	};
	_xmlhttp.send(null);
};

function carte_out(){
	BulleHide();
};

// Modules photos location
// Affichage d'une photo
function affichage(id,arret,debut,auto){
	// Recherche de l'index du tableau
	for(i=0;i<nb_images;i++){
		if(tab_images[7][i]==id){// si c'est cette image qui est choisie
			// Effet transition
			/*var change_ok=1;
			if(auto==1){
				if(debut==0){
					toggle_appear(1);// apparaitre
				};
				timer_effet=setTimeout("toggle_appear(0)",delai_effet);// disparaitre
			}else{
				// on fait apparaitre l'imga esi elle est disparu quand c pas en auto
				if(effet_en_cours==0){
					if(image_visible==0){
						toggle_appear(1);// apparaitre
					};
				}else{
					change_ok=0;
				};
			};*/
			
			//if(change_ok==1){
				// Photo courante
				pho_courante=i;
				
				// On met toutes les miniatures en class normale
				for(h=0;h<nb_images;h++){
					document.getElementById('img_'+tab_images[7][h]).className='normal';
				};
				
				// On recupere les valeurs encodés
				desc=tab_images[5][i];
				desc=unescape(desc);
				desc=desc.replace(/[+]/g," ");
				document.getElementById('photo_desc').innerHTML = desc;
				titre=tab_images[6][i];
				titre=unescape(titre);
				titre=titre.replace(/[+]/g," ");
				document.getElementById('photo_titre').innerHTML = titre;
				
				// On affiche l'image normal
				var big_photo=document.getElementById('big_pict');
				big_photo.alt=titre;
				big_photo.title=titre;
				big_photo.src=tab_images[0][i];
				big_photo.width=tab_images[1][i];
				big_photo.height=tab_images[2][i];
				
				// On change le lien de l'image
				var width_grand=tab_images[3][i];
				var height_grand=tab_images[4][i];
				document.getElementById('photo_lien').onclick=function(){
					popup_open('locations-details-photos-popup.php?photo='+id,width_grand,height_grand);
				};
				
				// On met cette miniture entouré de rouge
				document.getElementById('img_'+id).className='select';
			//};
		};
	};
	if(arret==1){
		clearTimeout(timer);
	};
};

// Effet transition Photo
function toggle_appear(result){
	effet_en_cours=1;
	setTimeout("effet_fin()",delai_en_cours);
	Effect.toggle('big_pict','appear');
	image_visible=result;
};

// Fin effet
function effet_fin(){
	effet_en_cours=0;
};

// Préchargement des photos
function prechargement(){
	document.image_chargee = new Array();
	for(i=0;i<nb_images;i++){
		document.image_chargee[i] = new Image;
		document.image_chargee[i].src = tab_images[0][i];
	};
};

// Photo précédente
function photo_precedente(){
	var num=0;
	num=pho_courante-1;
	if(num<0){
		num=nb_images-1;
	};
	affichage(tab_images[7][num],1,0,0);
};

// Photo suivante
function photo_suivante(){
	var num=0;
	num=pho_courante+1;
	if(num>(nb_images-1)){
		num=0;
	};
	affichage(tab_images[7][num],1,0,0);
};

// Photo scroll auto
function photo_scroll_auto(i,debut){
	affichage(tab_images[7][i],0,debut,1);
	if(i<(nb_images-1)){
		i++;
	}else{
		i=0;
	};
	timer=setTimeout("photo_scroll_auto("+i+",0)",delai);
};

// Arrete le scroll
function arret_scroll_auto(){
	clearTimeout(timer);
	//clearTimeout(timer_effet);
};

//////// Fin Module photo /////////

function confirm_suppression(text,href){
	a=confirm(text);
	if(a){
		window.document.location.href=href;
	};
};

function overarea(){
	var name = navigator.appName;
	if (name == "Microsoft Internet Explorer"){
		document.body.style.cursor='hand';
	};
};
function outarea(){
	var name = navigator.appName;
	if(name == "Microsoft Internet Explorer"){
		document.body.style.cursor='default';
	};
};







