//pour connaitre la position d'un élément
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};
	}
});


/*
* Selects an option by value
*
* @name     selectOptions
* @author   Mathias Bank (http://www.mathias-bank.de)
* @param    value specifies, which options should be selected
* @example  jQuery("#myselect").selectOptions("val1");
*
*/
jQuery.fn.selectOptions = function(value) {
	
	this.each(
	function()	{
		if(this.nodeName.toLowerCase() != "select") return;

		// get number of options
		var optionsLength = this.options.length;

		if(value)
		{
			for(var i = 0; i<optionsLength; i++) {
				if (this.options[i].value == value) {
					this.options[i].selected = true;
				};
			}
		}

		else
		{
			
			this.options[0].selected = true;
			
		}
	}
	)
	
	return this;
}
/////////////////////debut cache moteur////////////////////////	
	function change_combo_dest(dest){
		$('.loading1').css("display","none");
		$('.loading2').css("display","block");
		if(document.getElementById("check").value == "avance"){				
			$('.loading3').css("display","block");
			$('.loading4').css("display","block");	
			$('.loading5').css("display","block");	
			//$('#bt_rech').css("visibility","hidden");
		}	
					
		$('#cbdate').empty().append('');
		$('#cbcomp').empty().append('');
		$('#cbprix').empty().append('');
		$('#cbduree').empty().append('');
						
		//Recuperation premiere date 
			$.ajax({
				type: "POST",
				url: '/proxy.php',
				data: {what:'comboSearchDate', dest: dest},
				success: function(msg){
					if(msg.length>0){
						var dateEnCours=msg;
					}
			
					$.ajax({
						type: "POST",
						url: '/proxy.php',
						data: { what: 'comboDate', dest: dest, date_en_cours:dateEnCours},
						success: function(msg){
						if(msg.length>0){
							$('.loading2').css("display","none");
							if(document.all) $('#cbdate').empty().append(msg);
							 $('#cbdate').empty().append(msg);
							//else $('#cbdate').empty().append(msg).selectOptions(dateEnCours);
						}
						//recharger le combo comp	
						$.ajax({
							type: "POST",
							url: '/proxy.php',
							data: {what: 'comboComp', dest: dest, depart:$('#cbdate').val()},
							success: function(msg){
								if(msg.length>0){
									$('.loading3').css("display","none");
									if(document.all) $('#cbcomp').empty().append(msg);
									$('#cbcomp').empty().append(msg);
									//else $('#cbcomp').empty().append(msg).selectOptions();
								}
								//recharger le combo prix	
								$.ajax({
									type: "POST",
									url: '/proxy.php',
									data: {what: 'comboPrix', dest: dest,depart:$('#cbdate').val(), comp:$('#cbcomp').val()},							
									success: function(msg){
										if(msg.length>0){
											$('.loading4').css("display","none");
											if(document.all) $('#cbprix').empty().append(msg);
											 $('#cbprix').empty().append(msg);
											//else $('#cbprix').empty().append(msg).selectOptions();
										}
										$.ajax({
											type: "POST",
											url: '/proxy.php',
											data: {what: 'comboDuree', dest: dest,depart:$('#cbdate').val(),prix: $('#cbprix').val(), comp:$('#cbcomp').val()},
											success: function(msg){
												if(msg.length>0){
													$('.loading5').css("display","none");
													if(document.all) $('#cbduree').empty().append(msg);
													$('#cbduree').empty().append(msg);
													//else $('#cbduree').empty().append(msg).selectOptions();
												}
											},
											error: function(msg){
												$("#cbduree").attr("disabled","true");												
											}
										});
									},
									error: function(msg){
										$("#cbprix").attr("disabled","true");
											
									}
								});
							},
							error: function(msg){
								$("#cbcomp").attr("disabled","true");
							}
						});
					},
					error: function(msg){
						$("#cbdest").attr("disabled","true");
						$("#cbdate").attr("disabled","true");
					}					
				});
			},
			error: function(msg){
								
			}
			/*$('#cbdate').ajaxStop(function(){ 				
				$('#bt_rech').css("visibility","visible");					
		});*/
		});			
	}
	
	
