/**** SEARCH RESULTS.JS ****/

//lien etablissement depuis bloc resultat de recherche
function submitFormEtab(sAction, sIndex)
{
	showPleaseWait();
	
	document.getElementById('infosEtab').action = sAction ;
	document.getElementById('minPrice').value = document.getElementById('minPrice_'+sIndex).value ;	
	document.getElementById('minPriceWithoutDiscounts').value = document.getElementById('minPriceWithoutDiscounts_'+sIndex).value ;	
	document.getElementById('startDate').value = document.getElementById('startDate_'+sIndex).value ;	
	document.getElementById('endDate').value = document.getElementById('endDate_'+sIndex).value ;	
	document.getElementById('roomType').value = document.getElementById('roomType_'+sIndex).value ;	
	document.getElementById('proposalLink').value = document.getElementById('proposalLink_'+sIndex).value ;	
	
	document.getElementById('infosEtab').submit();

}

//lien etablissement depuis bloc smart page
function submitFormStay(sAction, sIndex)
{
	showPleaseWait();
	myForm = document.getElementById('infosStay_' + sIndex);
	myForm.action = sAction;
	myForm.submit();
}

//fonction d'ajout au panier via modeles resalys
function modeleAddToCart(_webResLink)
{
	
	showPleaseWait();
	document.location.href = _webResLink;
	
	return false;
}

function changeSearchPage(index)
{

	document.getElementById("search_page_pagination").value = index;
}

function submitFormComparer(id,alert1,alert2,url){
  var form = document.getElementById(id);
  var filter = /^comparer_([0-9])+_hackIE$/;
  var filter2 = /^bak_comparer_([0-9])+$/;
  
  var inputs = form.getElementsByTagName("input");
  var length = inputs.length;
  var count = 0;
  for(var i=0; i<length; i++){
    if(inputs[i].type == "hidden"){

      if(filter2.test(inputs[i].name)){
        count++;
      }
      
    }
  }
  //ne pas compter les checkbox qui sont checkees et qui sont dejq dans les hidden...
  for(var i=0; i<length; i++){
      if(filter.test(inputs[i].name) && inputs[i].value != "0" && !isInArray("bak_"+inputs[i].name.substring(0,inputs[i].name.length-7),inputs)){
        count++;
      }
  }

  if(count < 1){
    alert(alert1);
    return;
  }
  if(count > 4){
    alert(alert2);
    return;
  }
  
  form.action = url;
  form.submit();
}

function isInArray(value,array){
  var bool=0;
  for(var i=0;i<array.length;i++){
    if(value == array[i].name) { bool = 1; }
  }
  return bool;
}
function removeHiddenField(id){
  var checkbox = document.getElementById(id+"_hackIE");
  if(checkbox.value == "0" && document.getElementById("span_bak_"+id)){
    document.getElementById("span_bak_"+id).innerHTML = "";
  }
}

function doHackIE(id){
  var checkbox = document.getElementById(id+"_hackIE");
  if(checkbox.value == "0"){
    checkbox.value = document.getElementById(id).value;
  }else{
    checkbox.value = "0";
    document.getElementById(id).checked = false;
  }
}

function addToSejourSelection(id){

  $.ajax({
    type: "POST",
 		data: "id="+id,
 		url: "ajax/ajax_add_selection.php",
 		success: function(msg){
      if(msg != ""){
        var response = msg.split("###");
        //on affiche le nombre de selections

        if(response[1] != "0" && response[1] != " 0"){
          document.getElementById("nbselections").innerHTML = "("+response[1]+")";
        }

        //surbrillance de l'icone selections
        $("#li_selections").css("background","transparent url(images/sous_menu_fond.gif) no-repeat scroll -124px -39px");

        printLayerMessage(response[2],response[3]);
        
        //on remet la bonne couleur et les bons eventHandlers
        setTimeout(function(){
          $("#li_selections").css("background","transparent url(images/sous_menu_fond.gif) no-repeat scroll 0 -39px");

          $("#li_selections").mouseover(function (){
            $("#li_selections").css("background","transparent url(images/sous_menu_fond.gif) no-repeat scroll -124px -39px");
          });
          $("#li_selections").mouseout(function (){
            $("#li_selections").css("background","transparent url(images/sous_menu_fond.gif) no-repeat scroll 0 -39px");
          });
        },1000);

      }
    }
 	});

}

function printLayerMessage(text,ok){
    var layout = document.getElementById("please_wait_layer");
    var original_layout = document.getElementById("original_text_layout");
    original_layout.style.display = "none";
    document.getElementById("selection_text_layout").innerHTML = "<div class='text_layer_selection'>"+text+"<br /><input type='button' value='"+ok+"' class='button_layout' onclick=\"document.getElementById('please_wait_layer').style.display='none';document.getElementById('original_text_layout').style.display = 'block';document.getElementById('selection_text_layout').innerHTML = '';\" /></div>";
    layout.style.display = "block";
}

/*********************************************/
/*** Gestion recherche via modeles Resalys ***/
/*********************************************/
//mise en panier
function chooseProposal( sFormName, sBlockID )
{
	
    var nProposalIndex = getDOMInputValue( 'proposal_index_' + sBlockID );
   // setInputValue( 'proposal_index_' +sBlockID , sProposalIndex, sFormName );
    if( !nProposalIndex )
    {
    	if(document.getElementById("erreur_reservation") && document.getElementById("erreur_reservation").value != "")
    	{
    		var erreur = document.getElementById("erreur_reservation").value;
    		alert(erreur);
    	}
    	return false;
    }
    setInputValue( 'proposal_index', nProposalIndex, sFormName );
	
    if(document.getElementById("lien_reservation") && document.getElementById("lien_reservation").value != "")
    {	
		var lien = document.getElementById("lien_reservation").value;
	
				
		submitDisplayForm('search_pagination', 'reservation_content', 'chooseProposalForReview', 'ignore_token', null, null, null, lien, null, null);	
    }
    
    return false;
}
//bouton retour resultat recherche
function submit_back_form(session)
{
	document.getElementById('session_name').value = session;
	document.getElementById('back_form').submit();	
}

function changeSearchHebergement(idType,type)
{
	if(document.getElementById('center_search_form_etab'))
	{
		
		var tabOptions = document.getElementById('center_search_form_etab').options;
		for(var i = 0; i < tabOptions.length; i++)
		{		
			if(tabOptions[i].value == idType)
			{		
				tabOptions[i].selected = "selected";
				document.getElementById("center_search_form_etab_input").value = type;
				document.getElementById("center_search_form_etab_input_"+tabOptions[i].value).className="selected";
			}
			else
			{
				document.getElementById("center_search_form_etab_input_"+tabOptions[i].value).className="";
			}
		}
		
	}
}
		
function add_param_destination(destination)
{	
	if(document.getElementById("param_destinations"))
	{
		var found = false;
		var strDestinations = document.getElementById("param_destinations").value;
		document.getElementById("param_destinations").value = "";
		var reg=new RegExp("[,]+", "g");
		var aDestinations =strDestinations.split(reg);
		
		//On verifie si la destination est dans la liste	
		for (var i=0; i<aDestinations.length; i++) {
 				
			if(aDestinations[i] != destination)
			{
				//On ajoute les autres destinations
				if(document.getElementById("param_destinations").value != "")
				{
					document.getElementById("param_destinations").value += ",";	
				}
				document.getElementById("param_destinations").value += aDestinations[i];	
	 					
			}
			else
			{
				//On l'a trouvée
				found = true;
				
			}
		}
		
		//Si pas trouvée, on l'ajoute
		if(!found)
		{
			if(document.getElementById("param_destinations").value != "")
			{
				document.getElementById("param_destinations").value += ",";	
			}
			document.getElementById("param_destinations").value += destination;
		}		
		
		
	}
	
	if (jQuery.browser.msie) {
		
		if(document.getElementById('search_form_theme_codes_'+destination))
		{
			
			if(document.getElementById('search_form_theme_codes_'+destination).checked  == true)
			{	
				document.getElementById('search_form_theme_codes_'+destination).checked = false;
			}	
			else
			{
				document.getElementById('search_form_theme_codes_'+destination).checked= true;	
			}
		}
	
	};
	
}

