/*--FUNCTIONS.JS--*/

/*--------------------------------------------------GENERICS-------------------------------------------------------------------*/
//Vider un textarea de formulaire prérempli
function textareaFocus(element, value){
	if($(element).html() == value){
		$(element).html('');
	}
}

//Vider un textarea de formulaire prérempli
function textareaBlur(element, value){
	if($(element).html() == ''){
		$(element).html(value);
	}
}

//Vider un champ de formulaire prérempli
function fieldFocus(element, value){
	if($(element).val() == value){
		$(element).val('');
	}
}

//Remplir un champ de formulaire vide, préalablement prérempli
function fieldBlur(element, value){
	if($(element).val() == ''){
		$(element).val(value);
	}
}

//Expandre le FOOTER
function moreInformation(element){
	if(typeof(element) != 'undefined'){
		if($(element).hasClass('expand')){
			$('#moreInformation').show();
			$(element).removeClass('expand').addClass('collapse');
		}
		else{
			$('#moreInformation').hide();
			$(element).removeClass('collapse').addClass('expand');
		}
	}
	else{
		$('#moreInformation').hide();
		$('#toolbar .otherLinks a.collapse').removeClass('collapse').addClass('expand');
	}
	
	return false;
}

//Fonction permettant de recaler la TOOLBAR sur IE6
function ie6FixedPos(divName){
	$(window).load(function(){
		var value = $(window).scrollTop() - $('#'+divName).height() + $(window).height();
		$('#'+divName).css('position', 'absolute').css('bottom', 'auto').css('top', value+'px');
	});
	$(window).scroll(function(){
		var value = $(window).scrollTop() - $('#'+divName).height() + $(window).height();
		$('#'+divName).css('top', value+'px');
	});
	$(window).resize(function(){
		var value = $(window).scrollTop() - $('#'+divName).height() + $(window).height();
		$('#'+divName).css('top', value+'px');
	});
}
/*--------------------------------------------------GENERICS-------------------------------------------------------------------*/

