﻿// JavaScript Document
var object;
/**
 * check that javascript is activated and manager error for each call of
 * javascript menu *
 */
function call(to_call) {

	eval(to_call);
}
/** check the type of the flight Aller/retour * */
function CheckVolType() {
	if ($('#flightsSingleTicket').attr("checked") == true)
		$('#flightsBackDate').attr("disabled", true);
	else
		$('#flightsBackDate').attr("disabled", false);

}

function showMenu(id) {
	if (id != "menu_prod")
		$('menu_prod').hide();
	if (id != "menu_params")
		$('menu_params').hide();
	if (id != "menu_global")
		$('menu_global').hide();
	if (id != "")
		$(id).show();

	Set_Cookie("menu", id, 500);
}
function Set_Cookie(name, value, expires, path, domain, secure) {
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime(today.getTime());

	/*
	 * if the expires variable is set, make the correct expires time, the
	 * current script below will set it for x number of days, to make it for
	 * hours, delete * 24, for minutes, delete * 60 * 24
	 */
	if (expires) {
		expires = expires * 1000 * 60 * 24;
	}
	var expires_date = new Date(today.getTime() + (expires));
	
	document.cookie = name + "=" + escape(value)
			+ ((expires) ? ";expires=" + expires_date.toGMTString() : "")
			+ ((path) ? ";path=" + path : "")
			+ ((domain) ? ";domain=" + domain : "")
			+ ((secure) ? ";secure" : "");

}
function Get_Cookie(check_name) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split(';');
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for (i = 0; i < a_all_cookies.length; i++) {
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split('=');

		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if (cookie_name == check_name) {
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no =
			// sign, that is):
			if (a_temp_cookie.length > 1) {
				cookie_value = unescape(a_temp_cookie[1].replace(/^\s+|\s+$/g,
						''));
			}
			// note that in cases where cookie is initialized but no value, null
			// is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if (!b_cookie_found) {
		return null;
	}
}

function ShowSerie(num, m) {
	// try
	// {
	if ($('#prec_F').val() == "serie" + num)
		return;
	$('#serie' + num).show();
	divtohide = "#" + $('#prec_F').val();
	$(divtohide).hide();
	$(divtohide).addClass("hide");
	$('#prec_F').val('serie' + num);
	// $('linkserie' + num).class= "current";
	for (i = 1; i <= m; i++) {
		$('#liserie' + i).html(
				$('#liserie' + i).html().replace("class=\"current\"", ""));
	}
	$('#liserie' + num).html(
			$('#liserie' + num).html()
					.replace("href", "class=\"current\" href"));
	// }catch ()
	// {
	// alert("error");
	// }

}
function allowNext() {

	$('#next')
			.html(
					'<a href="#" onclick="showNext();return false;">Vols suivants&nbsp;&nbsp;&nbsp; >> </a>&nbsp;&nbsp; </li></ul>');
	$('#type_current').val('next');
}

function allowPrevious() {

	if ($('#previousflight').html().indexOf("ERROR") != -1) {
		$('#previous')
				.html(
						'<p class="content"><a href="#" onclick="return false;">XX&nbsp;&nbsp;&nbsp; Vols pr&eacute;c&eacute;dents</a>&nbsp;&nbsp; </p>');

	} else
		$('#previous')
				.html(
						'<p class="content"><a href="#" onclick="showPrevious();return false;"><<&nbsp;&nbsp;&nbsp; Vols pr&eacute;c&eacute;dents</a>&nbsp;&nbsp; </p>');
	$('#type_current').val('previous');

}
function runnext() {

	// eval($('remote_next').value);
}
function showNext() {
	effectshownext();
	// new Effect.Highlight($('results'), { startcolor: '#ffff99', endcolor:
	// '#ffffff' });return false;

}
function effectshownext() {
	
	temp = $(".pagination #next a").html();
	$(".pagination #next a").html(
			'<img src="/images/indicator_medium.gif" id="nextbutton" />');
	$('#results').html($('#nextflight').html().replace(/__a__/g, ""));

	$('#nextflight').html("");
	// lert($('#remote_next').val());
	eval($('#remote_next').val().replace("current_choice", "next_choice"));
	// alert($('#remote_previous').val());

	eval($('#remote_previous').val());
	$(".pagination #next a").html(temp);
}
function showPrevious() {
	if ($('#previousflight').html() == "___ERROR") {

		alert("Il n'y a pas de vol précédent");
		return;
	}
	eval($('#remote_next').val());
	eval($('#remote_previous').val().replace("current_choice",
			"previous_choice"));
	$('#results').html($('#previousflight').html().replace(/__a__/g, ""));
	$('#previousflight').html("");

}

