//Appel à faire quand la page est chargée
$(document).ready( function() {

	initEvenementCIN($('.form_num_thecard.booking_num_tha_cin'),false);
	initBookingTheCard();

	// Synchronisation des selects station
	selectStationsSort('station_depart',label_gare_depart);
	selectStationsSort('station_arrivee',label_gare_arrivee);
	selectStationsSortTGB('tgb_select_depart_retrait',label_choisir_gare_depart);
	selectStationsSortTGB('tgb_select_arrivee_retrait',label_choisir_gare_arrivee);
	synchronizeStationsDeparture();
	synchronizeStationsDepartureChange();
	synchronizeStationsArrival();
	choiceLondon();

	paysRetraitNl();

	pushDestination($('#station_arrivee').val());
	synchronizeInfoTrafic();

	initMonVoyageMesDates();
	initMonConfort();
	initMesBillets();
	choiceSeason();
	initLesPassagers();
	checkedSmsPlacement();
	initMembreTheCard();
	formElementsFocus();
	initErrors();

	ID_PASSAGER_OUBLIE = false;
	popin_numero_thalys_oublie = false;
	clickNumeroThalysOublie();
	boookingTooltip();
	$.uniform.update('#station_arrivee');
	disabledAbonnements();
	synchronizeTimeAjax('arr');

	disabledThePass();
	masquerParagrapheMobileTicket();

	if(TICKETLESS_ACCES == false) {
		disabledTicket('eticket');
		enableTooltip('tkl', label_booking_tkl_bloque);
		disabledTheCard();
		if(isBookingTheCard()) {
			$('.conteneur_lien_num-thalys-oublie').hide();
		}
	}

	
	checkBlock02042012();
	//openBlockPopup();
});
function choiceSeason() {
	var o = $('#station_depart').val();
	var d = $('#station_arrivee').val();

	if((false !== isSeasonStation(o)) || (false !== isSeasonStation(d))  ) {
		disabledTicket('eticket');
		if(TICKETLESS_ACCES == true) {
			enableTooltip('tkl', label_booking_tkl_indisponible);
		}
		disabledPaysRetrait('de');
		enableTooltip('de', label_booking_error_trajet_paper_de);
	} else {

		if($.inArray('eticket', tickets) >= 0 && TICKETLESS_ACCES == true) {
			enabledTicket('eticket');
		}
		if(TICKETLESS_ACCES == true) {
			disableTooltip('tkl');
			enabledPaysRetrait('de');
			if (!$('#pays_retrait_de').attr('disabled') ) {//sao
				disableTooltip('de');
			}
		}
	}
}

function disabledTheCard() {

	if($('#ttc_1').length > 0) {
		for(var i=1; i<=6;i++) {
			$('#ttc_'+i).attr('checked',false);
			$('#ttc_'+i).attr('disabled',true);
			enableTooltip('thepass', label_booking_thepass_non_disponible);
			$.uniform.update('#ttc_'+i);
		}

	}
}

function disabledThePass(ct) {
	if(URL_VARS['id'] != 1 || ct == 'nl' || TICKETLESS_ACCES == false) {
		if($('#thepass_1').length > 0) {
			$('#thepass_1').attr('checked',false);
			checkThePass('thepass_1');
			$('#thepass_1').attr('disabled',true);
			enableTooltip('thepass', label_booking_thepass_non_disponible);
			$.uniform.update('#thepass_1');
		}
	}
}

function enabledThePass(ct) {
	if(URL_VARS['id'] == 1 && ct != 'nl') {
		if($('#thepass_1').length > 0) {
			$('#thepass_1').attr('disabled',false);
			disableTooltip('thepass');
			$.uniform.update('#thepass_1');
		}
	}
}

function isBookingTheCard() {
	var type_booking = 'thecard';
	if(URL_VARS['booking_type'] == 'thecard') {
		return true;
	}
	return false;
}

function initBookingTheCard() {
	var type_booking = 'thecard';
	if(true == isBookingTheCard()) {
		if($('#header_top').length > 0) {
			$('#header_top').addClass('header_thecard');
		}
		if($('#ttc_1').length > 0) {
			$('#ttc_1').attr('checked',true);
			$.uniform.update('#ttc_1');
		}
		return true;
	}
	return false;
}

function disabledAbonnements() {
	// B2B
	if(URL_VARS['id'] == 9) {
		if($('.form_box_lys').length > 0) {
			$('.form_box_lys').hide();
			$('.form_checkbox_lys').attr('disabled',true);
			$('.form_text_num_lys').attr('disabled',true);
		}
		if($('.form_box_thepass').length > 0) {
			$('.form_box_thepass').hide();
			$('.form_checkbox_thepass').attr('disabled',true);
			$('.form_select_passager_thepass').attr('disabled',true);
		}
	}
}

function boookingTooltip() {
	$('.booking_show_tooltip_type').tooltip({
		delay: 0,
		showURL: false,
		bodyHandler: function() {
			return $('#booking_tooltip_passager').html();
		}
	});
}

function initErrors() {
	if($("#date_aller").length > 0) {
		if($("#date_aller").closest('.form_box_date.error').length > 0) {
			$("#date_aller").addClass('error');
		}
	}
	if($("#date_retour").length > 0) {
		if($("#date_retour").closest('.form_box_date.error').length > 0) {
			$("#date_retour").addClass('error');
		}
	}
}

var membres_thecard = [];
var passagers_telephone = [];
var passagers_telephone_show = [];
function formElementsFocus() {
	$('.global').each( function() {
		$(this).click( function () {
			if(this.id != '#btn_valider') {
				$('.global').removeClass('active');
				$(this).addClass('active');
			}
		});
	});
	monVoyageMesDates();
}

function monVoyageMesDates() {
	$('.global').removeClass('active');
	$('#mon_voyage_mes_dates_global').addClass('active');
}

function initMonVoyageMesDates() {
	if($(".datepicker").length > 0) {
		$(".datepicker").datepicker("destroy");
	}
	dateAllerBooking();
	if($("#date_aller").length > 0) {
		// Date Retour
		if(isValidDate($("#date_aller").val(), LANGUAGE)) {
			dateRetourBooking();
		}
	}
	initTgb();
	autocompleteTGB();
	choiceTgb();
	synchronizeTime();
	clickAllerSimple();
	initAllerSimple();
}

function initMonConfort() {
	if(default_comfort == '') {
		if($(".comfort-2").length > 0 && $.inArray('2', disabled_comfort) < 0) {
			if(default_comfort == '' && $("#comfort_2").length > 0) {
				if(true === $("#comfort_2").attr('checked')) {
					default_comfort = 2;
				}
			}
		}
		if($(".comfort-1").length > 0 && $.inArray('1', disabled_comfort) < 0) {
			if($("#comfort_1").length > 0) {
				if(true === $("#comfort_1").attr('checked')) {
					default_comfort = 1;
				}
			}
		}
	}
	for(i=1; i <= 2; i++) {
		if($(".comfort-"+i).length > 0 && $.inArray(""+i, disabled_comfort) >= 0) {
			$("#comfort_"+i).attr('disabled',true);
			$("#comfort_"+i).attr('checked',false);
			default_comfort =(i==1)? 2 : 1;
			$.uniform.update("#comfort_"+i);
		} else {
			$("#comfort_"+i).attr('disabled',false);
			$("#comfort_"+i).attr('checked',true);
			$(".comfort-"+i).removeClass('inactive');
			$(".label-cf"+i).removeClass('inactive');
			$.uniform.update("#comfort_"+i)
		}
	}

	initComfort(default_comfort);
	pushConfort(default_comfort);

}

function initMesBillets() {
	if($('#type_billet').val() != '' && $('#type_billet').val() != default_ticket) {
		default_ticket = ( $('#type_billet').val() == 'eticket')? 'eticket' : 'paper';
	}
	initTicket(default_ticket);
	initPaysRetrait();
}

function initLesPassagers() {
	synchronizePassengers();
	changePassengers();
	checkedTheCard();
	checkedThePass();
	changeAbonnementThepass();
	checkedLys();
	focusLys();
	blurLys();
	synchronizeTypePassagerFirst();
	initTypePassagers();
	synchronizeTooltipKidAll();
	initAbonnements();
	initMobileTicketing();
	initInfosPassagersTelephone();
	initCopyDataCheck();
	initCopyData();
}

// Mon Voyage Mes dates

function synchronizeStationsDeparture() {
	if($("#station_depart").length > 0) {
		var station = $('#station_depart').val();
		if(undefined != booking_stations_map[station]) {
			synchronizeTgb(station,'station_depart');
			//			if(station != '' && $("#station_arrivee").length > 0){
			if($("#station_arrivee").length > 0) {
				var station_arrivee = $('#station_arrivee').val();
				if($("#station_arrivee > option").length > 0) {
					$("#station_arrivee > option").remove();
				}

				if($("#station_arrivee > optgroup").length > 0) {
					$("#station_arrivee > optgroup").remove();
				}
				var in_array_station_arrivee = false;
				if(booking_stations_map[station].length > 1) {
					$("#station_arrivee").
					append($("<option></option>").
					attr("value",'').
					attr("id",'arr_').
					text(label_gare_depart));
				}
				for (i=0; i < booking_stations_map[station].length; i++) {
					code_ssim = booking_stations_map[station][i];
					id_station = 'arr_'+code_ssim;
					name_station = booking_stations[code_ssim];
					$("#station_arrivee").
					append($("<option></option>").
					attr("value",code_ssim).
					attr("id",id_station).
					text(name_station));

					if(station_arrivee == code_ssim) {
						in_array_station_arrivee = true;
					}
				}
				selectStationsSort('station_arrivee',label_gare_arrivee);
				if(station_arrivee != '') {
					if(true !== in_array_station_arrivee) {
						station_arrivee = '';
					}
					$("#station_arrivee").val(station_arrivee);
					synchronizeTgb(station_arrivee,'station_arrivee');
				}
				$.uniform.update("#station_depart");
				$.uniform.update("#station_arrivee");
			}

			var id_booking = $('#id_booking').val();
			if(id_booking == ID_BOOKING_FLASH_NEIGE) {

				var date_aller_datepicker = $("#date_aller").datepicker('getDate');

				var d = $('#station_depart').val();
				var arr = $('#station_arrivee').val();

				tab_actif     = Array ();
				tab_actif_cf  = Array ();

				if ( d == 'BEBMI' ) {
					tab_actif    = tab_1;
					tab_actif_cf = tab_1_cf;
				} else if ( d == 'BEABC') {
					tab_actif    = tab_2;
					tab_actif_cf = tab_2_cf;
				} else if (arr =='BEBMI') {
					tab_actif    = tab_3;
					tab_actif_cf = tab_3_cf;
				} else if (arr =='BEABC') {
					tab_actif    = tab_4;
					tab_actif_cf = tab_4_cf;
				} else if (d.substring(0,2) == 'NL') {
					tab_actif    = tab_5;
					tab_actif_cf = tab_5_cf;
				} else if (arr.substring(0,2) == 'NL') {
					tab_actif    = tab_6;
					tab_actif_cf = tab_6_cf;
				}
				if ( d == 'BEBMI' || d == 'BEABC' || arr =='BEBMI' || arr =='BEABC' || d.substring(0,2) == 'NL' || arr.substring(0,2) == 'NL') {
					if( null != date_aller_datepicker && $.inArray(date_aller_datepicker.getTime() , tab_actif) < 0) {
						$("#date_aller").datepicker("setDate",null);
					}
				}
			}
		}
	}
}

function synchronizeStationsDepartureChange() {
	if($("#station_depart").length > 0) {
		$('#station_depart').change( function() {
			synchronizeStationsDeparture();
			synchronizeCalendarAller();
			synchronizeCalendarRetour();
			$("#station_arrivee").val('');
			choiceLondon();
			choiceSeason();
			paysRetraitNl();
			var station_arrivee = $('#station_arrivee').val();
			if (station_arrivee != '') {
				pushDestination(station_arrivee);
			}
			synchronizePaysRetraitTgb();
			synchronizeTimeAjax('dep');
			synchronizeInfoTrafic();
			synchronizeTimeAjax('arr');
			$.uniform.update("#station_arrivee");
		});
	}
}

function synchronizeStationsArrival() {
	if($("#station_arrivee").length > 0) {
		$('#station_arrivee').change( function() {
			var station = $('#station_arrivee').val();
			synchronizeTgb(station,'station_arrivee');
			if (station != '') {
				pushDestination(station);
			}
			synchronizeCalendarAller();
			synchronizeCalendarRetour();
			verifyTicket();
			synchronizeInfoTrafic();
			choiceLondon();
			choiceSeason();
			paysRetraitNl();
			synchronizePaysRetraitTgb();
			synchronizeTimeAjax('dep');
			synchronizeTimeAjax('arr');

			var id_booking = $('#id_booking').val();
			if(id_booking == ID_BOOKING_FLASH_NEIGE) {

				var date_retour_datepicker = $("#date_retour").datepicker('getDate');

				var d = $('#station_depart').val();
				var arr = $('#station_arrivee').val();

				tab_actif     = Array ();
				tab_actif_cf  = Array ();

				if ( d == 'BEBMI' ) {
					tab_actif    = tab_1;
					tab_actif_cf = tab_1_cf;
				} else if ( d == 'BEABC') {
					tab_actif    = tab_2;
					tab_actif_cf = tab_2_cf;
				} else if (arr =='BEBMI') {
					tab_actif    = tab_3;
					tab_actif_cf = tab_3_cf;
				} else if (arr =='BEABC') {
					tab_actif    = tab_4;
					tab_actif_cf = tab_4_cf;
				} else if (d.substring(0,2) == 'NL') {
					tab_actif    = tab_5;
					tab_actif_cf = tab_5_cf;
				} else if (arr.substring(0,2) == 'NL') {
					tab_actif    = tab_6;
					tab_actif_cf = tab_6_cf;
				}
				if (arr =='BEBMI' || arr =='BEABC'|| arr.substring(0,2) == 'NL') {
					if( null != date_retour_datepicker && $.inArray(date_retour_datepicker.getTime() , tab_actif) < 0) {
						$("#date_retour").datepicker("setDate",null);
					}
				}
			}
		});
	}
}