function add_other_parameters(formName)
{
	if(formName == '')
		formName = 'search_form';
		
	var myForm = document.getElementById(formName);
	if(myForm)
	{
		if(myForm.search_form_sort_string)
			myForm.search_form_sort_string.value='';
		
		if(myForm.search_form_start_date && myForm.search_form_start_date.value != "")
			myForm.param_date_depart.value = myForm.search_form_start_date.value;
		
		if(myForm.search_form_nb_days && myForm.search_form_nb_days.value != "")
			myForm.param_nombre_nuits.value = myForm.search_form_nb_days.value;
		
		if(myForm.search_form_nb_adults && myForm.search_form_nb_adults.value != "")
			myForm.param_nombre_adultes.value = myForm.search_form_nb_adults.value;
		
		if(myForm.search_form_nb_children_1 && myForm.search_form_nb_children_1.value != "")
			myForm.param_nombre_enfants.value = myForm.search_form_nb_children_1.value;
		
		if(myForm.recherche_region && myForm.recherche_region.value != "")
			myForm.param_region.value = myForm.recherche_region.value;
			
		
		if(myForm.recherche_station && myForm.recherche_station.value != "")
			myForm.param_station.value = myForm.recherche_station.value;
		
		if(myForm.page)
			myForm.page.value = "";
		
		if(myForm.search_form_etab && myForm.search_form_etab.value != "")
			myForm.param_etablissement.value = myForm.search_form_etab.value;
	}
	
	return false;
}
/*****************************************/
/*** gestion recherche via webservices ***/
/*****************************************/

//mise en panier
function addToCart(appliPath,baseId, nEtabID, sCampaignCode, nConventionID, nRMethodID, sStartDate, sEndDate, sRoomType,webUser,Ident ) {

   location.href = appliPath + '?webuser='+webUser+'&base_id='+baseId+'&FRMACT_cart%5Fcontent%3BbuildProposalFromCache%2CaddProposalToCart%3B%3B'+Ident+'=1&proposal_etab_id='+nEtabID+'&proposal_campaign_code='+sCampaignCode+'&proposal_convention_id='+nConventionID+'&proposal_rmethod_id='+nRMethodID+'&proposal_start_date='+sStartDate+'&proposal_end_date='+sEndDate+'&proposal_room_type='+sRoomType;
  
   return 0;
}

function valid_cgv()
{	

	if (jQuery.browser.msie) {
		
	if(document.getElementById('salescondition'))
	{
		
		if(document.getElementById('salescondition').checked  == true)
		{	
			document.getElementById('salescondition').checked = false;
		}	
		else
		{
			document.getElementById('salescondition').checked= true;	
		}
	}
	
	};
}

function set_param_last_minutes(id_form,id_date,id_nb_nuit)
{
    //alert(date);
    //alert(nb_nuit);
    //document.getElementById(id_date).id =  "pdd";
    document.getElementById(id_date).name =  "pdd";
    //document.getElementById(id_nb_nuit).id =  "pn";
    document.getElementById(id_nb_nuit).name =  "pn";
    document.getElementById(id_form).action = 'search_result.php';
    document.getElementById(id_form).submit();
    
    //window.location.href = 'search_result.php?pdd='+date+'&pn='+nb_nuit;
}

function recherche_hebergement(etab,heber,offer)
{
	
	
	if(document.getElementById("search_form") && document.getElementById("addHiddenFields"))
	{
		
		document.getElementById("search_form_period_categories").value=offer;
		document.getElementById("search_form_etab").value=etab;
		document.getElementById("nb_night").value='';
		document.getElementById("addHiddenFields").innerHTML += "<input type=\"hidden\" name=\"search_form_room_type\" value=\""+heber+"\"/>";
		document.getElementById("addHiddenFields").innerHTML += "<input type=\"hidden\" name=\"searchType\" value=\"1\"/>";
				
	}
}



function detect_browser(id_form)
{
	
	if(document.getElementById(id_form))
	{
		
		
		
		if(jQuery.browser.msie && jQuery.browser.version < 7)
		{
	
			document.getElementById(id_form).innerHTML += '<input type="hidden" name="browser" value="IE6" />';
		}
		else
		{
			if(jQuery.browser.msie)
			{
		
				document.getElementById(id_form).innerHTML += '<input type="hidden" name="browser" value="IE7" />';
			}
			else
			{
		
				document.getElementById(id_form).innerHTML += '<input type="hidden" name="browser" value="" />';			
			}
		}
	}	
	
	
}

function refresh_filters(_loadPage)
{
	if(document.getElementById('param_destinations') && document.getElementById('param_region') && document.getElementById('param_station') && document.getElementById('param_etablissement'))
	{
	
	//On recupere les filtres à partir des champs param
	if(document.getElementById('param_destinations').value != "")
	{
		document.getElementById('filtre_destination').value = document.getElementById('param_destinations').value;
	}
	
	if(document.getElementById('param_region').value != "")
	{
		document.getElementById('filtre_region').value = document.getElementById('param_region').value;
	}
	
	if(document.getElementById('param_station').value != "")
	{
		document.getElementById('filtre_station').value = document.getElementById('param_station').value;
	}
	if(document.getElementById('param_etablissement') && document.getElementById('param_etablissement').value != "")
	{
		document.getElementById('filtre_etablissement').value = document.getElementById('param_etablissement').value;
	}
	
	//On vérifie la cohérence des champs de recherche avec les filtres
	filter_search(_loadPage);

	}
}

function add_destination_filter(id_destination)
{
	//On verifie si la destination est dans la liste	
	var aFilters = document.getElementById('filtre_destination').value.split(',');
	var found = false;
	document.getElementById('filtre_destination').value = '';
	
	for(i = 0; i < aFilters.length; i++)
	{
		if(aFilters[i]	!= id_destination)
		{
			if(document.getElementById('filtre_destination').value != '')
			{
				document.getElementById('filtre_destination').value += ',';
			}
			document.getElementById('filtre_destination').value += aFilters[i];	
		}
		else
		{
			found = true;	
		}
	}
	if(!found)
	{
		//On ajoute le nouveau filtre destination
		if(document.getElementById('filtre_destination').value != "")
		{
			document.getElementById('filtre_destination').value += ",";
		}
		document.getElementById('filtre_destination').value += id_destination;
	}
	
	
	
	
	//On vérifie la cohérence des champs de recherche avec les filtres
	filter_search(false);
	
}

function add_region_filter(id_region)
{
	//On change le filtre region
	document.getElementById('filtre_region').value = id_region;
	

	//On vérifie la cohérence des champs de recherche avec les filtres
	filter_search(false);
}

function add_station_filter(id_station)
{
	//On change le filtre station
	document.getElementById('filtre_station').value = id_station;
		
	//On vérifie la cohérence des champs de recherche avec les filtres
	filter_search(false);
}

function add_etab_filter(id_etab)
{
	//On change le filtre region
	document.getElementById('filtre_etablissement').value = id_etab;
	
	//On vérifie la cohérence des champs de recherche avec les filtres
	filter_search(false);
}


