var secon = 35; // initialise les secondes avec 35 par défaut

function getVar(nomVariable) {
	var infos = location.href.substring(location.href.indexOf("?") + 1, location.href.length) + "&";
	if (infos.indexOf("#") != -1) {
		infos = infos.substring(0, infos.indexOf("#")) + "&";
	}
	var variable = null;
	nomVariable = nomVariable + "=";
	var taille = nomVariable.length;
	if (infos.indexOf(nomVariable) != -1) {
		variable = infos.substring(infos.indexOf(nomVariable) + taille, infos.length).substring(0, infos.substring(infos.indexOf(nomVariable) + taille, infos.length).indexOf("&"));
	}
	return variable;
}

function chrono() {
	secon--;
	var timerValue = document.getElementById("timerValue");
	if (timerValue != null) {
		timerValue.value = " " + secon; // on affiche les secondes
	}
	if (secon >= 4) {	
		compte = setTimeout('chrono()', 1000); // la fonction est relancée toutes les secondes
	}
}

function initTimer() {
	if (getVar("timerStart") != null) {
		secon = getVar("timerStart");
	}
	var isPackage = document.getElementById("isPackage");
	var isMap = document.getElementById("isMap");
	var searchWhere = "";
	// si recherche par adresse par ville ou par poi
		if(document.getElementById("name0") != null){
			searchWhere = document.getElementById("name0").value;
		}
	var searchBeginDate = document.getElementById("byDayBeginDate").value;
	var searchEndDate = document.getElementById("byDayEndDate").value;
	
	var waitSearchLeft = document.getElementById("waitSearchLeft");
	if (waitSearchLeft!=null) {
		var innerHtmlText = searchWhere + "<br/>du " + searchBeginDate + " au " + searchEndDate;
		waitSearchLeft.innerHTML = innerHtmlText;
	}
	/* Informations de vol*/
	if(isPackage != null && isPackage.value == "true"){
		if(document.getElementById("departureName") != null && document.getElementById("arrivalName") != null){
			var aeroportDeparture = document.getElementById("departureName").value;
			var aeroportArrival = document.getElementById("arrivalName").value;
		}
		var waitStartAirport = document.getElementById("waitStartAirport");
		var titleWaitStartAirport =  document.getElementById("titleWaitStartAirport");
		if (waitStartAirport!=null && titleWaitStartAirport != null) {
			waitStartAirport.innerHTML = aeroportDeparture;
			titleWaitStartAirport.innerHTML = "Aéroport de départ : ";
		}
		var waitEndAirport = document.getElementById("waitEndAirport");
		var titleWaitEndAirport =  document.getElementById("titleWaitEndAirport");
		if (waitEndAirport!=null && titleWaitStartAirport != null) {
			waitEndAirport.innerHTML = aeroportArrival;
			titleWaitEndAirport.innerHTML = "Aéroport d'arrivée : ";
			
		}
	}
	
	var titleWaitSearchWhere =  document.getElementById("titleWaitSearchWhere");
	var waitSearchWhere = document.getElementById("waitSearchWhere");
	if(isMap != null && isMap.value == "false"){
		if (waitSearchWhere!=null && titleWaitSearchWhere!=null) {
			waitSearchWhere.innerHTML = searchWhere;
			titleWaitSearchWhere.innerHTML = "Destination : ";
		}
	}
	
	var waitSearchBeginDate = document.getElementById("waitSearchBeginDate");
	if (waitSearchBeginDate!=null) {
		waitSearchBeginDate.innerHTML = searchBeginDate;
	}

	var waitSearchEndDate = document.getElementById("waitSearchEndDate");
	if (waitSearchEndDate!=null) {
		waitSearchEndDate.innerHTML = searchEndDate;
	}
	
	var waitSearchRight = document.getElementById("waitSearchRight");
	if (waitSearchRight!=null) {
		var innerHtmlRepartition = "";
		var roomsNumber = document.getElementById("roomsNumber").value;
		for (var index=0; index<roomsNumber; index++) {
			var numRoom = index + 1;
			innerHtmlRepartition += "Chambre " + numRoom + " : " + document.getElementById("roomAdults[" + index+"]").value + " adulte(s)";
			var nbChild = document.getElementById("roomChildren[" + index+"]").value;
			//var nbInfant = document.getElementById("roomInfants[" + index+"]").value;
			if (nbChild>0) {
//				if (nbInfant>0){
//					innerHtmlRepartition += ", " + nbChild + " enfant(s)";
//				} else {
					innerHtmlRepartition += " et " + nbChild + " enfant(s)";
//				}
			}
//			if (nbInfant>0) {
//				innerHtmlRepartition += " et " + nbInfant + " bébé(s)";
//			}
			innerHtmlRepartition += "<br>";
		}
		waitSearchRight.innerHTML = innerHtmlRepartition;
	}
	
	showWaitDisplay('wait-anim', null, null);
	var timerZone = document.getElementById("timerZone");
	timerZone.style.display = "block";
	timerZone.style.visibility = "visible";
	chrono();
}