var already_call = false;
var dorsale_wallone = new Array('BECRL', 'BEQMO','BEQNM');
var dorsale_wallone_exist = new Array;
function synchronizeInfoTrafic() {
	var o = $('#station_depart').val();
	var d = $('#station_arrivee').val();
	var date_aller = $('#date_aller').val();
	var date_retour = $('#date_retour').val();
	if(o != '' && d != '' && isValidDate(date_aller, LANGUAGE)   ) {
		already_call = true;
		if ($.inArray(o, dorsale_wallone) >= 0 && dorsale_wallone_exist[o] != undefined) {
			return;
		}
		if ($.inArray(o, dorsale_wallone) >= 0 ) {
			dorsale_wallone_exist [o] = true;
		}
		if ($.inArray(d, dorsale_wallone)>= 0 && dorsale_wallone_exist[d] != undefined ) {
			return;
		}
		if ($.inArray(d, dorsale_wallone)>= 0) {
			dorsale_wallone_exist [d] = true;
		}
		ajaxDate = new Date();
		$.ajax({
			type: "GET",
			url: domain_name+'?ajax=Infotrafic_News',
			data: "o="+o+'&d='+d+'&date_aller='+date_aller+'&date_retour='+date_retour+'&lg='+LANGUAGE+'&country='+COUNTRY+'&ts='+ajaxDate.getTime(),
			success: function(msg) {
				if (msg != '') {
					// affiche bloc suivant
					$('#infotrafic_popin_conteneur').html(msg);
					$('.popin_content').html(null);
					popin_info_trafic = $('#infotrafic_popin_conteneur');
					popin_info_trafic.popin({id_content:'#infotrafic_popin_conteneur'});
					popin_info_trafic.show();
				} else {
					if ($.inArray(o, dorsale_wallone) >= 0 ) {
						delete dorsale_wallone_exist [o] ;
					}
					if ($.inArray(d, dorsale_wallone)>= 0) {
						delete dorsale_wallone_exist [d] ;
					}
				}
			}
		});
	}
}

function choiceLondon() {
	var o = $('#station_depart').val();
	var d = $('#station_arrivee').val();
	if(o == CODE_SSIM_LONDRES || d == CODE_SSIM_LONDRES) {
		disabledTicket('eticket');
		if(TICKETLESS_ACCES == true) {
			enableTooltip('tkl', label_booking_tkl_indisponible);
		}
	} else {
		if($.inArray('eticket', tickets) >= 0 && TICKETLESS_ACCES == true) {
			enabledTicket('eticket');
			disableTooltip('tkl');
		}
	}
}

function synchronizeTgb(station,id) {
	if($("#tgb_"+id).length > 0) {
		if (id == "station_depart") {
			$('#mes_dates_retour').addClass('tgb_active');
			$('#mon_voyage_arrivee').addClass('tgb_active');
		}
		var parent_div = $("#tgb_"+id).closest('.form_box_tgb').closest('.form_box');
		if(isTGBAllowStation(station) && COUNTRY == 'be' && use_tgb == 1) {
			parent_div.show();
			choiceTgb();
		} else {
			parent_div.hide();
			if (id == "station_depart") {
				$('#mes_dates_retour').removeClass('tgb_active');
				$('#mon_voyage_arrivee').removeClass('tgb_active');
			}
			choiceTgb();
		}
	}
}

function initTgb() {
	synchronizeTgb($('#station_depart').val(),'station_depart');
	synchronizeTgb($('#station_arrivee').val(),'station_arrivee');

	if(use_tgb == 1) {
		if((false !== isTGBAllowStation($('#station_depart').val())) || (false !== isTGBAllowStation($('#station_arrivee').val()))) {
			default_ticket = 'paper';
			disabledTicket('eticket');
			if($.inArray('eticket', tickets) >= 0) {
				enableTooltip('tkl', label_trajet_tgb_tkl_indisponible);
			}
		}
	}
}

function choiceTgb() {
	if((false !== isTGBAllowStation($('#station_depart').val())) || (false !== isTGBAllowStation($('#station_arrivee').val()))) {
		disabledTicket('eticket');
		if($.inArray('eticket', tickets) >= 0 && TICKETLESS_ACCES == true) {
			enableTooltip('tkl', label_trajet_tgb_tkl_indisponible);
		}
		paysRetraitNl();
	} else {

		if($.inArray('eticket', tickets) >= 0 && TICKETLESS_ACCES == true) {
			enabledTicket('eticket');
		}
		if(TICKETLESS_ACCES == true) {
			disableTooltip('tkl');
		}
		paysRetraitNl();
	}
}

function autocompleteTGB() {
	if($(".form_autocomplete_tgb").length > 0) {
		if($('#tgb_station_depart').length > 0) {
			$('#tgb_station_depart').val(label_saisir_gare_depart);
		}
		if($('#tgb_station_arrivee').length > 0 ) {
			$('#tgb_station_arrivee').val(label_saisir_gare_arrivee);
		}

		$(".form_autocomplete_tgb").focus( function() {
			if($(this).val() == label_saisir_gare_depart || $(this).val() == label_saisir_gare_arrivee) {
				$(this).val('');
			}
		});
		$(".form_autocomplete_tgb").blur( function() {
			if($(this).val() == '') {
				if(this.id.search(/arrivee/i) > 0) {
					$(this).val(label_saisir_gare_arrivee);
				} else {
					$(this).val(label_saisir_gare_depart);
				}
			}
		});
		$(".form_autocomplete_tgb").autocomplete({
			minLength: 2,
			source: source_stations_tgb
		});
	}
}

function synchronizeTime() {
	if($("#station_depart").length > 0) {
		$('#station_depart').change( function() {
			synchronizeTimeAjax('dep');
		});
	}

	if($("#station_arrivee").length > 0) {
		$('#station_arrivee').change( function() {
			synchronizeTimeAjax('arr');
		});
	}
}

function synchronizeTimeAjax(field) {
	var departure = '';
	var aller = '';
	var retour = '';
	if($("#station_depart").length > 0) {
		departure = $('#station_depart').val();
	}
	if($("#station_arrivee").length > 0) {
		arrival = $('#station_arrivee').val();
	}
	if($("#date_aller").length > 0) {
		aller = $("#date_aller").val();
	}
	if($("#date_retour").length > 0) {
		retour = $("#date_retour").val();
	}
	if(arrival != '' && departure != '' && isValidDate(aller) && field == 'dep') {
		synchronizeTimeCallAjax('heure_aller',departure,arrival,aller);
	}

	if(arrival != '' && departure != '' && isValidDate(retour) && field == 'arr') {
		synchronizeTimeCallAjax('heure_retour',departure,arrival,retour);
	}

}

function synchronizeTimeCallAjax(id_select,dep,arr,d) {
	//alert(id+' '+dep+' '+arr+' '+d);
	if($("#"+id_select).length > 0) {
		ajaxDate = new Date();
		$.ajax({
			type: "GET",
			url: domain_name+'?ajax=Booking_Time',
			data: 'booking='+$('#id_booking').val()+ '&select='+id_select+ '&ori='+dep+'&ter='+arr+'&date='+d+'&lg='+LANGUAGE+'&ct='+COUNTRY+'&ts='+ajaxDate.getTime(),
			success: function(msg) {
				var obj = $.parseJSON(msg);
				var hour = false;
				if(obj.length > 0) {
					if($("#"+id_select+" > option").length > 0) {
						$("#"+id_select+" > option").remove();
					}
					var prefix_id = (id_select == 'heure_aller')? 'hdp_' : 'hap_';
					var id_date_pick = (id_select == 'heure_aller')? '#date_aller' : '#date_retour';
					var reg1=new RegExp("[:]","g");
					for(i=0; i < obj.length; i++) {
						var horaire_value = ''+obj[i];
						if(horaire_value == URL_VARS[$("#"+id_select).attr('name')]) {
							hour = URL_VARS[$("#"+id_select).attr('name')];
						} else if(DATE_PREVIEW == $(id_date_pick).val()) {
							if(HEURE_ACTUELLE < horaire_value && ( false == hour || hour > horaire_value || hour < HEURE_ACTUELLE)) {
								hour = horaire_value;
							}
						}
						if(horaire_value.indexOf(':') > 0) {
							var horaire_time = obj[i].split(':');
							var heure = horaire_time[0];
							var minute = horaire_time[1];
						} else {
							var heure = obj[i];
							var minute = '00';
						}
						option_content = heure+label_heure+minute;
						option_id = prefix_id+heure;
						$("#"+id_select).
						append($("<option></option>").
						attr("value",horaire_value).
						attr("id",option_id).
						text(option_content));
					}
				}

				if(false !== hour) {
					$("#"+id_select).val(hour);
				}
				$.uniform.update("#"+id_select);
			}
		});
	}
}

function synchronizeDateCallAjax(id_select) {
	// alert(id+' '+dep+' '+arr+' '+d);
	if($("#"+id_select).length > 0) {
		ajaxDate = new Date();
		$.ajax({
			type: "GET",
			url: domain_name+'?ajax=Booking_Date',
			data: 'booking='+$('#id_booking').val()+ '&select='+id_select+'&lg='+LANGUAGE+'&ct='+COUNTRY+'&ts='+ajaxDate.getTime(),
			success: function(msg) {
				$("#"+id_select).val(msg);
				$("#"+id_select).addClass('disabled');
				$.uniform.update("#"+id_select);
			}
		});
	}
}

function dateAllerBooking() {
	if($("#date_aller").length > 0) {
		if(choose_day != 0) {
			synchronizeCalendarAller();
		}
		if(use_ajax_calendar != 0) {
			synchronizeDateCallAjax('date_aller');
		}
		if(use_ajax_calendar_return != 0) {
			synchronizeDateCallAjax('date_retour');
		}
		synchronizeInfoTrafic();
	}
}

function dateRetourBooking(date) {
	// alert(date);
	if(($("#date_aller").length > 0) && isValidDate($("#date_aller").val(), LANGUAGE)) {
		synchronizeTimeAjax('dep');
		if($("#date_retour").length > 0) {
			if(choose_return_day == 0) {
				var date_aller = $("#date_aller").datepicker('getDate');
				var date_aller_str = $("#date_aller").val();
				var booking_min_date_retour_str = booking_min_date_retour;
				if (date_aller) {
					date_aller.setDate(date_aller.getDate() + restrict_return_days);
					date_aller_str = dateConvertFormat(date_aller,LANGUAGE);
					$("#date_retour").val(date_aller_str);
				}

			} else {
				if(isValidDate($("#date_retour").val(), LANGUAGE)) {
					var diff = daydiff(parseDate($("#date_aller").val()), parseDate($("#date_retour").val()));
					if(diff < 0) {
						// alert(diff);
						$("#date_retour").val(label_date_retour);
					}
				}
				synchronizeCalendarRetour();
				synchronizeInfoTrafic();
			}
		}
	} else {
		$("#date_retour").addClass('calendar-disabled');
	}
}

function synchronizeCalendarAller() {
	if($("#date_aller").length > 0) {
		$("#date_aller").datepicker("destroy");
		if($("#date_retour").length > 0) {
			$("#date_retour").addClass('calendar-disabled');
		}
	}
	if(isSoleilStation($("#station_depart").val()) || (isSoleilStation($("#station_arrivee").val()))) {
		createCalendarAller('soleil');
	} else if(isNeigeStation($("#station_depart").val()) || (isNeigeStation($("#station_arrivee").val()))) {
		createCalendarAller('neige');
	} else if(isNewGermanStation($("#station_depart").val()) || (isNewGermanStation($("#station_arrivee").val()))) {
		createCalendarAller('newgermanstation');
	} else if(isBxlAeroport($("#station_depart").val()) || (isBxlAeroport($("#station_arrivee").val()))) {
		createCalendarAller('bxlaeroport');
	} else {
		createCalendarAller('normal');
	}
}

function synchronizeCalendarRetour() {
	if($("#date_retour").length > 0) {
		$("#date_retour").datepicker("destroy");
	}
	if(($("#date_aller").length > 0) && isValidDate($("#date_aller").val(), LANGUAGE)) {
		if(isSoleilStation($("#station_depart").val()) || (isSoleilStation($("#station_arrivee").val()))) {
			createCalendarRetour('soleil');
		} else if(isNeigeStation($("#station_depart").val()) || (isNeigeStation($("#station_arrivee").val()))) {
			createCalendarRetour('neige');
		} else if(isNewGermanStation($("#station_depart").val()) || (isNewGermanStation($("#station_arrivee").val()))) {
			createCalendarRetour('newgermanstation');
		} else if(isBxlAeroport($("#station_depart").val()) || (isBxlAeroport($("#station_arrivee").val()))) {
			createCalendarRetour('bxlaeroport');
		} else {
			createCalendarRetour('normal');
		}
	}
}

