function popForm(formurl, titre, width, height) {
	var formWin = window.open(formurl,titre,'location=0,menubar=0,status=1,scrollbars=1,resizable=1,width='+ width +',height='+ height +'');
}

function GoPage(Link){
	document.location.href=Link;
}

function AfficheDiv(qui, quoi){
	$("#" + qui).addClass('visible');
	$("#" + qui).removeClass('invisible');
	if(quoi){
	$("#" + quoi).addClass('visible');
	$("#" + quoi).removeClass('invisible');
	}
}

function CacheDiv(qui, quoi){
	$("#" + qui).addClass('invisible');
	$("#" + qui).removeClass('visible');
	if(quoi){
	$("#" + quoi).addClass('invisible');
	$("#" + quoi).removeClass('visible');
	}

}

function AfficheCacheDiv(qui, quoi){
		AfficheDiv(qui);
		CacheDiv(quoi);
}

function VerifFieldFill(qui,champ){
	if($("#" + qui).val()==""){
		CacheDiv(champ);
	} else {
		AfficheDiv(champ);
	}
}

function DisplayAutreJob(){
	var autreprofession = new Array();
	autreprofession["FR"]="Autre profession";
	autreprofession["ES"]="Otra profesión";
	autreprofession["EN"]="Other profession";
	autreprofession["IT"]="Altra professione";
	autreprofession["DE"]="Anderer Beruf";
	
	if($("#Profession option:selected").val() == 104){
		AfficheDiv("AutreProfession");
	}else{
		CacheDiv("AutreProfession");
	}
	
}

function AffichePaiement(){
	if($("#TypePaiement option:selected").val() == "CB en ligne"){
		AfficheDiv("paiementCB");
		CacheDiv("paiementCheque");
		CacheDiv("paiementVirement");
	
	}else if($("#TypePaiement option:selected").val() == "Cheque"){
		AfficheDiv("paiementCheque");
		CacheDiv("paiementCB");
		CacheDiv("paiementVirement");
		
	}else if($("#TypePaiement option:selected").val() == "Virement"){
		AfficheDiv("paiementVirement");
		CacheDiv("paiementCB");
		CacheDiv("paiementCheque");
	}
	
}


/* AJOUT ACCOMPAGNANT */

function AjoutAccomp(){
	var cpt = parseInt($("#valeuri").val());										 
	//alert(cpt);
//	$("p").live("click", function(){

		$.ajax({
		   type: "POST",
		   url: "../Ajax/ajoutaccomp.php",
		   data: "valeuri=" + cpt,
		   success: function(msg){
			   if(msg != 0){
					$("#ajout").append(msg);
					$("#valeuri").val(cpt + 1) ;
				} else {
					$("#ajout").append("pbme d'ajout");			
				}
			 
			}
		});
//	 });
}

/* SUPPRIMER ACCOMPAGNANT */

function DeleteAccomp(qui, id){
	
		$.ajax({
		   type: "POST",
		   url: "../Ajax/deleteaccomp.php",
		   data: "id=" + id,
		   success: function(msg){
				if(msg=="1"){
					$("#" + qui).fadeOut(400,function(){
						$("#" + qui).remove();					
					});
					
				}
			}
		});
	

}





/* GESTION DYNAMIQUE DES EPREUVES */

function DisplayEpreuve(idpart){
	$('#loader').removeClass('invisible');
	$('#loader').addClass('visible');
	
	if($("#discipline").val() != ""){
		
		$.ajax({
		   type: "POST",
		   url: "../Ajax/displayepreuve.php",
		   data: "id=" + escape($("#discipline").val()) + "&idpart=" + idpart,
		   async:false,
		   success: function(msg){
				if(msg){
					$("#epreuve").html(msg);
				}
			}
		});			
		
	//	$("#epreuve").load("../Ajax/displayepreuve.php?id=" + escape($("#discipline").val()) + "&idpart=" + idpart);
	
	} else {
		alert("aucune id ");		
	}
	
	$('#loader').removeClass('visible');
	$('#loader').addClass('invisible');
	
}

function AjoutEpreuve(idepreuve, iddisci, idpart){
	if(idepreuve != "" && iddisci != "" && idpart != ""){
		$("#choixepreuve").load("../Ajax/ajoutepreuve.php?id=" + idepreuve + "&iddisci=" + iddisci + "&idpart=" + idpart);
		$('html, body').animate({scrollTop:$("#choixepreuve").offset().top-50}, 'slow');
	} else {
		alert("erreur de reception id ");		
	}
}

