﻿// TabbedWindowsControl JScript File

var global_TabbedWindowsControl_CurrentlySelectedTab = null;

// variables used to determine if page has already been loaded
var globalKGListPageLoaded = false;
var globalIndexedDocsPageLoaded = false;
var globalTextViewPageLoaded = false;
var globalDocumentPageLoaded = false;
var globalCommunityPageLoaded = false;
var globalCategoryHomePageLoaded = false;
var RelatedConcept = "";
var currentlySelectedKG = "";
var savedConcept;
var currentDocListKnowdeID;
var currentDocListMode = "None";

// 
// this will rerender audit history table after call back
function KGTabbedWindowsControl_CallbackDone_Wrapped(args, context, _tabStripClientID)
{

}

// The Callback trigger will populate the selected tab if it has not yet been loaded.
// If it has been loaded, it will do nothing.
function KGTabbedWindowsControl_CallbackTrigger_Wrapped(action,
                                                        _cbreference, 
                                                        _tabStripClientID,
                                                        _thisClientID,
                                                        _parsingDocControlSessionNameForDocument,
                                                        _clientSideOnDocumentTabClosed,
                                                        _kgMemberControlSessionNameForCommunity,
                                                        _clientSideOnCommunityTabClosed,
                                                        _SelectedTabOnPageLoad,
                                                        _srmIndex,
                                                        _doButtonToolbarCallback)
{

}

// This function evals the cbreference for the selected tab (_tabID)
function KGTabbedWindowsControl_RepopulateTab(_tabID,
                                              _thisClientID,
                                              action,
                                              _cbreference,
                                              _srmIndex)
{

}

function CallbackAfterTimeout(_args, _cbreference)
{
  var args = _args;
  eval(_cbreference);
}

function KGTabbedWindowsControl_TabSelected_Wrapped(_eventArgs,
                                                    _thisClientID,
                                                    _srmIndex)
{

}

// prevent double gene click until one has loaded
var globalGeneClick = 'true';
var globalHighlightedRow = '';

function HightlightSelectedRow(_rowID)
{
//debugger;
	var frm = document.getElementById('LTSC_LeftPaneMyKnowledgeControl_Grid');

	for(var k=0;k< frm.getElementsByTagName("tr").length;k++)
  {
    if(frm.getElementsByTagName("tr").item(k).className == "LeftPaneRowHighlight")
    {
			frm.getElementsByTagName("tr").item(k).className = ""
//			frm.getElementsByTagName("tr").item(k).onmouseover = function(){this.style.backgroundColor="#f7f7f7"};
//			frm.getElementsByTagName("tr").item(k).onmouseout = function(){this.style.backgroundColor="#ffffff"};
    }
  }
  
//  document.getElementById(_rowID).parentNode.parentNode.parentNode.onmouseover = '';
//	document.getElementById(_rowID).parentNode.parentNode.parentNode.onmouseout = '';
  document.getElementById(_rowID).parentNode.parentNode.parentNode.className = 'LeftPaneRowHighlight';

////debugger;
//  document.getElementById(_rowID).parentNode.parentNode.parentNode.className = 'LeftPaneRowHighlight';
//  
//  if(globalHighlightedRow != '' && globalHighlightedRow != _rowID)
//  {
//    // the kg may have ben deleted or removed, so lets first check its still in the list...
//    if(document.getElementById(globalHighlightedRow) != null)
//			document.getElementById(globalHighlightedRow).parentNode.parentNode.parentNode.className = '';
//  }
//  
//  globalHighlightedRow = _rowID;
}

function RemoveOption_Show(_removeBtnId)
{
  document.getElementById(_removeBtnId).className = "LeftPaneMyKGControl_GeneDocumentRemoveShow";
}

function RemoveOption_Hide(_removeBtnId)
{
  document.getElementById(_removeBtnId).className = "LeftPaneMyKGControl_GeneDocumentRemoveHide";
}

