text: (function () {
      'use strict'
  
      const form = document.getElementById('filterForm');
      const dateInput = document.getElementById('date-filter');
      const invalidDateAlarm = document.getElementById('invalidDateAlarm');
  
      dateInput.addEventListener('change', function (event) {
  
          const forecastDay = dateInput.value.split('-');
          var today = new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate());
          dateInput.classList.remove('is-invalid');
          dateInput.classList.remove('is-valid');
  
          const validFormat = isValidDate(forecastDay);
          const validValue = withinRange(forecastDay);
          if (validFormat && validValue) {
               if (!form.checkValidity()) {
                   form.classList.add('was-validated');
               }
          } else if(!validValue){
              dateInput.classList.add('is-invalid');
              invalidDateAlarm.innerHTML = `Date of the trip must be from ${getDateFormat(today)} to ${getDateFormat(today.addDays(7))}`
          } else {
              dateInput.classList.add('is-invalid');
         }
       })
  
     form.addEventListener('submit', function (event) {
  
          const forecastDay = dateInput.value.split('-');
          var today = new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate());
         dateInput.classList.remove('is-invalid');
         dateInput.classList.remove('is-valid');
  
         const validFormat = isValidDate(forecastDay);
         const validValue = withinRange(forecastDay);
        if (validFormat && validValue) {
              if (!form.checkValidity()) {
                  event.preventDefault();
                  event.stopPropagation();
                  form.classList.add('was-validated');
              }
         } else if(!validValue){
              dateInput.classList.add('is-invalid');
              event.preventDefault();
              event.stopPropagation();
              invalidDateAlarm.innerHTML = `Date of the trip must be from ${getDateFormat(today)} to ${getDateFormat(today.addDays(7))}`
          } else {
              dateInput.classList.add('is-invalid');
              event.preventDefault();
              event.stopPropagation();
         }
  
      }, false)
  
  })()
  
  function isValidDate(dateArray) {
      if (dateArray.length !== 3) return false;
      var d = new Date(`${dateArray[0]}/${dateArray[1]}/${dateArray[2]}`);
      Date.prototype.isValid = function () {
          return this.getTime() === this.getTime();
      };
      return d.isValid();
  }
  
  function withinRange(dateArray) {
      var date = new Date(`${dateArray[0]}/${dateArray[1]}/${dateArray[2]}`);
      var today = new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate());
      var differenceInTime = date.getTime() - today.getTime();
      var differenceInDays = differenceInTime / (1000 * 3600 * 24);
      return (differenceInDays >= 0 && differenceInDays < 8);
  }
  
  function getDateFormat(date) {
      var dd = date.getDate();
      var mm = date.getMonth()+1; 
      var yyyy = date.getFullYear();
      if(dd<10) dd='0'+dd;
      if(mm<10) mm='0'+mm;
      return mm+'-'+dd+'-'+yyyy;
  }
  
  Date.prototype.addDays = function(days) {
      var date = new Date(this.valueOf());
      date.setDate(date.getDate() + days);
      return date;
  }
  
  
  
  