function DeleteEpreuve(id, idpart){
	if(id){
		$("#choixepreuve").load("../Ajax/deletepreuve.php?id=" + id + "&idpart=" + idpart);
	} else {
		alert("erreur de reception id ");		
	}
}

function DisplayEpreuveAccomp(cpt, idaccomp){
	$('#loader').removeClass('invisible');
	$('#loader').addClass('visible');
	
	if($("#discipline" + cpt).val() != ""){
		$.ajax({
		   type: "POST",
		   url: "../Ajax/displayepreuve.php",
		   data: "id=" + escape($("#discipline" + cpt).val()) + "&idaccomp=" + idaccomp + "&cpt=" + cpt,
		   async:false,
		   success: function(msg){
				if(msg){
					$("#epreuve" + cpt).html(msg);
				}
			}
		});		
		
	//	$("#epreuve" + cpt).load("../Ajax/displayepreuve.php?id=" + escape($("#discipline" + cpt).val()) + "&idaccomp=" + idaccomp + "&cpt=" + cpt);
	
	} else {
		alert("aucune id ");
	}
	
	$('#loader').removeClass('visible');
	$('#loader').addClass('invisible');
}

function AjoutEpreuveAccomp(cpt, idepreuve, iddisci, idaccomp){
	if(idepreuve != "" && iddisci != "" && idaccomp != "" && cpt != ""){
		$("#choixepreuve" + cpt).load("../Ajax/ajoutepreuve.php?id=" + idepreuve + "&iddisci=" + iddisci + "&idaccomp=" + idaccomp + "&cpt=" + cpt);
		$('html, body').animate({scrollTop:$("#choixepreuve" + cpt).offset().top-50}, 'slow');
	} else {
		alert("erreur de reception id ");		
	}
}

function DeleteEpreuveAccomp(cpt, id, idaccomp){
	if(id){
		$("#choixepreuve" + cpt).load("../Ajax/deletepreuve.php?id=" + id + "&idaccomp=" + idaccomp + "&cpt=" + cpt);
	} else {
		alert("erreur de reception id ");		
	}
}

/* GESTION DYNAMIQUE DES HOTELS */
function DisplayChambre(){
	var hebergement = $("#hebergement option:selected").val();
	if( hebergement != "" ){
		$("#chambre").load("../Ajax/displaychambre.php?id=" + escape(hebergement));
	} else {
		alert("aucune id ");		
	}
}

function DisplayChambreSup(){
	var hebergement = $("#hebergement option:selected").val();
	if( hebergement != "" ){
		$("#chambreSup").load("../Ajax/displaychambre.php?id=" + escape(hebergement));
		AfficheDiv("liChambreSup");
		CacheDiv("btnChambreSup");
	} else {
		alert("aucune id ");		
	}
}

/* GESTION DYNAMIQUE DES PRIX DE L'HEBERGEMENT*/

function CalculPrixChambre(cpt){
	
	CalculPrixChambrePart();
	CalculPrixAccomp(cpt);
	
}

function CalculPrixChambrePart(){
	var LHebergement = $("#hebergement option:selected").val() != "" ? 1 : 0;
	var LChambre = $("#chambre option:selected").val() != "" ? 1 : 0;
	var result = LHebergement + LChambre ;
	
	var nbnuit = (($("#MoisDep option:selected").val() - $("#MoisArr option:selected").val()) * 30 + ($("#JourDep option:selected").val() - $("#JourArr option:selected").val()));
	
	if(result == 2 && nbnuit > 0){
		$.ajax({
		   type: "GET",
		   url: "../Ajax/calculprix.php",
		   data: "hebergement=" + escape($("#hebergement option:selected").val()) + "&chambre=" + escape($("#chambre option:selected").val()) + "&forfait=" + escape($("#LForfait").val()) + "&nbNuit=" + nbnuit,
		   success: function(msg){
			   if(msg != 0){
					$("#TarifHebergementWeb").val(msg);
				}
			 
			}
		});	
	}
	
}

