fDomOffset = function( oObj, sProp )
{ 
	// oObj : [Object] - Objet dont on désire le positionnement 
	// sProp : [String] - Propriété désirée : offsetLeft - offsetTop 
	var iVal = 0; 
	// On boucle tant que l'on n'est pas à la racine du document 
	while (oObj && oObj.tagName != 'BODY') { 
		eval('iVal += oObj.' + sProp + ';');
		oObj = oObj.offsetParent; 
	} 
	return iVal; 
} 

jQuery.fn.extend({
    findPos : function() {
		obj = $(this).get(0);
        var curleft = obj.offsetLeft || 0;
        var curtop = obj.offsetTop || 0;
        while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
            curtop += obj.offsetTop
        }
        return {x:curleft,y:curtop};
	}
});

deplie=false;

$(document).ready(
	function()
	{	
	
		
		if (verif_check_vol()==0) {
		
			$('input[@name^=assurance_checkbox_annulation]').each(
				function() {
					if ($(this)) { 
						$(this).attr('checked', 'true');
					}
				}
			);
			$('input[@name^=assurance_checkbox_multirisque]').each(
				function() {
					//if ($(this)) { 
						$(this).attr('checked','');
					//}
				}
			);
		}else {
			$('input[@name^=assurance_checkbox_annulation]').each(
				function() {
					if ($(this)) { 
						$(this).attr('checked', '');
					}
				}
			);
			$('input[@name^=assurance_checkbox_multirisque]').each(
				function() {
					//if ($(this)) { 
						$(this).attr('checked','true');
					//}
				}
			);
		}
		
		$("#destinations").removeAttr('disabled');
		$("#destinations").css('background', '#ffffff');
		
		$("#inp_hebergement").removeAttr('disabled');
		$("#inp_hebergement").css('background', '#ffffff');
		
		// Onglets du menu de recherche
		$("#menu_moteur_recherche a").hover(function(){
			texteor=$('#menu_fond_texte').html();
			var texte=eval('traduc_'+this.id);
			$('#menu_fond_texte').html(texte);
		},function(){
			$('#menu_fond_texte').html(texteor);
		});
		
		$("#menu_moteur_recherche a").click(function(){
			$("#menu_moteur_recherche a").removeClass('currentlink');
			jQuery(this).addClass('currentlink');
			var texte=eval('traduc_'+this.id);
			$('#menu_fond_texte').html(texte);
			texteor=$('#menu_fond_texte').html();
		});
		
		$("#top1_aero").click(function(){
			$("#top_aero").css('display', 'block');
			$("#autre_aero").css('display', 'none');
			$("#aut_aero").addClass('airport2');
			$("#top1_aero").removeClass('airport2');
			//$("#ListAirport").css('background', 'url(../../../medias/images/okipi/structure/moteur_recherche/vol.png) no-repeat;');
			$("#ListAirport").css('background-position', '0px 0px');
		});
		
		$("#aut_aero").click(function(){
			$("#top_aero").css('display', 'none');
			$("#autre_aero").css('display', 'block');
			$("#top1_aero").addClass('airport2');
			$("#aut_aero").removeClass('airport2');
			//$("#ListAirport").css('background', 'url(../../../medias/images/okipi/structure/moteur_recherche/vol1.png) no-repeat;');
			$("#ListAirport").css('background-position', '0px -400px');
		});
		
		$("#top1_aero1").click(function(){
			$("#top_aero1").css('display', 'block');
			$("#autre_aero1").css('display', 'none');
			$("#aut_aero1").addClass('airport2');
			$("#top1_aero1").removeClass('airport2');
			//$("#ListAirport1").css('background', 'url(../../../medias/images/okipi/structure/moteur_recherche/vol.png) no-repeat;');
			$("#ListAirport1").css('background-position', '0px 0px');
		});
		
		$("#aut_aero1").click(function(){
			$("#top1_aero1").addClass('airport2');
			$("#aut_aero1").removeClass('airport2');
			$("#top_aero1").css('display', 'none');
			$("#autre_aero1").css('display', 'block');
			//$("#ListAirport1").css('background', 'url(../../../medias/images/okipi/structure/moteur_recherche/vol1.png) no-repeat;');
			$("#ListAirport1").css('background-position', '0px -400px');
		});
		
		// survol des evenements speciaux
		$("div.event_spe_txt").hover(function(){
			jQuery(this).css('background-color', '#E7EDEC');
		},function(){
			jQuery(this).css('background-color', '');
		});
		
		// survol des evenements speciaux
		$("div.panier_titre4").hover(function(){
			jQuery(this).css('background-color', '#0F73B6');
			jQuery(this).css('color', '#ffffff');
		},function(){
			jQuery(this).css('background-color', '#E3EBED');
			jQuery(this).css('color', '#3DA2DA');
		});

		//**************************************************************************************************/
		// Destinations autocomplete
		$("#destinations").autocomplete("../../../librairie/js/moteur_recherche_v3/ajax/autocomplete_destinations.php", {		
			extraParams: {code_pays2:function (){return $("#code_pays").val()},langue:function (){return $("#langue").val()}},
			width: 200,
			max:20,
			/*autoFill:true,*/
			minChars:3,
			scroll:true,
			scrollHeight:400,
			selectFirst: false,
			formatItem: function(data, value) {
				switch(data[0]){
					case "station":
						//stations
						return data[1];
					break;
					case "situ":
						//situations
						return data[1];
					break;
					case "titre":
						//titre
						return '<b>'+data[1]+'</b>';
					break;
					
					default:
						//pas de resultat
					return '<span style="color:#ce0000;font-weight:bold;">'+data[0]+'</span>';
				}
			}
		});
				
		$("#destinations").result(function(event, data, formatted) {
			if (data){
				if(data[0]=="station"){
					//stations
						$('#hebergement').val("");
						$("#destinations").val(data[1]);
						$("#station").val(data[1]);
						$('#select_station').val(data[2]);
						$('#code_station_4d').val(data[2]);
						$('#list1').val(data[4]);
						$('#site_geo_4d').val(data[4]);
				}else if(data[0]=="situ"){
					//situations
					
						$('#hebergement').val("");
						$("#station").val("");
						$("#destinations").val(data[1]);
						$('#select_station').val("");
						$('#code_station_4d').val("");
						$('#list1').val(data[2]);
						$('#site_geo_4d').val(data[2]);
					
				}else{
					//pas de resultat
						$('#hebergement').val("");
						$("#station").val("");
						$("#destinations").val("");
						$('#select_station').val("");
						$('#code_station_4d').val("");
						$('#list1').val("");
						$('#site_geo_4d').val("");
				}	
			}		
		});
		//**************************************************************************************************/
		
		//**************************************************************************************************/
		// HOTEL AUTOCOMPLETE
		$("#inp_hebergement").autocomplete("../../../librairie/js/moteur_recherche_v3/ajax/autocomplete_heberg.php", {		
			extraParams: {code_pays2:function (){return $("#code_pays").val()},langue:function (){return $("#langue").val()}},
			width: 300,
			max:20,
			/*autoFill:true,*/
			minChars:3,
			scroll:true,
			scrollHeight:400,
			selectFirst: false,
			formatItem: function(data, value) {
				if(data[0]=='titre'){
					// pas de resultat
					return '<b>'+data[1]+'</b>';
				}else{
					return '<span class="span_over">' + data[1] + '</span><br/><span style="font-size:11px;">' + data[3] + ' (' + data[5] + ')</span>';
				}
			}
		});
				
		$("#inp_hebergement").result(function(event, data, formatted) {
			if (data[0]!='titre'){
				$("#inp_hebergement").val(data[1]);
				$('#hebergement').val(data[2]);
				$('#code_station_4d').val(data[4]);
				$('#site_geo_4d').val(data[6]);	
			}
		});
		
		//**************************************************************************************************/
		//  AUTOCOMPLETE EMAIL MON OKIPI PANIER EN CENTRALE
		$("#email_monokipi_centrale").autocomplete("../../../librairie/js/moteur_recherche_v3/ajax/autocomplete_email_monokipi.php", {		
			//extraParams: {code_pays2:function (){return $("#code_pays").val()},langue:function (){return $("#langue").val()}},
			width: 300,
			max:20,
			/*autoFill:true,*/
			minChars:3,
			scroll:true,
			scrollHeight:400,
			selectFirst: false,
			formatItem: function(data, value) {
				if(data[0]=='titre'){
					// pas de resultat
					return '<b>'+data[1]+'</b>';
				}else{
					return '<b>'+data[0]+'</b>'+'<br/>' + data[2] + ' ' + data[1] ;
				}
			}
		});

		
		$("#email_monokipi_centrale").result(function(event, data, formatted) {
			if (data[0]!='titre'){
				xajax_remplir_panier_monokipi(data[0], data[3], 'centrale');
			}
		});
		
		
		$("#email_monokipi_centrale").keyup(
			function() {
				$("#cli_civil").val('');
				
				$('#cli_nom').val('');
				$('#cli_prenom').val('');
				$('#cli_email').val('');
				
				if(document.getElementById("cli_email2")){
					$('#cli_email2').val('');
				}
				
				$('#cli_adr').val('');
				$('#cli_zip').val('');
				$('#cli_ville').val('');
				$('#cli_tlf').val('');
				
				$('#cli_pays').val('');
				
				/*$("#cli_origin_mot").attr("checked", "checked"); */
				
				if(document.getElementById("id_cli_monokipi")){
					$("#id_cli_monokipi").val('');
				}				
			}
		);
		
		//**************************************************************************************************/
		
		$("#code_pays").change(
			function() {
				if ($("#code_pays").val()==''){
					alert(traduc_pays_obligatoire);
				}else{
					if(document.getElementById("sel_destinations")){
						getList_Zone(this.value, $("#langue").val());
						cleanZoneList("sel_heberg") ;
					}else{
						document.getElementById("destinations").value = '';
						document.getElementById("destinations").focus();
					}
				}
			}
		);
		
		$("#sel_destinations").change(
			function() {
				getList_Stations(this.value, $("#langue").val());
				$("#hebergement").val('');	
			}
		);
		
		$("#station").change(
			function() {
				getList_Heberg('station',this.value);
				document.getElementById("hebergement").value='';
				//clear_champs();
			}
		);
		
		
		$("#destinations").keyup(
			function() {
				$("#inp_hebergement").val("");	
				$("#hebergement").val("");	
				$('#site_geo_4d').val("");
				$('#code_station_4d').val("");
				
				if ($("#code_pays").val()==''){
					alert(traduc_pays_obligatoire);
				}
			}
		);

		$("#inp_hebergement").keyup(
			function() {
				$("#destinations").val("");	
				$("#hebergement").val("");	
				$('#site_geo_4d').val("");
				$('#code_station_4d').val("");
				
				if ($("#code_pays").val()==''){
					alert(traduc_pays_obligatoire);
				}
			}
		);
		
		//PARADORS
		$('#situation').change(function() {
			
			$('#hebergement').load('../../../librairie/php/commun/requete_ajax/req_ajax_maj_paradors.php', {'situation': $(this).val()});
			//clear_champs();
		});
		
		
	}
);


