// logged in user can request the friendship of another member
function request_friend(friend_id) {
  // make sure they're logged in first
  if (!logged_in()) {
    // throw-up the login form
    request_login( function(){ request_friend(friend_id); } );
    // and bail out
    return;
  }
  new Ajax.Request('/member/request_friendship/' + friend_id + '.json', {params:'', asynchronous:true, onSuccess:request_friend_onSuccess, onFailure:request_friend_onFailure});
}

function request_friend_onSuccess(t) {
  result = t.responseJSON;
  if (!result.success) {
    display_notification('A contact request has already been sent to this member');
  } else {
    display_notification('Contact request sent. This member has been added to your <a href="/member/contacts">contact list</a>.');
  }
}

function request_friend_onFailure(t) {
  display_notification('Sorry, something went wrong with the request.');
}