function createCalendarAller(season) {
	if(choose_day != 0) {
		if(use_season_config != 1 && season!= 'newgermanstation') {
			season = 'normal';
		}
		switch(season) {
			case 'neige':
				$.datepicker.regional[LANGUAGE]['minDate'] = booking_min_date_aller_neige;
				$.datepicker.regional[LANGUAGE]['maxDate'] = booking_max_date_aller_neige;
				$.datepicker.regional[LANGUAGE]['beforeShowDay'] = excludeDatesAllerBookingNeige;
				break;
			case 'soleil':
				$.datepicker.regional[LANGUAGE]['minDate'] = booking_min_date_aller_soleil;
				$.datepicker.regional[LANGUAGE]['maxDate'] = booking_max_date_aller_soleil;
				$.datepicker.regional[LANGUAGE]['beforeShowDay'] = excludeDatesAllerBookingSoleil;
				break;
			case 'newgermanstation':
				$.datepicker.regional[LANGUAGE]['minDate'] = booking_min_date_aller_new_german_stations;
				$.datepicker.regional[LANGUAGE]['maxDate'] = booking_max_date_aller;
				$.datepicker.regional[LANGUAGE]['beforeShowDay'] = excludeDatesAllerBooking;
				break;
			case 'bxlaeroport':
				$.datepicker.regional[LANGUAGE]['minDate'] = booking_min_date_aller_bxl_aeroport;
				$.datepicker.regional[LANGUAGE]['maxDate'] = booking_max_date_aller;
				$.datepicker.regional[LANGUAGE]['beforeShowDay'] = excludeDatesAllerBooking;
				break;
			default:
				$.datepicker.regional[LANGUAGE]['minDate'] = booking_min_date_aller;
				$.datepicker.regional[LANGUAGE]['maxDate'] = booking_max_date_aller;
				$.datepicker.regional[LANGUAGE]['beforeShowDay'] = excludeDatesAllerBooking;
				break;
		}
		$.datepicker.regional[LANGUAGE]['onSelect'] = synchronizeDateAllerBooking;
		$("#date_aller").datepicker($.datepicker.regional[LANGUAGE]);
	}
}

function createCalendarRetour(season) {
	if(choose_day != 0 && choose_return_day != 0) {
		if(use_season_config != 1 && season!= 'newgermanstation') {
			season = 'normal';
		}
		var date_aller = $("#date_aller").datepicker('getDate');
		var date_aller_str = $("#date_aller").val();
		switch(season) {
			case 'neige':
				var booking_min_date_retour_str = booking_min_date_retour_neige;
				var restrict_days = restrict_return_days_neige;
				$.datepicker.regional[LANGUAGE]['maxDate'] = booking_max_date_retour_neige;
				$.datepicker.regional[LANGUAGE]['beforeShowDay'] = excludeDatesRetourBookingNeige;
				break;
			case 'soleil':
				var booking_min_date_retour_str = booking_min_date_retour_soleil;
				var restrict_days = restrict_return_days_soleil;
				$.datepicker.regional[LANGUAGE]['maxDate'] = booking_max_date_retour_soleil;
				$.datepicker.regional[LANGUAGE]['beforeShowDay'] = excludeDatesRetourBookingSoleil;
				break;
			case 'newgermanstation':
				var booking_min_date_retour_str = booking_min_date_retour_new_german_stations;
				var restrict_days = restrict_return_days;
				$.datepicker.regional[LANGUAGE]['maxDate'] = booking_max_date_retour;
				$.datepicker.regional[LANGUAGE]['beforeShowDay'] = excludeDatesRetourBooking;
				break;
			case 'bxlaeroport':
				var booking_min_date_retour_str = booking_min_date_retour_bxl_aeroport;
				var restrict_days = restrict_return_days;
				$.datepicker.regional[LANGUAGE]['maxDate'] = booking_max_date_retour;
				$.datepicker.regional[LANGUAGE]['beforeShowDay'] = excludeDatesRetourBooking;
				break;
			default:
				var booking_min_date_retour_str = booking_min_date_retour;
				var restrict_days = restrict_return_days;
				$.datepicker.regional[LANGUAGE]['maxDate'] = booking_max_date_retour;
				$.datepicker.regional[LANGUAGE]['beforeShowDay'] = excludeDatesRetourBooking;
				break;
		}
		if (date_aller) {
			date_aller.setDate(date_aller.getDate() + restrict_days);
			date_aller_str = dateConvertFormat(date_aller,LANGUAGE);
		}

		var diff = daydiff(parseDate(date_aller_str), parseDate(booking_min_date_retour));
		if(diff < 0) {
			var booking_min_date_retour_str = date_aller_str;
		}
		$.datepicker.regional[LANGUAGE]['minDate'] = booking_min_date_retour_str;
		$.datepicker.regional[LANGUAGE]['onSelect'] = synchronizeDateRetourBooking;
		$("#date_retour").datepicker($.datepicker.regional[LANGUAGE]);
		$("#date_retour").removeClass('calendar-disabled');
	}
}

function synchronizeDateAllerBooking(date,inst) {
	paysRetraitDe();
	choiceSeason();
	var date_aller = $("#date_aller").datepicker('getDate');
	synchronizeComfortByDate(date_aller);
	dateRetourBooking(date);

	var date_selectionnee = new Date(inst.currentYear, inst.currentMonth, inst.currentDay);

	var id_booking = $('#id_booking').val();
	if(id_booking == ID_BOOKING_FLASH_NEIGE) {
		if( $.inArray(date_selectionnee.getTime() , tab_actif) >= 0) {
			index = $.inArray(date_selectionnee.getTime() , tab_actif) ;
			if ($("#comfort_1").attr('checked')) {
				confort = '1';
			} else {
				confort = '2';
			}

			cf_autorise = tab_actif_cf[index];
			disabled_comfort = Array();
			for(i=1; i <= 2; i++) {
				if (cf_autorise.indexOf(i) <0 ) {
					disabled_comfort.push( i+ "" );
				}
			}

			initMonConfort();

		}
	}
	/*date_bloquage = new Date(2012,03,02);
	if (date_aller >= date_bloquage) {
		$('.popin_content').html(null);
		$('#message_02042012_copy').html($('#message_02042012').html());
		popin_02042012 = $('#message_02042012_copy');
		popin_02042012.popin({id_content:'#message_02042012_copy'});
		popin_02042012.show();
	}*/
	checkBlock02042012();

}

function synchronizeDateRetourBooking(date) {
	choiceSeason();
	var date_retour = $("#date_retour").datepicker('getDate');
	synchronizeComfortByDate(date_retour);
	synchronizeTimeAjax('arr');
	/*date_bloquage = new Date(2012,03,02);
	if (date_retour >= date_bloquage) {
		$('.popin_content').html(null);
		$('#message_02042012_copy').html($('#message_02042012').html());
		popin_02042012 = $('#message_02042012_copy');
		popin_02042012.popin({id_content:'#message_02042012_copy'});
		popin_02042012.show();
	}*/
	
	checkBlock02042012();
}

function excludeDatesAllerBooking(date) {
	var day = date.getDay();
	for (var i = 0; i < closed_days_aller.length; i++) {
		if (day == closed_days_aller[i]) {
			return [false];
		}

	}

	for (i = 0; i < closed_dates_aller.length; i++) {
		if (date.getMonth() == parseInt(closed_dates_aller[i][1],10) - 1 &&
		date.getDate() == parseInt(closed_dates_aller[i][2],10) &&
		date.getFullYear() == parseInt(closed_dates_aller[i][0],10)) {
			return [false];
		}
	}

	var id_booking = $('#id_booking').val();
	if(id_booking == ID_BOOKING_FLASH_NEIGE) {
		var d = $('#station_depart').val();
		var arr = $('#station_arrivee').val();

		tab_actif     = Array ();
		tab_actif_cf  = Array ();

		if ( d == 'BEBMI' ) {
			tab_actif    = tab_1;
			tab_actif_cf = tab_1_cf;
		} else if ( d == 'BEABC') {
			tab_actif    = tab_2;
			tab_actif_cf = tab_2_cf;
		} else if (arr =='BEBMI') {
			tab_actif    = tab_3;
			tab_actif_cf = tab_3_cf;
		} else if (arr =='BEABC') {
			tab_actif    = tab_4;
			tab_actif_cf = tab_4_cf;
		} else if (d.substring(0,2) == 'NL') {
			tab_actif    = tab_5;
			tab_actif_cf = tab_5_cf;
		} else if (arr.substring(0,2) == 'NL') {
			tab_actif    = tab_6;
			tab_actif_cf = tab_6_cf;
		}

		if ( d == 'BEBMI' || d == 'BEABC' || arr =='BEBMI' || arr =='BEABC' || d.substring(0,2) == 'NL' || arr.substring(0,2) == 'NL') {
			if( $.inArray(date.getTime() , tab_actif) < 0) {
				return [false];
			}
		}

	}
	return [true];
}

function excludeDatesAllerBookingSoleil(date) {
	var day = date.getDay();
	for (var i = 0; i < closed_days_aller_soleil.length; i++) {
		if (day == closed_days_aller_soleil[i]) {
			return [false];
		}

	}

	for (i = 0; i < closed_dates_aller_soleil.length; i++) {
		if (date.getMonth() == parseInt(closed_dates_aller_soleil[i][1],10) - 1 &&
		date.getDate() == parseInt(closed_dates_aller_soleil[i][2],10) &&
		date.getFullYear() == parseInt(closed_dates_aller_soleil[i][0],10)) {
			return [false];
		}
	}

	return [true];
}

function excludeDatesAllerBookingNeige(date) {
	var day = date.getDay();
	for (var i = 0; i < closed_days_aller_neige.length; i++) {
		if (day == closed_days_aller_neige[i]) {
			return [false];
		}

	}

	for (i = 0; i < closed_dates_aller_neige.length; i++) {
		if (date.getMonth() == parseInt(closed_dates_aller_neige[i][1],10) - 1 &&
		date.getDate() == parseInt(closed_dates_aller_neige[i][2],10) &&
		date.getFullYear() == parseInt(closed_dates_aller_neige[i][0],10)) {
			return [false];
		}
	}

	return [true];
}

function excludeDatesRetourBooking(date) {
	var day = date.getDay();
	for (var i = 0; i < closed_days_retour.length; i++) {
		if (day == closed_days_retour[i]) {
			return [false];
		}

	}

	for (i = 0; i < closed_dates_retour.length; i++) {
		if (date.getMonth() == parseInt(closed_dates_retour[i][1],10) - 1 &&
		date.getDate() == parseInt(closed_dates_retour[i][2],10) &&
		date.getFullYear() == parseInt(closed_dates_retour[i][0],10)) {
			return [false];
		}
	}
	var id_booking = $('#id_booking').val();
	if(id_booking == ID_BOOKING_FLASH_NEIGE) {
		var d = $('#station_depart').val();
		var arr = $('#station_arrivee').val();

		tab_actif     = Array ();
		tab_actif_cf  = Array ();

		if ( d == 'BEBMI') {
			tab_actif    = tab_3;
			tab_actif_cf = tab_3_cf;
		} else if ( d == 'BEABC') {
			tab_actif    = tab_4;
			tab_actif_cf = tab_4_cf;
		} else if ( arr == 'BEBMI') {
			tab_actif    = tab_1;
			tab_actif_cf = tab_1_cf;
		} else if ( arr == 'BEABC') {
			tab_actif    = tab_2;
			tab_actif_cf = tab_2_cf;
		} else if (d.substring(0,2) == 'NL') {
			tab_actif    = tab_5;
			tab_actif_cf = tab_5_cf;
		} else if (arr.substring(0,2) == 'NL') {
			tab_actif    = tab_6;
			tab_actif_cf = tab_6_cf;
		}

		if ( d == 'BEBMI' || d == 'BEABC' || arr == 'BEABC' || arr == 'BEBMI' || d.substring(0,2) == 'NL' || arr.substring(0,2) == 'NL') {
			if( $.inArray(date.getTime() , tab_actif) < 0) {
				return [false];
			}
		}

	}
	return [true];
}

function excludeDatesRetourBookingNeige(date) {
	var day = date.getDay();
	for (var i = 0; i < closed_days_retour_neige.length; i++) {
		if (day == closed_days_retour_neige[i]) {
			return [false];
		}

	}

	for (i = 0; i < closed_dates_retour_neige.length; i++) {
		if (date.getMonth() == parseInt(closed_dates_retour_neige[i][1],10) - 1 &&
		date.getDate() == parseInt(closed_dates_retour_neige[i][2],10) &&
		date.getFullYear() == parseInt(closed_dates_retour_neige[i][0],10)) {
			return [false];
		}
	}

	return [true];
}

function excludeDatesRetourBookingSoleil(date) {
	var day = date.getDay();
	for (var i = 0; i < closed_days_retour_soleil.length; i++) {
		if (day == closed_days_retour_soleil[i]) {
			return [false];
		}

	}

	for (i = 0; i < closed_dates_retour_soleil.length; i++) {
		if (date.getMonth() == parseInt(closed_dates_retour_soleil[i][1],10) - 1 &&
		date.getDate() == parseInt(closed_dates_retour_soleil[i][2],10) &&
		date.getFullYear() == parseInt(closed_dates_retour_soleil[i][0],10)) {
			return [false];
		}
	}

	return [true];
}

function initAllerSimple() {
	if($("#aller_simple").length > 0) {
		if(true === $("#aller_simple").attr('disabled')) {
			if($("#type_voyage_aller_simple").length > 0) {
				$("#type_voyage_aller_simple").addClass('inactive');
			}
		}
		if(true === $('#aller_simple').attr('checked')) {
			if($("#date_retour").length > 0) {
				$("#date_retour").datepicker("destroy");
				$("#date_retour").addClass("input_disabled");
				$("#date_retour").attr("disabled",true);
				$("#date_retour").val(label_date_retour);
				$("#heure_retour").addClass("select_disabled");
				$("#heure_retour").attr("disabled",true);
				$.uniform.update("#heure_retour");
			}
		} else {
			if($("#date_retour").length > 0) {
				$("#date_retour").removeClass("input_disabled");
				$("#date_retour").attr("disabled",false);
				$("#heure_retour").removeClass("select_disabled");
				$("#heure_retour").attr("disabled",false);
				$.uniform.update("#heure_retour");
				if(isValidDate($("#date_aller").val(), LANGUAGE)) {
					dateRetourBooking();
				}
			}
		}
	}
}