function verif_check() {
	var cpt=0;
	$('input[@name^=assurance_checkbox]').each(
		function() {
			if ($(this).attr('checked')== true) {
				cpt++;
			}
		}
	);
	return cpt;
}

function verif_check_vol() {
	var cpt=0;
	$('input[@name^=check_vol_]').each(
		function() {
			if ($(this).val()== 'vol') {
				cpt++;
			}
		}
	);	
	return cpt;
}

function verif_check_multirisque(i) {
	var cpt_multi=0;
	$('input[@name^=assurance_checkbox_multirisque]').each(
		function() {
			
			if ($(this).attr('checked')== true) {
				cpt_multi++;
			}
		}
	);
	if (cpt_multi==0) {
			$('#div_assurance').hide();
		}
	$('#form_pers_'+i).html('').remove();
	$('#multi_'+i).val(0);
}
function changeNameCheckCgpa() {
	if (verif_check()==0) {
		$('#div_cgpa input[@name=check_cgpa]').attr('id', 'uncheck_cgpa');
		$('#div_titre_cgpa').hide();
		$('#div_cgpa').hide();
	}
	else {
		$('#div_cgpa input[@name=check_cgpa]').attr('id', 'check_cgpa');
		$('#div_cgpa').show();
		$('#div_titre_cgpa').show();
	}
}

