 const firebaseConfig = {
    apiKey: "AIzaSyCWh7I5IbOSDnNjsnA3H6fVMiHaUz30wyM",
    authDomain: "contactus-62c16.firebaseapp.com",
    databaseURL: "https://contactus-62c16-default-rtdb.firebaseio.com",
    projectId: "contactus-62c16",
    storageBucket: "contactus-62c16.appspot.com",
    messagingSenderId: "668967928982",
    appId: "1:668967928982:web:66553880c2b1b6679f2eb7",
    measurementId: "G-GBS6EQSVGF"
  };

  firebase.initializeApp(firebaseConfig);

  var contactFormDb = firebase.database().ref('ContactedUs');

  document.getElementById('frmContactUs').addEventListener('submit',submitForm);

  function submitForm(e){
      e.preventDefault();
      var Name = getElementVal('Name');
      var Email = getElementVal('Email');
      var ContactNo = getElementVal('ContactNo');
      var Subject = getElementVal('Subject');
      var Message = getElementVal('Message');

      savedmessages(Name,Email,ContactNo,Subject,Message);

      document.querySelector('.alert').style.display = 'block';

      setTimeout(() => {
      document.querySelector('.alert').style.display = 'none';
      },5000);
      document.getElementById('frmContactUs').reset();
  }

  const savedmessages = (Name,Email,ContactNo,Subject,Message) => {
      var newcontactform = contactFormDb.push();
      newcontactform.set({
          Name : Name,
          Email : Email,
          ContactNo : ContactNo,
          Message : Message,
          Subject : Subject,
      });
  };

  const getElementVal = (id) => {
  return document.getElementById(id).value;
  };
