﻿function KGTopicsControl_OnNodeSelect(_nodeText, _nodeId, _topLevelTopicId, _hasChildren)
{
 //debugger;
  try
  {
    SetSessionProperty('ConceptTopics_SelectedTopicName', _nodeText.replace('&','%26'));
    var keys = 'ConceptTopics_SelectedTopicGroupId|ConceptTreeTabbedView_SelectedTab|IndexedDocListMode|Topics_CategoryJustClicked|SelectedKnowdeSiblingInfo';
	  var values = _nodeId + '|CS_' + _topLevelTopicId + '|Category|true|';
    SetSessionProperty(keys, values, true);

    /*SetSessionProperty('Topics_SelectedTopicGroupId', _nodeId);
    SetSessionProperty('ConceptTabbedView_SelectedTab', 'CS_' + _topLevelTopicId);
    SetSessionProperty('IndexedDocListMode', 'Category');
    SetSessionProperty('Topics_CategoryJustClicked', true);
    
    // new default map will be load, clear old session
    SetSessionProperty('SelectedKnowdeSiblingInfo', '');	*/
    
    // reload the concept tree
    if (_hasChildren.toLowerCase() == "false") // only the lowest level categories have semantic trees
    {
      if (window.KGNavigationControl_SwitchTabs)
      {
        KGNavigationControl_SwitchTabs('CS_' + _topLevelTopicId, _nodeText);
        if(_topLevelTopicId > 0)
        {
          if (window.KGNavigationControl_ShowHideSemanticTreeCheckBox)
            KGNavigationControl_ShowHideSemanticTreeCheckBox(1);
        }
        KGNavigationControl_TreeNavBarRePopulate();
      }
    }
    
    // reload the home content control if we're on the home page, otherwise redirect to home page
    var currentLocation = window.location.href;
    var currentPage = currentLocation.substring(currentLocation.lastIndexOf('/')+1, currentLocation.length).toLowerCase();
    if (currentPage.indexOf('home') > -1 || currentPage.length == 0)
    {
        // select the Indexed Docs tab
      globalIndexedDocsPageLoaded = false;
      //KGTabbedWindowsControl_SelectTabById('Indexed Documents');
      
      // let the map view reload when it is viewed
      globalMapViewControlLoaded = false;

      SetSessionProperty('KGMapViewCollapsed',false);
      var mapViewCollapsed = !globalMapPaneOpen;
      if (mapViewCollapsed == false) // map view is visible, reload it
        MapViewControl1_CallbackTrigger();
      else // map view is not visible - open the splitter
      {
        //globalMapViewControlLoaded = false;
        DoExpandMapViewPane();
      }
    }
    else if(currentPage.indexOf('configurecommunityspace') > -1 || currentPage.length == 0)
    {
      var hostURL = currentLocation.substring(0, currentLocation.lastIndexOf('/') + 1);
      window.location = hostURL + 'configurecommunityspace.aspx';
    }
    else
    {
      var hostURL = currentLocation.substring(0, currentLocation.lastIndexOf('/') + 1);
      window.location = hostURL + 'home.aspx';
    }
  }
  catch (e) 
  {
    alert("An exception occurred in the script. Error name: " + e.name + ". Error message: " + e.message); 
    //debugger;
  }

}


// Handle tree node expand or collapsed 
function TopicsControl_SetTreeNodeStatus(_node, _hiddenFieldClientID, _sessionNameForExpandedNodes, _scrollFunctionName, _srmIndex) 
{
  if(_node != null)
  {
    var seperator = '@';
    var nodeID = _node.ID;
    var box = document.getElementById(_hiddenFieldClientID);
    if(box != null)
    {
      var nodesstatus = box.value;
      if(_node.Expanded)
      {
        // then this node will be collapsed
        box.value = nodesstatus.replace(nodeID+seperator,'');
      }
      else
      {
        // will be expanded
        if(nodesstatus.indexOf(nodeID) < 0)
        {
          // not recorded yet
          box.value = nodesstatus + nodeID + seperator;
        } //end index if
      } //end expanded if
      SetSessionProperty(_sessionNameForExpandedNodes, box.value);
    }
    else
    {
        alert('Topic tree hidden field not found.');
    } //end box null if
  } //end node null if
  
  return true; 
}// end function




function KGTopicsControl_ProcessCallBackError_Wrapped(_args, _context, _topicsControlClientID)
{
  //debugger;
  try
  {
    var holder = document.getElementById(_topicsControlClientID);
    if (holder != null)
        holder.innerHTML = 'Exception occurred.';
  }
  catch (e) 
  {
    alert("An exception occurred in the script. Error name: " + e.name + ". Error message: " + e.message); 
    //debugger;
  }
}


function Topics_Repopulation(_args, _context)
{
  //debugger;
  try
  {
    var repop = _args.split('[@|@]');
    var repopulateStatus = repop[0].split('=');
    if(repopulateStatus[1] == 'true')
    {
      _args = repop[1];
      var holderId = _args.substring(0, _args.indexOf('='));
      var holder = document.getElementById(holderId);
      if(holder != null)
        holder.innerHTML = _args.substring(_args.indexOf('=')+1);
    }
  }
  catch (e) 
  {
    alert("An exception occurred in the script. Error name: " + e.name + ". Error message: " + e.message); 
    //debugger;
  }
}

function TopicsControl_RepopulateCallbackDone()
{
  // Check for a session time out before completing the callback
  if (CheckSessionTimeout())
    return;
}


function KGTopicsControl_CallBackDone()
{
  // Check for a session time out before completing the callback
  if (CheckSessionTimeout())
    return;
}


// temp fix for ConceptTabbedView - so don't show back button for categories tab
function KGTopicsControl_isTopicSelected()
{
  return false;
}
