﻿// JScript File
// for KGProfileHeaderControl 

function KGProfileHeaderControl_AddToMyNetwork(_userAddingId, _userAddedId, _callbackTriggerName)
{
  KGProfileHeaderControl_AddRemove(_userAddingId, _userAddedId, 'add', _callbackTriggerName);
}

function KGProfileHeaderControl_RemoveFromMyNetwork(_userAddingId, _userAddedId, _callbackTriggerName, e)
{
  KGProfileHeaderControl_AddRemove(_userAddingId, _userAddedId, 'remove', _callbackTriggerName);
  CancelBubble(e);
}

function KGProfileHeaderControl_AddRemove(_userAddingId, _userAddedId, _action, _callbackTriggerName)
{
  if(_userAddingId != null && _userAddedId != null && _action != null)
  {
    var args = 'action=' + _action + '|UserAddingId=' + _userAddingId + '|UserAddedId=' + _userAddedId;
    eval(_callbackTriggerName + "('" + args + "')");
    // currently, add and remove are never visible on the profile tab, 
    // so if we get here should callback to the Community tab's profile header
    // but passing in the callback trigger name incase it changes in future
  }
  return true;
}// end function

function KGProfileHeaderControl_CallbackDone(args, context)
{
  // Check for a session time out before completing the callback
  if (CheckSessionTimeout())
    return;
  
  // extract the predefined control client IDs
  var s = args.split('|');
  if(s.length > 1)
  {
    var id = s[0];
    var action = s[1];
    var htmlText = s[2];
    
    // search for the control container
    var holder = document.getElementById(id);
    
    // Test if the container is found
    // Yes: replace the innerHTML with the callback result
    //  No: call CallbackError with Content div not found error message
    if(holder != null)
    {
      SetOuterHtml(holder,htmlText);   
      if (action == "add" || action == "remove")
      {
        if (window.myNetworkControl_CallbackTrigger)
          setTimeout("myNetworkControl_CallbackTrigger('action=repopulate')", 10);
      }
    }//end if(holder ....
    else
    {
      KGProfileHeaderControl_CallbackError('ContentDiv not found in KGProfileHeaderControl.', '');
    }
  }
}

function KGProfileHeaderControl_CallbackError(args, context)
{
  alert('Error in KGProfileHeaderControl callback');
}
