(function() { // Crear e insertar el estilo CSS const style = document.createElement('style'); style.innerHTML = ` body { font-family: Arial, sans-serif; background-color: #f4f7f9; margin: 0; padding: 20px; } #travelCalcContainer { max-width: 800px; margin: 0 auto; padding: 20px; background-color: #ffffff; border: 2px solid #0074D9; border-radius: 10px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); } h1 { text-align: center; color: #0074D9; margin-bottom: 20px; font-size: 24px; } h3 { color: #0074D9; margin-bottom: 10px; } .form-group { margin-bottom: 15px; } label { display: block; margin-bottom: 5px; color: #333; font-weight: bold; } input, select { width: 100%; padding: 10px; border: 1px solid #ddd; border-radius: 5px; font-size: 16px; } .button-group { display: flex; justify-content: space-between; margin-top: 20px; } button { flex: 1; padding: 12px; background-color: #0074D9; color: #ffffff; border: none; border-radius: 5px; font-size: 18px; cursor: pointer; } button:hover { background-color: #005bb5; } .clear-button { background-color: #f44336; } .clear-button:hover { background-color: #d32f2f; } #result { margin-top: 20px; padding: 20px; background-color: #FF851B; color: white; border-radius: 5px; } #result h2, #result p { color: white; } .hidden { display: none; } .percent-input { position: relative; } .percent-input input { padding-right: 50px; } .percent-input::after { content: '%'; position: absolute; right: 20px; top: 50%; transform: translateY(-50%); color: #333; font-size: 16px; } `; document.head.appendChild(style); // Crear el contenido de la calculadora de costos de viaje const container = document.getElementById('travelCalcContainer'); container.innerHTML = `
The company will pay: $${companyPayment} USD
`; } // Calcular cuánto pagará cada viajero for (let i = 1; i <= numPeople; i++) { const paymentPercentage = parseFloat(document.getElementById(`person${i}`).value) || 100; const paymentPerPerson = (totalWithExtras * (paymentPercentage / 100)).toFixed(2); const paymentPerDay = (paymentPerPerson / numDays).toFixed(2); paymentDetailsDiv.innerHTML += `Traveler ${i} will pay: $${paymentPerPerson} USD (per day: $${paymentPerDay} USD)
`; } // Sugerencias de ahorro aleatorias const suggestions = [ "Consider booking your flights in advance for better prices.", "Look for accommodation discounts or bundle deals.", "Use public transportation instead of taxis to save money.", "Travel during the off-season to avoid peak prices.", "Share accommodation or rental costs with other travelers.", "Bring your own snacks to avoid high food prices at the airport.", "Use travel rewards or points to reduce the cost of flights or hotels.", "Check for free activities at your destination.", "Stay in hostels or budget hotels instead of luxury accommodations.", "Cook your own meals instead of eating out every day." ]; const randomIndex = Math.floor(Math.random() * suggestions.length); document.getElementById('savingsSuggestions').textContent = suggestions[randomIndex]; document.getElementById('result').classList.remove('hidden'); } // Validar que el total de los porcentajes no exceda el 100% function validateTravelerPercentages() { const numPeople = parseInt(document.getElementById('numPeople').value) || 1; let totalTravelerPercentage = 0; for (let i = 1; i <= numPeople; i++) { totalTravelerPercentage += parseFloat(document.getElementById(`person${i}`).value) || 0; } const companyPercentage = parseFloat(document.getElementById('companyPercentage').value) || 0; const totalPercentage = totalTravelerPercentage + companyPercentage; if (totalPercentage > 100) { alert("The total percentage exceeds 100%. Please adjust the percentages."); return false; } return true; } // Función para limpiar todos los campos function clearFields() { document.getElementById('numPeople').value = 1; document.getElementById('numChildren').value = 0; document.getElementById('tripType').value = ''; document.getElementById('numDays').value = 1; document.getElementById('flightCost').value = 0; document.getElementById('transportCost').value = 0; document.getElementById('accommodationCost').value = 0; document.getElementById('foodCost').value = 0; document.getElementById('extraCosts').value = 0; document.getElementById('companyPercentage').value = 0; document.getElementById('activitiesCost').value = 0; document.getElementById('percentageContainer').classList.add('hidden'); document.getElementById('percentageContainer').innerHTML = ''; document.getElementById('totalCost').textContent = ''; document.getElementById('paymentDetails').innerHTML = ''; document.getElementById('savingsSuggestions').textContent = ''; document.getElementById('result').classList.add('hidden'); } })();