/**
 * sejourInit.js
 * @author Emmanuel Sammut (TS)
 * Last modified July 31, 2008 by Emmanuel Sammut (TS)
 */

/*
 * Defined constant of ID element.
 */
var NAME_BTN_SEARCH = "";
var ANCHOR_CAL_ID = document.getElementById('anchorCalendar');
var	DESTI_ID = document.getElementById('destination');
var CITY_DESTI_ID = document.getElementById('cityOfDestination');


/*
 * Calendar icon : onclick event
 */
ANCHOR_CAL_ID.onclick = function () {
	showCal('anchorCalendar');	
}


/**
 *  init button of form
 */
var NAME_BTN_SEARCH = "";
document.getElementById("search").value = NAME_BTN_SEARCH;

/**
 *  init title of form
 */
//var TITLE_H2_SEARCH = "Trouver votre séjour";
//document.getElementById("titleH2").innerHTML = TITLE_H2_SEARCH;

/**
 *  init button of form
 */
document.getElementById("search").value = NAME_BTN_SEARCH;

/**
 *  display the select box of the departure city or the check box for the witoutTransport
 */
function checkVisible() {
   // --- Check status of check box, if checked => display list
   if ( document.getElementById('withoutTransport').checked ){
	 document.getElementById('city').selectedIndex = 0;
     document.getElementById('city').disabled = true;
     document.getElementById('withoutTransport').value='XXX';
   }
   // --- Else disable list
   else {
     document.getElementById('city').disabled = false;
     document.getElementById('withoutTransport').value='';
   }
   ///alert(document.getElementById('withoutTransport').value);
	}

/**
 *  put the value 'oui' for the protion check box
 */
	function promotionvalue() {
   // --- Check status of check box, if checked => value='oui'
   if ( document.getElementById('onSale').checked ){
     document.getElementById('onSale').value='1';
   }
   // --- Else value=''
   else {
     document.getElementById('onSale').value='';
   }
   ///alert(document.getElementById('onSale').value);
	}

/*
 * Destination select : onchange event
 */
DESTI_ID.onchange = function () {
	if(this.value != '') {
		CITY_DESTI_ID.disabled = false;
		CITY_DESTI_ID.value = '';
		updateDepCities()
	} else {
		CITY_DESTI_ID.disabled = true;
		CITY_DESTI_ID.value = '';

	}
}

/**
* mise a jour de la liste des villes de depart
*/
function updateDepCities() {

	var citiesSelectBoxOptions = document.getElementById('cityOfDestination').options;
	var selectedCountryIndex = document.getElementById('destination').selectedIndex;

	citiesSelectBoxOptions.length = 0;
	citiesSelectBoxOptions[0] = new Option('Sélectionner une ville', '');

	if (selectedCountryIndex >= 1) {
		var citiesList = destCities[selectedCountryIndex - 1];
		var i;
		for (i = 0; i < citiesList.length; i++) {
			var city = citiesList[i];
			var separatorIndex = city.indexOf('||');
			var cityCode = city.substring(0, separatorIndex);
			var cityLabel = city.substring(separatorIndex + 2, city.length);
			citiesSelectBoxOptions[citiesSelectBoxOptions.length] = new Option(cityLabel, cityCode);
		}
	}
}

	
