// Bouton "Switch to the Van" du bandeau confort (choix du client)
document.addEventListener('click', function (e) {
if (!e.target || e.target.id !== 'switchToVan') return;
const sed = document.getElementById('veh_sedan');
const van = document.getElementById('veh_van');
if (!van || van.disabled) return;
van.checked = true;
if (sed) sed.checked = false;
autoUpgraded = false;
syncVehicleSelected();
window.calculateTotalPrice?.();
checkLoad();
});
/* ---------------------------------------------------------------
Sieges enfants : 2 offerts, puis 10 € par siege supplementaire
--------------------------------------------------------------- */
function updateSeatNotice() {
const box = document.getElementById('seatNotice');
if (!box) return;
const cfg = window.CHILD_SEAT_FEE || { freeSeats: 2, fee: 10 };
const qty = window.billableSeats ? window.billableSeats() : 0;
const fee = window.childSeatFee ? window.childSeatFee() : 0;
if (!qty) { box.className = 'notice hidden'; box.innerHTML = ''; return; }
const totalSeats = intVal('child_seats') + intVal('booster_seats');
box.className = 'notice notice--seat';
box.innerHTML = 'You have selected ' + totalSeats + ' child seats. ' +
'The first ' + cfg.freeSeats + ' are free — €' + fee + ' has been added for the ' +
qty + ' extra seat' + (qty > 1 ? 's' : '') + ' (€' + cfg.fee + ' each).';
}
['luggages','child_seats','booster_seats'].forEach(function (n) {
document.querySelector('[name="' + n + '"]')?.addEventListener('change', function () {
checkLoad();
window.calculateTotalPrice?.();
updateSeatNotice();
});
});
/* ---------------------------------------------------------------
Reservation de derniere minute : supplement + explication
--------------------------------------------------------------- */
function updateLateNotice() {
const box = document.getElementById('lateNotice');
if (!box) return;
const cfg = window.LATE_BOOKING || { hours: 12, fee: 30 };
const fee = window.lateBookingFee ? window.lateBookingFee() : 0;
if (!fee) { box.className = 'notice hidden'; box.innerHTML = ''; return; }
box.className = 'notice notice--info';
box.innerHTML = 'This is a short-notice booking — less than ' + cfg.hours +
' hours before pickup. We are in peak season and assigning a driver at that notice is difficult, ' +
'so a €' + cfg.fee + ' short-notice fee has been added to your total. ' +
'Booking earlier avoids it.';
}
/* ---------------------------------------------------------------
Trajet de nuit : 22h00 -> 05h00, +30 € par trajet concerne
--------------------------------------------------------------- */
function pad2(n) { return (n < 10 ? '0' : '') + n; }
function updateNightNotice() {
const box = document.getElementById('nightNotice');
if (!box) return;
const cfg = window.NIGHT_FEE || { startHour: 22, endHour: 5, fee: 30 };
const legs = window.nightLegs ? window.nightLegs() : 0;
const fee = window.nightFee ? window.nightFee() : 0;
if (!legs) { box.className = 'notice hidden'; box.innerHTML = ''; return; }
const window_ = pad2(cfg.startHour) + ':00 and ' + pad2(cfg.endHour) + ':00';
box.className = 'notice notice--night';
box.innerHTML = 'Night transfer — ' +
(legs > 1 ? 'both your pickup and your return are' : 'your pickup is') +
' between ' + window_ + '. A €' + cfg.fee + ' night surcharge' +
(legs > 1 ? ' per journey (€' + fee + ' in total)' : '') +
' has been added to your total.';
}
['pickup_date','pickup_time','return_date','return_time'].forEach(function (id) {
document.getElementById(id)?.addEventListener('change', function () {
window.calculateTotalPrice?.();
updateLateNotice();
updateNightNotice();
});
});
/* ---------------------------------------------------------------
Indicatif telephonique : on prefixe le numero avant l'envoi
--------------------------------------------------------------- */
document.getElementById('bookingForm')?.addEventListener('submit', function () {
const code = document.getElementById('phone_code');
const tel = document.getElementById('phone');
if (!code || !tel) return;
let num = (tel.value || '').trim();
if (!num) return;
if (num.charAt(0) === '+') return; // deja international
if (code.value === '+other') return; // le client saisit tout
num = num.replace(/^0+/, '').replace(/[\s.-]/g, '');
tel.value = code.value + num;
});
document.getElementById('pickup')?.addEventListener('change', () => { toggleExtraBoxes(); window.calculateTotalPrice?.(); });
document.getElementById('dropoff')?.addEventListener('change', () => { toggleExtraBoxes(); window.calculateTotalPrice?.(); });
document.getElementById('passengers')?.addEventListener('change', () => { updateVehicleUI(); window.calculateTotalPrice?.(); syncVehicleSelected(); syncGroupSelected(); checkLoad(); updateSeatNotice(); });
document.getElementById('pickup_disney_hotel')?.addEventListener('change', () => toggleOther('pickup_disney_hotel','pickupDisneyOtherBox','pickup_disney_other'));
document.getElementById('dropoff_disney_hotel')?.addEventListener('change', () => toggleOther('dropoff_disney_hotel','dropoffDisneyOtherBox','dropoff_disney_other'));
document.getElementById('pickup_paris_train_station')?.addEventListener('change', () => toggleOther('pickup_paris_train_station','pickupParisTrainOtherBox','pickup_paris_train_other'));
document.getElementById('dropoff_paris_train_station')?.addEventListener('change', () => toggleOther('dropoff_paris_train_station','dropoffParisTrainOtherBox','dropoff_paris_train_other'));
document.querySelectorAll('input[name="vehicle"], input[name="vehicle_sub"]').forEach(el => {
el.addEventListener('change', () => { autoUpgraded = false; window.calculateTotalPrice?.(); syncVehicleSelected(); syncGroupSelected(); checkLoad(); });
});
document.addEventListener('change', e => {
if (e.target?.matches('input[name="vehicle"]')) syncVehicleSelected();
if (e.target?.matches('input[name="vehicle_sub"]')) { syncGroupSelected(); const v = document.getElementById('vehicle_sub'); if (v) v.value = e.target.value; }
});
// INIT
toggleExtraBoxes();
toggleOther('pickup_disney_hotel','pickupDisneyOtherBox','pickup_disney_other');
toggleOther('dropoff_disney_hotel','dropoffDisneyOtherBox','dropoff_disney_other');
toggleOther('pickup_paris_train_station','pickupParisTrainOtherBox','pickup_paris_train_other');
toggleOther('dropoff_paris_train_station','dropoffParisTrainOtherBox','dropoff_paris_train_other');