// Script Property of MileOne Autogroup. Contact Marketing before attempting to make changes.

//  ------------------------------  DYNAMIC EXPIRATION DATE  ------------------------------  //
  
  function moExpDate() {
  
  // Get the last day of the current month
  var lastDayOfMonth = new Date(new Date().getFullYear(), new Date().getMonth() + 1, 0);
  
  // Check if the last day of the month is a Sunday
  if (lastDayOfMonth.getDay() === 0) {
    // If it's a Sunday, subtract one day to get the previous day (Saturday)
    lastDayOfMonth.setDate(lastDayOfMonth.getDate() - 1);
  }
  
  // Format the date as MM/DD/YYYY
  var formattedDate = `${(lastDayOfMonth.getMonth() + 1).toString().padStart(2, '0')}/${lastDayOfMonth.getDate().toString().padStart(2, '0')}/${lastDayOfMonth.getFullYear()}`;
  
  // Update all elements with the class name "MO_EXPIRATION_DATE"
  var expirationDateElements = document.querySelectorAll('.MO_EXPIRATION_DATE');
  expirationDateElements.forEach(function (element) {
    element.textContent = " Offer ends " + formattedDate + ".";
  });
}

moExpDate();
