// // var config = {
// //     apiKey: "AIzaSyAWcNgrrHRVM45y4H3YYT4anC6ZBs67wFk",
// //     authDomain: "dignifind.firebaseapp.com",
// //     databaseURL: "https://dignifind.firebaseio.com",
// //     projectId: "dignifind",
// //     storageBucket: "dignifind.appspot.com",
// //     messagingSenderId: "19644371771"
// //   };
// //   firebase.initializeApp(config);
//   var username;
//   var childData;
//   var funeralId = window.location.search.substring(1);

// /** Screenshots **/
// $('#myCarousel').carousel({
//     interval: 7000
// })


  


// function getUrlParameter(name) {
//     name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
//     var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
//     var results = regex.exec(location.search);
//     return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
// }


// $.ajax({
//     url: "https://dignifind.firebaseio.com/funerals/ki06oXyYOdZcbNHAMFAFcPiDIyx2/"+funeralId+".json",
//     method: "GET",
//     success: function (result){
//         childData = result;
//         loadData();},
//     error: function (error){ console.log(error); }
// })

// function loadData() {
//     console.log("Grave Number : "+JSON.stringify(childData));
//     var location = childData.lat+','+childData.lng;
//     var locationURL = 'https://www.google.com/maps/search/?api=1&query='+location;
//     var homelocation = childData.homelat+','+childData.homelng;
//     var homelocationURL = 'https://www.google.com/maps/search/?api=1&query='+homelocation;
//     var servicelocation = childData.servicelat+','+childData.servicelng;
//     var servicelocationURL = 'https://www.google.com/maps/search/?api=1&query='+servicelocation;
//     document.getElementById('servicelocation').href = servicelocationURL;
//     document.getElementById('homelocation').href = homelocationURL;
//     document.getElementById('cemeterylocation').href = locationURL;
//     document.getElementById('deceasedname').innerText = childData.firstName +' '+ childData.surname;
//     document.getElementById('deceaseddob').innerText = 'Sunrise : ' + convertDate(childData.dateOfBirth);
//     document.getElementById('deceaseddod').innerText = 'Sunset : ' + convertDate(childData.dateOfDeath);
//     document.getElementById('dateoffuneral').innerText = 'Date : ' + convertDate(childData.dateOfFuneral);
// //document.getElementById('dateofunveiling').innerText = childData.dateOfUnveiling?'Date of Unveiling : ' + convertDate(childData.dateOfUnveiling):'';
//     document.getElementById('venue').innerText = childData.venue?'Venue : ' + (childData.venue):'Venue: to be uploaded';
//     document.getElementById('time').innerText = childData.time?'Time : ' + (childData.time):'Time: to be uploaded';
//     document.getElementById('programme').innerText = childData.programme?childData.programme:'to be uploaded...';
//     document.getElementById('obituary').innerText = childData.obituary?childData.obituary:'to be uploaded...';
//     $("#deceasedimage").attr("src", childData.picture);
//     document.getElementById('info').innerText = childData.info?childData.info:'to be uploaded...';

//     var hl = "https://www.google.com/maps/embed/v1/place?zoom=15&key=AIzaSyBBkmORi786_fXlxb0jjBlielbo19d3s98&q="+homelocation;
//     document.getElementById('homemap').src = hl;
//     var cl = "https://www.google.com/maps/embed/v1/place?zoom=15&key=AIzaSyBBkmORi786_fXlxb0jjBlielbo19d3s98&q="+location;
//     document.getElementById('map').src = cl;
//     var sl = "https://www.google.com/maps/embed/v1/place?zoom=15&key=AIzaSyBBkmORi786_fXlxb0jjBlielbo19d3s98&q="+servicelocation;
//     document.getElementById('servicemap').src = sl;

//     if(childData.memorial){
//         document.getElementById("mybuttons").style.display = "block";
//         loadMemorial();
//     }else{
//         document.getElementById("funeraldetails").style.display = "block";
//     }

//     if(childData.pictures){
//         if(childData.pictures.pic5){loadimages(childData.pictures.pic5);}
//         if(childData.pictures.pic4){loadimages(childData.pictures.pic4);}
//         if(childData.pictures.pic3){loadimages(childData.pictures.pic3);}
//         if(childData.pictures.pic2){loadimages(childData.pictures.pic2);}
//         if(childData.pictures.pic1){loadimages(childData.pictures.pic1);}
//     }
//     if(childData.picture){$("#deceasedimage").attr("src", childData.picture);}

//     if(childData.streaming){

//         if(!childData.memorial){
//             document.getElementById("streaming").style.display = "block";
//         }