function change_combo_date(){		
	if(document.getElementById("check").value == "avance"){	
		$('.loading3').css("display","block");
		$('.loading4').css("display","block");	
		$('.loading5').css("display","block");	
		//$('#bt_rech').css("visibility","hidden");
	}	
	$('#cbcomp').empty().append('');
	$('#cbprix').empty().append('');
	$('#cbduree').empty().append('');		

	
	
	//alert($('#cbdate_jour').val());
	//recharger le combo comp	
	$.ajax({
		type: "POST",
		url: '/proxy.php',
		data: {what: 'comboComp', dest: $('#cbdest').val(),depart:$('#cbdate').val()},
		success: function(msg){
			if(msg.length>0){
				$('.loading3').css("display","none");
				if(document.all) $('#cbcomp').empty().append(msg);
				else $('#cbcomp').empty().append(msg).selectOptions();
			}
			//recharger le combo prix	
				$.ajax({
					type: "POST",
					url: '/proxy.php',
					data: {what: 'comboPrix', dest: $('#cbdest').val(),depart:$('#cbdate').val(), comp:$('#cbcomp').val()},
					success: function(msg){
					if(msg.length>0){
						$('.loading4').css("display","none");
						if(document.all) $('#cbprix').empty().append(msg);
						else $('#cbprix').empty().append(msg).selectOptions();
					}
					$.ajax({
						type: "POST",
						url: '/proxy.php',
						data: {what: 'comboDuree', dest: $('#cbdest').val(),depart:$('#cbdate').val(),prix: $('#cbprix').val(), comp:$('#cbcomp').val()},
						success: function(msg){
							if(msg.length>0){
								$('.loading5').css("display","none");
								if(document.all) $('#cbduree').empty().append(msg);
								else $('#cbduree').empty().append(msg).selectOptions();
							}
						},
						error: function(msg){
							$("#cbduree").attr("disabled","true");
						}
					});
				},
				error: function(msg){
					$("#cbprix").attr("disabled","true");
				}
			});
		},
		error: function(msg){
			$("#cbcomp").attr("disabled","true");
												
		}
	});
}

function change_combo_comp(){
	if(document.getElementById("check").value == "avance"){	
		$('.loading4').css("display","block");	
		$('.loading5').css("display","block");	
		//$('#bt_rech').css("visibility","hidden");
	}							
	$('#cbprix').empty().append('');
	$('#cbduree').empty().append('');						
	//recharger le combo prix	
	$.ajax({
		type: "POST",
		url: '/proxy.php',
		data: {what: 'comboPrix', dest: $('#cbdest').val(),depart:$('#cbdate').val(), comp:$('#cbcomp').val()},
			success: function(msg){
				if(msg.length>0){
					$('.loading4').css("display","none");
					if(document.all) $('#cbprix').empty().append(msg);
					else $('#cbprix').empty().append(msg).selectOptions();
				}
				$.ajax({
					type: "POST",
					url: '/proxy.php',
					data: {what: 'comboDuree', dest: $('#cbdest').val(),depart:$('#cbdate').val(),prix: $('#cbprix').val(), comp:$('#cbcomp').val()},
					success: function(msg){
					if(msg.length>0){
						$('.loading5').css("display","none");
						if(document.all) $('#cbduree').empty().append(msg);
						else $('#cbduree').empty().append(msg).selectOptions();
					}
				},
				error: function(msg){
					$("#cbduree").attr("disabled","true");
				}
			});
		},
		error: function(msg){
			$("#cbprix").attr("disabled","true");
		}
	});
}

function change_combo_prix(){		
	if(document.getElementById("check").value == "avance"){	
		$('.loading5').css("display","block");	
		//$('#bt_rech').css("visibility","hidden");
	}	
	$('#cbduree').empty().append('');
		$.ajax({
		type: "POST",
		url: '/proxy.php',
		data: {what: 'comboDuree', dest: $('#cbdest').val(),depart:$('#cbdate').val(),prix: $('#cbprix').val(), comp:$('#cbcomp').val()},
		success: function(msg){
			if(msg.length>0){
				$('.loading5').css("display","none");
				if(document.all) $('#cbduree').empty().append(msg);
				else $('#cbduree').empty().append(msg).selectOptions();
			}
		},
		error: function(msg){
			$("#cbduree").attr("disabled","true");
		}
	});
}

function change_combo_promo(){		
	$('#date').empty().append('');
		$.ajax({
		type: "POST",
		url: '/proxy.php',
		data: {what: 'comboDate', dest: $('#dest').val(), promo:1},
		success: function(msg){
			if(msg.length>0){
				if(document.all) $('#date').empty().append(msg);
				else $('#date').empty().append(msg).selectOptions();
			}
		},
		error: function(msg){
			$("#date").attr("disabled","true");
		}
	});
}
	
//moteure luxe
	
