﻿// ConceptTabbedView JScript File
var global_ConceptTabbedControl_CurrentlySelectedTab = 'none';

function KGOptionControl_OptionChange(tab, _modeAlertCheck, _administrator, _bCategoryAdministrator)
{
  //debugger;
  try
  {
    if(document.getElementById('KGOptionControlID1') != null)
    {
      var optiondiv = document.getElementById('KGOptionControl');
      var loginview = "Library_LoginView_";

      try
      {
          loginview = "Library_LoginView_";
          var check = document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber0").src = "Images/NewKgIcon.png";
      }
      catch(Exception)
      {
        loginview = "";
      }
      switch(tab.ID)
      {
      case "Personal":     

//            document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber0").src = "Images/NewKgIcon.png";  
//            document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber0").width = 30;       
//            document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber0").onclick = function(){ShowKGNewKnowledgeGeneControl()};       
//            document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber0").onmouseover = function(){this.style.cursor='pointer'};
//            document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber0").title = "Create new Knowledge Gene in \"My Knowledge\"";
            
//            document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber0").src = "Images/NewCategoryIcon.png";
//            document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber0").onclick = function(){KGPrivateSpaceCreatedControl_CreatePrivateSpace()};
//            document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber0").onmouseover = function(){this.style.cursor='pointer'};
//            document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber0").title = "Create a Community/Sub-Community Space";
            
            document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber0").src = "Images/NewCategoryIcon_Grey.png";
            document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber0").onclick = "";
            document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber0").onmouseover = function(){this.style.cursor='default'};
            document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber0").title = "";
         
          break;
      case "Library":

//            document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber0").src = "Images/NewCategoryIcon_Grey.png";
//            document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber0").onclick = "";
//            document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber0").onmouseover = function(){this.style.cursor='default'};
//            document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber0").title = "";
//            
//            document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber0").src = "Images/NewCategoryIcon_Grey.png";
//            document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber0").onclick = "";
//            document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber0").onmouseover = function(){this.style.cursor='default'};
//            document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber0").title = "";
            
            document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber0").src = "Images/NewCategoryIcon_Grey.png";
            document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber0").onclick = "";
            document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber0").onmouseover = function(){this.style.cursor='default'};
            document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber0").title = "";
       
          break;   
      case "Results":  
//          document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber0").src = "Images/NewCategoryIcon_Grey.png";
//          document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber0").onclick = "";
//          document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber0").onmouseover = function(){this.style.cursor='default'};
//          document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber0").title = "";
       
//          document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber0").src = "Images/NewCategoryIcon_Grey.png";
//          document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber0").onclick = "";
//          document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber0").onmouseover = function(){this.style.cursor='default'};
//          document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber0").title = "";
          
          document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber0").src = "Images/NewCategoryIcon_Grey.png";
          document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber0").onclick = "";
          document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber0").onmouseover = function(){this.style.cursor='default'};
          document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber0").title = "";
        
          break;   
      default:
        // This is for Community Space Tabs that have been dynamically created
        // They all start with CS_
        if(tab.ID.substr(0,3) == 'CS_')
        { 
          if(_administrator == 1 && tab.Text != "Categories")
          {
//          document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber0").src = "Images/NewCategoryIcon_Grey.png";
//          document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber0").onclick = "";
//          document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber0").onmouseover = function(){this.style.cursor='default'};
//          document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber1").title = "";
          
//          document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber0").src = "Images/NewCategoryIcon.png";
//          document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber0").onclick = function(){KGPrivateSpaceCreatedControl_CreatePrivateSpace()};
//          document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber0").onmouseover = function(){this.style.cursor='pointer'};
//          document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber0").title = "Create a Community/Sub-Community Space";
//          
          document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber0").src = "Images/Cog2.png";        
          document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber0").onclick = function(){KGPrivateSpaceAdminControl_OpenPrivateSpace()};       
          document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber0").onmouseover = function(){this.style.cursor='pointer'};
          document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber0").title = "Configure your Community Space";
          }
          else
          {
//          document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber0").src = "Images/NewCategoryIcon_Grey.png";
//          document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber0").onclick = "";
//          document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber0").onmouseover = function(){this.style.cursor='default'};
//          document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber0").title = "";
          
            // If they are a category Administrator they can add new categories 
//            if(_bCategoryAdministrator = true)
//            {
//              document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber0").src = "Images/NewCategoryIcon.png";
//              document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber0").onclick = function(){KGPrivateSpaceCreatedControl_CreatePrivateSpace()};
//              document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber0").onmouseover = function(){this.style.cursor='pointer'};
//              document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber0").title = "Create a Community/Sub-Community Space";          
//            }
//            else
//            {
//              document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber0").src = "Images/NewCategoryIcon_Grey.png";
//              document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber0").onclick = "";
//              document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber0").onmouseover = function(){this.style.cursor='default'};
//              document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber0").title = "";
//            }
          
          document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber0").src = "Images/NewCategoryIcon_Grey.png";        
          document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber0").onclick = "";       
          document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber0").onmouseover = function(){this.style.cursor='default'};
          document.getElementById(loginview + "ConceptTabbedView1_KGOptionControl_ImageNumber0").title = "";
          }      
        }
          break;    
      }
    }
  }
  catch (e) 
  {
    alert("An exception occurred in the script. Error name: " + e.name + ". Error message: " + e.message); 
    //debugger;
  }
}