//Fonction utilisée pour filtrer les paramètres de recherche en fonction des paramètres englobants
function filter_search(_loadPage)
{
	
	if( ! _loadPage)
		showPleaseWait('please_wait_layer_search_form');
	
	var destinations = '';
	if(document.getElementById('filtre_destination') && document.getElementById('filtre_destination') != '')
	{
		destinations = document.getElementById('filtre_destination');
	}
	
	var regions = '';
	if(document.getElementById('filtre_region') && document.getElementById('filtre_region') != '')
	{
		regions = document.getElementById('filtre_region');
	}
	
	var stations = '';
	if(document.getElementById('filtre_station') && document.getElementById('filtre_station') != '')
	{
		stations = document.getElementById('filtre_station');
	}
	
	
	$.ajax({   
 		type: "POST",   
 		data: "destinations="+document.getElementById("filtre_destination").value+"&regions="+document.getElementById("filtre_region").value+"&stations="+document.getElementById("filtre_station").value,    
 		url: "ajax/ajax_refresh_search.php",   
 		success: function(msg){ 
 			
 		if( ! _loadPage)
	 			stopPleaseWait('please_wait_layer_search_form');
			
 			var tableau=msg.split('|');
	 		if(tableau[1] != "ko"){
	 			
	 			//Vide la liste des regions
 				while ( document.getElementById('regions').options.length > 0) {
    					
    					document.getElementById('regions').options[0] = null;
				}
	 			
	 			//Assignation de la liste des regions 			
	 			var regions = tableau[1].split('####');
	 			for(var i=0; i < regions.length; i++) {
	 			
	 				var region = regions[i].split('##');
	 				
		   			var oOption = document.createElement("OPTION");
		   			oOption.text= region[1];
		   			
		   			if(region[0] != "")
		   			{
		   				oOption.value= region[0];	
		   			}
		   			else
		   			{
		   				oOption.value= '';
		   			}
		   			
		   			
		   			if(region[0] == tableau[2])
		   			{
		   				oOption.selected=true;
		   			}
		   			
		   			if(jQuery.browser.msie)
		   			{	   			
		   				document.getElementById('regions').add(oOption);
		   			}
		   			else
		   			{
		   				document.getElementById('regions').appendChild(oOption);
		   			}
				}

	 			//Regeneration du code JQUERY de la region
	 			document.getElementById('regions_input').parentNode.removeChild(document.getElementById('regions_input'));
		 		document.getElementById('regions_container').parentNode.removeChild(document.getElementById('regions_container')); 			
		 		$('#regions').selectbox({ containerClass: 'selectbox-wrapper etablist'});
	 			
	 			//Assignation du filtre region
	 			document.getElementById('filtre_region').value = tableau[2];
		 			
	 			//Changement de l'input region (le nom et sa valeur)
 				document.getElementById('recherche_region').name = 'search_form_theme_codes_' + tableau[2];
 				document.getElementById('recherche_region').value= tableau[2];
 				
 				
 				//Vide la liste des stations
 				while ( document.getElementById('stations').options.length > 0) {
    					
    					document.getElementById('stations').options[0] = null;
				}
 				
 				//Assignation de la liste des stations
	 			var stations = tableau[3].split('####');
	 			for(var i=0; i < stations.length; i++) {
	 			
	 				var station = stations[i].split('##');
	 				
		   			var oOption = document.createElement("OPTION");
		   			oOption.text= station[1];
		   			
		   			if(station[0] != "")
		   			{
		   				oOption.value= station[0];	
		   			}
		   			else
		   			{
		   				oOption.value= '';
		   			}
		   			
		   			if(station[0] == tableau[4])
		   			{
		   				oOption.selected=true;
		   			}
		   			
		   			if(jQuery.browser.msie)
		   			{
		   				document.getElementById('stations').add(oOption);
		   			}
		   			else
		   			{
		   				document.getElementById('stations').appendChild(oOption);
		   			}
				}	 				
	 				
 				//Regeneration du code JQUERY de la station
	 			document.getElementById('stations_input').parentNode.removeChild(document.getElementById('stations_input'));
	 			document.getElementById('stations_container').parentNode.removeChild(document.getElementById('stations_container')); 			
	 			$('#stations').selectbox({ containerClass: 'selectbox-wrapper etablist'});
 			
	 			//Assignation du filtre station
	 			document.getElementById('filtre_station').value = tableau[4];
	 				
	 			//Changement de l'input station (le nom et sa valeur)
	 			document.getElementById('recherche_station').name = 'search_form_theme_codes_' + tableau[4];
	 			document.getElementById('recherche_station').value= tableau[4];	
 				
 				
 				//Vide la liste des etablissements
 				while ( document.getElementById('search_form_etab').options.length > 0) {
    					
    					document.getElementById('search_form_etab').options[0] = null;
				}
 				
	 			//Assignation de la liste des etablissements	 			
	 			var etablissements = tableau[5].split('####');
	 			for(var i=0; i < etablissements.length; i++) {
	 			
	 				var etablissement= etablissements[i].split('##');
	 				
		   			var oOption = document.createElement("OPTION");
		   			oOption.text= etablissement[1];
		   			
		   			if(etablissement[0] != "")
		   			{
		   				oOption.value= etablissement[0];	
		   			}
		   			else
		   			{
		   				oOption.value= '';
		   			}
		   			
		   			//alert(document.getElementById("filtre_etablissement").value);
		   			
		   			if(etablissement[0] == document.getElementById("filtre_etablissement").value)
		   			{
		   				oOption.selected=true;
		   			}

		   			if(jQuery.browser.msie)
		   			{
		   				document.getElementById('search_form_etab').add(oOption);
		   			}
		   			else
		   			{
		   				document.getElementById('search_form_etab').appendChild(oOption);
		   			}
				}	 
	 			
 				//Regeneration du code JQUERY de l'etablissement
 				document.getElementById('search_form_etab_input').parentNode.removeChild(document.getElementById('search_form_etab_input'));
 				document.getElementById('search_form_etab_container').parentNode.removeChild(document.getElementById('search_form_etab_container')); 			
 				$('#search_form_etab').selectbox({ containerClass: 'selectbox-wrapper etablist', maxChar: '27'});
 	 		}
 		
 		} 
 	});  
}	

/**** FIN SEARCH RESULTS.JS ****/

/**** INIT .JS ****/
try {
	document.execCommand('BackgroundImageCache', false, true);
} catch(e) {}
	
/**** FIN INIT .JS ****/

/**** ALL.JS ****/
$(document).ready(function() {
	try {
		document.execCommand('BackgroundImageCache', false, true);
	} catch(e) {}
			
	if (jQuery.browser.msie && jQuery.browser.version < 7) {
		$('#menubar_hl li').hover( function(){
			$(this).addClass('shover'); 
		}, function() {
			$(this).removeClass('shover'); 
		});
		$('.accountMainPush li').hover( function(){
			$(this).addClass('shover'); 
		}, function() {
			$(this).removeClass('shover'); 
		});		
		
	};
	
	// modification des selectbox
	// left
	$('#nb_night').selectbox();
	$('#nb_adults').selectbox({ containerClass: 'selectbox-wrapper nb_adults'}); 
	$('#nb_kids').selectbox({ containerClass: 'selectbox-wrapper nb_kids'}); 
	$('#th_activities').selectbox();
	$('#regions').selectbox({ containerClass: 'selectbox-wrapper etablist'});
	$('#stations').selectbox({ containerClass: 'selectbox-wrapper etablist'});
	$('#search_form_etab').selectbox({ containerClass: 'selectbox-wrapper etablist', maxChar: '27'});
	// contact
	if($('.form').length) 
	{
		$('#select_pays').selectbox();
		$('#theme_demande').selectbox();
	}
	// modification des boutons radio
	$(".left_search form").cssCheckbox();
	$(".bloc_resultat_annonce").cssCheckbox();
	
	// create datePicker
	if(document.getElementById('closingDate') && document.getElementById('openingDate'))
	{	
		
		if(document.getElementById('closingDate').value != '' && document.getElementById('openingDate').value != '')
		{
			$('.date-pick').datePicker({ startDate:document.getElementById('openingDate').value,endDate:document.getElementById('closingDate').value });
			
			
			
		}
		else
		{
			$('.date-pick').datePicker({ });	
		}
	}
	else
	{
		$('.date-pick').datePicker({  });	
	}
	
	
	
	// Prepare and hide element to preserve functionality w/out javascript enable
	// when page is loading : (because of Webkit)
//	$('.more_crit_fieldset').hide();
//	$('.switch_crit a:first').toggle(); 
	$('.choix_recherche_geo img:first').toggle(); 
	$('.choix_recherche_geo img:last').toggle(); 
	
	$('.switch_crit a').click(function(e){
		e.preventDefault(); // return false
		$('.switch_crit a').toggle(); 
		$('.more_crit_fieldset').toggle('fast');
	});
	
	// switch geo_search
	$('.choix_recherche_geo img').click(function(e){
		e.preventDefault(); // return false
		$('.choix_recherche_geo img').toggle(); 
		$('.link_recherche_geo').toggle();
	});

	// tooltip mouseover on .tooltip elements
	tooltip();
	
	// inputValue
	textInputDynamicValue('input[@type=text]','value');
	
	if($('.nos_offres').length)
	{
		$('.nos_offres').hover( function(){
			if($('a', this).length){ $(this).addClass('shover'); }
		}, function() {
			if($('a', this).length){ $(this).removeClass('shover'); }
		});
		$('.nos_offres').click(function(){
			if($('a', this).length)
			{
				//$(this).find("a").click();
				//$(this).find("a").trigger('click');return false;
    		window.location=$(this).find("a").attr("href");
			}
			return false;
	});
	}
	if($('.thematique').length)
	{
		$('.thematique').hover( function(){
			if($('a', this).length){ $(this).addClass('shover'); }
		}, function() {
			if($('a', this).length){ $(this).removeClass('shover'); }
		});
		$('.thematique').click(function(){
			if($('a', this).length)
			{
				$(this).find("a").click();
    			window.location=$(this).find("a").attr("href");
			}
			return false;
	});
	}
	
	if($('#center dl.offerList').length)
	{
		$('#center dl.offerList').hover( function(){
			$(this).addClass('offerList_shover'); 
		}, function() {
			$(this).removeClass('offerList_shover'); 
		});
	}
	
	refresh_filters(true);
	tabNav_planList();//gestion de la nav par onglet page plan et acces
	
	
if ($('#last_minutes').length)
{                          
    $.ajax({
				type: "POST",
				url: "ajax/ajax_dernieres_minutes.php",				
			 	async: true,
				success: function(data){	  
					$("#last_minutes").html(data);
				}
			 });			 			        
}

	
});