function change_combo_dest_luxe(dest){
	$('.loading2').css("display","block");
	$('.loading3').css("display","block");
	$('.loading4').css("display","block");	
	//$('#bt_rech').css("visibility","hidden");
	$('#cbdate').empty().append('');
	$('#cbcomp').empty().append('');
	$('#cbduree').empty().append('');
			
	//Recuperation premiere date 
	$.ajax({
		type: "POST",
		url: '/proxy.php',
		data: {what:'comboSearchDate', dest:dest, luxe:1},
		success: function(msg){
			if(msg.length>0){
				var dateEnCours=msg;
			}							
			$.ajax({
				type: "POST",
				url: '/proxy.php',
				data: { what: 'comboDate', dest:dest, date_en_cours:dateEnCours, luxe:1},
				success: function(msg){
					if(msg.length>0){												
						$('.loading2').css("display","none");
						if(document.all) $('#cbdate').empty().append(msg);
						else $('#cbdate').empty().append(msg).selectOptions(dateEnCours);
					}
					//recharger le combo comp	
					$.ajax({
						type: "POST",
						url: '/proxy.php',
						data: {what: 'comboComp', dest:dest,depart:$('#cbdate').val(), luxe:1},
						success: function(msg){
							if(msg.length>0){
								$('.loading3').css("display","none");
								if(document.all) $('#cbcomp').empty().append(msg);
								else $('#cbcomp').empty().append(msg).selectOptions();
							}									
										
							$.ajax({
								type: "POST",
								url: '/proxy.php',
													data: {what: 'comboDuree', dest:dest,depart:$('#cbdate').val(),prix: $('#cbprix').val(), comp:$('#cbcomp').val(), luxe:1},
													success: function(msg){
													if(msg.length>0){
														$('.loading4').css("display","none");
														if(document.all) $('#cbduree').empty().append(msg);
														else $('#cbduree').empty().append(msg).selectOptions();
													}
											},
											error: function(msg){												
												$("#cbduree").attr("disabled","true");												
											}
									});
								},
								error: function(msg){											
									$("#cbcomp").attr("disabled","true");
								}
							});
							},
								error: function(msg){
									$("#cbdest").attr("disabled","true");
									$("#cbdate").attr("disabled","true");
								}					
							});
						},
						error: function(msg){
											
						}
			  		});			
				
		
		}
		function change_combo_date_luxe(){			
						$('.loading3').css("display","block");
						$('.loading4').css("display","block");	
						//$('#bt_rech').css("visibility","hidden");
						$('#cbcomp').empty().append('');
						$('#cbduree').empty().append('');
						//recharger le combo comp	
						$.ajax({
							type: "POST",
							url: '/proxy.php',
							data: {what: 'comboComp', dest: $('#cbdest').val(),depart:$('#cbdate').val(), luxe:1},
							success: function(msg){
								if(msg.length>0){
									$('.loading3').css("display","none");
									if(document.all) $('#cbcomp').empty().append(msg);
									else $('#cbcomp').empty().append(msg).selectOptions();
								}
								$.ajax({
									type: "POST",
									url: '/proxy.php',
									data: {what: 'comboDuree', dest: $('#cbdest').val(),depart:$('#cbdate').val(),prix: $('#cbprix').val(), comp:$('#cbcomp').val(), luxe:1},
									success: function(msg){
										if(msg.length>0){
											$('.loading4').css("display","none");
											if(document.all) $('#cbduree').empty().append(msg);
											else $('#cbduree').empty().append(msg).selectOptions();
										}
									},
									error: function(msg){
										$("#cbduree").attr("disabled","true");
									}
								});									
							},
							error: function(msg){
								$("#cbcomp").attr("disabled","true");
							}
						});
					
			
			}
			
			function change_combo_comp_luxe(){					
						$('.loading4').css("display","block");	
						//	$('#bt_rech').css("visibility","hidden");
						$('#cbduree').empty().append('');								
							$.ajax({
								type: "POST",
								url: '/proxy.php',
								data: {what: 'comboDuree', dest: $('#cbdest').val(),depart:$('#cbdate').val(),prix: $('#cbprix').val(), comp:$('#cbcomp').val(), luxe:1},
								success: function(msg){
									if(msg.length>0){
										$('.loading4').css("display","none");
										if(document.all) $('#cbduree').empty().append(msg);
										else $('#cbduree').empty().append(msg).selectOptions();
									}
								},
								error: function(msg){
									$("#cbduree").attr("disabled","true");
								}
							});
					
				
				}
