// brides-les-bains

/* renvoie true si on est en msie < 7 */

var CURRENT_BOX_MENU_SELECTED = "";
var scrollbar = null;

function checkIfOldMSIE(){
	if(navigator.appName == 'Microsoft Internet Explorer'){
		var arVersion = navigator.appVersion.split("MSIE");
		var version = parseFloat(arVersion[1]);
		if(version < 7){
			return true;	
		}
	}

	return false;
}


function getMsieVersion(){
	if(navigator.appName == 'Microsoft Internet Explorer'){
		var arVersion = navigator.appVersion.split("MSIE");
		var version = parseFloat(arVersion[1]);
			return version;	
	}

	return false;
}

/* redimensionnement selon taille du viewport */
function initHeight(new_height)
{
	if($chk($('parent_content') ) )
	{
    $('parent_content').setStyle('height', new_height);
		$('content_gallery').setStyle('height', new_height);
    $('content').setStyle('height', new_height);
    $('galerie').setStyle('height', new_height);
    $('image').setStyle('height', new_height);
    $('box_infos').setStyle('height', new_height);
	  $('box_texte').setStyle('height', new_height-260);
		
    $$('.gallery_img').each(function(elt){
        $(elt).setStyle('height', new_height);
    });
		
		$('previous_img').setStyle('top', parseInt((new_height-12)/2)+'px');
		$('next_img').setStyle('top', parseInt((new_height-12)/2)+'px');
		$('to_gallery_button').setStyle('top', parseInt((new_height-12)/2, 10)+'px');
	}else if($chk('corps')){
			$('corps').setStyle('height', new_height );
			//$('actu_scroll').setStyle('height', new_height - $('presentation').getSize().y);
			var to_height = new_height - $('presentation').getSize().y - $('footer').getSize().y - 30;
			$$('.scrollable').each(function(el) {el.setStyle('height', to_height)});
			$$('.scroll_handler_bkg').each(function(el) {el.setStyle('height', to_height)});
			
			if(new_height < 500){
				$("maigrir3").setStyle("top", new_height - parseInt($('maigrir3').getStyle('width').replace('px', '')) );
			}
	}
	
}//fin initHeight


/*
*
*/
function initWidth(new_width){
	if($chk($('parent_content'))){
		 var marge = 80;

			if(new_width > 1600){
				new_width = 1600;
			}
	
		$('parent_content').setStyle('width', new_width);
		 $('galerie').setStyle('margin-left', marge);
		 $('content_gallery').setStyle('width', new_width - marge);
		 $('galerie').setStyle('width', new_width - marge*2);
		 $('quit_button').setStyle('left', parseInt(new_width - marge*2, 10)+'px');
		 $('next_img').setStyle('left', parseInt(new_width - marge*2, 10)+'px');
		 var new_content_width = 300 + parseInt($('content_gallery').getSize().x) + parseInt($('box_infos').getSize().x);
		 $('content').setStyle('width', new_content_width );
		 var image_length = (new_width - marge*2)*$$('.gallery_img').length;
		 $('image').setStyle('width', image_length);
	
		 $$('.gallery_img').each(function(elt){
					$(elt).setStyle('width', new_width - marge*2);
			});
			
			if($('box_infos').getStyle('visibility') != 'hidden'){
				$('content').setStyle('margin-left', getMarginLeft(new_width, marge));
			}
			
			$('content').setStyle('width', $('galerie').getSize().x + $('box_infos').getSize().x+marge);
			
			$('previous_area').setStyle('width', (new_width - marge*2)/2);
			$('next_area').setStyle('width', (new_width - marge*2)/2);
			$('next_area').setStyle('left', marge+parseInt((new_width - marge*2)/2) + 'px');
			
			$('resa').setStyle('left', $('box_infos').getPosition().x - 126/2);
		}
}// fin initWidth


/*
*	retourne margin necessaire pour laisser les infos importantes centrées
*/
function getMarginLeft(new_width, marge){
	return -1*parseInt(new_width - marge, 10)+parseInt(new_width - 800, 10);
}


