/* ############################################################################################################ ############################################################################################################ © Copyright 2022 - Guide of US, LLC and Guide of Hawaii, LLC - All Rights Reserved Developed by: John C. Derrick This script may not be copied or reproduced without permission from Guide of US, LLC. Inspiration for this script originated from the 'Simple Price Calculator' script developed by Femy Praseeth. ############################################################################################################ ############################################################################################################ */ //Include the CSS var head = document.getElementsByTagName('HEAD')[0]; var link = document.createElement('link'); link.rel = 'stylesheet'; link.type = 'text/css'; link.href = 'https://aws.hawaii-guide.com/files/css/budget-calculator-v3.css'; head.appendChild(link); //set the maximum allowed non-premium calculator submissions var calcTimes = 5; var calcTimesHalf = calcTimes * 0.5; var currentGasPrice = 4.25; //Tab Control - load this early to avoid flashing screen var currentTab = 0; // Current tab is set to be the first tab (0) showTab(currentTab); // Display the current tab function showTab(n) { // This function will display the specified tab of the form ... var x = document.getElementsByClassName("tab"); x[n].style.display = "block"; // ... and fix the Previous/Next buttons: if (n == 0) { document.getElementById("prevBtn").style.display = "none"; } else { document.getElementById("prevBtn").style.display = "inline"; } if (n == (x.length - 1)) { document.getElementById("nextBtn").style.display = "none"; document.getElementById("prevBtn").style.display = "none"; document.getElementById("steps").style.display = "none"; } else { document.getElementById("nextBtn").innerHTML = "Next »"; } // ... and run a function that displays the correct step indicator: fixStepIndicator(n); } function nextPrev(n) { // This function will figure out which tab to display var x = document.getElementsByClassName("tab"); // Exit the function if any field in the current tab is invalid: if (n == 1 && !validateForm()) return false; // Hide the current tab: x[currentTab].style.display = "none"; // Increase or decrease the current tab by 1: currentTab = currentTab + n; // if you have reached the end of the form... : if (currentTab >= x.length) { //...the form gets submitted: // return false; } // Otherwise, display the correct tab: showTab(currentTab); } function validateForm() { // This function deals with validation of the form fields var x, y, z, i, valid = true; x = document.getElementsByClassName("tab"); y = x[currentTab].getElementsByTagName("input"); z = x[currentTab].getElementsByTagName("select"); // A loop that checks every input field in the current tab: for (i = 0; i < y.length; i++) { // If a field is empty... if (y[i].value == "" ) { // add an "invalid" class to the field: y[i].className += " invalid"; // and set the current valid status to false: valid = false; } } for (i = 0; i < z.length; i++) { // If a field is empty... if (z[i].value == "" ) { // add an "invalid" class to the field: z[i].className += " invalid"; // and set the current valid status to false: valid = false; } } // If the valid status is true, mark the step as finished and valid: if (valid) { document.getElementsByClassName("step")[currentTab].className += " finish"; } return valid; // return the valid status } function fixStepIndicator(n) { // This function removes the "active" class of all steps... var i, x = document.getElementsByClassName("step"); for (i = 0; i < x.length; i++) { x[i].className = x[i].className.replace(" active", ""); } //... and adds the "active" class to the current step: if (i == x.length) { } else { x[n].className += " active"; } } // set Cookie Function function createCookieCalculator(cookieName, cookieValue, daysToExpire) { var date_estimate = new Date(); date_estimate.setTime(date_estimate.getTime() + (daysToExpire * 24 * 60 * 60 * 1000)); document.cookie = cookieName + "=" + cookieValue + "; expires=" + date_estimate.toGMTString() + "; path=/; secure"; } //Use logic to change values of future fields based on earlier inputs var inputa = document.getElementById('id_accommodation_nights'); var inputb = document.getElementById('id_days_rented'); inputa.addEventListener('change', function() { inputb.value = parseInt(inputa.value) + 1; }); var inputc = document.getElementById('id_number_travelers'); var inputd = document.getElementById('id_quantity_dining'); var inputf = document.getElementById('id_quantity_attractions'); inputc.addEventListener('change', function() { inputd.value = parseInt(inputc.value); inputf.value = parseInt(inputc.value); }); //check to see if user has taken quiz and has cookie - update announcements var calculator_form = document.getElementById("hawaii_budget_calculator"); var calculator_announcements = document.getElementById('announcements'); var calculator_announcements_footer = document.getElementById('announcements_footer'); var calculator_announcements_premium = document.getElementById('announcements_premium'); var premium_email = document.getElementById('premium_email'); var regular_email = document.getElementById('regular_email'); function getCalcCookie(cname) { let name = cname + "="; let ca = document.cookie.split(';'); for(let i = 0; i < ca.length; i++) { let c = ca[i]; while (c.charAt(0) == ' ') { c = c.substring(1); } if (c.indexOf(name) == 0) { return c.substring(name.length, c.length); } } return ""; } var premium_drip_email = getCalcCookie("premium_email"); var cookieCheck = getCalcCookie("calculator_times_taken"); //if the user is premium, their remaining times will never change, bc the cookies don't update below if (cookieCheck == '') { var cookieTimesTaken = 0; var cookieTimesRemaining = calcTimes; } else { var cookieTimesTaken = parseInt(getCalcCookie("calculator_times_taken"),10); var cookieTimesRemaining = parseInt(getCalcCookie("calculator_times_remaining"),10); } var remaining_html_footer = document.getElementById('remaining_footer'); var cookie = document.cookie; var premium = cookie.indexOf("hawaii-guide-adfree"); var calculator_form = document.getElementById("hawaii_budget_calculator"); document.getElementById("btn_trip_reset").style.display = 'none'; var remaining_text_verbiage = '' + cookieTimesRemaining + ' estimates remaining'; var remaining_text_critical_verbiage = '' + cookieTimesRemaining + ' estimates remaining'; if (premium > -1){ calculator_announcements.remove(); calculator_announcements_footer.remove(); } else if(cookieTimesRemaining == 0 ) { calculator_form.remove(); remaining_html_footer.innerHTML = remaining_text_critical_verbiage + '. Get HawaiiGuide Premiium →'; calculator_announcements_premium.remove(); } else if(cookieTimesTaken == ''){ //no cookie - first time remaining_html_footer.innerHTML = remaining_text_verbiage; calculator_announcements_premium.remove(); } else if(cookieTimesTaken > 0 && cookieTimesTaken < calcTimesHalf){ remaining_html_footer.innerHTML = remaining_text_verbiage; calculator_announcements_premium.remove(); } else if(cookieTimesTaken > 0 && cookieTimesTaken >= calcTimesHalf){ remaining_html_footer.innerHTML = remaining_text_critical_verbiage; calculator_announcements_premium.remove(); } if(premium_drip_email != ''){ var premium_email_html = document.getElementById('premium_email_html'); premium_email_html.innerHTML = "
Aloha, Welcome back! You've already provided your email address... click the button below to obtain your results.
"; regular_email.remove(); } else { premium_email.remove(); } // set Global vars var flight_departure = document.getElementById("id_flight_departure"); var accommodations_type = document.getElementById("id_accommodations_type"); var vehicle_type = document.getElementById("id_vehicle"); var whichMonth = document.getElementById("id_month_of_visit"); var whichYear = document.getElementById("id_year_of_visit"); var secondIsland = document.getElementById("id_second_island"); var island = document.getElementById("id_island"); var baggageFeeBox = document.getElementById("id_baggage_fee"); var parkingFeeBox = document.getElementById("id_parking_fees"); var MealBreakfast = document.getElementById("id_breakfast"); var MealLunch = document.getElementById("id_lunch"); var MealDinner = document.getElementById("id_dinner"); var NatParks = document.getElementById("id_national_parks"); var StateParks = document.getElementById("id_state_parks"); var OtherAttractions = document.getElementById("id_other_attractions"); if(premium > -1){ document.addEventListener('DOMContentLoaded', function(){ document.getElementById('hawaii_budget_calculator').addEventListener('submit', estimateTotal); }); } else if (cookieTimesRemaining > 0) { document.addEventListener('DOMContentLoaded', function(){ document.getElementById('hawaii_budget_calculator').addEventListener('submit', estimateTotal); }); } function estimateTotal(event) { event.preventDefault(); //remove these elements on submit document.getElementById("btn_trip_estimate").remove(); document.getElementById("btn_trip_reset").style.display = 'inline-block'; document.getElementById("final_questions").remove(); //premium_email.remove(); //whichMonth.remove(); //whichYear.remove(); //secondIsland.remove(); if( accommodations_type.value === ''){ accommodations_type.focus(); } // Set early vars var fuel_costs = document.querySelector('input[name=fuel_costs]:checked').value || 0; var tour_costs = document.querySelector('input[name=tours]:checked').value || 0; var number_travelers = document.getElementById("id_number_travelers").value; var accommodation_nights = document.getElementById("id_accommodation_nights").value; var rental_days = document.getElementById("id_days_rented").value; var accommodation_rooms = document.getElementById("id_accommodation_rooms").value; var qty_dining = document.getElementById("id_quantity_dining").value; var qty_attractions = document.getElementById("id_quantity_attractions").value; let email; if(premium_drip_email == ''){ email = document.getElementById("id_email_address").value; } else { email = premium_drip_email; } var taxes = document.querySelector('input[name=accommodation_taxes]:checked').value || ''; var taxCost, nightlyRate, islandModifier, flightRate, totalFlightPrice, totalAccommodationPrice, netAccommodationPrice, baggageFees, totalBaggageFee, parkingFees, totalParkingFee, netFlightPrice, finalestimate, estimate, remaining_text, remaining_text_critical, dailyRentalRate, fuelCost, HawaiiTours, totalVehiclePrice, netVehiclePrice, Breakfast, Lunch, Dinner, NtlPark, StParks, OtherAttr, netDiningPrice, totalDiningPrice, totalAttractionsPrice, AttractionsOther, TotalEstimate, which_month, which_year, which_second_island; if (flight_departure.value === 'East Coast'){ flightRate = 905.00; } else if(flight_departure.value ==='West Coast'){ flightRate = 480.00; } else if(flight_departure.value ==='MidWest'){ flightRate = 780.00; } else if(flight_departure.value ==='International'){ flightRate = 1060.00; } if (baggageFeeBox.checked == true){ baggageFees = baggageFeeBox.value; } else { baggageFees = 0; } if (parkingFeeBox.checked == true){ parkingFees = parkingFeeBox.value; } else { parkingFees = 0; } if (MealBreakfast.checked == true){ Breakfast = MealBreakfast.value; } else { Breakfast = 0; } if (MealLunch.checked == true){ Lunch = MealLunch.value; } else { Lunch = 0; } if (MealDinner.checked == true){ Dinner = MealDinner.value; } else { Dinner = 0; } if (NatParks.checked == true){ NtlPark = NatParks.value; } else { NtlPark = 0; } if (StateParks.checked == true){ StParks = StateParks.value; } else { StParks = 0; } if (OtherAttractions.checked == true){ OtherAttr = OtherAttractions.value; } else { OtherAttr = 0; } if (accommodations_type.value === 'Hotel'){ nightlyRate = 330; } else if(accommodations_type.value ==='Resort'){ nightlyRate = 435; } else if(accommodations_type.value ==='BB-Inn'){ nightlyRate = 180; } else if(accommodations_type.value ==='VR'){ nightlyRate = 160; } else if(accommodations_type.value ==='Undecided'){ nightlyRate = 335; } if (island.value === 'Oahu'){ islandModifier = 0.6855; } else if(island.value === 'Maui'){ islandModifier = 1.6322; } else if(island.value === 'Kauai'){ islandModifier = 0.9863; } else if(island.value === 'Big Island'){ islandModifier = 1.0590; } else if(island.value === 'Undecided'){ islandModifier = 1; } if (vehicle_type.value === 'Car'){ dailyRentalRate = 75; } else if(vehicle_type.value ==='SUV'){ dailyRentalRate = 120; } else if(vehicle_type.value ==='Convertable'){ dailyRentalRate = 130; } else if(vehicle_type.value ==='Luxury'){ dailyRentalRate = 160; } else if(vehicle_type.value ==='None'){ dailyRentalRate = 0; } else if(vehicle_type.value ==='Undecided'){ dailyRentalRate = 75; } which_month = whichMonth.value; which_year = whichYear.value; which_second_island = secondIsland.value; //Flight Costs netFlightPrice = parseInt(flightRate) * parseInt(number_travelers); totalBaggageFee = parseInt(baggageFees) * parseInt(number_travelers); totalFlightPrice = parseInt(netFlightPrice) + parseInt(totalBaggageFee); //Vehicle Rental Costs netVehiclePrice = parseInt(dailyRentalRate) * parseInt(rental_days); if(vehicle_type.value == 'None'){ fuelCost = 0; } else { fuelCost = currentGasPrice.toFixed(2) * parseInt(fuel_costs) * parseInt(rental_days); } totalVehiclePrice = parseInt(netVehiclePrice) + parseInt(fuelCost); //Accommodation Costs totalParkingFee = parseInt(parkingFees) * parseInt(accommodation_nights); netAccommodationPrice = parseInt(accommodation_nights) * parseInt(nightlyRate) * parseInt(accommodation_rooms) * islandModifier.toFixed(2); taxCost = (netAccommodationPrice * taxes) - netAccommodationPrice; totalAccommodationPrice = netAccommodationPrice + taxCost + totalParkingFee; //Dining Costs netDiningPrice = (parseInt(Breakfast) + parseInt(Lunch) + parseInt(Dinner)) * parseInt(qty_dining); totalDiningPrice = parseInt(netDiningPrice) * parseInt(rental_days); //Activity Costs HawaiiTours = parseInt(tour_costs); AttractionsOther = (parseInt(NtlPark) + parseInt(StParks) + parseInt(OtherAttr)) * parseInt(qty_attractions); totalAttractionsPrice = (parseInt(NtlPark) + parseInt(StParks) + parseInt(OtherAttr) + parseInt(HawaiiTours)) * parseInt(qty_attractions); remaining_text = '' + cookieTimesRemaining + ' estimates remaining'; remaining_text_critical = '' + cookieTimesRemaining + ' estimates remaining'; TotalEstimate = totalAccommodationPrice + totalFlightPrice + totalVehiclePrice + totalDiningPrice + totalAttractionsPrice; estimate = TotalEstimate.toLocaleString('en-US', {minimumFractionDigits: 0,maximumFractionDigits:0}); finalestimate = '$' +estimate; if (finalestimate == '$NaN') { //empty - no results } else { //output the results as HTML var result_html = document.getElementById('results'); result_html.innerHTML ='* This is an estimate based on our projections for 2022. Rates and prices are subject to change without notice.