function ConceptTabbedView_SelectInitialTab(_tabStrip, _srmIndex)
{
  //debugger;
  try
  {
    SetRepopulationHiddenFields();
    
    var tab = _tabStrip.GetSelectedTab();
    if (tab.ID == "PrivateSpace")
    {
       ConceptTabbedView1_SelectPersonalTab();
       tab = _tabStrip.GetSelectedTab();
    }
    
    // vertical tab strip selected tab will be hidden
    ConceptTabbedView_TabSelected(null, null, tab, _srmIndex);
  }
  catch (e) 
  {
    alert("An exception occurred in the script. Error name: " + e.name + ". Error message: " + e.message); 
    //debugger;
  }
}

function ConceptTabbedView1_UpdateTabTextAndTitle_Wrapper(_tabStripClientID, _tabID, _titleLabelClientID, _tabContextSeparator, _subfixName)
{
  //debugger;
  try
  {
    var tabStrip = _tabStripClientID;
    if(tabStrip != null)
    {
      var tab = tabStrip.FindTabById(_tabID);
      if(tab != null)
      {
        // update tab text
        ConceptTabbedView_UpdateTabText(tab, _tabContextSeparator, _subfixName);
        
        // update title lable
        var titleLabel = document.getElementById(_titleLabelClientID);
        if(titleLabel != null)
        {
          titleLabel.innerHTML = tab.Text;
        }
      }
    }
  }
  catch (e) 
  {
    alert("An exception occurred in the script. Error name: " + e.name + ". Error message: " + e.message); 
    //debugger;
  }
}

function ConceptTabbedView_UpdateTabText(_tab, _tabContextSeparator, _subfixName)
{
  //debugger;
  try
  {
    // set the correct tab name
    var tabName = _tab.Text;
    var separatorIndex = tabName.indexOf(_tabContextSeparator);
    
    // If the subfix name is no length we wish to remove the last item as going up a level
    // if(_subfixName.length == 0)
    // This has broken the original function. this method shouldn't be changed, it should be the code that calling into this function
    // to pass in the correct Full subFixName or empty if don't need subfix
    if(separatorIndex > 0)
    {
      tabName = tabName.substring(0, separatorIndex);
    }
      
    if(_subfixName.length > 0)
    {
      // capitalize first letter
      _subfixName = _subfixName.substring(0,1).toUpperCase() + _subfixName.substring(1);
      tabName = tabName + _tabContextSeparator + _subfixName;
    }
    
    if(_tab.Text != tabName) 
    {
      _tab.Text = tabName;
      _tab.SaveState();
    }
  }
  catch (e) 
  {
    alert("An exception occurred in the script. Error name: " + e.name + ". Error message: " + e.message); 
    //debugger;
  }
}


function ConceptTabbedView1_SwitchTabs_Wrapper(_tabStripClientID, _tabID, _titleLabelClientID, _tabContextSeparator, _subfixName, _groupNameHiddenField, _groupIDHiddenField)
{
  //debugger;
  try
  {
    // show the previously selected tab
    var tabStrip = _tabStripClientID;
    if(tabStrip != null)
    {
      var tab = tabStrip.FindTabById(_tabID);
      if(tab != null)
      {
        // updat tab text
        if(_subfixName != null && _subfixName.length > 0)
        {
          ConceptTabbedView_UpdateTabText(tab, _tabContextSeparator, _subfixName);
        }
        
        // switch tabs
        if(global_ConceptTabbedControl_CurrentlySelectedTab != null && global_ConceptTabbedControl_CurrentlySelectedTab != tab.ID)
        {
          var previousTab = tabStrip.FindTabById(global_ConceptTabbedControl_CurrentlySelectedTab);
          if(previousTab != null)
          {
            previousTab.Visible = 1; 
            previousTab.SaveState();
          }
        }
        // select current tab
        global_ConceptTabbedControl_CurrentlySelectedTab = tab.ID;
        SetSessionProperty('ConceptTreeTabbedView_SelectedTab', tab.ID);
        
        // Set hidden fields
        var groupName = document.getElementById(_groupNameHiddenField);
        if(groupName != null)
        {
          groupName.value = "Temp Text";
        }
        
        var groupID = document.getElementById(_groupIDHiddenField);
        if(groupID != null)
        {
          groupID.value = tab.ID;
        }
        
        ConceptTabbedView_ChangeBackButtonMode(ShowBackButton(tab));
        
        // hide the current tab and set the title
        tab.Visible = 0; 
        tab.SaveState();
        
        var titleLabel = document.getElementById(_titleLabelClientID);
        if(titleLabel != null)
        {
          titleLabel.innerHTML = tab.Text;
        }
      }
    }

    var currentLocation = window.location.href;
		var hostURL = currentLocation.substring(0, currentLocation.lastIndexOf('/') + 1);
    if(window.location.href == hostURL + "PrivateSpaceAdmin.aspx" && tab.ID.substr(0,3) != 'CS_')
    {
      window.location = "home.aspx";
    }
  }
  catch (e) 
  {
    alert("An exception occurred in the script. Error name: " + e.name + ". Error message: " + e.message); 
    //debugger;
  }
}