//         document.getElementById("homestream").href = childData.homestream;
//         //   document.getElementById("cemstream").href = childData.cemstream;
//         document.getElementById("hstreamtime").innerText = childData.hstreamtime;
//         //  document.getElementById("cstreamtime").innerText = childData.cstreamtime;
//         document.getElementById("mstreamtime").innerText = childData.mstreamtime;
//         document.getElementById("memostream").href = childData.memostream;
//     }

//     if(childData.thankson){
//         document.getElementById("thanks").style.display = "block";
//         document.getElementById("thanksmessage").innerHTML = childData.voteofthanks;
//         document.getElementById("thanksname").innerText = childData.surname + "'s Family";
//     }else{
//         document.getElementById("thanks").style.display = "none";
//     }
// }

// // function loadFields(){
// //     var funeralId = window.location.search.substring(1);
// //     var provider = 'ki06oXyYOdZcbNHAMFAFcPiDIyx2';

// //     var query = firebase.database().ref("funerals/"+provider);
// //      console.log("Loading fields ====== Provider : "+provider);
// //     query.orderByKey().equalTo(funeralId).once("value")
// //       .then(function(snapshot) {
// //         snapshot.forEach(function(childSnapshot) {
// //           childData = childSnapshot.val();
// //           console.log("Grave Number : "+JSON.stringify(childData));
// //           var location = childData.lat+','+childData.lng;
// //           var locationURL = 'https://www.google.com/maps/search/?api=1&query='+location;
// //           var homelocation = childData.homelat+','+childData.homelng;
// //           var homelocationURL = 'https://www.google.com/maps/search/?api=1&query='+homelocation;
// //           var servicelocation = childData.servicelat+','+childData.servicelng;
// //           var servicelocationURL = 'https://www.google.com/maps/search/?api=1&query='+servicelocation;
// //           document.getElementById('servicelocation').href = servicelocationURL;
// //           document.getElementById('homelocation').href = homelocationURL;
// //           document.getElementById('cemeterylocation').href = locationURL;
// //           document.getElementById('deceasedname').innerText = childData.firstName +' '+ childData.surname;
// //           document.getElementById('deceaseddob').innerText = 'Sunrise : ' + convertDate(childData.dateOfBirth);
// //           document.getElementById('deceaseddod').innerText = 'Sunset : ' + convertDate(childData.dateOfDeath);
// //           document.getElementById('dateoffuneral').innerText = 'Date : ' + convertDate(childData.dateOfFuneral);
// //           //document.getElementById('dateofunveiling').innerText = childData.dateOfUnveiling?'Date of Unveiling : ' + convertDate(childData.dateOfUnveiling):'';
// //           document.getElementById('venue').innerText = childData.venue?'Venue : ' + (childData.venue):'Venue: to be uploaded';
// //           document.getElementById('time').innerText = childData.time?'Time : ' + (childData.time):'Time: to be uploaded';
// //           document.getElementById('programme').innerText = childData.programme?childData.programme:'to be uploaded...';
// //           document.getElementById('obituary').innerText = childData.obituary?childData.obituary:'to be uploaded...';
// //           $("#deceasedimage").attr("src", childData.picture); 
// //           //document.getElementById('whatsapp').href = whatsappurl + encodeURIComponent(whats);

// //           var hl = "https://www.google.com/maps/embed/v1/place?zoom=15&key=AIzaSyBBkmORi786_fXlxb0jjBlielbo19d3s98&q="+homelocation;
// //           document.getElementById('homemap').src = hl;
// //           var cl = "https://www.google.com/maps/embed/v1/place?zoom=15&key=AIzaSyBBkmORi786_fXlxb0jjBlielbo19d3s98&q="+location;
// //           document.getElementById('map').src = cl;
// //           var sl = "https://www.google.com/maps/embed/v1/place?zoom=15&key=AIzaSyBBkmORi786_fXlxb0jjBlielbo19d3s98&q="+servicelocation;
// //           document.getElementById('servicemap').src = sl;

// //           if(childData.memorial){
// //               document.getElementById("mybuttons").style.display = "block";
// //                     loadMemorial();
// //                 }else{
// //                     document.getElementById("funeraldetails").style.display = "block";
// //                 }

// //           if(childData.pictures){
// //               if(childData.pictures.pic5){loadimages(childData.pictures.pic5);}
// //                 if(childData.pictures.pic4){loadimages(childData.pictures.pic4);}
// //                 if(childData.pictures.pic3){loadimages(childData.pictures.pic3);}
// //                 if(childData.pictures.pic2){loadimages(childData.pictures.pic2);}
// //                 if(childData.pictures.pic1){loadimages(childData.pictures.pic1);}
// //           }
// //           if(childData.picture){$("#deceasedimage").attr("src", childData.picture);}
          
// //           if(childData.streaming){
                
// //                 if(!childData.memorial){
// //                     document.getElementById("streaming").style.display = "block";
// //                 }
                