function check_assu_annu(object, i) {
	changeNameCheckCgpa();
	var cpt_multi = $('#cpt_multi_'+i).val();
	var prix_annu = $('#prix_assu_annu_'+i).val();
	var prix_multi = $('#prix_assu_multi_'+i).val();
	var cpt_annu = $('#cpt_annu_'+i).val();
	var site = $('#assu_site_web').val();
	var client = $('#assu_client').val();
	if  (object.attr('checked') == true) {
		$.ajax({
			type: "POST",
			url: "../../../pages/commun/session_assurance.php",
			data: "assurance=annulation&type_operation=ajouter&montant="+prix_annu+"&id="+i
		});
		$('#assurance_checkbox_multirisque_'+i).attr('checked', false) ;
		verif_check_multirisque(i);
		tab_pers_ea[i]='';
		actualiser_prix_panier(prix_annu, '+', i);
		actualiser_prix_total_panier(prix_annu, '+');
		if ((cpt_multi)>0) {
			actualiser_prix_panier(prix_multi, '-', i);
			actualiser_prix_total_panier(prix_multi, '-');
			$('#cpt_multi_'+i).val(1);	
		}
		$('#cpt_annu_'+i).val(1);
		$('#cpt_multi_'+i).val(0);	
	}	
	else {
		$.ajax({
			type: "POST",
			url: "../../../pages/commun/session_assurance.php",
			data: "assurance=annulation&type_operation=supprimer&montant="+prix_annu+"&id="+i
		});
		actualiser_prix_panier(prix_annu, '-', i);
		actualiser_prix_total_panier(prix_annu, '-');
		$('#cpt_annu_'+i).val(0);
	}
}

