var lang_en_link = "images/menu_lang_en.jpg";
var lang_fr_link = "images/menu_lang_fr_ov.jpg";
var lang_sp_link = "images/menu_lang_sp.jpg";
var lang_it_link = "images/menu_lang_it.jpg";
var lang_ge_link = "images/menu_lang_ge.jpg";
var lang_nl_link = "images/menu_lang_nl.jpg";

var nb_days_by_month = new Array();
nb_days_by_month['01'] = 31;
nb_days_by_month['02'] = 29;
nb_days_by_month['03'] = 31;
nb_days_by_month['04'] = 30;
nb_days_by_month['05'] = 31;
nb_days_by_month['06'] = 30;
nb_days_by_month['07'] = 31;
nb_days_by_month['08'] = 31;
nb_days_by_month['09'] = 30;
nb_days_by_month['10'] = 31;
nb_days_by_month['11'] = 30;
nb_days_by_month['12'] = 31;

function $(element_id)
{
	return document.getElementById(element_id);
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function getRadioValue(radio)
{
	for (var i=0; i < radio.length; i++)
	{
		if (radio[i].checked)
			return radio[i].value;
	}
	return 0;
}

function isValidEmail(str)
{
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	return filter.test(str);
}

function isNumeric(sText)
{
	var ValidChars = "0123456789.";
	for (i = 0; i < sText.length; i++)
	{
		if (ValidChars.indexOf(sText.charAt(i)) == -1)
			return false;
	}
	return true;
}

function showWindow(element_id)
{
	$(element_id).style.display = "";
}

function closeConfirmWindow(element_id)
{
	hs.htmlExpand(this, {elementId:'close_alert_window', align:'center'});
}

function closeWindow(element_id)
{
	$(element_id).style.display = "none";
	if ($("google_map"))
		$("google_map").style.display = "none";
	$("background").style.display = "none";
}

function submitWindow(url)
{
	document.location.href = url;
}

function updateCustomTypesDisplay(img_element, housing_id)
{
	if ($('custom_types'+housing_id).style.display == 'none')
	{
		$('custom_types'+housing_id).style.display = '';
		img_element.src = 'images/hide_icon.gif';
	}
	else
	{
		$('custom_types'+housing_id).style.display = 'none';
		img_element.src = 'images/show_icon.gif';
	}
}

function showLanguageTab(tab_id)
{
	$('english_tab').style.display = "none";
	$('french_tab').style.display = "none";
	$('spanish_tab').style.display = "none";
	$('italian_tab').style.display = "none";
	$('german_tab').style.display = "none";
	$('netherland_tab').style.display = "none";
	$(tab_id).style.display = "";
}

function addAccomodationPeriod()
{
	var monthes = new Array();
	monthes[1] = 'Janvier';
	monthes[2] = 'F&eacute;vrier';
	monthes[3] = 'Mars';
	monthes[4] = 'Avril';
	monthes[5] = 'Mai';
	monthes[6] = 'Juin';
	monthes[7] = 'Juillet';
	monthes[8] = 'Aout';
	monthes[9] = 'Septembre';
	monthes[10] = 'Octobre';
	monthes[11] = 'Novembre';
	monthes[12] = 'D&eacute;cembre';

	var index = 0;
	if (document.edit_accomodation.elements["period_id[]"])
	{
		if (document.edit_accomodation.elements["period_id[]"].length)
			index = document.edit_accomodation.elements["period_id[]"].length;
		else
			index = 1;
	}

	var new_div = 	"	<input type=\"hidden\" name=\"period_id[]\" id=\"period_id"+index+"\" value=\"0\" />";
	new_div += 		"	P&eacute;riode du";
	new_div += 		"	<select name=\"period_from_day[]\" id=\"period_from_day"+index+"\">";
	for (var i=1; i<=31; i++)
	{
		var str_i = i;
		if (i < 10)
			str_i = '0'+i;
		new_div +=	"		<option value=\""+str_i+"\">"+i+"</option>";
	}
	new_div += 		"	</select>";
	new_div += 		"	<select name=\"period_from_month[]\" id=\"period_from_month"+index+"\" onchange=\"updateDaysFromMonth('period_from_day"+index+"', this.value)\">";
	for (var i=1; i<=12; i++)
	{
		var str_i = i;
		if (i < 10)
			str_i = '0'+i;
		new_div +=	"		<option value=\""+str_i+"\">"+monthes[i]+"</option>";
	}
	new_div += 		"	</select>";
	new_div += 		"	au";
	new_div += 		"	<select name=\"period_to_day[]\" id=\"period_to_day"+index+"\">";
	for (var i=1; i<=31; i++)
	{
		var str_i = i;
		if (i < 10)
			str_i = '0'+i;
		new_div +=	"		<option value=\""+str_i+"\">"+i+"</option>";
	}
	new_div += 		"	</select>";
	new_div += 		"	<select name=\"period_to_month[]\" id=\"period_to_month"+index+"\" onchange=\"updateDaysFromMonth('period_to_day"+index+"', this.value)\">";
	for (var i=1; i<=12; i++)
	{
		var str_i = i;
		if (i < 10)
			str_i = '0'+i;
		new_div +=	"		<option value=\""+str_i+"\">"+monthes[i]+"</option>";
	}
	new_div += 		"	</select>";
	new_div += 		"	- <a href=\"javascript: void(0);\" onClick=\"hideAccomodationPeriod("+index+")\">Supprimer</a>";

	var new_div_element = document.createElement("div");
	new_div_element.setAttribute("id", "period"+index);
	new_div_element.innerHTML = new_div;
//	$("periods").innerHTML += new_div;
	$("periods").appendChild(new_div_element);
}

function displayAccomodationPeriods()
{
	$("add_period_link").style.display = '';
	addAccomodationPeriod();
}

function hideAccomodationPeriod(index)
{
	$('periods').removeChild($('period'+index));
	if ($('periods').innerHTML.replace(/^\s+|\s+$/g, '') == '')
	{
		document.edit_accomodation.open_whole_year.checked = true;
		$('add_period_link').style.display = 'none';
	}
}

function hideAccomodationPeriods()
{
	$("add_period_link").style.display = 'none';
	$('periods').innerHTML = "";
}


function addAccomodationHousing()
{
	for (var index = 1; index <= 10; index++)
	{
		if ($('housing'+index).style.display == "none")
		{
			displayAccomodationHousing(index);
			break;
		}
	}
}

function displayAccomodationHousing(index)
{
	$('housing'+index).style.display = "";
	eval('document.edit_accomodation.housing'+index+'_active.value = 1');
}

function hideAccomodationHousing(index)
{
	$('housing'+index).style.display = "none";
	eval('document.edit_accomodation.housing'+index+'_active.value = 0');
}

function hideAccomodationHousings()
{
	for (var index = 1; index <= 10; index++)
	{
		$('housing'+index).style.display = "none";
		eval('document.edit_accomodation.housing'+index+'_active.value = 0');
	}
}

function checkHebergement1()
{
	with (document.edit_accomodation)
	{
		if (country.value == -1)
		{
			alert("Veuillez sélectionner un pays...");
			return false;
		}
		if (currency.value == -1)
		{
			alert("Veuillez sélectionner une devise...");
			return false;
		}
		if (!isNumeric(postal_code.value))
		{
			alert("Le code postal doit être composé de chiffres uniquement...");
			postal_code.focus();
			return false;
		}
		if (!isNumeric(baby_age_limit.value))
		{
			alert("L'âge limite pour les bébés doit être composé de chiffres uniquement...");
			baby_age_limit.focus();
			return false;
		}
		if (parseInt(baby_age_limit.value) > 18)
		{
			alert("L'âge limite pour les bébés doit être inférieur à 18 ans...");
			baby_age_limit.focus();
			return false;
		}
		if (!isNumeric(child_age_limit.value))
		{
			alert("L'âge limite pour les enfants doit être composé de chiffres uniquement...");
			child_age_limit.focus();
			return false;
		}
		if (parseInt(child_age_limit.value) > 18)
		{
			alert("L'âge limite pour les enfants doit être inférieur à 18 ans...");
			child_age_limit.focus();
			return false;
		}
		if (!isNumeric(kid_age_limit.value))
		{
			alert("L'âge limite pour les adolescents doit être composé de chiffres uniquement...");
			kid_age_limit.focus();
			return false;
		}
		if (parseInt(kid_age_limit.value) > 18)
		{
			alert("L'âge limite pour les adolescents doit être inférieur à 18 ans...");
			kid_age_limit.focus();
			return false;
		}

		var from_dates = new Array();
		var to_dates = new Array();

		var total = 0;
		if (elements["period_id[]"])
		{
			if (elements["period_id[]"].length)
				total = elements["period_id[]"].length;
			else
				total = 1;
		}
		for (var dates_index=0; dates_index<total; dates_index++)
		{
			from_dates[dates_index] = new Date();
			from_dates[dates_index].setFullYear(2000, $("period_from_month"+dates_index).value - 1, $("period_from_day"+dates_index).value);
			if (from_dates[dates_index].getFullYear() != 2000
			 || from_dates[dates_index].getMonth() != $("period_from_month"+dates_index).value - 1
			 || from_dates[dates_index].getDate() != $("period_from_day"+dates_index).value)
			{
				alert("La date de début de la période n'est pas valide...");
				return false;
			}
			to_dates[dates_index] = new Date();
			to_dates[dates_index].setFullYear(2000, $("period_to_month"+dates_index).value - 1, $("period_to_day"+dates_index).value);
			if (to_dates[dates_index].getFullYear() != 2000
			 || to_dates[dates_index].getMonth() != $("period_to_month"+dates_index).value - 1
			 || to_dates[dates_index].getDate() != $("period_to_day"+dates_index).value)
			{
				alert("La date de fin de la période n'est pas valide...");
				return false;
			}
			if (from_dates[dates_index] >= to_dates[dates_index])
			{
				alert("La date de début de la période doit être antérieure à la date de fin...");
				return false;
			}
		}
		for (var index=0; index<dates_index; index++)
		{
			for (var index2=0; index2<dates_index; index2++)
			{
				if (index == index2) continue;
				if (from_dates[index] <= to_dates[index2] && from_dates[index2] <= to_dates[index])
				{
					alert("Les périodes ne doivent pas se chevaucher...");
					return false;
				}
			}
		}
	}

	return true;
}

function submitHebergement1()
{
	if (checkHebergement1())
	{
		with (document.edit_accomodation)
		{
			$('link_accomodation_name').innerHTML = name.value;
			$('title_accomodation_name').innerHTML = name.value;
			$('menu_accomodation_name'+id.value).innerHTML = name.value;

			var address = address1.value+" "+address2.value+" "+postal_code.value+" "+city.value+" "+country.value;
			var label = "<strong>"+name.value+"</strong><br />"+address1.value+"<br />";
			if (address2.value != "")
				label += address2.value+"<br />";
			if (postal_code.value != "")
				label += postal_code.value+"<br />";
			if (city.value != "")
				label += city.value+"<br />";
			label += country.value;

			gmap_geolocate(address, label);

			var total = 0;
			if (elements["period_id[]"])
			{
				if (elements["period_id[]"].length)
					total = elements["period_id[]"].length;
				else
					total = 1;
			}

			var periods_params = '&nb_periods='+total;
			if (total > 1)
			{
				for (var i=0; i<total; i++)
				{
					periods_params += '&period'+i+'_id='+elements["period_id[]"][i].value;
					periods_params += '&period'+i+'_from_day='+elements["period_from_day[]"][i].value;
					periods_params += '&period'+i+'_from_month='+elements["period_from_month[]"][i].value;
					periods_params += '&period'+i+'_to_day='+elements["period_to_day[]"][i].value;
					periods_params += '&period'+i+'_to_month='+elements["period_to_month[]"][i].value;
				}
			}
			else if (total == 1)
			{
				periods_params += '&period0_id='+elements["period_id[]"].value;
				periods_params += '&period0_from_day='+elements["period_from_day[]"].value;
				periods_params += '&period0_from_month='+elements["period_from_month[]"].value;
				periods_params += '&period0_to_day='+elements["period_to_day[]"].value;
				periods_params += '&period0_to_month='+elements["period_to_month[]"].value;
			}

			display('inner_edit_accomodation', '_includes/fr/manager-config/hebergement2.php',
					'id='+id.value+
					'&secondary_type='+secondary_type.value+
					'&responsible_title='+responsible_title.value+
					'&responsible='+responsible.value+
					'&address1='+address1.value+
					'&address2='+address2.value+
					'&postal_code='+postal_code.value+
					'&city='+city.value+
					'&department='+department.value+
					'&department2='+department2.value+
					'&region='+region.value+
					'&country='+country.value+
					'&currency='+currency.value+
					'&open_whole_year='+open_whole_year.checked+
					'&min_arrival_hour='+min_arrival_hour.value+
					'&min_arrival_minute='+min_arrival_minute.value+
					'&max_arrival_hour='+max_arrival_hour.value+
					'&max_arrival_minute='+max_arrival_minute.value+
					'&baby_age_limit='+baby_age_limit.value+
					'&child_age_limit='+child_age_limit.value+
					'&kid_age_limit='+kid_age_limit.value+
					'&name='+name.value+
					'&new_other_type='+new_other_type.value+
					periods_params
			);
		}
	}
}

function checkHebergement2()
{
	with (document.edit_accomodation)
	{
		if (!isValidEmail(email.value))
		{
			alert("L'adresse email n'est pas valide...");
			email.focus();
			return false;
		}
		for (var i=1; i<=5; i++)
		{
			if ($('active'+i).value == 1)
			{
				if ($('add_email'+i).value == '' || !isValidEmail($('add_email'+i).value))
				{
					alert("L'adresse email n'est pas valide...");
					$('add_email'+i).focus();
					return false;
				}
			}
		}
	}
	return true;
}

function checkHebergement3()
{
	with (document.edit_accomodation)
	{
/*		if (!isNumeric(min_capacity.value))
		{
			alert("La capacité minimum doit être composée de chiffres uniquement...");
			min_capacity.focus();
			return false;
		}
		if (!isNumeric(max_capacity.value))
		{
			alert("La capacité maximum doit être composée de chiffres uniquement...");
			max_capacity.focus();
			return false;
		}
		for (var index = 1; index <= 10; index++)
		{
			if ($('housing'+index).style.display == "" && !eval('isNumeric(housing'+index+'_nb.value)'))
			{
				alert("Le nombre de logement doit être composé de chiffres uniquement...");
				eval('housing'+index+'_nb.focus()');
				return false;
			}
		}*/
	}
	return true;
}

function checkFiche1()
{
	with (document.edit_accomodation)
	{
		if (short_description_en.value.length > 250)
		{
			alert("La description courte ne doit pas dépasser 250 caractères...");
			updateLangMenu('lang_en');
			showLanguageTab('english_tab');
			short_description_en.focus();
			return false;
		}
		if (short_description_fr.value.length > 250)
		{
			alert("La description courte ne doit pas dépasser 250 caractères...");
			updateLangMenu('lang_fr');
			showLanguageTab('french_tab');
			short_description_fr.focus();
			return false;
		}
		if (short_description_es.value.length > 250)
		{
			alert("La description courte ne doit pas dépasser 250 caractères...");
			updateLangMenu('lang_sp');
			showLanguageTab('spanish_tab');
			short_description_es.focus();
			return false;
		}
		if (short_description_it.value.length > 250)
		{
			alert("La description courte ne doit pas dépasser 250 caractères...");
			updateLangMenu('lang_it');
			showLanguageTab('italian_tab');
			short_description_it.focus();
			return false;
		}
		if (short_description_de.value.length > 250)
		{
			alert("La description courte ne doit pas dépasser 250 caractères...");
			updateLangMenu('lang_ge');
			showLanguageTab('german_tab');
			short_description_de.focus();
			return false;
		}
		if (short_description_nl.value.length > 250)
		{
			alert("La description courte ne doit pas dépasser 250 caractères...");
			updateLangMenu('lang_nl');
			showLanguageTab('netherland_tab');
			short_description_nl.focus();
			return false;
		}
	}

	return true;
}

function checkLogement2()
{
	with (document.edit_accomodation)
	{
		if (quantity.value == '')
		{
			alert("Vous devez spécifier la quantité...");
			quantity.focus();
			return false;
		}
		if (!isNumeric(quantity.value))
		{
			alert("La quantité doit être composée de chiffres uniquement...");
			quantity.focus();
			return false;
		}
		if (parseInt(quantity.value) == 0)
		{
			alert("La quantité doit être supérieure à 0...");
			quantity.focus();
			return false;
		}
		if (parseInt(quantity.value) > 1)
		{
			if (min_surface.value == '')
			{
				alert("Vous devez spécifier la surface minimum...");
				min_surface.focus();
				return false;
			}
			if (!isNumeric(min_surface.value))
			{
				alert("La surface minimum doit être composée de chiffres uniquement...");
				min_surface.focus();
				return false;
			}
			if (parseInt(min_surface.value) == 0)
			{
				alert("La surface minimum doit être supérieure à 0...");
				min_surface.focus();
				return false;
			}
			if (max_surface.value == '')
			{
				alert("Vous devez spécifier la surface maximum...");
				max_surface.focus();
				return false;
			}
			if (!isNumeric(max_surface.value))
			{
				alert("La surface maximum doit être composée de chiffres uniquement...");
				max_surface.focus();
				return false;
			}
			if (parseInt(max_surface.value) == 0)
			{
				alert("La surface maximum doit être supérieure à 0...");
				max_surface.focus();
				return false;
			}
			if (parseInt(min_surface.value) > parseInt(max_surface.value))
			{
				alert("La surface maximum doit être supérieure à la surface minimum...");
				max_surface.focus();
				return false;
			}
		}
		else
		{
			if (min_surface.value == '')
			{
				alert("Vous devez spécifier la surface...");
				min_surface.focus();
				return false;
			}
			if (!isNumeric(min_surface.value))
			{
				alert("La surface doit être composée de chiffres uniquement...");
				min_surface.focus();
				return false;
			}
			if (parseInt(min_surface.value) == 0)
			{
				alert("La surface doit être supérieure à 0...");
				min_surface.focus();
				return false;
			}
		}
	}
	return true;
}

function checkStayLimitsPlanning(week_day, pricing_frequency)
{
	with (document.edit_accomodation)
	{
		switch (week_day)
		{
			case 0:
				if (!any_day.checked && !sunday.checked)
				{
					alert("Ce jour du planning ne correspond pas à un des jours de la semaine choisis comme jour d'arrivée accepté...");
					return false;
				}
				break;
			case 1:
				if (!any_day.checked && !monday.checked)
				{
					alert("Ce jour du planning ne correspond pas à un des jours de la semaine choisis comme jour d'arrivée accepté...");
					return false;
				}
				break;
			case 2:
				if (!any_day.checked && !tuesday.checked)
				{
					alert("Ce jour du planning ne correspond pas à un des jours de la semaine choisis comme jour d'arrivée accepté...");
					return false;
				}
				break;
			case 3:
				if (!any_day.checked && !wednesday.checked)
				{
					alert("Ce jour du planning ne correspond pas à un des jours de la semaine choisis comme jour d'arrivée accepté...");
					return false;
				}
				break;
			case 4:
				if (!any_day.checked && !thursday.checked)
				{
					alert("Ce jour du planning ne correspond pas à un des jours de la semaine choisis comme jour d'arrivée accepté...");
					return false;
				}
				break;
			case 5:
				if (!any_day.checked && !friday.checked)
				{
					alert("Ce jour du planning ne correspond pas à un des jours de la semaine choisis comme jour d'arrivée accepté...");
					return false;
				}
				break;
			case 6:
				if (!any_day.checked && !saturday.checked)
				{
					alert("Ce jour du planning ne correspond pas à un des jours de la semaine choisis comme jour d'arrivée accepté...");
					return false;
				}
				break;
		}
	}
	
	return checkStayLimits(pricing_frequency);
}

function checkStayLimits(pricing_frequency)
{
	with (document.edit_accomodation)
	{
		if (pricing_frequency != 4)
		{
			if (min_stay.value == '')
			{
				alert("Vous devez spécifier la durée minimum du séjour...");
				min_stay.focus();
				return false;
			}
			if (!isNumeric(min_stay.value))
			{
				alert("La durée minimum du séjour doit être composée de chiffres uniquement...");
				min_stay.focus();
				return false;
			}
			if (parseInt(min_stay.value) > 0)
			{
				if (max_stay.value == '')
				{
					alert("Vous devez spécifier la durée maximum du séjour...");
					max_stay.focus();
					return false;
				}
				if (!isNumeric(max_stay.value))
				{
					alert("La durée maximum du séjour doit être composée de chiffres uniquement...");
					max_stay.focus();
					return false;
				}
				if (parseInt(max_stay.value) > 0 && parseInt(max_stay.value) < parseInt(min_stay.value))
				{
					alert("La durée maximum du séjour doit être supérieure à la durée minimum du séjour...");
					max_stay.focus();
					return false;
				}
			}
		}
		else
		{
			if (min_nb_stay.value == '')
			{
				alert("Vous devez spécifier le nombre minimum de séjours...");
				min_nb_stay.focus();
				return false;
			}
			if (!isNumeric(min_nb_stay.value))
			{
				alert("Le nombre minimum de séjours doit être composé de chiffres uniquement...");
				min_nb_stay.focus();
				return false;
			}
			if (parseInt(min_nb_stay.value) > 0)
			{
				if (max_nb_stay.value == '')
				{
					alert("Vous devez spécifier le nombre maximum de séjours...");
					max_nb_stay.focus();
					return false;
				}
				if (!isNumeric(max_nb_stay.value))
				{
					alert("Le nombre maximum de séjours doit être composé de chiffres uniquement...");
					max_nb_stay.focus();
					return false;
				}
				if (parseInt(max_nb_stay.value) > 0 && parseInt(max_nb_stay.value) < parseInt(min_nb_stay.value))
				{
					alert("La durée maximum du séjour doit être supérieure à la durée minimum du séjour...");
					max_nb_stay.focus();
					return false;
				}
			}
		}
	}
	return true;
}

function updateNextFromRange(index)
{
	with (document.edit_accomodation)
	{
		if (index < 5)
			eval('from'+(index+1)).value = parseInt(eval('to'+index).value)+1;
	}
}

function updateRanges(min_capacity, max_capacity, nb_units, min_stay, max_stay, pricing_frequency)
{
	with (document.edit_accomodation)
	{
		var nb_rangesx = parseInt($('nb_ranges').value);
		for (var i=2; i<=nb_rangesx; i++)
			removeDecreaseRange(i);
		
		if (decrease_type.value == 1)
		{
			$('label1').innerHTML = 'logement(s)';
			eval('from1').value = 1;
			eval('to1').value = '';
		}
		else if (decrease_type.value == 2)
		{
			$('label1').innerHTML = 'personne(s)';
			eval('from1').value = min_capacity;
			eval('to1').value = '';
		}
		else
		{
			var label = 'séjour(s)';
			if (pricing_frequency == 1)
				label = 'nuit(s)';
			else if (pricing_frequency == 2)
				label = 'semaine(s)';
			else if (pricing_frequency == 3)
				label = 'mois';

			$('label1').innerHTML = label;
			eval('from1').value = min_stay;
			eval('to1').value = '';
		}
	}
}

function canAddRange(max_capacity, nb_units, max_stay)
{
	with (document.edit_accomodation)
	{
		var last_index = 1;
		for (var i=1; i<= 5; i++)
		{
			if (eval('active'+i).value == 0)
			{
				last_index = i-1;
				break;
			}
		}

		if (decrease_type.value == 1)
		{
			if (eval('to'+last_index).value >= nb_units)
				return false;
		}
		else if (decrease_type.value == 2)
		{
			if (eval('to'+last_index).value >= max_capacity)
				return false;
		}
		else
		{
			if (eval('to'+last_index).value >= max_stay)
				return false;
		}
	}

	return true;
}

function checkRecordTarificationPlanning(week_day, min_capacity, max_capacity, nb_units, min_stay, max_stay)
{
	with (document.edit_accomodation)
	{
		switch (week_day)
		{
			case 0:
				if (!any_day.checked && !sunday.checked)
				{
					alert("Ce jour du planning ne correspond pas à un des jours de la semaine choisis comme jour d'arrivée accepté...");
					return false;
				}
				break;
			case 1:
				if (!any_day.checked && !monday.checked)
				{
					alert("Ce jour du planning ne correspond pas à un des jours de la semaine choisis comme jour d'arrivée accepté...");
					return false;
				}
				break;
			case 2:
				if (!any_day.checked && !tuesday.checked)
				{
					alert("Ce jour du planning ne correspond pas à un des jours de la semaine choisis comme jour d'arrivée accepté...");
					return false;
				}
				break;
			case 3:
				if (!any_day.checked && !wednesday.checked)
				{
					alert("Ce jour du planning ne correspond pas à un des jours de la semaine choisis comme jour d'arrivée accepté...");
					return false;
				}
				break;
			case 4:
				if (!any_day.checked && !thursday.checked)
				{
					alert("Ce jour du planning ne correspond pas à un des jours de la semaine choisis comme jour d'arrivée accepté...");
					return false;
				}
				break;
			case 5:
				if (!any_day.checked && !friday.checked)
				{
					alert("Ce jour du planning ne correspond pas à un des jours de la semaine choisis comme jour d'arrivée accepté...");
					return false;
				}
				break;
			case 6:
				if (!any_day.checked && !saturday.checked)
				{
					alert("Ce jour du planning ne correspond pas à un des jours de la semaine choisis comme jour d'arrivée accepté...");
					return false;
				}
				break;
		}
	}
	
	return checkRecordTarification(min_capacity, max_capacity, nb_units, min_stay, max_stay);
}

function checkRecordTarification(min_capacity, max_capacity, nb_units, min_stay, max_stay)
{
	with (document.edit_accomodation)
	{
		if (type.value == 1)
		{
			if (fix_amount.value == '')
			{
				alert("Vous devez spécifier un prix fixe...");
				fix_amount.focus();
				return false;
			}
			if (!isNumeric(fix_amount.value))
			{
				alert("Le prix fixe doit être composé de chiffres uniquement...");
				fix_amount.focus();
				return false;
			}
/*			if (parseInt(fix_amount.value) == 0)
			{
				alert("Le prix fixe doit être supérieur à 0...");
				fix_amount.focus();
				return false;
			}*/
		}
		else
		{
			var nb_rangex = $('nb_ranges').value;
			for (var i=1; i<=nb_rangex; i++)
			{
				if (eval('from'+i+'.value') == '')
				{
					alert("Vous devez spécifier un début de tranche...");
					eval('from'+i).focus();
					return false;
				}
				if (!isNumeric(eval('from'+i+'.value')))
				{
					alert("Le début de tranche doit être composé de chiffres uniquement...");
					eval('from'+i).focus();
					return false;
				}
				if (eval('to'+i+'.value') == '')
				{
					alert("Vous devez spécifier une fin de tranche...");
					eval('to'+i).focus();
					return false;
				}
				if (!isNumeric(eval('to'+i+'.value')))
				{
					alert("La fin de tranche doit être composée de chiffres uniquement...");
					eval('to'+i).focus();
					return false;
				}
//				if (i == 1)
//				{
					if ((parseInt(eval('to'+i+'.value')) != 0 || i != nb_rangex) && parseInt(eval('to'+i+'.value')) < parseInt(eval('from'+i+'.value')))
					{
						alert("La fin de tranche doit être supérieure ou égale au début de tranche...");
						eval('to'+i).focus();
						return false;
					}
/*				}
				else
				{
					if (parseInt(eval('to'+i+'.value')) <= parseInt(eval('from'+i+'.value')))
					{
						alert("La fin de tranche doit être strictement supérieure au début de tranche...");
						eval('to'+i).focus();
						return false;
					}
				}
*/			}
			fix_amount.value = 0;

			if (decrease_type.value == 1)
			{
				var min = 0;
				var max = 0;
				for (var i=1; i<=nb_rangex; i++)
				{
					if (min == 0)
						min = eval('from'+i+'.value');
					max = eval('to'+i+'.value');
					if (eval('from'+i+'.value') > nb_units)
					{
						alert("Le début de la tranche ne peut pas être supérieur au nombre de logements de ce type ("+nb_units+")...");
						eval('from'+i).focus();
						return false;
					}
					if (eval('to'+i+'.value') > nb_units)
					{
						alert("La fin de la tranche ne peut pas être supérieure au nombre de logements de ce type ("+nb_units+")...");
						eval('to'+i).focus();
						return false;
					}
				}
				if (min != 1)
				{
					alert("La 1ère tranche doit commencer à un logement...");
					return false;
				}
				if (max != nb_units)
				{
					alert("La fin de la dernière tranche doit correspondre au nombre de logements de ce type ("+nb_units+")...");
					return false;
				}
			}
			else if (decrease_type.value == 2)
			{
				var min = 0;
				var max = 0;
				for (var i=1; i<=nb_rangex; i++)
				{
					if (min == 0)
						min = eval('from'+i+'.value');
					max = eval('to'+i+'.value');
					if (eval('from'+i+'.value') > max_capacity)
					{
						alert("Le début de la tranche ne peut pas être supérieur à la capacité maximum de ce logement ("+max_capacity+")...");
						eval('from'+i).focus();
						return false;
					}
					if (eval('to'+i+'.value') > max_capacity)
					{
						alert("La fin de la tranche ne peut pas être supérieure à la capacité maximum de ce logement ("+max_capacity+")...");
						eval('to'+i).focus();
						return false;
					}
					if (eval('from'+i+'.value') < min_capacity)
					{
						alert("Le début de la tranche ne peut pas être inférieur à la capacité minimum de ce logement ("+min_capacity+")...");
						eval('from'+i).focus();
						return false;
					}
					if (eval('to'+i+'.value') < min_capacity)
					{
						alert("La fin de la tranche ne peut pas être inférieure à la capacité minimum de ce logement ("+min_capacity+")...");
						eval('to'+i).focus();
						return false;
					}
				}
				if (min != min_capacity)
				{
					alert("Le début de la 1ère tranche doit correspondre à la capacité minimum de ce logement ("+min_capacity+")...");
					return false;
				}
				if (max_capacity != 99 && max != max_capacity)
				{
					alert("La fin de la dernière tranche doit correspondre à la capacité maximum de ce logement ("+max_capacity+")...");
					return false;
				}
			}
			else if (decrease_type.value == 3)
			{
				var min = 0;
				var max = 0;
				for (var i=1; i<=nb_rangex; i++)
				{
					if (min == 0)
						min = eval('from'+i+'.value');
					max = eval('to'+i+'.value');
					if (max_stay > 0)
					{
						if (eval('from'+i+'.value') > max_stay)
						{
							alert("Le début de la tranche ne peut pas être supérieur à la durée maximum de séjour ("+max_stay+")...");
							eval('from'+i).focus();
							return false;
						}
						if (eval('to'+i+'.value') > max_stay)
						{
							alert("La fin de la tranche ne peut pas être supérieure à la durée maximum de séjour ("+max_stay+")...");
							eval('to'+i).focus();
							return false;
						}
					}
					if (eval('from'+i+'.value') < min_stay)
					{
						alert("Le début de la tranche ne peut pas être inférieur à la durée minimum de séjour ("+min_stay+")...");
						eval('from'+i).focus();
						return false;
					}
					if (eval('to'+i+'.value') != 0 && eval('to'+i+'.value') < min_stay)
					{
						alert("La fin de la tranche ne peut pas être inférieure à la durée minimum de séjour ("+min_stay+")...");
						eval('to'+i).focus();
						return false;
					}
				}
				if (min != min_stay)
				{
					alert("Le début de la 1ère tranche doit correspondre à la durée minimum de séjour ("+min_stay+")...");
					return false;
				}
				if (max != max_stay)
				{
					alert("La fin de la dernière tranche doit correspondre à la durée maximum de séjour ("+max_stay+")...");
					return false;
				}
			}
		}
	}
	return true;
}

function updateTarificationPlanning(idx, housing_custom_type_id, whole_yearx, fromx, tox)
{
	with (document.edit_accomodation)
	{
		var params = 'id='+idx+'&year='+current_year.value+'&whole_year='+whole_yearx+'&from='+fromx+'&to='+tox+'&type='+type.value+'&decrease_type='+decrease_type.value+'&fix_amount='+fix_amount.value+'&any_day='+any_day.checked+'&monday='+monday.checked+'&tuesday='+tuesday.checked+'&wednesday='+wednesday.checked+'&thursday='+thursday.checked+'&friday='+friday.checked+'&saturday='+saturday.checked+'&sunday='+sunday.checked+'&nb_ranges='+nb_ranges.value;
		for (var i=1; i<=nb_ranges.value; i++)
		{
			params += '&from'+i+'='+eval('from'+i+'.value');
			params += '&to'+i+'='+eval('to'+i+'.value');
			params += '&amount'+i+'='+eval('amount'+i+'.value');
		}
		display('planning', '_includes/fr/manager-config/prix-planning.php', params+'&housing_custom_type_id='+housing_custom_type_id);
	}
}

function checkLogement31()
{
	with (document.edit_accomodation)
	{
		if (stay_length.value == '')
		{
			if (pricing_frequency.value == 4)
			{
				alert("Vous devez spécifier une durée de séjour...");
				stay_length.focus();
				return false;
			}
			else
				stay_length.value = 1;
		}
		if (!isNumeric(stay_length.value))
		{
			if (pricing_frequency.value == 4)
			{
				alert("La durée de séjour doit être composée de chiffres uniquement...");
				stay_length.focus();
				return false;
			}
			else
				stay_length.value = 1;
		}
		if (stay_length.value == 0)
		{
			if (pricing_frequency.value == 4)
			{
				alert("La durée de séjour doit être supérieure à 0...");
				stay_length.focus();
				return false;
			}
			else
				stay_length.value = 1;
		}
	}
	return true;
}

function submitLogement31(params)
{
	if (checkLogement31())
	{
		with (document.edit_accomodation)
		{
/*			params += '&nb_periods='+nb_periods.value;
			for (var i=0; i<nb_periods.value; i++)
			{
				params += '&date'+i+'='+eval('date'+i+'.value');
				params += '&min'+i+'='+eval('min'+i+'.value');
				params += '&max'+i+'='+eval('max'+i+'.value');
			}*/

			display('inner_edit_accomodation', '_includes/fr/manager-config/logement32.php', params+'&name_en='+name_en.value+'&description_en='+description_en.value+'&name_fr='+name_fr.value+'&description_fr='+description_fr.value+'&name_es='+name_es.value+'&description_es='+description_es.value+'&name_it='+name_it.value+'&description_it='+description_it.value+'&name_de='+name_de.value+'&description_de='+description_de.value+'&name_nl='+name_nl.value+'&description_nl='+description_nl.value+'&pricing_type='+pricing_type.value+'&pricing_frequency='+pricing_frequency.value+'&stay_length='+stay_length.value+'&stay_type='+stay_type.value);
		}
	}
}

function checkLogement32()
{
	if (document.edit_accomodation.empty_periods.value == 1)
	{
		alert("Vous n'avez enregistré aucune durée de séjour...");
		return false;
	}
	return true;
}

function checkLogement33(baby_age_limit, child_age_limit, kid_age_limit, quantity_types, quantity_housing)
{
	with (document.edit_accomodation)
	{
		if (min_capacity.value == '')
		{
			alert("Vous devez spécifier la capacité minimum...");
			min_capacity.focus();
			return false;
		}
		if (!isNumeric(min_capacity.value))
		{
			alert("La capacité minimum doit être composée de chiffres uniquement...");
			min_capacity.focus();
			return false;
		}
		if (parseInt(min_capacity.value) == 0)
		{
			alert("La capacité minimum doit être supérieure à 0...");
			min_capacity.focus();
			return false;
		}
		if (max_capacity.value == '')
		{
			alert("Vous devez spécifier la capacité maximum...");
			max_capacity.focus();
			return false;
		}
		if (!isNumeric(max_capacity.value))
		{
			alert("La capacité maximum doit être composée de chiffres uniquement...");
			max_capacity.focus();
			return false;
		}
		if (parseInt(max_capacity.value) < parseInt(min_capacity.value))
		{
			alert("La capacité maximum doit être supérieure à la capacité minimum...");
			max_capacity.focus();
			return false;
		}
		if (baby_age_limit > 0 || child_age_limit > 0 || kid_age_limit > 0)
		{
			if (max_capacity_adults.value == '')
			{
				alert("Vous devez spécifier la capacité maximum pour les adultes...");
				max_capacity_adults.focus();
				return false;
			}
			if (!isNumeric(max_capacity_adults.value))
			{
				alert("La capacité maximum pour les adultes doit être composée de chiffres uniquement...");
				max_capacity_adults.focus();
				return false;
			}
			if (parseInt(max_capacity.value) != 99 && parseInt(max_capacity_adults.value) > parseInt(max_capacity.value))
			{
				alert("La capacité maximum pour les adultes doit être inférieure ou égale à la capacité maximum globale...");
				max_capacity_adults.focus();
				return false;
			}
			var cumul = 0;
			if (kid_age_limit > 0)
			{
				if (max_capacity_kid.value == '')
				{
					alert("Vous devez spécifier la capacité maximum pour les adolescents...");
					max_capacity_kid.focus();
					return false;
				}
				if (!isNumeric(max_capacity_kid.value))
				{
					alert("La capacité maximum pour les adolescents doit être composée de chiffres uniquement...");
					max_capacity_kid.focus();
					return false;
				}
				if (parseInt(max_capacity.value) != 99 && parseInt(max_capacity_kid.value) > parseInt(max_capacity.value))
				{
					alert("La capacité maximum pour les adolescents doit être inférieure ou égale à la capacité maximum globale...");
					max_capacity_kid.focus();
					return false;
				}
				cumul += parseInt(max_capacity_kid.value);
			}
			if (child_age_limit > 0)
			{
				if (max_capacity_child.value == '')
				{
					alert("Vous devez spécifier la capacité maximum pour les enfants...");
					max_capacity_child.focus();
					return false;
				}
				if (!isNumeric(max_capacity_child.value))
				{
					alert("La capacité maximum pour les enfants doit être composée de chiffres uniquement...");
					max_capacity_child.focus();
					return false;
				}
				if (parseInt(max_capacity.value) != 99 && parseInt(max_capacity_child.value) > parseInt(max_capacity.value))
				{
					alert("La capacité maximum pour les enfants doit être inférieure ou égale à la capacité maximum globale...");
					max_capacity_child.focus();
					return false;
				}
				cumul += parseInt(max_capacity_child.value);
			}
			if (baby_age_limit > 0)
			{
				if (max_capacity_babies.value == '')
				{
					alert("Vous devez spécifier la capacité maximum pour les bébés...");
					max_capacity_babies.focus();
					return false;
				}
				if (!isNumeric(max_capacity_babies.value))
				{
					alert("La capacité maximum pour les bébés doit être composée de chiffres uniquement...");
					max_capacity_babies.focus();
					return false;
				}
				if (parseInt(max_capacity.value) != 99 && parseInt(max_capacity_babies.value) > parseInt(max_capacity.value))
				{
					alert("La capacité maximum pour les bébés doit être inférieure ou égale à la capacité maximum globale...");
					max_capacity_babies.focus();
					return false;
				}
				cumul += parseInt(max_capacity_babies.value);
			}
			if (parseInt(max_capacity_adults.value)+cumul < parseInt(min_capacity.value))
			{
				alert("Le cumul des capacités maximum doit être supérieur à la capacité minimum globale...");
				max_capacity_adults.focus();
				return false;
			}
		}
		if (nb_units.value == '')
		{
			alert("Vous devez spécifier le nombre de logements...");
			nb_units.focus();
			return false;
		}
		if (!isNumeric(nb_units.value))
		{
			alert("Le nombre de logements doit être composé de chiffres uniquement...");
			nb_units.focus();
			return false;
		}
		if (parseInt(nb_units.value) == 0)
		{
			alert("Le nombre de logements doit être supérieur à 0...");
			nb_units.focus();
			return false;
		}
		if (parseInt(nb_units.value) > parseInt(housing_quantity.value))
		{
			alert("Le nombre de logements de ce type ne doit pas être supérieur à la capacité totale du logement...");
			nb_units.focus();
			return false;
		}
		if (parseInt(nb_units.value) + quantity_types > quantity_housing)
		{
			alert("Le cumul du nombre de types ("+(parseInt(nb_units.value) + quantity_types)+") ne doit pas dépasser le nombre total de logements ("+quantity_housing+").");
			nb_units.focus();
			return false;
		}
		var from_dates = new Array();
		var to_dates = new Array();
		var dates_index = 0;
		for (var i=1; i<=5; i++)
		{
			if (parseInt(eval('active'+i+'.value')) == 1)
			{
				if (!eval('arrival_any_day'+i+'.checked'))
				{
					if (!eval('arrival_mondays'+i+'.checked') && !eval('arrival_tuesdays'+i+'.checked') && !eval('arrival_wednesdays'+i+'.checked') && !eval('arrival_thursdays'+i+'.checked') && !eval('arrival_fridays'+i+'.checked') && !eval('arrival_saturdays'+i+'.checked') && !eval('arrival_sundays'+i+'.checked'))
					{
						alert("Vous devez au moins sélectionner un jour d'arrivée...")
						return false;
					}
				}

				from_dates[dates_index] = new Date();
				from_dates[dates_index].setFullYear(2000, eval('from_month'+i+'.value')-1, eval('from_day'+i+'.value'));
				if (from_dates[dates_index].getFullYear() != 2000
				 || from_dates[dates_index].getMonth() != eval('from_month'+i+'.value')-1
				 || from_dates[dates_index].getDate() != eval('from_day'+i+'.value'))
				{
					alert("La date de début de la période n'est pas valide...");
					return false;
				}
				to_dates[dates_index] = new Date();
				to_dates[dates_index].setFullYear(2000, eval('to_month'+i+'.value')-1, eval('to_day'+i+'.value'));
				if (to_dates[dates_index].getFullYear() != 2000
				 || to_dates[dates_index].getMonth() != eval('to_month'+i+'.value')-1
				 || to_dates[dates_index].getDate() != eval('to_day'+i+'.value'))
				{
					alert("La date de fin de la période n'est pas valide...");
					return false;
				}
				if (from_dates[dates_index] >= to_dates[dates_index])
				{
					alert("La date de début de la période doit être antérieure à la date de fin...");
					return false;
				}
				dates_index++;
			}
		}
		for (var index=0; index<dates_index; index++)
		{
			for (var index2=0; index2<dates_index; index2++)
			{
				if (index == index2) continue;
				if (from_dates[index] <= to_dates[index2] && from_dates[index2] <= to_dates[index])
				{
					alert("Les périodes ne doivent pas se chevaucher...");
					return false;
				}
			}
		}
	}
	return true;
}

function checkPrix21()
{
	if (document.edit_accomodation.setup_for_year.value == 0)
	{
		alert("Toute la période de l'année en cours doit être couverte par un prix...");
		return false;
	}

	return true;
}

function checkPrix22(min_capacity, max_capacity, max_capacity_adults, max_capacity_kid, max_capacity_child, max_capacity_babies)
{
	with (document.edit_accomodation)
	{
		if (!$('no_stay_tax').checked)
		{
			if (stay_tax_amount.value == '')
			{
				alert("Vous devez renseigner le montant de la taxe de séjour...");
				stay_tax_amount.focus();
				return false;
			}
			if (!isNumeric(stay_tax_amount.value))
			{
				alert("Le montant de la taxe de séjour doit être composé de chiffres uniquement...");
				stay_tax_amount.focus();
				return false;
			}
		}
		if (!$('no_single_tax').checked)
		{
			if (single_tax_amount.value == '')
			{
				alert("Vous devez renseigner le montant du supplément pour une personne seule...");
				single_tax_amount.focus();
				return false;
			}
			if (!isNumeric(single_tax_amount.value))
			{
				alert("Le montant du supplément pour une personne seule doit être composé de chiffres uniquement...");
				single_tax_amount.focus();
				return false;
			}
		}
		if (!$('no_caution').checked)
		{
			if (caution_amount.value == '')
			{
				alert("Vous devez renseigner le montant de la caution...");
				caution_amount.focus();
				return false;
			}
			if (!isNumeric(caution_amount.value))
			{
				alert("Le montant de la caution doit être composé de chiffres uniquement...");
				caution_amount.focus();
				return false;
			}
		}
		if (!stay_tax_adults.checked && !stay_tax_kids.checked && !stay_tax_children.checked && !stay_tax_babies.checked)
		{
			alert("Vous devez au moins sélectionner un type de personne taxée...");
			return false;
		}
		if (!additional_tax_adults.checked && !additional_tax_children.checked && !additional_tax_babies.checked)
		{
			alert("Vous devez au moins sélectionner un type de personne taxée...");
			return false;
		}

		var nb_additional_taxes_value = parseInt($('nb_additional_taxes').value);
		if (!$('no_additional_tax').checked)
		{
			var last_from = 0;
			for (var i=0; i <= nb_additional_taxes_value; i++)
			{
				if ($('additional_tax_amount'+i))
				{
					if ($('additional_tax_amount'+i).value == '')
					{
						alert("Vous devez renseigner le montant du supplément pour les personnes supplémentaires...");
						$('additional_tax_amount'+i).focus();
						return false;
					}
					if (!isNumeric($('additional_tax_amount'+i).value))
					{
						alert("Le montant du supplément doit être composé de chiffres uniquement...");
						$('additional_tax_amount'+i).focus();
						return false;
					}
					if ($('additional_tax_from_nb'+i).value == '')
					{
						alert("Vous devez renseigner le nombre de personne(s)...");
						$('additional_tax_from_nb'+i).focus();
						return false;
					}
					if (!isNumeric($('additional_tax_from_nb'+i).value))
					{
						alert("Le nombre de personne(s) doit être composé de chiffres uniquement...");
						$('additional_tax_from_nb'+i).focus();
						return false;
					}
					if (parseInt($('additional_tax_from_nb'+i).value) <= last_from)
					{
						alert("Le nombre de personne(s) doit être supérieur à la tranche précedente...");
						$('additional_tax_from_nb'+i).focus();
						return false;
					}
					if (max_capacity != 99 && parseInt($('additional_tax_from_nb'+i).value) > max_capacity)
					{
						alert("Le nombre de personne(s) doit être inférieur au maximum autorisé ("+max_capacity+")...");
						$('additional_tax_from_nb'+i).focus();
						return false;
					}
					last_from = $('additional_tax_from_nb'+i).value;
				}
			}
		}

		var nb_babies_taxes_value = parseInt($('nb_babies_taxes').value);
		if (!$('no_babies_tax').checked)
		{
			var last_from = 0;
			for (var i=0; i <= nb_babies_taxes_value; i++)
			{
				if ($('babies_tax_amount'+i))
				{
					if ($('babies_tax_amount'+i).value == '')
					{
						alert("Vous devez renseigner le montant du tarif spécial pour les bébés...");
						$('babies_tax_amount'+i).focus();
						return false;
					}
					if (!isNumeric($('babies_tax_amount'+i).value))
					{
						alert("Le montant du tarif spécial doit être composé de chiffres uniquement...");
						$('babies_tax_amount'+i).focus();
						return false;
					}
					if ($('babies_tax_from_nb'+i).value == '')
					{
						alert("Vous devez renseigner le nombre de bébé(s)...");
						$('babies_tax_from_nb'+i).focus();
						return false;
					}
					if (!isNumeric($('babies_tax_from_nb'+i).value))
					{
						alert("Le nombre de bébé(s) doit être composé de chiffres uniquement...");
						$('babies_tax_from_nb'+i).focus();
						return false;
					}
					if (parseInt($('babies_tax_from_nb'+i).value) <= last_from)
					{
						alert("Le nombre de bébé(s) doit être supérieur à la tranche précedente...");
						$('babies_tax_from_nb'+i).focus();
						return false;
					}
					if (max_capacity_babies != 99 && parseInt($('babies_tax_from_nb'+i).value) > max_capacity_babies)
					{
						alert("Le nombre de bébé(s) doit être inférieur au maximum autorisé ("+max_capacity_babies+")...");
						$('babies_tax_from_nb'+i).focus();
						return false;
					}
					last_from = $('babies_tax_from_nb'+i).value;
				}
			}
		}

		var nb_children_taxes_value = parseInt($('nb_children_taxes').value);
		if (!$('no_children_tax').checked)
		{
			var last_from = 0;
			for (var i=0; i <= nb_children_taxes_value; i++)
			{
				if ($('children_tax_amount'+i))
				{
					if ($('children_tax_amount'+i).value == '')
					{
						alert("Vous devez renseigner le montant du tarif spécial pour les enfants...");
						$('children_tax_amount'+i).focus();
						return false;
					}
					if (!isNumeric($('children_tax_amount'+i).value))
					{
						alert("Le montant du tarif spécial doit être composé de chiffres uniquement...");
						$('children_tax_amount'+i).focus();
						return false;
					}
					if ($('children_tax_from_nb'+i).value == '')
					{
						alert("Vous devez renseigner le nombre d'enfant(s)...");
						$('children_tax_from_nb'+i).focus();
						return false;
					}
					if (!isNumeric($('children_tax_from_nb'+i).value))
					{
						alert("Le nombre d'enfant(s) doit être composé de chiffres uniquement...");
						$('children_tax_from_nb'+i).focus();
						return false;
					}
					if (parseInt($('children_tax_from_nb'+i).value) <= last_from)
					{
						alert("Le nombre d'enfant(s) doit être supérieur à la tranche précedente...");
						$('children_tax_from_nb'+i).focus();
						return false;
					}
					if (max_capacity_child != 99 && parseInt($('children_tax_from_nb'+i).value) > max_capacity_child)
					{
						alert("Le nombre d'enfant(s) doit être inférieur au maximum autorisé ("+max_capacity_child+")...");
						$('children_tax_from_nb'+i).focus();
						return false;
					}
					last_from = $('children_tax_from_nb'+i).value;
				}
			}
		}

		var nb_kids_taxes_value = parseInt($('nb_kids_taxes').value);
		if (!$('no_kids_tax').checked)
		{
			var last_from = 0;
			for (var i=0; i <= nb_kids_taxes_value; i++)
			{
				if ($('kids_tax_amount'+i))
				{
					if ($('kids_tax_amount'+i).value == '')
					{
						alert("Vous devez renseigner le montant du tarif spécial pour les adolescents...");
						$('kids_tax_amount'+i).focus();
						return false;
					}
					if (!isNumeric($('kids_tax_amount'+i).value))
					{
						alert("Le montant du tarif spécial doit être composé de chiffres uniquement...");
						$('kids_tax_amount'+i).focus();
						return false;
					}
					if ($('kids_tax_from_nb'+i).value == '')
					{
						alert("Vous devez renseigner le nombre d'adolescent(s)...");
						$('kids_tax_from_nb'+i).focus();
						return false;
					}
					if (!isNumeric($('kids_tax_from_nb'+i).value))
					{
						alert("Le nombre d'adolescent(s) doit être composé de chiffres uniquement...");
						$('kids_tax_from_nb'+i).focus();
						return false;
					}
					if (parseInt($('kids_tax_from_nb'+i).value) <= last_from)
					{
						alert("Le nombre d'adolescent(s) doit être supérieur à la tranche précedente...");
						$('kids_tax_from_nb'+i).focus();
						return false;
					}
					if (max_capacity_kid != 99 && parseInt($('kids_tax_from_nb'+i).value) > max_capacity_kid)
					{
						alert("Le nombre d'adolescent(s) doit être inférieur au maximum autorisé ("+max_capacity_kid+")...");
						$('kids_tax_from_nb'+i).focus();
						return false;
					}
					last_from = $('kids_tax_from_nb'+i).value;
				}
			}
		}
	}
	return true;
}

function showHousingPeriodSelection()
{
	$("period_selection").style.display = "";
}

function hideHousingPeriodSelection()
{
	$("period_selection").style.display = "none";
}

function addHousingStayPeriod()
{
	for (var i=2; i<=5; i++)
	{
		if ($("period"+i).style.display == "none")
		{
			$("period"+i).style.display = "";
			$("active"+i).value = 1;
			break;
		}
	}
}

function removeHousingStayPeriod(index)
{
	$("period"+index).style.display = "none";
	$("active"+index).value = 0;
}

function updateHousingPricing(pricing_type)
{
	$("stay_length_row").style.display = "none";
	if (pricing_type == 4)
	{
		$("stay_length_row").style.display = "";
		document.edit_accomodation.stay_length.value = 1;
	}
}

function showHousingArrivalPeriods()
{
	$("period_selection1").style.display = "";
	$("active1").value = 1;
	$("add_arrival_link").style.display = "";
}

function hideHousingArrivalPeriods()
{
	$("add_arrival_link").style.display = "none";
	$("period_selection1").style.display = "none";
	for (var i=2; i<=5; i++)
	{
		$("period"+i).style.display = "none";
		$("active"+i).value = 0;
	}
}

function addHousingArrivalPeriod()
{
	for (var i=2; i<=5; i++)
	{
		if ($("period"+i).style.display == "none")
		{
			$("period"+i).style.display = "";
			$("active"+i).value = 1;
			break;
		}
	}
}

function removeHousingArrivalPeriod(index)
{
	$("period"+index).style.display = "none";
	$("active"+index).value = 0;
}

function updateArrivalDays(index)
{
	if ($('arrival_any_day'+index).checked)
		$('arrival_days'+index).style.display='none';
	else
		$('arrival_days'+index).style.display='';
}

function updateLangMenu(selected_item)
{
	lang_en_link = "images/menu_lang_en.jpg";
	$('lang_en').src = lang_en_link;
	lang_fr_link = "images/menu_lang_fr.jpg";
	$('lang_fr').src = lang_fr_link;
	lang_sp_link = "images/menu_lang_sp.jpg";
	$('lang_sp').src = lang_sp_link;
	lang_it_link = "images/menu_lang_it.jpg";
	$('lang_it').src = lang_it_link;
	lang_ge_link = "images/menu_lang_ge.jpg";
	$('lang_ge').src = lang_ge_link;
	lang_nl_link = "images/menu_lang_nl.jpg";
	$('lang_nl').src = lang_nl_link;

	if (selected_item == "lang_en")
	{
		lang_en_link = "images/menu_lang_en_ov.jpg";
		$('lang_en').src = lang_en_link;
	}
	else if (selected_item == "lang_fr")
	{
		lang_fr_link = "images/menu_lang_fr_ov.jpg";
		$('lang_fr').src = lang_fr_link;
	}
	else if (selected_item == "lang_sp")
	{
		lang_sp_link = "images/menu_lang_sp_ov.jpg";
		$('lang_sp').src = lang_sp_link;
	}
	else if (selected_item == "lang_it")
	{
		lang_it_link = "images/menu_lang_it_ov.jpg";
		$('lang_it').src = lang_it_link;
	}
	else if (selected_item == "lang_ge")
	{
		lang_ge_link = "images/menu_lang_ge_ov.jpg";
		$('lang_ge').src = lang_ge_link;
	}
	else if (selected_item == "lang_nl")
	{
		lang_nl_link = "images/menu_lang_nl_ov.jpg";
		$('lang_nl').src = lang_nl_link;
	}
/*	eval(selected_item+"_link = 'images/menu_"+selected_item+"_ov.jpg'");
	$(selected_item).src = "images/menu"+selected_item+"_ov.jpg";*/
}

function is_child_of(parent, child)
{
	if (child != null)
	{
		while (child.parentNode)
		{
			if ((child = child.parentNode) == parent )
				return true;
		}
	}
	return false;
}

function displayMenu()
{
	var pos = getPosition($('li_menu'));
	$('menu').style.left = pos[0]+'px';
	$('menu').style.top = (pos[1]+20)+'px';
	$('menu').style.display = '';
}

function hideMenu(element, event)
{
	var current_mouse_target = null;

	if (event.toElement)
		current_mouse_target = event.toElement;
	else if( event.relatedTarget )
		current_mouse_target = event.relatedTarget;

	if (!is_child_of(element, current_mouse_target) && element != current_mouse_target)
		element.style.display = "none";
}

function getPosition(element)
{
	var T = 0, L = 0;
	while (element)
	{
		L += element.offsetLeft;
		T += element.offsetTop;
		element = element.offsetParent;
	}
	return [L, T];
}

function addDecreaseRange(index, label, min_capacity, max_capacity, nb_units, min_stay, max_stay)
{
	if ($('to'+(index-1)).value == '')
	{
		alert("Veuillez spécifier la valeur maximum pour cette tranche...");
		$('to'+(index-1)).focus();
		return;
	}
	if (!isNumeric($('to'+(index-1)).value))
	{
		alert("La valeur maximum doit être un entier...");
		$('to'+(index-1)).focus();
		return;
	}
	if (parseInt($('to'+(index-1)).value) < parseInt($('from'+(index-1)).value))
	{
		alert("La valeur maximum ne peut pas être strictement inférieure à la valeur minimum...");
		$('to'+(index-1)).focus();
		return;
	}

	if (document.edit_accomodation.decrease_type.value == 1)
	{
		if ($('to'+(index-1)).value > nb_units)
		{
			alert("La valeur maximum doit être inférieure ou égale au nombre de logements de ce type ("+nb_units+")...");
			return;
		}
	}
	else if (document.edit_accomodation.decrease_type.value == 2)
	{
		if (max_capacity != 99 && $('to'+(index-1)).value > max_capacity)
		{
			alert("La valeur maximum doit être inférieure ou égale à la capacité maximum de ce logement ("+max_capacity+")...");
			return;
		}
	}
	else if (document.edit_accomodation.decrease_type.value == 3)
	{
		if (max_stay != 0 && $('to'+(index-1)).value > max_stay)
		{
			alert("La valeur maximum doit être inférieure ou égale à la durée maximum de séjour ("+max_stay+")...");
			return;
		}
	}

	var nb_ranges = parseInt($('nb_ranges').value)+1;
	var previous_label = $('label'+(nb_ranges-1)).innerHTML;
	$('range'+(nb_ranges-1)+'_actions').style.display = 'none';
	var new_tr = document.createElement('tr');
	new_tr.setAttribute('id', "range"+nb_ranges);
	var new_td1 = document.createElement('td');
	var from_value = '';
	if ($('to'+(nb_ranges-1)).value != '')
		from_value = parseInt($('to'+(nb_ranges-1)).value)+1;
	new_td1.innerHTML = "De <input type=\"textbox\" size=\"2\" name=\"from"+nb_ranges+"\" id=\"from"+nb_ranges+"\" value=\""+from_value+"\" readonly=\"readonly\" /> ";
	new_td1.innerHTML += "à <input type=\"textbox\" size=\"2\" name=\"to"+nb_ranges+"\" id=\"to"+nb_ranges+"\" value=\"\" onBlur=\"updateDecreaseTopRange("+(nb_ranges+1)+", parseInt(this.value)+1, "+min_capacity+", "+max_capacity+", "+nb_units+", "+min_stay+", "+max_stay+")\" /> ";
	new_td1.innerHTML += "<span id=\"label"+nb_ranges+"\">"+previous_label+"</span> : ";
	new_td1.innerHTML += "<input type=\"textbox\" size=\"5\" name=\"amount"+nb_ranges+"\" value=\"0\" /> "+label;
	var new_td2 = document.createElement('td');
	new_td2.setAttribute('id', "range"+nb_ranges+"_actions");
	new_td2.setAttribute('align', 'right');
	new_td2.innerHTML = "<a href=\"javascript:void(0);\" onClick=\"removeDecreaseRange("+(nb_ranges-1)+")\">Supprimer</a><span id=\"add_button"+nb_ranges+"\"> | <a href=\"javascript:void(0);\" onClick=\"addDecreaseRange("+(nb_ranges+1)+", '"+label+"', "+min_capacity+", "+max_capacity+", "+nb_units+", "+min_stay+", "+max_stay+")\">Ajouter</a></span>";
	new_tr.appendChild(new_td1);
	new_tr.appendChild(new_td2);
	$('decrease_ranges').tBodies[0].appendChild(new_tr);
	$('nb_ranges').value = nb_ranges;
}

function removeDecreaseRange(index)
{
	var nb_ranges = parseInt($('nb_ranges').value);
	$('decrease_ranges').tBodies[0].removeChild($('range'+nb_ranges));
	$('nb_ranges').value = nb_ranges-1;
	$('range'+(nb_ranges-1)+'_actions').style.display = '';
}

function updateDecreaseTopRange(index, value, min_capacity, max_capacity, nb_units, min_stay, max_stay)
{
	var valid = true;
	if ($('to'+(index-1)).value == '')
	{
		alert("Veuillez spécifier la valeur maximum pour cette tranche...");
		$('to'+(index-1)).focus();
		valid = false;
	}
	if (!isNumeric($('to'+(index-1)).value))
	{
		alert("La valeur maximum doit être un entier...");
		$('to'+(index-1)).focus();
		valid = false;
	}
	if (parseInt($('to'+(index-1)).value) < parseInt($('from'+(index-1)).value))
	{
		if (document.edit_accomodation.decrease_type.value != 3 && max_stay != 0 && $('to'+(index-1)).value != 0)
		{
			alert("La valeur maximum ne peut pas être strictement inférieure à la valeur minimum...");
			$('to'+(index-1)).focus();
			valid = false;
		}
	}

	if (document.edit_accomodation.decrease_type.value == 1)
	{
		if ($('to'+(index-1)).value > nb_units)
		{
			alert("La valeur maximum doit être inférieure ou égale au nombre de logements de ce type ("+nb_units+")...");
			valid = false;
		}
		else if ($('to'+(index-1)).value == nb_units)
			valid = false;
	}
	else if (document.edit_accomodation.decrease_type.value == 2)
	{
		if (max_capacity != 99 && $('to'+(index-1)).value > max_capacity)
		{
			alert("La valeur maximum doit être inférieure ou égale à la capacité maximum de ce logement ("+max_capacity+")...");
			valid = false;
		}
		else if (max_capacity != 99 && $('to'+(index-1)).value == max_capacity)
			valid = false;
	}
	else if (document.edit_accomodation.decrease_type.value == 3)
	{
		if (max_stay != 0 && $('to'+(index-1)).value > max_stay)
		{
			alert("La valeur maximum doit être inférieure ou égale à la durée maximum de séjour ("+max_stay+")...");
			valid = false;
		}
		else if (max_stay != 0 && $('to'+(index-1)).value == max_stay)
			valid = false;
	}
	if (!valid)
	{
		$('add_button'+(index-1)).style.display = 'none';
		return;
	}
	else
		$('add_button'+(index-1)).style.display = '';

	if ($('from'+index))
		$('from'+index).value = value;
	if ($('to'+index) && $('to'+index).value != '' && parseInt($('to'+index).value) < value)
	{
		$('to'+index).value = value;
		updateDecreaseTopRange(index+1, parseInt($('to'+index).value)+1, min_capacity, max_capacity, nb_units, min_stay, max_stay);
	}
	else
	{
		if (document.edit_accomodation.decrease_type.value == 1)
		{
			if ($('to'+(index-1)).value == nb_units)
				$('add_button'+(index-1)).style.display = 'none';
		}
		else if (document.edit_accomodation.decrease_type.value == 2)
		{
			if ($('to'+(index-1)).value == max_capacity)
				$('add_button'+(index-1)).style.display = 'none';
		}
		else if (document.edit_accomodation.decrease_type.value == 3)
		{
			if ($('to'+(index-1)).value == max_stay)
				$('add_button'+(index-1)).style.display = 'none';
		}
	}
}

function addPricingPeriod()
{
	for (var i=1; i<=5; i++)
	{
		if ($('period'+i).style.display == 'none')
		{
			$('period'+i).style.display = '';
			$('active'+i).value = '1';
			break;
		}
	}
}

function removePricingPeriod(index)
{
	$('period'+index).style.display = 'none';
	$('active'+index).value = '0';
}

function switchPriceDisplay(price_type)
{
	if (price_type == 2)
	{
		$('decrease').style.display = '';
		$('fix').style.display = 'none';
		$('decrease_type').style.display = '';
		if ($('decrease_type').value == 3)
			$('stay_details').style.display = '';
/*		$('active1').value = '1';
		$('range1').style.display = '';
		for (var range_index=2; range_index<=5; range_index++)
		{
			$('active'+range_index).value = '0';
			$('range'+range_index).style.display = 'none';
		}*/
	}
	else
	{
		$('decrease').style.display = 'none';
		$('fix').style.display = '';
		$('decrease_type').style.display = 'none';
		$('stay_details').style.display = 'none';
/*		$('active1').value = '1';
		$('range1').style.display = '';
		for (var range_index=2; range_index<=5; range_index++)
		{
			$('active'+range_index).value = '0';
			$('range'+range_index).style.display = 'none';
		}*/
	}
}

function addCancelFee()
{
	for (var i=1; i<=10; i++)
	{
		if ($('active'+i).value == 0)
		{
			$('active'+i).value = 1;
			$('range'+i).style.display = '';
			break;
		}
	}
}

function removeCancelFee(index)
{
	$('active'+index).value = 0;
	$('range'+index).style.display = 'none';
}

function checkCGV()
{
	with (document.edit_accomodation)
	{
		if (more_than_days.value == '')
		{
			alert();
		}
	}

	return true;
}

function checkArrhes()
{
	with (document.edit_accomodation)
	{
		if (arrhes.value == '')
		{
			alert("Vous devez spécifier le montant...");
			arrhes.focus();
			return false;
		}
		if (!isNumeric(arrhes.value))
		{
			alert("Le montant doit être numérique...");
			arrhes.focus();
			return false;
		}
		if (parseInt(arrhes.value) < 10)
		{
			alert("Le montant doit être supérieur à 10%...");
			arrhes.focus();
			return false;
		}
		if (parseInt(arrhes.value) > 100)
		{
			alert("Le montant doit être inférieur à 100%...");
			arrhes.focus();
			return false;
		}
	}

	return true;
}

function checkModesPaiement()
{
	with (document.edit_accomodation)
	{
		if (currency.value == -1)
		{
			alert("Veuillez sélectionner une devise...");
			return false;
		}
		if (paiement_mode_check.checked && paiement_mode_other_check.checked && paiement_mode_other_check_name.value == '')
		{
			alert("Vous devez spécifier un autre type de chèque...");
			paiement_mode_other_check_name.focus();
			return false;
		}
		if ($('paiement_mode_card_advanced').checked)
		{
			if (arrhes.value == '')
			{
				alert("Vous devez spécifier le débit immédiat...");
				immediate_debit.focus();
				return false;
			}
			if (!isNumeric(arrhes.value))
			{
				alert("Le débit immédiat doit être numérique...");
				immediate_debit.focus();
				return false;
			}
			if (parseInt(arrhes.value) < 10)
			{
				alert("Le débit immédiat doit être supérieur à 10%...");
				immediate_debit.focus();
				return false;
			}
			if (parseInt(arrhes.value) > 100)
			{
				alert("Le débit immédiat doit être inférieur à 100%...");
				immediate_debit.focus();
				return false;
			}
		}
/*		if (account_owner.value == '')
		{
			alert("Vous devez spécifier le titulaire du compte...");
			account_owner.focus();
			return false;
		}
		if (bank.value == '')
		{
			alert("Vous devez spécifier la banque du compte...");
			bank.focus();
			return false;
		}
		if (counter.value == '')
		{
			alert("Vous devez spécifier le guichet du compte...");
			counter.focus();
			return false;
		}
		if (account_number.value == '')
		{
			alert("Vous devez spécifier le numéro du compte...");
			account_number.focus();
			return false;
		}
		if (account_key.value == '')
		{
			alert("Vous devez spécifier la clé du compte...");
			account_key.focus();
			return false;
		}
		if (bic.value == '')
		{
			alert("Vous devez spécifier le code BIC du compte...");
			bic.focus();
			return false;
		}
		if (swift.value == '')
		{
			alert("Vous devez spécifier le code SWIFT du compte...");
			swift.focus();
			return false;
		}
		if (card_number.value == '')
		{
			alert("Vous devez spécifier votre numéro de carte de crédit...");
			card_number.focus();
			return false;
		}*/
	}

	return true;
}

function checkCoord()
{
	with (document.edit_accomodation)
	{
		if (coord_bank_country.value == -1)
		{
			alert("Veuillez sélectionner un pays...");
			return false;
		}
		if (coord_account_owner.value == '')
		{
			alert("Vous devez spécifier le titulaire du compte...");
			coord_account_owner.focus();
			return false;
		}
		if (coord_bank_name.value == '')
		{
			alert("Vous devez spécifier le nom de la banque...");
			coord_bank_name.focus();
			return false;
		}
		if (coord_bank_address.value == '')
		{
			alert("Vous devez spécifier l'adresse de la banque...");
			coord_bank_address.focus();
			return false;
		}
		if (coord_bank_cp.value == '')
		{
			alert("Vous devez spécifier le code postal de la banque...");
			coord_bank_cp.focus();
			return false;
		}
		if (coord_bank_city.value == '')
		{
			alert("Vous devez spécifier la ville de la banque...");
			coord_bank_city.focus();
			return false;
		}
		if (coord_bank_country.value == 'FR')
		{
			if (coord_rib_bank_code.value == '')
			{
				alert("Vous devez spécifier le code de la banque...");
				coord_rib_bank_code.focus();
				return false;
			}
			if (coord_rib_counter_code.value == '')
			{
				alert("Vous devez spécifier le code guichet de la banque...");
				coord_rib_counter_code.focus();
				return false;
			}
			if (coord_rib_account_number.value == '')
			{
				alert("Vous devez spécifier le numéro de compte...");
				coord_rib_account_number.focus();
				return false;
			}
			if (coord_rib_account_key.value == '')
			{
				alert("Vous devez spécifier la clé RIB...");
				coord_rib_account_key.focus();
				return false;
			}
		}
		else
		{
			if (coord_iban_code.value == '')
			{
				alert("Vous devez spécifier le code IBAN...");
				coord_iban_code.focus();
				return false;
			}
			if (coord_iban_bic_code.value == '')
			{
				alert("Vous devez spécifier le code BIC...");
				coord_iban_bic_code.focus();
				return false;
			}
			if (coord_iban_currency.value == -1)
			{
				alert("Veuillez sélectionner une devise...");
				return false;
			}
			if (coord_bank_country.value == 'US' && coord_iban_route.value == '')
			{
				alert("Vous devez spécifier le n° de route...");
				coord_iban_route.focus();
				return false;
			}
		}
		if (coord_card_owner.value == '')
		{
			alert("Vous devez spécifier le titulaire de la carte...");
			coord_card_owner.focus();
			return false;
		}
		if (coord_card_number.value == '')
		{
			alert("Vous devez spécifier le numéro de la carte...");
			coord_card_number.focus();
			return false;
		}
		if (coord_card_crypto.value == '')
		{
			alert("Vous devez spécifier le cryptogramme de la carte...");
			coord_card_crypto.focus();
			return false;
		}
	}
	
	return true;
}

function addAdditionalTax(currency, frequency)
{
	var nb_additional_taxes = parseInt($('nb_additional_taxes').value)+1;
	var new_tr = document.createElement('tr');
	new_tr.setAttribute('id', "additional_tax"+nb_additional_taxes);
	var new_td1 = document.createElement('td');
	new_td1.innerHTML = "<input type=\"textbox\" name=\"additional_tax_amount"+nb_additional_taxes+"\" id=\"additional_tax_amount"+nb_additional_taxes+"\" size=\"5\" /> "+currency+" "+frequency+" par personne supplémentaire à partir de <input type=\"textbox\" name=\"additional_tax_from_nb"+nb_additional_taxes+"\" id=\"additional_tax_from_nb"+nb_additional_taxes+"\" size=\"2\" /> personnes(s)";
	var new_td2 = document.createElement('td');
	new_td2.setAttribute('align', 'right');
	new_td2.innerHTML = "<a id=\"remove_additional_tax_link"+nb_additional_taxes+"\" href=\"javascript:void(0);\" onClick=\"removeAdditionalTax("+nb_additional_taxes+")\">Supprimer</a>";
	new_tr.appendChild(new_td1);
	new_tr.appendChild(new_td2);
	$('additional_tax_amount').tBodies[0].appendChild(new_tr);
	$('nb_additional_taxes').value = nb_additional_taxes;
}

function removeAdditionalTax(index)
{
	$('additional_tax_amount').tBodies[0].removeChild($('additional_tax'+index));
}

function submitPrix22(page, id, housing_id, custom_type_id)
{
	var nb_additional_taxes = parseInt($('nb_additional_taxes').value);
	var additional_taxes = '';
	var nb_babies_taxes = parseInt($('nb_babies_taxes').value);
	var babies_taxes = '';
	var nb_children_taxes = parseInt($('nb_children_taxes').value);
	var children_taxes = '';
	var nb_kids_taxes = parseInt($('nb_kids_taxes').value);
	var kids_taxes = '';
	var additional_index = 0;
	if (!$('no_additional_tax').checked)
	{
		for (var i=0; i <= nb_additional_taxes; i++)
		{
			if ($('additional_tax_amount'+i))
			{
				additional_taxes += '&additional_tax_amount'+additional_index+'='+$('additional_tax_amount'+i).value;
				additional_taxes += '&additional_tax_from_nb'+additional_index+'='+$('additional_tax_from_nb'+i).value;
				additional_index++;
			}
		}
	}
	var babies_index = 0;
	if (!$('no_babies_tax').checked)
	{
		for (var i=0; i <= nb_babies_taxes; i++)
		{
			if ($('babies_tax_amount'+i))
			{
				babies_taxes += '&babies_tax_amount'+babies_index+'='+$('babies_tax_amount'+i).value;
				babies_taxes += '&babies_tax_from_nb'+babies_index+'='+$('babies_tax_from_nb'+i).value;
				babies_index++;
			}
		}
	}
	var children_index = 0;
	if (!$('no_children_tax').checked)
	{
		for (var i=0; i <= nb_children_taxes; i++)
		{
			if ($('children_tax_amount'+i))
			{
				children_taxes += '&children_tax_amount'+children_index+'='+$('children_tax_amount'+i).value;
				children_taxes += '&children_tax_from_nb'+children_index+'='+$('children_tax_from_nb'+i).value;
				children_index++;
			}
		}
	}
	var kids_index = 0;
	if (!$('no_kids_tax').checked)
	{
		for (var i=0; i <= nb_kids_taxes; i++)
		{
			if ($('kids_tax_amount'+i))
			{
				kids_taxes += '&kids_tax_amount'+kids_index+'='+$('kids_tax_amount'+i).value;
				kids_taxes += '&kids_tax_from_nb'+kids_index+'='+$('kids_tax_from_nb'+i).value;
				kids_index++;
			}
		}
	}
	display('inner_edit_accomodation', '_includes/fr/manager-config/'+page+'.php', 'id='+id+'&housing_id='+housing_id+'&custom_type_id='+custom_type_id+'&no_stay_tax='+document.edit_accomodation.no_stay_tax.checked+'&stay_tax_amount='+document.edit_accomodation.stay_tax_amount.value+'&stay_tax_type='+document.edit_accomodation.stay_tax_type.value+'&stay_tax_frequency='+document.edit_accomodation.stay_tax_frequency.value+'&stay_tax_adults='+document.edit_accomodation.stay_tax_adults.checked+'&stay_tax_kids='+document.edit_accomodation.stay_tax_kids.checked+'&stay_tax_children='+document.edit_accomodation.stay_tax_children.checked+'&stay_tax_babies='+document.edit_accomodation.stay_tax_babies.checked+'&single_tax_amount='+document.edit_accomodation.single_tax_amount.value+'&additional_tax_adults='+document.edit_accomodation.additional_tax_adults.checked+'&additional_tax_children='+document.edit_accomodation.additional_tax_children.checked+'&additional_tax_babies='+document.edit_accomodation.additional_tax_babies.checked+'&no_caution='+document.edit_accomodation.no_caution.checked+'&caution_amount='+document.edit_accomodation.caution_amount.value+'&no_single_tax='+document.edit_accomodation.no_single_tax.checked+'&no_additional_tax='+document.edit_accomodation.no_additional_tax.checked+'&no_babies_tax='+document.edit_accomodation.no_babies_tax.checked+'&no_children_tax='+document.edit_accomodation.no_children_tax.checked+'&no_kids_tax='+document.edit_accomodation.no_kids_tax.checked+additional_taxes+'&nb_additional_taxes='+additional_index+babies_taxes+'&nb_babies_taxes='+babies_index+children_taxes+'&nb_children_taxes='+children_index+kids_taxes+'&nb_kids_taxes='+kids_index);
}

function addBabiesTax(currency, frequency)
{
	var nb_babies_taxes = parseInt($('nb_babies_taxes').value)+1;
	var new_tr = document.createElement('tr');
	new_tr.setAttribute('id', "babies_tax"+nb_babies_taxes);
	var new_td1 = document.createElement('td');
	new_td1.innerHTML = "<input type=\"textbox\" name=\"babies_tax_amount"+nb_babies_taxes+"\" id=\"babies_tax_amount"+nb_babies_taxes+"\" size=\"5\" /> "+currency+" "+frequency+" par bébé à partir de <input type=\"textbox\" name=\"babies_tax_from_nb"+nb_babies_taxes+"\" id=\"babies_tax_from_nb"+nb_babies_taxes+"\" size=\"2\" /> bébé(s)";
	var new_td2 = document.createElement('td');
	new_td2.setAttribute('align', 'right');
	new_td2.innerHTML = "<a id=\"remove_babies_tax_link"+nb_babies_taxes+"\" href=\"javascript:void(0);\" onClick=\"removeBabiesTax("+nb_babies_taxes+")\">Supprimer</a>";
	new_tr.appendChild(new_td1);
	new_tr.appendChild(new_td2);
	$('babies_tax_amount').tBodies[0].appendChild(new_tr);
	$('nb_babies_taxes').value = nb_babies_taxes;
}

function removeBabiesTax(index)
{
	$('babies_tax_amount').tBodies[0].removeChild($('babies_tax'+index));
}

function addChildrenTax(currency, frequency)
{
	var nb_children_taxes = parseInt($('nb_children_taxes').value)+1;
	var new_tr = document.createElement('tr');
	new_tr.setAttribute('id', "children_tax"+nb_children_taxes);
	var new_td1 = document.createElement('td');
	new_td1.innerHTML = "<input type=\"textbox\" name=\"children_tax_amount"+nb_children_taxes+"\" id=\"children_tax_amount"+nb_children_taxes+"\" size=\"5\" /> "+currency+" "+frequency+" par enfant à partir de <input type=\"textbox\" name=\"children_tax_from_nb"+nb_children_taxes+"\" id=\"children_tax_from_nb"+nb_children_taxes+"\" size=\"2\" /> enfant(s)";
	var new_td2 = document.createElement('td');
	new_td2.setAttribute('align', 'right');
	new_td2.innerHTML = "<a id=\"remove_children_tax_link"+nb_children_taxes+"\" href=\"javascript:void(0);\" onClick=\"removeChildrenTax("+nb_children_taxes+")\">Supprimer</a>";
	new_tr.appendChild(new_td1);
	new_tr.appendChild(new_td2);
	$('children_tax_amount').tBodies[0].appendChild(new_tr);
	$('nb_children_taxes').value = nb_children_taxes;
}

function removeChildrenTax(index)
{
	$('children_tax_amount').tBodies[0].removeChild($('children_tax'+index));
}

function addKidsTax(currency, frequency)
{
	var nb_kids_taxes = parseInt($('nb_kids_taxes').value)+1;
	var new_tr = document.createElement('tr');
	new_tr.setAttribute('id', "kids_tax"+nb_kids_taxes);
	var new_td1 = document.createElement('td');
	new_td1.innerHTML = "<input type=\"textbox\" name=\"kids_tax_amount"+nb_kids_taxes+"\" id=\"kids_tax_amount"+nb_kids_taxes+"\" size=\"5\" /> "+currency+" "+frequency+" par adolescent à partir de <input type=\"textbox\" name=\"kids_tax_from_nb"+nb_kids_taxes+"\" id=\"kids_tax_from_nb"+nb_kids_taxes+"\" size=\"2\" /> adolescent(s)";
	var new_td2 = document.createElement('td');
	new_td2.setAttribute('align', 'right');
	new_td2.innerHTML = "<a id=\"remove_kids_tax_link"+nb_kids_taxes+"\" href=\"javascript:void(0);\" onClick=\"removeKidsTax("+nb_kids_taxes+")\">Supprimer</a>";
	new_tr.appendChild(new_td1);
	new_tr.appendChild(new_td2);
	$('kids_tax_amount').tBodies[0].appendChild(new_tr);
	$('nb_kids_taxes').value = nb_kids_taxes;
}

function removeKidsTax(index)
{
	$('kids_tax_amount').tBodies[0].removeChild($('kids_tax'+index));
}

function addAdditionalEmail()
{
	for (var i=1; i<=5; i++)
	{
		if ($('add_email_row'+i).style.display == 'none')
		{
			$('add_email_row'+i).style.display = '';
			$('active'+i).value = 1;
			break;
		}
	}
}

function removeAdditionalEmail(index)
{
	$('add_email_row'+index).style.display = 'none';
	$('active'+index).value = 0;
}

function checkEnter(e)
{
	var characterCode;

	if (e && e.which)
	{
		e = e;
		characterCode = e.which;
	}
	else
	{
		e = event;
		characterCode = e.keyCode;
	}

	if (characterCode == 13)
		return true;
	else
		return false;
}

function updateSearchNbSpec()
{
	with (document.search)
	{
		if (search_nb_persons.value == '0')
			$('search_nb_specifics').style.display = 'none';
		else
		{
			$('search_nb_adults').options.length = 0;
			for (var i=0; i<= search_nb_persons.value; i++)
				$('search_nb_adults').options[$('search_nb_adults').options.length] = new Option(i, i);
			$('search_nb_children').options.length = 0;
			for (var i=0; i<= search_nb_persons.value; i++)
				$('search_nb_children').options[$('search_nb_children').options.length] = new Option(i, i);
			$('search_nb_specifics').style.display = '';
		}
	}
}

function updateAdvancedSearch()
{
	with (document.search)
	{
		if (advanced_search.value == '0')
		{
			advanced_search.value = 1;
			$('advanced_search_field').style.display = '';
		}
		else
		{
			advanced_search.value = 0;
			$('advanced_search_field').style.display = 'none';
		}
	}
}

// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1)
		return false
	if (strMonth.length<1 || month<1 || month>12)
		return false
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month])
		return false
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear)
		return false
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false)
		return false