/*
*	initialisation des traitements js
*/
function init(){
	
		if(!checkIfOldMSIE() && $chk($('actu_scroll')) ){
		$('actu_scroll').addClass('scrollable');
		$$('.scrollable').each(function(el) {
				scrollbar = new Scrollbar(el);
																		});
	}
	// gestion du viewport :
		if($chk($('parent_content'))){
			$('parent_content').setStyle('width', $(window).getSize().x);
		}
		
			var new_height = $(window).getSize().y - $('footer').getSize().y - $('header').getSize().y;
			
			 if(new_height > 300){
						initHeight(new_height);
			 }
			 
			 var new_width = $(window).getSize().x;
			 if(new_width > 700){
						initWidth(new_width);
			 }
		
		 // initialisation de la galerie;
		 if($chk($('content_gallery'))){
			 var gallery_size = $$('.gallery_img').length;
			 var boxSlider = new BoxSlider('image', 'previous_img', 'next_img', 'quit_button', gallery_size-3, $('galerie').getSize().x);
			}
		
		 $(window).addEvent('resize', function(evt){
					 // redimensionnement de la hauteur																 
					 var new_height = $(window).getSize().y - $('footer').getSize().y - $('header').getSize().y;
						 if(new_height > 450){
						initHeight(new_height);
						}
						
					// redimensionnement de la largeur
					var new_width = $(window).getSize().x;
					if(new_width > 700 ){
						 if(new_width > 1600){
								new_width = 1600; 
						 }
						 if(boxSlider){
							boxSlider.setScrollWidth(new_width-160);
							initWidth(new_width);
							if(boxSlider.getNum() == 0){
									$('image').setStyle('margin-left', 0);
							}else{
								var new_scroll = -1*parseInt( boxSlider.getScrollWidth() * boxSlider.getNum());
									$('image').setStyle('margin-left', new_scroll);
							}
						 }
					}
			 }.bindWithEvent(boxSlider));

		
	
	// affichage des images de la galerie

	if($chk($('parent_content'))){
		var parent_class = $('parent_content').getProperty('class');
		var path = null;
		switch(parent_class){
			case 'vitalite_content':
				path = 'brides';
			break;
			case 'spa_content':
			path = 'spa';
			break;
			case 'village_content':
			path = 'levillage';
			break;
			case 'troisvallees':
			path = 'nature';
			break;
			case 'sejour_content':
			path = 'sejour';
			break;
			case 'office_content':
			path = 'brides';
			break;
		/*	default:
			path = 'brides';
			break;*/
		}
		
		if(path){
				var i =1;
				$('image').getChildren().each(function(e){
				
				/*img.src = '../imgs/'+path+'/galerie/'+i+'.jpg';
					img.addEvent('load', function(evt){
							$(e).setStyle('background-image', 'url('+img.src+')');	
					}.bindWithEvent(e, img)
					);*/
					$(e).setStyle('background-image', 'url(../imgs/'+path+'/galerie/'+i+'.jpg)');
					i++;
				});
		}
	}
	
	/* page d'accueil de chaque rubrique : initialisation pour la gestion des infos en ajax */
	// on n'affiche les scrollbar js que si on est > msie6
	if(!checkIfOldMSIE() && $chk($('box_texte')) ){
		$('box_texte').addClass('scrollable');	
	}
	
	if(!checkIfOldMSIE() && $chk($('actu_scroll')) ){
		$('actu_scroll').addClass('scrollable');
		$$('.scrollable').each(function(el) {
				scrollbar = new Scrollbar(el);
																		});
	}
	
	if( $chk($('box_menu_list')) ){
		$('box_menu_list').getChildren().each(function(e){
		e.getChildren().each(function(elt){					   
				if(elt.hasClass('lien_info') ){
					elt.addEvent('click', displayTxt);
				}
			});
		});
		$$('.scrollable').each(function(el) {
				var scroll = new Scrollbar(el);
		});
		
	}
	
	addPictoRollOver();

	// initialisation de la gallerie 
   if($chk($('galerie'))){
		// loadGallery();
		 
	   $('next_img').fade('hide');
	   $('previous_img').fade('hide');
	   $('quit_button').fade('hide');
	   var scroll_content = $('parent_content').get('class');
	   var tween_margin_left = -720;
		
	
		// affichage de la gallerie
		  $('to_gallery_button').addEvent('click', function(evt){
			evt.stop();
			$('to_gallery_button').fade('hide');
			$('logo').fade('hide');
			$('content').setStyle('width', parseInt($('content').getStyle('width').replace('px', ''))+300 );
			$('content').tween('margin-left', 0);
			$('resa').fade('hide');
			$(window).scrollbars = 'no';
			
			$('box_infos').tween('margin-left', $('box_infos').get('margin-left')+300);
			$('box_infos').fade('out');
			boxSlider.displayGallery(); // affichage des boutons + activation des zones de gestion des fleches de défilement
			boxSlider.stopMove();
		}.bindWithEvent(boxSlider));
	
	
		// fermeture de la gallerie et affichage du menu
		$(boxSlider.quit_button).addEvent('click', function(evt){
			evt.stop();
			boxSlider.endDisplayGallery(); // les boutons sont cachés
			$('to_gallery_button').fade('show');
			$('logo').fade('show');
			$('content').tween('margin-left', tween_margin_left);
			$('content').setStyle('width', parseInt($('content').getSize().x ) );
			$('box_infos').tween('margin-left', $('box_infos').get('margin-left'-300));
						$('box_infos').fade('in');

			$('resa').fade('show');
			boxSlider.startMove();

		}.bindWithEvent(boxSlider));
		
		boxSlider.startMove();
   }// fin initialisationd de la gallerie
   
	 
	 // initialisation des rollover png
	 if(!checkIfOldMSIE()){
		 if($chk($('offre'))){
				$('offre').addEvent('mouseover', function(evt){
								var url = $('offre').getProperty('src').split('/');																		
							 $('offre').setProperty('src', url[0]+'/'+url[1]+'/'+url[2]+'/offre_over.png');
				});
				
				$('offre').addEvent('mouseout', function(evt){
								var url = $('offre').getProperty('src').split('/');																		
							 $('offre').setProperty('src', url[0]+'/'+url[1]+'/'+url[2]+'/offre_norm.png');
				});
		 }
		 
		 // pastille reservation rollover
		  if($chk($('resa'))){
				$('resa').addEvent('mouseover', function(evt){
							 $('resa').setProperty('src', 'imgs/elements/res_over.png');
				});
				
				$('resa').addEvent('mouseout', function(evt){
								var url = $('resa').getProperty('src').split('/');																		
							 $('resa').setProperty('src', 'imgs/elements/res_norm.png');
				});
		 }
		 
		  if($chk($('reservation'))){
				$('reservation').addEvent('mouseover', function(evt){
							 $('reservation').setProperty('src', 'imgs/elements/res_over.png');
				});
				
				$('reservation').addEvent('mouseout', function(evt){
								var url = $('reservation').getProperty('src').split('/');																		
							 $('reservation').setProperty('src', 'imgs/elements/res_norm.png');
				});
		 }
	 }
   
	 $$('.commerce').each(function(e){
					e.addEvent('click', getCommerceList);											 
		});
	 

   // initialisation des rollover des menus du "box_menu_list_menu"
   // + on selectionne le premier menu
   var cnt_menu = 0;

   if($('box_menu_list')) {
    $$('.box_menu_list_menu').each(function(el) { 

          cnt_menu++;
					
          if(cnt_menu == 1) {
            el.setStyle("background-position", "bottom left");
            CURRENT_BOX_MENU_SELECTED = el.id;
          }
      
          el.addEvent('mouseout', function(evt) {
            if((evt.target).id != CURRENT_BOX_MENU_SELECTED) {
              (evt.target).setStyle("background-position", "top left");
            }
          });
          
          el.addEvent('mouseover', function(evt) {
            (evt.target).setStyle("background-position", "bottom left");
          });  

          el.addEvent('click', function(evt) {
								checkSelected(evt.target);															
          }); 
          
       }
    );
   }
	 
	 addSelectSousMenu();


	// homepage : gestion de la taille de la div actualité : dès qu'une actu dépasse, on coupe la div de manière à ne pas l'afficher
	initDivActu();
	
	
	
		// gestion du formulaire d'hebergement
		$$('.form_brides').each(function(e){
					e.addEvent('submit', checkHebForm);								
			});
		
}// fin init