// Client Side On Tab Select
function ConceptTabbedView_TabSelected_Wrapped(tab, _tabStripClientID, _titleLabelClientID, _modeAlertCheck, _cbreference, _personalLibDropDownListClientID, _groupID, _hiddenfieldID, _administrator, _srmIndex, _bCategoryAdministrator)
{
  //debugger;
  try
  {
    if(tab != null)
    {
      SetSessionProperty('KGCurrentTabID', tab.ID);
      
      try
      {
        if (m_srmGetTimes!= null && m_srmGetTimes == "True" && _srmIndex != null)
          m_srmAction[_srmIndex] += ',' + tab.ID;
      }
      catch(e){}
      
      ConceptTabbedView1_SwitchTabs(tab.ID, null);
      
      var oddl = document.getElementById(_personalLibDropDownListClientID);

      switch(tab.ID)
      {
      case "Personal": 
          KGOptionControl_OptionChange(tab, _modeAlertCheck, _administrator, _bCategoryAdministrator);
          SetSessionProperty('ConceptKGCurrentGroupID', _groupID);
          SetSessionProperty('ConceptTopics_SelectedTopicGroupId', null);
          SetSessionProperty('ConceptTopics_SelectedTopicName', null);
          break
      case "Results":
          KGOptionControl_OptionChange(tab, _modeAlertCheck, _administrator, _bCategoryAdministrator);
          SetSessionProperty('ConceptKGCurrentGroupID', _groupID);
          SetSessionProperty('ConceptTopics_SelectedTopicGroupId', null);
          SetSessionProperty('ConceptTopics_SelectedTopicName', null);
          break;
      case "Library":
          KGOptionControl_OptionChange(tab, _modeAlertCheck, _administrator, _bCategoryAdministrator);
          SetSessionProperty('ConceptTopics_SelectedTopicGroupId', null);
          SetSessionProperty('ConceptTopics_SelectedTopicName', null);
          break
      default:
        // This is for Community Space Tabs that have been dynamically created
        // They all start with CS_ also includes the category tab
        if(tab.ID.substr(0,3) == 'CS_')
        {
          KGOptionControl_OptionChange(tab, _modeAlertCheck, _administrator, _bCategoryAdministrator);
          
          // To set the correct Group ID we use the ID from the Tab ID
          var groupID = tab.ID.substr(3,tab.ID.length - 1)
          
          SetSessionProperty('ConceptKGCurrentGroupID', groupID);
        }
        else
        {
          SetSessionProperty('ConceptKGCurrentGroupID', -1);
        }
      }

      if(oddl != null)
      {
        if(tab.ID == 'Personal')
        {
          oddl.className = 'PersonalLibDropDownList';
        }
        else
        {
          oddl.className = 'PersonalLibDropDownListHidden';
        } // end if tab.ID
      } // end if oddl
//debugger;
      var repopulateStatus = document.getElementById(_hiddenfieldID);
      if (repopulateStatus != null && repopulateStatus.value.indexOf(tab.ID + '|') > -1)
      {
        // This check is to ensure that it repopulates all instances of the Community Spaces Tab
        // This also incudes the Category Tab as well.
        if(tab.ID.substr(0,3) != 'CS_')
          repopulateStatus.value = repopulateStatus.value.replace(tab.ID + '|', '');
        
        var args = 'Action=RepopulateTab|TabID=' + tab.ID + '|SrmIndex=' + _srmIndex;
        eval(_cbreference);
      } // end if repopulate status true
      
      if (window.MapViewDefaultFocus)
        MapViewDefaultFocus();
        
      var currentLocation = window.location.href;
      var currentPage = currentLocation.substring(currentLocation.lastIndexOf('/')+1, currentLocation.length).toLowerCase();
      if (currentPage.indexOf('home') > -1 || currentPage.length == 0)
        HomeContentControl_CallbackTrigger();
    } 
    return true; //end tab null if
  }
  catch (e) 
  {
    alert("An exception occurred in the script. Error name: " + e.name + ". Error message: " + e.message); 
    //debugger;
  }
} //end function

// Personal library drop list selection changed
function ConceptTabbedView_PersonalLibOptionsChanged_Wrapped(_cbreference, _personalLibDropDownListClientID, _optionDivClientID, _personalLibraryContentConcepts)
{
  //debugger;
  try
  {
    var personalLibDDL = document.getElementById(_personalLibDropDownListClientID);
    if(personalLibDDL != null)
    {
      var selectedOption = personalLibDDL.options[personalLibDDL.selectedIndex].value;
      SetSessionProperty('ConceptTabbedView_PersonalLibContent',selectedOption);
      var odiv = document.getElementById(_optionDivClientID);
      if(odiv != null)
      {
        if(selectedOption == _personalLibraryContentConcepts)
        {
          odiv.className = 'SubscriptionOptionCell';
        }
        else
        {
          odiv.className = 'SubscriptionOptionCellHidden';
        } // end if tab.ID
      } // end if odiv    
      var args = 'Action=RepopulateTab|TabID=Personal';
      eval(_cbreference);
    } // end if not null
  }
  catch (e) 
  {
    alert("An exception occurred in the script. Error name: " + e.name + ". Error message: " + e.message); 
    //debugger;
  }
} //end function

