text: $("#contactForm").validator().on("submit", function (event) {
    if (event.isDefaultPrevented()) {
      formError();
      submitMSG(false, "Did you fill in the form properly?");
    } else {
      event.preventDefault();
      submitForm();
    }
  });
  
  function submitForm(){
    var name = $("#name").val();
    var email = $("#email").val();
    var msg_subject = $("#msg_subject").val();
    var message = $("#message").val();
    var db = firebase.firestore();
    var docID = Math.random().toString(36).substring(7);
  
    db.collection("paeyContactMessage").doc(docID).set({
      name: name,
      email: email,
      messageSubject: msg_subject,
      message: message
    })
    .then(function() {
      formSuccess();
    })
    .catch(function(error) {
      formError();
      submitMSG(false,error);
    });
  }
  
  function formSuccess(){
    $("#contactForm")[0].reset();
    submitMSG(true, "Your message was sent successfully. Thanks!")
  }
  
  function formError(){
    $("#contactForm").removeClass().addClass('shake animated').one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function(){
      $(this).removeClass();
    });
  }
  
  function submitMSG(valid, msg){
    if(valid){
      var msgClasses = "h3 text-left tada animated text-success";
    } else {
      var msgClasses = "h3 text-left text-danger";
    }
    $("#msgSubmit").removeClass().addClass(msgClasses).text(msg);
  }