function initDivActu(){
		if($chk($('actu_scroll0'))){
			if( navigator.appName == 'Microsoft Internet Explorer' && ( getMsieVersion() == 6 || getMsieVersion() == 7) )
			{
					if( window.getSize().y < 644){
							var length = $('liste_actu').getChildren()[0].getSize().y;
							$('actu_scroll0').setStyle('height', length);
					}
			}else{
					var MAX = $('actu_scroll0').getSize().y;
					var size = 0;
					var espace = 8;

					$('liste_actu').getChildren().each(function(elt){
								if(MAX < size + elt.getSize().y){
										$('actu_scroll0').setStyle('height', size);
										return;
								}
								size += elt.getSize().y+espace;
					});
			}
		}
}


/*
*	gestion du sous menu (select/pas select) et du titre png lorsqu'on accede à une sous rubrique par l'url
*/
function addSelectSousMenu(){
	 // si on affiche la page avec une url possedant des variables :
	 // maj du lien du sous-menu
	 // maj du sous titre
	var page_url = null;
	var rub = '';
	 if(document.location.href.match('/?/')){
		 var values = new Array();
			var query = document.location.href.split('?');
			if(query[1]){
					query[1].split('&').each(function(e){
									var q = e.split('=');																																	
									if(q[0] == 'rub'){
											rub = q[1];
											page_url = 'fr';
											page_url += query[0].split('fr')[1].replace('index.php', '')+rub+'.php';
									}
					});
			}
	 }
	 
	 if(page_url){
		 var replaced = false; 
		 
		 $$('.lien_info').each(function(elt){								
					if($(elt).getProperty('href') == page_url){
							checkSelected(elt.getFirst());
							var new_src = $('current_cat').get('src').split('/');
							new_src[new_src.length-1] = rub+'.png';
							$('current_cat').set('src', new_src.join('/'));
							replaced = true;
					}
		 });
			
			// on n'a pas trouvé le paramètre : on met la page 1 par defaut
			if(!replaced){
					var elt = $$('.lien_info')[0];
					checkSelected(elt.getFirst());
					rub = elt.href.split('/');
					var new_rub = rub[rub.length-1].split('.');
					var new_src = $('current_cat').get('src').split('/');
					new_src[new_src.length-1] = new_rub[0]+'.png';
					$('current_cat').set('src', new_src.join('/'));
			}
		
	 }
}