function CalculPrixAccomp(cpt){
	
	$('#loader').removeClass('invisible');
	$('#loader').addClass('visible');

	var LHebergement = $("#hebergement option:selected").val() != "" ? 1 : 0;
	var LChambre = $("#chambre option:selected").val() != "" ? 1 : 0;
	var result = LHebergement + LChambre ;
	var nbnuit = (($("#MoisDep option:selected").val() - $("#MoisArr option:selected").val()) * 30 + ($("#JourDep option:selected").val() - $("#JourArr option:selected").val()));
	var prixheb;
	// parse int du nb d'occupant
	var nboccupant = parseInt($("#nboccupant").val());
	
	if(cpt){
	// recuperer l'id de l'accompagnant checker
	var accomp = $("#accompagnant" + cpt + ":checkbox:checked" ).val();
	//incrementation du nb occupant estime
	if(accomp > 0){
		$("#nboccupant").val(nboccupant + 1);
	} else {
		$("#nboccupant").val(nboccupant - 1);
	}}
	

	//boucle pour re-evaluer les prix pour chaque occupant
	for(var i=0;i<$("#compteur").val();i++){
		// recuperer l'id de l'accompagnant chcker
		accomp = $("#accompagnant" + i + ":checkbox:checked" ).val();
		if(accomp > 0){
			if(result == 2 && nbnuit > 0){
					$.ajax({
					   type: "GET",
					   url: "../Ajax/calculprixaccomp.php",
					   dataType: "json",
					   data: "hebergement=" + escape($("#hebergement option:selected").val()) + "&chambre=" + escape($("#chambre option:selected").val()) + "&accompagnant=" + accomp + "&nbNuit=" + nbnuit + "&nbOccupant=" + escape($("#nboccupant").val()) + "&compteur=" + i,
					   success: function(msg){
						   if(msg != 0){
						   		$("#prixForfait" + msg.id).val(msg.prix);
								prixheb=parseInt($("#TarifHebergementWeb").val());
								$("#TarifHebergementWeb").val(prixheb + parseInt(msg.prix))
							}
						 
						}
					});
			}
		} else { 
			 prixheb = parseInt($("#TarifHebergementWeb").val());
			 if(isNaN(prixheb)){
					$("#TarifHebergementWeb").val( prixheb - parseInt($("#prixForfait" + i).val()));
			}
			$("#prixForfait" + i).val("0");
		}
	}
	
	$('#loader').removeClass('visible');
	$('#loader').addClass('invisible');

}

function CalculPrixAccompSup(cpt){
	
	$('#loader').removeClass('invisible');
	$('#loader').addClass('visible');
	CalculPrixChambre();
	
	var LHebergement = $("#hebergement option:selected").val() != "" ? 1 : 0;
	var LChambre = $("#chambreSup option:selected").val() != "" ? 1 : 0;
	var result = LHebergement + LChambre ;
	var nbnuit = (($("#MoisDep option:selected").val() - $("#MoisArr option:selected").val()) * 30 + ($("#JourDep option:selected").val() - $("#JourArr option:selected").val()));
	var prixheb;
	// parse int du nb d'occupant
	var nboccupant = parseInt($("#nboccupantSup").val());
	
	if(cpt){
	// recuperer l'id de l'accompagnant checker
	var accomp = $("#accompagnantSup" + cpt + ":checkbox:checked" ).val();
	//incrementation du nb occupant estime
	if(accomp > 0){
		$("#nboccupantSup").val(nboccupant + 1);
	} else {
		$("#nboccupantSup").val(nboccupant - 1);
	}}
	

	//boucle pour re-evaluer les prix pour chaque occupant
	for(var i=0;i<$("#compteurSup").val();i++){
		// recuperer l'id de l'accompagnant chcker
		accomp = $("#accompagnantSup" + i + ":checkbox:checked" ).val();
		if(accomp > 0){
			if(result == 2 && nbnuit > 0){
					$.ajax({
					   type: "GET",
					   url: "../Ajax/calculprixaccomp.php",
					   dataType: "json",
					   data: "hebergement=" + escape($("#hebergement option:selected").val()) + "&chambre=" + escape($("#chambreSup option:selected").val()) + "&accompagnant=" + accomp + "&nbNuit=" + nbnuit + "&nbOccupant=" + escape($("#nboccupantSup").val()) + "&compteur=" + i,
					   success: function(msg){
						   if(msg != 0){
						   		$("#prixForfaitSup" + msg.id).val(msg.prix);
								prixheb=parseInt($("#TarifHebergementWeb").val());
								$("#TarifHebergementWeb").val(prixheb + parseInt(msg.prix))
							}
						 
						}
					});
			}
		} else { 
			 prixheb = parseInt($("#TarifHebergementWeb").val());
			 if(isNaN(prixheb)){
					$("#TarifHebergementWeb").val( prixheb - parseInt($("#prixForfaitSup" + i).val()));
			}
			$("#prixForfaitSup" + i).val("0");
		}
	}
	
	$('#loader').removeClass('visible');
	$('#loader').addClass('invisible');

}