// //                 document.getElementById("homestream").href = childData.homestream;
// //             //   document.getElementById("cemstream").href = childData.cemstream;
// //                 document.getElementById("hstreamtime").innerText = childData.hstreamtime;
// //             //  document.getElementById("cstreamtime").innerText = childData.cstreamtime;
// //              document.getElementById("mstreamtime").innerText = childData.mstreamtime;
// //              document.getElementById("memostream").href = childData.memostream;
// //             } 

// //           if(childData.thankson){
// //             document.getElementById("thanks").style.display = "block";
// //             document.getElementById("thanksmessage").innerHTML = childData.voteofthanks;
// //             document.getElementById("thanksname").innerText = childData.surname + "'s Family";
// //           }else{
// //             document.getElementById("thanks").style.display = "none";
// //           }
// //               });
// //     });
// // };

// function loadMemorial(){
//     document.getElementById('dateofmemorial').innerText = childData.dateofmemorial?'Date : ' + convertDate(childData.dateofmemorial):'Date: to be uploaded';
//     document.getElementById('memorialvenue').innerText = childData.memorialvenue?'Venue : ' + (childData.memorialvenue):'Venue: to be uploaded';
//     document.getElementById('memorialtime').innerText = childData.memorialtime?'Time : ' + (childData.memorialtime):'Time: to be uploaded';
    
//     document.getElementById('memorialprogramme').innerText = childData.memorialprogramme? (childData.memorialprogramme):'to be uploaded';

//     var memoriallocation = childData.memoriallocation?childData.memoriallocation:'undefined';
//     var memorialMap = "https://www.google.com/maps/embed/v1/place?zoom=15&key=AIzaSyBBkmORi786_fXlxb0jjBlielbo19d3s98&q="+memoriallocation;
//     document.getElementById('memorialmap').src = memorialMap;
//     var memorialURL = 'https://www.google.com/maps/search/?api=1&query='+memoriallocation;
//     document.getElementById('memoriallocation').href = memorialURL;
// }

// function showFuneralDetails(){
//     document.getElementById("memorialButton").disabled = false;
//     document.getElementById("funeralButton").disabled = true;
//     document.getElementById("funeraldetails").style.display = "block";
//     document.getElementById("funeralprogramme").style.display = "block";
//     document.getElementById("memorialdetails").style.display = "none";
//     document.getElementById("memorialprogrammedetails").style.display = "none";
    
//     if(childData.streaming){
//         document.getElementById("memostreaming").style.display = "none";
//         document.getElementById("streaming").style.display = "block";
//     }
// }

// function showMemorialDetails(){
//     document.getElementById("memorialButton").disabled = true;
//     document.getElementById("funeralButton").disabled = false;
//     document.getElementById("funeraldetails").style.display = "none";
//     document.getElementById("funeralprogramme").style.display = "none";
//     document.getElementById("memorialdetails").style.display = "block";
//     document.getElementById("memorialprogrammedetails").style.display = "block";
    
//     if(childData.streaming){
//         document.getElementById("memostreaming").style.display = "block";
//         document.getElementById("streaming").style.display = "none";    
//     }
// }


// function convertDate(epoch){
//     if(isNaN(epoch)){
//         if(epoch){
//             return epoch;
//         }else{
//             return '';
//         }
        
//     }else{
//         var curdate = new Date(null);
//         curdate.setTime(epoch);
//         return curdate.getDate() +'/'+(curdate.getMonth()+1)+'/'+curdate.getFullYear();
//     }
// };



// function loadProvider(provider){
//     var query = firebase.database().ref("/providers/");
//     console.log("Loading fields ");
//     query.orderByChild("user").equalTo(provider).once("value")
//       .then(function(snapshot) {
//         snapshot.forEach(function(childSnapshot) {
//             var childData = childSnapshot.val();
//             console.log("Provider Logo : "+childData.providerlogo);
//             document.getElementById('providername').innerText = childData.providerName;
//             $("#providerimage").attr("src", childData.providerlogo); 
//             $("#provideraddress").attr("href", childData.providerwebsite); 
//         });
//       });
// };

// function loadimages(imagesrc){
//     var image = '<div><a href="'+imagesrc+'"><img src="'+imagesrc+'" class="img-responsive" alt="to be uploaded..."></a></div>';
//     var item = document.createElement('div');
//     item.className = 'item';
//     item.innerHTML = image;
//     var images = document.getElementById('myCar');
//     images.insertBefore(item, images.firstChild)
// }


function switchTab(evt, tabId) {
    document.querySelectorAll('.tab-content').forEach(c => c.classList.remove('show'));
    document.querySelectorAll('.tab-link').forEach(l => l.classList.remove('active'));
    document.getElementById(tabId).classList.add('show');
    evt.currentTarget.classList.add('active');
  }