/*
*		gestion du sous menu pour chgment couleur au survol et sur click
*/
function checkSelected(elt){
		if(CURRENT_BOX_MENU_SELECTED != "") {
			$(CURRENT_BOX_MENU_SELECTED).setStyle("background-position", "top left");
		}
		CURRENT_BOX_MENU_SELECTED = $(elt).id;
				$(elt).setStyle("background-position", "bottom left");
}




/*
*	affichage des commerces en ajax
*/
function getCommerceList(evt){
	
	var newBox = new Element('div', {id : 'box_texte'});
	if(!checkIfOldMSIE()){
		$(newBox).addClass('scrollable');
	}
	var loader = new Element('img', {id: 'box_texte_ajax_loader', src:'../imgs/loader/ajax_loader.gif', alt:'ajax_loader'});
	$(newBox).grab(loader);
	$(newBox).replaces($('box_texte'));
	
	evt.stop();
	
	var url = $(evt.target ).getProperty('href');
	var req = new Request.HTML({
		method: 'get',
		url: url,
		noCache : true,
		evalScripts :true
	}).send();
	
	req.addEvent('success', displayTxtSuccess);

	req.addEvent('failure', function(xhr){
		if($chk($('box_texte')) ){			
			updateErrorTxt('failure');
		}	
	});
	
	req.addEvent('exception', function(headerName, value){
		if($chk($('box_texte')) ){			
			updateErrorTxt('exception');
		}
	});
}


