var gMyUserId;
function acceptInvitation( inviteId, otherUserName, myUserId, firstResult, pageSize )
{
  if( !confirm( 'Do you want to accept ' + otherUserName + '\'s invitation to become your friend?' ) )
  {
    return;
  }
  var url = '/manageUserNetworkController.dobbb?op=acceptInvitation';
  var params = 'inviteId=' + inviteId + '&firstResults=' + firstResult + '&pageSize=' + pageSize;
  gMyUserId = myUserId;
  ajaxUpdate( 'networkFriendsBoxElem', url, params, onSuccessAcceptInvite );
}
function onSuccessAcceptInvite( userName )
{
  reportAjaxSuccessInline( 'You have accepted the Friend invitation' );
  loadNetworkWidget( gMyUserId, 'palette_network_collapsible' );  
}
function rejectInvitation( inviteId, otherUserName, firstResult, pageSize )
{
  if( !confirm( 'Do you want to decline ' + otherUserName + ' invitation to become your friend?' ) )
  {
    return;
  }
  var url = '/manageUserNetworkController.dobbb?op=rejectInvitation';
  var params = 'inviteId=' + inviteId + '&firstResults=' + firstResult + '&pageSize=' + pageSize;
  ajaxUpdate( 'networkFriendsBoxElem', url, params, onSuccessRejectInvitation );
}
function onSuccessRejectInvitation( request )
{
  reportAjaxSuccessInline( 'You have declined the Friend invitation.' );
}
var gOtherUserName;
function cancelInvitation( inviteId, otherUserName )
{
  if( !confirm( 'Canceling this invitation will remove it from your list of sent invitations and from ' + otherUserName + '\'s list of received invitations. Are you sure you want to cancel the invitation?' ) )
  {
    return;
  }
  var url = '/manageUserNetworkController.dobbb?op=cancelFriendInvite';
  var params = 'inviteId=' + inviteId;
  gOtherUserName = otherUserName;
  ajaxUpdate( 'networkFriendsBoxElem', url, params, onSuccessCancelInvitation );
}
function onSuccessCancelInvitation( request )
{
  reportAjaxSuccessInline( 'Your invitation to ' + gOtherUserName + ' has been cancelled.' );
}
function removeSentInvitations()
{
  if( !validateCheckboxes( 'invitationsToRemove', 'Invitation' ) )
  {
    return;
  }
  /*
  //ritter changed his mind about needing this code (tf!), but i'm leaving it in here so it's at least in p4 once, in case he changes his mind later
  //delete this if you see it in p4, since by then we'll have it on record.
  var confirmationMessage = 'Are you sure you want to remove these invitations? This process cannot be reversed.'; //normal
  var elements = document.getElementsByName( 'invitationsToRemove' );
  var foundPending = false;
  for( var i = 0; !foundPending && i < elements.length; i++ )
  {
    if( elements[i].checked )
    {
      var statusElem = $( 'invitationStatus' + elements[i].value );
      alert( 'got checked element with status of:' + statusElem.value );
      if( statusElem.value == 'PENDING' )
      {
        foundPending = true;
      }
    }
  }
  if( foundPending )
  {
    confirmationMessage = 'Some of these invitations have not been acted upon by their recipient. Removing these invitations will cancel them. Are you sure you want to remove these invitations? This process cannot be reversed.';
  }*/
  if( !confirm( 'Any pending invitations that you remove will be automatically canceled.  Are you sure you want to remove these invitations?' ) )
  {
    return;
  }
  document.forms['sentInvitations'].submit();
  return true;
}
function removeReceivedInvitations()
{
  if( !validateCheckboxes( 'invitationsToRemove', 'Invitation' ) )
  {
    return;
  }
  if( !confirm( 'Any pending invitations that you remove will be automatically declined.  Are you sure you want to remove these invitations?' ) )
  {
    return;
  }
  document.forms['receivedInvitations'].submit();
  return true;
}