

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// verifie la validite d'un email
function validemail(champ)
{
	
	
	var email = document.getElementById(champ);
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (!filter.test(email.value)) 
	{
	 	alert(get_trad_champ("email"));
		email.focus
		return false;
	}
	else
	{
		return true;
	}
}

// verifie les champs obligatoire d'un formulaire
valider_formulaire = function () {
	var tab = valider_formulaire.arguments;

	taille = tab.length;

	for (i=0;i<taille;i++) {
		if (tab[i]=="email") {
			if (!validemail(tab[i])) {
				return 0; 
			}
		}else{
			if ((document.formulaire.elements[tab[i]].value=="") || (document.formulaire.elements[tab[i]].value==" ")) {
				str_temp = tab[i].replace(/_/g," ");
				alert(get_trad_champ(str_temp));
				return 0; 
			}
		}
	}
	
	document.formulaire.submit();
}

function empechechar()
{
	if( event.keyCode < 48 || event.keyCode > 57 )
 	{ 
 		alert(get_trad_champ("numeric") );
   		event.returnValue = false;
   	}
}

// fonction qui fait apparaitre le sablier sur soumission de formulaire un peu long..

// Variable témoin de la validation effectuée ou pas


function valider(nom_form) {

  deja = 1;
	if ( deja == 0 ) {

		deja = 1;					
		document.body.className = 'sablier';		
		eval('document.'+nom_form+'.submit()');
	} 
}

function show_sablier()
{
	document.body.className = 'sablier';
}


// verifie les champs obligatoire d'un formulaire
verif_formulaire_nom = function () {
	var tab = verif_formulaire_nom.arguments;
	var nom_form = "formulaire";
	
	taille = tab.length;

	if (taille>0)
	{
		nom_form = tab[0];
	}	

	for (i=1;i<taille;i++) {
		if (tab[i]=="email") {
			if (!validemail(tab[i])) {
				return 0; 
			}
		}else{
	
			if ((document.getElementById(tab[i]).value=="")  || (document.getElementById(tab[i]).value==" ")) {
				//str_temp = tab[i].replace(/_/g," ");
				str_temp = tab[i];
				alert(get_trad_champ(str_temp));
				return 0; 
			}
		}
	}
	
	return true
}



function goto_url(URL_page)
{
	window.location.href = URL_page;	
}

function changeSearchPage(_index)
{  
	if(document.getElementById("force_search_page")) document.getElementById("force_search_page").value = _index;
		
	document.getElementById("search_page_pagination").value = _index;
}

function submitPagination(index)
{
	document.getElementById("page").value=index;
	document.getElementById("paginationForm").submit();
}


/* Fonctions génériques de validation de formulaire */
// Verifie la validite d'un email
function valide_mail_generique ( nameForm, champ ) {
	
	var email = document.forms[nameForm].elements[champ];
		
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	
	if ( !filter.test(email.value) ) {
		
	 	alert(get_trad_champ("email"));
		email.focus();
		return false;
	}
	else {
		return true;
	}
}


// Verifie les champs obligatoire d'un formulaire
valider_formulaire_generique = function () {
	var tab = valider_formulaire_generique.arguments;

	taille = tab.length;

	if ( taille > 0 ) {

		nameForm = tab[0];
		
		for ( i = 1; i < taille; i++ ) {
			
			if ( tab[i] == "email" ) {
				if ( !valide_mail_generique( nameForm, tab[i] ) ) {
					return false; 
				}
			}
			else {
				if ( ( document.forms[nameForm].elements[tab[i]].value.trim() == "" ) ) {				
					alert ( get_trad_champ( tab[i] ) );				
					document.forms[nameForm].elements[tab[i]].focus();
					return false; 
				}
			}
		}
		
		return true;
		
	}
	else {
		return false;
	}
}
/* Fonctions génériques de validation de formulaire */

function validContact() {
	if ( valider_formulaire_generique('formContact', 'nom', 'prenom', 'pays', 'email', 'sujet', 'message') ) {				
		document.getElementById('formContact').submit();					
	}
	else {
		return false;
	}		
}