function showFilter(url) {

	if ($('filter_content_status').innerHTML != "")
		return;
	if ($('button_show_filter').src.indexOf("plus.gif") > 0) {

		Effect.SlideDown('filter_content', {
			duration :1.0
		});

		$('button_show_filter').src = "/images/minus.gif";
	} else {
		Effect.SlideUp('filter_content', {
			duration :1.0
		});
		$('button_show_filter').src = "/images/plus.gif";
	}
}

function validatePassagers(id) {

	total = $('total_pass').value;
	valid = true;
	for (i = 0; i < total; i++) {

		if ($('nom_' + i).value == "") {
			$('nom_' + i + 'Error').style.display = "inline";
			valid = false;
		} else
			$('nom_' + i + 'Error').style.display = "none";

		if ($('prenom_' + i).value == "") {
			$('prenom_' + i + 'Error').style.display = "inline";
			valid = false;
		} else
			$('prenom_' + i + 'Error').style.display = "none";
		if ($('annif_' + i).value == "") {
			$('annif_' + i + 'Error').style.display = "inline";
			valid = false;
		} else
			$('annif_' + i + 'Error').style.display = "none";
	}
	return valid;
}
function updatePriceAssurance() {
	base = parseInt($('#base').val());
	if ($('#receptionMail:checked').length != 0)
		base += parseInt($('#receptionMail_price').val());
	if ($('#insuranceMulti:checked').length != 0)
		base += parseInt($('#insuranceMulti_price').val());
	if ($('#insuranceCancel:checked').length != 0)
		base += parseInt($('#insuranceCancel_price').val());
	if ($('#insuranceNone:checked').length != 0)
		base += parseInt($('#insuranceNone_price').val());
	$('#total_price').html(base + " € ttc");
	$('#total').val(base);
}

function checkRooms(element) {
	nb = $("#" + element.id).val();
	prev = $('#previous_room').val();
	$('#previous_room').val(nb);

	$('#hotelsAdults2').show();
	$('.people').height(50 + (nb * 10))

	for (i = 2; i <= 5; i++) {

		if (i <= nb) {
			if (prev < i) {
				$('#hotelsAdults' + i).show();

				$('#hotelsBabes' + i).show();

				$('#hotelsKids' + i).show();
				$('#brHA' + i).show();
				$('#brHK' + i).show();
				$('#brHB' + i).show();
				$('#hotelsAdults' + i).fadeTo("slow", 1);
				$('#hotelsKids' + i).fadeTo("slow", 1);
				$('#hotelsBabes' + i).fadeTo("slow", 1);
			}

		} else {
			if (prev >= i) {
				$('#hotelsAdults' + i).fadeTo("slow", 0);
				$('#hotelsKids' + i).fadeTo("slow", 0);
				$('#hotelsBabes' + i).fadeTo("slow", 0);

				$('#hotelsBabes' + i).hide();
				$('#hotelsAdults' + i).hide();
				$('#hotelsKids' + i).hide();
				$('#brHA' + i).hide();
				$('#brHK' + i).hide();
				$('#brHB' + i).hide();
			}
		}
	}
}

function updateHotels(laid) {
	prev = $('current_hotel').value;
	$('current_hotel').value = laid;

	$('icon' + laid).src = $('icon' + laid).src.replace("chevrons", "down");
	$('hlt_' + prev).innerHTML = "";
	$('icon' + prev).src = $('icon' + laid).src.replace("down", "chevrons");

}

function checkMax(val) {
	$('#back').val(val);
	return true;
	adults = parseInt($('volAdults').value);
	childs = parseInt($('volKids').value);
	babe = parseInt($('volBabes').value);
	if ((adults + childs + babe) == 0) {
		alert("Veuillez choisir le nombre de passager");
		return false;
	}

	return true;
	maxi = parseInt($('max').value);

	if ((adults + childs + babe) > maxi) {
		alert("Il n'y a pas assez de place disponible");
		return false;
	}
	return false;

}
function submitcar(id) {
	$('#submit_' + id).click();
}
function checkMaxi(id) {
	adults = parseInt($('#adultes_' + id).val());
	childs = parseInt($('#enfants_' + id).val());
	babe = parseInt($('#bebes_' + id).val());

	if ((adults + childs + babe) == 0) {
		alert("Veuillez choisir le nombre de passager");
		return false;
	}
	return true;
	error = validateForm(id);

	if (!error)
		return false;
	error = 0;
	if ($('single_' + id).value > $('maxS_' + id).value)
		error = 1;
	if ($('double_' + id).value > $('maxD_' + id).value)
		error = 1;
	if ($('triple_' + id).value > $('maxT_' + id).value)
		error = 1;
	$('submit_' + id).click();
	if (error) {
		alert("Il n'y a pas assez de place disponible");
		return false;
	}
	$('submit_' + id).click();
	return false;

}