// RePopulateCallbackDone - Also used when Subscription changed as well
function ConceptTabbedView_RepopulateTabCallbackDone_Wrapped(args, context,_tabStripClientID)
{
  //debugger;
  try
  {
    // Check for a session time out before completing the callback
    if (CheckSessionTimeout())
      return;
    if(args.indexOf('Status=Error') > -1)
    {
      var statusInfo = args.split('[@|@]'); 
      var status = statusInfo[0].split('=');
      if(status[1]=='Error')
      {
        var holderID = statusInfo[1].split('=');
        var exception = statusInfo[2].split('=');
        var callbackerror = holderID[1] + '=' + exception[1];
        ConceptTabbedView_ProcessCallBackError(callbackerror, '');
      }
    }
    else
    {
      var scriptToCall = args.split('[@|@]');
      var scriptFunction = scriptToCall[0].split('=');
      if(scriptFunction[1].length > 0)
      {
        var newArgs = args.substring(args.indexOf('[@|@]') + 5);
        eval(scriptFunction[1] + '(newArgs, context)');
      }
      else
      {
        ConceptTabbedView_ProcessCallBackError('Script function not found.', '');
      }
    }
    
    var tabStrip = _tabStripClientID;
    var tab = tabStrip.GetSelectedTab()
    
    var lastRootNodeHiddenFieldClientID;
    var lastRootNodeHiddenField;
    if (tab.ID == "Results")
    {
      lastRootNodeHiddenFieldClientID = SearchResult_GetLastRootNodeHiddenFieldID();
      lastRootNodeHiddenField = document.getElementById(lastRootNodeHiddenFieldClientID);
    }
    else if (tab.ID.substr(0,3) == 'CS_')
    {
      if (window.Topic_GetLastRootNodeHiddenFieldID)
      {
        lastRootNodeHiddenFieldClientID = Topic_GetLastRootNodeHiddenFieldID();
        lastRootNodeHiddenField = document.getElementById(lastRootNodeHiddenFieldClientID);
      }
    }
    else if (tab.ID == "Personal")
    {
      lastRootNodeHiddenFieldClientID = PersonalLibrary_GetLastRootNodeHiddenFieldID();
      lastRootNodeHiddenField = document.getElementById(lastRootNodeHiddenFieldClientID);
    }

    if (lastRootNodeHiddenField != null)
    {
      if(args.indexOf('lastRootNodeID:') > -1)
      {
        var subLastRootNodeID = args.split('lastRootNodeID:');
        lastRootNodeHiddenField.value = subLastRootNodeID[1];
      }
      else
      {
        lastRootNodeHiddenField.value = null;
      }
      
      ConceptTabbedView_ChangeBackButtonMode(ShowBackButton(tab));
    }
  }
  catch (e) 
  {
    alert("An exception occurred in the script. Error name: " + e.name + ". Error message: " + e.message); 
    //debugger;
  }
}

// UpdateRepopulationHiddenFields
function SetRepopulationHiddenFields_Wrapped(_hiddenfieldID, _statusInfo) 
{
  //debugger;
  try
  {
    var repopulateStatus = document.getElementById(_hiddenfieldID);
    if (repopulateStatus != null) 
    {
      var statusInfo = '';
      // set status
      statusInfo = statusInfo + _statusInfo;
      repopulateStatus.value = statusInfo;
    } // end if repopulate status is not null
  }
  catch (e) 
  {
    alert("An exception occurred in the script. Error name: " + e.name + ". Error message: " + e.message); 
    //debugger;
  }
} //end function

// ProcessCallBackError
// this will return message in case of error
function ConceptTabbedView_ProcessCallBackError(args, context)
{
  //debugger;
  try
  {  
    // Here we are dealing with authentication timeout before callback, 
    // the message from the server is 'elogin' signify an error with 
    // authentication. The response will be trimmed to form the args 
    // 'login' here..... 
    if(args == 'login')
    {
      window.location='home.aspx';
    }
    else
    {
      if(args.indexOf('=') > -1)
      {
        var s = args.split('='); 
        var holder = document.getElementById(s[0]);
        if(holder != null)
        {
          holder.innerHTML = 'An error has occurred. ' + s[1];
        }
        else
        {
          alert('Exception occurred. '+ s[1]);
        }
      }
      else
      {
        alert('Exception occurred. '+ args);
      }
    }
  }
  catch (e) 
  {
    alert("An exception occurred in the script. Error name: " + e.name + ". Error message: " + e.message); 
    //debugger;
  }
}

// ConceptTabbedViewDocument_CallbackTrigger
function ConceptTabbedViewDocument_CallbackTrigger_Wrapped(action, _multiPageClientID, _tabStripClientID, _cbreference, _srmIndex) 
{
  //debugger;
  try
  {
    // render document
    if(action=='DocumentSelected')
    {
      var args = 'Action=RepopulateTab|TabID=Document|SrmIndex=' + _srmIndex;
      eval(_cbreference);
      // show document tab
      var tabStrip = _tabStripClientID;
      if(tabStrip != null)
      {
        var docTab = tabStrip.FindTabById('Document');
        if(docTab != null)
        {
          docTab.Visible = 1; docTab.SaveState();
          
          // select tab
          tabStrip.SelectTabById(global_ConceptTabbedControl_CurrentlySelectedTab);
        }// end doctab is not null
      } // end tabstrip is not null
    } // end action

    // document tab close
    if(action=='DocumentClosed')
    {
      selectedPageID = _multiPageClientID;
      var args = 'Action=RepopulateTab|TabID=Document';
      eval(_cbreference);
      // hide document tab 
      var tabStrip = _tabStripClientID;
      if(tabStrip != null)
      {
        var docTab = tabStrip.FindTabById('Document');
        if(docTab != null)
        {
          docTab.Visible = 0; docTab.SaveState();
          
          // select library tab instead if the current selected tab is the Document tab
          if(docTab.IsSelected())
          {
            tabStrip.SelectTabById('Library');
            SetSessionProperty('ConceptTreeTabbedView_SelectedTab', 'Library');
          }
          else
          {
            // remain in the current selected tab
            var currentTab = tabStrip.SelectedTabPostBackID;
            tabStrip.SelectTabByPostBackId(currentTab);
          } // end if else docTab selected
        } // end docTab is not null
      } // end tabStrip is not null
    } // end action DocumentClosed
  }
  catch (e) 
  {
    alert("An exception occurred in the script. Error name: " + e.name + ". Error message: " + e.message); 
    //debugger;
  }
} //end function