function CalculPrixService(i){
	var total = 0;
	$("#totalpresta" + i).val($("#tarif" + i).val() * $("#qte" + i).val());
	
	
	for(i = 1; i <= $("#imax").val();i++){
		total = total + ($("#tarif" + i).val() * $("#qte" + i).val());
	}
	
	$("#totalservice").val(total + " EUR");
	
	
}


//########################################## NOUVEAU HEBERGEMENT ################################################

/* AJOUT HEBERGEMENT */

function DisplayChambreNew(cpt){
	var hebergement = $("#hebergement" + cpt + " option:selected").val();
	if( hebergement != "" ){
		$("#chambre" + cpt).load("../Ajax/displaychambre.php?id=" + escape(hebergement));
	} else {
		alert("aucune id ");		
	}
}



function InitChoix(cpt){
	
	var JourArr = $("#JourArr" + cpt + " option:selected").val()!= "" ? 1 : 0;
	var MoisArr = $("#MoisArr" + cpt + " option:selected").val()!= "" ? 1 : 0;
	var JourDep = $("#JourDep" + cpt + " option:selected").val()!= "" ? 1 : 0;
	var MoisDep = $("#MoisDep" + cpt + " option:selected").val()!= "" ? 1 : 0;
	
	var hebergement = $("#hebergement" + cpt + " option:selected").val()!= "" ? 1 : 0;
	var chambre = $("#chambre" + cpt + " option:selected").val()!= "" ? 1 : 0;

	var testChampsDate = JourArr + MoisArr + JourDep + MoisDep;
	
		if(testChampsDate == 4){
			// TEST DATE
			if($("#MoisDep" + cpt + " option:selected").val() < $("#MoisArr" + cpt + " option:selected").val()){
				var mesgErreur=new Array;
				mesgErreur["FR"]="Le mois de départ est antérieur au mois d'arrivée";
				mesgErreur["ES"]="El mes de salida es anterior al mes de llegada";
				mesgErreur["EN"]="The departure month is prior to the arrival month";
				mesgErreur["IT"]="Il mese di partenza è antecedente al mese di arrivo";
				mesgErreur["DE"]="Der Abreisemonat liegt vor dem Ankunftsmonat";
				alert(mesgErreur[$('#lang').val()]);	
			
				$("#MoisArr" + cpt).addClass("required_alert");
				$("#MoisDep" + cpt).addClass("required_alert");
				
				$("#MoisArr" + cpt).val('');
				$("#MoisDep" + cpt).val('');
			
			} else if($("#MoisDep" + cpt + " option:selected").val() == $("#MoisArr" + cpt + " option:selected").val()) {
				
				$("#MoisArr" + cpt).removeClass("required_alert");
				$("#MoisArr" + cpt).addClass("required");
				$("#MoisDep" + cpt).removeClass("required_alert");
				$("#MoisDep" + cpt).addClass("required");
					
					if(($("#JourDep" + cpt + " option:selected").val() - $("#JourArr" + cpt + " option:selected").val()) < 3){
						var mesgErreur=new Array;
						mesgErreur["FR"]="Votre séjour ne doit pas être inferieur à 3 jours";
						mesgErreur["ES"]="Tu estancia no puede ser de menos de 3 días";
						mesgErreur["EN"]="Your stay cannot be under 3 nights";
						mesgErreur["IT"]="Il suo soggiorno non può essere inferiore alle 3 notti";
						mesgErreur["DE"]="Ihre Buchung darf nicht weniger als 3 Tage betragen";
						alert(mesgErreur[$('#lang').val()]);
						
						$("#JourArr" + cpt).addClass("required_alert");
						$("#JourDep" + cpt).addClass("required_alert");
						
						$("#JourArr" + cpt).val('');
						$("#JourDep" + cpt).val('');
					
					} else {
						$("#JourArr" + cpt).removeClass("required_alert");
						$("#JourArr" + cpt).addClass("required");
						$("#JourDep" + cpt).removeClass("required_alert");
						$("#JourDep" + cpt).addClass("required");
						
						//TEST SI HEBERGEMENT + CHAMBRE SONT SELECTIONES
						if((hebergement+chambre)==2){
							CalculPrixChambreNew(cpt);
						}
					
					}
			}
		}
	
}