/* FUNCTIONS */

/* Navigation par onglets liste plan et acces */
function tabNav_planList() {		
	if($('.menu_listPlan').length) {	
		$(".gab_txt .layerTab_plan").hide();		
		$("ul.menu_listPlan li:first-child").addClass("active");
		var initFirstTab = $("ul.menu_listPlan li:first-child").children().attr("href").split("#");		
		$("#"+initFirstTab[1]).show();
		
		$(".menu_listPlan li a").click(function(){
			
			$(".menu_listPlan li ").removeClass("active");
			$(".gab_txt .layerTab_plan").hide();
			
			var linkTab = $(this).attr("href").split("#");
			$("#"+linkTab[1]).show();
			
			$(this).parent("li").addClass("active");
			
			return false;
		});	
	}
}

/*init skin selectbox page ma selection */
function initSB_selection() {
	if($('.form_resa').length) {
		$('#center_search_form_etab').selectbox({ containerClass: 'selectbox-wrapper center_search_form_etab', maxChar: '26'});
		$('#center_nb_night').selectbox();
		$('#center_nb_adults').selectbox({ containerClass: 'selectbox-wrapper center_nb_adults'});
		$('#center_nb_kids').selectbox({ containerClass: 'selectbox-wrapper center_nb_kids'});
		$('#center_nb_baby').selectbox({ containerClass: 'selectbox-wrapper center_nb_baby'});
	}
}

this.tooltip = function(){	
	/* CONFIG */		
		xOffset = 20;
		yOffset = -25;		
		// these 2 variable determine popup's distance from the cursor
	/* END CONFIG */		
	$("a.tooltip").hover(function(e){											  
		this.t = this.title;
		this.title = "";									  
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
    },
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
    });	
	$("a.tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};

/**/
function textInputDynamicValue (input_selector, text_to_use, def_class) {
	if (text_to_use == undefined) text_to_use = 'title';
	if (def_class == undefined) def_class = 'dvDefault';
	var dynamic_value = [];
	$(input_selector).each(function(j) {
		switch (text_to_use) {
			case 'title' :
				dynamic_value[j] = $(this).attr('title');
				break;
			case 'value' :
				dynamic_value[j] = $(this).attr('value');
				break;
			default :
				dynamic_value[j] = text_to_use;
		}
		$(this).attr('value', dynamic_value[j]).addClass(def_class)
		.focus(function() {
			if (this.value == dynamic_value[j]) {
				this.value = '';
				$(this).removeClass(def_class);
			}
		})
		.blur(function() {
			if (this.value == '') {
				//this.value = dynamic_value[j];
				$(this).addClass(def_class);
			};
		});
	});
};
/**** FIN ALL.JS ****/

/**** SCRIPT .JS ****/

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
var deja = 0;

function valider(nom_form) {
	
	// Si on n'a pas déjà validé
	
	if ( deja == 0 ) {

		// On marque qu'on valide
		deja = 1;
					
		// On affecte le style 'sablier' au corps de la page
		document.body.className = 'sablier';
		
		// On lance la soumission du formulaire
		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
}

// 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;
	}
}

//--------------------------------------------
// Pour ne permettre que la saisie de chiffre
//-----------------------------------------------
function OnlyNumber(e)
{
	// if aEvent is null, means the Internet Explorer event model,
	// so get window.event.
	var IE5 = false;
	
	if (!e) var e = window.event;
	if (e.keyCode) { IE5= true; code = e.keyCode;}
	else if (e.which) code = e.which ;
	
	//test du code
	if (code < 48 || code > 57)
	{
		if(IE5) e.returnValue = false;
		else e.preventDefault();
	}
} 

//--------------------------------------------
// Check whether string s is empty.
//--------------------------------------------
function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

function isNotEmpty(s)
{
	return (!(isEmpty(s)));
}

//--------------------------------------------
///check whether a element is not empty
//--------------------------------------------
function isNotEmptyElement(id_element,id_element_err)
{		
	val = document.getElementById(id_element).value;		
	if(isNotEmpty(val))
	{
		document.getElementById(id_element_err).style.display = "none";
		return true;
	}
	else
	{
		document.getElementById(id_element_err).style.display = "block";
		return false;
	}	
}

//--------------------------------------------
//check whether a checkbos is checked
//--------------------------------------------
function checkIsRadioChecked(name,nb_elements,id_element_err)
{	
	for(i=0 ; i < nb_elements ; i++)
	{
		if( document.getElementsByName(name)[i].checked == true	)
		{
			document.getElementById(id_element_err).style.display = "none";
			return true;						
		}
		
	}
	document.getElementById(id_element_err).style.display = "block";
	return false;
}


//--------------------------------------------
//check is a list not 
//--------------------------------------------
function checkListIsNotEmptyElement(id_element, value_default,id_element_err)
{		
	//si ce n'est pas un element vide, on affiche le champ span avec la classe span hint true
	if (document.getElementById(id_element).value!= value_default &&  document.getElementById(id_element).value !='' )
	{				
		document.getElementById(id_element_err).style.display = "none";		
		return true;		
	}
	else
	{	
		document.getElementById(id_element_err).style.display = "block";
		return false;
	}	
}

//--------------------------------------------
//check the email format 
//--------------------------------------------
function checkEmailFormat(id_element,id_element_err)
{	
	var email = document.getElementById(id_element);	
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (!filter.test(email.value)) 
	{
	 	email.focus
	 	document.getElementById(id_element_err).style.display = "block";	
		return false;
	}
	else
	{
		document.getElementById(id_element_err).style.display = "none";	
		return true;
	}
}


//-----------------------------------------
// check whether the element length >=  nb
//--------------------------------------
function checkElementMinLength(id_element,id_element_err,nb_length)
{
	val = document.getElementById(id_element).value;
	
	if(val.length >= nb_length )
	{
		document.getElementById(id_element_err).style.display = "none";	
		return true;
	}
	else
	{
		document.getElementById(id_element_err).style.display = "block";	
		return false;
	}
}


// 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;
	}
}

// Verifie la validité du champ email du bloc newsletter
function checkEmailNewsletter ( nameForm,sRedirectionOk,sRedirectionKo,sWebUser ) {
	if ( valider_formulaire_generique(nameForm, 'email') ) 
	{
				var url_news = "http://reservation.madamevacances.com/reservation/cgi/clickbooking.cgi?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" ;
				document.location.href = url_news;				
	}
	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;
	}
}

// Imprime la page
function printPage() {
	window.print();
}

// Modifie les input hidden en fonction de la region choisie
function changeRegion(code) {
	
	document.getElementById("recherche_region").value = code;
	document.getElementById("recherche_region").name = "search_form_theme_codes_" + code;
}