function ConceptTabbedView1_SelectResultTab_Wrapper(_tabStripClientID, _titleLabelClientID, _tabContextSeparator, _itemName)
{
  //debugger;
  try
  {
    SetSessionProperty('KGShowResultsTab', 'true');
    //SetSessionProperty('ConceptTabbedView_SelectedTab', 'Results');
      
    var tabStrip = _tabStripClientID;
    var resultsTab = tabStrip.FindTabById('Results');
    //resultsTab.Visible = 1;
    //resultsTab.SaveState();
    tabStrip.SelectTabById('Results');
    //ConceptTabbedView_TabSelected(null, null, resultsTab);
    
    // store in session
    SetSessionProperty('SearchResult_SearchRootPhraseName', _itemName); 
    //global_ConceptTabbedControl_CurrentlySelectedTab = 'Results';

    ConceptTabbedView1_SwitchTabs(resultsTab.ID, _itemName);
  }
  catch (e) 
  {
    alert("An exception occurred in the script. Error name: " + e.name + ". Error message: " + e.message); 
    //debugger;
  }
}

function ConceptTabbedView1_SelectPersonalTab_Wrapper(_tabStripClientID, _titleLabelClientID)
{
  //debugger;
  try
  {
    SetSessionProperty('KGShowPersonalTab', 'true');      
    var tabStrip = _tabStripClientID;
    var personalTab = tabStrip.FindTabById('Personal');
    tabStrip.SelectTabById('Personal');    
    ConceptTabbedView1_SwitchTabs(personalTab.ID, null);
  }
  catch (e) 
  {
    alert("An exception occurred in the script. Error name: " + e.name + ". Error message: " + e.message); 
    //debugger;
  }
}

// DisplaySearchResult Callback scripts
function ConceptTabbedView1_CallbackTrigger_Wrapped(_itemID, _itemType, _itemName, _rootPhraseName, _titleLabelClientID, _tabContextSeparator, _MapViewDisplayModeKGMapView, _cbreference, _srmIndex, _tabStripClientID, _tabbedViewClientID)
{
  //debugger;
  try
  {
    //Show loading icon (bug 2856)
    var holder = document.getElementById(_tabbedViewClientID.id + "_ResultsPage");
    if(holder != null)
    {
      holder.innerHTML = '<table width=\"100%\"><tr><td align=\"center\" style=\"font-size: xx-small;font-family:Verdana;\"><br/><img src=\"Images/loadingbar.gif\" /> Loading...</td></tr></table>';
    }

    SetSessionProperty('PageSession_LibrarySelectedItemID', _itemID);
    SetSessionProperty('PageSession_LibrarySelectedItemTypeID', _itemType);
    SetSessionProperty('PageSession_LibrarySelectedITemName', _itemName);
    
    var tabStrip = _tabStripClientID;
    var resultsTab = tabStrip.FindTabById('Results');
    tabStrip.SelectTabById('Results');
    
    var currentLocation = window.location.href;
    var currentPage = currentLocation.substring(currentLocation.lastIndexOf('/')+1, currentLocation.length).toLowerCase();
    
    // Update Mapview and TabbedWindow controls
    if (window.MapViewControl1_CallbackTrigger_IfVisible)
    {
      SetSessionProperty('MapViewDisplayMode', _MapViewDisplayModeKGMapView);
      MapViewControl1_CallbackTrigger_IfVisible(_srmIndex);
    }
    
    //if (window.KGTabbedWindowsControl_CallbackTrigger)
    //  KGTabbedWindowsControl_CallbackTrigger('ConceptSelected', _srmIndex);
    
    var args = 'Action=DisplaySearchResult|ItemID='+_itemID+'|'+'ItemType='+_itemType+'|'+'ItemName='+_itemName+'|SrmIndex='+_srmIndex;
    eval(_cbreference);
  }
  catch (e) 
  {
    alert("An exception occurred in the script. Error name: " + e.name + ". Error message: " + e.message); 
    //debugger;
  }
}