function DeleteOccupant(idoccupant, idpreresa, type){
	
	//TEST SI VARIABLE EXISTE BIEN
	var calcIdoccup = (idoccupant ? 1 : 0) ;
	var calcPresresa = (idpreresa ? 1 : 0) ;
	var calcType = (type ? 1 : 0) ;
	if((calcIdoccup + calcPresresa + calcType) == 3){
	
		$.ajax({
		   type: "POST",
		   url: "../Ajax/deleteoccupant.php",
		   data: "idoccup=" + escape(idoccupant) + "&idpreresa=" + escape(idpreresa) + "&type=" + escape(type),
		   success: function(msg){
				if(msg=="1"){
					//alert("suppression occupant");
				}
			}
		});	
	}
	
}




function CalculPrixChambreNew(cpt){
	
	// INITIALISATION DES VARIABLES
	var JourArr = $("#JourArr" + cpt + " option:selected").val();
	var MoisArr = $("#MoisArr" + cpt + " option:selected").val();
	var JourDep = $("#JourDep" + cpt + " option:selected").val();
	var MoisDep = $("#MoisDep" + cpt + " option:selected").val();
	var LHebergement = $("#hebergement" + cpt + " option:selected").val();
	var LChambre = $("#chambre" + cpt + " option:selected").val();
	var lanceCalcul = "PASOK";
	
	
	//TABLEAU DES ALERTS LANGUES
	var TxtLang = new Array("FR", "ES", "EN", "IT", "DE");
	
	TxtLang["FR"] = new Array(
						 "Vous n'avez pas sélectionné de jour d'arrivée",
						 "Vous n'avez pas sélectionné de mois d'arrivée",
						 "Vous n'avez pas sélectionné de jour de départ",
						 "Vous n'avez pas sélectionné de mois de départ",
						 "Vous n'avez pas sélectionné d'hebergement",
						 "Vous n'avez pas sélectionné de chambre"
						 );
	
	TxtLang["ES"] = new Array(
						 "No ha seleccionado el día de llegada",
						 "No ha seleccionado el mes de llegada",
						 "No ha seleccionado el día de salida",
						 "No ha seleccionado el mes de salida",
						 "No ha seleccionado el alojamiento",
						 "No ha seleccionado la habitación"
						 );
	
	TxtLang["EN"] = new Array(
					 "You have not selected your arrival date",
					 "You have not selected your arrival month",
					 "You have not selected your departure date",
					 "You have not selected your departure month",
					 "You have not selected any accommodation",
					 "You have not selected the type of room"
					 );

	TxtLang["IT"] = new Array(
					 "Non ha selezionato il giorno dell'arrivata",
					 "Non ha selezionato il mese dell'arrivata ",
					 "Non ha selezionato il giorno di partenza ",
					 "Non ha selezionato il mese di partenza",
					 "Non ha selezionato gli alloggi",
					 "Non ha selezionato la camera"
					 );

	TxtLang["DE"] = new Array(
					 "Sie haben nicht Ihren Ankunftstag ausgewählt",
					 "Sie haben nicht Ihren Ankunftsmonat ausgewählt",
					 "Sie haben nicht Ihren Anfangstag ausgewählt",
					 "Sie haben nicht Ihren Anfangsmonat ausgewählt",
					 "Sie haben keine Unterkunft ausgewählt",
					 "Sie haben kein Zimmer ausgewählt"
					 );
	
		// TEST SI VALEUR ONT ETE SELECTIONNEES
		if(JourArr == ""){
			alert(TxtLang[$('#lang').val()][0]);
		} else if(MoisArr == ""){
			alert(TxtLang[$('#lang').val()][1]);
		} else if(JourDep == ""){
			alert(TxtLang[$('#lang').val()][2]);
		} else if(MoisDep == ""){
			alert(TxtLang[$('#lang').val()][3]);
		} else if(LHebergement == ""){
			alert(TxtLang[$('#lang').val()][4]);
		} else if(LChambre == ""){
			alert(TxtLang[$('#lang').val()][5]);
		} else {	
			lanceCalcul = "OK";
		}
		
	// SI SELECTION OBLIGATOIRE FAITE ALORS LANCE CALCUL PRIX CHAMBRE PART + ACCOMP
	if(lanceCalcul == "OK"){
		
		//TESTER SI PARTICIPANT CHECKER
		var part = $("#id" + cpt + ":checkbox:checked").length;
			
		// CALCULER LE PRIX PARTICIPANT
			// AJOUT SI CHECKER
			if(part){
				var prixPart = CalculPrixChambrePartNew(cpt);
				$("#prixPart" + cpt).val(prixPart);
			
			//REDUCTION ET SUPPRESSION SI DECHECKER
			} else {
				if($("#prixPart" + cpt).val()>0){
					if($("#idpreresa" + cpt).val() != ""){
						DeleteOccupant($("#id" + cpt).val(), $("#idpreresa" + cpt).val(), 'part');
					}
					var prixPart = CalculPrixChambrePartNew(cpt);
					var diff = $("#prixPart" + cpt).val() - prixPart;
					$("#prixPart" + cpt).val(diff);
				}
			}


	// CALCULER LES PRIX ACCOMPAGNANTS
		 //CALCULER NB OCCUPANT
			var nboccup = 0;
			var prixAccomp = 0;
			var totalPrixAccomp = 0;
			var z = 0;
			var tabIdAccomp = new Array();

			for(var i=0;i<$("#compteur" + cpt).val();i++){
				// recuperer l'id de l'accompagnant chcker
				nbaccomp = $("#accompagnant" + cpt + "_" + i + ":checkbox:checked" ).length;
				nboccup += nbaccomp;
				if(nbaccomp==1){
					z += 1;
					tabIdAccomp[z] = $("#accompagnant" + cpt + "_" + i).val();
				}
				
			}
		nboccup = part + nboccup;
		 
		 //TEST SI ACCOMP CHECKER
			for(var i=0;i<$("#compteur" + cpt).val();i++){
				// recuperer l'id de l'accompagnant chcker
				accomp = $("#accompagnant" + cpt + "_" + i + ":checkbox:checked" ).length;
				if(accomp){
					prixAccomp = CalculPrixAccompNew(cpt,$("#accompagnant" + cpt + "_" + i + ":checkbox:checked" ).val(),nboccup);
					$("#prixAccomp" + cpt + "_" + i).val(prixAccomp);
				
				// SI ACCOMP DECHECKER PRIX ACCOMP=0 ET SUPPRESSION
				} else {
					if($("#idpreresa" + cpt).val() != ""){
						DeleteOccupant($("#accompagnant" + cpt + "_" + i).val(), $("#idpreresa" + cpt).val(), 'accomp');
					}
					$("#prixAccomp" + cpt + "_" + i).val(0);					
				}
				
				//CALCUL PRIX TOTAL ACCOMPAGNANT
				totalPrixAccomp += parseInt($("#prixAccomp" + cpt + "_" + i).val());
			}
			
			//CALCUL PRIX RESERVATION N
			var totalReservation = totalPrixAccomp + parseInt($("#prixPart" + cpt).val());	
			$("#prixHebergement" + cpt).val(totalReservation);
			
			calculTarifHebergementWeb();

	} 

}