// Modifie les input hidden en fonction de la thematique choisie
function changeThematique(code) {
	
	document.getElementById("recherche_thematique").value = code;
	document.getElementById("recherche_thematique").name = "search_form_theme_codes_" + code;
	
	document.getElementById("thematique").value = code;
}

// Modifie les input hidden en fonction de la station
function changeStation(code) {
	
	document.getElementById("recherche_station").value = code;
	document.getElementById("recherche_station").name = "search_form_theme_codes_" + code;
}


//----------------------------------------------------------
//---specifique formulaire de contact
function contactFormSubmit()
{
	//controle des champs obligatoires 
	result1 = checkIsRadioChecked('civilite', 3, 'err_civ');
	result2 = isNotEmptyElement('nom','err_nom');
	result3 = isNotEmptyElement('prenom','err_prenom');
	result4 = isNotEmptyElement('adresse','err_adresse');
	result5 = isNotEmptyElement('cp','err_cp');
	result6 = isNotEmptyElement('ville_contact','err_ville');
	result7 = checkListIsNotEmptyElement('select_pays',0,'err_pays');		
	result8 = isNotEmptyElement('email_contact','err_email');		
	result9 = checkListIsNotEmptyElement('theme_demande',0,'err_theme_demande');		
	result10 = isNotEmptyElement('demande','err_demande');		
	result11 = checkEmailFormat("email_contact",'err_email_incorrect');
	if(document.getElementById('tel_dom').value!= "" ) result12 = checkElementMinLength("tel_dom","err_tel_dom_long",7);
	else document.getElementById('err_tel_dom_long').style.display = "none";
	if(document.getElementById('tel_mobile').value!= "" ) result13 = checkElementMinLength("tel_mobile","err_tel_mobile_long",7);
	else document.getElementById('err_tel_mobile_long').style.display = "none";
	
					
	/*for(i=1;i<=11;i++)
	{
		res = 'result' + i ; 
		alert( 'i : '+ i + eval(res));
	}*/

	//submit contact form
	if(result1 && result2 && result3 && result4 && result5 && result6 && result7 && result8 && result9 && result10 && result11)
	{		
		document.getElementById("form_contact").submit();
	}
}

//-----------------------------------------------------------------
//--specifique nos offres
function searchOffreSubmit(code_groupe_periode)
{
	document.getElementById('search_form_period_categories').value=code_groupe_periode;	
	document.getElementById('id_submit_search_form').onclick();	
}



/****** RESULTS .JS ******/
$(document).ready(function() {
	// hover sur les resultats de recherche
	$(".bloc_resultat_annonce div, .sort_search_services").hide();

	$(".bloc_resultat_annonce").hoverIntent({
		sensitivity: 7, // number = sensitivity threshold (must be 1 or higher)
		interval: 300,   // number = milliseconds of polling interval
		over: blocResultDown , // function = onMouseOver callback (required)
		timeout: 300,   // number = milliseconds delay before onMouseOut function call
		out: blocResultUp    // function = onMouseOut callback (required)
	});
	
	// fonctionnement FAQ
	$(".faq_rep p").hide();
	$(".faq_rep h4").click(function(){
		$(this).next("p").slideToggle("slow")
		.siblings("p:visible").slideUp("slow");
		$(this).toggleClass("active");
		$(this).siblings("h4").removeClass("active");
	});	
	$(".faq_top5 a").click(function(){
		var faqID = $(this).attr("rel");
		$("h4[id='" + faqID + "']").toggleClass("active").next("p").slideToggle("slow")
		.siblings("p:visible").slideUp("slow");
	});
});
	
$(document).ready(function() {
	$(".sort_search_more").click(function(){
		$(".sort_search_services").slideToggle();
	});
});

function blocResultDown() {			
	$(this).find('>div').slideToggle("normal");
	$(this).css("height", "auto");
	$(this).toggleClass("active");
};
function blocResultUp() {			
	$(this).find('>div').slideToggle("normal");
	$(this).toggleClass("active");
};


/**** FIN SCRIPT .JS ****/

/**** HOME .JS ******/

$(document).ready(function() {
	
	// links on different element
	$('.encart_special dl,.encart_coupcoeur ul li,.encart_listoffre dl,.encart_listoffre2 dl,.encart_minutes dl').click(function(){
    	window.location=$(this).find("a").attr("href");return false;
	});
	$('.encart_special dl dd a,.encart_listoffre dl dd a,.encart_listoffre2 dl dd a,.encart_minutes dl a,.encart_listoffre3 dl dd a').hide();

//the property lenght used here to check if 'last_minutes' exists



//encart_listoffre3_type_destination
//the property lenght used here to check if 'encart_listoffre3_type_destination' exists
if ($('#encart_listoffre3_type_destination').length)
{    
    $.ajax({
				type: "POST",
				url: "ajax/ajax_type_destination_offres.php",				
				success: function(data){				  
					var tab = data.split("|");
					$("#encart_listoffre3_type_destination").html(tab[0]);
					$("#encart_listoffre3_type_destination_bis").html(tab[1]);
					
					if($.trim(tab[1])!="") $("#encart_listoffre3_type_destination_bis").css("display","block");										
					if($.trim(tab[0])=="") $("#encart_listoffre3_type_destination").css("background-color","#FFFFFF");
					
					$('.encart_listoffre3 dl').click(function(){
						$(this).find("a").trigger('click');return false;
				    //	window.location=$(this).find("a").attr("href");return false;
					});		
					$('.encart_listoffre3 dl a').hide();
				}
			 });
			 
	
}

if ($('.accountMainPush').length)
{      

$('.accountMainPush li').click(function(){
window.location=$(this).find("a").attr("href");return false;
});
	
}


//encart_listoffre3_thematique
//the property lenght used here to check if 'encart_listoffre3_thematique' exists
if ($('#encart_listoffre3_thematique').length)
{    
    //alert(document.location);
    /*$("#encart_listoffre3_thematique").load("ajax/ajax_thematique_offres.php", function() { 
		$('.encart_listoffre3 dl').click(function(){
	    	window.location=$(this).find("a").attr("href");return false;
		});
		$('.encart_listoffre3 dl a').hide();
	}); */
    
    
     
    $.ajax({
				type: "POST",
				data: "id_thematique=" + document.getElementById("id_thematique").value,
				url: "ajax/ajax_thematique_offres.php",				
				success: function(data){				  

          if(data != ""){
            $("#encart_listoffre3_thematique").html(data);
            $('.encart_listoffre3 dl').click(function(){
              window.location = $(this).find("a").attr('href');
            });
            $('.encart_listoffre3 dl a').hide();
          }
          else
            $("#encart_listoffre3_thematique").css("display","none");

/*					$("#encart_listoffre3_thematique").html(tab[0]);
					$("#encart_listoffre3_thematique_bis").html(tab[1]);
					
					if($.trim(tab[1])!="") $("#encart_listoffre3_thematique_bis").css("display","block");										
					if($.trim(tab[0])=="") $("#encart_listoffre3_thematique").css("background-color","#FFFFFF");
					
					$('.encart_listoffre3 dl').click(function(){
	    				//window.location=$(this).find("a").attr("onclick");return false;
						$(this).find("a").trigger('click');return false;
					});
					$('.encart_listoffre3 dl a').hide();*/
				}
			 });
			 
			 
}

//encart_listoffre3_destination
//the property lenght used here to check if 'encart_listoffre3_destination' exists
if ($('#encart_listoffre3_destination').length)
{   
	$.ajax({
				type: "POST",
				url: "ajax/ajax_destination_offres.php",				
				success: function(data){				  
					var tab = data.split("|");
					$("#encart_listoffre3_destination").html(tab[0]);
					$("#encart_listoffre3_destination_bis").html(tab[1]);
					
					if($.trim(tab[1])!="") $("#encart_listoffre3_destination_bis").css("display","block");										
					if($.trim(tab[0])=="") $("#encart_listoffre3_destination").css("background-color","#FFFFFF");
					
					$('.encart_listoffre3 dl').click(function(){
						$(this).find("a").trigger('click');return false;
				    	//window.location=$(this).find("a").attr("href");return false;
					});		
					$('.encart_listoffre3 dl a').hide();
				}
			 });
}


//encart_listoffre3_etablissement
//the property lenght used here to check if 'encart_listoffre3_etablissement' exists
if ($('#encart_listoffre3_etablissement').length)
{   
	$.ajax({
				type: "POST",
				url: "ajax/ajax_etablissement_offres.php",				
				success: function(data){				  
					var tab = data.split("|");
					$("#encart_listoffre3_etablissement").html(tab[0]);
					
					//if($.trim(tab[0])=="") $("#encart_listoffre3_etablissement").css("background-color","#FFFFFF");
					if($.trim(tab[0])=="") $("#encart_listoffre3_etablissement").css("display","none");
					
					$('.encart_listoffre3 dl').click(function(){
						//$(this).find("a").trigger('click');return false;
				    	window.location=$(this).find("a").attr("href");return false;
					});		
					$('.encart_listoffre3 dl a').hide();
				}
			 });
}


//encart_listoffre3_region
//the property lenght used here to check if 'encart_listoffre3_region' exists
if ($('#encart_listoffre3_region').length)
{    
    $.ajax({
				type: "POST",
				url: "ajax/ajax_region_offres.php",				
				success: function(data){				  
					var tab = data.split("|");
					$("#encart_listoffre3_region").html(tab[0]);
					$("#encart_listoffre3_region_bis").html(tab[1]);
					
					if($.trim(tab[1])!="") $("#encart_listoffre3_region_bis").css("display","block");										
					if($.trim(tab[0])=="") $("#encart_listoffre3_region").css("background-color","#FFFFFF");
					
					$('.encart_listoffre3 dl').click(function(){
				    	$(this).find("a").trigger('click');return false;
				    	//window.location=$(this).find("a").attr("href");return false;
					});		
					$('.encart_listoffre3 dl a').hide();
				}
			 });
			 
	
}


});