/*
*	affichage d'une fiche hotel en ajax
*/
function getHotelList(evt){
	var newBox = new Element('div', {id : 'box_texte'});
	if(!checkIfOldMSIE()){
		$(newBox).addClass('scrollable');
	}
	var loader = new Element('img', {id: 'box_texte_ajax_loader', src:'../imgs/loader/ajax_loader.gif', alt:'ajax_loader'});
	$(newBox).grab(loader);
	$(newBox).replaces($('box_texte'));
	
	evt.stop();
	var url = $(evt.target.getParent()).getProperty('href');
	
	var req = new Request.HTML({
		method: 'get',
		url: url,
		noCache : true,
		evalScripts :true
	}).send();
	
	req.addEvent('success', displayTxtSuccess);

	req.addEvent('failure', function(xhr){
		if($chk($('box_texte')) ){			
			updateErrorTxt('failure');
		}	
	});
	
	req.addEvent('exception', function(headerName, value){
		if($chk($('box_texte')) ){			
			updateErrorTxt('exception');
		}
	});
}


/* pagination de la liste des hotels */
function getNextHebList(evt){
	var newBox = new Element('div', {id : 'box_texte'});
	
	if(!checkIfOldMSIE()){
		$(newBox).addClass('scrollable');
	}
	var loader = new Element('img', {id: 'box_texte_ajax_loader', src:'../imgs/loader/ajax_loader.gif', alt:'ajax_loader'});
	$(newBox).grab(loader);
	$(newBox).replaces($('box_texte'));
	
	evt.stop();
	var tmpUrl = $(evt.target).getProperty('href').split('?');

	var req = new Request.HTML({
		method: 'post',
		url: tmpUrl[0],
		noCache : true,
		evalScripts :true,
		data : tmpUrl[1]
	}).send();
	
	req.addEvent('success', displayTxtSuccess);

	req.addEvent('failure', function(xhr){
		if($chk($('box_texte')) ){			
			updateErrorTxt('failure');
		}	
	});
	
	req.addEvent('exception', function(headerName, value){
		if($chk($('box_texte')) ){			
			updateErrorTxt('exception');
		}
	});
}


/* gestion de la div #box_texte */
/* MAJ des infos sur click d'un lien de la liste #box_menu_list
*/
function displayTxt(evt){	
	displayLoader();

	evt.stop();
  
	var url = $(evt.target ).getParent().getProperty('href');
	var param = 'ajax=1';
	var req = new Request.HTML({
		method : 'post',
		url: url,
		data: 'ajax=true',
		noCache : true,
		evalScripts :true
	}).send();
	
	var path = url.split('/');
	$('current_cat').setProperty('src', '/imgs/'+path[1]+'/elements/'+path[2].replace('.php', '')+'.png');

	req.addEvent('success', displayTxtSuccess);
	
	req.addEvent('failure', function(xhr){
		if($chk($('box_texte')) ){			
			updateErrorTxt('failure');
		}	
	});
	
	req.addEvent('exception', function(headerName, value){
		if($chk($('box_texte')) ){			
			updateErrorTxt('exception');
		}
	});
} // fin displayTxt


/*
* fonction de maj de la div contenant les infos
*/

function displayTxtSuccess(responseTree, responseElements, responseHTML, responseJavaScript){
		if($chk($('box_texte')) ){
			var newBox = $('box_texte').clone(true, true);
			newBox.set('text', '');
			newBox.adopt(responseTree);	
			
			var gParent = null;
			if(!checkIfOldMSIE()){
				gParent = $('box_texte').getParent().getPrevious();
			}
			else{
				gParent = $('box_texte').getPrevious();
			}

			$(gParent).getNext().dispose();
			$(newBox).inject(gParent, 'after');
			initHeight($(window).getSize().y - $('footer').getSize().y - $('header').getSize().y);
			
			if($chk($('reservation_form_id'))){
						myCal = new Calendar({ arrivee_jour: 'd/m/Y' } );
						myCal2 = new Calendar({ depart_jour: 'd/m/Y' } );
			}
			
			if(!checkIfOldMSIE()){
				var scroll = new Scrollbar(newBox);
			}
		}else{
					initHeight($(window).getSize().y - $('footer').getSize().y - $('header').getSize().y);
		}
		addPictoRollOver();
		
		initEvent();
		
		delete FancyForm.initing;
		FancyForm.start();
}