function clickAllerSimple() {
	if($('#aller_simple').length > 0) {
		$('#aller_simple').click( function() {
			if(true === $(this).attr('checked')) {
				if($("#date_retour").length > 0) {
					$("#date_retour").datepicker("destroy");
					$("#date_retour").addClass("input_disabled");
					$("#date_retour").attr("disabled",true);
					$("#date_retour").val(label_date_retour);
					$("#heure_retour").addClass("select_disabled");
					$("#heure_retour").attr("disabled",true);
					$.uniform.update('#aller_simple');
				}
			} else {
				if($("#date_retour").length > 0) {
					$("#date_retour").removeClass("input_disabled");
					$("#date_retour").attr("disabled",false);
					$("#heure_retour").removeClass("select_disabled");
					$("#heure_retour").attr("disabled",false);
					$.uniform.update('#aller_simple');
					if(isValidDate($("#date_aller").val(), LANGUAGE)) {
						dateRetourBooking();
					}
				}
			}
		});
	}
}

// Mon Voyage Mes dates

// Mon Confort

already_pushConfort = false ;
function pushConfort(default_comfort) {
	if($("#mon_confort").length > 0) {

		if (!already_pushConfort ) {
			$("#mon_confort").find('input').click( function() {
				if($(this).val() == 1) {
					$(".cf1").addClass('active');
					$(".cf2").removeClass('active');
				} else {
					$(".cf2").addClass('active');
					$(".cf1").removeClass('active');
				}
				ajaxDate = new Date();
				var id_booking = $('#id_booking').val();
				$.ajax({
					type: "GET",
					url: domain_name+'?ajax=Push_Confort',
					data: "cf="+$(this).val()+'&id_booking='+id_booking+'&lg='+LANGUAGE+'&ct='+COUNTRY+'&ts='+ajaxDate.getTime(),
					success: function(msg) {
						$('#mon_confort_push').html(msg);
					}
				});
			});
			already_pushConfort = true	;
		}

		ajaxDate = new Date();
		var id_booking = $('#id_booking').val();
		$.ajax({
			type: "GET",
			url: domain_name+'?ajax=Push_Confort',
			data: "cf="+default_comfort+'&id_booking='+id_booking+'&lg='+LANGUAGE+'&ct='+COUNTRY+'&ts='+ajaxDate.getTime(),
			success: function(msg) {
				$('#mon_confort_push').html(msg);
			}
		});
	}
}

function disabledComfortTable() {
	for(i=1; i <=2 ; i++) {
		if($("#comfort_"+i).length > 0) {
			if(true === $("#comfort_"+i).attr("disabled")) {
				if($(".comfort-"+i).length > 0) {
					$(".comfort-"+i).addClass('inactive');
					$(".cf"+i).removeClass('active');
					$(".label-cf"+i).addClass('inactive');
				}
			}
		}
	}
}

function initComfort(id) {
	disabledComfortTable();
	if($(".comfort-"+id).length > 0 && $.inArray(""+id, disabled_comfort) < 0) {
		if($("#comfort_"+id).length > 0) {
			$("#comfort_"+id).attr('checked',true);
			$(".cf"+id).addClass('active');
			//$.uniform.update("#comfort_"+id);
			$.uniform.update('input[name$="cf"]');
		}
		if (id == 2) {
			$("#mon_confort").find('input').click();
			$.uniform.update("#comfort_"+id);
		}
	}
}

function synchronizeComfortByDate(date_choose) {
	for(i=1; i <=2 ; i++) {
		if($("#comfort_"+i).length > 0) {
			if(true === excludeComfortDates(date_choose,i)) {
				if($(".comfort-"+i).length > 0) {
					$("#comfort_"+i).attr("disabled",true);
					$("#comfort_"+i).attr("checked",false);
					$(".comfort-"+i).addClass('inactive');
					var to_check = (i == 1)? 2 : 1;
					$("#comfort_"+to_check).attr("checked",true);
				}
			} else {
				if($(".comfort-"+i).length > 0 && $.inArray(""+i, disabled_comfort) < 0) {
					$("#comfort_"+i).attr("disabled",false);
					$(".comfort-"+i).removeClass('inactive');
				}
			}
		}
	}
	//	disabledComfortTable();
	$.uniform.update("#comfort_1");
	$.uniform.update("#comfort_2");
}

function excludeComfortDates(date,cf) {
	var day = date.getDay();
	if(cf == 1) {
		for (var i = 0; i < exclude_days_cf1.length; i++) {
			if (day == exclude_days_cf1[i]) {
				return true;
			}

		}

		for (i = 0; i < exclude_dates_cf1.length; i++) {
			if (date.getMonth() == parseInt(exclude_dates_cf1[i][1],10) - 1 &&
			date.getDate() == parseInt(exclude_dates_cf1[2],10) &&
			date.getFullYear() == parseInt(exclude_dates_cf1[i][0],10)) {
				return true;
			}
		}
	} else {
		for (var i = 0; i < exclude_days_cf2.length; i++) {
			if (day == exclude_days_cf2[i]) {
				return true;
			}

		}

		for (i = 0; i < exclude_dates_cf2.length; i++) {
			if (date.getMonth() == (parseInt(exclude_dates_cf2[i][1],10) - 1) &&
			date.getDate() == parseInt(exclude_dates_cf2[i][2],10) &&
			date.getFullYear() == parseInt(exclude_dates_cf2[i][0],10)) {
				return true;
			}
		}
	}

	return [false];
}

// Mon Confort

// Mes billets

function synchronizeTickets(id) {
	id_push = id;
	if(id == 'eticket') {
		if($("#mes_billets_eticket_div").length > 0) {
			$("#mes_billets_eticket_div").show();
		}
		if($("#mes_billets_eticket_onglet").length > 0) {
			$("#mes_billets_eticket_onglet").addClass('active');
		}
		if($("#mes_billets_eticket").length > 0) {
			$("#mes_billets_eticket").addClass('active');
		}
		if($("#mes_billets_papier_div").length > 0) {
			$("#mes_billets_papier_div").hide();
		}
		if($("#mes_billets_papier_onglet").length > 0) {
			$("#mes_billets_papier_onglet").removeClass('active');
		}
		if($("#mes_billets_papier").length > 0) {
			$("#mes_billets_papier").removeClass('active');
		}
		for(i=1; i <=6 ; i++) {
			if($(".les_passagers_infos_coordonnees").length > 0) {
				$(".les_passagers_infos_coordonnees").show();
				$("#les_passagers_infos_coordonnees_ttc_"+i).hide();
				$("#les_passagers_infos_coordonnees_light_"+i).hide();
				if($("#ttc_"+i).length > 0) {
					if(true === $("#ttc_"+i).attr('checked')) {
						if($("#div_tkl_mobile_ticketing_"+i).length > 0) {
							$("#div_tkl_mobile_ticketing_"+i).show();
						}
						if($("#les_passagers_infos_coordonnees_"+i).length > 0) {
							$("#les_passagers_infos_coordonnees_"+i).show();
							$("#les_passagers_infos_coordonnees_ttc_"+i).show();
						} else {
							if($("#les_passagers_infos_coordonnees_"+i).length > 0) {
								$("#les_passagers_infos_coordonnees_"+i).show();
								$("#les_passagers_infos_coordonnees_light_"+i).show();
								showHideCheckbox('sms_placement',i,'show');
								showHideCheckbox('newsletter',i,'show');
							}
						}
						// sao
						if ($('#div_ttc_mobile_ticketing_'+i).length > 0) {
							$('#div_ttc_mobile_ticketing_'+i).show();
						}
						// sao
					} else {
						if($("#les_passagers_infos_coordonnees_"+i).length > 0) {
							$("#les_passagers_infos_coordonnees_"+i).show();
							$("#les_passagers_infos_coordonnees_light_"+i).show();
							showHideCheckbox('sms_placement',i,'show');
							showHideCheckbox('newsletter',i,'show');
						}
					}
				}
			}
			enabledMobileTicketing(i);
		}
		if(TICKETLESS_ACCES != true)
			enabledThePass();
	} else if(id == 'paper') {
		if($("#mes_billets_eticket_div").length > 0) {
			$("#mes_billets_eticket_div").hide();
		}
		if($("#mes_billets_eticket_onglet").length > 0) {
			$("#mes_billets_eticket_onglet").removeClass('active');
		}
		if($("#mes_billets_eticket").length > 0) {
			$("#mes_billets_eticket").removeClass('active');
		}
		if($("#mes_billets_papier_div").length > 0) {
			$("#mes_billets_papier_div").show();
		}
		if($("#mes_billets_papier_onglet").length > 0) {
			$("#mes_billets_papier_onglet").addClass('active');
		}
		if($("#mes_billets_papier").length > 0) {
			$("#mes_billets_papier").addClass('active');
		}
		id_push = id = 'paper';
		if($(".input_pays_retrait").length > 0) {
			for(i=0; i < COUNTRIES_THALYS.length; i++) {
				var id_input = "#pays_retrait_"+COUNTRIES_THALYS[i];
				if(true === $(id_input).attr('checked')) {
					id_push = COUNTRIES_THALYS[i];
					disabledThePass(id_push);
				}
			}
		}
		for(i=1; i <=6 ; i++) {
			if($("#ttc_"+i).length > 0) {
				$("#les_passagers_infos_coordonnees_light_"+i).hide();
				if(true === $("#ttc_"+i).attr('checked')) {
					if($("#div_tkl_mobile_ticketing_"+i).length > 0) {
						$("#div_tkl_mobile_ticketing_"+i).hide();
					}

					if($("#les_passagers_infos_coordonnees_"+i).length > 0) {
						$("#les_passagers_infos_coordonnees_"+i).show();
						$("#les_passagers_infos_coordonnees_ttc_"+i).show();
					}
				} else {
					if($("#les_passagers_infos_coordonnees_"+i).length > 0) {
						$("#les_passagers_infos_coordonnees_"+i).hide();
						$("#les_passagers_infos_coordonnees_ttc_"+i).hide();
					}
				}
			}
			disabledMobileTicketing(i);
		}
		// sao
		if($('.div_mobile_ticketing').length > 0) {
			$('.div_mobile_ticketing').hide();
		}
		// sao
	}
	if($("#type_billet").length > 0) {
		var ticket_push = (id_push == 'eticket')? 'eticket' : 'paper';
		$("#type_billet").val(ticket_push);
	}
	mesBilletsFocus();
	pushBillets(id_push);
	synchronizeTypePassagerOther();
}

function initTicket(id) {
	synchronizeTickets(id);
	verifyTicket();
}

function verifyTicket() {
	if(use_season_config != 1) {
		season = 'normal';
	} else {

		if(isSoleilStation($("#station_depart").val()) || (isSoleilStation($("#station_arrivee").val()))) {
			season = 'soleil';
		} else if(isNeigeStation($("#station_depart").val()) || (isNeigeStation($("#station_arrivee").val()))) {
			season = 'neige';
		} else {
			season = 'normal';
		}
	}
	switch(season) {
		case 'neige':
			if($.inArray('eticket', tickets_neige) < 0) {
				disabledTicket('eticket');
				if(TICKETLESS_ACCES == true) {
					enableTooltip('tkl', label_booking_tkl_indisponible);
				}
			} else {
				if(TICKETLESS_ACCES == true) {
					enabledTicket('eticket');
					disableTooltip('tkl');
				}
			}
			if($.inArray('paper', tickets_neige) < 0) {
				disabledTicket('paper');
				enableTooltip('paper', label_booking_thepass_non_disponible);
			} else {
				enabledTicket('paper');
			}
			break;
		case 'soleil':
			if($.inArray('eticket', tickets_soleil) < 0) {
				disabledTicket('eticket');
				if(TICKETLESS_ACCES == true) {
					enableTooltip('tkl', label_booking_tkl_indisponible);
				}
			} else {
				enabledTicket('eticket');
				disableTooltip('tkl');
			}
			if($.inArray('paper', tickets_soleil) < 0) {
				disabledTicket('paper');
				enableTooltip('paper', label_booking_thepass_non_disponible);
			} else {
				enabledTicket('paper');
			}
			break;
		default:
			if($.inArray('eticket', tickets) < 0) {
				disabledTicket('eticket');
				if(TICKETLESS_ACCES == true) {
					enableTooltip('tkl', label_booking_tkl_indisponible);
				}
			} else {
				if(TICKETLESS_ACCES == true) {
					enabledTicket('eticket');
					disableTooltip('tkl');
				}
			}
			if($.inArray('paper', tickets) < 0) {
				disabledTicket('paper');
				enableTooltip('paper', label_booking_thepass_non_disponible);
			} else {
				enabledTicket('paper');
			}
			break;
	}
}

function mesBilletsFocus() {
	$('.global').removeClass('active');
	$('#mes_billets_global').addClass('active');
}

function enabledTicket(id) {
	if(id == 'eticket') {
		if($("#mes_billets_eticket_onglet").length > 0) {
			var o = $('#station_depart').val();
			var d = $('#station_arrivee').val();
			if(false === isTGBAllowStation(o) && false === isTGBAllowStation(d) && false === isSeasonStation(o) && false === isSeasonStation(d) && o != CODE_SSIM_LONDRES && d != CODE_SSIM_LONDRES) {
				$("#mes_billets_eticket_onglet").bind('click', function() {
					synchronizeTickets('eticket');
				});
				$("#mes_billets_eticket_onglet").removeClass('inactive');
			}
		}
	} else if(id == 'paper') {
		if($("#mes_billets_papier_onglet").length > 0) {
			$("#mes_billets_papier_onglet").bind('click', function() {
				synchronizeTickets('paper');
			});
			$("#mes_billets_papier_onglet").removeClass('inactive');
		}
	}
}

function disabledTicket(id) {
	if(id == 'eticket') {
		if($("#mes_billets_eticket_onglet").length > 0) {
			$("#mes_billets_eticket_onglet").removeAttr('onclick');
			$("#mes_billets_eticket_onglet").unbind('click');
			$("#mes_billets_eticket_onglet").addClass('inactive');
			synchronizeTickets('paper');
		}
	} else if(id == 'paper') {
		if($("#mes_billets_papier_onglet").length > 0) {
			$("#mes_billets_papier_onglet").removeAttr('onclick');
			$("#mes_billets_papier_onglet").unbind('click');
			$("#mes_billets_papier_onglet").addClass('inactive');
			synchronizeTickets('eticket');
		}
	}
}

