var gFriendUserId;
var gFriendDivId;
function addAsFriend( otherUserId, otherUserName )
{
  gFriendUserId = otherUserId;
  if( !confirm( 'Do you want to send an invitation to ' + otherUserName + ' to become your friend?' ) )
  {
    return;
  }
  var url = '/manageUserNetworkController.dobbb?op=addFriend';
  var params = 'otherUserId=' + otherUserId + "&otherUserName=" + otherUserName;
  ajaxRequest( url,
               params,
               onSuccessAddFriend,
               onFailureAddFriend );
}
function onSuccessAddFriend( request )
{
  reportAjaxSuccessInline( request.responseText );
  $( 'addFriendLink' + gFriendUserId ).style.display = 'none';
  $( 'pendingFriendLink' + gFriendUserId ).style.display = 'block';
}
function onFailureAddFriend( request )
{
  var message = getStatusText( request )
  if( message == "NEED_VERIFY" )
  {
    //special case where we want a link in the inline receipt -- don't do this often!
    message = "You are unable to add a friend until you validate your email address.  " +
              "Click <a href=\"#\" onclick=\"doVerify()\">this link</a> to start the email validation process.";
    setErrorInlineReceipt( message, null, true );
  }
  else
  {
    setErrorInlineReceipt( message );
  }
}
function removeFriend( friendUserId, divId )
{
  if( !confirm( 'Are you sure you want to remove this friend?  This process cannot be reversed.' ) )
  {
    return;
  }
  gFriendDivId = divId;
  gFriendUserId = friendUserId;
  var url = "/manageUserNetworkController.dobbb";
  var params = "op=removeFriend&friendUserId=" + friendUserId;
  ajaxRequest( url,
               params,
               onSuccessRemoveFriend );
}
function onSuccessRemoveFriend( )
{
  reportAjaxSuccessInline( 'The user has been removed from your friends' );
  hideElement( gFriendDivId );
  gFriendDivId = '';
  $( 'removeFriendLink' + gFriendUserId ).style.display = 'none';
  $( 'addFriendLink' + gFriendUserId ).style.display = 'block';
}
function goToSentInvitations( )
{
  document.location = '/sentInvites.dobbb';
}
function goToReceivedInvitations( )
{
  document.location = '/receivedInvites.dobbb';
}