/*
* maj du texte si la requête ajax n'aboutie pas
*/
function updateErrorTxt(errorType){	
	var newBox = new Element('div', {id : 'box_texte'});
	var title = new Element('h4');
		title.appendText('Erreur de chargement');
	var content = new Element('p');
		content.appendText('La page demandée est actuellement indisponible.');
		content.grab(new Element('br'));
		content.appendText('Merci de rééssayer plus tard.');
	$(newBox).grab(title);
	$(newBox).grab(content);
	//newBox.replaces($('box_texte'));
	if(!checkIfOldMSIE()){
		gParent = $('box_texte').getParent().getPrevious();
		$(newBox).addClass('scrollable');
	}
	else{
		gParent = $('box_texte').getPrevious();
	}

	$(gParent).getNext().dispose();
	$(newBox).inject(gParent, 'after');
	if(!checkIfOldMSIE()){
		var scroll = new Scrollbar(newBox);
	}	
} // fin updateErrorTxt



/*
*	gestion des erreurs dans les requetes ajax
*/
function addErrorXHRRequest(req){
	req.addEvent('failure', function(xhr){
		if($chk($('box_texte')) ){			
			updateErrorTxt('failure');
		}	
	});
	
	req.addEvent('exception', function(headerName, value){
		if($chk($('box_texte')) ){			
			updateErrorTxt('exception');
		}
	});
}



/*
*	ajout des infos sur survol d'un picto
*/
function addPictoRollOver(){
	// légende pour les pictos
	if($chk($("form_hebergement"))){
		$$('.form_bienetre').each(function(e){
			e.addEvent('mouseover', function(evt){
				$('form_bienetre_info').set('html',$(evt.target).getProperty('alt'));				 
			});
			e.addEvent('mouseout', function(evt){
				$('form_bienetre_info').set('html', '&nbsp;');						 
			});
		});
		
		$$('.form_confort').each(function(e){
			e.addEvent('mouseover', function(evt){
				$('form_confort_info').set('html',$(evt.target).getProperty('alt'));				 
			});
			e.addEvent('mouseout', function(evt){
				$('form_confort_info').set('html', '&nbsp;');						 
			});
		});
		
		$$('.form_equip_log').each(function(e){
			e.addEvent('mouseover', function(evt){
				$('form_equip_log_info').set('html',$(evt.target).getProperty('alt'));				 
			});
			e.addEvent('mouseout', function(evt){
				$('form_equip_log_info').set('html', '&nbsp;');						 
			});
		});
			
		$$('.form_equip_com').each(function(e){
			e.addEvent('mouseover', function(evt){
				$('form_equip_com_info').set('html',$(evt.target).getProperty('alt'));				 
			});
			e.addEvent('mouseout', function(evt){
				$('form_equip_com_info').set('html', '&nbsp;');						 
			});
		});
	}
}


/*
*	retourne un tableau contenant des chaines de caractÃ¨res 'nom_champ=valeur_champ' pour tous les champs du formulaire de l'id 'formId'
*/

var  getValuesFromValues = new Array();
var deepValuesFromForm;

function getValuesFromForm(formId) {
	getValuesFromValues = new Array();
	var deepValuesFromForm = 1;
	myelm = $(formId);
	getValuesFromFormRecursive(myelm, deepValuesFromForm);	
	return getValuesFromValues;
}