function ShowDetail(elem, id) {
	if (elem.value == 0)
		return;
	$('current_count').value = elem.value;
	$('current_type').value = elem.id.substr(0, 6);
	$('current_id').value = id;
	$('details' + id).href = "/offres/pax/nb/" + elem.value + ".html";

	return hs.htmlExpand($('details' + id), {
		objectType :'ajax',
		preserveContent :false,
		cacheAjax :false,
		width :600,
		height :200,
		align :'center'
	})

}
function ShowDetailOffre(elem, type) {
	if (elem.value == 0)
		return;
	$('current_count').value = elem.value;
	$('current_type').value = type.substr(0, 1);
	$('current_id').value = elem.id;
	$('details_' + type).href = "/offres/pax/nb/" + elem.value + ".html";

	return hs.htmlExpand($('details_' + type), {
		objectType :'ajax',
		preserveContent :false,
		cacheAjax :false,
		width :600,
		height :200,
		align :'center'
	})
	// return hs.htmlExpand($('details_'+type), { objectType: 'ajax',
	// preserveContent: false, cacheAjax: false, width: 600, height:200, align:
	// "center" } )

}
function ValidateDetail() {
	count = $('current_count').value;
	type = $('current_type').value;
	details = "";
	for (i = 1; i <= count; i++) {
		if (type == "single") {
			if ((parseInt($('ads_' + i).value) + parseInt($('kids_' + i).value) + parseInt($('bab_' + i).value)) > 1) {
				alert("une chambre single, ne peut contenir qu'une personne");
				return;
			}
		} else if (type == "double") {

			if ((parseInt($('ads_' + i).value) + parseInt($('kids_' + i).value)) > 2
					|| parseInt($('bab_' + i).value) > 2) {

				alert("une chambre double, ne peut contenir que deux personnes");
				return;
			}
		} else if (type == "triple") {

			if ((parseInt($('ads_' + i).value) + parseInt($('kids_' + i).value)) > 3
					|| parseInt($('bab_' + i).value) > 2) {

				alert("une chambre triple, ne peut contenir que trois personnes");
				return;
			}
		}
	}
	for (i = 1; i <= count; i++) {

		details += $('ads_' + i).value + "-";
		details += $('kids_' + i).value + "-";
		details += $('bab_' + i).value + "-";
		details += ";"
	}
	id = $('current_id').value;
	tid = (type.substr(0, 1)).toUpperCase();
	if ($('page').value == "offre")
		$('details_' + tid).value = details;
	else
		$('details_' + tid + "_" + id).value = details;
	return hs.close();
}
function validateForm(id) {
	if ($('details_S_' + id).value == "" && $('details_D_' + id).value == ""
			&& $('details_T_' + id).value == "") {
		alert("veuillez faire votre choix des chambres");
		ShowDetail($('single_' + id), id);
		return false;
	}
	return true;
}
function checkAccept(value) {

	if ($('#acceptCGV:checked').length == 0) {
		alert("Veuillez accepter les conditions générales de ventes");
		return false;
	}
	return true;
}
function adaptTotal(elem) {
	if ($(elem.id).checked) {
		val = parseInt($('#total_hotel').html());
		$('#total_hotel').html(val + parseInt(elem.val()));
	} else {
		val = parseInt($('#total_hotel').html());
		$('#total_hotel').html(val - parseInt(elem.val()));
	}
	$('base').value = $('total_hotel').innerHTML;
	updatePriceAssurance();
}
try {
	jQuery.extend(jQuery.validator.messages, {
		required :"",
		email :""
	});

} catch (s) {
}

