// JavaScript Document
// 20 December 2005 
// [SDE] 11 Octobre 2007 
<!--
//
// INITIALISE FORM
// ---------------
var bookingForm, td_village, td_ville, dep_year, dep_month, dep_day, td_adultes, td_enfants, td_duree, num_of_guest, sortByZone, lb_enfants, td_enfant_1, td_enfant_2, td_enfant_3, td_enfant_4, td_enfant_5, zone_enfant,chp_enfants_cm, zoneArr;
function initBookingForm(formName, bHomePage) {

	bookingForm = document.forms[formName];
	td_village = bookingForm.td_village;
	td_ville = bookingForm.td_ville;
	dep_year = bookingForm.dep_year;
	dep_month = bookingForm.dep_month;
	dep_day = bookingForm.dep_day;
	td_adultes = bookingForm.td_adultes;
	td_enfants = bookingForm.td_enfants;
	td_enfant_1 = bookingForm.td_enfant_1;
	td_enfant_2 = bookingForm.td_enfant_2;
	td_enfant_3 = bookingForm.td_enfant_3;
	td_enfant_4 = bookingForm.td_enfant_4;
	td_enfant_5 = bookingForm.td_enfant_5;
	lb_enfants = bookingForm.lb_enfants;
	chp_enfants_cm = bookingForm.chp_enfants_cm;
	zone_enfant = bookingForm.zone_enfant;
	td_duree = bookingForm.td_duree;
	num_of_guest = bookingForm.num_of_guest;
	input_calendar=bookingForm.input_calendar;

	
	populateVillage();
	

	// GLA 07/07/2006 Gestion double clic : remise ? NOCLIC pour g?rer le back navigateur
	if (document.getElementById('clic')) {
		var clic = document.getElementById('clic');
		clic.value = "NOCLIC";
	}
}

//
// MAKE VILLAGE SELECTION
// ----------------------
function selectVillage(bHomePage) { //called when user change village selection
	populateCity(); //rebuild city drop down
	if (bHomePage)
		populateDate(); //rebuild date drop down
}

//
// Display Enfants
// ----------------------
//
function displayEnfants() { 

}

// POPULATE DATA TO FORM
// ----------------------
// populate village
function populateVillage() { //execute once only!
   td_village.options.length = 0;		
	if (sortByZone) {
		for (var j = 0; j < zoneArr.length; j++) {
			td_village.options.length += 1;
			var theZone = zoneArr[j];
			var theOption = td_village.options[td_village.options.length - 1];
			// Nom de la zone geographique
			theOption.text = theZone["zonelib"];
			theOption.value = "";
			theOption.disabled = true;
			// Villages de cette zone
			for (var i = 0; i < mVillages.length; i++) {
				var theData = mVillages[i];
//				setInfoVillage(theData.getAttribute("id"));						
//				if (theZone["zonecod"] == mTabVille["zone"]) {
                if (theZone["zonecod"] == theData.getAttribute("zone")) {
					td_village.options.length += 1;
					theOption = td_village.options[td_village.options.length - 1];
					theOption.text = "  "+decode_utf8_browser(theData.getAttribute("label") + ", " + theData.getAttribute("pays"));
					theOption.value = theData.getAttribute("id");
				}
			}
		}
		
		td_village.selectedIndex = 1;
} else {
		for (var i = 0; i < mVillages.length; i++) {
			td_village.options.length += 1;
			var theData = mVillages[i];
			var theOption = td_village.options[td_village.options.length - 1];
			//si c IE
			if (navigator.userAgent.toLowerCase().indexOf('msie') != -1) {
				
				theOption.text = (theData.getAttribute("label") + ", " + theData.getAttribute("pays"));
			} else {
				theOption.text = (theData.getAttribute("label") + ", " + theData.getAttribute("pays"));
			}	
			theOption.value = theData.getAttribute("id");
		}
		td_village.selectedIndex = 0;
	}
	td_village.disabled = false;
}

// populate city
function populateCity() { //execute when user change village selection
	var cityList;
	var defaultCity;
	td_ville.options.length = 1;
	td_ville.options[0].text = td_ville[0]["label"];
	td_ville.options[0].value = "";
	td_ville.selectedIndex = 0;
	

	if (sortByZone) {
		for (var i = 0; i < td_village.length; i++) {
			var theVillage = td_village[i];
			if (theVillage["id"] == td_village.value) {
				tabville = theVillage["ville"];
				defaultCity = theVillage["defaultville"];
				break;
			}
		}
		for (var i = 0; i < td_ville.length; i++) {
			var theData = td_ville.options[i]
			for (j = 0; j < tabville.length; j++) {
				var theCode = tabville[j];
				if (theCode == theData["code"]) {
					td_ville.options.length += 1;
					var theOption = td_ville.options[td_ville.options.length - 1];
					
					theOption.text = theData["label"];
					theOption.value = theData["code"];
					
					break; // GLA 04/05/2006 Evite les doublons des villes de depart
				}
			}
		}
	} else {
		if (td_ville.selectedIndex != -1) { //record selection by user
			var selectedCity = td_ville.options[td_ville.selectedIndex].value;
		} else {
			var selectedCity = "";
		}
//cityList = mVillages[td_village.selectedIndex].getAttribute("ville");
tabville = mVillages[td_village.selectedIndex+1].getAttribute("ville");

defaultCity = mTabVille["defaultVille"] //not required on japan
//for (var i = 0; i < td_ville.length; i++) {
for (var i = 0; i < mVilles.length; i++) {

			var theData = mVilles[i];
			for (j = 0; j < tabville.length; j++) {
				var theCode = tabville[j];
				if (theCode == theData["code"]) {
					td_ville.options.length += 1;
					var theOption = td_ville.options[td_ville.options.length - 1];
					
					theOption.text = theData["label"];
					theOption.value = theData["code"];
					
					if (selectedCity == theOption.value) { //reapply selection by user
						td_ville.selectedIndex = theOption.index;
						selectedCity = undefined;
					}
					break; // GLA 04/05/2006 Evite les doublons des villes de depart
				}
			}
		}
		// (commented away due to the default city not required on japan)
		if (selectedCity != undefined) { //when no selection by user, display default from system
			for (var k = 1; k < td_ville.options.length; k++) {
				var theOption = td_ville.options[k];
				if (defaultCity == theOption.value) {
					td_ville.selectedIndex = k;
					break;
				}
			}
		}
	}
	td_ville.disabled = false;
}


// populate guest
var maxPax = 6;
var minPax = 1;
var totalPax = 1;
function populateGuest(theSelect) {

}

function hideFieldsBirth(reset){

}
	
// Use this method to get guest DOB (Mozilla only support this method)
function get(eN) {
	if(document.getElementById) {
		return(eval('document.getElementById(\'' + eN + '\')'));
	} else {
		if (document.all) {
			return (eval('document.all.' + eN));
		}
	}
}
function set(eN, eV) {
	if(document.getElementById) {
		eval('document.getElementById(\'' + eN + '\').value=\'' + eV + '\'');
	} else {
		if (document.all) {
			eval('document.all.' + eN + '.value=\'' + eV + '\'');
		}
	}
}
function SetValuesInputsHidden(yy, mm, dd){
		document.getElementById("dep_year").value = yy
		document.getElementById("dep_month").value = mm
		document.getElementById("dep_day").value = dd
}
function putSpaceCalendar(){
	if (document.getElementById("spacecalendar")) {
		document.getElementById("spacecalendar").style.display="block"
	}
}
function remSpaceCalendar(){
	if (document.getElementById("spacecalendar")) {
		document.getElementById("spacecalendar").style.display="none"
	}
}
//-->