function validFormTo() {
	if ( valider_formulaire_generique('formFormulaireTo', 'agence', 'nom', 'prenom', 'fonction', 'langue', 'licence', 'adresse', 'cp', 'ville', 'pays', 'telephone', 'telecopie', 'email', 'sujet') ) {				
		document.getElementById('formFormulaireTo').submit();					
	}
	else {
		return false;
	}		
}


function isValidDate ( _fieldId )
{
    if ( _fieldId == "" )
        return true;

    // Récupération de la valeur
    var totalDate    = document.getElementById( _fieldId ).value;
    if ( totalDate == "" )
        return false;
    
    // Découpage de la date récupérée
    var aDate = totalDate.split( "/" );
    if ( aDate.length != 3 )
        return false;

    // Création d'un objet date
    var generatedDate = new Date ( aDate[ 2 ], aDate[ 1 ] - 1, aDate[ 0 ] );
    
    // Test
    if (     generatedDate.getFullYear() == aDate[ 2 ]
        &&    generatedDate.getMonth() + 1 == aDate[ 1 ]
        &&    generatedDate.getDate() == aDate[ 0 ] )
        return true;
    
    return false;
}


// L'email du bloc newsletter est valide ?
function checkEmailNewsletter ( cgi_news_url,nameForm,sRedirectionOk,sRedirectionKo,sWebUser ) {
	if ( valider_formulaire_generique(nameForm, 'email') ) 
	{
				var url_newsletter = cgi_news_url + "?actions=register&tokens=ignore_token&webuser="	 + sWebUser + "&redirect_ok=" + sRedirectionOk + "&redirect_ko=" + sRedirectionKo + "&emaillogin=" + encodeURI(document.getElementById('email').value)  + "&password=news&Nom=&Prenom=&stat_NEWS_combo=1" ;
				//alert(url_newsletter);
        document.location.href = url_newsletter;				
	}
	else {
		return false;
	}
}

// Verifie la validité du champ email du bloc newsletter
function checkEmailDemandeMagazine ( nameForm ) {
	if ( valider_formulaire_generique(nameForm, 'email') ) {
		document.forms[nameForm].submit();
	}
	else {
		return false;
	}
}


//function set_langue

function set_langue(id_langue,action_url)
{
  document.getElementById('L').value = id_langue;
  document.getElementById('form_langue').action = action_url;    
  //alert(document.getElementById('form_langue').action);
  //alert(document.getElementById('L').value);
  document.getElementById('form_langue').submit();   
}

function set_saison(id_saison)
{
  document.getElementById('id_saison').value = id_saison;        
  document.getElementById('form_saison').submit();    
}

//ajout a la selection
function addtoSelection(idEtab,errorMsg){
  $.ajax({
    type: "POST",
	data: "id="+idEtab,
	url: "ajax/ajax_add_selection.php",
	success: function(msg){
		
      if(msg != "" && msg != "tooMuchResultAdded"){
        //on affiche le nombre de selections
        document.getElementById("nbselections").innerHTML = "("+msg+")";

        //surbrillance de l'icone selections
        $("#li_selections").animate({height : "250px"},1500);


      }else{
      	if(msg == "tooMuchResultAdded"){
      		alert(errorMsg);
      	}
      	return false;
      }
    }
 });	
	
}

//retrait de la selection
function removeFromSelection(idEtab,no_more_item_in_selection){
	var tds = document.getElementsByTagName('td');
	for(var i=1;i<8;i++){
		document.getElementById("fullCell_"+i+"_"+idEtab).innerHTML = "";
		document.getElementById("fullCell_"+i+"_"+idEtab).style.display = "none";
		document.getElementById("emptyCell_"+i+"_"+idEtab).innerHTML = "";
		document.getElementById("emptyCell_"+i+"_"+idEtab).style.display = "none";
	}
	$.ajax({
	    type: "POST",
		data: "id="+idEtab,
		url: "ajax/ajax_remove_selection.php",
		success: function(msg){
			document.getElementById("nbselections").innerHTML = "("+msg+")";
			if(msg == "0"){
			   document.getElementById("compare_table").innerHTML = no_more_item_in_selection; 
			   document.getElementById("legend").innerHTML = ""; 
			}
		}
	});	
}