function calculTarifHebergementWeb(){
			
			//CUMUL DES N RESERVATIONS
			var totalHebergement = 0;
			var calculHebergement = 0;
			var calculEtudiant = 0;
			var totalEtudiant = 0;
			
			for(var i=0;i<parseInt($("#valeuri").val());i++){
				if(isNaN(parseInt($("#prixHebergement" + i).val()))){
					calculHebergement = 0;
					calculEtudiant = 0;
				} else {
					calculHebergement = parseInt($("#prixHebergement" + i).val());
					calculEtudiant = parseInt($("#prixPart" + i).val());
				}
				totalHebergement += calculHebergement;
				totalEtudiant += calculEtudiant;
			}

			//CALCUL PRIX HEBERGEMENT TOTAL
			$("#TarifHebergementWeb").val(totalHebergement);
			$("#promoEtudiant").val(totalEtudiant*0.2);
}


function CalculPrixChambrePartNew(cpt){
	var LHebergement = $("#hebergement" + cpt + " option:selected").val();
	var LChambre = $("#chambre" + cpt + " option:selected").val();
	var nbnuit = (($("#MoisDep" + cpt + " option:selected").val() - $("#MoisArr" + cpt + " option:selected").val()) * 30 + ($("#JourDep" + cpt + " option:selected").val() - $("#JourArr" + cpt + " option:selected").val()));
	
	var prixpart = 0;
	
		if(nbnuit > 0){
			$.ajax({
			   type: "GET",
			   url: "../Ajax/calculprix.php",
			   async: false,
			   data: "hebergement=" + escape(LHebergement) + "&chambre=" + escape(LChambre) + "&forfait=" + escape($("#LForfait").val()) + "&nbNuit=" + nbnuit,
			   success: function(msg){
				   if(msg != 0){
						//alert("msg" + msg);
						prixpart = parseInt(msg);
					} else {
						prixpart = 0;
					}
				 
				}
			});	
		} else {
			prixpart = 0;
		}
		return prixpart;
}

