api_key = '3bcc4a4f9065f65865a2f52c4d15ddf4';

$(document).ready(function() {
   // do stuff when DOM is ready
   FB_RequireFeatures(['Api'], function(){
  
    FB.Facebook.init(api_key);
    
    FB.Connect.ifUserConnected(
      //if connected
      function() {         
        document.getElementById('FBProfilePic').style.display = 'block';
             
        if (FB_Message) {
          facebook_prompt_permission('publish_stream', function(accepted) {         
            if (accepted) {                                              
              FB.Connect.streamPublish(FB_Message, null, null, '', '', addMielForPublishedStatus, true, '');
              //addMielForPublishedStatus();         
            }  
          });
        } 
                        
      }, 
      //if not connected
      function() {      
        document.getElementById('FBLoginButton').style.display = 'block';      
      }
    );
       
  });
});

function addMielForPublishedStatus(post_id, exception) {
    
  if (post_id != 'null') {
    $.post("basicIncludes/FBStatusRewarder.inc.php", { "ours": MyOurs } );
  }
  
}
  
//fonction appelée lorsque l'utilisateur presse sur le bouton de connection FB sur squelet2.php
function onFBLogin()
{
  document.getElementById('FBProfilePic').style.display = 'block';
  document.getElementById('FBLoginButton').style.display = 'none';
}

/*
 * Prompts the user to grant a permission to the application.
 */
function facebook_prompt_permission(permission, callbackFunc) {      
  FB.Bootstrap.ensureInit(function() {
      //check if user already granted for this permission or not
      FB.Facebook.apiClient.users_hasAppPermission(permission, function(result) {
          if (result) {              
              // permission already granted.
              callbackFunc(true);
          } else {
            // render the permission dialog
            FB.Connect.showPermissionDialog(permission, function(perms){
              if(perms){
                callbackFunc(true)
              }
            });    
          }
      });
  });
}