// comparateur
// semaine < > nuit
function modifTypeTarif(idEtab,value,a_partir_de,text_no_tarifs){
  document.getElementById("type_tarifs_hidden_"+idEtab).value = value;
  var saison = document.getElementById("real_saison").value;
	$.ajax({
	    type: "POST",
		data: "value="+value+"&id="+idEtab+"&saison="+saison,
		url: "ajax/ajax_switch_tarifs.php",
		success: function(msg){
			var div = document.getElementById("tarifs_"+idEtab);
			div.innerHTML = "";
			if(msg != ""){
				var newTarifs = msg.split("###");
				for(var i=0; i<newTarifs.length; i++){
					varTabTarif = newTarifs[i].split("=");
					var aDivTarif = document.createElement('li');
					aDivTarif.innerHTML = "<strong>"+varTabTarif[0]+"</strong><br>"+a_partir_de+"<span> "+varTabTarif[1]+"&euro;</span>";
					if(i%2 == 0) aDivTarif.className = "even";
					div.appendChild(aDivTarif);
				}
			}else{
				div.innerHTML = '<br><div style="margin-left:5px">'+text_no_tarifs+'</div><br><br>';
			}
		}
	});			
}

// comparateur
// ete < > hiver
function changeSaison(saison,a_partir_de){
    var real_saison = document.getElementById("real_saison").value;
    if(saison != real_saison){
      real_saison == "hiver" ? document.getElementById("real_saison").value = 'ete' : document.getElementById("real_saison").value = 'hiver';
      var allIDS = document.getElementById("allIDS").value;
      allIDS = allIDS.split("_");
      var postType = "";
      for(var i=0; i<allIDS.length; i++){
         postType += "&type"+allIDS[i]+"="+document.getElementById("type_tarifs_hidden_"+allIDS[i]).value;
      }

  		$.ajax({
  		  type: "POST",
  			data: "saison="+saison+postType,
  			url: "ajax/ajax_switch_saison.php",
  			success: function(msg){

  				if(saison == "ete"){
  					$("#link_hiver").removeClass("active");
  					$("#link_ete").addClass("active");	
  				}else{	
  					$("#link_hiver").addClass("active");
  					$("#link_ete").removeClass("active");							
  				}
  				
  				var residences = msg.split("###");
  				var nbHebRes = null;
  				var allHeb = null;
  				var divTarifs = null;
  				for(var i=0; i<residences.length; i++){
  					var aRes = residences[i].split("+++");
  					var idRes = aRes[0];
  					
  					//vignette
  					var srcVignRes = aRes[1];
  					$("#fullCell_2_"+idRes).attr("src",srcVignRes);
  					
  					//argumentaire
  					var argRes = aRes[2];
  					$("#fullCell_3_"+idRes).html(argRes);			
  					
  					//activites
  					var actiRes = aRes[3];
  					$("#fullCell_4_"+idRes).html(actiRes);
  					
  					//tarifs
  					nbHebRes = aRes[4];
  					allHeb = aRes[5];
  					
  					divTarifs = document.getElementById("tarifs_"+idRes);
  					divTarifs.innerHTML = "";
  					if(allHeb){
  						var newTarifs = allHeb.split("@@@");
  						for(var j=0; j<newTarifs.length; j++){
  							varTabTarif = newTarifs[j].split("=");
  							var aDivTarif = document.createElement('li');
  							aDivTarif.innerHTML = "<strong>"+varTabTarif[0]+"</strong><br />"+a_partir_de+"<span> "+varTabTarif[1]+"&euro;</span>";
  							if(j%2 == 0) aDivTarif.className = "even";
  							divTarifs.appendChild(aDivTarif);
  						}
  					}else{
  						
  					}
  				}
  	
  			}
  		});	
    }
}

//agenda
//recherche des etablissements a proximite
function search_nearest_resids(params){
  document.getElementById("nb_night").value = "";
  document.getElementById("search_form_etab_list").value = params;
}

