/* Variables */
var code;

function changeDateTimesIndex(currentFareId, timeLength){
	for(var i=0; i<timeLength; i++){
		var selectToHide = document.getElementById("timesIndex_"+currentFareId+"_"+i);
		if(selectToHide != null){
			if(i != dateTimesIndex){
				selectToHide.className = "displayNone";
			}else{
				selectToHide.className = "displayInline";
			}
		}
	}
}

function removeBookedExtra (extraKey, responseId){
	var actionForm = document.getElementById("actionForm");
	actionForm.actionToDo.value = "extraRemove";
	actionForm.extraKey.value = extraKey;
	actionForm.responseId.value = responseId;
	actionForm.submit();
}

function processExtraSelect(extraKey, responseId){
	var actionForm = document.getElementById("actionForm");
	if(extraKey == "transfer"){
		actionForm.action = "result-search-extra.htm#transferSelectedRecap" 
	}else{
		actionForm.action = "result-search-extra.htm#activitySelectedRecap" 
	}
	actionForm.actionToDo.value = "extraselect";
	actionForm.extraKey.value = extraKey;
	actionForm.responseId.value = responseId;
	actionForm.submit();
}

function processExtraBooking(actionToDo){
	var actionForm = document.getElementById("actionForm");
	actionForm.actionToDo.value = actionToDo;
	actionForm.submit();
}


function launchTransferSearch(){
	//Formatage de l'heure
	var trSens = document.getElementById('transferSens').value;
	var hoursId, minId, timeId;
	if(trSens == 0){
		hoursId = "allerRamassageTimeHours";
		minId = "allerRamassageTimeMinutes";
		timeId = "allerRamassageTime";
	}else{
		hoursId = "retourDeposeTimeHours";
		minId = "retourDeposeTimeMinutes";
		timeId = "retourDeposeTime";
	}
	var hoursInput = document.getElementById(hoursId);
	var minInput = document.getElementById(minId);
	var timeInput = document.getElementById(timeId);
	
	if(hoursInput != null && hoursInput.value != ""){
		if(minInput != null && minInput.value != ""){
			document.getElementById(timeId).value = hoursInput.value + "." + minInput.value
			var actionForm = document.getElementById("actionForm");
			actionForm.actionToDo.value = "launchsearch";
			var transferSens = actionForm.transferSens.value; 
			showWaitDisplay('wait','search',false);
		    actionForm.submit();
		    return;
		}
	}
	alert("Merci de renseigner une heure pour votre transfert.");
}

function toggleInfos(ind){
	if(document.getElementById('plusDinfos'+ind).innerHTML == "+ d'infos"){
		document.getElementById('plusDinfos'+ind).innerHTML = "- d'infos";
		nav = navigator.appName;
		if( nav == "Microsoft Internet Explorer"){	
			document.getElementById('bodyPlusDinfos'+ind).style.display = "inline-block";
		}else{
			document.getElementById('bodyPlusDinfos'+ind).style.display = "table-row";
		}
	}else{
		document.getElementById('plusDinfos'+ind).innerHTML = "+ d'infos";
		document.getElementById('bodyPlusDinfos'+ind).style.display = "none";
	}
}
	
function toggleDetailsPrix(ind, listSize){
	if(document.getElementById('detailsPrixLink'+ind).title == "detailsPrixLinkClosed"){
		document.getElementById('detailsPrixLink'+ind).innerHTML = "Grille tarifaire <<";
		document.getElementById('detailsPrixLink'+ind).title = "detailsPrixLinkOpen";
		//document.getElementById('detailsPrixEnTete'+ind).style.display = "table-row";
		for(var i=0; i<listSize; i++){
			document.getElementById('detailsPrix'+ind+"_"+i).style.display = "table-row";
		}
	}else{
		document.getElementById('detailsPrixLink'+ind).innerHTML = ">> Grille tarifaire";
		document.getElementById('detailsPrixLink'+ind).title = "detailsPrixLinkClosed";
		//document.getElementById('detailsPrixEnTete'+ind).style.display = "none";
		for(var i=0; i<listSize; i++){
			document.getElementById('detailsPrix'+ind+"_"+i).style.display = "none";
		}
	}
}

function toggleGoBack(id){
	if(id == "toggleGoTransfer"){
		if(document.getElementById("tableTo"+id).style.display == "none"){
			document.getElementById("tableTo"+id).style.display = "block";
		}else{
			document.getElementById("tableTo"+id).style.display = "none";
		}
	}
	if(id == "toggleReturnTransfer"){
		if(document.getElementById("tableTo"+id).style.display == "none"){
			document.getElementById("tableTo"+id).style.display = "block";
		}else{
			document.getElementById("tableTo"+id).style.display = "none";
		}
	}
}

function showTableRow(idDiv){
	var div = document.getElementById(idDiv);
	var etat = div.style.display;
	if(etat == "table-row" || etat == "inline-block"){
		div.style.display = "none";
	}else{
		nav = navigator.appName;
		if( nav == "Microsoft Internet Explorer"){	
			div.style.display = "inline-block";
		}else{
			div.style.display = "table-row";
		}
	}
}

function changeTransferQuantity(buttonId, quantityId){
	var currentQuantity = document.getElementById(quantityId).value;
	if(buttonId.startsWith('add')){
		currentQuantity++;
		document.getElementById(quantityId).value = currentQuantity;
	}else{
		if(currentQuantity > 1){
			currentQuantity--;
			document.getElementById(quantityId).value = currentQuantity;
		}
	}
}