function pushBillets(billet) {
	ajaxDate = new Date();
	$.ajax({
		type: "GET",
		url: domain_name+'?ajax=Push_Billets',
		data: "billet="+billet+'&lg='+LANGUAGE+'&ct='+COUNTRY+'&ts='+ajaxDate.getTime(),
		success: function(msg) {
			$('#mes_billets_push').html(msg);
		}
	});
}

function initPaysRetrait() {
	hideTooltipPaysRetrait();
	var id_le_salon_input = false;
	var id_le_salon_push = false;
	var already_checked = false;
	for(i=0; i < COUNTRIES_THALYS.length; i++) {
		var id = COUNTRIES_THALYS[i];
		var id_input = "#pays_retrait_"+COUNTRIES_THALYS[i];
		if($(id_input).length > 0) {
			if($.inArray($(id_input).val(), pays_retrait_thalys) < 0) {
				disabledPaysRetrait(id);
			} else {
				if((URL_VARS['id'] == 8 || URL_VARS['id'] == 4) && COUNTRY == COUNTRIES_THALYS[i]) {
					id_le_salon_input = id_input;
					id_le_salon_push = id;
				}
				if(true === $(id_input).attr('checked')) {
					already_checked = id;
					pushBillets(id);
				}
				enabledPaysRetrait(id);
			}
		}
	}
	paysRetraitDe();
	paysRetraitNl();
	if($(".input_pays_retrait").length > 0) {
		$(".input_pays_retrait").click( function() {
			synchronizeTypePassagerOther();
			synchronizePaysRetraitTgb();
			synchronizeThepass($(this).val());
			if($(this).val() == 'nl') {
				disabledThePass($(this).val());
			} else if(URL_VARS['id'] != 8 && URL_VARS['id'] != 4) {
				enabledThePass();
			}

		});
	}
	synchronizeTypePassagerOther();
	synchronizePaysRetraitTgb();
	if(URL_VARS['id'] == 8 || URL_VARS['id'] == 4) {
		if(false === already_checked) {
			$(id_le_salon_input).attr('checked',true);
			pushBillets(id_le_salon_push);
		}
	}
	if(already_checked == 'nl') {
		disabledThePass();
	} else if(URL_VARS['id'] != 8 && URL_VARS['id'] != 4) {
		enabledThePass();
	}
	$.uniform.update('.input_pays_retrait');
}

function synchronizeThepass(country_checked) {
	if(country_checked == 'nl') {
		disabledThePass();
	} else if(URL_VARS['id'] != 8 && URL_VARS['id'] != 4) {
		enabledThePass();
	}
}

function synchronizePaysRetraitTgb() {
	var o = $('#station_depart').val();
	var d = $('#station_arrivee').val();
	var pays_checked = false;
	if($("#type_billet").val() == 'paper') {
		for(k = 0; k < COUNTRIES_THALYS.length; k++ ) {
			pays_to_test = COUNTRIES_THALYS[k];
			if($("#pays_retrait_"+pays_to_test).length > 0 && true === $("#pays_retrait_"+pays_to_test).attr('checked')) {
				pays_checked = pays_to_test;
				break;
			}
		}
	}
	if((false !== isTGBAllowStation(o) || false !== isTGBAllowStation(d)) && false !== pays_checked) {
		switch(COUNTRY) {
			case 'be':
				if($('#tgb_sncb').length > 0) {
					$('#tgb_sncb').hide();
				}
				if(pays_checked != 'be' && $('#tgb_ravel').length > 0) {
					if(false !== isTGBAllowStation(o)) {
						$('#tgb_select_depart_retrait').closest('.form_select_stations').closest('.form_box').show();
						$('#tgb_select_arrivee_retrait').closest('.form_select_stations').closest('.form_box').hide();
					} else if(false !== isTGBAllowStation(d)) {
						$('#tgb_select_arrivee_retrait').closest('.form_select_stations').closest('.form_box').show();
						$('#tgb_select_depart_retrait').closest('.form_select_stations').closest('.form_box').hide();
					}
					$('#tgb_ravel').show();
				} else {
					$('#tgb_ravel').hide();
				}
				break;
			case 'de':
			case 'fr':
				if($('#tgb_ravel').length > 0) {
					$('#tgb_ravel').hide();
				}
				if(pays_checked != 'fr' && pays_checked != 'de' && $('#tgb_sncb').length > 0) {
					if(false !== isTGBAllowStation(o)) {
						$('#tgb_station_depart_retrait').val(label_saisir_gare_depart);
						$('#tgb_station_depart_retrait').closest('.form_box_tgb').closest('.form_box').show();
						$('#tgb_station_arrivee_retrait').closest('.form_box_tgb').closest('.form_box').hide();
					} else if(false !== isTGBAllowStation(d)) {
						$('#tgb_station_arrivee_retrait').val(label_saisir_gare_arrivee);
						$('#tgb_station_arrivee_retrait').closest('.form_box_tgb').closest('.form_box').show();
						$('#tgb_station_depart_retrait').closest('.form_box_tgb').closest('.form_box').hide();
					}
					$('#tgb_sncb').show();
				} else {
					$('#tgb_sncb').hide();
				}
				break;
		}
	}
}

function selectStationsSortTGB(id_select,label_select) {
	var option_tgb = [];
	if($("#"+id_select).length > 0) {
		var str = '';
		select_station = $("#"+id_select);
		station = select_station.val();
		if(select_station.containsOption("")) {
			select_station.removeOption("");
		}
		select_station.sortOptions();
		if(select_station.children('option').length > 1) {
			select_station.children('option').each( function() {
				option_tgb.push( { text: $(this).text(), value: $(this).val(), id: $(this).attr('id') } );
			});
			if($("#"+id_select+" > option").length > 0) {
				$("#"+id_select+" > option").remove();
			}

			if($("#"+id_select+" > optgroup").length > 0) {
				$("#"+id_select+" > optgroup").remove();
			}
			if(undefined == label_select) {
				label_select = label_faites_votre_choix;
			}
			$("#"+id_select).
			append($("<option></option>").
			attr("value","").
			attr("id","select_empty").
			text(label_select));
			// Autres gares Belges
			if(option_tgb.length > 0) {
				$("#"+id_select).append('<optgroup class="select-tgb" label="'+label_autres_gares_belges+'">');
				for( var i = 0; i < option_tgb.length; i++ ) {
					$("#"+id_select).
					append($("<option></option>").
					attr("value",option_tgb[i]['value']).
					attr("id",option_tgb[i]['id']).
					text(option_tgb[i]['text']));
				}
				$("#"+id_select).append('</optgroup>');
			}
		}
		select_station.val(station);
		$.uniform.update("#"+id_select);
	}
}

function disabledPaysRetrait(suffixe) {
	var id = "#pays_retrait_"+suffixe;
	var id_flag = "#pays_retrait_flag_"+suffixe;
	if($(id).length > 0) {
		$(id).attr('checked',false);
		$(id).attr('disabled',true);
		$(id).unbind('click');
		var parent_div = $(id).closest('.pays-retrait');
		parent_div.addClass('inactive');
		// $(id_flag).unbind('click');
		enableTooltip(suffixe, eval('label_booking_error_trajet_paper_'+suffixe) ); //sao

	}
	$.uniform.update('.input_pays_retrait');
}

function enabledPaysRetrait(suffixe) {
	var id = "#pays_retrait_"+suffixe;
	var id_flag = "#pays_retrait_flag_"+suffixe;
	if($(id).length > 0) {
		if($.inArray($(id).val(), pays_retrait_thalys) >= 0) {
			$(id).attr('disabled',false);
			$(id).bind('click', function() {
				if($.inArray($(id).val(), pays_retrait_thalys) >= 0) {
					pushBillets(suffixe);
					var parent_div = $(id).closest('.pays-retrait');
					parent_div.removeClass('inactive');
					if($(id).val() == 'nl') {
						disabledLysAll();
					} else {
						enabledLys();
					}
				}
				$.uniform.update('.input_pays_retrait');
			});
			if($.inArray($(id).val(), pays_retrait_thalys) >= 0) {
				var parent_div = $(id).closest('.pays-retrait');
				parent_div.removeClass('inactive');
				if($(id).val() != 'nl') {
					enabledLys();
				}
			}
		}
	}
}

function paysRetraitDe() {
	id_pays = 'de';
	if($("#date_aller").length > 0) {
		date_aller = $("#date_aller").val();
		if(isValidDate(date_aller, LANGUAGE)) {
			var diff = daydiff(parseDate(booking_date_today), parseDate(date_aller));
			if(diff <= 7 && URL_VARS['id'] != 8 && URL_VARS['id'] != 5) {
				disabledPaysRetrait(id_pays);
				enableTooltip(id_pays, label_booking_commander_7_jours_avant);
			} else {
				enabledPaysRetrait(id_pays);
				disableTooltip(id_pays);
			}
		}
	}
}

function paysRetraitNl() {
	id_pays = 'nl';
	if(((false !== isTGBAllowStation($('#station_depart').val())) || (false !== isTGBAllowStation($('#station_arrivee').val()))  && URL_VARS['id'] != 8  && URL_VARS['id'] != 5)) {
		disabledPaysRetrait(id_pays);
		enableTooltip(id_pays, label_booking_tgb_indisponible);
	} else if($("#station_depart").val() != "" && $("#station_arrivee").val() != "" && $("#station_depart").val().substr(0,2).toLowerCase() != 'nl' && $("#station_arrivee").val().substr(0,2).toLowerCase() != 'nl' && URL_VARS['id'] != 8 && URL_VARS['id'] != 5) {
		disabledPaysRetrait(id_pays);
		enableTooltip(id_pays, label_booking_error_trajet_paper_nl);
	} else {
		enabledPaysRetrait(id_pays);
		disableTooltip(id_pays);
	}
}

function hideTooltipPaysRetrait() {
	if($(".booking_show_tooltip").length > 0) {
		$(".booking_show_tooltip").hide();
	}
}

function disableTooltip(suffixe) {
	if(suffixe == 'tkl') {
		var o = $("#station_depart").val();
		var d = $("#station_arrivee").val();
		if(false === isTGBAllowStation(o) && false === isTGBAllowStation(d) && false === isSeasonStation(o) && false === isSeasonStation(d) && o != CODE_SSIM_LONDRES && d != CODE_SSIM_LONDRES) {
			if($.inArray('eticket', tickets) >= 0) {
				$('#mes_billets_eticket').tooltip('destroy');
				if($("#booking_show_tooltip_"+suffixe).length > 0) {
					$("#booking_show_tooltip_"+suffixe).hide();
				}
			}
		}
	} else if(suffixe == 'paper') {
		if($.inArray('paper', tickets) >= 0) {
			$('#mes_billets_papier').tooltip('destroy');
			if($("#booking_show_tooltip_"+suffixe).length > 0) {
				$("#booking_show_tooltip_"+suffixe).hide();
			}
		}
	} else if(suffixe == 'thepass') {
		if($.inArray('eticket', tickets) >= 0) {
			$('#thepass_1').closest('.form_box_thepass').tooltip('destroy');
			if($("#booking_show_tooltip_"+suffixe).length > 0) {
				$("#booking_show_tooltip_"+suffixe).hide();
			}
		}
	} else {
		if ($('#pays_retrait_'+suffixe).attr('disabled') ) {//sao
			return;
		}
		var parent_div = $('#booking_show_tooltip_'+suffixe).closest('.pays-retrait');
		parent_div.tooltip('destroy');
		if($("#booking_show_tooltip_"+suffixe).length > 0) {
			$("#booking_show_tooltip_"+suffixe).hide();
		}
	}
}

function enableTooltip(suffixe, text_to_show) {
	if($("#booking_tooltip_"+suffixe).length > 0) {
		$("#booking_tooltip_"+suffixe).html('');
		$("#booking_tooltip_"+suffixe).append(text_to_show);
	}
	if($("#booking_show_tooltip_"+suffixe).length > 0) {
		$("#booking_show_tooltip_"+suffixe).show();
		if(suffixe == 'tkl') {
			tooltipTicketless();
		} else if(suffixe == 'paper') {
			tooltipPaper();
		} else if(suffixe == 'thepass') {
			tooltipThepass();
		} else {
			tooltipPaysRetrait(suffixe);
		}
	}

}

function tooltipPaysRetrait(suffixe) {
	var parent_div = $('#booking_show_tooltip_'+suffixe).closest('.pays-retrait');
	parent_div.tooltip({
		delay: 0,
		showURL: false,
		bodyHandler: function() {
			var child_div = $(this).find('.booking_tooltip');
			var content_tooltip = child_div.html();
			return $('<div>'+content_tooltip+'</div>');
		}});
}

function tooltipTicketless() {
	$('#mes_billets_eticket').tooltip({
		delay: 0,
		showURL: false,
		bodyHandler: function() {
			var child_div = $('#booking_tooltip_tkl');
			var content_tooltip = child_div.html();
			return $('<div>'+content_tooltip+'</div>');
		}});
}

function tooltipPaper() {
	$('#mes_billets_papier').tooltip({
		delay: 0,
		showURL: false,
		bodyHandler: function() {
			var child_div = $('#booking_tooltip_paper');
			var content_tooltip = child_div.html();
			return $('<div>'+content_tooltip+'</div>');
		}});
}

function tooltipThepass() {
	$('#thepass_1').closest('.form_box_thepass').tooltip({
		delay: 0,
		showURL: false,
		bodyHandler: function() {
			var child_div = $('#booking_tooltip_thepass');
			var content_tooltip = child_div.html();
			return $('<div>'+content_tooltip+'</div>');
		}});
}

//Mes billets