/*--------------------------------------------------GREYBOX-------------------------------------------------------------------*/
//greyBoxShow() : OUVERTURE GREYBOX
function greyBoxShow(mode, url, width, height, overflow){
	//On masque le champ SELECT CUSTOMIZé
	customSelectOptionHide();
	
	if(mode == 'ajax'){mode = 'get';}
	var config = {};
	if(typeof(height) != 'undefined'){
		config.height = height;
	}
	return greyBoxShowNew(url, width, mode, config);
}
var greyBoxDefaultConfig = {
	/*--Valeurs ci-dessous requises--*/
	top: 33,						//=> Décalage en PX du haut du document
	duration: 0.6,					//=> Durée totale de l'affichage
	opacity: 0.6					//=> Opacité du fond Overlay
	/*--Options supplémentaires--*/
	//height: 500,					//=> Fixer la hauteur
	//closeText: 'Retour',			//=> Ajouter un texte au bouton "fermer"
	//background: 'green',			//=> Modifier la couleur du fond de l'Overlay
	//style: 'background:red',		//=> Ajouter des styles CSS directement à la greyBox
	//className: 'customize',		//=> Ajouter une Classe CSS
	//data: {id: 12},				//=> Envoyer des données en POST
	/*customFunction: function(){	//=> Exécuter un fonction personnelle à l'affichage de la greyBox
		alert('test');
	}*/
};
//Variable définissant la durée de la transition
var greyBoxEffectDuration = Math.round((greyBoxDefaultConfig.duration*1000)/2);
//Fonctions GREYBOX
function greyBoxShowNew(b,c,d,a){if(!$("#overlay").length){$("body").append('<div id="overlay" onclick="greyBoxHide();"></div>');if(jQuery.browser.msie&&jQuery.browser.version=="6.0"){$(window).scroll(function(){$("#overlay").css("top",$(window).scrollTop()+"px")})}}if(!$("#greyBox").length){$("body").append('<div id="greyBox"><div class="content" id="greyBoxContent"></div><div onclick="greyBoxHide();" class="close"><img src="/templates/1/img/close.gif" alt="" /></div></div>')}if(typeof(a)!="undefined"){if(typeof(a.duration)=="undefined"){greyBoxEffectDuration=Math.round((greyBoxDefaultConfig.duration*1000)/2)}else{greyBoxEffectDuration=Math.round((a.duration*1000)/2)}if(typeof(a.top)=="undefined"){a.top=greyBoxDefaultConfig.top}if(typeof(a.opacity)=="undefined"){a.opacity=greyBoxDefaultConfig.opacity}if(typeof(a.height)=="undefined"&&typeof(greyBoxDefaultConfig.height)!="undefined"){a.height=greyBoxDefaultConfig.height}if(typeof(a.closeText)=="undefined"&&typeof(greyBoxDefaultConfig.closeText)!="undefined"){a.closeText=greyBoxDefaultConfig.closeText}if(typeof(a.title)=="undefined"&&typeof(greyBoxDefaultConfig.title)!="undefined"){a.title='<h1 class="title greybox">'+greyBoxDefaultConfig.title+"</h1>"}else{if(typeof(a.title)=="undefined"&&typeof(greyBoxDefaultConfig.title)=="undefined"){a.title=""}else{a.title='<h1 class="title greybox">'+a.title+"</h1>"}}if(typeof(a.error)=="undefined"&&typeof(greyBoxDefaultConfig.error)!="undefined"){a.error=greyBoxDefaultConfig.error}if(typeof(a.background)=="undefined"&&typeof(greyBoxDefaultConfig.background)!="undefined"){a.background=greyBoxDefaultConfig.background}if(typeof(a.style)=="undefined"&&typeof(greyBoxDefaultConfig.style)!="undefined"){a.style=greyBoxDefaultConfig.style}if(typeof(a.className)=="undefined"&&typeof(greyBoxDefaultConfig.className)!="undefined"){a.className=greyBoxDefaultConfig.className}if(typeof(a.loading)=="undefined"&&typeof(greyBoxDefaultConfig.loading)!="undefined"){a.loading=greyBoxDefaultConfig.loading}if(typeof(a.data)=="undefined"&&typeof(greyBoxDefaultConfig.data)!="undefined"){a.data=greyBoxDefaultConfig.data}if(typeof(a.customFunction)=="undefined"&&typeof(greyBoxDefaultConfig.customFunction)!="undefined"){a.customFunction=greyBoxDefaultConfig.customFunction}}else{greyBoxEffectDuration=Math.round((greyBoxDefaultConfig.duration*1000)/2);a=greyBoxDefaultConfig;a.title=""}$("#overlay").removeAttr("style");$("#greyBox .close").html('<img src="/templates/1/img/close.gif" alt="" />');$("#greyBox").removeAttr("class");$("#greyBoxContent").removeAttr("style");if(typeof(a.height)!="undefined"&&d!="iframe"&&d!="youtube"&&d!="dailymotion"){$("#greyBoxContent").css("overflow","auto").css("height",a.height+"px")}if(typeof(a.closeText)!="undefined"){$("#greyBox .close").html(a.closeText+'<img src="/templates/1/img/close.gif" alt="" />')}if(typeof(a.background)!="undefined"){$("#overlay").css("background",a.background)}if(typeof(a.style)!="undefined"){$("#greyBoxContent").attr("style",a.style)}if(typeof(a.className)!="undefined"){$("#greyBox").addClass(a.className)}$("#greyBoxContent").html('<div id="greyBoxLoader"></div>');if(typeof(a.loading)!="undefined"){$("#greyBoxLoader").html(a.loading)}$("#greyBox").css("width",c+"px").css("left","-"+(Math.ceil(c/2))+"px");if(typeof(a.customFunction)=="undefined"){switch(d){case"html":var e=function(){$("#greyBoxContent").html(a.title+b)};greyBoxDisplay(e,a.opacity,a.top);break;case"get":var e=function(){$.ajax({type:"GET",url:b,success:function(f){$("#greyBoxContent").html(a.title+f)},error:function(){$("#greyBoxContent").html(a.title+a.error)}})};greyBoxDisplay(e,a.opacity,a.top);break;case"post":var e=function(){$.ajax({type:"POST",url:b,data:a.data,success:function(f){$("#greyBoxContent").html(a.title+f)},error:function(){$("#greyBoxContent").html(a.title+a.error)}})};greyBoxDisplay(e,a.opacity,a.top);break;case"iframe":var e=function(){var f=400;if(typeof(a.height)!="undefined"){f=a.height}$("#greyBoxContent").html(a.title+'<iframe src="'+b+'" border="0" frameborder="0" width="100%" height="'+f+'" allowTransparency="true"></iframe>')};greyBoxDisplay(e,a.opacity,a.top);break;case"youtube":var e=function(){var f="";if(typeof(a.height)!="undefined"){f=' height="'+a.height+'"'}$("#greyBoxContent").html(a.title+'<iframe class="youtube" title="YouTube video player" style="width:100%;display:block;"'+f+' src="http://www.youtube.com/embed/'+b+'?wmode=transparent" frameborder="0" allowfullscreen></iframe>')};greyBoxDisplay(e,a.opacity,a.top);break;case"dailymotion":var e=function(){var f=400;if(typeof(a.height)!="undefined"){f=a.height}$("#greyBoxContent").html(a.title+'<object width="100%" height="'+f+'" style="display:block;"><param name="movie" value="http://www.dailymotion.com/swf/video/'+b+'"></param><param name="allowFullScreen" value="true"></param><param name="allowScriptAccess" value="always"></param><embed type="application/x-shockwave-flash" src="http://www.dailymotion.com/swf/video/'+b+'" width="100%" height="'+f+'" allowfullscreen="true" allowscriptaccess="always"></embed></object>')};greyBoxDisplay(e,a.opacity,a.top);break;case"image":var e=function(){$("#greyBoxContent").html($("#greyBoxContent").html()+'<img src="'+b+'" alt="" style="display:none;" id="greyBoxImage" />');$("#greyBoxImage").load(function(){$("#greyBoxImage").fadeOut(0);$("#greyBoxLoader").remove();$("#greyBoxContent").prepend(a.title);$("#greyBoxImage").fadeIn("medium");$("#greyBoxContent").css("width",Math.floor($("#greyBoxImage").outerWidth())+"px");$("#greyBox").css("width","auto").css("left","-"+(Math.ceil($("#greyBoxContent").outerWidth()/2))+"px")})};greyBoxDisplay(e,a.opacity,a.top);break;default:break}}else{greyBoxDisplay(a.customFunction,a.opacity,a.top)}return false}function greyBoxDisplay(c,a,b){if($("#greyBox").attr("status")!="running"){$("#greyBox").attr("status","running");$("#greyBox").css("top",($(window).scrollTop()+b)+"px");if(jQuery.browser.msie&&jQuery.browser.version=="6.0"){$("#overlay").css("position","absolute").css("height",$(window).height()+"px").css("top",$(window).scrollTop()+"px");$("#greyBoxLoader").css("height","200px")}$("object:not(.keep-visible), embed").css("visibility","hidden");if(jQuery.browser.msie&&jQuery.browser.version=="6.0"){$("select").css("visibility","hidden")}$("#overlay").fadeTo(greyBoxEffectDuration,a,function(){$("#greyBox").fadeIn(greyBoxEffectDuration,function(){$("#greyBox").attr("status","done");c()})})}}function greyBoxHide(){if($("#greyBox").attr("status")!="running"){$("#greyBox").attr("status","running");$("#greyBox").fadeOut(greyBoxEffectDuration,function(){$("#greyBox").hide();$("#overlay").fadeOut(greyBoxEffectDuration,function(){$("object:not(.keep-visible), embed").css("visibility","visible");if(jQuery.browser.msie&&jQuery.browser.version=="6.0"){$("select").css("visibility","visible")}$("#greyBox").attr("status","done")})})}};
/*function greyBoxShow(mode, url, width, height, overflow){
	//On masque le champ SELECT CUSTOMIZé
	customSelectOptionHide();
	
	//Si OVERLAY n'existe pas
	if(!$('#overlay').length){
		// On l'ajoute dynamiquement
		$('body').append('<div id="overlay" onclick="greyBoxHide();"></div>');
	}
	//Si GREYBOX n'existe pas
	if(!$('#greyBox').length){
		// On l'ajoute dynamiquement
		// greyBox			==> Positionnement en absolute centré
		// greyBoxContent	==> Contenus de la box
		// greyBoxLoader		==> Gif annimé de chargement
		// close			==> Div de fermeture
		$('body').append('<div id="greyBox"><div class="content" id="greyBoxContent"></div><div onclick="greyBoxHide();" class="close"><img src="/templates/1/img/close.gif" alt="Fermer cette fenêtre" /></div></div>');
	}
	
	// On dimensionne la box suivant les paramètres passés
	$('#greyBoxContent').html('<div id="greyBoxLoader"></div>');
	if(typeof(overflow)!='undefined' && overflow==true){
		$('#greyBox').attr('style', '').css('width', width+'px');
		$('#greyBoxContent').attr('style', '').css('height', height+'px');
	}
	else{
		$('#greyBox').attr('style', '').css('width', width+'px');
		$('#greyBoxContent').attr('style', '');
	}
	// On centre la box suivant les dimensions passés
	$('#greyBox').css('left', '-'+(Math.ceil(width/2))+'px');
	
	// On dimensionne la taille de l'overlay sur IE6
	if(jQuery.browser.msie && jQuery.browser.version=="6.0"){
		windowHeightIeFix = $(document.body).height();
		if($(document.body).height() == 0){
			var windowHeightIeFix = 670;
		}
		$('#overlay').css('height',windowHeightIeFix+'px');
		$('select').hide();
	}
	
	// Mode de contenu à afficher
	switch(mode){
		// AJAX		==> Page ajax à charger
		case 'ajax':
			if(jQuery.browser.msie && jQuery.browser.version=="6.0"){
				$('#greyBoxContent').load(url,'',function(){
					$('#overlay').show();
					$('#greyBox').show();
				});
			}
			else{
				$('#overlay').css('opacity','0');
				$('#overlay').show();
				$('#overlay').fadeTo('slow',0.6,function(){
					$('#greyBox').show();
					$('#greyBoxContent').load(url,'',function(){});
				});
			}
			break;
		// IFRAME		==> Iframe ajax à afficher
		case 'iframe':
			var paddings = parseInt($('#greyBoxContent').css('padding-left')) + parseInt($('#greyBoxContent').css('padding-right'));
			$('#greyBoxContent').html('<iframe src="'+url+'" border="0" frameborder="0" width="'+(width-paddings)+'" height="'+height+'" allowTransparency="true"></iframe>');
			if(jQuery.browser.msie && jQuery.browser.version=="6.0"){
				$('#overlay').show();
				$('#greyBox').show();
			}
			else{
				$('#overlay').css('opacity','0');
				$('#overlay').show();
				$('#overlay').fadeTo('slow',0.6,function(){
					$('#greyBox').show();
				});
			}
			break;
		// YOUTUBE	==> Code video youtube à afficher
		case 'youtube':
			var paddings = parseInt($('#greyBoxContent').css('padding-left')) + parseInt($('#greyBoxContent').css('padding-right'));
			$('#greyBoxContent').html('<object width="'+(width-paddings)+'" height="'+height+'"><param name="movie" value="http://www.youtube.com/v/'+url+'&hl=fr_FR&fs=1&rel=0&color1=0x006699&color2=0x54abd6"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/'+url+'&hl=fr_FR&fs=1&rel=0&color1=0x006699&color2=0x54abd6" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="'+(width-paddings)+'" height="'+height+'"></embed></object>');
			if(jQuery.browser.msie && jQuery.browser.version=="6.0"){
				$('#overlay').show();
				$('#greyBox').show();
			}
			else{
				$('#overlay').css('opacity','0');
				$('#overlay').show();
				$('#overlay').fadeTo('slow',0.6,function(){
					$('#greyBox').show();
				});
			}
			break;
		// DAILYMOTION	==> Code video dailymotion à afficher
		case 'dailymotion':
			var paddings = parseInt($('#greyBoxContent').css('padding-left')) + parseInt($('#greyBoxContent').css('padding-right'));
			$('#greyBoxContent').html('<object width="'+(width-paddings)+'" height="'+height+'"><param name="movie" value="http://www.dailymotion.com/swf/video/'+url+'"></param><param name="allowFullScreen" value="true"></param><param name="allowScriptAccess" value="always"></param><embed type="application/x-shockwave-flash" src="http://www.dailymotion.com/swf/video/'+url+'" width="'+(width-paddings)+'" height="'+height+'" allowfullscreen="true" allowscriptaccess="always"></embed></object>');
			if(jQuery.browser.msie && jQuery.browser.version=="6.0"){
				$('#overlay').show();
				$('#greyBox').show();
			}
			else{
				$('#overlay').css('opacity','0');
				$('#overlay').show();
				$('#overlay').fadeTo('slow',0.6,function(){
					$('#greyBox').show();
				});
			}
			break;
		// IMAGE		==> Image à afficher
		case 'image':
			var paddings = parseInt($('#greyBoxContent').css('padding-left')) + parseInt($('#greyBoxContent').css('padding-right'));
			$('#greyBox').css('width', (width+paddings)+'px').css('left', (parseInt($('#greyBox').css('left')) - (paddings/2))+'px');
			$('#greyBoxContent').html('<img src="'+url+'" alt="" />');
			if(jQuery.browser.msie && jQuery.browser.version=="6.0"){
				$('#overlay').show();
				$('#greyBox').show();
			}
			else{
				$('#overlay').css('opacity','0');
				$('#overlay').show();
				$('#overlay').fadeTo('slow',0.6,function(){
					$('#greyBox').show();
				});
			}
			break;
		default:
			break;
	}
	
	// On remonte le scroll en haut de page
	$(document).scrollTop(0);
	
	return false;
}

//greyBoxHide() : FERMETURE GREYBOX
function greyBoxHide(){
	//On masque le champ SELECT CUSTOMIZé
	customSelectOptionHide();
	
	if(jQuery.browser.msie && jQuery.browser.version=="6.0"){
		$('#overlay').hide();
		$('#greyBox').hide();
		$('#greyBoxContent').html('');
		$('select').show();
	}
	else{
		$('#greyBox').fadeOut('medium',function(){
			$('#greyBoxContent').html('');
			$('#overlay').fadeOut('fast');
		});
	}
}*/
/*--------------------------------------------------GREYBOX-------------------------------------------------------------------*/

