function add_class_on_scroll() {
  var header = document.getElementById("menuToggle");
  var menuToggle = document.getElementById("main-menu-toggle");
  
  menuToggle.classList.add("menu-toggle-inverse");
  menuToggle.classList.remove("menu-toggle");
  header.classList.add("menu-scroller");
  
  var menuLink = document.querySelectorAll(".menu-link");

  for(i=0;i<menuLink.length;i++) { 

      menuLink[i].classList.add("menu-link-inverse");
      menuLink[i].classList.remove("menu-link");
  }

}

function remove_class_on_scroll() {
  var header = document.getElementById("menuToggle");
  header.classList.remove("menu-scroller");
    var menuToggle = document.getElementById("main-menu-toggle");
  
  menuToggle.classList.add("menu-toggle");
  menuToggle.classList.remove("menu-toggle-inverse");
  
    var menuLink = document.querySelectorAll(".menu-link-inverse");
  
  for(i=0;i<menuLink.length;i++) { 
      
      menuLink[i].classList.add("menu-link");
      menuLink[i].classList.remove("menu-link-inverse");
  }


}

function submitLead(formId, buttonId, dismiss) {
  $("#" + buttonId + "").val("saving...");
  $.ajax({
    type: $("#" + formId + "").attr("method"),
    url: $("#" + formId + "").attr("action"),
    data: $("#" + formId + "").serialize(),
    success: function (data) {
      var form = JSON.parse(data);
      console.log($("#" + formId + "").serialize());
      if (form.result != "success") {
        $("#" + buttonId + "").val("Error");
      } else {
        $("#" + buttonId + "").addClass("d-none");
        $("#" + buttonId + "").before("<p>Thanks! We'll reach out shortly</p>");
        $("#" + buttonId + "").after(
          "<a href='/assets/docs/LEADSMODE-GIOVANNAS-Web-Redesign-Proposal-SLA.pdf' class='btn btn-md btn-blue' target='_blank'><i class='far fa-file-pdf mr-2 text-white'></i>Download Quote Now</a>"
        );
        $("#" + formId + "")[0].reset();
        setTimeout(function () {
          $(dismiss).click();
          $("#" + buttonId + "").val("Submit");
        }, 20000);
      }
    },
  });
}

window.onload = function () {
          remove_class_on_scroll();
  $("#waitingListForm").submit(function (event) {
    event.preventDefault();
    var submitForm = "";
    $("#waitingListForm input").each(function () {
      if (!$(this).val()) {
        $(this).addClass("glass-form-input-err");
        submitForm += "false";
        $(this).on(
          "input change focus keyup keydown keypress change",
          function () {
            $(this).removeClass("glass-form-input-err");
            submitForm -= "false";
          }
        );
      } else {
        submitForm += "true";
      }
    });
    if (submitForm.indexOf("false") > -1) {
    } else {
      submitLead(
        $(this).attr("id"),
        "submitWaitingListEntry",
        ".dismiss-modal"
      );
    }

    console.log("form button " + $(this).attr("id"));
  });

  //use window.scrollY
  var scrollpos = window.scrollY;

  window.addEventListener("scroll", function () {
    //Here you forgot to update the value
    scrollpos = window.scrollY;

    if (scrollpos > 10) {
      add_class_on_scroll();
    } else {
      remove_class_on_scroll();
    }
    console.log(scrollpos);
  });
};