function ConceptTabbedView1_CallbackDone_Wrapped(args, context, _tabStripClientID)
{
  //debugger;
  try
  {
    // Check for a session time out before completing the callback
    if (CheckSessionTimeout())
      return;
    
    var s = args.split('='); 
    var ids = s[0].split('@');
    
    var holder = document.getElementById(ids[0]);
    if(holder != null)
    {
      holder.innerHTML = args.substring(args.indexOf('=')+1);
      // need to redeclare the storage and the main function before calling it
      // therefore get the text of it
      // storage first
      var pos1 = args.indexOf('![CDATA[');
      if ( pos1 > - 1)
      {
        var string2 = args.substring(pos1, args.length);
        var pos2 = string2.indexOf('[[');
        var pos3 = string2.indexOf('//]]>');
        if ( pos2 > -1 && pos3 > -1 )
        {
          var storageString = string2.substring(pos2, pos3);
          var evalStorageString = 'window.ComponentArt_Storage_' + ids[1] + '_ResultTree = ' + storageString;
          // eval the string
          eval(evalStorageString);
          // now the init string
          var pos4 = string2.lastIndexOf('![CDATA[');
          if ( pos4 > -1 )
          {
            var string3 = string2.substring(pos4, string2.length);
            var pos5 = string3.indexOf('{');
            var pos6 = string3.lastIndexOf('}');
            if ( pos5 > -1 && pos6 > -1 )
            {
              var initString = string3.substring(pos5, pos6 + 1);
              var evalInitString = 'window.ComponentArt_Init_' + ids[1] + '_ResultTree = function()' + initString;
              // eval the string
              eval(evalInitString);
              // now execute it now that we've redefined it
              eval('ComponentArt_Init_' + ids[1] + '_ResultTree()');
            } // end if pos5 and pos6
          } // end if pos4
        } // end if pos2 and pos3
      } // end if pos1
      // Selecting the Result Page after callback returns
      var tabStrip = _tabStripClientID;
      tabStrip.SelectTabById('Results');
      
      // Highlisht Selected TreeNode
      if(ids[2] != null && ids[3] != null)
      {
        var nodeId = ids[2];
        var treeId = ids[3];
        var aTreeNode = null;
        var aTreeView = null;
        
        if(treeId != null && treeId !='' && treeId != '-1' && eval('window.'+ treeId+'!=null'))
          aTreeNode = eval(treeId + '.FindNodeById(\'' + nodeId + '\')');
          
        if(aTreeNode != null) 
        {
          aTreeView = aTreeNode.ParentTreeView;
          
          if(aTreeView!= null && aTreeView.TreeViewID != null && aTreeView.TreeViewID != '')
            conceptTreeControl_preTreeViewID = aTreeView.TreeViewID;
          
          if(aTreeNode.ID != null && aTreeNode.ID != '')
            conceptTreeControl_preTreeNodeID = aTreeNode.ID;
          
          aTreeView.SelectedNode = aTreeNode;
        } 
        
        // lowlight previous selected path
        //if(conceptTreeControl_preTreeViewID != null && conceptTreeControl_preTreeNodeID != null)
          //ConceptTreeControl_LowlightTreeNode(conceptTreeControl_preTreeViewID, conceptTreeControl_preTreeNodeID);
        
        // Highlight Selected Path
        //if(aTreeView != null)
          //ConceptTreeControl_HighlightTreeNode(treeId, nodeId); 
      } 
    }
    else
    {
      ConceptTabbedView_ProcessCallBackError('Content Cell not found.', '');
    }
    
    var searchResultsTreeLastRootNodeHiddenFieldClientID = SearchResult_GetLastRootNodeHiddenFieldID();
    var searchResultLastRootNodeHiddenField = document.getElementById(searchResultsTreeLastRootNodeHiddenFieldClientID);
    searchResultLastRootNodeHiddenField.value = null;
    
    var tabStrip = _tabStripClientID;
    var tab = tabStrip.GetSelectedTab();
    ConceptTabbedView_ChangeBackButtonMode(ShowBackButton(tab));
    m_treeViewIsLoaded = true;
  }
  catch (e) 
  {
    alert("An exception occurred in the script. Error name: " + e.name + ". Error message: " + e.message); 
    //debugger;
  }
  try
  {
    var srmIndex = ids[4];
    SrmControl_RecordTimes(srmIndex);
  }
  catch(e){}
};

// Check box javascripts
function ConceptTabbedView_SubscriptionModeChanged_Wrapped(_cb, _cbreference)
{
  //debugger;
  try
  {
		var optiondiv = document.getElementById('KGOptionControlID1');
    var loginview = "Library_LoginView_";
    try
    {
      loginview = "Library_LoginView_";
      var check = document.getElementById(loginview + "KGOptionControl_ImageNumber0").src = "Images/newGeneOption.png";
    }
    catch(Exception)
    {
      loginview = "";
    }
    
    if(_cb == false)
    {
      SetSessionProperty('ConceptTabbedView_AllowSubscripton', true);
      var args = 'Action=SubscriptionModeChanged|Value=' + true;
      eval(_cbreference);
      document.getElementById(loginview + "KGOptionControl_ImageNumber4").src = "Images/LeftSubsOn.png";        
      document.getElementById(loginview + "KGOptionControl_CellNumber4").onclick = function(){ConceptTabbedView_SubscriptionModeChanged(true)};     
      document.getElementById(loginview + "KGOptionControl_CellNumber4").onmouseover = function(){this.style.cursor='pointer'};
    }
    else
    {
      SetSessionProperty('ConceptTabbedView_AllowSubscripton', false);
      var args = 'Action=SubscriptionModeChanged|Value=' + false;
      eval(_cbreference);
      document.getElementById(loginview + "KGOptionControl_ImageNumber4").src = "Images/LeftSubsOff.png";        
      document.getElementById(loginview + "KGOptionControl_CellNumber4").onclick = function(){ConceptTabbedView_SubscriptionModeChanged(false)};     
      document.getElementById(loginview + "KGOptionControl_CellNumber4").onmouseover = function(){this.style.cursor='pointer'};
    }
  }
  catch (e) 
  {
    alert("An exception occurred in the script. Error name: " + e.name + ". Error message: " + e.message); 
    //debugger;
  }
} //end function