function check_assu_multi(object, id) {
	changeNameCheckCgpa();
	var cpt_annu = $('#cpt_annu_'+id).val();
	var cpt_multi = $('#cpt_multi_'+id).val();
	var prix_annu = $('#prix_assu_annu_'+id).val();
	var prix_multi = $('#prix_assu_multi_'+id).val();
	if  (object.attr('checked') == true) {
		if (verif_check_vol()==0){
			$('#div_assurance').show();
			$('#form_assurance').show();
			$.ajax({
				type: "POST",
				url: "../../../pages/commun/form_assu_multi.php",
				data: "id="+id,
				async: true,
				success: function(html){
					$('#form_assurance').append(html);
				}
			});
		}
		$.ajax({
			type: "POST",
			url: "../../../pages/commun/session_assurance.php",
			data: "assurance=multirisque&type_operation=ajouter&montant="+prix_multi+"&id="+id
		});
		$('#assurance_checkbox_annulation_'+id).attr('checked', false);
		actualiser_prix_panier(prix_multi, '+', id);
		actualiser_prix_total_panier(prix_multi, '+');
		if ((cpt_annu)>0) {
			actualiser_prix_panier(prix_annu, '-', id);
			actualiser_prix_total_panier(prix_annu, '-');
			$('#cpt_annu_'+id).val(1);
		}
		$('#cpt_multi_'+id).val(1);	
		$('#cpt_annu_'+id).val(0);
	}
	else {
		$.ajax({
			type: "POST",
			url: "../../../pages/commun/session_assurance.php",
			data: "assurance=multirisque&type_operation=supprimer&montant="+prix_multi+"&id="+id
		});
		verif_check_multirisque(id);
		tab_pers_ea[id]='';
		actualiser_prix_panier(prix_multi, '-', id);
		actualiser_prix_total_panier(prix_multi, '-');
		$('#cpt_multi_'+id).val(0);	
	}
}


function actualiser_prix_panier(prix, operation, i) {
	if (operation=='+'){
		$('#panier_total_produit_'+i).html(Math.round((parseFloat($('#panier_total_produit_'+i).html()) + parseFloat(prix))*100)/100);
		$('#px_total_panier1_reduc').html(Math.round((parseFloat($('#px_total_panier1_reduc').html()) + parseFloat(prix))*100)/100);
	}else{
		$('#panier_total_produit_'+i).html(Math.round((parseFloat($('#panier_total_produit_'+i).html()) - parseFloat(prix))*100)/100);
		$('#px_total_panier1_reduc').html(Math.round((parseFloat($('#px_total_panier1_reduc').html()) - parseFloat(prix))*100)/100);
	}
}