/*--------------------------------------------------SLIDING-------------------------------------------------------------------*/
//Afficher un slide
function displaySlide(data, id){

	//on stocke l'élément déclencheur
	var trigger = $('#slideData .pagination li:not(.previous)')[id];

	//Si un affichage de SLIDE n'est pas déjà en cours et que l'élément cliqué n'a pas déjà la classe ACTIVE
	if($('#slide').attr('status') == 'finished' && !$(trigger).hasClass('active')){
		$('#slide').attr('status', 'running');
		
		//On retire les précédentes classes ACTIVE
		$('#slideData .pagination li.active').removeClass('active');
		var trigger = $('#slideData .pagination li:not(.previous)')[id];
		//On applique la classe ACTIVE au <LI> trigger
		$(trigger).addClass('active');
		
		$('#slide').attr('current', id);

		if($('#slideCurrentContent').length){
			$('#slideCurrentContent').fadeOut(300, function(){
				$('#slideBackground').fadeOut(300, function(){
					$('#slideCurrentContent').empty();
					$('#slideCurrentContent').show();
					displaySlide_proceed(data);
				});
			});
		}
		else{
			$('#slideData').prepend('<div id="slideCurrentContent"></div>');
			displaySlide_proceed(data);
		}
	}
	
}

//Rendu d'affichage du slide
function displaySlide_proceed(data){
	
	//console.log(data);
	//On applique l'image de fond à SLIDE BACKGROUND
	$('#slideBackground').css('background-image', 'url('+data.img+')');
	
	//On prépare le contenu du SLIDE
	var slide = '<div class="filet-1"></div>';
	slide += '<div class="filet-2"></div>';
	slide += '<div class="title '+data.couleur_titre+'">'+data.title+'</div>';
	slide += '<br class="clear" />';
	slide += '<div class="desc">'+data.desc+'</div>';
	
	//On insère le contenu du SLIDE
	$('#slideCurrentContent').prepend(slide);
	
	
	/*----Annimation----*/
	//=> Fade In sur le BACKGROUND
	$('#slideBackground').fadeIn(500, function(){
		//Callback => slide de gauche à droite sur le TITLE
		$('#slideCurrentContent .title').show(
			'slide', {
				direction: 'left',
				mode: 'show'
			},
			500,
			function(){
				//Callback
				//=> Calage des filets
				slideFilets();
				//=> Slide In sur le DESC
				$('#slideCurrentContent .desc').show(
					'slide',
					{
						direction: 'left',
						mode: 'show'
					},
					500,
					function(){
						//Callback => Statut FINISHED
						$('#slide').attr('status', 'finished');
						setTimeout(function(){
							if($('#slide').attr('auto') == 'on'){
								slideNext();
							}
						}, timer);
					}
				);
			}
		);
	});
	
}

//Slide previous
function slidePrevious(){

	//On récupère l'ID du slide en cours
	var id = $('#slide').attr('current');
	id = parseInt(id);
	id--;
	
	
	//Si on a dépassé le dernier, on reviens à 0
	if(id < 0){
	
		//On récupère le nombre de slides possibles
		var size = $('#slide').attr('length');
		size = parseInt(size);
		
		id = size-1;
	}
	
	//On lance l'animation
	displaySlide(slide_data[id], id);
	
}

//Slide next
function slideNext(){

	//On récupère l'ID du slide en cours
	var id = $('#slide').attr('current');
	id = parseInt(id);
	id++;
	
	//On récupère le nombre de slides possibles
	var size = $('#slide').attr('length');
	size = parseInt(size);
	
	//Si on a dépassé le dernier, on reviens à 0
	if(id >= size){
		id = 0;
	}
	
	//On lance l'animation
	displaySlide(slide_data[id], id);
	
}

//Positionnement et affichage des filets
function slideFilets(){
	
	//On n'affichera pas les filets pour les versions 7 et 6 d'INTERNET EXPLORER (car le SPAN .make-line est en 100%)
	if(!jQuery.browser.msie || (jQuery.browser.version != '7.0' && jQuery.browser.version != '6.0')){
		//On calcule la position en largeur, en fonction de la dernière ligne crée
		var left = 358 + $('#slideCurrentContent .title .make-line:last').innerWidth() + 13;
		//On calcule la position en hauteur, en fonction de la dernière ligne crée
		var top = $('#slideCurrentContent .title .make-line:last').position().top + $('#slideCurrentContent .title .make-line:last').innerHeight();
		//On positionne FILET-2
		$('#slideCurrentContent .filet-2').css('left', left+'px').css('top', top+'px');
		//On affiche les filets
		$('#slideCurrentContent .filet-1').show(
			'slide',
			{
				direction: 'left',
				distance: 50
			},
			300
		);
		$('#slideCurrentContent .filet-2').show(
			'slide',
			{
				direction: 'right',
				distance: 50
			},
			300
		);
	}

}
/*--------------------------------------------------SLIDING-------------------------------------------------------------------*/

/*--------------------------------------------------WIDGETS-------------------------------------------------------------------*/
//Check des widgets précédent activés ou non
function widgetManager(trigger){

	if($('#widgets').attr('status') != 'running'){
		var size = $('#widgets .block.active').length;
		if(size > 0){
			var i = 0;
			$('#widgets .block.active').each(function(){
				if(i == (size-1)){
					widgetDisplay($(this).children('.trigger')[0]);
					if(typeof(trigger) != 'undefined'){
						widgetDisplay(trigger);
					}
				}
				i++;
			});
		}
		else{
			if(typeof(trigger) != 'undefined'){
				widgetDisplay(trigger);
			}
		}
	}

}

//Fonction d'affichage des widgets
function widgetDisplay(trigger){
	
	$('#widgets').attr('status', 'running');
	if($(trigger).parent('.block').hasClass('active')){
		$(trigger).next('.content').hide('slide', {}, 400, function(){
			$(trigger).parent('.block').removeClass('active');
			$(trigger).children('.preview').show('slide', {
				direction: 'right'
			},
			300,
			function(){
				$(trigger).children('.preview').css('float', 'none');
				$('#widgets').attr('status', 'finished');
			});
		});
		$(trigger).children('.close').hide();
	}
	else{
		$(trigger).children('.preview').css('float', 'right');
		$(trigger).children('.preview').hide('slide', {
			direction: 'right'
		},
		300,
		function(){
			$(trigger).parent('.block').addClass('active');
			$(trigger).next('.content').show('slide', {}, 400, function(){
				$(trigger).children('.close').css('display', 'inline-block');
				$('#widgets').attr('status', 'finished');
			});
		});
	}
	
	return false;
}
/*--------------------------------------------------WIDGETS-------------------------------------------------------------------*/

/*--------------------------------------------------DATEPICKER-------------------------------------------------------------------*/
//Afficher la zone du calendrier
function showDates(){
	//On vérifie que l'on est pas déjà en cours d'animation
	if($('#config').attr('status') != 'running'){
		//On spécifie que l'action est en cours
		$('#config').attr('status', 'running');
		//Action de déploiement
		if(!$('#config').hasClass('active')){
			//On masque les Champs #f_qty et #f_type
			$('#f_qty, #f_type').hide();
			$('#config .content').show('slide', {}, 500, function(){
				$('#config').addClass('active');
				$('#config').attr('status', 'finished');
			});
		}
		//Action de repli
		else{
			//On masque les Champs #f_qty et #f_type
			$('#f_qty, #f_type').show();
			$('#config .content').hide('slide', {}, 500, function(){
				$('#config').removeClass('active');
				$('#config').attr('status', 'finished');
			});
		}
	}
}

//Signification du chargement
function loadingSignifier(target, str){
	
	$(target).attr('onclick', '')
	$(target).css('background-image', 'url('+str+')');
	$(target).css('background-position', 'right bottom');
	if(typeof($(target).attr('value') != 'undefined')){
		$(target).attr('value', ' ');
	}
	if(typeof($(target).html()) != 'undefined' && $(target).html() != ''){
		$(target).html('&nbsp;');
	}
	
}