//Les Passagers
function synchronizePassengers() {
	if($("#nombre_passager").length > 0) {
		var passager = $('#nombre_passager').val();
		for(i=1; i <=6 ; i++) {
			if($("#les_passagers_infos_"+i).length > 0) {
				if(i<= passager) {
					$("#les_passagers_infos_"+i).show();
				} else {
					$("#les_passagers_infos_"+i).hide();
				}
			}
		}
	}
}

function changePassengers() {
	if($("#nombre_passager").length > 0) {
		$('#nombre_passager').change( function() {
			synchronizePassengers();
		});
	}
}

function initAbonnements() {
	if($(".form_select_passager_thepass").length > 0) {
		$(".form_select_passager_thepass").hide();
	}
	var checked_thepass = false;
	if($("#thepass_1").length > 0) {
		checked_thepass = $("#thepass_1").attr("checked");

		if($("#abo_thepass_1").length > 0) {
			if(true === checked_thepass) {
				showThePass('1');
			}
		}
	}
	for(i=1; i <=6 ; i++) {
		if($("#lys_"+i).length > 0) {
			if(false === $("#lys_"+i).attr('checked')) {
				if($("#num_lys_"+i).length > 0) {
					var parent_div_num_lys = $("#num_lys_"+i).closest('.form_box');
					//					$("#num_lys_"+i).hide();
					parent_div_num_lys.hide();
				}
			} else {
				var parent_div = $("#lys_"+i).closest('.form_box_lys');
				/*
 				* parent_div.removeClass('form_box_lys');
 				* parent_div.addClass('form_box_lys_checked');
 				*/
				if($("#num_lys_"+i).length > 0) {
					var parent_div_num_lys = $("#num_lys_"+i).closest('.form_box');
					//					$("#num_lys_"+i).show();
					parent_div_num_lys.show();
				}
			}
		}
		if(i > 1) {
			initThePass(i);
			if(true === checked_thepass) {
				disabledLys(i);
				disabledCheckTheCard(i);
				showThePass(i);
			}
		}
	}

	if($("#ttc_1").length > 0) {
		if(true !== $("#ttc_1").attr('checked')) {
			enabledCopyData();
		} else {
			disabledCopyData();
		}
	}
	$.uniform.update('.form_checkbox_thecard');
	$.uniform.update('.form_checkbox_lys');
	$.uniform.update('.form_checkbox_thepass');
}

function initThePass(id) {
	checked_thepass = $("#thepass_1").attr("checked");
	if($("#abo_thepass_"+id).length > 0) {
		$("#abo_thepass_"+id).attr("disabled",true);
		if(true === checked_thepass) {
			//			$("#abo_thepass_"+id).show();
			$('.form_box_select_thepass').show();
		} else {
			$('.form_box_select_thepass').hide();
		}
	}
	if($("#thepass_"+id).length > 0) {
		$("#thepass_"+id).attr("disabled",true);
		$("#thepass_"+id).attr("checked",checked_thepass);
	}
}

function showThePass(id) {
	//	$("#thepass_"+id).addClass('form_box_thepass_checked');
	//	$("#abo_thepass_"+id).closest('.form_box_thepass').addClass('form_box_thepass_checked');
	var parent_div = $("#abo_thepass_"+id).closest('.form_box').closest('.form_box');
	var thepass_box = parent_div.find('.form_select_passager_thepass');
	thepass_box.addClass('form_box_thepass_checked');
	thepass_box.show();
	//	$('.form_box_thepass_checked').removeClass('form_box_thepass');
}

function checkedTheCard() {
	if($(".form_checkbox_thecard").length > 0) {
		$(".form_checkbox_thecard").click( function() {
			var id = this.id.split('_');
			var click_id = id[id.length-1];
			checkThePass('1');
			infosPassagers(click_id);
			if(click_id == 1) {
				if(true !== $(".form_checkbox_thecard").attr('checked')) {
					enabledCopyData();
				} else {
					disabledCopyData();
				}
			}
		});
	}
}

function infosPassagers(click_id) {
	if($('#type_billet').val() != 'eticket') {
		if($('#les_passagers_infos_coordonnees_'+click_id).length > 0) {
			$('#les_passagers_infos_coordonnees_light_'+click_id).hide();
			if(true === $('#ttc_'+click_id).attr("checked")) {
				$('#les_passagers_infos_coordonnees_'+click_id).show();
				$('#les_passagers_infos_coordonnees_ttc_'+click_id).show();
			} else {
				$('#ttp_'+click_id).attr("checked",false);
				$('#les_passagers_infos_coordonnees_'+click_id).hide();
				$('#les_passagers_infos_coordonnees_ttc_'+click_id).hide();
			}
			$.uniform.update('.form_checkbox_thecard');
			$.uniform.update('.form_checkbox_lys');
			$.uniform.update('.form_checkbox_thepass');
		}
	} else {
		if($(".les_passagers_infos_coordonnees").length > 0) {
			$(".les_passagers_infos_coordonnees").show();
			$("#les_passagers_infos_coordonnees_ttc_"+click_id).hide();
			$("#les_passagers_infos_coordonnees_light_"+click_id).hide();
			if($("#ttc_"+click_id).length > 0) {
				if(true === $("#ttc_"+click_id).attr('checked')) {
					if($("#les_passagers_infos_coordonnees_"+click_id).length > 0) {
						$("#les_passagers_infos_coordonnees_"+click_id).show();
						$("#les_passagers_infos_coordonnees_ttc_"+click_id).show();
					} else {
						if($("#les_passagers_infos_coordonnees_"+click_id).length > 0) {
							$("#les_passagers_infos_coordonnees_"+click_id).show();
							$("#les_passagers_infos_coordonnees_light_"+click_id).show();
							showHideCheckbox('sms_placement',click_id,'show');
							showHideCheckbox('newsletter',click_id,'show');
						}
					}
				} else {
					if($("#les_passagers_infos_coordonnees_"+click_id).length > 0) {
						$("#les_passagers_infos_coordonnees_"+click_id).show();
						$("#les_passagers_infos_coordonnees_light_"+click_id).show();
						showHideCheckbox('sms_placement',click_id,'show');
						showHideCheckbox('newsletter',click_id,'show');
						infosPassagersTelephone(click_id);
					}
				}
				$.uniform.update('.form_checkbox_thecard');
				$.uniform.update('.form_checkbox_lys');
				$.uniform.update('.form_checkbox_thepass');
			}
		}
	}
}

function initInfosPassagersTelephone() {
	for(i=1; i <=6 ; i++) {
		infosPassagersTelephone(i);
	}
}

function infosPassagersTelephone(id) {
	if(true !== passagers_telephone_show[id]) {
		showTelephone(id,'mb');
		showTelephone(id,'sms');
	} else {
		if($("#mobile_ticketing_"+id).length > 0 && $("#mobile_ticketing_"+id).length > 0) {
			if(true !== $("#mobile_ticketing_"+id).attr('checked') && true !== $("#sms_placement_"+id).attr('checked')) {
				if(true === passagers_telephone_show[id]) {
					var parent_div_telephone = $("#mobile_ticketing_"+id).closest('.les_passagers_infos_inscriptions');
					var child_div_telephone = parent_div_telephone.find('.div_form_box_telephone');
					child_div_telephone.html('');
					child_div_telephone.remove();
					passagers_telephone_show[id] = false;
				}
			}
		}
	}
	initCopyData();
}

function showTelephone(id,type_telephone) {
	var to_show = (type_telephone == 'sms')? 'sms_placement_' : 'mobile_ticketing_';
	var id_to_show = "#"+to_show+id;
	if($(id_to_show).length > 0) {
		var parent_div_telephone =$(id_to_show).closest('.form_box');
		if(true === $(id_to_show).attr('checked')) {
			if(undefined != passagers_telephone[id]) {
				var html_div_telephone = passagers_telephone[id];
			} else {
				var html_div_telephone = $("#booking_passager_telephone_"+id).html();
				$("#booking_passager_telephone_"+id).html('');
				$("#booking_passager_telephone_"+id).remove();
			}
			if(parent_div_telephone.length > 0) {
				if(true != passagers_telephone_show[id]) {
					$(html_div_telephone).insertAfter(parent_div_telephone);
				}
				passagers_telephone[id] = html_div_telephone;
				passagers_telephone_show[id] = true;
				changeTelephone();
			}
		}
	}
}

function changeTelephone() {
	if($(".form_select_prefixe").length > 0) {
		$('.form_select_prefixe').change( function() {
			$.uniform.update('.form_select_prefixe');
		});
	}
}

function checkedMobileTicketing() {
	if($(".mobile_ticketing_input").length > 0) {
		$(".mobile_ticketing_input").click( function() {
			var id = this.id.split('_');
			var click_id = id[id.length-1];
			infosPassagersTelephone(click_id);
		});
	}
}

function checkedSmsPlacement() {
	if($(".sms_placement").length > 0) {
		$(".sms_placement").click( function() {
			var id = this.id.split('_');
			var click_id = id[id.length-1];
			infosPassagersTelephone(click_id);
		});
	}
}

function showHideCheckbox(id,click_id,showhide) {
	var parent_div = $('#'+id+'_'+click_id).closest('.form_checkbox_box');
	if(showhide != 'hide') {
		parent_div.show();
	} else {
		parent_div.hide();
	}

}

function checkedLys() {
	if($(".form_checkbox_lys").length > 0) {
		$(".form_checkbox_lys").click( function() {
			var id = this.id.split('_');
			var click_id = id[id.length-1];
			var parent_div_num_lys = $("#num_lys_"+click_id).closest('.form_box');
			if(true === $(this).attr("checked")) {
				parent_div_num_lys.find('.form_text_num_lys').show();
				parent_div_num_lys.show();
				if($(".form_checkbox_thepass").length > 0) {
					$(".form_checkbox_thepass").attr("checked",false);
				}
				if($(".form_box_select_thepass").length > 0) {
					$(".form_box_select_thepass").hide();
				}
				if($(".form_checkbox_thecard").length > 0 && TICKETLESS_ACCES == true) {
					$(".form_checkbox_thecard").attr("disabled",false);
				}

				var checked_pays_retrait_nl = false;

				if($("#pays_retrait_nl").length > 0) {
					checked_pays_retrait_nl = $("#pays_retrait_nl").attr("checked");
					//		alert(checked_thepass);
				}

				if($(".form_checkbox_lys").length > 0) {
					if(false === checked_pays_retrait_nl) {
						$(".form_checkbox_lys").attr("disabled",false);
					}
				}
				// parent_div_num_lys.find('.form_text_num_lys').removeClass('error');
				// parent_div.addClass('form_box_lys_checked');
				parent_div_num_lys.find('.error').show();
				if($(".form_box_thepass_checked").length > 0) {
					$(".form_box_thepass_checked").addClass('form_box_thepass');
					$(".form_box_thepass").removeClass('form_box_thepass_checked');
				}
			} else {
				parent_div_num_lys.hide();
				var parent_div = $(this).closest('.form_box_lys');
				parent_div.find('.form_text_num_lys').hide();
				parent_div.find('.error').hide();
				/*
 				* parent_div.removeClass('form_box_lys_checked');
 				* parent_div.addClass('form_box_lys');
 				*/
			}
			$.uniform.update('.form_checkbox_thecard');
			$.uniform.update('.form_checkbox_lys');
			$.uniform.update('.form_checkbox_thepass');
		});
	}
}

function disabledCheckTheCard(id) {
	if($("#ttc_"+id).length > 0) {
		$("#ttc_"+id).attr("checked",true);
		$("#ttc_"+id).attr("disabled",true);
		infosPassagers(id);
	}
}

function disabledLys(id) {
	if($("#lys_"+id).length > 0) {
		$("#lys_"+id).attr("disabled",true);
		$("#lys_"+id).attr("checked",false);
		$("#num_lys_"+id).closest('.form_box').hide();
		$.uniform.update('.form_checkbox_thecard');
		$.uniform.update('.form_checkbox_lys');
		$.uniform.update('.form_checkbox_thepass');
	}
}

function disabledLysAll() {
	if($(".form_checkbox_lys").length > 0) {
		$(".form_checkbox_lys").attr("disabled",true);
		$(".form_checkbox_lys").attr("checked",false);
		$(".form_text_num_lys").closest('.form_box').hide();
		$.uniform.update('.form_checkbox_thecard');
		$.uniform.update('.form_checkbox_lys');
		$.uniform.update('.form_checkbox_thepass');
	}
}

function enabledLys() {
	var checked_thepass = false;
	if($("#thepass_1").length > 0) {
		checked_thepass = $("#thepass_1").attr("checked");
		//		alert(checked_thepass);
	}
	if($(".form_checkbox_lys").length > 0) {
		if(false === checked_thepass) {
			$(".form_checkbox_lys").attr("disabled",false);
			$.uniform.update('.form_checkbox_thecard');
			$.uniform.update('.form_checkbox_lys');
			$.uniform.update('.form_checkbox_thepass');
		}
	}
}

function focusLys() {
	if($(".form_text_num_lys").length > 0) {
		$(".form_text_num_lys").focus( function() {
			if($(this).val() == label_numero_lys) {
				$(this).val('');
			}
		});
	}
}

function blurLys() {
	if($(".form_text_num_lys").length > 0) {
		$(".form_text_num_lys").blur( function() {
			if($(this).val() == '') {
				$(this).val(label_numero_lys);
			}
		});
	}
}

function checkedThePass() {
	if($(".form_checkbox_thepass").length > 0) {
		$(".form_checkbox_thepass").click( function() {
			checkThePass(this.id);
		});
	}
}

