 const firebaseConfig = {
    apiKey: "AIzaSyBZHOI9rj9qYfIEzRx6hX6Hr4DIS2eA1p4",
    authDomain: "appoinments-3f744.firebaseapp.com",
    databaseURL: "https://appoinments-3f744-default-rtdb.firebaseio.com",
    projectId: "appoinments-3f744",
    storageBucket: "appoinments-3f744.appspot.com",
    messagingSenderId: "43817379973",
    appId: "1:43817379973:web:addd9c7df77fb0a8ca61ec",
    measurementId: "G-KE1VH7M24H"
  };

  
  firebase.initializeApp(firebaseConfig);

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

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

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

      savedmessages(Name,Email,ContactNo,Date,Time,MeetingType,Message);

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

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

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

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