/*
* Cepat Sembuh v1.0
* Copyright 2016 Cepat Sembuh
*/

// Firebase go online whenever the application is open
document.addEventListener("deviceready", function () {
    Firebase.goOnline();
});

// Not available faskes
$('#not-available').on('click', function() {
	alert("Faskes is not available")
})

// Get no antrian function
function getNoAntri(tipe, username, name) {
  // Define firebase URL
  var faskesRef = new Firebase("https://cepatsembuh.firebaseio.com/" + tipe + "/faskes/" + username);

  // Log firebase URL
  console.log('Url :' + "https://cepatsembuh.firebaseio.com/" + tipe + "/faskes/" + username);

  // Warn user that this fiture need internet
	alert('Fitur ini membutuhkan internet untuk mengambil data');

  // Confirmation
  alert("Mohon konfirmasi ulang");
  var nama = prompt("Masukan nama"),
  nik = prompt("Masukan NIK:")
  if (nama != "" || nik.length != 16) {
    var pasien = new Firebase("https://cepatsembuh.firebaseio.com/" + tipe + '/pasien/');
    // Initialize data
    faskesRef.on("value", function(snapshot) {
      // Print data
      alert('No antrian: ' + snapshot.val().antrian);

      // Push data to firebase
      pasien.push().set({
        nama: nama,
        nomor_antrian: snapshot.val().antrian
      })

      // Updated variables
      var data = snapshot.val().antrian,
      one = 1,
      sum = data + one;

      // Update nomor antrian
      faskesRef.update({
        nama: name,
        antrian: sum
      });
    });
  } else {
    // Error message
    alert("Input anda tidak valid. \n Anda tidak bisa mendapatkan nomor antrian");
  }
}

@@ -844,16 +844,17 @@
 n NIK:%22)
+;
 %0A  if (n
@@ -1059,128 +1059,158 @@
  // 
-Print data%0A      alert('No antrian: ' + snapshot.val().antrian);%0A%0A      // Push data to firebase
+Update variables%0A      var data = snapshot.val().antrian,%0A      one = 1,%0A      sum = data + one;%0A%0A      // Update nomor antrian
 %0A      
-pasien.push().set
+faskesRef.update
 (%7B%0A 
@@ -1225,17 +1225,17 @@
 ama: nam
-a
+e
 ,%0A      
@@ -1240,14 +1240,8 @@
     
-nomor_
 antr
@@ -1246,37 +1246,18 @@
 trian: s
-napshot.val().antrian
+um
 %0A      %7D
@@ -1257,16 +1257,17 @@
       %7D)
+;
 %0A%0A      
@@ -1273,159 +1273,128 @@
  // 
-Updated variables%0A      var data = snapshot.val().antrian,%0A      one = 1,%0A      sum = data + one;%0A%0A      // Update nomor antrian
+Print data%0A      alert('No antrian: ' + snapshot.val().antrian);%0A%0A      // Push data to firebase
 %0A      
-faskesRef.update
+pasien.push().set
 (%7B%0A 
@@ -1401,33 +1401,33 @@
        nama: nam
-e
+a
 ,%0A        antria
@@ -1412,32 +1412,38 @@
 : nama,%0A        
+nomor_
 antrian: sum%0A   
@@ -1428,34 +1428,53 @@
 nomor_antrian: s
-um
+napshot.val().antrian
 %0A      %7D);%0A    %7D
@@ -1466,17 +1466,16 @@
       %7D)
-;
 %0A    %7D);

Expected semicolon