return true
}

function checkSearch()
{
	with (document.search)
	{
		if (!isDate(search_arrival_date.value))
		{
			alert("La date d'arrivée doit être au format 'JJ/MM/AAAA'...");
			search_arrival_date.focus();
			return false;
		}
		if (parseInt(search_nb_persons.value) > 0)
		{
			if (parseInt(search_nb_adults.value)+parseInt(search_nb_children.value) != parseInt(search_nb_persons.value))
			{
				alert("Le nombre d'adultes et d'enfants doit être égal au nombre total de personnes...");
				return false;
			}
		}
	}
	return true;
}

function checkReservation()
{
	with (document.reservation)
	{
		if (!isDate(search_arrival_date.value))
		{
			alert("La date d'arrivée doit être au format 'JJ/MM/AAAA'...");
			search_arrival_date.focus();
			return false;
		}
		if (first_name.value == '')
		{
			alert("Vous devez préciser votre prénom...");
			first_name.focus();
			return false;
		}
		if (last_name.value == '')
		{
			alert("Vous devez préciser votre nom de famille...");
			last_name.focus();
			return false;
		}
		if (card_number.value == '')
		{
			alert("Vous devez préciser le numéro de votre carte bancaire...");
			card_number.focus();
			return false;
		}
		if (crypto.value == '')
		{
			alert("Vous devez préciser le cryptogramme de votre carte bancaire...");
			crypto.focus();
			return false;
		}
	}
}