//moteur mini	
function change_combo_dest_mini(dest){
	$('#cbdate').empty().append('');						
				
	//Recuperation premiere date 
	$.ajax({
		type: "POST",
		url: '/proxy.php',
		data: {what:'comboSearchDate', dest: $('#cbdest').val(), mini:1},
		success: function(msg){
			if(msg.length>0){
				var dateEnCours=msg;
			}
				
			$.ajax({
				type: "POST",
					url: '/proxy.php',
					data: { what: 'comboDate', dest: $('#cbdest').val(), date_en_cours:dateEnCours, mini:1},
					success: function(msg){
					if(msg.length>0){												
						$('.loadingMini2').css("display","none");
						if(document.all) $('#cbdate').empty().append(msg);
						else $('#cbdate').empty().append(msg).selectOptions(dateEnCours);
					}											
				},
				error: function(msg){
					$("#cbdate").attr("disabled","true");
				}					
			});
		},
		error: function(msg){
			$("#cbdest").attr("disabled","true");
			$("#cbdate").attr("disabled","true");					
		}
	});			
}



	/////////////////////fin cache moteur ////////////////////////
	/////////////////////debut cache moteur////////////////////////
function change_combo_dest_comp(dest,id_comp){		
	$('.loading2').css("display","block");
	if(document.getElementById("check").value == "avance"){	
		$('.loading3').css("display","block");
		$('.loading4').css("display","block");	
	//	$('#bt_rech').css("visibility","hidden");
	}	
	$('#cbdate').empty().append('');
	$('#cbprix').empty().append('');
	$('#cbduree').empty().append('');
	//Recuperation premiere date 
	$.ajax({
		type: "POST",
		url: '/proxy.php',
		data: {what:'comboSearchDate', dest: $('#cbdest').val(),comp:id_comp},
		success: function(msg){
			if(msg.length>0){
				var dateEnCours=msg;
			}
			$.ajax({
				type: "POST",
				url: '/proxy.php',
				data: { what: 'comboDate', dest: $('#cbdest').val(), date_en_cours:dateEnCours,comp:id_comp},
				success: function(msg){
					if(msg.length>0){
						$('.loading2').css("display","none");
						if(document.all) $('#cbdate').empty().append(msg);
						else $('#cbdate').empty().append(msg).selectOptions(dateEnCours);
					}
					//recharger le combo prix	
					$.ajax({
						type: "POST",
						url: '/proxy.php',
						data: {what: 'comboPrix', dest: $('#cbdest').val(),depart:$('#cbdate').val(), comp:id_comp},
						success: function(msg){
							if(msg.length>0){
								$('.loading3').css("display","none");
								if(document.all) $('#cbprix').empty().append(msg);
								else $('#cbprix').empty().append(msg).selectOptions();
							}
							$.ajax({
								type: "POST",
								url: '/proxy.php',
								data: {what: 'comboDuree', dest: $('#cbdest').val(),depart:$('#cbdate').val(),prix: $('#cbprix').val(), comp:id_comp},
								success: function(msg){
									if(msg.length>0){
										$('.loading4').css("display","none");
										if(document.all) $('#cbduree').empty().append(msg);
										else $('#cbduree').empty().append(msg).selectOptions();
									}
								},
								error: function(msg){
									$("#cbduree").attr("disabled","true");
								}
							});
						},
						error: function(msg){
							$("#cbprix").attr("disabled","true");
						}
					});
				},
				error: function(msg){
					$("#cbdest").attr("disabled","true");
					$("#cbdate").attr("disabled","true");
				}					
			});
		},
		error: function(msg){
		}
	});			
}

function change_combo_date_comp(id_comp){
	//alert("--->"+id_comp)
	if(document.getElementById("check").value == "avance"){	
		$('.loading3').css("display","block");
		$('.loading4').css("display","block");	
//		$('#bt_rech').css("visibility","hidden");
	}	
	$('#cbprix').empty().append('');
	$('#cbduree').empty().append('');						
	//recharger le combo prix	
	$.ajax({
		type: "POST",
		url: '/proxy.php',
		data: {what: 'comboPrix', dest: $('#cbdest').val(), depart:$('#cbdate').val(), comp:id_comp},
		success: function(msg){
			if(msg.length>0){
				$('.loading3').css("display","none");
				if(document.all) $('#cbprix').empty().append(msg);
				else $('#cbprix').empty().append(msg).selectOptions();
			}
			$.ajax({
				type: "POST",
				url: '/proxy.php',
				data: {what: 'comboDuree', dest: $('#cbdest').val(),depart:$('#cbdate').val(),prix: $('#cbprix').val(), comp:id_comp},
				success: function(msg){
					if(msg.length>0){
						$('.loading4').css("display","none");
						if(document.all) $('#cbduree').empty().append(msg);
						else $('#cbduree').empty().append(msg).selectOptions();
					}
				},
				error: function(msg){
					$("#cbduree").attr("disabled","true");
				}
			});
		},
		error: function(msg){
			$("#cbprix").attr("disabled","true");
		}
	});				
}

