function facebook_login(appUrl) {
  FB.Facebook.get_sessionState().waitUntilReady(function() {
    var user = FB.Facebook.apiClient.get_session() ?
      FB.Facebook.apiClient.get_session().uid :
      null;

    // probably should give some indication of failure to the user
    if (!user) {
      alert("Invalid username or password entered for facebook. Please try again");
    } else {
      url = '/facebook/users/facebook_connect?uid=' + user + '&windowLocation=' + window.location;
      new Ajax.Request(url, {
        method: 'get',
        onSuccess: function(){
          $('facebook_connect_inner').update("<p>We have successfully connected your mDialog account to your Facebook profile.</p><p>Any videos you add will be available at <a href='" + appUrl + "' target=\"_blank\">the mDialog Video application</a></p>");
        },
        onFailure: function(){}
      });
    }
  });
}