
        window.fbAsyncInit = function() {
          FB.init({
            appId      : '317724241593536',
            status     : true, 
            cookie     : true,
            xfbml      : true,
            oauth      : true
          });        

          FB.getLoginStatus(function(response) {
            onStatus(response); // once on page load
            FB.Event.subscribe('auth.statusChange', onStatus); // every status change
          });
          
        };
 
 
 /**
 * This assumes the user is logged in and renders their profile picture,
 * name and a logout link.
 */
function showAccountInfo() {

  FB.api(
    {
      method: 'fql.query',
      query: 'SELECT name, pic_square,uid,email FROM user WHERE uid='+FB.getUserID()
    },
    function(response) {
      $.get("/registra_da_facebook.php?username="+response[0].name+"&email="+response[0].email+"&id_facebook="+response[0].uid,function(){
      
      if(ristorante)location.reload();
      
      });
    }
  );
}

/**
 * This assumes the user is logged out, and renders a login button.
 */
function showLoginButton() {
  
  document.getElementById('fbinfo').innerHTML = (
    '<img onclick="FB.login()" style="cursor: pointer;"' +
         'src="https://s-static.ak.fbcdn.net/rsrc.php/zB6N8/hash/4li2k73z.gif">'
  );
  
}

/**
 * This will be called once on page load, and every time the status changes.
 */
function onStatus(response) {
 
  if (response.status === 'connected') {
    showAccountInfo();
  } else {
    //showLoginButton();
  }
}