/**** FICHES .JS ****/
$(document).ready(function() {
	
	// test Laurent
	$('.panel_hbgt .submitChoisir').click(function(){
		$newText = $(this).parent().prev('h4').html();
		$defaultText = $('h3.prependSejour').html();
		$('h3.prependSejour').text($newText);
		$('.center_search.form_resa').expose({
			color: null,
			onLoad: function() {
				$('span.unexpose').show();
			},
			onClose: function() {
				$('h3.prependSejour').text($defaultText);
				$('span.unexpose').hide();
			} 
		});
		$('.unexpose').bind("click.",function(){$.expose.close();});
	});
	
	
	// links on different element
	$('.encart_listoffre3 dl').click(function(){
    	window.location=$(this).find("a").attr("href");return false;
	});
	$('.encart_listoffre3 dl dd a').hide();
	// modification des selectbox// center
	$('#center_search_form_etab').selectbox({ containerClass: 'selectbox-wrapper center_search_form_etab', maxChar: '26'});
	$('#center_nb_night').selectbox();
	$('#center_nb_adults').selectbox({ containerClass: 'selectbox-wrapper center_nb_adults'});
	$('#center_nb_kids').selectbox({ containerClass: 'selectbox-wrapper center_nb_kids'});
	$('#center_nb_baby').selectbox({ containerClass: 'selectbox-wrapper center_nb_baby'});

	// fonctionnement Vos services en ligne => etablissement_sejours.tpl
	//$("#hbgt_pannel_slide div").hide();
	//$("#hbgt_pannel_slide h4").eq(0).addClass("active");
	//$("#hbgt_pannel_slide div").eq(0).show();

	$(".#hbgt_pannel_slide h4").click(function(){
		$(this).next("div").slideToggle("slow")
		.siblings("div:visible").slideUp("slow");
		$(this).toggleClass("active");
		$(this).siblings("h4").removeClass("active");
	});	
	
	// fonctionnement Vos services en ligne
	$("#hbgt_pannel_slide2 h4").eq(0).addClass("active");

	$(".#hbgt_pannel_slide2 h4").click(function(){
		$(this).next("div").slideToggle("slow")
		.siblings("div:visible").slideUp("slow");
		$(this).toggleClass("active");
		$(this).siblings("h4").removeClass("active");if (jQuery.browser.msie && jQuery.browser.version < 8) { $(".#hbgt_pannel_slide2 img").toggle(); }
	});	
	if ( $('#carousel_basic') ) {
		$('#carousel_basic').jcarousel({
				scroll: 1, //avance d'un item a chaque fois		
				initCallback: mycarousel_initCallback
	    });
	}
	if (jQuery.browser.msie && jQuery.browser.version < 7) { }
	else {
		if ( $('.jcarousel-item') ) {
			$(".jcarousel-item a img").hoverIntent({
				sensitivity: 7, // number = sensitivity threshold (must be 1 or higher)
				interval: 100,   // number = milliseconds of polling interval
				over: growupImg , // function = onMouseOver callback (required)
				timeout: 0,   // number = milliseconds delay before onMouseOut function call
				out: growdownImg    // function = onMouseOut callback (required)
			});		
		}
	};
});

// Slider Conseil
window.onload = function(){ 
	if ( $('#news_slider') ) {
		$("#news_slider").accessNews(); 
	}
}

function growupImg() {			
	if (jQuery.browser.msie && jQuery.browser.version < 7) {}
	else {
		$(this).animate({width: "150px", height: "115px", marginLeft:"-10px", marginTop: "0px"});
	}
};
function growdownImg() {			
	if (jQuery.browser.msie && jQuery.browser.version < 7) {}
	else {
		$(this).animate({width: "110px", height: "85px", marginLeft:"10px", marginTop: "10px"});
	};
};

function mycarousel_initCallback(carousel){
	jQuery('#carousel_basic-next').bind('click', function() {
        carousel.next();
        return false;
    });
    jQuery('#carousel_basic-prev').bind('click', function() {
        carousel.prev();
        return false;
    });
};

//Gestion du click sur l'onglet saison de la fiche etablissement
function set_etablissement_saison(saison,id_etab)
{
	if(saison == 'ete')
	{
		if(document.getElementById('lien_saison_hiver'))
		{
			document.getElementById('lien_saison_hiver').className = 'season_hiver season_off';
		}
		
		if(document.getElementById('lien_saison_hiver'))
		{
			document.getElementById('lien_saison_ete').className = 'season_ete season_on';
		}
		
		if(document.getElementById('swf_img_diapo_hiver'))
		{
			document.getElementById('swf_img_diapo_hiver').style.display = 'none';	
		}
		
		if(document.getElementById("session_diapo_ete").value != "")
		{
			var flashvars = {};
			flashvars.saison = document.getElementById("session_diapo_ete").value;
			flashvars.id_etablissement	= id_etab;
			var params = {};
			params.wmode = "transparent";
			var attributes = {};
			swfobject.embedSWF("flash/diapo.swf", "swf_img_diapo_ete", "281", "253", "8", false, flashvars, params, attributes);
		}
		
		if(document.getElementById('points_forts_hiver'))
		{
			document.getElementById('points_forts_hiver').style.display = 'none';
		}
		if(document.getElementById('points_forts_ete'))
		{
			document.getElementById('points_forts_ete').style.display = 'block';
		}
		
		if(document.getElementById('descriptif_hiver'))
		{
			document.getElementById('descriptif_hiver').style.display = 'none';
		}
		if(document.getElementById('descriptif_ete'))
		{
			document.getElementById('descriptif_ete').style.display = 'block';
		}
		
		if(document.getElementById('description_conseil_hiver'))
		{
			document.getElementById('description_conseil_hiver').style.display = 'none';
		}
		if(document.getElementById('description_conseil_ete'))
		{
			document.getElementById('description_conseil_ete').style.display = 'block';
		}
		
		if(document.getElementById('selection_conseil_hiver'))
		{
			document.getElementById('selection_conseil_hiver').style.display = 'none';
		}
		if(document.getElementById('selection_conseil_ete'))
		{
			document.getElementById('selection_conseil_ete').style.display = 'block';
		}
		
	}
	
	if(saison == 'hiver')
	{
		if(document.getElementById('lien_saison_hiver'))
		{
			document.getElementById('lien_saison_hiver').className = 'season_hiver season_on';
		}
		if(document.getElementById('lien_saison_ete'))
		{
			document.getElementById('lien_saison_ete').className = 'season_ete season_off';
		}
		if(document.getElementById('swf_img_diapo_ete'))
		{
			document.getElementById('swf_img_diapo_ete').style.display = 'none';	
		}
		
		if(document.getElementById("session_diapo_hiver").value != "")
		{
			var flashvars = {};
			flashvars.saison = document.getElementById("session_diapo_hiver").value;
			flashvars.id_etablissement	= id_etab;
			var params = {};
			params.wmode = "transparent";
			var attributes = {};
			swfobject.embedSWF("flash/diapo.swf", "swf_img_diapo_hiver", "281", "253", "8", false, flashvars, params, attributes);
		}
		if(document.getElementById('points_forts_hiver'))
		{
			document.getElementById('points_forts_hiver').style.display = 'block';
		}
		if(document.getElementById('points_forts_ete'))
		{
			document.getElementById('points_forts_ete').style.display = 'none';
		}
		if(document.getElementById('descriptif_hiver'))
		{
			document.getElementById('descriptif_hiver').style.display = 'block';
		}
		if(document.getElementById('descriptif_ete'))
		{
			document.getElementById('descriptif_ete').style.display = 'none';
		}
		
		if(document.getElementById('description_conseil_hiver'))
		{
			document.getElementById('description_conseil_hiver').style.display = 'block';
		}
		if(document.getElementById('description_conseil_ete'))
		{
			document.getElementById('description_conseil_ete').style.display = 'none';
		}
		
		if(document.getElementById('selection_conseil_hiver'))
		{
			document.getElementById('selection_conseil_hiver').style.display = 'block';
		}
		if(document.getElementById('selection_conseil_ete'))
		{
			document.getElementById('selection_conseil_ete').style.display = 'none';
		}
		
	}
		
}

