var Common = {
	fermerEdito: function (){
		var myVerticalSlide = new Fx.Slide('top');
		myVerticalSlide.slideOut();
	},
	
	// moteur
	
	rechargerMoteur: function(){
		$('formulaire_details').set('send', {
			url: 'index.php?action=ajax_moteur',
			method: 'get',
			onSuccess : function (response) {
				if ( response!="") {
					//console.log(response);
					Common.hideLoading('');
					$('cadre_moteur').innerHTML = response;
				}
			},
			onFailure: function () {
				//alert('erreur dans l\'application');
			},
			onRequest : function () {
					Common.showLoading('process_resa');
			}
		});
		$('formulaire_details').send();
	},
	rechargerMoteurVol: function(){
		$('formulaire_details').set('send', {
			url: 'index.php?action=ajax_moteur_vol',
			method: 'get',
			onSuccess : function (response) {
			if ( response!="") {
				//console.log(response);
				Common.hideLoading('');
				$('cadre_moteur').innerHTML = response;
			}					
		},
		onFailure: function () {
			//alert('erreur dans l\'application');
		},
		onRequest : function () {					
			Common.showLoading('process_resa');
		}
		});
		$('formulaire_details').send();
	},
	chargerMoteur: function(type){
		$('formulaire_cache').set('send', {
			url: 'index.php?action=ajax_moteur',
			method: 'get',
			onSuccess : function (response) {
				if ( response!="") {
					//console.log(response);
					//Common.hideLoading('');
					$('cadre_moteur').innerHTML = response;
				}					
			},
			onFailure: function () {
				//alert('erreur dans l\'application');
			},
			onRequest : function () {
				if(type == 'affichage_home') {
					var loadMoteur = new Element('img', {
						'id'    : 'loadMoteur',
						'src'	: '/templates/cwt/images/attente.gif',
						'styles': {
					      'width'	:	'250px',
					      'height'	:	'250px'
						}
					});
				}else {				
					var loadMoteur = new Element('img', {
						'id'    : 'loadMoteur',
						'src'	: '/templates/cwt/images/gif_attente_moteur.gif',
						'styles': {
					      'width'	:	'160px',
					      'height'	:	'193px'
						}
					});					
				}
				loadMoteur.inject($('cadre_moteur')) ;
				//Common.showLoading('');
			}
		});
		$('formulaire_cache').send();
	},
	chargerMoteurVol: function(type){
		$('formulaire_cache').set('send', {
			url: 'index.php?action=ajax_moteur_vol',
			method: 'get',
			onSuccess : function (response) {
			if ( response!="") {
				//console.log(response);
				$('cadre_moteur').innerHTML = response;
				Autocompleter_vol();
				Vol.calendrier();
			}					
		},
		onFailure: function () {
			alert('erreur dans l\'application');
		},
		onRequest : function () {					
			//Common.showLoadingMoteur('');
		}
		});
		$('formulaire_cache').send();
	},
	chargerMoteurForfait: function(type){
		$('formulaire_cache').set('send', {
			url: 'index.php?action=ajax_moteur_forfait',
			method: 'get',
			evalScripts:true,
			onSuccess : function (response) {
				if ( response!="") {
					//alert('test');
					//console.log(response);
					$('cadre_moteur').innerHTML = response;
					Autocompleter_vol();
					Forfait.calendrier();
				}					
			},
			onFailure: function () {
				//alert('erreur dans l\'application');
			},
			onRequest : function () {
				if(type == 'affichage_home') {
					var loadMoteur = new Element('img', {
						'id'    : 'loadMoteur',
						'src'	: '/templates/cwt/images/attente.gif',
						'styles': {
					      'width'	:	'250px',
					      'height'	:	'250px'
						}
					});
				}else {
					var loadMoteur = new Element('img', {
							'id'    : 'loadMoteur',
							'src'	: '/templates/cwt/images/gif_attente_moteur.gif',
							'styles': {
						      'width'	:	'160px',
						      'height'	:	'193px'
							}
						});
				}
				loadMoteur.inject($('cadre_moteur')) ;
				//Common.showLoadingMoteur('');
			}
			});
		$('formulaire_cache').send();
	},
	rechercher: function(domaine, page_resultat){
		if(typeof(page_resultat)=='undefined'){
			Common.showLoading('recherche_moteur');
		} else {
			Common.showLoading('');
		}
		if(typeof(domaine)=='undefined'){
			domaine = '';
		}
		$('formulaire_details').action = domaine+"index.php";
		$('mode_page').innerHTML = '<input type="hidden" name="page" value="resultat" />';
		$('formulaire_details').method="get";
		$('formulaire_details').submit();
	},
	rechercherVol: function(){
		var frm_id='';
		if (document.getElementById('moteur_left')) {
			frm_id='moteur_left';
		} else {
			frm_id='moteur_vol';
		}
		$(frm_id).set('send', {
			url: 'index.php?action=interrogation_catalogue_vol',
			method: 'get',
			onSuccess : function (response) {
				if ( response!="") {
					eval(response);
					//Common.hideLoading();
				}					
			},
			onFailure: function () {
				Common.hideLoading();
			},
			onRequest : function () {				
				Common.showLoading('recherche_moteur');
			}
		});
		$(frm_id).send();
	},
	rechercherVolPush: function(filtre,domaine){
		var myRequest = new Request({
			method: 'get', 
			url: domaine+'index.php?action=interrogation_catalogue_vol',
			onSuccess : function (response) {
				if ( response!="") {
					//console.log(response);
					//alert(response);
					eval(response);
					//Common.hideLoading();
				}					
			},
			onFailure: function () {
				//alert('erreur dans l\'application');
			},
			onRequest : function () {					
					//Common.showLoadingMoteur('');
				Common.showLoading('process_resa');
			}
		});
		myRequest.send(filtre);
	},
	rechercherForfait: function(){
		$('moteur_forfait').set('send', {
			url: 'index.php?action=interrogation_catalogue_forfait',
			method: 'get',
			onSuccess : function (response) {
				//Common.hideLoading();
				if (response != "") {
					//console.log(response);
					eval(response);
				}					
			},
			onFailure: function () {
				//alert('erreur dans l\'application');
				Common.hideLoading();
			},
			onRequest : function () {		
				Common.showLoading('recherche_moteur');
			}
		});
		$('moteur_forfait').send();
	},
	rechercherAffinerForfait: function(){
		$('moteur_forfait_avancee').set('send', {
			url: 'index.php?action=interrogation_catalogue_forfait',
			method: 'get',
			onSuccess : function (response) {
				//Common.hideLoading();
				if (response != "") {
					//console.log(response);
					eval(response);
				}					
		},
		onFailure: function () {
			//alert('erreur dans l\'application');
		},
		onRequest : function () {		
			Common.showLoading('recherche_moteur');
		}
		});
		$('moteur_forfait_avancee').send();
	},
	rechercherForfaitPush: function(filtre,domaine){
		var myRequest = new Request({
			method: 'get', 
			url: domaine+'index.php?action=interrogation_catalogue_forfait',
			onSuccess : function (response) {
				if ( response!="") {
					//console.log(response);
					//alert(response);
					eval(response);
					//Common.hideLoading();
				}					
			},
			onFailure: function () {
				//alert('erreur dans l\'application');
			},
			onRequest : function () {					
					//Common.showLoadingMoteur('');
				Common.showLoading('process_resa');
			}
		});
		myRequest.send(filtre);
	},
	redirect: function(get){
		alert(get);
		window.location.href('index.php?'+get);
	},
	changeCritere: function(obj,nom){
		var critere_changed = "";
		critere_changed = obj.name.replace('filtre[','');
		critere_changed = critere_changed.replace(']','');
		
		var critere_value = $('filtre_old_'+nom).value;
		$('last_critere_name').value = critere_changed;
		$('last_critere_value').value = critere_value;
		$('num_page_moteur').value = "";
		$('tri_moteur').value = "";
	},
	getIEVersionNumber: function() {
	    var ua = navigator.userAgent;
	    var MSIEOffset = ua.indexOf("MSIE ");
	    
	    if (MSIEOffset == -1) {
	        return 0;
	    } else {
	        return parseFloat(ua.substring(MSIEOffset + 5, ua.indexOf(";", MSIEOffset)));
	    }
	},
	centerPopup: function(element,parent) {
		var height=document.getElementById(element).offsetHeight;//hauteur de l'élément à positionner
		var width=document.getElementById(element).offsetWidth;//largeur de l'élément à positionner
		if(parent == "body"){
			myParent=document.body;
		}else{
			myParent=document.getElementById(element).parentNode;
		}
		var pHeight=myParent.offsetHeight;//Hauteur de l'élément parent
		var pWidth=myParent.offsetWidth;//Largeur de l'élément parent
		var sTop=myParent.scrollTop;//Hauteur de défilement de l'élément parent
		var sLeft=myParent.scrollLeft;//Longueur de défilement de l'élément parent
		var posY=(pHeight/2)-(height/2)+sTop;//Calcul de la position en Y
		var posX=(pWidth/2)-(width/2)+sLeft;//Calcul de la position en X
		document.getElementById(element).style.top=posY+"px";
		document.getElementById(element).style.left=posX+"px";
	},	
	
	// page r�sultat
	
	checkTri: function(tri){
		if($('tri_moteur')){
			$('tri_moteur').value=tri;
			$('num_page_moteur').value="1";
			Common.rechercher('');
		}
	},
	checkPage: function(num_page){
		if($('num_page_moteur')){
			$('num_page_moteur').value = num_page;
			Common.rechercher('', 'changePage');
		}
	},
	getSejour: function(id_sejour){
		var newUrl = self.location.href;
		newUrl = newUrl.replace("page=resultat","page=sejour");
		document.location.href = newUrl + "&id_sejour="+id_sejour;
	},
	imprimerDevis: function(){
		//alert("imprimer");
		window.print();
	},
	getDispo: function(){
		var sejour = $('id_sejour').get('value');
		
		// Rechercher si ce séjour est une simulation ou non
		new Request({
			url: 'index.php?action=resa_simulation', 
			method: 'post',
			data: 'id_sejour='+sejour,
			onRequest : function () {					
				Common.showLoading('process_resa');
			},
			onSuccess: function(response) {
		    	if (response=='1')
		    	{
		    		$('page').value= 'choix_passagers_simulation';
		    		$('formulaire_resa').action = "index.php";
		    		$('formulaire_resa').method="get";
		    		$('formulaire_resa').submit();
		    	} else {
		    		$('formulaire_resa').set('send', {
		    			url: 'index.php?action=interrogation_quotation',
		    			method: 'get',
		    			evalScripts : true,
		    			onSuccess : function (response) {
	    					if (response!=""){
	    						eval(response);
	    						Common.hideLoading();
	    					}
		    			},
		    			onFailure: function () {
		    				alert('erreur dans l\'application');
		    			},
		    			onRequest : function () {
		    			}
		    		});
		    	}
		    	$('formulaire_resa').send();
			}
		}).send();
	},
	processReservation: function(){
		$('page').value= 'process_reservation';
		$('formulaire_resa').action = "index.php";
		$('formulaire_resa').method="get";
		$('formulaire_resa').submit();
	},
	hideLoading:function(style_page) {
		ieVersion = Common.getIEVersionNumber();
		if (ieVersion==6)
		{
			$$(".chp_recherche").each(function(el) {           
		        el.style.display = "";
		        //alert("fgd");
			});
			$$("#formReserver1").each(function(el) {           
		        el.style.display = "";
		        //alert("fgd");
			});
			$$('select').each(function(el) {           
		        el.style.display = "";
			});
		}
		if ($("attente")) {
			$("attente").dispose();
			if(style_page == "alone"){
				$("loadingHome").hide();
				$("loadingHome").dispose();
			}else{
				$("loading").hide();
				$("loading").dispose();
			}
		}
	},
	getIEVersionNumber:function() {
	    var ua = navigator.userAgent;
	    var MSIEOffset = ua.indexOf("MSIE ");
	    
	    if (MSIEOffset == -1) {
	        return 0;
	    } else {
	        return parseFloat(ua.substring(MSIEOffset + 5, ua.indexOf(";", MSIEOffset)));
	    }
	},
	showLoading:function(style_page, id_univers) {
		if(!$('loading')) {
			ieVersion = Common.getIEVersionNumber();
			if (ieVersion==6)
			{
				$$(".chp_recherche").each(function(el) {           
			        el.style.display = "none";
			        //alert("fgd");
				});
				$$("#formReserver1").each(function(el) {           
			        el.style.display = "none";
			        //alert("fgd");
				});
				$$('select').each(function(el) {           
			        el.style.display = "none";
				});
			}
			if(style_page != 'recherche_moteur') {
				Attente = new Element('div', {
					'id'    : 'attente',
					'styles': {
				      'display'           : '',
				      'position'          : 'absolute',
				      'opacity'           : 1,
				      'z-index'           : 10000,
				      'background-color'  : "#fff",
				      'height'            : '250px',
				      'width'             : '250px'
					}
				});
				
				var obj;
				if ($('searchForm')) {
					obj = $('searchForm');
				} else {
					obj = $('searchFormHome');
				}
				Attente.set('html', '<img src="/templates/cwt/images/attente.gif" />');
			} else {
				Attente = new Element('div', {
					'id'    : 'attente',
					'styles': {
				      'display'           : '',
				      'position'          : 'absolute',
				      'opacity'           : 1,
				      'z-index'           : 10000,
				      'background-color'  : "#fff",
				      'height'            : '460px',
				      'width'             : '638px'
					}
				});
				
				var obj;
				if ($('searchForm')) {
					obj = $('searchForm');
				} else {
					obj = $('searchFormHome');
				}
				loaderPrincipal.inject(Attente);
				if (id_univers) {
					new Request({
						url: 'index.php?action=loading&id_univers='+id_univers,
						method: 'get',
						async: false,
						onComplete: function(reponse) {
							Attente.innerHTML = reponse;
						}
					}).send();
				}
			}
			if(style_page == "alone"){
				OverlayHome = new Element('div', {
					'id'    : 'loadingHome',
					'styles': {
				      'display'           : 'none',
				      'position'          : 'absolute',
				      'top'               : '0',
				      'left'              : '0',
				      'z-index'           : 15000,
				      'background-color'  : "#fff",
				      'height'            : obj.getHeight() + 'px',
				      'width'             : obj.getWidth() + 'px'
					}
				});
				OverlayHome.injectInside(obj);
				Attente.injectInside($('loadingHome'));
				$("loadingHome").show();
			}else{
				Overlay = new Element('div', {
					'id'    : 'loading',
					'styles': {
				      'display'           : 'none',
				      'position'          : 'absolute',
				      'top'               : '0',
				      'left'              : '0',
				      'opacity'           : .75,
				      'z-index'           : 10000,
				      'background-color'  : "#fff",
				      'height'            : window.getScrollHeight() + 'px',
				      'width'             : window.getScrollWidth() + 'px'
					}
				});
				Overlay.injectInside(document.body);
				Attente.injectInside(document.body);
				Element.implement({  
					//implement show
					show: function() {
						this.setStyle('display','');
					},  
					//implement hide
					hide: function() {  
						this.setStyle('display','none');  
					} 
				});
				$("loading").show();
			}
			if(style_page == 'recherche_moteur') {
				$('loader_principal').setStyle('display',"block");	
				Common.remplirAttente();				
			}
			Common.centrerLoading();
		}
	},
	remplirAttente:function() {
		
		if ($('frm_search_hotel')) {
			var type_search=$('search_type').value;
			if (type_search=='poi') {
				$('attente_hotel_poi').style.display='';
				$('attente_hotel_adresse').style.display='none';
				$('search_libelle_attente').innerHTML=$('search_libelle').value;
			} else {
				$('attente_hotel_poi').style.display='none';
				$('attente_hotel_adresse').style.display='';
				$('search_adresse_attente').innerHTML=$('search_adresse').value;
				$('search_ville_attente').innerHTML=$('search_ville').value;
				$('search_cp_attente').innerHTML=$('search_cp').value;
				var index = $('search_pays').selectedIndex;
				$('search_pays_libelle_attente').innerHTML= $$('#search_pays option')[index].innerHTML;
			}
		}
		if($('recherche_de')) {
			if($('ville_depart')) {
				$('recherche_de').innerHTML = $('ville_depart').value;
			} else if($('departurecity')) {
				var index = $('departurecity').selectedIndex;
				$('recherche_de').innerHTML = $$('#departurecity option')[index].innerHTML;
			}else if($('LOC')) {
				var index = $('LOC').selectedIndex;
				$('recherche_de').innerHTML = $$('#LOC option')[index].innerHTML;
			}
		}
		if($('recherche_vers')) {
			if($('destination')) {
				$('recherche_vers').innerHTML = $('destination').value;
			} else if($('DESSEJ')) {
				var index = $('DESSEJ').selectedIndex;
				$('recherche_vers').innerHTML = $$('#DESSEJ option')[index].innerHTML;
			}else if($('LOC')) {
				var index = $('LOC').selectedIndex;
				if($('LOC2')){
					var index2 = $('LOC2').selectedIndex;
					$('recherche_vers').innerHTML = $$('#LOC2 option')[index2].innerHTML + ' ' + $$('#LOC option')[index].innerHTML;
				}else{
					$('recherche_vers').innerHTML = $$('#LOC option')[index].innerHTML;
				}
			}
		}
		
		if($('Depart')) {
			$('recherche_date_depart').innerHTML = $('Depart').value;
		} else if($('date_depart')) {
			$('recherche_date_depart').innerHTML = $('date_depart').value;
		} else if($('search_date_du')) {
			$('recherche_date_depart').innerHTML = $('search_date_du').value;
		} else if($('departure_date_day') && $('departure_date_month')) {
			var indexDep = $('departure_date_day').selectedIndex;
			var indexRet = $('departure_date_month').selectedIndex;
			$('recherche_date_depart').innerHTML = $$('#departure_date_day option')[indexDep].innerHTML +' '+ $$('#departure_date_month option')[indexRet].innerHTML;
		}
		
		if($('Retour')) {	
			$('recherche_date_retour').innerHTML = $('Retour').value;
		}else if ($('date_retour')) {
			$('recherche_date_retour').innerHTML = $('date_retour').value;
		}else if ($('search_date_au')) {
			$('recherche_date_retour').innerHTML = $('search_date_au').value;
		} else if($('flexibility')) {
			var index = $('flexibility').selectedIndex;
			$('recherche_date_retour').innerHTML = $$('#flexibility option')[index].innerHTML;
		}
		$('recherche_nb_people').innerHTML = '';
		if($('Adultes')) {
			$('recherche_nb_people').innerHTML += $('Adultes').value + ' adulte';
			if($('Adultes').value > 1) {
				$('recherche_nb_people').innerHTML += 's';
			}
		}
		if($('Enfants')) {
			$('recherche_nb_people').innerHTML += ', '+$('Enfants').value + ' enfant';
			if($('Enfants').value > 1) {
				$('recherche_nb_people').innerHTML += 's';
			}
		}
		if($('Bebes')) {
			$('recherche_nb_people').innerHTML += ', '+$('Bebes').value + ' bébé';
			if($('Bebes').value > 1) {
				$('recherche_nb_people').innerHTML += 's';
			}
		}
		
		if($('temps_restant')) {
			var tempsRestant = $('tempsRestant').value;
			var tmp = function () {
				if($('temps_restant') && tempsRestant > 1) {
					$('temps_restant').innerHTML = tempsRestant+' ';
					tempsRestant -= 1;
				} else {
					timer = $clear(timer);
				}
			}
			tmp();
			var timer = tmp.periodical(1000);
		}
	},
	centrerLoading:function() {
       if($('attente')) {
			var tailleLoading, talleWindow, nouvellePosition;
	        $('attente').setStyle('position', 'fixed');
	        if(Common.getIEVersionNumber() == 6) {
	        	$('attente').setStyle('position', 'absolute');
	        	//$(id_element).setStyle('left', documentElement.scrollTop+body.scrollTop);
	        }
	        // les x
	        tailleLoading = $('attente').getSize().y;
	        talleWindow = window.getSize().y;
	        nouvellePosition = (talleWindow - tailleLoading) / 2;
	        $('attente').setStyle('top', nouvellePosition+'px');
	        // les y
	        tailleLoading = $('attente').getSize().x;
	        talleWindow = window.getSize().x;
	        nouvellePosition = (talleWindow - tailleLoading) / 2;
	        $('attente').setStyle('left', nouvellePosition+'px');
       }
	},
	centrer:function(id_element) {
       if($(id_element)) {
			var tailleLoading, talleWindow, nouvellePosition;
	        $(id_element).setStyle('position', 'fixed');
	        if(Common.getIEVersionNumber() == 6) {
	        	$(id_element).setStyle('position', 'absolute');
	        	//$(id_element).setStyle('left', documentElement.scrollTop+body.scrollTop);
	        }
	        // les x
	        tailleLoading = $(id_element).getSize().y;
	        talleWindow = window.getSize().y;
	        nouvellePosition = (talleWindow - tailleLoading) / 2;
	        $(id_element).setStyle('top', parseInt(nouvellePosition)+'px');
	        // les y
	        tailleLoading = $(id_element).getSize().x;
	        talleWindow = window.getSize().x;
	        nouvellePosition = (talleWindow - tailleLoading) / 2;
	        $(id_element).setStyle('left', parseInt(nouvellePosition)+'px');
       }
	},
	inscrireNewsletter: function(){
		Sexy.confirm("Voulez-vous que l'adresse "+$('champNewsletter').value+" re&ccedil;oive la newsletter ?",{ 
			onComplete: 
			    function(result) {
			    	if(result){
						//On peut ajouter en db
						$('formInscription').set('send', {
						url: 'index.php?action=inscription_newsletter',
						method: 'post',
						onSuccess : function (response) {
							Common.hideLoading();
							var Sexy = new SexyAlertBox();
							if (response=="ok") {
								Sexy.error("Email correctement ajout&eacute;");
							} else {
								Sexy.error(response);
							}							
						},
						onFailure: function () {
							Common.hideLoading();
						},
						onRequest : function () {					
							Common.showLoading('process_resa');
						}
						});
						$('formInscription').send();
			    	}
				}
			});
	},
	controleInscription: function(){
		if($('formInscription')) {
			var myCheck = new FormCheck('formInscription', {
				submitByAjax: true,	
				display : {
					showErrors : 1,
		            indicateErrors : 1
		        },
		        alerts : {
		            required : 'Ce champs est obligatoire. Merci de remplir une valeur',
		            email : 'Merci de rentrer une adresse valide'
		        },
		        onAjaxSuccess : function(res) {
		        	Common.inscrireNewsletter();
		        }
		    });
		}
	},
	showDiaporama: function(id_sejour) {
		var myRequest = new Request({
			method: 'post', 
			url: 'index.php?action=diaporama',
			data: 'id_sejour='+id_sejour,
			onSuccess : function (response) {
				Common.hideLoading();
				Fond = new Element('div', {
					'id'	: 'fond',
					'styles': {
					  'display'           : 'block',
				      'position'          : 'absolute',
				      'top'               : '0',
				      'left'              : '0',
				      'opacity'           : .75,
				      'z-index'           : 9000,
				      'background-color'  : "#fff",
				      'height'            : window.getScrollHeight() + 'px',
				      'width'             : window.getScrollWidth() + 'px'
					}				
				});
				Fond.injectInside(document.body);
				Diaporama = new Element('div', {
					'id'    : 'diaporama',
					'styles': {
				      'display'           : '',
				      'position'          : 'relative',
				      'opacity'           : 1,
				      'z-index'           : 10000,
				      'background-color'  : "#fff"
					}
				});
				Diaporama.set('html', response);
				Diaporama.injectInside(document.body);
				var images = $$('.slideShowData');
			    var data = new Array();
				for(var i=0; i<images.length; i++) {
					data[i] = images[i].getAttribute('id');
				}
				var myShow = new Slideshow.KenBurns('show', data, { captions: false, controller: true, delay: 5000, duration: 2000, height: '', hu: '' });
			    Common.centrer('diaporama');
			    $('fermerDiapo').addEvent('click', function(){
			    	$('diaporama').destroy();
			    	$('fond').destroy();
			    	if(Common.getIEVersionNumber() == 6) {
				    	$$('select').each(function(el) {           
					        el.style.display = "";
						});
					}
			    });
			    if(Common.getIEVersionNumber() == 6) {
			    	$$('select').each(function(el) {           
				        el.style.display = "none";
					});
				}
			},
			onFailure: function () {
				alert('erreur dans l\'application');
			},
			onRequest : function () {
				Common.showLoading('process_resa');
			}
		});
		myRequest.send();
	},
	bloqueCtrlV : function (evt) {	
		if(evt.ctrlKey) {
			//Touche v ou V enfoncée
			if((evt.keyCode == 86) || (evt.keyCode == 118)) { 
				evt.returnValue = false;
			}
		}	
	},
	reloadAgence : function(){
		style_page = 'agence';
		var formSend = new Request.HTML({url:'index.php?action=findAgence&departement='+$('codeDepartement').value+'&ville='+$('nomVille').value+'&region='+$('codeRegion').value, 
			onSuccess: function(html) {
				//Clear the text currently inside the results div.
				$('recherche_agence').set('html', '');
				//Inject the new DOM elements into the results div.
				Common.hideLoading('');
				$('recherche_agence').adopt(html);
				ajaxLoad(0,{iconNumber:7})
			},
			onFailure: function() {
				$('agenceReload').set('text', 'The request failed.');
				Common.hideLoading('');
			},
			onRequest : function () {					
					Common.showLoading('process_resa');
				}		
		});
		formSend.send();
	},
	
	// Même fonction que reloadAgence, qui envoit en plus $display avec comme valeur moteur
	reloadAgenceMoteur : function(){
		style_page = 'agence';
		v_url = 'index.php?action=findAgence&display=moteur&departement='+$('codeDepartement').value+'&ville='+$('nomVille').value+'&region='+$('codeRegion').value;
		if($('code_to')){
			v_url += '&code_to='+$('code_to').value;
		}else{
			v_url += '&code_to=';
		}
		var formSend = new Request.HTML({url:v_url,  
			onSuccess: function(html) {
				//Clear the text currently inside the results div.
				$('blocRecherche').set('html', '');
				//Inject the new DOM elements into the results div.
				Common.hideLoading('');
				$('blocRecherche').adopt(html);
				ajaxLoadValider(0,{iconNumber:7});
			},
			onFailure: function() {
				$('recherche_agence').set('text', 'The request failed.');
				Common.hideLoading('');
			},
			onRequest : function () {					
					Common.showLoading('process_resa');
				}		
		});
		formSend.send();
	},
	reloadAgenceHome : function(){
		style_page = 'agence';
		var formSend = new Request.HTML({url:'ajax/findAgenceHome.php?departement='+$('codeDepartement').value+'&ville='+$('nomVille').value+'&region='+$('codeRegion').value, 
			onSuccess: function(html) {
			//Clear the text currently inside the results div.
			$('trouveragence').set('text', '');
			//Inject the new DOM elements into the results div.
			$('trouveragence').adopt(html);
			Common.hideLoading('');
		},
		onFailure: function() {
			$('trouveragence').set('text', 'The request failed.');
		},
		onRequest : function () {					
			Common.showLoading('process_resa');
		}		
		});
		formSend.send();
	},
	reloadMoteur : function (){
		style_page = 'agence';
		var formSend = new Request.HTML({url:'ajax/moteurAgence.php?departement='+$('codeDepartement').value+'&ville='+$('nomVille').value+'&region='+$('codeRegion').value, 
			onSuccess: function(html) {
				//Clear the text currently inside the results div.
				$('moteur').set('text', '');
				//Inject the new DOM elements into the results div.
				$('moteur').adopt(html);
				Common.hideLoading(style_page);
				ajaxLoad(0,{iconNumber:7})
			},
			onFailure: function() {
				$('moteur').set('text', 'The request failed.');
			},
			onRequest : function () {					
					Common.showLoading(style_page);
				}		
		});
		formSend.send();
	},

	rechercheAgenceHome: function(){
			//alert($('codeDepartement').title);
			document.location.href="index.php?page=resultat_recherche_agence&ville="+$('nomVille').value+"&departement="+$('codeDepartement').value+'&region='+$('codeRegion').value;

	},
	ajouterLoadingAHref: function (){
		$$('a').each(function(el) {
			if(el.getProperty('target') != '_blank') {
				el.addEvent('click', Common.showLoading);
			}
		});
	}
}
var loaderPrincipal;
window.addEvent('domready', function() {
	if($('depliable') && $('h3_cache')){
		$('h3_cache').fade('hide');
		$('depliable').addEvent('click', function(){
			if($('depliable').get('html') == 'En savoir plus'){
				$('h3_cache').style.display = 'block';
				setTimeout("$('h3_cache').fade('in');$('depliable').set('html', 'Masquer');",300);
			}else{
				$('h3_cache').fade('out');
				setTimeout("$('h3_cache').style.display = 'none';" +"$('depliable').set('html', 'En savoir plus');",500);
			}
		});
	}
	if($('edito_close')){
		$('edito_close').addEvent('click', Common.fermerEdito);	
	}
	if($('warning_msg')){
		msg=$('warning_msg').innerHTML;
		var Sexy = new SexyAlertBox();
		Sexy.error(msg);
	}

	Element.implement({  
		//implement show
		show: function() {
			this.setStyle('display','');
		},  
		//implement hide
		hide: function() {  
			this.setStyle('display','none');  
		} 
	});
	window.addEvent('resize', Common.centrerLoading);
	if($('SlideItMoo_outer')) {
		new SlideItMoo({
			overallContainer: 'SlideItMoo_outer',
			elementScrolled: 'SlideItMoo_inner',
			thumbsContainer: 'SlideItMoo_items',		
			itemsVisible:1,
			autoSlide: 5700,
			itemsSelector: '.MooItem',
			itemWidth: $$('.MooItem')[0].getSize().x,
			duration: 300,
			transition: Fx.Transitions.Sine.easeOut,
			showControls:1
		});
	}
	if($('loader_principal')) {
		loaderPrincipal = $('loader_principal').dispose();
	}
	Common.controleInscription();
});