function checkThePass(id_thepass) {
	if(true === $('#'+id_thepass).attr("checked")) {
		if($(".form_box_select_thepass").length > 0) {
			$(".form_box_select_thepass").show();
		}
		if($(".form_select_thepass").length > 0) {
			$(".form_select_thepass").show();
		}
		if($(".form_checkbox_thepass").length > 0) {
			$(".form_checkbox_thepass").attr("checked",true);
		}
		if($(".form_checkbox_lys").length > 0) {
			$(".form_checkbox_lys").attr("checked",false);
		}
		/*
 		* if($(".form_text_num_lys").length > 0){
 		* $(".form_text_num_lys").hide(); }
 		*/
		for(i=1; i <=6 ; i++) {
			if(i > 1) {
				if($("#lys_"+i).length > 0) {
					$("#lys_"+i).attr("disabled",true);
				}
				disabledCheckTheCard(i);
			}
			var parent_div_num_lys = $("#num_lys_"+i).closest('.form_box');
			parent_div_num_lys.hide();
			var parent_div = $("#num_lys_"+i).closest('.form_box');
			parent_div.find('.error').hide();
			$('#ttc_'+i).attr("checked",true);
			infosPassagers(i);
		}
	} else {
		if($(".form_box_select_thepass").length > 0) {
			$(".form_box_select_thepass").hide();
		}

		if($(".form_checkbox_thepass").length > 0) {
			$(".form_checkbox_thepass").attr("checked",false);
		}

		if($(".form_box_thepass_checked").length > 0) {
			$(".form_box_thepass_checked").addClass('form_box_thepass');
			$(".form_box_thepass").removeClass('form_box_thepass_checked');
		}

		if($(".form_checkbox_thecard").length > 0) {
			$(".form_checkbox_thecard").attr("disabled",false);
		}

		var checked_pays_retrait_nl = false;

		if($("#pays_retrait_nl").length > 0) {
			checked_pays_retrait_nl = $("#pays_retrait_nl").attr("checked");
			//		alert(checked_thepass);
		}

		if($(".form_checkbox_lys").length > 0) {
			if(false === checked_pays_retrait_nl) {
				$(".form_checkbox_lys").attr("disabled",false);
			}
		}
		$.uniform.update(".form_checkbox_thepass");
		$.uniform.update(".form_checkbox_thecard");
		$.uniform.update(".form_checkbox_lys");
	}
}

function changeAbonnementThepass() {
	if($(".form_select_thepass").length > 0) {
		$('.form_select_thepass').change( function() {
			var thepass = $(this).val();
			$(".form_select_thepass").val(thepass);
			$.uniform.update(".form_select_thepass");
		});
	}
}

function disabledMobileTicketing(i) {
	var id_div = $("#mobile_ticketing_"+i).closest('.mobile_ticketing');
	var id_sms_placement = $("#sms_placement_"+i).closest('.form_box');
	var id_input = $("#mobile_ticketing_"+i);
	if(id_div.length > 0) {
		id_div.hide();
		id_sms_placement.hide();
		if(id_input.length > 0) {
			id_input.attr('disabled',true);
		}
	}
	$.uniform.update("#mobile_ticketing_"+i);
}

function enabledMobileTicketing(i) {
	var id_div = $("#mobile_ticketing_"+i).closest('.mobile_ticketing');
	var id_sms_placement = $("#sms_placement_"+i).closest('.form_box');
	var id_input = $("#mobile_ticketing_"+i);
	if(id_div.length > 0) {
		id_div.show();
		id_sms_placement.show();
		if(id_input.length > 0) {
			id_input.attr('disabled',false);
		}
	}
	$.uniform.update("#mobile_ticketing_"+i);
}

function synchronizeTypePassagerFirst() {
	if($("#type_passager_1").length > 0) {
		$('#type_passager_1').change( function() {
			synchronizeTypePassagerOther();
			synchronizeTooltipKid(1);
		});
	}
}

function initTypePassagers() {
	for(i=2; i <=6 ; i++) {
		if($("#type_passager_"+i).length > 0) {
			$('#type_passager_'+i).change( function() {
				var id = this.id.split('_');
				var click_id = id[id.length-1];
				synchronizeTooltipKid(click_id);
			});
		}
	}
	synchronizeTypePassagerOther();
}

function synchronizeTypePassagerOther() {
	var pays_checked = false;
	if($("#type_billet").val() == 'paper') {
		for(k = 0; k < COUNTRIES_THALYS.length; k++ ) {
			pays_to_test = COUNTRIES_THALYS[k];
			if($("#pays_retrait_"+pays_to_test).length > 0 && true === $("#pays_retrait_"+pays_to_test).attr('checked')) {
				pays_checked = pays_to_test;
				break;
			}
		}
	} else {
		pays_checked = COUNTRY;
	}
	var allow_other = [];
	allow_other['adulte'] 	= ['adulte', 'enfant', 'jeune', 'senior'];
	allow_other['jeune'] 	= ['adulte', 'enfant', 'jeune', 'senior'];
	allow_other['senior'] 	= ['adulte', 'enfant', 'jeune', 'senior'];
	switch(pays_checked) {
		case 'nl':
		case 'be':
			allow_other['adulte'] 	= ['adulte', 'enfant'];
			allow_other['jeune'] 	= ['jeune', 'enfant'];
			allow_other['senior'] 	= ['senior', 'enfant'];
			break;
	}
	if($("#type_passager_1").length > 0) {
		var type_passager_first = $("#type_passager_1").val();
		for(i=2; i <=6 ; i++) {
			var type_passager = $("#type_passager_"+i).val();
			if($("#type_passager_"+i+" > option").length > 0) {
				$("#type_passager_"+i+" > option").remove();
			}
			for( var j = 0; j < allow_other[type_passager_first].length; j++ ) {
				if($.inArray(allow_other[type_passager_first][j], types_passagers) >= 0) {
					var option_text = label_type_passger[allow_other[type_passager_first][j]];
					var option_id = 'type_pass_'+i+'_'+allow_other[type_passager_first][j];
					$("#type_passager_"+i).
					append($("<option></option>").
					attr("value",allow_other[type_passager_first][j]).
					attr("id",option_id).
					text(option_text));
				}
			}
			$("#type_passager_"+i).val(type_passager);
		}
	}
	$.uniform.update('.form_select_passager_type');
}

function synchronizeTooltipKidAll() {
	for(i=1; i <=6 ; i++) {
		synchronizeTooltipKid(i);
	}
}

function synchronizeTooltipKid(id) {
	if($("#type_passager_"+id).length > 0) {
		if($("#type_passager_"+id).val() == 'enfant') {
			$("#booking_show_tooltip_passager_"+id).show();
		} else {
			$("#booking_show_tooltip_passager_"+id).hide();
		}
	}
}

function initCopyData() {
	if($(".idem_passager").length > 0) {
		if($("#ttc_1").length > 0) {
			if(true !== $("#ttc_1").attr('checked')) {
				$(".idem_passager").closest('.form_box').addClass('form_box_idem');
			}
		}
		$('.idem_passager').click( function() {
			id = ($(this).attr('id'));
			if (id.indexOf('idem_numero_telephone') >= 0) {
				if($('#prefixe_numero_telephone_1').val() == '' || $('#numero_telephone_1').val() == '') {
					$(this).attr('checked',false);
				}
			} else {
				if($('#contact_passager_1').val() == '' || $('#confirm_contact_passager_1').val() == '') {
					$(this).attr('checked',false);
				}
			}
			$.uniform.update('.idem_passager');
			synchronizeCopyData(this.id);
		});
	}
}

function initCopyDataCheck() {
	if($(".idem_passager").length > 0) {
		$('.idem_passager').each( function(index) {
			var reg_hidden=new RegExp("(show_)", "g");
			var val_id_hidden =  $(this).attr('name').replace(reg_hidden,'');
			if($('#'+val_id_hidden).val() == '1') {
				$(this).attr('checked',true);
			} else {
				$(this).attr('checked',false);
			}
			synchronizeCopyData(this.id);
		});
		$.uniform.update('.idem_passager');
	}
}

function enabledCopyData() {
	if($(".idem").length > 0) {
		$(".idem").show();
		$('.idem').each( function(index) {
			$(this).closest('.form_box').addClass('form_box_idem');
		});
	}
}

function disabledCopyData() {
	if($(".idem").length > 0) {
		$('.idem').each( function(index) {
			$('.idem').closest('.form_box').removeClass('form_box_idem');
			var val_id = $(this).find('.idem_passager').attr('id');
			$('#'+val_id).attr('checked', false);
			$.uniform.update('.idem_passager');
			synchronizeCopyData(val_id);
		});
		$(".idem").hide();
	}
}

function synchronizeCopyData(val_id) {
	var id = val_id.split('_');
	var click_id = id[id.length-1];
	var reg=new RegExp("(idem_)", "g");
	var data = val_id.replace(reg,'');
	var to_update = [];
	var regexp_email = new RegExp('contact_passager_[2-6]', "g");
	if (data.match(regexp_email)) {
		to_update.push(data);
		to_update.push('confirm_'+data);
	}
	var regexp_tel = new RegExp('numero_telephone_[2-6]', "g");
	if (data.match(regexp_tel)) {
		to_update.push(data);
		to_update.push('prefixe_'+data);
	}
	var reg_hidden=new RegExp("(show_)", "g");
	var val_id_hidden =  $('#'+val_id).attr('name').replace(reg_hidden,'');

	for(i=0; i < to_update.length; i++) {
		if(true === $('#'+val_id).attr('checked')) {
			if($('#'+to_update[i]).length > 0) {
				$('#'+to_update[i]).attr('disabled',true);
				$('#'+val_id_hidden).val('1');
				if (to_update[i].match(regexp_email)) {
					$('#newsletter_'+click_id).closest('.form_checkbox_box').hide();
					$('#contact_passager_'+click_id).addClass('idem_hidden');
					$('#contact_passager_'+click_id).val(label_idem_email_1er_passager);
					$('#confirm_contact_passager_'+click_id).val(label_idem_email_1er_passager);
				}
			}
		} else {
			if($('#'+to_update[i]).length > 0) {
				$('#'+to_update[i]).attr('disabled',false);
				$('#'+val_id_hidden).val('');
				if (to_update[i].match(regexp_email)) {
					$('#newsletter_'+click_id).closest('.form_checkbox_box').show();
					if($('#contact_passager_'+click_id).val() == label_idem_email_1er_passager) {
						$('#contact_passager_'+click_id).val('');
						$('#confirm_contact_passager_'+click_id).val('');
					}
				}
			}
		}

		if (to_update[i].match(regexp_email)) {
			if($('#idem_contact_passager_'+click_id).closest('.idem').css('display') == 'none') {
				$('#contact_passager_'+click_id).addClass('idem_hidden');
			} else {
				$('#contact_passager_'+click_id).removeClass('idem_hidden');
			}
		}
	}
	if ($('#div_tkl_mobile_ticketing_1').is(':visible')) {
		if ($('#'+val_id).attr('checked')) {
			disabledMobileTicketing(click_id);
			$('#div_tkl_mobile_ticketing_'+click_id).show();
		} else {
			enabledMobileTicketing(click_id);
			$('#div_tkl_mobile_ticketing_'+click_id).hide();
		}
	}
}

function initMembreTheCard() {
	if(isBookingTheCard()) {
		$("#ttc_1").unbind('click');
		$("#num_thalys_oublie_1").closest('p').hide();
		$("#num_tha_1").attr('readonly', true);
		$("#nom_passager_tha_1").attr('readonly', true);
	}
	membreTheCardBlur();
	membreTheCardCinBlur();
	for(i=1; i <=6 ; i++) {
		if($("#ttc_"+i).length > 0) {
			id_membre = "ttc_"+i;
			if(true === $('#'+id_membre).attr('checked')) {
				membreTheCardCinCallAjax(id_membre);
				mobileTicketing('',i,'tkl');
			} else {
				membreTheCardCallAjax(id_membre);
				mobileTicketing('',i,'ttc');
			}
		}

	}
}

function membreTheCardBlur() {
	membreTheCardNomBlur();
	membreTheCardPrenomBlur();
	membreTheCardContactBlur();
	membreTheCardContactConfirmBlur();
}

function membreTheCardNomBlur() {
	if($('.booking_nom').length > 0) {
		$('.booking_nom').blur( function() {
			membreTheCardCallAjax(this.id);
		});
	}
}

function membreTheCardPrenomBlur() {
	if($('.booking_prenom').length > 0) {
		$('.booking_prenom').blur( function() {
			membreTheCardCallAjax(this.id);
		});
	}
}

function membreTheCardContactBlur() {
	if($('.booking_contact').length > 0) {
		$('.booking_contact').blur( function() {
			var id = this.id.split('_');
			var blur_id = id[id.length-1];
			membreTheCardCallAjax(this.id);
			if($(this).val() == '' && blur_id == 1) {
				disabledIdem();
			}
		});
	}
}

function membreTheCardContactConfirmBlur() {
	if($('.booking_confirm_contact').length > 0) {
		$('.booking_confirm_contact').blur( function() {
			var id = this.id.split('_');
			var blur_id = id[id.length-1];
			if($(this).val() == '' && blur_id == 1) {
				disabledIdem();
			}
		});
	}
}

function membreTheCardCallAjax(id_membre) {
	var id = id_membre.split('_');
	var blur_id = id[id.length-1];
	var nom = $('#nom_passager_'+blur_id).val();
	var prenom = $('#prenom_passager_'+blur_id).val();
	var contact = $('#contact_passager_'+blur_id).val();
	if(nom != '' && prenom != '' && contact != '') {
		membreTheCardAjax(nom,prenom,contact,blur_id);
	} else {
		mobileTicketing('',blur_id,'tkl');
	}
}

function membreTheCardAjax(nom,prenom,contact,blur_id) {
	var id = cleanName(nom)+cleanName(prenom)+cleanEmail(contact);
	if(true === (id in membres_thecard)) {
		mobileTicketing(membres_thecard[id],blur_id,'tkl');
	} else {
		ajaxDate = new Date();
		$.ajax({
			type: "GET",
			url: domain_name+'?ajax=Booking_Thecard',
			data: "nom="+nom+"&prenom="+prenom+"&contact="+contact+"&lg="+LANGUAGE+"&ct="+COUNTRY+'&ts='+ajaxDate.getTime(),
			success: function(msg) {
				msg = $.trim(msg);
				membres_thecard[id] = msg;
				mobileTicketing(msg,blur_id,'tkl');
			}
		});
	}
}