//Gestion du click sur l'onglet saison de la fiche destination
function set_destination_saison(saison,id_dest)
{
	if(saison == 'ete')
	{
		if(document.getElementById('lien_saison_hiver'))
		{
			document.getElementById('lien_saison_hiver').className = 'season_hiver season_off';
		}
		if(document.getElementById('lien_saison_ete'))
		{
			document.getElementById('lien_saison_ete').className = 'season_ete season_on';
		}
		
		if(document.getElementById('swf_img_diapo_hiver'))
		{
			document.getElementById('swf_img_diapo_hiver').style.display = 'none';	
		}
		
		if(document.getElementById("session_diapo_ete").value != "")
		{
			var flashvars = {};
			flashvars.saison = document.getElementById("session_diapo_ete").value;
			flashvars.id_destination	= id_dest;
			var params = {};
			params.wmode = "transparent";
			var attributes = {};
			swfobject.embedSWF("flash/diapo.swf", "swf_img_diapo_ete", "281", "253", "8", false, flashvars, params, attributes);
		}
		
		if(document.getElementById('descriptif_hiver'))
		{
			document.getElementById('descriptif_hiver').style.display = 'none';
		}
		if(document.getElementById('descriptif_ete'))
		{
			document.getElementById('descriptif_ete').style.display = 'block';
		}
		
		if(document.getElementById('temoignage_ete'))
		{
			document.getElementById('temoignage_ete').style.display = 'block';
		}
		if(document.getElementById('temoignage_hiver'))
		{
			document.getElementById('temoignage_hiver').style.display = 'none';
		}
		
		if(document.getElementById('avoir_afaire_hiver'))
		{
			document.getElementById('avoir_afaire_hiver').style.display = 'none';
		}
		if(document.getElementById('avoir_afaire_ete'))
		{
			document.getElementById('avoir_afaire_ete').style.display = 'block';
		}
		
		if(document.getElementById('activites_hiver'))
		{
			document.getElementById('activites_hiver').style.display = 'none';
		}
		if(document.getElementById('activites_ete'))
		{
			document.getElementById('activites_ete').style.display = 'block';
		}
		
		
		
		
		
	}
	
	if(saison == 'hiver')
	{
		if(document.getElementById('lien_saison_hiver'))
		{
			document.getElementById('lien_saison_hiver').className = 'season_hiver season_on';
		}
		if(document.getElementById('lien_saison_ete'))
		{
			document.getElementById('lien_saison_ete').className = 'season_ete season_off';
		}
		
		if(document.getElementById('swf_img_diapo_ete'))
		{
			document.getElementById('swf_img_diapo_ete').style.display = 'none';	
		}
		
		if(document.getElementById("session_diapo_hiver").value != "")
		{
			var flashvars = {};
			flashvars.saison = document.getElementById("session_diapo_hiver").value;
			flashvars.id_destination	= id_dest;
			var params = {};
			params.wmode = "transparent";
			var attributes = {};
			swfobject.embedSWF("flash/diapo.swf", "swf_img_diapo_hiver", "281", "253", "8", false, flashvars, params, attributes);
		}
		
		if(document.getElementById('descriptif_hiver'))
		{
			document.getElementById('descriptif_hiver').style.display = 'block';
		}
		if(document.getElementById('descriptif_ete'))
		{
			document.getElementById('descriptif_ete').style.display = 'none';
		}
		
		if(document.getElementById('temoignage_ete'))
		{
			document.getElementById('temoignage_ete').style.display = 'none';
		}
		if(document.getElementById('temoignage_hiver'))
		{
			document.getElementById('temoignage_hiver').style.display = 'block';
		}
		
		if(document.getElementById('avoir_afaire_hiver'))
		{
			document.getElementById('avoir_afaire_hiver').style.display = 'block';
		}
		if(document.getElementById('avoir_afaire_ete'))
		{
			document.getElementById('avoir_afaire_ete').style.display = 'none';
		}
		
		if(document.getElementById('activites_hiver'))
		{
			document.getElementById('activites_hiver').style.display = 'block';
		}
		if(document.getElementById('activites_ete'))
		{
			document.getElementById('activites_ete').style.display = 'none';
		}
		
	}
		
}

//ma selection
//change letablissement selected dans le select du moteur de recherche
function changeSearchEtablissement(id,nom)
{
	if(document.getElementById('center_search_form_etab'))
	{
		
		var tabOptions = document.getElementById('center_search_form_etab').options;
		for(var i = 0; i < tabOptions.length; i++)
		{		
			if(tabOptions[i].value == id)
			{		
				tabOptions[i].selected = "selected";
				document.getElementById("center_search_form_etab_input").value = nom;
				document.getElementById("center_search_form_etab_input_"+tabOptions[i].value).className="selected";
			}
			else
			{
				document.getElementById("center_search_form_etab_input_"+tabOptions[i].value).className="";
			}
		}
		
	}
}

//selection
function deleteSelection(idEtab,lib_empty_selection){


		document.getElementById("selection_"+idEtab).innerHTML = "";
		document.getElementById("selection_"+idEtab).className = "";

	$.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("my_div_selection").innerHTML = lib_empty_selection;
			}
		}
	});	
}  


//script pour la smart page
function startSearch(sEtabId,url){

  document.getElementById('search_form_etab_list').value=sEtabId;
  var param_period = document.getElementById('search_form_period_categories');
  if(param_period.value != ""){
    var select = document.getElementById('nb_night');
    select.options[select.selectedIndex].value="";
  }
	add_other_parameters('search_form');
	submitDisplayForm('search_form','search_results','updateCriterias;getProposals','ignore_token','checkSearchForm',null, null,url,null,null);
	return true;
}
//Script pour la validation du formulaire + d'infos
function checkInfosForm()
{
	//Champs non vides 
	var fields = new Array('civilite','nom','prenom','email_contact','yourQuery');		
	
	var i = 0;
	for(i = 0; i < fields.length; i++)
	{
		if(document.getElementById(fields[i]))
		{
			if(document.getElementById(fields[i]).value == '')
			{			
				return false;	
			}
			
		}
		else
		{
			return false;
		}	
	}
	
	var tab_subject_options = document.getElementById('subject').options;
	for(i = 0; i < tab_subject_options.length; i++)
	{
		if(tab_subject_options[i].value != 0 && tab_subject_options[i].selected)
		{	
			document.getElementById('id_theme_demande').value = tab_subject_options[i].value;		
			document.getElementById('form_contact_small').submit();	
			return true;
		}	
	}
	
	return false;
}