function ConceptTabbedView_AlertSettingModeChanged_Wrapped(_cb, _cbreference, _srmIndex) 
{
  //debugger;
  try
  {
    if (m_srmGetTimes!= null && m_srmGetTimes == "True" && _srmIndex != null)
      m_srmAction[_srmIndex] += ',' + !_cb;
  }
  catch(e){}

  try
  {
    var optiondiv = document.getElementById('KGOptionControlID1');
    var loginview = "Library_LoginView_";
    
    try
    {
      loginview = "Library_LoginView_";
      var check = document.getElementById(loginview + "KGOptionControl_ImageNumber0").src = "Images/newGeneOption.png";
    }
    catch(Exception)
    {
      loginview = "";
    }

    if(_cb == false)
    {
      SetSessionProperty('ConceptTabbedView_AllowChangeAlertSetting', true);
      var args = 'Action=AlertSettingModeChanged|Value=' + true + '|SrmIndex=' + _srmIndex;
      eval(_cbreference);
      document.getElementById(loginview + "KGOptionControl_ImageNumber3").src = "Images/LeftAlertsOfn.png";        
      document.getElementById(loginview + "KGOptionControl_CellNumber3").onclick = function(){ConceptTabbedView_AlertSettingModeChanged(true)};     
      document.getElementById(loginview + "KGOptionControl_CellNumber3").onmouseover = function(){this.style.cursor='pointer'};
    }
    else
    {
      SetSessionProperty('ConceptTabbedView_AllowChangeAlertSetting', false);
      var args = 'Action=AlertSettingModeChanged|Value=' + false + '|SrmIndex=' + _srmIndex;
      eval(_cbreference);
      document.getElementById(loginview + "KGOptionControl_ImageNumber3").src = "Images/LeftAlertsOff.png";        
      document.getElementById(loginview + "KGOptionControl_CellNumber3").onclick = function(){ConceptTabbedView_AlertSettingModeChanged(false)};     
      document.getElementById(loginview + "KGOptionControl_CellNumber3").onmouseover = function(){this.style.cursor='pointer'};
    }
  }
  catch (e) 
  {
    alert("An exception occurred in the script. Error name: " + e.name + ". Error message: " + e.message); 
    //debugger;
  }
} //end function

function ConceptTabbedView1_RefocusTreeView_wrapped(_itemID,
                                                    _itemName,
                                                    _tabStripClientID,
                                                    _titleLabelClientID,
                                                    _tabContextSeparator,
                                                    _MapViewDisplayModeKGMapView,
                                                    _cbreference,
                                                    _isBackButtonPress,
                                                    _srmIndex)
{
  //debugger;
  try
  {
    if (window.CancelEdit)
      CancelEdit(true);
    
    var tabStrip = eval(_tabStripClientID);
    var currentTabID = (tabStrip.GetSelectedTab()).ID;
    if (currentTabID != null)
    {
      if(currentTabID == 'Library')
        SetSessionProperty('GlobalLibrary_NewRootConceptID', _itemID);
      else if(currentTabID == 'Personal')
        SetSessionProperty('PersonalLibrary_NewRootConceptID', _itemID);
      else if(currentTabID == 'Results')
        SetSessionProperty('SearchResult_NewRootConceptID', _itemID);
      else if(currentTabID.substr(0,3) == 'CS_')
        SetSessionProperty('Topic_NewRootConceptID', _itemID);             
      
      var currentLocation = window.location.href;
      var currentPage = currentLocation.substring(currentLocation.lastIndexOf('/')+1, currentLocation.length).toLowerCase();
      var hostURL = currentLocation.substring(0, currentLocation.lastIndexOf('/') + 1);
      
      // refocus tree
      if (_isBackButtonPress == true)
        var args = 'Action=Refocus|CurrentTabID='+currentTabID+'|BackButtonPress=true';
      else
        var args = 'Action=Refocus|NewRootConceptID='+_itemID+'|CurrentTabID='+currentTabID+'|SrmIndex='+_srmIndex;
      eval(_cbreference);
      
      try
      {
        if (m_srmGetTimes!= null && m_srmGetTimes == "True" && _srmIndex != null)
        {
          m_srmAction[_srmIndex] += ',' + currentPage + ',' + currentTabID;
          m_srmCallbacks[_srmIndex] = 2;
        }
      }
      catch(e){}
      
      if(!(_isBackButtonPress == true && (_itemID == 0 || _itemID == -1)))
      {
        if (window.MapViewControl1_CallbackTrigger_IfVisible)
        {
          SetSessionProperty('MapViewDisplayMode', _MapViewDisplayModeKGMapView);
          MapViewControl1_CallbackTrigger_IfVisible(_srmIndex);
        }
       // if (window.KGTabbedWindowsControl_CallbackTrigger)
        //  KGTabbedWindowsControl_CallbackTrigger('ConceptSelected', _srmIndex);
      }
    }
  }
  catch (e) 
  {
    alert("An exception occurred in the script. Error name: " + e.name + ". Error message: " + e.message); 
    //debugger;
  }
}