function getValuesFromFormRecursive(myelm, deepValuesFromForm){
   // var elts = document.forms[formId].elements;
	//var elts = document.forms[0].elements;
	//alert(deep + " " + myelm.id);
   	if(deepValuesFromForm >30){
				return;
		}
    //$$(elts)
		$(myelm).getChildren().each(function(e){
 				if(e.get('tag') == 'input'){
            if(e.type == 'checkbox'){
                if(e.checked){
                    getValuesFromValues.push(e.name+'='+'1');
                }else{
                    getValuesFromValues.push(e.name+'='+'0');
                }
            }else if(e.type == 'text' || e.type =='password' || e.type =='hidden'){
                getValuesFromValues.push(e.name+'='+e.value);
            }else if(e.type == 'radio' && e.checked){
									getValuesFromValues.push(e.name+'='+e.value);
						}
            // ajouter gestion radio

        }else if(e.get('tag') =='select'){
            $$(e.options).each(function(elts){
                if(elts.selected){
                     getValuesFromValues.push(e.name+'='+e.value);
                }
            });
        }else if(e.get('tag') == 'textarea'){
						getValuesFromValues.push(e.name+'='+e.value);
				}
				
				getValuesFromFormRecursive(e, (deepValuesFromForm+1));
				
    });

    //return values;
}


/*
*
*/
function checkHebForm(evt){
  var data = getValuesFromForm('form_hebergement').join('&');
	displayLoader();
	
    evt.stop();

		var url = evt.target.action;
    var req = new Request.HTML({
        method : 'post',
        url : url,
        data : data+'&ajax=1',
				noCache : true,
        evalResponse : true
    });
    req.send();

    req.addEvent('success', displayTxtSuccess);
  
   	addErrorXHRRequest(req);
}


/*
*	affichage de la page suivante / precedente dans la pagination
*/

function checkHebFormFromList(evt){
	displayLoader();
		
	if($(evt.target).get('tag') == 'a'){
		var temp_url = $(evt.target).getProperty('href').split('?');

		evt.stop();
		var req = new Request.HTML({
					method : 'post',
					url : temp_url[0],
					data : temp_url[1],
					noCache : true,
					evalResponse : true
			});
			req.send();
	
			req.addEvent('success', displayTxtSuccess);
		
			addErrorXHRRequest(req);
	}
}


/*
*	affichage d'une fiche etab
*/
function checkFiche(evt){
		displayLoader();
		
	if($(evt.target).get('tag') == 'a'){
		var temp_url = $(evt.target).getProperty('href').split('?');
	}else{
				var temp_url = $(evt.target).getParent().getProperty('href').split('?');
	}

		evt.stop();
		var req = new Request.HTML({
					method : 'post',
					url : temp_url[0],
					data : temp_url[1],
					noCache : true,
					evalResponse : true
			});
			req.send();
	
			req.addEvent('success', displayTxtSuccess);
		
			addErrorXHRRequest(req);
}


function addDisplayHebForm(evt){
	evt.stop();
	displayLoader();

	if($(evt.target).get('tag') == 'a'){
		var temp_url = $(evt.target).getProperty('href').split('?');
	}else{
				var temp_url = $(evt.target).getParent().getProperty('href').split('?');
	}

    var req = new Request.HTML({
        method : 'post',
        url : temp_url[0],
        data : temp_url[1],
				noCache : true,
        evalResponse : true
    });
		
		req.send();
    req.addEvent('success', displayTxtSuccess);
   	addErrorXHRRequest(req);
}



/*
*		fonctions de controle du formulaire
*/
function initResForm(){
	$('nb_enfants').addEvent('keydown', update_nb_enfants);
	$('nb_enfants').addEvent('keyup', update_nb_enfants);
}
// ????
function update_nb_enfants(nb){
dest = $('age_enfants');
dest.innerHTML = "";
	for(var i=0;i<nb;i++){
		my_select = Array();
		//my_select[i] = document.createElement("textarea");
		my_select = document.createElement("SELECT");
		my_select.setAttribute("name", 'age_enfant['+i+']');
		my_select.setAttribute("class", "select_small");
		//my_select.name = 'age_enfant_'+i+'';
		my_select.id = 'age_enfant['+i+']';
		
		for(j=1;j<19;j++){
			my_options = document.createElement("OPTION");
			my_options.value = j;
			an = ' an';
			if(j != 1) an = an + 's';
			my_options.innerHTML = j + an;
			//my_options.innerHTML = j;
			my_select.appendChild(my_options);
		}				
		dest.appendChild(my_select);
		space = document.createElement("span");
		space.innerHTML = "<br>";
		dest.appendChild(space);
	}
		if(nb>0) {
			if(document.getElementById("tr_age_enfants").style.display == "none") {
				document.getElementById("tr_age_enfants").style.display = '';
			}
		} else {
			if(document.getElementById("tr_age_enfants").style.display == "") {
				document.getElementById("tr_age_enfants").style.display = 'none';
			}
		}
}