//Envoi / Check du formulaire
function sendConfig(target, str){
	
	if($('#date_1').val() != '' && $('#date_2').val() != '' && $('#qty').val() != ''){
		if(typeof(target) != 'undefined' && typeof(str) != 'undefined'){
			loadingSignifier(target, str);
		}
		$('#configForm').submit();
	}
	else{
		//Paramètres de l'effet PULSATE
		var times = 3;
		var duration = 500;
		
		if($('#date_1').val() == ''){
			//alert("Veuillez indiquer votre date d'arrivée avant de valider");
			$('#formAlert').html("Veuillez indiquer <strong>votre date d'arrivée</strong> avant de valider");
			$('#formAlert').show('pulsate', {times:times}, duration);
			return;
		}
		if($('#date_2').val() == ''){
			$('#formAlert').html("Veuillez indiquer <strong>votre date de départ</strong> avant de valider");
			$('#formAlert').show('pulsate', {times:times}, duration);
			return;
		}
		if($('#qty').val() == ''){
			$('#formAlert').html("Veuillez spécifier <strong>le nombre de personnes</strong> avant de valider");
			$('#formAlert').show('pulsate', {times:times}, duration);
			return;
		}
	}
	
	
}
function ajaxloadpack(){
	$('#img_standing_load2').show();
	$('#listProducts_area').css('opacity', 0.6);
	$.ajax({
		type: "POST",
		url: '/templates/1/flux/ajax/get_pack.php',
		data: "num_promo="+$('#promo_colonne').val()+"&pe="+$('#qty_stock').val(),
		dataType: "html",
		cache: false,
		contentType: "application/x-www-form-urlencoded; charset=utf-8", 
		error:function(xhr, status, errorThrown) {
				alert(errorThrown+'\n'+status+'\n'+xhr.statusText);
		},
		success: function(data) {
			$('#listProducts_area').html(data);
			$('#listProducts_area').removeAttr('style');
		}
	});
	$.ajax({
		type: "POST",
		url: '/templates/1/flux/ajax/get_filtre.php',
		data: "num_promo="+$('#promo_colonne').val()+"&pe="+$('#qty_stock').val()+"&type=standingpack&pt=903",
		dataType: "html",
		cache: false,
		contentType: "application/x-www-form-urlencoded; charset=utf-8", 
		error:function(xhr, status, errorThrown) {
			alert(errorThrown+'\n'+status+'\n'+xhr.statusText);
		},
		success: function(data) {
			$('#selstanding_customized').html($('#sel_standing_customized').prev('select.customize').find('option:first').html());
			$('#selstanding_customized').removeClass('disabled');
			$('#img_standing_load2').hide();
			$('#selstandingPack').html(data);
		}
	});
}

function ajaxloadpromo(){
	$('#img_standing_load2').show();
	$('#listProducts_area').css('opacity', 0.6);
	$.ajax({
		type: "POST",
		url: '/templates/1/flux/ajax/get_promo.php',
		data: "num_promo="+$('#promo_colonne').val()+"&pe="+$('#qty_stock').val(),
		dataType: "html",
		cache: false,
		contentType: "application/x-www-form-urlencoded; charset=utf-8", 
		error:function(xhr, status, errorThrown) {
				alert(errorThrown+'\n'+status+'\n'+xhr.statusText);
		},
		success: function(data) {
			$('#listProducts_area').html(data);
			$('#listProducts_area').removeAttr('style');
		}
	});
	$.ajax({
		type: "POST",
		url: '/templates/1/flux/ajax/get_filtre.php',
		data: "num_promo="+$('#promo_colonne').val()+"&pe="+$('#qty_stock').val()+"&type=standingpack&pt=900",
		dataType: "html",
		cache: false,
		contentType: "application/x-www-form-urlencoded; charset=utf-8", 
		error:function(xhr, status, errorThrown) {
			alert(errorThrown+'\n'+status+'\n'+xhr.statusText);
		},
		success: function(data) {
			$('#selstanding_customized').html($('#sel_standing_customized').prev('select.customize').find('option:first').html());
			$('#selstanding_customized').removeClass('disabled');
			$('#img_standing_load2').hide();
			$('#selstandingPromo').html(data);
		}
	});
}


function ajaxloadlot(){
	$('#img_standing_load2').show();
	$('#listFilters, #listProducts_area').css('opacity', 0.6);
	$.ajax({
		type: "POST",
		url: '/templates/1/flux/ajax/get_lot.php',
		data: "dd="+$('#date_1_stock').val()+"&df="+$('#date_2_stock').val()+"&pe="+$('#qty_stock').val(),
		dataType: "html",
		cache: false,
		contentType: "application/x-www-form-urlencoded; charset=utf-8", 
		error:function(xhr, status, errorThrown) {
				alert(errorThrown+'\n'+status+'\n'+xhr.statusText);
		},
		success: function(data) {
			$('#listProducts_area').html(data);
			check_special();
			$('#listFilters, #listProducts_area').removeAttr('style');
		}
	});
	$.ajax({
		type: "POST",
		url: '/templates/1/flux/ajax/get_filtre.php',
		data: "dd="+$('#date_1_stock').val()+"&df="+$('#date_2_stock').val()+"&pe="+$('#qty_stock').val()+"&c2="+$(this).val()+"&type=standing",
		dataType: "html",
		cache: false,
		contentType: "application/x-www-form-urlencoded; charset=utf-8", 
		error:function(xhr, status, errorThrown) {
			alert(errorThrown+'\n'+status+'\n'+xhr.statusText);
		},
		success: function(data) {
			$('#selstanding_customized').html($('#sel_standing_customized').prev('select.customize').find('option:first').html());
			$('#selstanding_customized').removeClass('disabled');
			$('#img_standing_load2').hide();
			$('#selstanding').html(data);
		}
	});
	$.ajax({
		type: "POST",
		url: '/templates/1/flux/ajax/get_filtre.php',
		data: "dd="+$('#date_1_stock').val()+"&df="+$('#date_2_stock').val()+"&pe="+$('#qty_stock').val()+"&c2="+$(this).val()+"&type=typelogement",
		dataType: "html",
		cache: false,
		contentType: "application/x-www-form-urlencoded; charset=utf-8", 
		error:function(xhr, status, errorThrown) {
				alert(errorThrown+'\n'+status+'\n'+xhr.statusText);
		},
		success: function(data) {
			$('#seltypelogement').html(data);
		}
	});
}

function set_standing_home(date1, date2, qty){
	if(date1 != '' && date2 != '' && qty != ''){
		$('#sel_standing').attr('disabled', true);
		$('#img_standing_load').show();
		$('#standing').val('');
		$.ajax({
			type: "POST",
			url: '/templates/1/flux/ajax/get_filtre.php',
			data: "dd="+date1+"&df="+date2+"&pe="+qty+"&type=standing",
			dataType: "html",
			cache: false,
			contentType: "application/x-www-form-urlencoded; charset=utf-8", 
			error:function(xhr, status, errorThrown) {
					alert(errorThrown+'\n'+status+'\n'+xhr.statusText);
			},
			success: function(data) {
				$('#sel_standing').html(data);
				$('#sel_standing').removeAttr('disabled');
				$('#img_standing_load').css('display', 'none');
				$('#sel_standing_customized').html($('#sel_standing_customized').prev('select.customize').find('option:first').html());
				$('#sel_standing_customized').removeClass('disabled');
			}
		});
	}
}