function filterSearch(form){

  var tri = (document.getElementById('triEtabPrix').checked == true ? "prix" : "dest");
	

  showPleaseWait('please_wait_layer_search_form');
  
  var themes = '';
  for(var i in form){
    if(i.substr(0,6) == 'filtre' && form[i].checked == true)
      themes += form[i].value+"#";
  }
  themes = themes.substr(0,themes.length-1);

  var type_room = '';
  for(var i in form){
    if(i.substr(0,9) == 'type_heb_' && form[i].checked == true)
      type_room += form[i].value+"#";
  }
  type_room = type_room.substr(0,type_room.length-1);

  if(form.search_form_start_date.value != '') var reserver_mode = 1;
  else var reserver_mode = 0;

  if(form.onlyPromo.checked == true) var onlyPromo = 1;
  else var onlyPromo = 0;
  
  if(form.formule && form.formule.value != "") var formule = form.formule.value;
  else var formule = 0;
  	


	$.ajax({
	  type: "POST",
		data: "themes="+encodeURIComponent(themes)+"&reserver_mode="+reserver_mode+"&tri="+tri+"&type_room="+encodeURIComponent(type_room)+"&onlyPromo="+onlyPromo+"&formule="+formule,
		url: "ajax/ajax_filter_search.php",
		success: function(msg){
			document.getElementById('search_html_content').innerHTML = msg;
			$(".bloc_resultat_annonce").cssCheckbox();
			$(".bloc_resultat_annonce div").hide();
    	$(".bloc_resultat_annonce").hoverIntent({
    		sensitivity: 7, // number = sensitivity threshold (must be 1 or higher)
    		interval: 300,   // number = milliseconds of polling interval
    		over: blocResultDown , // function = onMouseOver callback (required)
    		timeout: 300,   // number = milliseconds delay before onMouseOut function call
    		out: blocResultUp    // function = onMouseOut callback (required)
    	});
		$(".sort_search_more").click(function(){
			$(".sort_search_services").slideToggle();
		});
			stopPleaseWait('please_wait_layer_search_form');
		}
	});
	
	

}

function submitPagination(page)
{

	showPleaseWait('please_wait_layer_search_form');

  var form = document.getElementById('paginationForm');

  var themes = '';
  for(var i in form){
    if(i.substr(0,6) == 'filtre' && form[i].checked == true)
      themes += form[i].value+"#";
  }
  themes = themes.substr(0,themes.length-1);

  if(form.search_form_start_date.value != '') var reserver_mode = 1;
  else var reserver_mode = 0;

	$.ajax({
	  type: "POST",
		data: "page="+page+"&reserver_mode="+reserver_mode+"&themes="+encodeURIComponent(themes),
		url: "ajax/ajax_change_page_search.php",
		success: function(msg){
			document.getElementById('search_html_content').innerHTML = msg;
			$(".bloc_resultat_annonce").cssCheckbox();
			$(".bloc_resultat_annonce div").hide();
    	$(".bloc_resultat_annonce").hoverIntent({
    		sensitivity: 7, // number = sensitivity threshold (must be 1 or higher)
    		interval: 300,   // number = milliseconds of polling interval
    		over: blocResultDown , // function = onMouseOver callback (required)
    		timeout: 300,   // number = milliseconds delay before onMouseOut function call
    		out: blocResultUp    // function = onMouseOut callback (required)
    	});
			stopPleaseWait('please_wait_layer_search_form');
		}
	});

	return false;
}

function submitPaginationLastMinutes(page)
{

  showPleaseWait('please_wait_layer_search_form');

  var form = document.getElementById('paginationForm');

  var nbNuits = document.getElementById('nbNuits').value;

	$.ajax({
	  type: "POST",
		data: "page="+page+"&nbNuits="+nbNuits,
		url: "ajax/ajax_change_page_last_minute.php",
		success: function(msg){
			document.getElementById('last_minute_html_content').innerHTML = msg;
			
			stopPleaseWait('please_wait_layer_search_form');
		}
	});

	return false;
}

function add_browser(link)
{
	if(jQuery.browser.msie && jQuery.browser.version < 7)
	{

		link.href += "&browser=IE6";
	}
	else
	{
		if(jQuery.browser.msie)
		{
	
			link.href += "&browser=IE7";
		}
		else
		{
	
			link.href += "&browser=";
		}
	}
}

function check_dispo(proposal_link,from,get_session,my_link)
{
	//Parser proposal Link pour recuperer les informations de reservation
	//350_2010-05-15_2010-05-22_LOC_2_1842_1-BAF-2-BAF
	//idetab_datedebut_datefin_baseproductcode_nbpers_method_nbetab-roomtype-nbpers-roomtype
	proposal_link = proposal_link.replace(/-/g,'_');
	var aElements = proposal_link.split("_");
	if(aElements.length == 14)
	{
		
		var etabId = aElements[0];
		var jourdebut = aElements[3];
		var moisdebut = aElements[2];
		var anneedebut = aElements[1];
		var jourfin = aElements[6];
		var moisfin = aElements[5];
		var anneefin = aElements[4];
		var baseproductcode = aElements[7];
		var nbpers = aElements[8];
		var roomtype = aElements[11];
		
		$.ajax({
			
		  	type: "POST",
			data: "etabId="+etabId+"&jourdebut="+jourdebut+"&moisdebut="+moisdebut+"&anneedebut="+anneedebut+"&jourfin="+jourfin+"&moisfin="+moisfin+"&anneefin="+anneefin+"&baseproductcode="+baseproductcode+"&nbpers="+nbpers+"&roomtype="+roomtype+"&from="+from,
			url: "ajax/ajax_check_dispo.php",
			success: function(msg){
				
		
				var retour = msg.split("|");

						
				if(retour[1] == "")
				{
					//Si aucun retour, la dispo est correcte
					//linkResa = document.getElementById('lien_reservation').href;
						
					if(get_session)
						my_link+=retour[0];
						
					
					document.location.href = my_link;
				}
				else
				{
					
					alert(retour[2]);
					//Si un retour, c'est le lien de la page de non disponibilite
					if(from == 1)
					{
						//Page etablissement : on lance un get de la page
						document.location.href = retour[1];
					}
					if(from == 2)
					{
						//Recherche : on recharge les post
						document.getElementById('search_form').submit();
					}
				
				}
			}
		});
	}
}


function check_params()
{
	if(document.getElementById('search_form'))
	{
		if(document.getElementById('date_dep'))
		{
			var input_date = document.getElementById('date_dep').value;
			if(input_date == "")
			{
				return true;	
			}
			return isValidDate(input_date);
		}
		return false;
	}	
	return false;
}

function isValidDate(dateStr) {

	var datePat = /^(\d{1,2})(\/)(\d{1,2})(\/)(\d{4})$/;
	var matchArray = dateStr.match(datePat); // is the format ok?

	if (matchArray == null) {
		alert(get_trad_champ("bad_date_format"));
		return false;
	}

	month = matchArray[3]; // p@rse date into variables
	day = matchArray[1];
	year = matchArray[5];

	if (month < 1 || month > 12) { // check month range
		alert(get_trad_champ("bad_date_month"));
		return false;
	}

	if (day < 1 || day > 31) {
		alert(get_trad_champ("bad_date_day"));
		return false;
	}

	if ((month==4 || month==6 || month==9 || month==11) && day==31) {

		var error = get_trad_champ("bad_even_month");
		var reg=new RegExp("(##month##)", "g");
		error = error.replace(reg,month);
		alert(error);
		return false;
	}

	if (month == 2) { // check for february 29th

		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day > 29 || (day==29 && !isleap)) {
			
			var error = get_trad_champ("bad_februray_month");
			var reg=new RegExp("(##year##)", "g");
			error = error.replace(reg,year);
			var reg=new RegExp("(##day##)", "g");
			error = error.replace(reg,day);
			alert(error);
			return false;
		}
	}
	
	
	var today=new Date()
	var search=new Date(year,month,day)
	
	if(today.getTime() >= search.getTime())
	{
		alert(get_trad_champ("date_passed"));
		return false;
	}
	
	return true; // date is valid
}