function change_combo_prix_comp(id_comp){
	//alert("--->"+id_comp)
	if(document.getElementById("check").value == "avance"){	
		$('.loading4').css("display","block");
	}	
	$('#cbduree').empty().append('');						
	//recharger le combo duree	
	$.ajax({
		type: "POST",
		url: '/proxy.php',
		data: {what: 'comboDuree', dest: $('#cbdest').val(),depart:$('#cbdate').val(),prix: $('#cbprix').val(), comp:id_comp},
		success: function(msg){
			if(msg.length>0){
				$('.loading4').css("display","none");
				if(document.all) $('#cbduree').empty().append(msg);
				else $('#cbduree').empty().append(msg).selectOptions();
			}
		},
		error: function(msg){
			$("#cbduree").attr("disabled","true");
		}
	});			
}		
	
	/////////////////////fin cache moteur////////////////////////


function recherche_avancer(txtAvance, txtMoin){	
		if(document.getElementById("cache_0").style.display == "block")	{			
			document.getElementById("cache_0").style.display = "none";
			document.getElementById("cache_1").style.display = "none";
			document.getElementById("cache_2").style.display = "none";
			document.getElementById("recherche_avance").title = txtAvance;
			document.getElementById("recherche_avance").innerHTML = txtAvance;
			document.getElementById("check").value = "moin_avance";
		}
		else{			
			document.getElementById("cache_0").style.display = "block";
			document.getElementById("cache_1").style.display = "block";
			document.getElementById("cache_2").style.display = "block";
			document.getElementById("recherche_avance").title = txtMoin;
			document.getElementById("recherche_avance").innerHTML = txtMoin;
			document.getElementById("check").value = "avance";
		}	
	}