function CalculPrixAccompNew(cpt,idaccomp,nboccup){
	var LHebergement = $("#hebergement" + cpt + " option:selected").val();
	var LChambre = $("#chambre" + cpt + " option:selected").val();
	var nbnuit = (($("#MoisDep" + cpt + " option:selected").val() - $("#MoisArr" + cpt + " option:selected").val()) * 30 + ($("#JourDep" + cpt + " option:selected").val() - $("#JourArr" + cpt + " option:selected").val()));

			if(nbnuit > 0){
					$.ajax({
					   type: "GET",
					   url: "../Ajax/calculprixaccomp2.php",
			   			async: false,
					   data: "hebergement=" + escape(LHebergement) + "&chambre=" + escape(LChambre) + "&accompagnant=" + idaccomp + "&nbNuit=" + nbnuit + "&nbOccupant=" + escape(nboccup),
					   success: function(msg){
						   if(msg != 1){
								prixaccomp = parseInt(msg);
							} else {
								prixaccomp = 0;
							}
						 
						}
					});
			} else {
				prixaccomp = 0;
			}
		return prixaccomp;
}









/* SUPPRIMER HOTEL */

function viderCheckBox(cpt){
	
	$("#id" + cpt).attr('checked', false);
	
	for(var i=0;i<$("#compteur" + cpt).val();i++){
		$("#accompagnant" + cpt + "_" + i).attr('checked', false);
	}
	
}

function initValeurHebergement(cpt){
	$("#prixHebergement" + cpt).val(0);
	$("#MoisArr" + cpt).val('');
	$("#MoisDep" + cpt).val('');
	$("#JourArr" + cpt).val('');
	$("#JourDep" + cpt).val('');
	$("#hebergement" + cpt).val('');
	$("#chambre" + cpt).val('');
	
	
}


function DeleteHotel(cpt,qui){
	viderCheckBox(cpt);
	initValeurHebergement(cpt);	
	calculTarifHebergementWeb();
	$("#" + qui).fadeOut(400,function(){
		$("#" + qui).remove();					
	});
	
}

function DeletePreResa(cpt,qui){
	
	if($("#idpreresa" + cpt).val() != ""){
		
		$.ajax({
		   type: "POST",
		   url: "../Ajax/deletehebergement.php",
		   data: "id=" + escape($("#idpreresa" + cpt).val()),
		   success: function(msg){
				if(msg=="1"){
					viderCheckBox(cpt);
					initValeurHebergement(cpt);	
					calculTarifHebergementWeb();
					$("#" + qui).fadeOut(400,function(){
					$("#" + qui).remove();					
					});
				}
			}
		});
		
	}
	
}

//########################################## FICHE SPORT ################################################

function OpenFicheSport(){
	var url = "http://www.medigames.com/layouts/ficheSport/";
	var lang = $("#lang").val();
	var ficheSport = $("#fichesport option:selected").val();
	if(ficheSport != ""){
		window.open(url + lang + "/" + ficheSport) ;	
	}
	
}