// _groupID: the GroupID for the KG
function KGTabbedWindowsControl_MyHK_KGSelected(_KnowdeKey, _ownerKey, _kgid, _openText, _groupID, _rowID)
{

  if(_rowID != undefined)
		HightlightSelectedRow(_rowID.id);
		
	if(globalGeneClick == 'true')
	{
		globalGeneClick = 'false';
		// these two session variables are used in the TabbedWindowsControl callback then removed in ProcessAJAXCallback
		// so if the callback is not triggered they shouldn't be set
		if(_openText != true &&	global_TabbedWindowsControl_CurrentlySelectedTab != 'Indexed Documents')
		{
			// The map view callback is triggered this side of the TabbedWindowsControl callback 
			// so cancel the callback trigger in the TabbedWindowsControl_callback done
			SetSessionProperty('IndexedDoc_MyHK_KGID', _kgid);
		}
		
		KGTabbedWindowsControl_KGSelected(_KnowdeKey, _ownerKey, _kgid, _openText, true, _groupID);
		globalGeneClick = 'true';
	}  
}


// KGTabbedWindowsControl_KGSelected handler
// _KnowdeKey: the string KnowdeKey
// _groupID: the GroupID for the KG
function KGTabbedWindowsControl_KGSelected(_KnowdeKey, _ownerKey, _kgid, _openText, _MyHK, _groupID)
{
  if (window.CloseApplicationControl && m_applicationControlOpen && !m_appForceOpen)
  {
    CloseApplicationControl();
  }
	// if the current map has been clicked and a different KG map will be loaded, 
	// then the old map need to become background map
	var sdiv1 = document.getElementById('scrolling-section');
	var sdiv2 = document.getElementById('scrolling-section-disable');
	// if not first time loading the map
	if(sdiv1 != null && sdiv2 != null && Active_KGID != '')
	{
		if(LastKnowdeClickedKGID == Active_KGID)
		{
			Background_KGID = Active_KGID;
			Background_SelectedKnowde = Active_GlobalLastSelectedKnowde;
			SetSessionProperty('Background_SelectedKG', Background_KGID + '|' + returnKnowdeID(Background_SelectedKnowde));
			SetSessionProperty('BackUpKGContext', Active_KGID);
			if(Active_KGID != ('' + _kgid + ''))
			{
				Background_howChainArray = howChainArray;
				Background_whyChainArray = whyChainArray;
				Background_ShadowKnowdeList = Active_ShadowKnowdeList;
				Background_CenterShadowKnowdeList = Background_ShadowKnowdeList;
				Background_SelectedKnowdePosX = parseInt(Background_SelectedKnowde.parentNode.style.left);
				Background_SelectedKnowdePosY = parseInt(Background_SelectedKnowde.parentNode.style.top) + Background_SelectedKnowde.offsetTop;
				Background_KnowdeWidth = knowdeWidth;
        
				//if(Background_ShadowKnowdeList.indexOf(','+returnKnowdeID(Background_SelectedKnowde)+'|') > -1)
				//{
					// there is shadow showed in it, adjust the offset top
					//Background_SelectedKnowdePosY -= KnowdeShadow_OffsetTopPX;
				//}
				// set background map
				Background_DivInnerHTML = sdiv1.innerHTML;
				var contents = Background_DivInnerHTML;//.replace("KnowdeShadow' style='visibility:visible;","KnowdeShadow' style='visibility:hidden;");
				//contents = contents.replace("KnowdeShadow style='visibility:visible;","KnowdeShadow style='visibility:hidden;");
				sdiv2.innerHTML = contents;
			}
		}
    
		if(Background_KGID == ('' + _kgid + ''))
		{
			// same mapview, don't show the background one, 
			ClearBackgroundMapView();
		}
		else
		{
				// don't show background map at the moment  
				HighlightConcept = false; //HighlightConcept = true;
		}
	} 
	// in the SessionPropertiesAshxHandler, if the knowdeKey is same with Background_SelectedKnowdeID, then won't override the context
	if (_KnowdeKey != null)
	{
		if(sdiv1 != null && sdiv2 != null && Active_KGID != '')
			SetSessionProperty('KGList_SelectedKGID', _KnowdeKey);
		else
			SetSessionProperty('SelectedKGID', _KnowdeKey);
	}

  var keys = 'RemoveSelectedConcept|MapViewDisplayMode'
  var values = '0|KGMapView';
  if (_groupID != null)
  {
    keys += '|Topics_SelectedTopicGroupId';
    values += '|' + _groupID;
  }
  SetSessionProperty(keys, values, true);
  
	// let the map view reload when it is viewed
	globalMapViewControlLoaded = false;
  
	if(_openText == true)
	{
	//debugger;
		ClearTextViewValues();
		// Load the text view page
		globalTextViewPageLoaded = false;
		if (_MyHK)
			ShowSelectedKnowdeHalo(globalLastSelectedKnowde, globalLastMapDirection);
		//KGTabbedWindowsControl_SelectTabById('TextView');

	}
	else
	{ // kg click
    
		// turn off edit mode
		if(m_bEditable == true)
		{
			SwitchEditableFlag();
		}
      
		// don't show background map at the moment  
		ShowBackgroundMapView = 0; //ShowBackgroundMapView = 1;
		SetSessionProperty('KGMapViewCollapsed',false);
         
		var mapViewCollapsed = PaneBStatus();
		if (mapViewCollapsed == null || mapViewCollapsed == false) // map view is visible, reload it
		{
			MapViewControl1_CallbackTrigger();
		}
		else // map view is not visible - open the splitter
		{
			//globalMapViewControlLoaded = false;
			DoExpandMapViewPane("fully");
		}
		if(globalSplitterSetting == "split")
			ShowSplitterArrowDown();
	}// else show text view click, don't reload the map
  
	currentlySelectedKG = _kgid;
	globalLastTickerAction = "";
}