function ConceptTabbedView_ControlReload(args, context)
{
  //debugger;
  try
  {
    if(args.indexOf('SelectedTabId') > 0)
    {
      var params = args.split('|');
      var tabStrip = eval(params[0].substring(params[0].indexOf('=') + 1, params[0].length));
      var selectedTabID = params[1].substring(params[1].indexOf('=') + 1, params[1].length);
      
      if((selectedTabID != null) && (tabStrip != null))
      {
        var selectedTab = tabStrip.FindTabById(selectedTabID);
        if(selectedTab != null)
        {
          tabStrip.SelectTabById(selectedTabID);
          ConceptTabbedView_TabSelected(null, null, selectedTab);
        }
      }
    }
    else
    {
      var s = args.split('=');
	    var ids = s[1].split(' ');
	    var holder = document.getElementById(ids[0].replace(/"/g,''));
    	
	    if(holder != null)
	    {
		    holder.parentNode.innerHTML = args;
		    var jscripts = args.split('<script');
		    var targets = new Array();
		    var x;
    		
		    for(x in jscripts)
		    {
			    if(jscripts[x].indexOf('//<![CDATA[') > 0)
			    {
				    targets.push(jscripts[x].substring(jscripts[x].indexOf('//<![CDATA['), jscripts[x].indexOf('//]]>') + 5));
			    }
		    }
    		
		    for(x in targets)
		    {
			    var posWindow = targets[x].indexOf('window');
			    var posFunction = targets[x].indexOf('function');
			    var evalString;
    			
			    if((posWindow < posFunction) || (posFunction == -1))
			    {
				    evalString = targets[x].substring(targets[x].indexOf('window'), targets[x].indexOf('//]]>'));
			    }
			    else if((posWindow > posFunction) && (posFunction != -1))
		      {
            evalStrng = targets[x].substring(targets[x].indexOf('function'), targets[x].indexOf('//]]>'));
		      }
    			
			    eval(evalString);
		    }
	    }
	    else
	    {
	      ConceptTabbedView_ProcessCallBackError('Content Cell not found.', '');
	    }
	  }
	}
  catch (e) 
  {
    alert("An exception occurred in the script. Error name: " + e.name + ". Error message: " + e.message); 
    //debugger;
  }
}

// show (true) or hide (false) the back button, depending on _boolShow (can get _boolShow from ShowBackButton below)
function ConceptTabbedView_ChangeBackButtonMode_Wrapped(_boolShow, _backButtonCellClientID)
{
  //debugger;
  try
  {
    var backButtonCell = document.getElementById(_backButtonCellClientID);
    if (backButtonCell != null)
    {
      if (_boolShow)
        backButtonCell.className = "TabBackButton";
      else
        backButtonCell.className = "TabBackButtonHidden";
    }
  }
  catch (e) 
  {
    alert("An exception occurred in the script. Error name: " + e.name + ". Error message: " + e.message); 
    //debugger;
  }
}

function ConceptTabbedView_onBackButtonClickHandler_Wrapped(_tabStrip)
{
  //debugger;
  try
  {
    var tab = _tabStrip.GetSelectedTab();
    if (tab.ID.substr(0,3) == 'CS_')
    {
      var lastRootNodeHiddenFieldID = Topic_GetLastRootNodeHiddenFieldID();
      var lastRootNodeHiddenField = document.getElementById(lastRootNodeHiddenFieldID);
      if (lastRootNodeHiddenField!=null && lastRootNodeHiddenField.value != null && lastRootNodeHiddenField.value != 'null' && lastRootNodeHiddenField.value.length > 0)
        ConceptTabbedView1_RefocusTreeView(lastRootNodeHiddenField.value, null, null, true);
      else
        KGTopicsControl_upToTopLevel(tab.ID, _tabStrip);
    }
    else if (tab.ID == 'Results')
    {
      var lastRootNodeHiddenFieldID = SearchResult_GetLastRootNodeHiddenFieldID();
      var lastRootNodeHiddenField = document.getElementById(lastRootNodeHiddenFieldID);
      
      SearchResult_ResetTreeScrollingVariables();
      
      // refocus tree view _backbuttonpress = true
      if (lastRootNodeHiddenField.value != null && lastRootNodeHiddenField.value != 'null' && lastRootNodeHiddenField.value.length > 0)
      {
        if(global_SearchResult_ClickedItemID == lastRootNodeHiddenField.value)
          SetSessionProperty('HideSearchResultItemInfo', 'false'); // reach the original display tree
        ConceptTabbedView1_RefocusTreeView(lastRootNodeHiddenField.value, null, null, true);
      }
    }
    else if (tab.ID == 'Personal')
    {
      var lastRootNodeHiddenFieldID = PersonalLibrary_GetLastRootNodeHiddenFieldID();
      var lastRootNodeHiddenField = document.getElementById(lastRootNodeHiddenFieldID);
      
      // refocus tree view _backbuttonpress = true
      if (lastRootNodeHiddenField.value != null && lastRootNodeHiddenField.value != 'null' && lastRootNodeHiddenField.value.length > 0)
        ConceptTabbedView1_RefocusTreeView(lastRootNodeHiddenField.value, null, null, true);
    }
  }
  catch (e) 
  {
    alert("An exception occurred in the script. Error name: " + e.name + ". Error message: " + e.message); 
    //debugger;
  }
}

// return true if the back button should be shown, false otherwise
function ShowBackButton(_tab)
{
  //debugger;
  try
  {
    if (_tab != null)
    {
      if (_tab.ID.substr(0,3) == 'CS_')
      {
        if (KGTopicsControl_isTopicSelected())
          return true;
      }
      else if (_tab.ID == 'Results')
      {
        var lastRootNodeHiddenFieldClientID = SearchResult_GetLastRootNodeHiddenFieldID();
        var lastRootNodeHiddenField = document.getElementById(lastRootNodeHiddenFieldClientID);
        
        if(lastRootNodeHiddenField.value == null || 
          lastRootNodeHiddenField.value == "null" ||
          lastRootNodeHiddenField.value == "")
          return false;
        else
          return true;
      }
      else if (_tab.ID == 'Personal')
      {
        var lastRootNodeHiddenFieldClientID = PersonalLibrary_GetLastRootNodeHiddenFieldID();
        var lastRootNodeHiddenField = document.getElementById(lastRootNodeHiddenFieldClientID);
        
        if (lastRootNodeHiddenField.value == null || 
            lastRootNodeHiddenField.value == "null" ||
            lastRootNodeHiddenField.value == "")
          return false;
        else
          return true;
      }
    }
    return false;
  }
  catch (e) 
  {
    alert("An exception occurred in the script. Error name: " + e.name + ". Error message: " + e.message); 
    //debugger;
  }
}