function recherche_luxe(dest_par_defaut){
	$(document).ready(function(){
		$('.loading1').css("display","block");
		$('.loading2').css("display","block");	
		$('.loading3').css("display","block");
		$('.loading4').css("display","block");	
		$('#bt_rech').css("visibility","hidden");	
		
		$('#comboDest').empty().append('');
		$('#cbdate').empty().append('');
		$('#cbcomp').empty().append('');
		$('#cbduree').empty().append('');
		//charge dynamiquement le combo dest de moteur
		$.ajax({
			type: "POST",
			url: '/proxy.php',
			data: {what:'comboDest', luxe:1},
			success: function(msg){
				if(msg.length>0){
					$('.loading1').css("display","none");
					if(document.all) $('#cbdest').empty().append(msg);
					else $('#cbdest').empty().append(msg).selectOptions(dest_par_defaut);
				}
				//Recuperation premiere date 
				$.ajax({
					type: "POST",
					url: '/proxy.php',
					data: {what:'comboSearchDate',dest: $('#cbdest').val(), luxe:1},
					success: function(msg){
					if(msg.length>0){						
						var dateEnCours=msg;
					}					
				//charge dynamiquement le combo date 				
				$.ajax({
					type: "POST",
					url: '/proxy.php',
					data: {what: 'comboDate', dest:$('#cbdest').val(), date_en_cours:dateEnCours, luxe:1},
					success: function(msg){
						if(msg.length>0){
							$('.loading2').css("display","none");
							if(document.all) $('#cbdate').empty().append(msg);
							else $('#cbdate').empty().append(msg).selectOptions(dateEnCours);
						}
						//charge dynamiquement le combo cbcomp lors de l'affichage de la page
						$.ajax({
							type: "POST",
							url: '/proxy.php',
							data: {what: 'comboComp',  dest: $('#cbdest').val(),depart:$('#cbdate').val(), luxe:1},
							success: function(msg){
								if(msg.length>0){
									$('.loading3').css("display","none");
									if(document.all) $('#cbcomp').empty().append(msg);
									else $('#cbcomp').empty().append(msg).selectOptions();
								}
								$.ajax({
										type: "POST",
										url: '/proxy.php',
										data: {what: 'comboDuree', dest:$('#cbdest').val(), depart:$('#cbdate').val(), comp:$('#cbcomp').val(), prix:$('#cbprix').val(), luxe:1},
										success: function(msg){
											if(msg.length>0){
												$('.loading4').css("display","none");
												if(document.all) $('#cbduree').empty().append(msg);
												else $('#cbduree').empty().append(msg).selectOptions();
											}						
												
										},
										error: function(msg){
											$("#cbduree").attr("disabled","true");
										}
									});	
							},
							error: function(msg){
								$("#cbcomp").attr("disabled","true");
							}
						
						});
						},					
					error: function(msg){
						
					}
				});
					},					
					error: function(msg){
						$("#cbdest").attr("disabled","true");
						$("#cbdate").attr("disabled","true");
					}
				});
	
				//recharger le combo date
				$('#cbdest').change(
					function(dest){	
						$('.loading2').css("display","block");
						$('.loading3').css("display","block");
						$('.loading4').css("display","block");	
						$('#bt_rech').css("visibility","hidden");
						$('#cbdate').empty().append('');
						$('#cbcomp').empty().append('');
						$('#cbduree').empty().append('');
							
						//Recuperation premiere date 
						$.ajax({
							type: "POST",
							url: '/proxy.php',
							data: {what:'comboSearchDate', dest: $('#cbdest').val(), luxe:1},
							success: function(msg){
								if(msg.length>0){
									var dateEnCours=msg;
								}							
								$.ajax({
									type: "POST",
									url: '/proxy.php',
									data: { what: 'comboDate', dest: $('#cbdest').val(), date_en_cours:dateEnCours, luxe:1},
									success: function(msg){
										if(msg.length>0){												
											$('.loading2').css("display","none");
											if(document.all) $('#cbdate').empty().append(msg);
											else $('#cbdate').empty().append(msg).selectOptions(dateEnCours);
										}
										//recharger le combo comp	
										$.ajax({
											type: "POST",
											url: '/proxy.php',
											data: {what: 'comboComp', dest: $('#cbdest').val(),depart:$('#cbdate').val(), luxe:1},
											success: function(msg){
												if(msg.length>0){
													$('.loading3').css("display","none");
													if(document.all) $('#cbcomp').empty().append(msg);
													else $('#cbcomp').empty().append(msg).selectOptions();
												}									
												
												$.ajax({
													type: "POST",
													url: '/proxy.php',
													data: {what: 'comboDuree', dest: $('#cbdest').val(),depart:$('#cbdate').val(),prix: $('#cbprix').val(), comp:$('#cbcomp').val(), luxe:1},
													success: function(msg){
													if(msg.length>0){
														$('.loading4').css("display","none");
														if(document.all) $('#cbduree').empty().append(msg);
														else $('#cbduree').empty().append(msg).selectOptions();
													}
											},
											error: function(msg){												
												$("#cbduree").attr("disabled","true");												
											}
									});
								},
								error: function(msg){											
									$("#cbcomp").attr("disabled","true");
								}
							});
							},
								error: function(msg){
									$("#cbdest").attr("disabled","true");
									$("#cbdate").attr("disabled","true");
								}					
							});
						},
						error: function(msg){
											
						}
			  		});			
				} );
				
				//recharger le combo comp
				$('#cbdate').change(
					function(date){
						$('.loading3').css("display","block");
						$('.loading4').css("display","block");	
						$('#bt_rech').css("visibility","hidden");
						$('#cbcomp').empty().append('');
						$('#cbduree').empty().append('');
						//recharger le combo comp	
						$.ajax({
							type: "POST",
							url: '/proxy.php',
							data: {what: 'comboComp', dest: $('#cbdest').val(),depart:$('#cbdate').val(), luxe:1},
							success: function(msg){
								if(msg.length>0){
									$('.loading3').css("display","none");
									if(document.all) $('#cbcomp').empty().append(msg);
									else $('#cbcomp').empty().append(msg).selectOptions();
								}
								$.ajax({
									type: "POST",
									url: '/proxy.php',
									data: {what: 'comboDuree', dest: $('#cbdest').val(),depart:$('#cbdate').val(),prix: $('#cbprix').val(), comp:$('#cbcomp').val(), luxe:1},
									success: function(msg){
										if(msg.length>0){
											$('.loading4').css("display","none");
											if(document.all) $('#cbduree').empty().append(msg);
											else $('#cbduree').empty().append(msg).selectOptions();
										}
									},
									error: function(msg){
										$("#cbduree").attr("disabled","true");
									}
								});									
							},
							error: function(msg){
								$("#cbcomp").attr("disabled","true");
							}
						});
					});	
				//recharger le combo prix
				$('#cbcomp').change(
					function(comp){	
						if(document.getElementById("check").value == "avance"){	
							$('.loading4').css("display","block");	
							$('#bt_rech').css("visibility","hidden");
						}							
						$('#cbduree').empty().append('');								
							$.ajax({
								type: "POST",
								url: '/proxy.php',
								data: {what: 'comboDuree', dest: $('#cbdest').val(),depart:$('#cbdate').val(),prix: $('#cbprix').val(), comp:$('#cbcomp').val(), luxe:1},
								success: function(msg){
									if(msg.length>0){
										$('.loading4').css("display","none");
										if(document.all) $('#cbduree').empty().append(msg);
										else $('#cbduree').empty().append(msg).selectOptions();
									}
								},
								error: function(msg){
									$("#cbduree").attr("disabled","true");
								}
							});
					});	
			},
			
			error: function(msg){
				$("#cbdest").attr("disabled","true");
				$("#cbdate").attr("disabled","true");
				$("#cbcomp").attr("disabled","true");
				$("#cbduree").attr("disabled","true");
			}
			
		});
		
		$('#cbduree').ajaxStop(function(){ 				
				$('#bt_rech').css("visibility","visible");					
		});
	
	});
}


