function oninit(){
  initMoteur();
  //corrigePNGAvecIE6();
}

window.urlListe="hotel/liste.html";

function envoiMailNewletter(){
  envoiMailByAjaxByForm('frm_newsletter','div_frmNews',false);
}

function initMoteur(){
  if($("div_moteurRecherche")){  
    $$(".affMoteurHeb").each( function(obj){obj.observe("click",affMoteurHeb);} );
    $$(".affMoteurSejour").each( function(obj){obj.observe("click",affMoteurSej);} );
    $$(".affMoteurAct").each( function(obj){obj.observe("click",affMoteurAct);} );
    
    setActionSurOngletMoteur();
    
    if ($("div_calendGite")) setCalendrierGeneral("gites13","1","","G","div_calendGite",clicCalendJsMoteur,"inpt_dateDeb","","","lst_nbjG","1","");
    if ($("div_calendChambre")) setCalendrierGeneral("gites13","1","","H","div_calendChambre",clicCalendJsMoteur,"inpt_dateDeb","","","lst_nbjCh","1","");
    if ($("calendrierMoteurSej")) setCalendrierGeneral("gites13","1","","","calendrierMoteurSej",clicCalendJsMoteurSej,"inpt_dateDebSej","","","nbj_sej","1","");
    if ($("calendrierMoteurAct")) setCalendrierGeneral("gites13","1","","","calendrierMoteurAct",clicCalendJsMoteurAct,"inpt_dateDebAct","","","nbj_Act","1","");
    initAProximiteDe();
  }
}

function initAProximiteDe(){
	//LISTALLVILLE_GP
	appelAjaxToFunc("/lib/ajax/infosCGI.php","typeInfo=LISTALLCHLIEU_GL",function(reponse){
			var lst=new String(reponse).evalJSON();
			if (!lst || !lst.length)return;
			var selected=0;
			for (var i=0;i<lst.length;i++){
				if (lst[i]==$("inpt_libcheflieu").value)selected=i+1;
				$("sel_chpAProximiteDeGL").insert("<option>"+lst[i]+"</option>");
			}
			$("sel_chpAProximiteDeGL").selectedIndex=selected;

		}
	);
	appelAjaxToFunc("/lib/ajax/infosCGI.php","typeInfo=LISTALLVILLE_GP&VAL=HOTEL",function(reponse){
			var lst=new String(reponse).evalJSON();
			if (!lst || !lst.length)return;
			var selected=0;
			for (var i=0;i<lst.length;i++){
				if (lst[i]==$("inpt_libville").value)selected=i+1;
				$("sel_chpAProximiteDeGP").insert("<option>"+lst[i]+"</option>");
			}
			$("sel_chpAProximiteDeGP").selectedIndex=selected;
		}
	);


}


function affMoteurHeb(){
  $("moteurHebergement").style.display="block";
  $("moteurSejours").style.display="none";
  $("moteurActivites").style.display="none";
  ongletGite();
}
function affMoteurSej(){
  $("moteurHebergement").style.display="none";
  $("moteurSejours").style.display="block";
  $("moteurActivites").style.display="none";
}
function affMoteurAct(){
  $("moteurHebergement").style.display="none";
  $("moteurSejours").style.display="none";
  $("moteurActivites").style.display="block";
}

function selectLabel(){
  if(($("check_cleva").checked)&&($("check_gdf").checked)) $("inpt_base").value="CLEVA,GFRAN";
  else if(($("check_cleva").checked)&&(!$("check_gdf").checked)) $("inpt_base").value="CLEVA";
  else if((!$("check_cleva").checked)&&($("check_gdf").checked)) $("inpt_base").value="GFRAN";
}

function ongletHotel(){
  $("inpt_urlListe").value="/hotel/liste.html";
  $("lst_nbjG").style.display="none";
  $("lst_nbjCh").style.display="block";  
  $("div_calendGite").style.display="none";
  $("div_calendChambre").style.display="block";
  $("div_proxGl").style.display="none";
  $("div_proxGp").style.display="block";
  setClassForObj($("sp_ongletMoteurHotel"),"ongletMoteurHebOn");
  setClassForObj($("sp_ongletMoteurCh"),"ongletMoteurHeb");
  setClassForObj($("sp_ongletMoteurGite"),"ongletMoteurHeb");
  $("inpt_hideNbj").value=$("lst_nbjCh").value;
  $("div_labels").style.display="none";
}
function ongletGite(){
  $("inpt_urlListe").value="/location/liste.html";
  $("lst_nbjCh").style.display="none";
  $("lst_nbjG").style.display="block";
  $("div_calendGite").style.display="block";
  $("div_calendChambre").style.display="none";
  $("div_proxGl").style.display="block";
  $("div_proxGp").style.display="none";
  setClassForObj($("sp_ongletMoteurHotel"),"ongletMoteurHeb");
  setClassForObj($("sp_ongletMoteurCh"),"ongletMoteurHeb");
  setClassForObj($("sp_ongletMoteurGite"),"ongletMoteurHebOn");
  $("inpt_hideNbj").value=$("lst_nbjG").value;
  $("div_labels").style.display="block";
}
function ongletChambre(){
  $("inpt_urlListe").value="/chambre/liste.html";  
  $("lst_nbjG").style.display="none";
  $("lst_nbjCh").style.display="block";
  $("div_calendGite").style.display="none";
  $("div_calendChambre").style.display="block";
  $("div_proxGl").style.display="block";
  $("div_proxGp").style.display="none";
  setClassForObj($("sp_ongletMoteurHotel"),"ongletMoteurHeb");
  setClassForObj($("sp_ongletMoteurCh"),"ongletMoteurHebOn");
  setClassForObj($("sp_ongletMoteurGite"),"ongletMoteurHeb");
  $("inpt_hideNbj").value=$("lst_nbjCh").value;
  $("div_labels").style.display="block";
}
function setActionSurOngletMoteur(){
   $("sp_ongletMoteurHotel").onclick=function (evt){ongletHotel();}
   $("sp_ongletMoteurCh").onclick=function (evt){ongletChambre();}
   $("sp_ongletMoteurGite").onclick=function (evt){ongletGite();}
}