$(document).ready(function(){
	$('#sel_standing').change(function(){
		//console.log('sel_standing');
		$('#standing').val($('#sel_standing').val());
	});
	$('#selstanding').change(function(){
		if($(this).val()!=""){
			$('#listProducts_area, #listFilters').css('opacity', 0.6);
			$.ajax({
				type: "POST",
				url: '/templates/1/flux/ajax/get_lot.php',
				data: "dd="+$('#date_1_stock').val()+"&df="+$('#date_2_stock').val()+"&pe="+$('#qty_stock').val()+"&c2="+$(this).val(),
				dataType: "html",
				cache: false,
				contentType: "application/x-www-form-urlencoded; charset=utf-8", 
				error:function(xhr, status, errorThrown) {
						alert(errorThrown+'\n'+status+'\n'+xhr.statusText);
				},
				success: function(data) {
					$('#listProducts_area').html(data);
				}
			});
			$.ajax({
				type: "POST",
				url: '/templates/1/flux/ajax/get_filtre.php',
				data: "dd="+$('#date_1_stock').val()+"&df="+$('#date_2_stock').val()+"&pe="+$('#qty_stock').val()+"&c2="+$(this).val()+"&type=typelogement",
				dataType: "html",
				cache: false,
				contentType: "application/x-www-form-urlencoded; charset=utf-8", 
				error:function(xhr, status, errorThrown) {
						alert(errorThrown+'\n'+status+'\n'+xhr.statusText);
				},
				success: function(data) {
					$('#listProducts_area, #listFilters').removeAttr('style');
					$('#seltypelogement').html(data);
				}
			});
		}
	});
	
	$('#selstandingPack').change(function(){
		if($(this).val()!=""){
			$('#listProducts_area').css('opacity', 0.6);
			$.ajax({
				type: "POST",
				url: '/templates/1/flux/ajax/get_pack.php',
				data: "num_promo="+$('#promo_colonne').val()+"&pe="+$('#qty_stock').val()+"&c2="+$(this).val(),
				dataType: "html",
				cache: false,
				contentType: "application/x-www-form-urlencoded; charset=utf-8", 
				error:function(xhr, status, errorThrown) {
						alert(errorThrown+'\n'+status+'\n'+xhr.statusText);
				},
				success: function(data) {
					$('#listProducts_area').html(data);
					$('#listProducts_area').removeAttr('style');
				}
			});
		}
	});
	$('#selstandingPromo').change(function(){
		if($(this).val()!=""){
			$('#listProducts_area').css('opacity', 0.6);
			$.ajax({
				type: "POST",
				url: '/templates/1/flux/ajax/get_promo.php',
				data: "num_promo="+$('#promo_colonne').val()+"&pe="+$('#qty_stock').val()+"&c2="+$(this).val(),
				dataType: "html",
				cache: false,
				contentType: "application/x-www-form-urlencoded; charset=utf-8", 
				error:function(xhr, status, errorThrown) {
						alert(errorThrown+'\n'+status+'\n'+xhr.statusText);
				},
				success: function(data) {
					$('#listProducts_area').html(data);
					$('#listProducts_area').removeAttr('style');
				}
			});
		}
	});
	
	$('#seltypelogement').change(function(){
		$('#listProducts_area').css('opacity', 0.6);
		$.ajax({
			type: "POST",
			url: '/templates/1/flux/ajax/get_lot.php',
			data: "dd="+$('#date_1_stock').val()+"&df="+$('#date_2_stock').val()+"&pe="+$('#qty_stock').val()+"&c2="+$("#selstanding").val()+"&lot_tcial="+$(this).val(),
			dataType: "html",
			cache: false,
			contentType: "application/x-www-form-urlencoded; charset=utf-8", 
			error:function(xhr, status, errorThrown) {
					alert(errorThrown+'\n'+status+'\n'+xhr.statusText);
			},
			success: function(data) {
				$('#listProducts_area').removeAttr('style');
				$('#listProducts_area').html(data);
			}
		});
	});
	$('#selsortprix').change(function(){
		$('#listProducts_area').css('opacity', 0.6);
		$.ajax({
			type: "POST",
			url: '/templates/1/flux/ajax/get_lot.php',
			data: "dd="+$('#date_1_stock').val()+"&df="+$('#date_2_stock').val()+"&pe="+$('#qty_stock').val()+"&c2="+$("#selstanding").val()+"&lot_tcial="+$("#seltypelogement").val()+"&sort="+$(this).val(),
			dataType: "html",
			cache: false,
			contentType: "application/x-www-form-urlencoded; charset=utf-8", 
			error:function(xhr, status, errorThrown) {
					alert(errorThrown+'\n'+status+'\n'+xhr.statusText);
			},
			success: function(data) {
				$('#listProducts_area').removeAttr('style');
				$('#listProducts_area').html(data);
			}
		});
	});
}); 

//Augmenter le nombre de personnes
function qtyUp(trigger){

	if(typeof($(trigger).prev('.num').attr('num_id')) == 'undefined'){
		$(trigger).prev('.num').attr('num_id', '0');
	}
	var id = parseInt($(trigger).prev('.num').attr('num_id'));
	id++;
	
	if(id == quantities.length){
		id = 0;
	}
	
	$('#qty').val(quantities[id]);
	if(quantities[id].length == 1){
		var string = '0'+quantities[id];
	}
	else{
		var string = quantities[id];
	}
	$(trigger).prev('.num').attr('num_id', id).html(string);
}

function qtyUpMiniPack(trigger){
	qtyUp(trigger);
	$('span.select').attr('focus_status', 'false');
	$('#customSelect').hide();
	var id = parseInt($(trigger).prev('.num').attr('num_id'));
	$('#qty_stock').val(quantities[id]);
	$('.nombre_prestation').html(quantities[id]);
	ajaxloadpack();
}

function qtyUpMiniPromo(trigger){
	qtyUp(trigger);
	$('span.select').attr('focus_status', 'false');
	$('#customSelect').hide();
	var id = parseInt($(trigger).prev('.num').attr('num_id'));
	$('#qty_stock').val(quantities[id]);
	ajaxloadpromo();
}
function qtyUpMini(trigger){
	qtyUp(trigger);
	$('span.select').attr('focus_status', 'false');
	$('#customSelect').hide();
	var id = parseInt($(trigger).prev('.num').attr('num_id'));
	$('#qty_stock').val(quantities[id]);
	ajaxloadlot();
}
function qtyUpBig(trigger){
	qtyUp(trigger);
	$('span.select').attr('focus_status', 'false');
	$('#customSelect').hide();
	set_standing_home($('#date_1').val(), $('#date_2').val(), $('#qty').val());
}

//Diminue le nombre de personnes
function qtyDown(trigger){

	if(typeof($(trigger).nextAll('.num').attr('num_id')) == 'undefined'){
		$(trigger).nextAll('.num').attr('num_id', '0');
	}
	var id = parseInt($(trigger).nextAll('.num').attr('num_id'));
	id--;
	
	if(id < 0){
		id = quantities.length-1;
	}
	
	$('#qty').val(quantities[id]);
	if(quantities[id].length == 1){
		var string = '0'+quantities[id];
	}
	else{
		var string = quantities[id];
	}
	$(trigger).nextAll('.num').attr('num_id', id).html(string);
	
	
}
function qtyDownMiniPack(trigger){
	qtyDown(trigger);
	$('span.select').attr('focus_status', 'false');
	$('#customSelect').hide();
	var id = parseInt($(trigger).nextAll('.num').attr('num_id'));
	$('#qty_stock').val(quantities[id]);
	$('.nombre_prestation').html(quantities[id]);
	ajaxloadpack();
}

function qtyDownMiniPromo(trigger){
	qtyDown(trigger);
	$('span.select').attr('focus_status', 'false');
	$('#customSelect').hide();
	var id = parseInt($(trigger).nextAll('.num').attr('num_id'));
	$('#qty_stock').val(quantities[id]);
	ajaxloadpromo();
}

function qtyDownMini(trigger){
	qtyDown(trigger);
	$('span.select').attr('focus_status', 'false');
	$('#customSelect').hide();
	var id = parseInt($(trigger).nextAll('.num').attr('num_id'));
	$('#qty_stock').val(quantities[id]);
	ajaxloadlot();
}
function qtyDownBig(trigger){
	qtyDown(trigger);
	$('span.select').attr('focus_status', 'false');
	$('#customSelect').hide();
	set_standing_home($('#date_1').val(), $('#date_2').val(), $('#qty').val());
}

function qtyUpPackage(trigger){

	if(typeof($(trigger).prev('.num').attr('num_id')) == 'undefined'){
		$(trigger).prev('.num').attr('num_id', '2');
	}
	var id = parseInt($(trigger).prev('.num').attr('num_id'));
	id++;
	
	if(id == packageQuantities.length){
		id = 0;
	}
	
	$(trigger).parents('.input').prev('input').val(packageQuantities[id]);
	if(packageQuantities[id].length == 1){
		var string = '0'+packageQuantities[id];
	}
	else{
		var string = packageQuantities[id];
	}
	$(trigger).prev('.num').attr('num_id', id).html(string);
}

function qtyDownPackage(trigger){

	if(typeof($(trigger).nextAll('.num').attr('num_id')) == 'undefined'){
		$(trigger).nextAll('.num').attr('num_id', '2');
	}
	var id = parseInt($(trigger).nextAll('.num').attr('num_id'));
	id--;
	
	if(id < 0){
		id = packageQuantities.length-1;
	}
	
	$(trigger).parents('.input').prev('input').val(packageQuantities[id]);
	if(packageQuantities[id].length == 1){
		var string = '0'+packageQuantities[id];
	}
	else{
		var string = packageQuantities[id];
	}
	$(trigger).nextAll('.num').attr('num_id', id).html(string);
	
	
}


//Remplissage des champs "FAKES"
function sendData(target, value, mode){

	$('#formAlert').fadeOut();
	var fakeField = '#f_'+(target.substr(1, target.length));
	
	$(target).val(value);
	$(fakeField).find('.input .default').hide();
	$(fakeField).find('.input .value').empty();
	
	var day = value.substr(2, 2);
	var month = value.substr(0, 2);
	
	if(month[0] == 0){
		month_id = month[1] - 1;
	}
	else{
		month_id = month - 1;
	}
	
	var year = value.substr(4, 4);
	
	$(fakeField).find('.input .value').css('float', 'right').html('<span class="pink">'+day+'</span>'+month_names[month_id]).show('slide', {direction: 'up'}, 200, function(){
		$(this).css('float', 'none');
		if($(this).parents('.field').next().length && $(this).parents('.field').next().css('display') != 'block' && $(this).parents('.field').next().attr('id') != 'resetDates'){
			if($(this).parents('.field').attr('id') != 'f_date_2'){
				$(this).parents('.field').next().show('slide', {direction: 'up'}, 200);
			}
		}
	});

}

//Stocker les dates Json dans un tableau
function getJsonDates(variable){
	var results_values = new Array();
	var results = jQuery.parseJSON(variable);
	for(var i=0; i<results.length; i++){
		results_values[i] = results[i].value;
	}
	
	return results_values;
}

