﻿var globalMyProfileTabLoaded;

function KGMyProfileTab_Activate()
{
  if (!globalMyProfileTabLoaded)
  {
    var args = "Action=Load";
    Pfl_KGMemberControl_CallbackTrigger(args);
    globalMyProfileTabLoaded = true; // doesn't need resetting until the page reloads
  }
}

function ShowUser_Wrapped(_personId, _pageLoad, _currentUserPersonId) {
  if (_currentUserPersonId > 0 && _currentUserPersonId == _personId)
  {
    //if(globalVisibleTab != 'TSC_myprofile')
  	// ChangeTab('myprofile');
  	// This needs to be changed nga0509
  	globalShowKeepKGPrompt = false;
  	//returnFromEditView(); -- remove this to fix 10460
  	var currentLocation = window.location.href;
  	var hostURL = currentLocation.substring(0, currentLocation.lastIndexOf('/') + 1);
  	window.location = hostURL + 'home.aspx?t=profile';
  }
  else
  {
    if (globalVisibleTab.indexOf("communities") == -1)
      ChangeTab('communities', 'Communities', false);
    
    // if this is from a page load, we need to setup the tab tool strip
    if(_pageLoad)
      ChangeTabToolStrip('communities');
    
    var extraRepopArgs = "PersonId=" + _personId;
    LoadCommunityTab("User", extraRepopArgs);

    DeselectInformationTab();
    // Also want to shift the splitter across as well
    var closedSize = 0;
    $('#MySplitter').trigger('resize', closedSize);

    var communitiesOptionsDiv = document.getElementById(appOptionsNavControlPrefix + "AppOptionsNavigationControl_OptionDiv");

    if (communitiesOptionsDiv != null) {
    	communitiesOptionsDiv.style.display = "none";
    }

		// Now want to add some code to disable everything that the user cannot do
    $('#InformationPaneHorizontal').css('display', 'none');
    $("#HomeSplitter").css('display', 'none');
    $("#HomeSplitterTab").css('display', 'none');
    $("#ApplicationPane").css('left', '0px');
    $("#MySplitter").css('background-color', '#FAFAFA');

  }
}

function KGMemberControl_CallbackError(_args, _context)
{
  var alertMessage = "The KGMemberControl encountered an error. \n\n" + _args;
  alert(alertMessage);
}

function KGMemberControl_CallbackDone(_args, _context)
{
  // check for exceptions
  if (_args.indexOf("Exception") == 0 || _args.length == 0)
  {
    KGMemberControl_CallbackError(_args, _context);
    return;
    // looking for indexOf == 0 instead of > -1 incase it's genuine html that happens to contain 'Exception' in there
    // e.g. a user called "... Exceptional ..." 
  }

  // get the parameters
  var argsSplit = _args.split('[@|@]');
  var holderId = argsSplit[0];
  var javascripts = argsSplit[1];
  var htmlContent = argsSplit[2];
  
  //var retMsg = eval( '(' + json + ')' );
  //var holderId = retMsg.HolderId;
  
  var holder = document.getElementById(holderId);
  if (!holder)
  {
    KGCommunityControl_CallbackError('The holder doesn\'t exist ' + holderId);
    return;
  }
  
  // fill the control
  SetOuterHtml(holder, htmlContent);

  window.setTimeout("SetFullPageContainerDivStyle('" + holderId + "')", 200);

  // eval any javascripts
  if (javascripts)
    eval(javascripts);
}

