Add lead and calender event to appointments
diff --git a/erpnext/www/book-appointment/index.html b/erpnext/www/book-appointment/index.html
index 43275eb..2e03213 100644
--- a/erpnext/www/book-appointment/index.html
+++ b/erpnext/www/book-appointment/index.html
@@ -51,10 +51,12 @@
                 placeholder="Contact Number" required>
             <input class="form-control mt-3" type="text" name="customer_skype" id="customer_skype" placeholder="Skype"
                 required>
+            <input class="form-control mt-3"type="email" name="customer_email" id="customer_email" 
+                placeholder="Email Address">
             <textarea class="form-control mt-3" name="customer_notes" id="customer_notes" cols="30" rows="10"
                 placeholder="Notes"></textarea>
             <div class="row mt-3 ">
-                <div class="col-md"><button class="btn btn-dark form-control" onclick="initialize_select_date()">Go back</button></div>
+                <div class="col-md"><button class="btn btn-dark form-control" onclick="initialise_select_date()">Go back</button></div>
                 <div class="col-md"><button class="btn btn-primary form-control " onclick="submit()" id="submit-button">Submit</button></div>
             </div>
         </div>
diff --git a/erpnext/www/book-appointment/index.js b/erpnext/www/book-appointment/index.js
index 90572fb..f9d9b6e 100644
--- a/erpnext/www/book-appointment/index.js
+++ b/erpnext/www/book-appointment/index.js
@@ -5,7 +5,7 @@
 window.holiday_list = [];
 
 async function initialise_select_date() {
-    document.getElementById('enter-details').style.display = 'none';
+    navigate_to_page(1);
     await get_global_variables();
     setup_date_picker();
     setup_timezone_selector();
@@ -115,7 +115,6 @@
         timeslot_container.appendChild(timeslot_div);
     });
     set_default_timeslot();
-    show_next_button();
 }
 
 function clear_time_slots() {
@@ -146,6 +145,7 @@
     window.selected_time = this.id
     selected_element.classList.remove("selected");
     this.classList.add("selected");
+    show_next_button();
 }
 
 function set_default_timeslot() {
@@ -159,11 +159,25 @@
     }
 }
 
-function setup_details_page(){
+function navigate_to_page(page_number){
     let page1 = document.getElementById('select-date-time');
     let page2 = document.getElementById('enter-details');
-    page1.style.display = 'none';
-    page2.style.display = 'block';
+    switch(page_number){
+        case 1: 
+            page1.style.display = 'block';
+            page2.style.display = 'none';
+            break;
+        case 2:
+            page1.style.display = 'none';
+            page2.style.display = 'block';
+            break;
+        default:
+            console.log("That's not a valid page")
+    }
+}
+
+function setup_details_page(){
+    navigate_to_page(2)
     let date_container = document.getElementsByClassName('date-span')[0];
     let time_container = document.getElementsByClassName('time-span')[0];
     date_container.innerHTML = moment(window.selected_date).format("MMM Do YYYY");
@@ -196,6 +210,7 @@
     contact.number = document.getElementById('customer_number').value;
     contact.skype = document.getElementById('customer_skype').value;
     contact.notes = document.getElementById('customer_notes').value;
+    contact.email = document.getElementById('customer_email').value;
     window.contact = contact
     console.log({ date, time, contact });
 }
diff --git a/erpnext/www/book-appointment/index.py b/erpnext/www/book-appointment/index.py
index 1b87b86..530445f 100644
--- a/erpnext/www/book-appointment/index.py
+++ b/erpnext/www/book-appointment/index.py
@@ -94,8 +94,16 @@
     appointment.customer_skype = contact['skype']
     appointment.customer_details = contact['notes']
     appointment.status = 'Open'
+    appointment.lead = find_lead_by_email(contact['email']).name
     appointment.insert()
 
+def find_lead_by_email(email):
+    if frappe.db.exists({
+        'doctype':'Lead',
+        'email_id':email
+    }):
+        return frappe.get_list('Lead',filters={'email_id':email})[0]
+    frappe.throw('Email ID not associated with any Lead. Please make sure to use the email address you got this mail on')
 
 # Helper Functions
 def filter_timeslots(date, timeslots):