function affiche_promo(){
$(document).ready(function(){ 		
		$.ajax({
			type: "POST",
			url: '/proxy.php',
			data: {what: 'promoIndex'},
			success: function(msg){
				if(msg.length>0){
					$('#indexPromo').empty().append(msg);
				}
			},
			error: function(msg){
				$("#indexPromo").attr("disabled","true");
			}
		});
	});	
}

function recherche_avancer_comp(txtAvance, txtMoin)
	{	
		if(document.getElementById("cache_0").style.display == "block")
		{
			
			document.getElementById("cache_0").style.display = "none";
			document.getElementById("cache_1").style.display = "none";
			document.getElementById("recherche_avance").title = txtAvance;
			document.getElementById("recherche_avance").innerHTML = txtAvance;
			document.getElementById("check").value = "moin_avance";
		}
		else
		{
				
			document.getElementById("cache_0").style.display = "block";
			document.getElementById("cache_1").style.display = "block";
			document.getElementById("recherche_avance").title = txtMoin;
			document.getElementById("recherche_avance").innerHTML = txtMoin;
			document.getElementById("check").value = "avance";
		}	
	}

//Moteur compagnie

//fonction à insérer dans les différents templates v2
//param: valeur de la destination par defaut pour la selection par defaut du moteur
//param: compagnie
function load_document_in_comp(dest_par_defaut , comp)
{
	$(document).ready(function(){
		load_news_letter();
		//charge dynamiquement le combo dest de moteur
		$.ajax({
			type: "POST",
			url: '/proxy.php',
			data: {what:'comboDest' , comp:comp},
			success: function(msg){
				if(msg.length>0)
				{
					if(document.all) $('#cbdest').empty().append(msg);
					else $('#cbdest').empty().append(msg).selectOptions(dest_par_defaut);
				}
	
				//charge dynamiquement le combo date lors de l'affichage de la page
				$.ajax({
					type: "POST",
					url: '/proxy.php',
					data: {what: 'comboDate',  dest: $('#cbdest').val() , comp:comp},
					success: function(msg){
						if(msg.length>0)
						{
							if(document.all) $('#cbdate').empty().append(msg);
							else $('#cbdate').empty().append(msg).selectOptions();
						}
					},
					error: function(msg){
						//alert('erreur 34');
						$("#cbdest").attr("disabled","true");
						$("#cbdate").attr("disabled","true");
					}
				});
	
				//si on change la dest, on recharge le combo date
				$('#cbdest').change(
				function(dest)
				{
					$.ajax({
						type: "POST",
						url: '/proxy.php',
						data: { what: 'comboDate', dest: $('#cbdest').val() , comp:comp },
						success: function(msg){
						if(msg.length>0)
						{
							if(document.all) $('#cbdate').empty().append(msg);
							else $('#cbdate').empty().append(msg).selectOptions();
						}
						},
						error: function(msg){
							//alert('erreur 344');
							$("#cbdest").attr("disabled","true");
							$("#cbdate").attr("disabled","true");
						}
					});
				} );
			},
			error: function(msg){
				//alert('erreur de chargement du moteur');
				$("#cbdest").attr("disabled","true");
				$("#cbdate").attr("disabled","true");
			}
		});
	
	});
}

	function load_document_promotion_croisiere(dest_par_defaut,comp)
	{
		
		$(document).ready(function(){
		load_news_letter();		
				//charge dynamiquement le combo dest de moteur
	$.ajax({
		type: "POST",
		url: '/proxy.php',
		data: {what:'comboDest', comp:comp, promo:1},
		success: function(msg){
			if(msg.length>0)
			{
				if(document.all) $('#cbdest').empty().append(msg);
				else $('#cbdest').empty().append(msg).selectOptions(dest_par_defaut);
			}

			//charge dynamiquement le combo date lors de l'affichage de la page
			$.ajax({
				type: "POST",
				url: '/proxy.php',
				data: {what: 'comboDate',  dest: $('#cbdest').val(), comp:comp, promo:1},
				success: function(msg){
					if(msg.length>0)
					{
						if(document.all) $('#cbdate').empty().append(msg);
						else $('#cbdate').empty().append(msg).selectOptions();
					}
				},
				error: function(msg){
					//alert('erreur sur la moteur de recherche');
					$("#cbdest").attr("disabled","true");
					$("#cbdate").attr("disabled","true");
				}
			});

			//si on change la dest, on recharge le combo date
			$('#cbdest').change(function(dest){
				$.ajax({
					type: "POST",
					url: '/proxy.php',
					data: { what: 'comboDate', dest: $('#cbdest').val(), comp:comp, promo:1},
					success: function(msg){
						if(msg.length>0)
					{
						if(document.all) $('#cbdate').empty().append(msg);
						else $('#cbdate').empty().append(msg).selectOptions();
					}
					},
					error: function(msg){
						//alert('erreur sur la moteur de recherche: PAS DE DESTINATION');
						$("#cbdest").attr("disabled","true");
						$("#cbdate").attr("disabled","true");
					}
				});
			})
		},
		error: function(msg){
			//alert('erreur de chargement du moteur');
			$("#cbdest").attr("disabled","true");
			$("#cbdate").attr("disabled","true");
		}
								   
			});
	 });
		
	
	}