function verif_date(totalDate,field_id)
{
    if (totalDate == "") 
    {
      return true;
    }    
        
    else    
    {

		   if ( document.getElementById("nb_night") && document.getElementById("nb_night").value == "" ) 
	     {
	    	alert(get_trad_champ('saisir_nbr_nuits'));
	    	return false;
	     }
		
   		isIE6 = navigator.userAgent.toLowerCase().indexOf('msie 6') != -1;    	    	 												
			 
		   if (isIE6)
			 {								 				 				    
 				   if( document.getElementById("nb_pers_input") && document.getElementById("nb_pers_input").value == "------") 
			     {
			    	alert(get_trad_champ('saisir_nbr_personnes'));
			    	return false;
			     }else{
			     			document.getElementById("search_form").search_form_nb_adults.value = document.getElementById("nb_pers_input").value;		
			    	}


			 }
		   
		   else 
		   {			   		   
		   		
				   if( document.getElementById("nb_pers") && document.getElementById("nb_pers").value == "") 
			     {
			    	alert(get_trad_champ('saisir_nbr_personnes'));
			    	return false;
			     }
    	 }
    	 
      // Découpage de la date récupérée
      var aDate = totalDate.split( "/" );
          
      if ( aDate.length != 3 )
      {          
          alert(get_trad_champ('saisir_date_valide'));
          return false;
      }
  
      if (isValidDate(totalDate))
      {          
          return true;
      }else{
          alert(get_trad_champ('saisir_date_valide'));          
          document.getElementById(field_id).value = "";                  
          return false;
      }
    }
    
}

function set_nb_pers(val)
{		
	document.getElementById("nbre_de_personnes").value = val;	
	document.getElementById("search_form").search_form_nb_adults.value = val;	
	
	//document.getElementById("nb_pers").value = val;
}

function isValidDate(d) {
    var dateRegEx = /^((((0?[1-9]|[12]\d|3[01])[\.\-\/](0?[13578]|1[02])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|[12]\d|30)[\.\-\/](0?[13456789]|1[012])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|1\d|2[0-8])[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|(29[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00)))|(((0[1-9]|[12]\d|3[01])(0[13578]|1[02])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|[12]\d|30)(0[13456789]|1[012])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|1\d|2[0-8])02((1[6-9]|[2-9]\d)?\d{2}))|(2902((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00))))$/;
    return d.match(dateRegEx);
}


function addTypeDestination(typeDestination)
{
	  
  //var aTypesDestination = document.getElementById("typesDestination").value.split(',');
    
  //alert('typesDestination = ' + document.getElementById("typesDestination").value);
  
  var aTypesDestination = document.getElementById("param_type_destination").value.split(',');
	var sNewTypesDestination = '';
	var i = 0;
	var found = false; 
	
	for(i = 0; i < aTypesDestination.length; i++)
	{
		if(aTypesDestination[i] != typeDestination)
		{
			if(sNewTypesDestination != '')
			{
				sNewTypesDestination += ',';
			}
			sNewTypesDestination += aTypesDestination[i];
		}
		else
		{
			found = true;
		}
	}
	if (! found)
	{
		if(sNewTypesDestination != '')
		{
			sNewTypesDestination += ',';
		}
		sNewTypesDestination += typeDestination;
	}
	
	//alert(sNewTypesDestination);
	
	document.getElementById("typesDestination").value = sNewTypesDestination;
	document.getElementById("param_type_destination").value = sNewTypesDestination;
}