function updateChildrenSearch(nb_children)
{
	$('children_search_td').innerHTML = '';
	var html_content = '';
	for (var i=0; i<nb_children; i++)
	{
		html_content = '';
		html_content += '&nbsp;Enfant '+(i+1)+' : ';
		html_content += '<select name="child_age'+(i+1)+'">';
		html_content += '<option value="-1">- ? -</option>';
		html_content += '<option value="0"><1</option>';
		html_content += '<option value="1">1</option>';
		html_content += '<option value="2">2</option>';
		html_content += '<option value="3">3</option>';
		html_content += '<option value="4">4</option>';
		html_content += '<option value="5">5</option>';
		html_content += '<option value="6">6</option>';
		html_content += '<option value="7">7</option>';
		html_content += '<option value="8">8</option>';
		html_content += '<option value="9">9</option>';
		html_content += '<option value="10">10</option>';
		html_content += '<option value="11">11</option>';
		html_content += '<option value="12">12</option>';
		html_content += '<option value="13">13</option>';
		html_content += '<option value="14">14</option>';
		html_content += '<option value="15">15</option>';
		html_content += '<option value="16">16</option>';
		html_content += '<option value="17">17</option>';
		html_content += '<option value="18">18</option>';
		html_content += '</select><br />';
		$('children_search_td').innerHTML += html_content;
	}
	$('children_search_tr').style.display = '';
}

function updateDaysFromMonth(element_id, month)
{
	var day_select = $(element_id);
	var current_value = day_select.selectedIndex;

	day_select.options.length = 0;
	var option_value;
	while (day_select.options.length < nb_days_by_month[month])
	{
		option_value = ''+(day_select.length+1);
		if (day_select.length+1 < 10)
			option_value = '0'+(day_select.length+1);
		day_select.options[day_select.options.length] = new Option(day_select.length+1, option_value);
	}
	
	if (day_select.options.length > current_value)
		day_select.selectedIndex = current_value;
	else
		day_select.selectedIndex = day_select.options.length-1;
}