function load_document_promotion(dest_par_defaut)
{
	
		
		$(document).ready(function(){
		load_news_letter();		
				//charge dynamiquement le combo dest de moteur
	$.ajax({
		type: "POST",
		url: '/proxy.php',
		data: {what:'comboDest',  promo:1},
		success: function(msg){
			if(msg.length>0)
			{
				if(document.all) $('#cbdest').empty().append(msg);
				else $('#cbdest').empty().append(msg).selectOptions(dest_par_defaut);
			}

			//charge dynamiquement le combo date lors de l'affichage de la page
			$.ajax({
				type: "POST",
				url: '/proxy.php',
				data: {what: 'comboDate',  dest: $('#cbdest').val(),  promo:1},
				success: function(msg){
					if(msg.length>0)
					{
						if(document.all) $('#cbdate').empty().append(msg);
						else $('#cbdate').empty().append(msg).selectOptions();
					}
				},
				error: function(msg){
					//alert('erreur sur la moteur de recherche');
					$("#cbdest").attr("disabled","true");
					$("#cbdate").attr("disabled","true");
				}
			});

			//si on change la dest, on recharge le combo date
			$('#cbdest').change(function(dest){
				$.ajax({
					type: "POST",
					url: '/proxy.php',
					data: { what: 'comboDate', dest: $('#cbdest').val(), promo:1},
					success: function(msg){
						if(msg.length>0)
					{
						if(document.all) $('#cbdate').empty().append(msg);
						else $('#cbdate').empty().append(msg).selectOptions();
					}
					},
					error: function(msg){
						//alert('erreur sur la moteur de recherche: PAS DE DESTINATION');
						$("#cbdest").attr("disabled","true");
						$("#cbdate").attr("disabled","true");
					}
				});
			})
		},
		error: function(msg){
			$("#cbdest").attr("disabled","true");
			$("#cbdate").attr("disabled","true");
		}
								   
			});
	 });
		
	
	
}
function pop_up_pays_sa(cache,url){ 
	$.ajax({
		type: "POST",
		url: '/pop_up_pays_sa.php',
		data: {what:'paysSA'},
		success: function(msg){
			if(msg==1){
				if(cache=="video"){ 
					$('#pop_pays_sa').jqm({ajax: '/pop_up_pays_sa.php?what=affiche&cache=video&url='+url, modal: true}).jqmShow();						
				}
				else
				{ 
					$('#pop_pays_sa').jqm({ajax: '/pop_up_pays_sa.php?what=affiche&url='+url, modal: true}).jqmShow();
				}
			}			
		},	
		error: function(msg){
				//alert('Erreur');
		}
	});
}
function pop_up_pays_sa_new(cache){ 
	$.ajax({
		type: "POST",
		url: '/../pop_up_pays_sa.php',
		data: {what:'paysSA'},
		success: function(msg){
			if(msg.length>0 && msg=="oui"){ 
				if(cache=="video"){
					$('#pop_pays_sa').jqm({ajax: '/../pop_up_pays_sa.php?what=affiche&cache=video', modal: true}).jqmShow();						
				}
				else
					$('#pop_pays_sa').jqm({ajax: '/../pop_up_pays_sa.php?what=affiche', modal: true}).jqmShow();
			}			
		},	
		error: function(msg){
				//alert('Erreur');
		}
	});
}


