
$(document).ready(function() {
	
	$.abonnement = function(){
		if($("#email").isMail()){
			
			$.ajax({
			   type: "POST",
			   url: "ajax/newsletter.cfm",
			   data: "TypeNewsletter=1&email=" + $("#email").val(),
			   dataType: "html",
			   cache: false,
			   beforeSend : function(){
					$("#idIndicator").css("display","");
					$("#idIndicator").html('<img src="images/indicator.gif" alt="indicator" border="0"> Inscription en cours');
				},
			   success: function(){
				 $("#email").css("backgroundColor","white");
				 $("#idIndicator").html('');
				 $("#idIndicator").css("display","none");
				 alert(unescape("Votre inscription a %E9t%E9 effectu%E9e avec succ%E8s"));
			   },
			   error: function(){
				 alert( "inscription KO" );
				 $("#idIndicator").html('');
				 $("#idIndicator").css("display","none");
			   }
			 });
		}else{
			$("#email").css("background", "red");
			alert(msgMailIncorrect);
		}
	};
	
	$(document).keypress(function(e){
		if(e.which == 13){ // 'Enter' keypad
			currentEmail = $("#email").attr("value");
			$.abonnement();
			//$("#email").attr("value",currentEmail);
			$("#email").blur();
			return false;
		}							  
	});
	
	$("#btnNewsletter").click(function(){ 
		$.abonnement();
	});
	
	
	
	$("#btnDesabonne").click(function(){ 
		if($("#email").isMail()){
			$.ajax({
			   type: "POST",
			   url: "ajax/newsletter.cfm",
			   data: "TypeNewsletter=0&email=" + $("#email").val(),
			   dataType: "html",
			   cache: false,
			   beforeSend : function(){
					$("#idIndicator").css("display","");
					$("#idIndicator").html('<img src="images/indicator.gif" alt="indicator" border="0"> Desinscription en cours');
				},
			   success: function(){
				 $("#idIndicator").html('');
				 $("#idIndicator").css("display","none");
				 alert( unescape("Votre d%E9sinscription a %E9t%E9 effectu%E9e avec succ%E8s") );
				},
				error: function(){
					 alert( "d%E9sinscription KO" );
					 $("#idIndicator").html('');
				 	 $("#idIndicator").css("display","none");
				}
			 });
		}else{
			$("#email").css("background", "red");
			alert(msgMailIncorrect);
		}
	});
	
	$("#aLeftToHome").hover(function(){
		$(this).css("cursor","pointer");				  
	});
	$("#aLeftToHome").click(function(){
		resetEngine();
		
		var currentPageLeft = $.trim($("#currentPage").attr("value"));
		if(currentPageLeft.toLowerCase().indexOf("index") >= 0){
			resetEngineInterface();
		}
		else{
			if($("#pays").attr("value") != undefined)
				window.location.href = $("#pays").attr("value").toLowerCase() + '_index.html';
			else
				window.location.href = 'index.cfm';
		}
	});
	
	$("a[id^='aPrestationLeft_']").click(function(){
		typePrestation = $(this).attr("id").split("_")[1];
		$("#idTypePrestationFromLeft").attr("value",typePrestation);
		var nomPrestation = $.trim($(this).html());
		$("#nomPrestation").attr("value",nomPrestation);
		SetCookie("checkTransport",0);
		SetCookie("checkHotel",0);
		SetCookie("checkVoiture",0);
		SetCookie("checkAutre",1);
		SetCookie("atTypePrestation",typePrestation);
		//return ;
		var currentPage = $.trim($("#currentPage").attr("value"));
		
		SetCookie("AllerRetour1",1);
		SetCookie("AllerRetour0",0);
		//$("#tr_DateRetour").css("display","");
		SetCookie("trVilleDepart",0);
		SetCookie("trVilleArrive",0);
		SetCookie("trDateDepart","");
		SetCookie("trDateRetour","");
		SetCookie("trNbAdulte",2);
		SetCookie("trNbEnfant",0);
		SetCookie("trNbBebe",0);
		SetCookie("trClasseConfort",0);
		
		//Hotel
		SetCookie("HtRegion",0);
		SetCookie("HtVille",0);
		SetCookie("HtDateDepart","");
		SetCookie("HtNbNuit",7);
		SetCookie("HtCategorieHotel",0);
		SetCookie("HtNbChambre",1);
		SetCookie("HtNbAdulte1",2);
		SetCookie("HtNbEnfant1",0);
		SetCookie("HtNbBebe1",0);
		/*$("#idLigneCh2").css("display","none");
		$("#idLigneCh3").css("display","none");*/
		SetCookie("HtNbAdulte2",2);
		SetCookie("HtNbEnfant2",0);
		SetCookie("HtNbBebe2",0);
		SetCookie("HtNbAdulte3",2);
		SetCookie("HtNbEnfant3",0);
		SetCookie("HtNbBebe3",0);
		
		//Voiture
		SetCookie("vtVille",0);
		SetCookie("vtDateDepart","");
		SetCookie("vtDuree",7);
		
		
		SetCookie("atRegion",0);
		SetCookie("atDateDepart","");
		SetCookie("atNbAdulte",2);
		SetCookie("atNbEnfant",0);
		SetCookie("atNbBebe",0);
		SetCookie("labelAutrePrestation",nomPrestation);
		var newContent = $("#autreNomPrestation").clone(true);
		newContent.attr("value",nomPrestation);
		
		newTypePrestation = "<input type=hidden name=atTypePrestation id=atTypePrestation value=" + typePrestation + ">";
		SetCookie("spanTypeAutrePrestation",newTypePrestation);

		
		
		if(currentPage.toLowerCase().indexOf("index") >= 0){
			$.loadVilleAT({typePrestation : typePrestation});
			$("#checkTransport").attr("checked","");
			$("#checkHotel").attr("checked","");
			$("#checkVoiture").attr("checked","");
			$("#checkAutre").attr("checked","checked");
			$("#blockTransport").hide();
			$("#blockHotel").hide();
			$("#blockVoiture").hide();
			$("#blockAutre").show();
			$("#labelAutrePrestation").html(nomPrestation);
			
			
			$("#atRegion").attr("value",0);
			$("#atDateDepart").attr("value","");
			$("#atNbAdulte").attr("value",2);
			$("#atNbEnfant").attr("value",0);
			$("#atNbBebe").attr("value",0);
			/*SetCookie("atDateDepart","");
			SetCookie("atNbAdulte",2);
			SetCookie("atNbEnfant",0);
			SetCookie("atNbBebe",0);*/
			//alert(nomPrestation);
			reg=new RegExp(' ', 'g');
			//newContent = "<input type=hidden id=autreNomPrestation name=autreNomPrestation value=" + nomPrestation.replace('&amp;','&') + ">" + nomPrestation;
			//newContent = "<input type=hidden id=autreNomPrestation name=autreNomPrestation value=" + nomPrestation.replace(reg,'&nbsp;') + ">" + nomPrestation;
			$("#titreBlocAutrePrestation").html(newContent);
			$("#titreBlocAutrePrestation").html($("#titreBlocAutrePrestation").html() + nomPrestation);
			SetCookie("titreBlocAutrePrestation",$("#titreBlocAutrePrestation").html());
			
			$("#spanTypeAutrePrestation").html(newTypePrestation);
			if(typePrestation == 276){
				document.location.href = "#myOffreSpecial";
			}else{
				document.location.href = "#myMoteur";	
			}
		}
		else{
			$("#specialContentForTheName").html(newContent);
			$("#specialContentForTheName").html($("#specialContentForTheName").html() + nomPrestation);
			SetCookie("titreBlocAutrePrestation",$("#specialContentForTheName").html());
			SetCookie("atVille",0);
			DeleteCookie("labelAutrePrestation");
			DeleteCookie("titreBlocAutrePrestation");
			DeleteCookie("spanTypeAutrePrestation");
			SetCookie("clickBoutonsLeft", 1);
			
			if(typePrestation == 276){ 
				$("#frmFromLeft").attr("action", $("#pays").attr("value").toLowerCase() + '_index.html?#myOffreSpecial');
			}
			$("#frmFromLeft").submit();		
			
		}
	});
	
});