/*
*	initialisation du calendrier pour le formulaire d'hbergement
*/
function initCalendar(){/*
		new CalendarEightysix('arrivee_jour',	 {
			'pickFunction': function(date) {
				$('arrivee_mois').set('value', date.get('month') + 1);
				$('arrivee_annee').set('value', date.get('year'));
			},
			'linkWithInput': false, 
			'defaultDate': '1/1/2010', 
			'minDate': '1/1/2010', 
			'maxDate': '12/31/2014', 
			'format': '%d', 
			'toggler': 'exampleIX-picker', 
			'offsetY': -4, 
			'offsetX': 76
		});*/
		/*
		MooTools.lang.set('fr-FR', 'Date', {
			months:    ['Januari', 'Februari', 'Maart', 'April', 'Mei', 'Juni', 'Juli', 'Augustus', 'September', 'Oktober', 'November', 'December'],
			days:      ['Zondag', 'Maandag', 'Dinsdag', 'Woensdag', 'Donderdag', 'Vrijdag', 'Zaterdag'],
			dateOrder: ['date', 'month', 'year', '/']
		});
		
		MooTools.lang.set('de-DE', 'Date', {
			months:    ['Januar', 'Februar', 'M&auml;rz', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember'],
			days:      ['Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag'],
			dateOrder: ['date', 'month', 'year', '/']
		});*/
}




/*
*	MAJ box_texte avec le loader en attendant retour req ajax
*/
function displayLoader(){
	var newBox = new Element('div', {id : 'box_texte'});
	if(!checkIfOldMSIE()){
		$(newBox).addClass('scrollable');
	}
	var loader = new Element('img', {id: 'box_texte_ajax_loader', src:'imgs/loader/ajax_loader.gif', alt:'ajax_loader'});
	$(newBox).grab(loader);
	$(newBox).replaces($('box_texte'));
}


/*
*	formulaire de reservation
*/
function addReservationForm(evt){
		var data = getValuesFromForm('reservation_form_id').join('&');
		displayLoader();
	
    evt.stop();
		var url = evt.target.action;

    var req = new Request.HTML({
        method : 'post',
        url : url,
        data : data+'&ajax=1',
        evalResponse : true,
				noCache : true
    });
    req.send();

    req.addEvent('success', displayTxtSuccess);
  
   	addErrorXHRRequest(req);
}


/*
*	ajout des ecouteurs
*/
function initEvent(){
		$$('.commerce').each(function(e){
					e.addEvent('click', getCommerceList);											 
		});
			 
	 $$('.scroll_handler_bkg').each(function(e){
						$(e).setStyle('left', ($('box_texte').getSize().x - 70)+'px');		 
		});

	 $$('.list_hebergements').each(function(e){
				e.addEvent('click', checkHebFormFromList);
		});

		$$('.hotel_list').each(function(e){
				e.addEvent('click', checkFiche);
		});

		
		$$('.form_brides').each(function(e){
				e.addEvent('submit', checkHebForm);								
		});

		$$('.lien_res').each(function(e){
					e.addEvent('click', addDisplayHebForm);		
		});
		
		$$('.reservation_form').each(function(e){
				e.addEvent('submit', addReservationForm)
		});
}




//Fonction modifiée pour afficher le popup au centre de l'écran
function openCenteredWindow(theURL,winName,width,height,features) { //v2.0
	var top=(screen.height-height)/2;
    var left=(screen.width-width)/2;
	window.open(theURL,winName,"top="+top+",left="+left+",width="+width+",height="+height+","+features);
}

window.addEvent('domready', init);