//Convertir Objet DATE vers [ddmmyyyy]
function formatDate(dateText){
	var date = dateText;
	var date_day = dateText.getDate()+'';
	var date_month = (dateText.getMonth()+1)+'';
	var date_year = dateText.getFullYear()+'';
	if(date_day.length == 1){
		date_day = '0'+date_day;
	}
	if(date_month.length == 1){
		date_month = '0'+date_month;
	}
	var full_date = date_month+date_day+date_year;
	
	return full_date;
}

//Convertir [ddmmyyyy] vers Objet DATE
function dateToDateformat(dateText){
	var day = parseInt(dateText.substr(2,2), 10) ;
	var month = parseInt(dateText.substr(0,2), 10) - 1 ;
	var year = parseInt(dateText.substr(4,4), 10) ;
	//alert("jour mois annee : "+day+" "+month+" "+year) ;
	
	//~ month.substr(0,1) == '0' ? month = parseInt(month.substr(1,1)) - 1 : '';
	//~ day.substr(0,1) == '0' ? day = parseInt(day.substr(1,1)) : '';
	
	var formated_date = new Date(year, month, day);
	
	return formated_date;
}

//Remise à zéro de la config DATE
function resetDates(){
	//On cache le bouton "RESET"
	$('#resetDates').hide();
	//On supprime le datepicker DEPART
	$('#date-2').datepicker('destroy');
	//On supprime le DIV #date-2
	$('#date-2').remove();
	//On vide les champ INPUTS
	$("#date_1").attr('value', '');
	$("#date_2").attr('value', '');
	$("#f_date_2").hide();
	$("#qty").attr('value', '2');
	//$("#f_qty").hide();
	$('#configResume .value').hide().empty();
	$('#configResume .default').show();
	//On recrée le datepicker ARRIVÉE
	displayDatepicker1();
}

//DATEPICKER ARRIVÉE
/*---------------------------------------------------------------------------------------------------------------------------------*/
function displayDatepicker1(arrivalDate){
	
	//On crée le DIV #DATE-1
	if(!$('#date-1').length){
		$('#datepicker').prepend('<div id="date-1"></div>');
	}

	//On récupère un tableau contenant les date d'arrivée possibles.
	results_values = getJsonDates(url_get_arkiane_durations);
	//Initialisation du datepicker
	$("#date-1").datepicker({
		
		duration:0,
		dateFormat:'mmddyy',
		firstDay:1,
		dayNames:day_Big_names,
		dayNamesMin:day_names,
		showOtherMonths:false,
		defaultDate:results_values[0],
		monthNames:month_Big_names,
		//On parse les dates affichées
		beforeShowDay:function(dateText){
		
			//On formate la date
			full_date = formatDate(dateText);
			
			//Si elle est dans le tableau des dates Json, on l'active
			if(jQuery.inArray(full_date, results_values) == -1){
				return [false, 'disabled'];
			}
			else{
				return [true, 'activated'];
			}
			
		},
		//On parse les dates affichées
		onSelect:function(dateText){
			//On affiche le datepicker DÉPART
			displayDatepicker2(dateText);
			//On supprime le datepicker ARRIVÉE
			$('#date-1').datepicker('destroy');
			$('#date-1').remove();
		}
		
	});
}

//DATEPICKER DÉPART
/*---------------------------------------------------------------------------------------------------------------------------------*/
function displayDatepicker2(arrivalDate){
	
	//On crée le DIV #DATE-2
	$('#datepicker').prepend('<div id="date-2"></div>');
	
	//On stocke la date dans un champ INPUT
	sendData('#date_1', arrivalDate, 'date');
	//On affiche le bouton RESET
	
	$.ajax({
		type: "POST",
		url: "/templates/1/flux/ajax/get_dates_fin.php",
		data: "annee="+arrivalDate,
		dataType: "html",
		cache: false,
		// contentType: "text/plain; charset=utf-8",
		contentType: "application/x-www-form-urlencoded; charset=utf-8", 		
		error:function(xhr, status, errorThrown) {
                alert(errorThrown+'\n'+status+'\n'+xhr.statusText);
        },
		success: function(data) {
			$("#resetDates").show();
			//On cache le datepicker ARRIVÉE
			$("#date-1").hide();
			//On initialise le datepicker DÉPART
			$("#date-2").datepicker({
				duration:0,
				dateFormat:'mmddyy',
				firstDay:1,
				defaultDate:arrivalDate,
				dayNames:['Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi'],
				dayNamesMin:['Di', 'Lu', 'Ma', 'Me', 'Je', 'Ve', 'Sa'],
				showOtherMonths:false,
				monthNames:['Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Août', 'Septembre', 'Octobre', 'Novembre', 'Décembre'],
				//On parse les dates affichées
				beforeShowDay:function(dateText){
					//Si il existe une date de DÉPART
					if($("#date_1").val() != '' && $("#date_2").val() != ''){
						var date_arrivee = dateToDateformat($("#date_1").val());
						var date_depart = dateToDateformat($("#date_2").val());
						if(dateText >= date_arrivee && dateText <= date_depart){
							return [false, 'highlightDate'];
						}
					}
				
					//On formate la date
					full_date = formatDate(dateText);
					//On récupère un tableau contenant les date de départ possibles.
					
					// results_values = getJsonDates(url_get_arkiane_departureDate);
					results_values = getJsonDates(data);
					// results_values = data;
					
					//On indique la date d'ARRIVÉE précédemment sélectionnée
					if(full_date == arrivalDate){
						return [false, 'arrivalDate'];
					}
					
					//Si elle est dans le tableau des dates Json, on l'active
					if(jQuery.inArray(full_date, results_values) == -1){
						return [false, 'disabled'];
					}
					else{
						//Si la date du tableau est supérieure à la date d'ARRIVÉE précédemment sélectionnée
						if(dateText > dateToDateformat(arrivalDate)){
							return [true, 'activated'];
						} else{
							return [false, 'disabled'];
						}
					}
					
				},
				onSelect:function(dateText){
					//On stocke la date dans un champ INPUT
					sendData('#date_2', dateText, 'date');
					set_standing_home($('#date_1').val(), $('#date_2').val(), $('#qty').val());
				}
				
			});
		}
	});
	
}
/*--------------------------------------------------DATEPICKER-------------------------------------------------------------------*/

/*--------------------------------------------------DIAPORAMA-------------------------------------------------------------------*/
function diaporamaTrigger(movement, ulIndex, speed){

	var whatLength = parseInt($('#diapo').attr('length'));
	var whatItem = parseInt($('#diapo').attr('current_id')) + movement;
	
	$('#diapo').attr('current_id', whatItem);
	
	if(movement == 1){
		if(whatItem >= whatLength){
			$('#diapo').attr('current_id', 0);
			whatItem = 0;
			var whatFormerLI = $('#diapo li')[whatLength-1];
		}
		else{
			var whatFormerLI = $('#diapo li')[whatItem-1];
		}
	}
	else if(movement == -1){
		if(whatItem < 0){
			$('#diapo').attr('current_id', whatLength-1);
			whatItem = whatLength-1;
			var whatFormerLI = $('#diapo li')[0];
		}
		else{
			var whatFormerLI = $('#diapo li')[whatItem+1];
		}
	}
	var whatLI = $('#diapo li')[whatItem];
	
	$('#diapo').attr('running', 'true');
	$(whatFormerLI).fadeOut(
		speed,
		function(){
			$(whatFormerLI).css('display', 'none');
		}
	);
	$(whatLI).fadeIn(
		speed,
		function(){
			$('#diapo').attr('running', 'false');
			//$(whatLI).css('display', 'block');
		}
	);
}
function diaporama_generator(ulIndex, speed, autoDefil, autoDefilTimer, autoDefilResume){

	/*--------------------------------------------------------------------DIAPORAMA_GENERATOR-----------------------------------------------------------------------------*/
	
	//	!!! Requiers		=> 	diaporamaTrigger()
	//	v1.0
	
	/*------Paramètres-----*/
		//[sliderUlIndex]				==> Index de profondeur du <BLOCK DÉPLACÉ> par rapport au <BLOCK SLIDER> (slider exclu)
		//[speed]					==> Durée de la transition en secondes
		//[autoDefil]				==> Défilement auto : TRUE / FALSE (FALSE par défaut)
		//[autoDefilTimer]			==> Intervalle du défilement auto
		//[autoDefilResume]			==> Intervalle de reprise du défilement auto après l'arrêt par click sur les boutons
	/*------Paramètres-----*/
	/*------Structure HTML requise-----*/
	/*
		<div class="slider">					//BLOCK SLIDER				CSS : libre
			<ul>						//BLOCK DÉPLACÉ			CSS : libre
				<li></li>				//ITEM					CSS : position:absolute;
				<li></li>				//ITEM					CSS : position:absolute;
				<li></li>				//ITEM					CSS : position:absolute;
			</ul>
			<span class="buttonLeft off"></span>		//BOUTON PRÉCÉDENT		CSS : libre
			<span class="buttonRight"></span>		//BOUTON SUIVANT			CSS : libre
		</div>
	*/
	/*------Structure HTML requise-----*/

	speed = speed*1000;
	autoDefilTimer = autoDefilTimer*1000;
	autoDefilResume = autoDefilResume*1000;
	
	$('#diapo').attr('current_id', 0);
	$('#diapo').attr('running', 'false');
	$('#diapo').attr('length', $('#diapo li').length);
	
	$('#diapo ul li').hide();
	$('#diapo ul li:first').show();
	
	$('#diapo .buttonLeft').each(function(){
		$(this).click(function(){
			if($('#diapo').attr('running') == 'false'){
				if(!$('#diapo').hasClass('manual')){
					$('#diapo').addClass('manual');
				}
				diaporamaTrigger(-1, ulIndex, speed);
			}
		});
	});
	$('#diapo .buttonRight').each(function(el){
		$(this).click(function(){
			if($('#diapo').attr('running') == 'false'){
				if(!$('#diapo').hasClass('manual')){
					$('#diapo').addClass('manual');
				}
				diaporamaTrigger(1, ulIndex, speed);
			}
		});
	});
	
	if(autoDefil){
	
		var diapo_timer1 = setInterval(function(){
			if($('#diapo').hasClass('manual') && $('#diapo').attr('running') == 'false'){
				$('#diapo').removeClass('manual');
			}
		}, autoDefilResume);
		
		var diapo_timer2 = setInterval(function(){
			if(!$('#diapo').hasClass('manual') && $('#diapo').attr('running') == 'false'){
				diaporamaTrigger(1, ulIndex, speed);
			}
		}, autoDefilTimer);
		
	}
	
}
/*--------------------------------------------------DIAPORAMA-------------------------------------------------------------------*/