function KGTabbedWindowsControl_SelectTabById_Wrapped(_tabId, _thisClientID, _tabStripClientID, _doButtonToolbarCallback)
{
  /*if(_thisClientID != "undefined")
  {
    var tabStrip = eval(_tabStripClientID);
    if(tabStrip != null)
    {
      var selectedTab = tabStrip.selectTabById(_tabId);
      SetSessionProperty(_thisClientID + '_SelectedTab', _tabId);
      global_TabbedWindowsControl_CurrentlySelectedTab = _tabId;
      KGTabbedWindowsControl_CallbackTrigger('TabSelected, ' + _tabId, null, _doButtonToolbarCallback);
    }
  }*/
}

function ShowTextView(_knowdeKey, _ownerKey, _kgId, _openText, _HK)
{
   //debugger;
  // if ! editing
  if(m_bEditable == true)
    if(_HK == true)
      KGTabbedWindowsControl_MyHK_KGSelected(_knowdeKey, _ownerKey, _kgId, _openText);
    else
      KGTabbedWindowsControl_KGSelected(_knowdeKey, _ownerKey, _kgId, _openText); 
  else
  {
		if(globalSplitterSetting == "split")
			ShowSplitterArrowDown();
    globalHelpTopicKey = 'needTextView';
    
    if(document.getElementById("DockedHelpWindow") != null)
      DisplayTextViewInTab('TextView', '', 'false', _kgId);
    else
      DisplayTextViewInTab('TextView', '', 'true', _kgId);
    
    var MapHelpBox = document.getElementById("KGHelpControlID1");
    MapHelpBox.title = "Associated Text";
    
    //KGHelpControl_CallbackTrigger(globalHelpTopicKey, globalHelpTopicParams);
  }
}

function ShowWebDocument(_url)
{
  window.open(_url);
}

function ResetScrollBar()
{
  //this resets the indexed docs scroll bar position back to the top when using the paging
  document.getElementById("Splitter1_pane_1").firstChild.scrollTop = 0;
}