function membreTheCardCinBlur() {
	membreTheCardCinNomBlur();
	membreTheCardCinNumThalysBlur();
}

function membreTheCardCinNomBlur() {
	if($('.booking_num_tha_nom').length > 0) {
		$('.booking_num_tha_nom').blur( function() {
			membreTheCardCinCallAjax(this.id);
		});
	}
}

function membreTheCardCinNumThalysBlur() {
	if($('.form_text_num_thalys').length > 0) {
		$('.form_text_num_thalys').blur( function() {
			membreTheCardCinCallAjax(this.id);
		});
	}
}

function membreTheCardCinCallAjax(id_membre) {
	var id = id_membre.split('_');
	var blur_id = id[id.length-1];
	var nom = $('#nom_passager_tha_'+blur_id).val();
	var cin = $('#num_tha_'+blur_id).val();
	if(nom != '' && cin != '') {
		membreTheCardCinAjax(nom,cin,blur_id);
	} else {
		mobileTicketing('',blur_id,'ttc');
	}
	masquerParagrapheMobileTicket();

}

function membreTheCardCinAjax(nom,cin,blur_id) {
	var id = cin;
	if(true === (id in membres_thecard)) {
		mobileTicketing(membres_thecard[id],blur_id,'ttc');
		masquerParagrapheMobileTicket();
	} else {
		ajaxDate = new Date();
		$.ajax({
			type: "GET",
			url: domain_name+'?ajax=Booking_Numerothalys',
			data: "cin="+cin+"&nom="+nom+"&lg="+LANGUAGE+"&ct="+COUNTRY+'&ts='+ajaxDate.getTime(),
			success: function(msg) {
				membres_thecard[id] = $.trim(msg);
				mobileTicketing(msg,blur_id,'ttc');
				masquerParagrapheMobileTicket();
			}
		});
	}
}

function masquerParagrapheMobileTicket() {
	// sao
	if(true === $("#mes_billets_papier_onglet").hasClass('active')) {
		if($('.div_mobile_ticketing').length > 0) {
			$('.div_mobile_ticketing').hide();
		}
	}
	// sao
}

function initMobileTicketing() {
	checkedMobileTicketing();
	for(var i=1 ; i <= 6; i++) {
		var id_membre = 'id_'+i;
		if($('#ttc_'+i).length > 0) {
			if(true !== $('#ttc_'+i).attr('checked')) {
				membreTheCardCallAjax(id_membre);
			} else {
				membreTheCardCinCallAjax(id_membre);
			}
		}
	}
}

function mobileTicketing(str,blur_id,type_membre) {
	if(type_membre == 'tkl') {
		if(str == THECARD || str == TKL) {
			disabledMobileTicketing(blur_id);
		} else {
			enabledMobileTicketing(blur_id);
		}
	}
	modifyMobileTicketing(str, blur_id,type_membre);
}

function modifyMobileTicketing(str, blur_id,type_membre) {
	if(type_membre == 'ttc') {
		var id = '#div_ttc_mobile_ticketing_'+blur_id;
		var id_tkl = '#div_ttc_mobile_ticketing_ticketless_'+blur_id;
		if(str == TKL) {
			if($(id_tkl).length > 0) {
				$(id_tkl).show();
				$(id).hide();
			}
		} else {
			if($(id).length > 0) {
				$(id).show();
				$(id_tkl).hide();
			}
		}
	} else {
		var id = '#div_tkl_mobile_ticketing_'+blur_id;
		var id_tkl = '#div_tkl_mobile_ticketing_ticketless_'+blur_id;

		if(str == TKL) {
			if($(id_tkl).length > 0) {
				$(id_tkl).show();
				$(id).hide();
			}
		} else if(str == THECARD) {
			if($(id).length > 0) {
				$(id).show();
				$(id_tkl).hide();
			}
		} else {
			if($(id).length > 0) {
				$(id).hide();
				$(id_tkl).hide();
			}
		}
	}
	$.uniform.update('.mobile_ticketing_input');
}

function numeroThalysOublie() {
	ajaxDate = new Date();
	$.ajax({
		type: "GET",
		url: domain_name+'?ajax=Booking_Numerothalysoublie',
		data: "email="+$("#numero_thalys_oublie_email").val()+"&pwd="+$("#numero_thalys_oublie_pwd").val()+'&lg='+LANGUAGE+'&country='+COUNTRY+'&ts='+ajaxDate.getTime(),
		success: function(msg) {
			var obj = jQuery.parseJSON(msg);
			if (obj.valide == 'valide') {// affiche bloc suivant
				var id_cin = '#num_tha_'+ID_PASSAGER_OUBLIE;
				var id_nom = '#nom_passager_tha_'+ID_PASSAGER_OUBLIE;
				$(id_cin).val(obj.cin);
				$(id_nom).val(obj.nom);
				membreTheCardCinCallAjax(ID_PASSAGER_OUBLIE);
				popin_numero_thalys_oublie.hide();
			} else {
				$('#numero_thalys_oublie_email').removeClass('error');
				$('#numero_thalys_oublie_pwd').removeClass('error');
				$('.popin_content span.error').remove();
				if(obj.reponse != true) {
					$('#numero_thalys_oublie_email').addClass('error');
					$('#numero_thalys_oublie_pwd').addClass('error');
					$('#numero_thalys_oublie_email').closest('.form_box').before(obj.reponse);
				}
				if(obj.email_reponse != true) {
					$('#numero_thalys_oublie_email').addClass('error');
					$('#numero_thalys_oublie_email').before(obj.email_reponse);
				}
				if(obj.pwd_reponse != true) {
					$('#numero_thalys_oublie_pwd').addClass('error');
					$('#numero_thalys_oublie_pwd').before(obj.pwd_reponse);
				}
			}
		}
	});
}

function clickNumeroThalysOublie() {
	if($(".lien_num_thalys_oublie").length > 0) {
		$(".lien_num_thalys_oublie").click( function() {
			var id = this.id.split('_');
			var click_id = id[id.length-1];
			ID_PASSAGER_OUBLIE = click_id;
			ajaxDate = new Date();
			$.ajax({
				type: "GET",
				url: domain_name+'?ajax=Booking_Numerothalysoublieblock',
				data: 'lg='+LANGUAGE+'&ct='+COUNTRY+'&content=pwd&ts='+ajaxDate.getTime(),
				success: function(msg) {
					$('#forgot_informations').html(msg);
					$('.popin_content').html(null);
					popin_numero_thalys_oublie = $('#forgot_informations');
					popin_numero_thalys_oublie.popin({id_content:'#forgot_informations'});
					popin_numero_thalys_oublie.show();
				}
			});
		});
	}
}

function motDePasseOublie() {
	ajaxDate = new Date();
	$.ajax({
		type: "GET",
		url: domain_name+'?ajax=Booking_Motdepasseoublie',
		data: "nom="+$("#pwd_forgot_nom").val()+"&prenom="+$("#pwd_forgot_prenom").val()+"&email="+$("#pwd_forgot_email").val()+'&lg='+LANGUAGE+'&country='+COUNTRY+'&ts='+ajaxDate.getTime(),
		success: function(msg) {
			var obj = jQuery.parseJSON(msg);
			if (obj.valide == 'valide') {// affiche bloc suivant
				var id_cin = '#num_tha_'+ID_PASSAGER_OUBLIE;
				var id_nom = '#nom_passager_tha_'+ID_PASSAGER_OUBLIE;
				$(id_cin).val(obj.cin);
				$(id_nom).val(obj.nom);
				membreTheCardCinCallAjax(ID_PASSAGER_OUBLIE);
				popin_numero_thalys_oublie.hide();
			} else {
				$('#pwd_forgot_nom').removeClass('error');
				$('#pwd_forgot_prenom').removeClass('error');
				$('#pwd_forgot_email').removeClass('error');
				$('.popin_content span.error').remove();
				if(obj.reponse != true) {
					$('#pwd_forgot_nom').addClass('error');
					$('#pwd_forgot_prenom').addClass('error');
					$('#pwd_forgot_email').addClass('error');
					$('#pwd_forgot_nom').closest('.form_box').before(obj.reponse);
				}
				if(obj.nom_reponse != true) {
					$('#pwd_forgot_nom').addClass('error');
					$('#pwd_forgot_nom').before(obj.nom_reponse);
				}
				if(obj.prenom_reponse != true) {
					$('#pwd_forgot_prenom').addClass('error');
					$('#pwd_forgot_prenom').before(obj.prenom_reponse);
				}
				if(obj.email_reponse != true) {
					$('#pwd_forgot_email').addClass('error');
					$('#pwd_forgot_email').before(obj.email_reponse);
				}
			}
		}
	});
}

function disabledIdem() {
	if($(".idem").length > 0) {
		$(".idem").show();
		$('.idem').each( function(index) {
			var val_id = $(this).find('.idem_passager').attr('id');
			var id = val_id.split('_');
			var click_id = id[id.length-1];
			var reg=new RegExp("(idem_)", "g");
			var data = val_id.replace(reg,'');
			var regexp_email = new RegExp('contact_passager_[2-6]', "g");
			if (data.match(regexp_email)) {
				var reg_hidden=new RegExp("(show_)", "g");
				var val_id_hidden =  $('#'+val_id).attr('name').replace(reg_hidden,'');
				$('#idem_contact_passager_'+click_id).attr('checked',false);
				$('#contact_passager_'+click_id).val('');
				$('#confirm_contact_passager_'+click_id).val('');
				$('#contact_passager_'+click_id).attr('disabled',false);
				$('#confirm_contact_passager_'+click_id).attr('disabled',false);
				$('#'+val_id_hidden).val('');
				$.uniform.update('#idem_contact_passager_'+click_id);
			}
		});
	}
}
function checkBlock02042012() {
	date_aller = $("#date_aller").val(); 
	date_retour = $("#date_retour").val();

	date_aller_str = parseDate($("#date_aller").val());
	date_retour_str = parseDate($("#date_retour").val());
	
	if (((date_aller_str.getDate() == "31")&&(date_aller_str.getMonth() == "00")&&(date_aller_str.getFullYear() == "2012"))) {
		affichePopInBloquage();
	}
	if (((date_retour_str.getDate() == "31")&&(date_retour_str.getMonth() == "00")&&(date_retour_str.getFullYear() == "2012"))) {
		affichePopInBloquage();
	}
	function affichePopInBloquage(){	
		$('.popin_content').html(null);
		$('#message_02042012_copy').html($('#message_02042012').html());
		popin_02042012 = $('#message_02042012_copy');
		popin_02042012.popin({id_content:'#message_02042012_copy'});
		popin_02042012.show();
	}
} 

// Les Passagers

//Tableaux pour la flash neige
var tab_1 = Array(new Date(2012, 0, 07).getTime(),new Date(2012, 0, 14).getTime(),new Date(2012, 0, 21).getTime(),new Date(2012, 0, 28).getTime()
,new Date(2012, 01, 11).getTime(),new Date(2012, 2, 3).getTime(),new Date(2012, 2, 17).getTime(),new Date(2012, 2, 24).getTime()
,new Date(2012, 3, 7).getTime());
var tab_1_cf = Array('12','2','2','2','12','12','2','12','12');

var tab_2 = Array(new Date(2011, 11, 24).getTime(),new Date(2012, 0, 07).getTime(),new Date(2012, 0, 14).getTime(),new Date(2012, 0, 21).getTime(),new Date(2012, 0, 28).getTime()
,new Date(2012, 01, 11).getTime(),new Date(2012, 2, 3).getTime(),new Date(2012, 2, 10).getTime(),new Date(2012, 2, 17).getTime(),new Date(2012, 2, 24).getTime());
var tab_2_cf = Array('12','12','12','2','12','12','12','2','12','12');

var tab_3 = Array(new Date(2011, 11, 24).getTime(),new Date(2012, 0, 14).getTime(),new Date(2012, 0, 21).getTime(),new Date(2012, 0, 28).getTime()
,new Date(2012, 01, 4).getTime(),new Date(2012, 1, 18).getTime(),new Date(2012, 2, 10).getTime(),new Date(2012, 2, 24).getTime(),new Date(2012, 2, 31).getTime()
,new Date(2012, 3, 14).getTime());
var tab_3_cf = Array('12','12','12','2','2','12','12','2','12','12');

var tab_4 = Array(new Date(2011, 11, 31).getTime(),new Date(2012, 0, 14).getTime(),new Date(2012, 0, 21).getTime(),new Date(2012, 1, 4).getTime()
,new Date(2012, 01, 18).getTime(),new Date(2012, 2, 10).getTime(),new Date(2012, 2, 24).getTime(),new Date(2012, 2, 31).getTime());
var tab_4_cf = Array('12','12','12','12','12','12','12','12');

var tab_5 = Array(new Date(2012, 0, 7).getTime(),new Date(2012, 0, 14).getTime(),new Date(2012, 0, 21).getTime(),new Date(2012, 1, 28).getTime()
,new Date(2012, 01, 11).getTime(),new Date(2012, 2, 3).getTime(),new Date(2012, 2, 10).getTime(),new Date(2012, 2, 17).getTime(),new Date(2012, 2, 24).getTime());
var tab_5_cf = Array('12','12','2','12','12','12','2','12','12');

var tab_6 = Array(new Date(2012, 0, 14).getTime(),new Date(2012, 0, 21).getTime(),new Date(2012, 1, 04).getTime()
,new Date(2012, 01, 18).getTime(),new Date(2012, 2, 10).getTime(),new Date(2012, 2, 24).getTime(),new Date(2012, 2, 31).getTime());
var tab_6_cf = Array('12','12','12','12','12','12','12');