/*--------------------------------------------------CHECKBOX CUSTOM-------------------------------------------------------------------*/
function checkboxCustomClick(element){
	if($(element).parent().find('span.checkbox').hasClass('active')){
		$(element).parent().find('input[type="checkbox"]').attr('checked', false);
		$(element).parent().find('span.checkbox').removeClass('active');
	}
	else{
		$(element).parent().find('input[type="checkbox"]').attr('checked', true);
		$(element).parent().find('span.checkbox').addClass('active');
	}
}
/*--------------------------------------------------CHECKBOX CUSTOM-------------------------------------------------------------------*/

/*--------------------------------------------------SELECT CUSTOM-------------------------------------------------------------------*/
function customSelectManager(element, stylize){

	if(!$('#customSelect').length){
		$('body').append('<ul id="customSelect"></ul>');
	}
	
	$('span.select').attr('focus_status', 'false');
	$(element).attr('focus_status', 'true');
	
	if($('#customSelect').css('display') != 'block' && !$(element).parent().find('select.customize').attr('disabled')){
		$(element).removeClass('disabled');
		var item = '';
		$('#customSelect').html('');
		$('#customSelect').attr('class', '');
		var cpt = 0;
		$(element).parent().find('select.customize').children('option').each(function(){
			//On n'affiche pas le premier ITEM pour éviter une redite de la valeur par défaut
			if(cpt != 0){
				item += '<li onclick="customSelectTrigger(this);" custom_value="'+$(this).val()+'">'+$(this).html()+'</li>';
			}
			cpt++;
		});
		$('#customSelect').html(item);
		$('#customSelect').css('width', ($(element).innerWidth() - 6)+'px');
		var posTop = $(element).outerHeight() + $(element).offset().top;
		$('#customSelect').css('top', posTop+'px').css('left', $(element).offset().left+'px');
		if(typeof(stylize) != 'undefined'){
			$('#customSelect').attr('class', stylize);
		}
		$('#customSelect').show();
	}
	else{
		customSelectOptionHide();
	}
}
function customSelectTrigger(element){
	$('span.select[focus_status="true"]').parent().find('select.customize').val($(element).attr('custom_value'));
	$('span.select[focus_status="true"]').parent().find('select.customize').trigger('change');
	$('span.select[focus_status="true"]').html($(element).html());
	customSelectOptionHide();
}
function customSelectOptionHide(){
	$('span.select[focus_status="true"]').attr('focus_status', 'false');
	$('#customSelect').hide();
}
/*--------------------------------------------------SELECT CUSTOM-------------------------------------------------------------------*/

/*--------------------------------------------------MEDIA BOX MANAGER-------------------------------------------------------------------*/
function mediaBoxManager(element, mode){
	$('#diapo, #video, #demo_360').hide();
	$(element).parent().parent().find('li.active').removeClass('active');
	$(element).parent().addClass('active');
	switch(mode){
		case 'photos':
			$('#diapo').show();
			break;
		case 'video':
			$('#video').show();
			break;
		case '360':
			$('#demo_360').show();
			break;
	}
	
	return false;
}
/*--------------------------------------------------MEDIA BOX MANAGER-------------------------------------------------------------------*/

/*--------------------------------------------------DETAILS INFOS PISTES-------------------------------------------------------------------*/
function infoPistes(element){
	$(element).toggleClass('active').nextAll('tr.details:first').toggleClass('show');
}
/*--------------------------------------------------DETAILS INFOS PISTES-------------------------------------------------------------------*/