function filter_search()
{
	//recuperation des types de destination coches et des regions et stations selectionnees
	var typesDestination = '';
	if(document.getElementById('typesDestination'))
	{
		typesDestination = document.getElementById('typesDestination').value;
	}
	var region = document.getElementById('recherche_region').value;
	var station = document.getElementById('recherche_station').value;
	
	
	$.ajax({
		type: "POST",
		data: "region="+region+"&typesDestination="+typesDestination,
		url: "ajax/ajax_filter_search.php",
		success: function(msg){
						
		      	if(msg != ""){
		        	
		        	
		        	var result = msg.split('|');
		        	if(result.length == 3)
		        	{
		        		//Traitement des regions
		        		var aRegions = result[1].split(':');
		        		if(!display_search_selectbox(aRegions[0],aRegions[1].split(','),region))
		        		{
		        			document.getElementById('recherche_region').value = '';
		        		}
		        		
		        		//Traitement des destinations
		        		var aDestinations = result[2].split(':');
		        		if(!display_search_selectbox(aDestinations[0],aDestinations[1].split(','),station))
		        		{
		        			document.getElementById('recherche_station').value = '';
		        		}
		        				        		
		        	}
			
			}
			return false;
	      	}
	    
	 });	
}

function display_search_selectbox(idSelectBox,optionList,defaut)
{
	var found = false;
	
	var selectObject = document.getElementById(idSelectBox);
	if(selectObject)
	{
		//Vide la liste
		while ( selectObject.options.length > 1) {
    					
    			selectObject.options[1] = null;
		}
		if(optionList.length > 0 && optionList!= '')
		{
			for(var i=0; i < optionList.length; i++) {
		 			
				var tabOption = optionList[i].split('##');
				var oOption = document.createElement("OPTION");
			   	oOption.text= tabOption[1];
			   	oOption.value= tabOption[0];
			   		
			   	if(defaut == tabOption[0])
			   	{
			   		oOption.selected=true;
			   		found = true;
			   	}	
			   					
	   			if(jQuery.browser.msie)
	   			{	   			
	   				selectObject.add(oOption);
	   			}
	   			else
	   			{
	   				selectObject.appendChild(oOption);
	   			}
			}
			
		}
		
		//Regeneration du code JQUERY de la station
		 document.getElementById(idSelectBox+'_input').parentNode.removeChild(document.getElementById(idSelectBox+'_input'));
		 document.getElementById(idSelectBox+'_container').parentNode.removeChild(document.getElementById(idSelectBox+'_container')); 			
		 $('#'+idSelectBox).selectbox({ containerClass: 'selectbox-wrapper '+idSelectBox});
	}
	
	return found;
}


function submit_form_prix_et_dispo()
{
    document.getElementById("form_prix_et_dispo").action = document.getElementById("input_prix_et_dispo_url").value + '#ancre_tarif';    
    document.getElementById("form_prix_et_dispo").submit();
}


function add_favoris(site_url) {

if ( navigator.appName != 'Microsoft Internet Explorer' )
{ 
  window.sidebar.addPanel("Location RESIDHOTEL",site_url,""); 
}
else 
{ 
  window.external.AddFavorite(site_url,"Location RESIDHOTEL"); 
} 

} 



function submit_form_envoi_ami()
{


	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

  if (document.getElementById("votre_nom").value == "")
  {
      alert(get_trad_champ("nom"));
      return false;  
  } 

  if (document.getElementById("nom_ami").value == "")
  {
      alert(get_trad_champ("nom_ami"));
      return false;  
  } 

  if ( document.getElementById("votre_email").value == "" || !filter.test(document.getElementById("votre_email").value) )
  {
      alert('Votre Email : ' + get_trad_champ("email"));
      return false;  
  }
   
  if ( document.getElementById("email_ami").value == "" || !document.getElementById("email_ami").value )
  {
      alert('Email de votre ami : ' + get_trad_champ("email"));  
      return false;
  } 

  document.getElementById("envoi").value ="2" ;
  document.getElementById("form_envoi_ami").submit();
  
}

/*Ajouter par wil - résidhotel*/

function Valider(){
var done=0;
var password=document.login.password.value;
password=password.toLowerCase();
if (password=="pvazurea0609") { window.location="pdf/proces_verbal_constat.pdf"; done=1; }
if (done==0) { alert("Veuillez entrer votre mot de passe."); }
}

function Valid(){
var done=0;
var password=document.entrer.password.value;
password=password.toLowerCase();
if (password=="barjac") { window.location="pdf/rapport_solidite.pdf"; done=1; }
if (done==0) { alert("Veuillez entrer votre mot de passe."); }
}

/*fin*/	