function actualiser_prix_total_panier(prix, operation)	{
	if (operation=='+') {
		$('#px_total_panier1').html(Math.round((parseFloat($('#px_total_panier1').html()) + parseFloat(prix))*100)/100);
		$('#px_total_panier').html(Math.round((parseFloat($('#px_total_panier').html()) + parseFloat(prix))*100)/100);
		$('#px_total_panier_reduc').html(Math.round((parseFloat($('#px_total_panier_reduc').html()) + parseFloat(prix))*100)/100);
	}
	else {
		$('#px_total_panier1').html(Math.round((parseFloat($('#px_total_panier1').html()) - parseFloat(prix))*100)/100);
		$('#px_total_panier').html(Math.round((parseFloat($('#px_total_panier').html()) - parseFloat(prix))*100)/100);
		$('#px_total_panier_reduc').html(Math.round((parseFloat($('#px_total_panier_reduc').html()) - parseFloat(prix))*100)/100);
	}
}

function clear_champs() {
	$('#hebergement').val("");
	$("#destinations").val("");
	$('#station').val("");
	$('#sel_heberg').val("");
	$('#site_geo_4d').val("");
	$('#code_station_4d').val("");
}


function init() {
	/*$('#site_geo_4d').val(val_zone);*/
	$("#heberg").val("");
	$('#hebergement').val("");
	$("#destinations").val("");
	$("#sel_destinations").val("");
	$('#select_station').val("");
	
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// POUR RAPPEL FONCTIONS JQUERY PAR XAJAX
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

function saisieDestination(){
	$("#destinations").autocomplete("../../../librairie/js/moteur_recherche_v3/ajax/autocomplete_destinations.php", {		
		extraParams: {code_pays2:function (){return $("#code_pays").val()},langue:function (){return $("#langue").val()}},
		width: 200,
		max:20,
		/*autoFill:true,*/
		minChars:3,
		scroll:true,
		scrollHeight:400,
		selectFirst: false,
		formatItem: function(data, value) {
			switch(data[0]){
				case "station":
					//stations
					return data[1];
				break;
				case "situ":
					//situations
					return data[1];
				break;
				case "titre":
					//titre
					return '<b>'+data[1]+'</b>';
				break;
				
				default:
					//pas de resultat
				return '<span style="color:#ce0000;font-weight:bold;">'+data[0]+'</span>';
			}
		}
	});
			
	$("#destinations").result(function(event, data, formatted) {
		if (data){
			if(data[0]=="station"){
				//stations
					$('#hebergement').val("");
					$("#destinations").val(data[1]);
					$("#station").val(data[1]);
					$('#select_station').val(data[2]);
					$('#code_station_4d').val(data[2]);
					$('#list1').val(data[4]);
					$('#site_geo_4d').val(data[4]);
			}else if(data[0]=="situ"){
				//situations
				
					$('#hebergement').val("");
					$("#station").val("");
					$("#destinations").val(data[1]);
					$('#select_station').val("");
					$('#code_station_4d').val("");
					$('#list1').val(data[2]);
					$('#site_geo_4d').val(data[2]);
				
			}else{
				//pas de resultat
					$('#hebergement').val("");
					$("#station").val("");
					$("#destinations").val("");
					$('#select_station').val("");
					$('#code_station_4d').val("");
					$('#list1').val("");
					$('#site_geo_4d').val("");
			}	
		}		
	});
	
	$("#destinations").keyup(
		function() {
			$("#inp_hebergement").val("");	
			$("#hebergement").val("");	
			$('#site_geo_4d').val("");
			$('#code_station_4d').val("");
			
			if ($("#code_pays").val()==''){
				alert(traduc_pays_obligatoire);
			}
		}
	);
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// AUTOCOMPLETE HEBERGEMENT
function saisieHebergement(){
	$("#inp_hebergement").autocomplete("../../../librairie/js/moteur_recherche_v3/ajax/autocomplete_heberg.php", {		
		extraParams: {code_pays2:function (){return $("#code_pays").val()},langue:function (){return $("#langue").val()}},
		width: 300,
		max:20,
		/*autoFill:true,*/
		minChars:3,
		scroll:true,
		scrollHeight:400,
		selectFirst: false,
		formatItem: function(data, value) {
			if(data[0]=='titre'){
				// pas de resultat
				return '<b>'+data[1]+'</b>';
			}else{
				return data[1] + '<br/>' + data[3] + ' (<b>' + data[5] + '</b>)';
			}
		}
	});

	
	$("#inp_hebergement").result(function(event, data, formatted) {
		if (data[0]!='titre'){
			$("#inp_hebergement").val(data[1]);
			$('#hebergement').val(data[2]);
			$('#code_station_4d').val(data[4]);
			$('#site_geo_4d').val(data[6]);	
		}
	});
	
	
	$("#inp_hebergement").keyup(
		function() {
			$("#destinations").val("");	
			$("#hebergement").val("");	
			$('#site_geo_4d').val("");
			$('#code_station_4d').val("");
			
			if ($("#code_pays").val()==''){
				alert(traduc_pays_obligatoire);
			}
		}
	);
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// 	
function changePays(){
	$("#code_pays").change(
		function() {
			if ($("#code_pays").val()==''){
				alert(traduc_pays_obligatoire);
			}else{
				if(document.getElementById("sel_destinations")){
					getList_Zone(this.value, $("#langue").val());
				}else{
					document.getElementById("destinations").value = '';
					document.getElementById("destinations").focus();
				}
			}
		}
	);
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// 
function changeDestination(){		
	$("#sel_destinations").change(
		function() {
			if(document.getElementById('station')){
				getList_Stations(this.value, $("#langue").val());
				$("#hebergement").val('');	
			}
		}
	);
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// 
function changeStation(){
	$("#station").change(
		function() {
			getList_Heberg('station',this.value);
			document.getElementById("hebergement").value='';
			//clear_champs();
			//document.getElementById('hebergement').value='';	
		}
	);
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// 
function clickTopAero(){
	$("#top1_aero").click(function(){
		$("#top_aero").css('display', 'block');
		$("#autre_aero").css('display', 'none');
		$("#aut_aero").addClass('airport2');
		$("#top1_aero").removeClass('airport2');
		//$("#ListAirport").css('background', 'url(../../../medias/images/okipi/structure/moteur_recherche/vol.png) no-repeat;');
		$("#ListAirport").css('background-position', '0px 0px');
	});
}	

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// 
function clickAutAero(){	
	$("#aut_aero").click(function(){
		$("#top_aero").css('display', 'none');
		$("#autre_aero").css('display', 'block');
		$("#top1_aero").addClass('airport2');
		$("#aut_aero").removeClass('airport2');
		//$("#ListAirport").css('background', 'url(../../../medias/images/okipi/structure/moteur_recherche/vol1.png) no-repeat;');
		$("#ListAirport").css('background-position', '0px -400px');
	});
}	

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// 
function clickTopAero1(){
	$("#top1_aero1").click(function(){
		$("#top_aero1").css('display', 'block');
		$("#autre_aero1").css('display', 'none');
		$("#aut_aero1").addClass('airport2');
		$("#top1_aero1").removeClass('airport2');
		//$("#ListAirport1").css('background', 'url(../../../medias/images/okipi/structure/moteur_recherche/vol.png) no-repeat;');
		$("#ListAirport1").css('background-position', '0px 0px');
	});
}	

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// 
function clickAutAero1(){	
	$("#aut_aero1").click(function(){
		$("#top_aero1").css('display', 'none');
		$("#autre_aero1").css('display', 'block');
		$("#top1_aero1").addClass('airport2');
		$("#aut_aero1").removeClass('airport2');
		//$("#ListAirport1").css('background', 'url(../../../medias/images/okipi/structure/moteur_recherche/vol1.png) no-repeat;');
		$("#ListAirport1").css('background-position', '0px -400px');
	});
}