$(document).ready( function() {

	try {
		$("#passengers").validate( {
			errorContainer :"#errornew"

		});

		jQuery.validator.addMethod("dateadults", function(value, element) {
			var today = Date.today().addYears(-12);
			if (today.compareTo(Date.parse(value)) < 0)
				return false;
			return true;
		}, "");
		jQuery.validator.addMethod("dateenfant", function(value, element) {
			var today = Date.today().addYears(-12);
			if (today.compareTo(Date.parse(value)) > 0)
				return false;
			return true;
		}, "");
		jQuery.validator.addMethod("datebebe", function(value, element) {
			var today = Date.today().addYears(-2);
			if (today.compareTo(Date.parse(value)) > 0)
				return false;
			return true;
		}, "");

	} catch (e) {
	}
		if($("#promo").length>0)
		{
				$.superbox.settings = {
					afterShow: function ()
				   {


				$("#superbox-wrapper .chicklet").each(function ()
				{
					id = $(this).attr("id");
					$(this).attr("id","super_"+id);
				});
				$("#superbox-wrapper #partager").after('<a name="fb_share" type="button_count" share_url="http://www.facebook.com/event.php?eid=143450642350604#!/event.php?eid=143450642350604" href="http://www.facebook.com/sharer.php">Partager</a>');

FB.Share._onFirst();
		$(".etRec").bind("click",displayRecommand);
	$("#superbox-wrapper .friend").validate({
	 submitHandler: function(form) {
   		$("#superbox-wrapper form").ajaxSubmit();
		$("#superbox-wrapper .friend").html("Merci");
		$(".etMainPromoPic").removeClass("pr_height_small");
 	  },
	  invalidHandler: function(form, validator) {
      var errors = validator.numberOfInvalids();
      if (errors) {
		alert("Veuillez encoder des emails valides");
      }
	  alert("Erreur");
	  
    }
	
	});
					
				   }
			};

		$.superbox();

		}

});
function submitIt()
{

	$("#superbox-wrapper .friend").validate({
	 submitHandler: function(form) {
   		$(form).ajaxSubmit();
		$("#superbox-wrapper .friend").html("Merci");
 	  },
	  invalidHandler: function(form, validator) {
      var errors = validator.numberOfInvalids();
      if (errors) {
		alert("Veuillez encoder des emails valides");
      }
	  alert("Erreur");
	  
    }
	
	});

return false;
}
function displayRecommand()
{
	$(".etMainPromoPic").addClass("pr_height_small");
	$("#superbox-wrapper #sendToAFriend").removeClass("hidden");
}

$(document).ready( function() {
	try {
		$("#authForm").validate( {
			errorContainer :"#errorauth",
			rules : {
				logemail : {
					required :true,
					email :true
				},
				logpassword : {
					required :true
				}
			},
			messages : {
				required :""
			}

		});
	} catch (e) {
	}

});

$(document).ready( function() {
	try {
		$("#newForm").validate( {
			errorContainer :"#errornew",
			rules : {
				nom : {
					required :true
				},
				ville : {
					required :true
				},
				prenom : {
					required :true
				},
				codepostal : {
					required :true
				},
				email : {
					required :true,
					email :true
				},
				pays : {
					required :true
				},
				adresse : {
					required :true
				},
				mobile : {
					required :true
				},
				tel : {
					required :true
				},
				password : {
					required :true,
					minlength :6

				},
				confirmation : {
					required :true,
					equalTo :"#password"
				}
			},
			messages : {
				nom :"",
				ville :"",
				prenom :"",
				codepostal :"",
				password :"",
				confirmation :"",
				email :"",
				adresse :"",
				tel :"",
				mobile :"",
				pays :""
			}
		});
	} catch (e) {

	}
});

$(document)
		.ready(
				function() {
					try {
						$("form")
								.bind(
										"invalid-form.validate",
										function(e, validator) {
											var errors = validator
													.numberOfInvalids();

											if (errors) {
												var message = errors == 1 ? '1 champ n\'a pas été rempli correctement. Il a été mis en surbrillance'
														: errors + ' champs n\'ont pas été remplis correctement.  ils ont été mis en surbrillance';
												$("div.error span").html(
														message);

											} else {
												$("div.error").hide();
											}
										});
					} catch (e) {

					}
				});

$(document).ready( function() {
	try {
		$("#paypervisa").click( function() {
			$("#payperphone").hide();
			$("#topay").show();
		});
	} catch (e) {

	}
});

function updatePrice(date_id) {

	adultes = $('#adultes_' + date_id).val();
	// adultes = adultes[$('adultes_' & date_id).selectedIndex].value;
	enfants = $('#enfants_' + date_id).val();
	bebes = $('#bebes_' + date_id).val();
	$.ajax( {
		type :"POST",
		url :'/offres/pricepax/date_id/' + date_id + '/adultes/' + adultes
				+ '/enfants/' + enfants + '/bebes/' + bebes + '.html',
		success : function(value) {
			if (value.substr(0, 1) != "0") {
				$("#total_euro").html(value);
				$("#apartirde").html("Total");
			} else {
				$("#total_euro").html($("#base_euro").html());
				$("#apartirde").html("par pers.");
			}
			$("#total_euro").highlightFade();

		}

	});
}