$(document).ready(function(){
	
	if($('#page:not(.home) #footer').length){
		if($('#widgets').height() > $('#page:not(.home) #content > .container').height()){
			// alert($('#widgets').height());
			// alert($('#page:not(.home) #content > .container').height());
			// alert(parseInt($('#page:not(.home) #footer').css('margin-top')));
			var diff = parseInt($('#page:not(.home) #footer').css('margin-top')) + ($('#widgets').height() - $('#page:not(.home) #content > .container').height());
			// alert(diff);
			$('#page:not(.home) #footer').css('margin-top', diff+'px');
		}
	}
	
	//RAZ du formulaire CONFIG FORM (empêche les navigateurs de préremplir les champs)
	$("#date_1").attr('value', '');
	$("#date_2").attr('value', '');
	$("#qty").attr('value', '2');
	
	//Initialisation du DATEPICKER
	if($('#datepicker').length){
		displayDatepicker1();
	}

	//Gestion du repli automatique des WIDGETS
	$('#slide, #content, #toolbar, #slide *, #content *, #toolbar *').click(function(){
		widgetManager();
	});
	//Gestion du repli automatique du custom SELECT
	$('#slide, #toolbar, #slide *, #toolbar *').click(function(){
		customSelectOptionHide();
	});
	
	if($('#slide').length){
		/*--------------------------------------------------GÉNÉRATION DE LA PAGINATION-------------------------------------------------------------------*/
		//On masque le titre de référencement
		$('#slide h1').hide();
		//On stocke le nombre de slides dans un attribut custom du DIV #slide
		$('#slide').attr('length', slide_data.length);
		$('#slide').attr('auto', 'on');
		//Création de la pagination
		var pagination = '<ul class="pagination">';
		pagination += '<li class="previous" onclick="$(\'#slide\').attr(\'auto\', \'off\');slidePrevious();"></li>';
		//En fonction de la longeur du JSON, on crée autant de boutons
		for(var i=1; i<=slide_data.length; i++){
		
			if(i <= 3){
				//On précharge les 3 premières images du slide
				jQuery("<img>").attr('src', (slide_data[i-1].img));
			}
			
			var cnt = i+'';
			//Si on est < 10, on ajoute un "0" devant
			cnt.length < 2 ? cnt = '0'+cnt : '';
			
			pagination += '<li onclick="$(\'#slide\').attr(\'auto\', \'off\');displaySlide(slide_data['+(i-1)+'], '+(i-1)+');">'+cnt+'</li>';
		}
		pagination += '<li class="next" onclick="$(\'#slide\').attr(\'auto\', \'off\');slideNext();"></li>';
		pagination += '</ul>';
		//Une fois la pagination prête, on l'insère à la fin de SLIDEDATA
		$('#slide').attr('status', 'finished');
		$('#slideData').append(pagination);
		if(slide_data.length > 1){
			$('#slideData .pagination').show();
		}
		/*---------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
		
		/*--------------------------------------------------------ON AFFICHE LE SLIDE #1--------------------------------------------------------------------------*/
		displaySlide(slide_data[0], 0);
		/*---------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
	}
	
	//Gestion de l'affichage en 100% de la partie déroulée du MAIN MENU
	//Si on est pas sous IE6
	if(jQuery.browser.msie && jQuery.browser.version=="6.0"){}
	else{
		/*--Rollover--*/
		$('#mainMenu dl').mouseover(function(){
			customSelectOptionHide();
			
			if($(window).scrollTop() > 0 && $(window).scrollTop() < 33){
				$(this).children('dd').css('top', (33-$(window).scrollTop())+'px');
			}
			$(this).children('dd').show();
		});
		/*--Rollout--*/
		$('#mainMenu dl').mouseout(function(){
			$(this).children('dd').hide().css('top', '33px');
		});
	}
	
	//Alternative à DD Belated PNG pour IE6 dans les blocks widget
	if(jQuery.browser.msie && jQuery.browser.version=="6.0"){
		$('#widgets img').each(function(){
			var string = $(this).attr('src');
			extension = string.substr(string.length-3, string.length-1);
			string = string.substr(0, string.length-3);
			if(extension == 'png'){
				$(this).attr('src', string+'gif');
			}
		});
	}
	
	/*--------------------------------------------------------DIAPORAMA--------------------------------------------------------------------------*/
	if($('#diapo').length){
		diaporama_generator(0, 1, true, 5, 20);
	}

	/*--------------------------------------------------------SELECT CUSTOMS--------------------------------------------------------------------------*/
	$('.classicForm select.customize').each(function(){
		$(this).hide();
		var disabled_class = '';
		if($(this).attr('disabled')){
			disabled_class = ' disabled';
		}
		var default_html = '';
		if($('option:selected', this).html() != ''){
			default_html = $('option:selected', this).html();
		}
		else{
			default_html = $('option:first', this).html();
		}
		$(this).after('<span class="select'+disabled_class+'" onclick="customSelectManager(this);">'+default_html+'</span>');
	});
	$('#listFilters select.customize').each(function(){
		$(this).hide();
		var disabled_class = '';
		if($(this).attr('disabled')){
			disabled_class = ' disabled';
		}
		var default_html = '';
		if($('option:selected', this).html() != ''){
			default_html = $('option:selected', this).html();
		}
		else{
			default_html = $('option:first', this).html();
		}
		$(this).after('<span class="select'+disabled_class+'" onclick="customSelectManager(this, \'filter\');">'+default_html+'</span>');
	});
	$('#configOptions select.customize').each(function(){
		$(this).hide();
		var disabled_class = '';
		if($(this).attr('disabled')){
			disabled_class = ' disabled';
		}
		var default_html = '';
		if($('option:selected', this).html() != ''){
			default_html = $('option:selected', this).html();
		}
		else{
			default_html = $('option:first', this).html();
		}
		$(this).after('<span id="sel_standing_customized" class="select'+disabled_class+'" onclick="customSelectManager(this, \'widget\');">'+default_html+'</span>');
	});
	$('#configResume select.customize').each(function(){
		$(this).hide();
		var disabled_class = '';
		if($(this).attr('disabled')){
			disabled_class = ' disabled';
		}
		var default_html = '';
		if($('option:selected', this).html() != ''){
			default_html = $('option:selected', this).html();
		}
		else{
			default_html = $('option:first', this).html();
		}
		$(this).after('<span id="selstanding_customized" class="select'+disabled_class+'" onclick="customSelectManager(this, \'config\');">'+default_html+'</span>');
	});
	/*--------------------------------------------------------SELECT CUSTOMS--------------------------------------------------------------------------*/
	
	
	/*--------------------------------------------------------CHECKBOXS CUSTOMS--------------------------------------------------------------------------*/
	//Création des checkbox custom
	$('input[type="checkbox"]').each(function(){
		if(jQuery.browser.msie){
			if(jQuery.browser.version=="8.0"){
				$(this).css('display','block');
			}
			$(this).css('position','absolute');
			$(this).css('left','-5000px');
		}
		
		if($(this).attr('disabled') == true){
			if($(this).attr('checked') == true){
				$(this).after('<span class="checkbox disabledChecked"></span>');
			}
			else{
				$(this).after('<span class="checkbox disabled"></span>');
			}
		}
		else{
			if($(this).attr('checked') == true){
				$(this).after('<span class="checkbox active" onclick="checkboxCustomClick(this)"></span>');
			}
			else{
				$(this).after('<span class="checkbox" onclick="checkboxCustomClick(this)"></span>');
			}
			
			if($(this).attr('id') == $(this).parent().find('label').attr('for')){
				$(this).parent().find('label').removeAttr('for');
				$(this).parent().find('label').css('cursor', 'default');
				$(this).parent().find('label').attr('onclick', 'checkboxCustomClick(this);');
			}
		}
	});
	/*------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
	
});

//Gestion de l'affichage en 100% de la partie déroulée du MAIN MENU
//Si on est pas sous IE6
if(jQuery.browser.msie && jQuery.browser.version=="6.0"){}
else{
	//Au scroll de la page, on masque la partie déroulée.
	$(window).scroll(function(){
		$('#mainMenu dd').hide();
	});
}

var id_meteo = 1 ;
var id_webcam = 0 ;
function meteo_previous(){
	if(id_meteo > 1) {
		$("#meteo_"+id_meteo).hide() ;
		id_meteo -= 1 ;
		$("#meteo_"+id_meteo).show() ;
		$("#meteo_altitude_actuelle").text($(".altitude"+id_meteo).val()) ;
		if(id_meteo==1){
			$('#meteo_previous').css('opacity', '0.3');
			$('#meteo_previous').css('cursor', 'default');
		}else{
			$('#meteo_next').css('opacity', '1');
			$('#meteo_next').css('cursor', 'pointer');
		}
	}
}

function meteo_next(){
	if(id_meteo < 3) {
		$("#meteo_"+id_meteo).hide() ;
		id_meteo += 1 ;
		$("#meteo_"+id_meteo).show() ;
		$("#meteo_altitude_actuelle").text($(".altitude"+id_meteo).val()) ;
		if(id_meteo==3){
			$('#meteo_next').css('opacity', '0.3');
			$('#meteo_next').css('cursor', 'default');
		}else{
			$('#meteo_previous').css('opacity', '1');
			$('#meteo_previous').css('cursor', 'pointer');
		}
	}
}

var titre_webcam = "" ;
var altitude_webcam = "" ;

function webcam_previous() {
	if(id_webcam <= 0) {
		id_webcam = $("#les_webcams .photo").size();
	}
	$("#les_webcams .photo").each(function(index, valeur) {
		$(valeur).hide() ;
		if(index == (id_webcam - 1)) {
			$(valeur).show() ;
			titre_webcam = $(valeur).find(".titre_photo").val() ;
			altitude_webcam = $(valeur).find(".altitude_photo").val() ;
		}
		
	}) ;
	id_webcam -= 1 ;
	$("#titre_photo").text(titre_webcam) ;
	$("#altitude_photo").text(altitude_webcam) ;
}

function webcam_next() {
	if(id_webcam >= ($("#les_webcams .photo").size() - 1)) {
		id_webcam = -1;
	}
	$("#les_webcams .photo").each(function(index, valeur) {
		$(valeur).hide() ;
		if(index == (id_webcam + 1)) {
			$(valeur).show() ;
			titre_webcam = $(valeur).find(".titre_photo").val() ;
			altitude_webcam = $(valeur).find(".altitude_photo").val() ;
		}
	}) ;
	id_webcam += 1 ;
	$("#titre_photo").text(titre_webcam) ;
	$("#altitude_photo").text(altitude_webcam) ;
}

function verif_dispo(lot_imme_no, lot_no, dd, df){
	var html = $.ajax({
		type: "POST",
		url: '/templates/1/flux/ajax/get_dispo.php',
		data: "lot_imme_no="+lot_imme_no+"&lot_no="+lot_no+"&dd="+dd+"&df="+df,
		dataType: "html",
		cache: false,
		async: false,
		contentType: "application/x-www-form-urlencoded; charset=utf-8"
	}).responseText;
	if(html == 'OK'){
		return true;
	}else{
		//alert('Ce logement est dêja reservé pour cette période.');
		greyBoxShow('ajax', urlAlert, 550);
		return false;
	}
}

function verif_dispo_pack(lot_imme_no, lot_no, dd, df){
	var html = $.ajax({
		type: "POST",
		url: '/templates/1/flux/ajax/get_dispo.php',
		data: "lot_imme_no="+lot_imme_no+"&lot_no="+lot_no+"&dd="+dd+"&df="+df,
		dataType: "html",
		cache: false,
		async: false,
		contentType: "application/x-www-form-urlencoded; charset=utf-8"
	}).responseText;
	if(html == 'OK'){
		$('#form_package').click();
		return false;
	}else{
		//alert('Ce logement est dêja reservé pour cette période.');
		greyBoxShow('ajax', urlAlert, 550);
		return false;
	}
}


function cache_non_special(){
	$('#listProducts_area li').each(function(){
		if($(this).attr('class') != 'special ' && $(this).attr('class') != 'special lineLastChild'){
			$(this).css('display', 'none');
			$('#link_offres_speciales').click(function(){
				aff_non_special();
			});
		}
	});
}
function aff_non_special(){
	$('#listProducts_area li').each(function(){
		$(this).css('display', 'block');
		$('#link_offres_speciales').click(function(){
			cache_non_special();
		});
	});
}

function check_special(){
	$('#link_offres_speciales').addClass('off');
	$('#link_offres_speciales').click(function(){
		return false;
	});
	if($('#listProducts_area li.special').length){
		$('#link_offres_speciales').removeClass('off');
		$('#link_offres_speciales').click(function(){
			cache_non_special();
		});
	}
}
