function changeNbj(obj){
  $("inpt_hideNbj").value=obj.value;
}

function lanceRechercheHeb(){
  document.location.href=$("inpt_urlListe").value+"?"+getQueryStringByForm($("frm_hebergements"));
}
function lanceRechercheSejours(){
  document.location.href='/sejour/liste.html?'+getQueryStringByForm($("frm_sejours"));
}
function lanceRechercheActivites(){
  document.location.href='/billet/liste.html?'+getQueryStringByForm($("frm_activites"));
}

// Calendrier JS
function afficheEffaceCalendJs(nomDiv){
  if($(nomDiv).showing==true){
    Effect.BlindUp(nomDiv,{"duration":0.4});       
    $(nomDiv).showing=false;
  }
  else{
    Effect.BlindDown(nomDiv,{"duration":0.6});       
    $(nomDiv).showing=true;
  }
}
function clicCalendJsMoteur(evt,jour,mois,annee,etat){
  $("inpt_dateDeb").value=jour+"/"+mois+"/"+annee;
  afficheEffaceCalendJs("calendrierMoteurHeb");
}
function clicCalendJsMoteurSej(evt,jour,mois,annee,etat){
  $("inpt_dateDebSej").value=jour+"/"+mois+"/"+annee;
  afficheEffaceCalendJs("calendrierMoteurSej");
}
function clicCalendJsMoteurAct(evt,jour,mois,annee,etat){
  $("inpt_dateDebAct").value=jour+"/"+mois+"/"+annee;
  afficheEffaceCalendJs("calendrierMoteurAct");
}


function clickMdpOubliCompteClient(){
	$("inpt_password_client").hide();
	$("a_passwd_oublie").hide();
	$("pCptCli_msg").innerHTML="Veuillez saisir l'adresse mail correspondant au compte enregistr&eacute; :";
	$("pCptCli_msg").addClassName("msgErreur");
	$("bt_okCptCli").onclick=function(evt){
                $("pCptCli_msg").innerHTML="Recherche en cours...";
		var email=$("inpt_login_client").value;
		var params={};
		params.expediteur="resa13@visitprovence.com";
		params.foncFin=function(retour){
			var msg;
			if (retour=="KO")msg="L'email saisi n'a pu etre retrouv&eacute;.";
			else msg="Un mail avec le mot de passe a &eacute;t&eacute; envoy&eacute; &aacute; l'adresse saisie.";
	                $("pCptCli_msg").innerHTML=msg;
        	        $("pCptCli_msg").addClassName("msgErreur");
			$("inpt_password_client").show();
			$("bt_okCptCli").onclick=clickOkCompteClient;
		}
		verifMailEtEnvoiMotDePasse(email,params);
	}
	
}

function clickOkCompteClient(){
	var login=$("inpt_login_client").value;
	var pass=$("inpt_password_client").value;
	
	if (!login || !pass){
		$("pCptCli_msg").innerHTML="Vous devez saisir un email et un mot de passe dans chacun des champs ci dessous";
		$("pCptCli_msg").addClassName("msgErreur");
	}
	else{

		var params={};
	
		params.foncAffichageOk=function(infosCli){
			var lnk="http://reservation.visitprovence.com/";
			if (infosCli.typeResa=="GL")lnk+="GL/cpt_clientLCEN.php?CMD=ACCES_LISTERESA&email="+login+"&MDP="+pass;
			if (infosCli.typeResa=="GP")lnk+="GP/compte_client.php?INPT_LOGIN="+login+"&INPT_PASSWORD="+pass;
	
			var html="<div id=cptClientConnecte>Bonjour "+infosCli.prenomclient+" "+infosCli.nomclient+", ";
			html+="Vous pouvez acc&eacute;der &agrave; vos r&eacute;servation en cliquant <a href='"+lnk+"'>ici</a>";
			$("div_menuCptCli").innerHTML=html;	
			location.href=lnk;
		}
		params.foncAffichageKo=function(infos){
	                $("pCptCli_msg").innerHTML=infos.msg;
        	        $("pCptCli_msg").addClassName("msgErreur");
		}

		verifInfosClientByLogin(login,pass,params);
	}
}

function verifSaisieRappel(){
  if(($("inpt_numRappel").value=='')||($("inpt_numRappel").value=='Votre numéro')) alertAMalibu("Vous devez saisir votre num&eacute;ro afin que nous puissions vous rappeler.");
  else envoiMailByAjaxByForm('frmRappel','div_rappelImmediat',false);
}


