﻿// KGHelpControl JScript File
var objectiveImgs=new Array(); 
objectiveImgs[0]='images/help/objectiveexample.png'; 
var m_helpCookieExpiration = 8760; 

var currentObjectiveImg = 0;
var m_HelpFrame = null;
var m_DockedHelpFrame = null;
var helpText;

var globalShowingWebDoc = false;
// if true then the docked control is full expanded to cover the whole bottom panel
var m_globalFullDocked = false;

var m_previousHighLightedPath = '';

//var m_bHelpFrameLoadSiblingKnowde = false;
//var m_bHelpFrameManualScroll = false;

//var m_helpFrameScrollTimeOut = null;


//var m_helpFrameHighlightColor = '#EAF4F7'; 
//var m_helpFrameHighlightBorderLeftStyle = '2px #A7A9E2 solid'; //8EA4DB A7A9E2
//var m_helpFrameHighlightBorderLeftPadding = '5';

var m_newTextViewWindow;
//var m_helpFrameScrollDelay = 50; // ms
//var m_helpFrameScrollMoreOnTopTimeOut;
//var m_dockedFrameScrollMoreOnTopTimeOut;

//var m_helpFrameLoadingDivTimeOut;

//var m_helpFrameCallbackStatus = 'none';


function KGHelpControl_CallbackTrigger_Wrapped(_key, _params, _callbackScript, _imgDockInPageID)
{
  //debugger;
  // Make sure we clear the contents of the document window
  /*if(_key != 'NewWindowTextView' && m_bHelpFrameLoadSiblingKnowde == false)
    ClearHelpFrame(false);
    
  globalShowingWebDoc = false;
  // show textview view mode option if in read mode
  // need to use set time out otherwise iframe height become 0 in Safari and Chrome
  if(m_bEditable == true)
    window.setTimeout('HideOrShowTextViewOptionDiv(false)',5);
  else
    window.setTimeout('HideOrShowTextViewOptionDiv(true)', 5);
    
  var MapHelpBox = document.getElementById("KGHelpControlID1");
  MapHelpBox.title = "Associated Text";
  
  var imgDockInPage = document.getElementById(_imgDockInPageID);
  if (imgDockInPage.style.display == "none")
    imgDockInPage.style.display = "";
  
  var args;
  //debugger;
  // Construct the callback arguments
  if(_key != null)
  { 
    args = 'key=' + _key + "|params=" + _params;
    
    if(args.length > 0)
    {
      m_helpFrameCallbackStatus = 'trigger';
      if(_key.indexOf('ReloadTextView') == -1)
      {
        // show loading div
        if(args.indexOf('LoadTrigger=Scrolling') == -1)//(m_bHelpFrameLoadSiblingKnowde == false)
        {
          if(m_helpFrameLoadingDivTimeOut != null)
          {
            clearTimeout(m_helpFrameLoadingDivTimeOut);
            m_helpFrameLoadingDivTimeOut = null;
          }
          m_helpFrameLoadingDivTimeOut = window.setTimeout("HideOrShowHelpControlLoadingDiv(true, 'Loading...')",10);
        }
      }
      // trigger the callback
      eval(_callbackScript);    
    }
  }*/
}
				  
function KGHelpControl_CallbackDone(_args, _context)
{
  // Check for a session time out before completing the callback
  if (CheckSessionTimeout())
    return;
  
  /*m_helpFrameCallbackStatus = 'done';
  
  m_HelpFrame = document.getElementById("HelpFrame");
  
  var action = '';
  if(_args.indexOf('[@|@]') != -1)
  {
    action = _args.substring(0, _args.indexOf('[@|@]'));
    _args = _args.substring(_args.indexOf('[@|@]') + 5);
  }
  
  if(action.indexOf('-ReloadTextView') != -1)
  {
    // edit mode textview
    var ids = _args.split('@');
    var controlId = ids[0];
    var content = _args.substring(controlId.length+1);
    var hccontainer = document.getElementById('KGHelpControlID1');
    var tvControl = document.getElementById('TextViewControlContent');
    if(tvControl != null && hccontainer != null)
    {
      //debugger;
      if (tvControl.childNodes.length == 2) //IE
      {
        tvControl.childNodes[0].style.height = '30px';
        tvControl.childNodes[1].outerHTML = content;
        
        tvControl.childNodes[1].style.height = (hccontainer.clientHeight - 75) + 'px';
        tvControl.childNodes[1].style.width = (hccontainer.clientWidth - 5) + 'px';
              
        m_textViewControlSpanFixedSize = 1;

      }
      else if (tvControl.childNodes.length == 4) //FF - counts carriage returns in html as textnodes
      {
        tvControl.childNodes[0].style.height = '30px';
        var container = document.getElementById('TextViewControlContent');

        //tvControl.childNodes[2].outerHTML = content;
        // not support outerHtml
        var tempElement = document.createElement("div");
        tempElement.style.overflow = 'auto';
        
        var start = content.indexOf('<');
        if(start > 0)
          content = content.substring(start);
        var end = content.lastIndexOf('>');
        if(end < content.length -1)
          content = content.substring(0, end + 1);
          
        tempElement.innerHTML = content;
        
        var root = null;
        for(var i=0; i<tempElement.childNodes.length; i++) 
        {
          if(tempElement.childNodes[i].nodeType == 1) 
          {
            root = tempElement.childNodes[i];
            root.style.display = 'block';
            
            if(container != null)
            {
              root.style.height = (hccontainer.clientHeight - 75) + 'px';
              root.style.width = (hccontainer.clientWidth - 5) + 'px';
              
              m_textViewControlSpanFixedSize = 1;
            }
            break;
          }
        }
        
        if(root)
          tvControl.replaceChild(root, tvControl.childNodes[2]);
                  
      }
      setTimeout("LoadTextView()",300);
      
    }
      HideOrShowHelpControlLoadingDiv(false);

      m_helpFrameCallbackStatus = 'none';
  }
  else
  { // read only text view
    if(_args.indexOf('|<TextViewInfo>|') != -1)
    {
      var values = _args.split('|<TextViewInfo>|');
      // set selected knowde id
      var ids = values[0].split('@');
      // get action key
      var actionKey = ids[0];
      var viewmode = ids[1];
      if(actionKey != 'NewWindowTextView')
      {
        // get old kgId
        var oldFrameKGID = m_strFrameSelectedKGID;
        // set view mode
        m_strFrameViewMode = viewmode;
        // set kgId
        m_strFrameSelectedKGID = ids[2];
        // knowdeID
        m_strFrameSelectedKnowdeDBID = ids[3];
        // use client Id for the moment
        m_strFrameSelectedKnowdeID = ids[4];
        var knowdeContexts = values[0].substring(ids[0].length + ids[1].length + ids[2].length + ids[3].length + ids[4].length + 5).split('||');
        m_strFrameSelectedKnowdeContext = knowdeContexts[0];
        m_strFrameCentreKnowdeContext = knowdeContexts[1];
        
        //alert(m_strFrameSelectedKnowdeID + '|' + m_strFrameSelectedKnowdeContext);
        
        if(oldFrameKGID != m_strFrameSelectedKGID || m_bHelpFrameLoadSiblingKnowde == false)
        {
          // kg changed
          ClearHelpFrame(false);
        }
        
        if(m_strFrameViewMode == "Full" && m_currentTextViewViewMode == m_strFrameViewMode)
        {
          // load all textviews
          HandleHelpFrameLoadAll(values[1], values[2]);
        }
        else if(m_strFrameViewMode == "Single" && m_currentTextViewViewMode == m_strFrameViewMode) 
        {
          // load single textview
          var content = values[2];
          var kndText = GetCurrentKnowdeTextForTextView(m_strFrameSelectedKnowdeID);
          if(kndText != '')
          {
            if(content == '')
            {
              content = GetDefaultTextViewContentWithTitle(m_strFrameSelectedKnowdeID, kndText, 1, m_noTextViewFoundContent);
            }else
            {
              content = TrimTickerSpans(content);
              if (content.indexOf(m_textViewTickerSelectionHighlightColor) > -1)
                content = ReturnUnhighlightedTickerText(content);
                
              // check whether it has an existing title, if not, add the title manually
              if(CheckTextViewHasTitle(m_strFrameSelectedKnowdeID, kndText, content) == false)
                content = WrapTextViewContentWithTitle(m_strFrameSelectedKnowdeID, kndText, content);
            }
         }

          m_HelpFrame.contentWindow.document.write("<html><head><base target='_blank'><link href='CSS/KGHelpControl.css' type='text/css' rel='stylesheet'/><link href='CSS/TextViewDocument.css' type='text/css' rel='stylesheet'/></head><body class='PersonalisedScrollBar' style='overflow:scroll;'>");
          m_HelpFrame.contentWindow.document.write(content);
          m_HelpFrame.contentWindow.document.write("</body></html>");
           
          // Copy the text view to the docked window if it exists
          var dockedText = document.getElementById("DockedHelpWindow");
          
          if (dockedText != null)
          {
            dockedText.contentWindow.document.open();
            dockedText.contentWindow.document.write("");
            dockedText.contentWindow.document.close();

            dockedText.contentWindow.document.write("<html><head><base target='_blank'><link href='CSS/KGHelpControl.css' type='text/css' rel='stylesheet'/><link href='CSS/TextViewDocument.css' type='text/css' rel='stylesheet'/></head><body class='PersonalisedScrollBar' style='overflow:scroll;'>");
            dockedText.contentWindow.document.write(content);
            dockedText.contentWindow.document.write("</body></html>");
          }

          // Store the 'actual' text incase the user wishes to dock the help
          helpText = content;
        }
      }
      else if(m_newTextViewWindow != null)
      {
        // get highlighted knowde context
        var knowdeContexts = values[0].substring(ids[0].length + ids[1].length + ids[2].length + ids[3].length + ids[4].length + 5).split('||');
        var strFrameSelectedKnowdeContext = knowdeContexts[0];

        // new window full load
        HandleNewWindowTextViewLoadAll(values[1], values[2], strFrameSelectedKnowdeContext);
        
      }
      
   }
   else
   { 
      // Make sure we clear the contents of the document window
      ClearHelpFrame();

      m_HelpFrame.contentWindow.document.write("<html><head><base target='_blank'><link href='CSS/KGHelpControl.css' type='text/css' rel='stylesheet'/><link href='CSS/TextViewDocument.css' type='text/css' rel='stylesheet'/></head><body class='PersonalisedScrollBar' style='overflow:scroll;'>");
      m_HelpFrame.contentWindow.document.write(_args);
      //if (window.ReturnUnhighlightedTickerText && _args.indexOf(m_textViewTickerSelectionHighlightColor) > -1)
        //_args = ReturnUnhighlightedTickerText(_args);
      //m_HelpFrame.contentWindow.document.body.innerHTML = _args;  // Removed this because it was causing the lines of text to disappear in the text view - bug 4277
      m_HelpFrame.contentWindow.document.write("</body></html>");
       
      // Copy the text view to the docked window if it exists
      var dockedText = document.getElementById("DockedHelpWindow");
      
      if (dockedText != null)
      {
        dockedText.contentWindow.document.open();
        dockedText.contentWindow.document.write("");
        dockedText.contentWindow.document.close();

        dockedText.contentWindow.document.write("<html><head><base target='_blank'><link href='CSS/KGHelpControl.css' type='text/css' rel='stylesheet'/><link href='CSS/TextViewDocument.css' type='text/css' rel='stylesheet'/></head><body class='PersonalisedScrollBar' style='overflow:scroll;'>");
        dockedText.contentWindow.document.write(_args);
        dockedText.contentWindow.document.write("</body></html>");
      }

      // Store the 'actual' text incase the user wishes to dock the help
      helpText = _args;
    }
    
    // hide loading div
    //if(m_helpFrameLoadingDivTimeOut != null)
    //{
      //clearTimeout(m_helpFrameLoadingDivTimeOut);
     // m_helpFrameLoadingDivTimeOut = null;
    //}
    //m_helpFrameLoadingDivTimeOut = window.setTimeout("HideOrShowHelpControlLoadingDiv(false)",20);
    HideOrShowHelpControlLoadingDiv(false);

    m_helpFrameCallbackStatus = 'none';
  }*/
    
}

function IsHelpControlOpen()
{
  m_MapHelpBox = document.getElementById("KGHelpControlID1");
  if (m_MapHelpBox != null)
  {
    if(m_MapHelpBox.className != "OverlayPositionHidden")
      return true;
  }
  return false;
}
  			
function KGHelpControl_CallbackError(_args, _context)
{
  m_helpFrameCallbackStatus = 'none';
  
  alert(_args);
}

function ToggleImage(e)
{
  var pic = document.getElementById('HelpExample');
  e = e || window.event;
  var targ = e.target || e.srcElement;
  switch (targ.id)
  {
    case 'ObjectiveHelp':
      // We'd want to get the list of images here, but for now they're hard coded at the beginning of the file
      
      // Cycle through the available images
      if (currentObjectiveImg < objectiveImgs.length - 1)
        currentObjectiveImg++;
      else
        currentObjectiveImg = 0;
      pic.src = objectiveImgs[currentObjectiveImg];
      break;
  }
}

function SetHelpStateCookie()
{
  // If the element is on the help page, we need to remember that it has been closed
  var path = window.location.pathname;
  var page = path.substring(path.lastIndexOf('/') + 1);
  if ((page == 'MapTabbedView.aspx' || page == 'Home.aspx' || page == '') && KGMapHelpStateSetting != null)
  {
    WM_setCookie('KGMapHelpState',KGMapHelpStateSetting, m_cookieExpiration); // reset expiry date
  }
}

var helpBoxWidth;
var helpBoxHeight;
var helpBoxTop;
var helpBoxLeft;

function MaximiseKGHelpControl(_helpBoxID, _maximiseBtnId)
{
//debugger;
// get the help box
  var helpBox = document.getElementById(_helpBoxID);
  
  // store the help box'x current width, height and positioning for a 'restore'
  helpBoxWidth = helpBox.style.width;
  helpBoxHeight = helpBox.style.height;
  helpBoxTop = helpBox.style.top;
  helpBoxLeft = helpBox.style.left;
  
  // Set the help windows new properties
  helpBox.style.width = document.body.clientWidth;
  helpBox.style.height = document.body.clientHeight;
  helpBox.style.top = "0";
  helpBox.style.left = "0";
  
  // change image and onclick handler
  document.getElementById(_maximiseBtnId).className = "RestoreButtonImage";
  document.getElementById(_maximiseBtnId).onclick = function(){RestoreKGHelpControl('KGHelpControlID1', _maximiseBtnId)}; 
  
  if(!globalShowingWebDoc && document.frames)
  { 
    // don't have permission to do this for web docs (iframe refers to another domain)
    // added for text view (TS bug 4787)
    //setTimeout('document.frames[\'HelpFrame\'].location.reload(true)', 1000); 
  }
  
  HelpFrameDivResize('HelpFrame'); // might need to load more textview because the width is now bigger
}

function RestoreKGHelpControl(_helpBoxID, _restoreBtnId)
{
//debugger;
  var helpBox = document.getElementById(_helpBoxID);
  
  // reset the old size and positioning
  helpBox.style.top = helpBoxTop;
  helpBox.style.left = helpBoxLeft;
  helpBox.style.width = helpBoxWidth;
  helpBox.style.height = helpBoxHeight;
  
  // reload iFrame: - this fixes the annoying 'line of text missing' bug
  // this will break the aggregate text view and partial loading
  //if(helpBox.title == "Associated Text")
    //document.frames['HelpFrame'].location.reload(true);
  
  // change image and onclick handler
  document.getElementById(_restoreBtnId).className = "MaximiseButtonImage";
  document.getElementById(_restoreBtnId).onclick = function(){MaximiseKGHelpControl('KGHelpControlID1', _restoreBtnId)}; 
  
  HelpFrameDivResize('HelpFrame');
  // make sure scroll to the right position - if it's the text view not a web doc
  if (!globalShowingWebDoc)
    window.setTimeout('SetupHelpFrameKnowdeTextViewDivs()',1000);
    
  if(!globalShowingWebDoc && document.frames)
  { 
    // don't have permission to do this for web docs (iframe refers to another domain)
    // added for text view (TS bug 4787)
    //setTimeout('document.frames[\'HelpFrame\'].location.reload(true)', 1000); 
  }
}


function OpenInNewWindowKGHelpControl()
{
  //debugger;
  var control = document.getElementById("HelpFrame");
  if (control.src != null && control.src != "")
    var helpWindow = window.open(control.src);
  else if(m_strFrameViewMode == "Full")
  {
    var helpWindow = window.open();
    m_newTextViewWindow = helpWindow;
    helpWindow.opener = window;
    helpWindow.document.write("<html><head><script language='javascript' type='text/javascript' src='JavaScript/Yahoo.js'></script><script language='javascript' type='text/javascript' src='JavaScript/KGHelpControl.js'></script><script language='javascript' type='text/javascript' src='JavaScript/TextView.js'></script><link href='CSS/KGHelpControl.css' type='text/css' rel='stylesheet' /></head>");
    helpWindow.document.write("<body style='overflow:hidden;'><IFRAME id='NewWindowHelpFrame' frameBorder='0' width='100%' height='100%' onload='parent.NewWindowTextViewOnLoad(\"" + m_strFrameSelectedKGID + "\", \"" + m_strFrameSelectedKnowdeID + "\", \"" + m_strFrameSelectedKnowdeContext + "\")'></IFRAME>");
    helpWindow.document.write("<input type='hidden' id='NewWindowTextViewHiddenField' value='" + m_FrameUnLoadedKnowdeIdString + "' /><DIV id='NewWindowTextViewDiv' style='display:none'>" + control.contentWindow.document.body.innerHTML + "</DIV><div id='NewWindowTextViewLoadingDiv' style='width: 100%; top:0px; left:0px; position:absolute; display:block;'><table width=\"100%\"><tr><td align=\"center\"><br/><br/><br/><div class='NewTextViewWindowLoadingDiv'><br/><img src=\"Images/loadingbar.gif\" /> Loading, please wait ...</div></td></tr></table></div>");
    helpWindow.document.write("<KGCoreControls:KGHelpControl ID='KGHelpControl1' runat='server' Title = 'Hyperknowledge' DivPosType = 'absolute' ControlName='KGHelpControl' /> </body></html>");
    
  }else if(m_strFrameViewMode == "Single")
  {
    var helpWindow = window.open();
    m_newTextViewWindow = helpWindow;
    helpWindow.opener = window;
    helpWindow.document.write(control.contentWindow.document.body.innerHTML);
  }
}

function NewWindowTextViewOnLoad(_kgID, _knowdeID, _knowdeContext)
{
  //debugger;
  var frame = document.getElementById('NewWindowHelpFrame');
  var hiddenDiv = document.getElementById('NewWindowTextViewDiv');
  var hiddenField = document.getElementById('NewWindowTextViewHiddenField');
  var loadingDiv = document.getElementById('NewWindowTextViewLoadingDiv');
    
  var toloadDivs = '';
  var loadedDivs = '';
  if(frame != null && hiddenField != null && hiddenDiv != null)
  {
    toloadDivs = hiddenField.value;
    loadedDivs = hiddenDiv.innerHTML;
    
    frame.contentWindow.document.write("<html><head></head><body style='overflow: auto;'>" + loadedDivs + "</body></html>");

    if(toloadDivs != '' && window.opener != null)
    {
      // do callback to load all the unloaded text views
      var args = "|KGId=" + _kgID + '|KnowdeId=' + _knowdeID + '|KnowdePathContext=' + _knowdeContext + '|KnowdeTitle=|CentreKnowdePathContext=|KnowdeIdList=' + toloadDivs;
      args += "|LoadSiblingKnowde=true";
      args += "|KnowdeLoaded=false";
      args += "|ViewMode=Full";
      
      window.opener.KGHelpControl_CallbackTrigger('NewWindowTextView', args);
      
      if(loadingDiv != null)
        loadingDiv.style.display = 'block';
    }
    else
    {
      if(loadingDiv != null)
        loadingDiv.style.display = 'none';
      window.setTimeout('SetupNewWindowTextViewDivs("'+_knowdeContext+'")', 200);

    }
  }else
  {
    // delay 
    window.setTimeout('NewWindowTextViewOnLoad("' + _kgID + '", "' + _knowdeID + '", "' + _knowdeContext + '")', 1000);
  }
  
}

function SetupNewWindowTextViewDivs(_knowdeContext)
{
//debugger;
  var frame = document.getElementById('NewWindowHelpFrame');
  // scroll to the right place
      if(_knowdeContext != null && _knowdeContext != '')
      {
            var method = function(el){if(el.id == _knowdeContext) return true; return false;};
            //var frameDivs = YAHOO.util.Dom.getElementsBy(method,null,frame.contentWindow.document.body);  
            var frameDivs = YAHOO.util.Dom.getChildrenBy(frame.contentWindow.document.body,method);   
            if(frameDivs.length > 0)
            {
              frame.contentWindow.document.body.scrollTop  = frameDivs[0].offsetTop - 10;
            }
      }
}


function DockInPageKGHelpControl(_helpBoxID, _newTabBtn, _dockBtn, _maxBtn, _resizeDiv)
{
  /*if(globalSplitterSetting == "single" || globalHideIndexedDocs == true)
  {
     m_globalFullDocked = true;
  }

  if(document.getElementById("GreyDiv") != null)
  {
    purge(document.getElementById("GreyDiv"));
	document.getElementById("Form1").removeChild(document.getElementById("GreyDiv"));
  }
  document.getElementById("m_cookieDiv").className = "m_cookieDivHidden";
  document.getElementById("miniGlobe").className = "miniGlobe";
  var tabbedControlDiv = document.getElementById("KGTabbedWindowsControl1");
  tabbedControlDiv.style.width = "1300px";
  if(m_globalFullDocked  == true)
  {
    hkLastChild(tabbedControlDiv).style.width = "0px";
    hkLastChild(tabbedControlDiv).style.height = "0px";
    if (window.ActiveXObject)
    {
      // can't set to invisable, the images in the grid still showing and will then overlay with the docked div
    }
    else
      hkLastChild(tabbedControlDiv).style.display = "none";
  }
  else
    hkLastChild(tabbedControlDiv).style.width = "800px";
  
  if(m_globalFullDocked  == true)
  {
    document.getElementById("SplitterArrowDown").parentNode.parentNode.style.overflow = "hidden";
  }
  else
  {
    // set the new css properties
    hkLastChild(document.getElementById("SplitterArrowDown").parentNode).style.height = "100%";
    hkLastChild(document.getElementById("SplitterArrowDown").parentNode).style.width = "100%";
    hkFirstChild(hkLastChild(document.getElementById("SplitterArrowDown").parentNode)).style.height = "97%";
  }

  document.getElementById("KGTabbedWindowsControl1_IndexedDocDiv").style.overflow = "visible";

  // get the docked control
  var controlToInsert = document.getElementById("DockedHelpWindow"); 
  var controlToInsert2 = document.getElementById("DockedHelpWindowOptions");
  var controlToInsert3 = document.getElementById("DockedHelpWindowContainer");
  var controlToInsert4 = document.getElementById("DockedHelpWindowTVOptions");
  var loadingDiv = document.getElementById("DockedHelpWindowLoadingDiv");

  // check if it exists (currently docked on the page)
  if(controlToInsert == null)
  {
    // this element is a 'container' for the tool bar (undock, close) and the iframe containing the text
    controlToInsert3 = document.createElement("div");
    controlToInsert3.setAttribute("id","DockedHelpWindowContainer");
    controlToInsert3.setAttribute("style","float:left");
    controlToInsert3 = InsertAdjacentElement(document.getElementById("KGTabbedWindowsControl1"),"afterBegin", controlToInsert3);

    if(m_globalFullDocked == true)
    {
    if(tabbedControlDiv.clientWidth > 0)
      controlToInsert3.style.width = tabbedControlDiv.clientWidth - 50 + 'px';
    if(document.getElementById("SplitterArrowDown").parentNode.parentNode.style.pixelHeight && document.getElementById("SplitterArrowDown").parentNode.parentNode.style.pixelHeight != '')
      controlToInsert3.style.height = document.getElementById("SplitterArrowDown").parentNode.parentNode.style.pixelHeight; //lastChild.firstChild
    else if(document.getElementById("SplitterArrowDown").parentNode.parentNode.offsetHeight && document.getElementById("SplitterArrowDown").parentNode.parentNode.offsetHeight != '')
      controlToInsert3.style.height = document.getElementById("SplitterArrowDown").parentNode.parentNode.offsetHeight;
    else
      controlToInsert3.style.height = "100%";
    }
    else
    {
      //debugger;
      if(globalHideIndexedDocs == true)
      {      
        controlToInsert3.style.width = screen.width;
        
        globalSplitterSetting = "split";
        SplitterControl('up');
      }
      else
        controlToInsert3.style.width = "400px";
      if(window.ActiveXObject && (document.getElementById("SplitterArrowDown").parentNode.parentNode.style.pixelHeight && document.getElementById("SplitterArrowDown").parentNode.parentNode.style.pixelHeight != ''))
        controlToInsert3.style.height = document.getElementById("SplitterArrowDown").parentNode.parentNode.style.pixelHeight; 
      else if(document.getElementById("SplitterArrowDown").parentNode.parentNode.offsetHeight && document.getElementById("SplitterArrowDown").parentNode.parentNode.offsetHeight != '')
        controlToInsert3.style.height = document.getElementById("SplitterArrowDown").parentNode.parentNode.offsetHeight;
      else
        controlToInsert3.style.height = "100%";   
    }
    controlToInsert3.style.styleFloat = "left";
    controlToInsert3.style.textAlign = "left";
        
    // If not, then create it and set the styling
    controlToInsert = document.createElement("iframe");
    controlToInsert.setAttribute("id","DockedHelpWindow");
    controlToInsert.setAttribute("frameBorder","no"); 
    controlToInsert = InsertAdjacentElement(document.getElementById("DockedHelpWindowContainer"),"afterBegin", controlToInsert);
    controlToInsert.style.height = "89%";
    if(m_globalFullDocked == true || globalHideIndexedDocs == true)
    {
      controlToInsert.style.width = controlToInsert3.style.width;
      document.getElementById("KGTabbedWindowsControl1").style.height = controlToInsert.style.height;
      document.getElementById("KGTabbedWindowsControl1").style.overflowY = "hidden";
    }
    else
      controlToInsert.style.width = "400px";
      
    
    //controlToInsert.style.styleFloat = "left";
    controlToInsert.style.textAlign = "left";
    
    // create a div to put the textview view mode option div
    controlToInsert4 = document.createElement("div");
    controlToInsert4.setAttribute("id","DockedHelpWindowTVOptions");
    controlToInsert4.style.marginTop = "20px";
    controlToInsert4.style.textAlign = "right";
    controlToInsert4.style.paddingRight = "10px";
    // if not in edit mode and not showing web docs, then show the option div
    if(m_bEditable != true && globalShowingWebDoc == false)
      controlToInsert4.style.display = "block";
    else
      controlToInsert4.style.display = "none";
    controlToInsert4 = InsertAdjacentElement(document.getElementById("DockedHelpWindowContainer"),"afterBegin", controlToInsert4);
    if(m_currentTextViewViewMode == "Full")
      controlToInsert4.innerHTML = "<SPAN class='ToSingleTextView' id='DockedTextViewModeSwitch' onclick='SwitchTextViewViewMode()'></SPAN>";
    else
      controlToInsert4.innerHTML = "<SPAN class='ToFullTextView' id='DockedTextViewModeSwitch' onclick='SwitchTextViewViewMode()'></SPAN>";


    // create a div to put the toolbar buttons into and set any styling  
    controlToInsert2 = document.createElement("div");
    controlToInsert2.setAttribute("id","DockedHelpWindowOptions");
    controlToInsert2 = InsertAdjacentElement(document.getElementById("DockedHelpWindowContainer"),"afterBegin", controlToInsert2); 
    controlToInsert2.innerHTML = "<img id='close' class='close_img' src='UserControls/Images/BaseControls/CloseButton.png' onclick=\"CloseDockedKGHelpControl('HelpFrame');CloseHelpControl();\"/><img id='undock' class='undock_img' src='UserControls/Images/BaseControls/imgUnDock.png' onclick=\"UnDockKGHelpControl('HelpFrame');\" />";

    // create a div to put the toolbar buttons into and set any styling  
    laodingDiv = document.createElement("div");
    laodingDiv.setAttribute("id","DockedHelpWindowLoadingDiv");
    laodingDiv = InsertAdjacentElement(document.getElementById("DockedHelpWindowContainer"),"afterBegin", laodingDiv); 
    laodingDiv.style.display = 'none';
    laodingDiv.style.position = 'absolute';
    laodingDiv.style.fontSize = 'xx-small';
    laodingDiv.style.fontFamily = 'Verdana';
    laodingDiv.style.backgroundColor = 'white';
    laodingDiv.style.width = '120px';
    laodingDiv.style.padding = '5px';
    laodingDiv.style.textAlign = 'center';
    laodingDiv.style.border = '1px solid Gray';    

  }
  
  // Open, clear, and then close the documents text - this fixes the missing line of text bug
  controlToInsert.contentWindow.document.open();
  controlToInsert.contentWindow.document.write("");
  controlToInsert.contentWindow.document.close();
  
  // copy in the new text
  controlToInsert.contentWindow.document.write("<head><base target='_blank'><link href='CSS/KGHelpControl.css' type='text/css' rel='stylesheet'/><link href='CSS/TextViewDocument.css' type='text/css' rel='stylesheet'/></head><body class='PersonalisedScrollBar' style='overflow:scroll;' onscroll='parent.HelpFrameScrollTimeOut(\"DockedHelpWindow\")'>");
  controlToInsert.contentWindow.document.write(helpText);
  controlToInsert.contentWindow.document.write("</body>");
    
  if(document.frames)
  {
    document.frames['DockedHelpWindow'].location.reload(true);
  }

  // store the help box'x current width, height and positioning for a 'restore'
  helpBoxWidth = controlToInsert.style.width;
  helpBoxHeight = controlToInsert.style.height;
  helpBoxTop = controlToInsert.style.top;
  helpBoxLeft = controlToInsert.style.left;
  
  // Close the pop up window
  HideKGHelpControl();
  
  //controlToInsert3.style.float = "left";
  
    
  if(m_globalFullDocked == true)
  {
    // auto expand the splitter
    // split view 50/50
		DoExpandMapViewPane("split");
    //window.setTimeout('AdjustFullyDockedControlSize()', 50);
  }
  
  window.setTimeout('AdjustFullyDockedControlSize()', 50);
  window.setTimeout('HelpFrameDivResize()', 100);
    // make sure scroll to the right position
  window.setTimeout('SetupHelpFrameKnowdeTextViewDivs()',500);
*/
  
}

function AdjustFullyDockedControlSize()
{
  ///debugger;
   /* var tabbedControlDiv = document.getElementById("KGTabbedWindowsControl1");
    var controlToInsert = document.getElementById("DockedHelpWindow"); 
    var controlToInsert2 = document.getElementById("DockedHelpWindowOptions");
    var controlToInsert3 = document.getElementById("DockedHelpWindowContainer");

  if(m_globalFullDocked  == true)
  {
    hkLastChild(tabbedControlDiv).style.width = "0px";
    hkLastChild(tabbedControlDiv).style.height = "0px";
    if (window.ActiveXObject)
    {
      // can't set to invisable, the images in the grid still showing and will then overlay with the docked div
    }
    else
      hkLastChild(tabbedControlDiv).style.display = "none";
    
    
    controlToInsert3.style.width = document.getElementById("SplitterArrowDown").parentNode.parentNode.clientWidth - 10 + 'px';
    
    if(window.ActiveXObject && (document.getElementById("SplitterArrowDown").parentNode.parentNode.style.pixelHeight && document.getElementById("SplitterArrowDown").parentNode.parentNode.style.pixelHeight != ''))
      controlToInsert3.style.height = document.getElementById("SplitterArrowDown").parentNode.parentNode.style.pixelHeight - 5; //lastChild.firstChild
    else if(document.getElementById("SplitterArrowDown").parentNode.parentNode.offsetHeight && document.getElementById("SplitterArrowDown").parentNode.parentNode.offsetHeight != '')
      controlToInsert3.style.height = document.getElementById("SplitterArrowDown").parentNode.parentNode.offsetHeight - 5;
    else
      controlToInsert3.style.height = "100%";
      
    controlToInsert.style.width = controlToInsert3.style.width;
    
    if(controlToInsert3.style.height != "100%")
      controlToInsert.style.height = (controlToInsert3.style.height.replace('px','') - controlToInsert2.style.height.replace('px','') - 15) + 'px';
    else
      controlToInsert.style.height = "100%";
      
    document.getElementById("SplitterArrowDown").parentNode.parentNode.style.overflow = "hidden";
    
  }else
  {
    // make sure the div float to the left
    //controlToInsert3.style.float = "left";

  }
  
  if(navigator.appName == "Opera")
  {
    var dockedText = document.getElementById("DockedHelpWindow");
      
    // copy in the new text
    dockedText.contentWindow.document.write("<head><base target='_blank'><link href='CSS/KGHelpControl.css' type='text/css' rel='stylesheet'/><link href='CSS/TextViewDocument.css' type='text/css' rel='stylesheet'/></head><body class='PersonalisedScrollBar' style='overflow:scroll;' onscroll='parent.HelpFrameScrollTimeOut(\"DockedHelpWindow\")'>");
    dockedText.contentWindow.document.write(helpText);
    dockedText.contentWindow.document.write("</body>");

  }*/
}


function UnDockKGHelpControl(_helpBoxID)
{  
  m_bHelpFrameLoadSiblingKnowde = false;
  
  // now close the docked window and reset any css which has been changed
  CloseDockedKGHelpControl(_helpBoxID, "undock");
  
  //HideOrShowTextViewOptionDiv(false);
  HelpLinkClicked(true);
  
  // change image and onclick handler
  document.getElementById("SiteOverlays_KGHelpControl1_MaximiseToPageButton").className = "MaximiseButtonImage";
  document.getElementById("SiteOverlays_KGHelpControl1_MaximiseToPageButton").onclick = function(){MaximiseKGHelpControl('KGHelpControlID1', 'SiteOverlays_KGHelpControl1_MaximiseToPageButton')};  
}



function CloseDockedKGHelpControl(_helpBoxID, _undock, _tabbedWindow)
{  
  /*m_bHelpFrameLoadSiblingKnowde = false;
  
  var d = document.getElementById('DockedHelpWindowContainer');
  
  //debugger;
  // check if the indexed docs window is 'closed' if it is then drop the splitter
  if(globalHideIndexedDocs == true)
  {
    SplitterControl('down');
  }

  // remove the docked item from the page
  if(d != null)
  {
    purge(d);
    d.parentNode.removeChild(d);
  }

  // reset the old css values
  var controlToInsertTo = document.getElementById("KGTabbedWindowsControl1");
  controlToInsertTo.style.width = "100%";
  hkLastChild(controlToInsertTo).style.width = "100%";
  hkLastChild(controlToInsertTo).style.height = "100%";
  document.getElementById("SplitterArrowDown").parentNode.parentNode.style.overflow = "auto";
  
  document.getElementById("KGTabbedWindowsControl1_IndexedDocDiv").style.overflow = "auto";
  hkFirstChild(hkLastChild(document.getElementById("SplitterArrowDown").parentNode)).style.height = "100%";

  if(m_globalFullDocked == true)
  {
    m_globalFullDocked = false;
    
    if(hkLastChild(controlToInsertTo).style.display == "none")
      hkLastChild(controlToInsertTo).style.display = "";
    
    if(_tabbedWindow == null || _tabbedWindow != true)
      DoExpandMapViewPane("fully"); // close the bottom pane
  }
  
  var currentKG = document.getElementById(currentlySelectedKG)
			  
  if (currentKG != null)
  {
    if(_undock == "undock")
    {
			currentKG.innerHTML = "Now showing the Knowledge Gene<sup>&#174;</sup> and document";
		}
    else
    {
			if(globalSplitterSetting == "single")
			{
				currentKG.innerHTML = "Click here to show the Knowledge Gene";
				currentKG.href = "javascript:function temp(){ SwitchPaneView('map');return;" + currentKG.href.replace('javascript:','') + "} temp();";
			}
			else
			{
				currentKG.innerHTML = "Now showing the Knowledge Gene<sup>&#174;</sup>, click here to view the document";	
      }
    }
  }*/
}

function ClearHelpFrame(_clearSelectedValues)
{
  
  var HelpFrame = document.getElementById("HelpFrame");
  if (HelpFrame.src != null && HelpFrame.src != "")
  {
    var parent = HelpFrame.parentNode;
    
    var newHelpFrame = document.createElement('iframe');
    newHelpFrame.id = "HelpFrame";
    newHelpFrame.className = "helpIFrame";
    newHelpFrame.frameBorder = 0;
      
    purge(HelpFrame);  
    parent.removeChild(HelpFrame);
    InsertAdjacentElement(parent,"beforeend", newHelpFrame);
  }
  else
  {
    // Make sure we clear the contents of the document window
    HelpFrame.contentWindow.document.write("");
    HelpFrame.contentWindow.document.close();
  }
  
  // clear member variables
    //debugger;
  
  /*m_FrameLoadedKnowdeIdList = new Array();
  m_FrameLoadedKnowdeIdString = '';
  m_FrameUnLoadedKnowdeIdString = '';

  // knowde and client knowde list
  m_FrameKnowdeIdsArray = new Array();
  m_FrameKnowdeClientIdsArray = new Array();

  m_FrameDivIDArray = new Array();
  m_FrameDivPathArray = new Array();
  m_FrameDivHeightArray = new Array();
  m_FrameKnowdePathString = '';
  
  if(_clearSelectedValues == null || _clearSelectedValues == true)
  {
    m_strFrameSelectedKGID = '';
    m_strFrameSelectedKnowdeID = '';
    m_strFrameSelectedKnowdeDBID = '';
    m_strFrameSelectedKnowdeContext = '';
    m_strFrameCentreKnowdeContext = '';
    m_bHelpFrameLoadSiblingKnowde = false;
  }
  
  m_helpFrameScrollTimeOut = null;*/
}

//pass through the session stuff...
function OpenHelpControl_wrapped(_hideDockButton, _imgDockInPageID)
{
  var docButton = document.getElementById(_imgDockInPageID);
  if (_hideDockButton)
  {
    docButton.style.display = "none";
    globalHideDockButton = true;
  }
  else
  {
    docButton.style.display = "";
    globalHideDockButton = false;
  }
  
  // make sure the docked window is close then the help control popup
  if(document.getElementById('DockedHelpWindowContainer') != null)
    CloseDockedKGHelpControl('HelpFrame');
  
  ShowKGHelpControl();
}

function CloseHelpControl()
{
	if(document.getElementById("GreyDiv") != null)
	{
	    purge(document.getElementById("GreyDiv"));
		document.getElementById("Form1").removeChild(document.getElementById("GreyDiv"));
		document.getElementById("m_cookieDiv").className = "m_cookieDivHidden";
		document.getElementById("miniGlobe").className = "miniGlobe";
	}
  globalShowingWebDoc = false;
  var MapHelpBox = document.getElementById("KGHelpControlID1");
  
  // reset the tooltip
  MapHelpBox.title = "Associated Text";
  // hide textview view option div
  //HideOrShowTextViewOptionDiv(false);
  
  // reset the view mode
  //SwitchTextViewViewMode("Single");
  //globalLastTickerAction = "";
  
  ClearHelpFrame()
  SetHelpStateCookie();
  HideKGHelpControl();
  
  //debugger;
  //if (window.KGTextViewEditingToolbar_ChangeEditbarMode && m_bTextViewWritable == true)
    //KGTextViewEditingToolbar_ChangeEditbarMode("TextViewReset");

  // show the preview button if in edit mode
  /*if(m_bEditable == true)
  {
    KGButtonToolbar_hideOrShowPreviewFullTVButton(true);
    if(m_bTextViewWritable == true && EditFrameContentWindowExists())
    {
      SaveCurrentlyEditingTextView(false);
  
      m_EditFrameDiv = document.getElementById('TextViewEditFrameDiv');

      if(m_EditFrameDiv != null)
        m_EditFrameDiv.innerHTML = "";
        
      m_bTextViewWritable = false;
    }else
    {
      // clear text view auto save timeout
      if(m_autoSaveTimeOut != null)
        clearTimeout(m_autoSaveTimeOut);
      
      // update the application control if it's open
      if (m_applicationControlOpen)
        ApplicationContextChanged(returnKnowdeID(_parentKnowdeDiv), Active_KGID)
    }
  }else
    KGButtonToolbar_hideOrShowPreviewFullTVButton(false);
  */
  

}

function CookieCheckBox(e)
{
  e = e || window.event;
  var targ = e.target || e.srcElement;
	if(targ.checked)
	{
		//set the persistent cookie
		WM_setCookie('initHelp','hide', m_helpCookieExpiration);
	}
	else
	{
		//delete the persistent cookie
		WM_killCookie('initHelp');
	}
}

/*function HandleHelpFrameLoadAll(_knowdeSequenceInfo, _loadedContentList)
{
  //debugger;
  
  if(m_bHelpFrameLoadSiblingKnowde == false)
  {
    m_FrameLoadedKnowdeIdList = new Array();
    m_FrameLoadedKnowdeIdString = '';
  
    m_FrameKnowdeIdsArray = new Array();
    m_FrameKnowdeClientIdsArray = new Array();
    
    m_FrameKnowdePathString = '';
    
    var frameDivHtml = '';
    
    // loop through all the knowdes m_strSelectedKnowdeID is the currently selecte knowde
    // knowdes above and below will be loaded in top and bottom iframes
    // don't use split incase the knowde title contains character that is used as our seperator
    var foundCurrentKnowde = 0;
    var kidx = _knowdeSequenceInfo.indexOf('(kid=');
    while(kidx >= 0)
    {
      var kidx2 = _knowdeSequenceInfo.indexOf('|ckid=', kidx+1);
      if(kidx2 > kidx)
      {
        var knowdeId = _knowdeSequenceInfo.substr(kidx+5, kidx2-(kidx+5));
        var kidx3 = _knowdeSequenceInfo.indexOf('|path=', kidx2+1);
        if(kidx3 > kidx2)
        {
          var clientKnowdeId = _knowdeSequenceInfo.substr(kidx2+6, kidx3-(kidx2+6));
          
          // store the knowde and client id mapping
          m_FrameKnowdeIdsArray.push(knowdeId);
          m_FrameKnowdeClientIdsArray.push(clientKnowdeId);
          
          var kidx4 = _knowdeSequenceInfo.indexOf('|title=', kidx3+1);
          if(kidx4 > kidx3)
          {
            var pathContext = _knowdeSequenceInfo.substr(kidx3+6, kidx4-(kidx3+6));
            kidx = _knowdeSequenceInfo.indexOf(')(kid=', kidx4+1);
            var knowdeTitle = '';
            if(kidx > kidx4)
            {
              knowdeTitle = _knowdeSequenceInfo.substr(kidx4+7, kidx-(kidx4+7));
              kidx = kidx + 1; // because we are searching for )( instead of just (
            }else if(kidx == -1)
            {
              knowdeTitle = _knowdeSequenceInfo.substr(kidx4+7, _knowdeSequenceInfo.length-1-(kidx4+7));
            }
            
            // now create div and load to the content
            var frame = m_HelpFrame;
             
             if(frame != null)
             {
               var loaded = 0;
               var sidx = _loadedContentList.indexOf('<HKTextView' + clientKnowdeId + '>');
               var sidx2 = _loadedContentList.indexOf('</HKTextView>', sidx+1);
               var content = '';
               if(sidx != -1 && sidx2 != -1)
               {
                  loaded = 1;
                  content = _loadedContentList.substr(sidx+11+clientKnowdeId.length+1,sidx2-(sidx+11+clientKnowdeId.length+1));
                  var kid = clientKnowdeId;
                 
                  m_FrameLoadedKnowdeIdList.push(kid);
                  m_FrameLoadedKnowdeIdString += kid + ','
                 
                  var bidx = content.toLowerCase().indexOf('<body');
                  var bidx2 = content.indexOf('>');
                  var bidx3 = content.toLowerCase().indexOf('</body>');
                  if(bidx != -1 && bidx2 > bidx && bidx3 > bidx2)
                    content = content.substr(bidx2+1, bidx3-(bidx2+1));
        
                  if(content == '')
                  {
                    content = GetDefaultTextViewContentWithTitle(clientKnowdeId, knowdeTitle, 1, m_noTextViewFoundContent);
                  }else
                  {
                    content = TrimTickerSpans(content);
                    if (content.indexOf(m_textViewTickerSelectionHighlightColor) > -1)
                      content = ReturnUnhighlightedTickerText(content);
                      
                    // check whether it has an existing title, if not, add the title manually
                    if(CheckTextViewHasTitle(clientKnowdeId, knowdeTitle, content) == false)
                      content = WrapTextViewContentWithTitle(clientKnowdeId, knowdeTitle, content);
                  }
                                    
               }else
               {
                 loaded = 0;
                 // text view is not loaded yet
                 content = GetDefaultTextViewContentWithTitle(clientKnowdeId, knowdeTitle, 1, m_notLoadedText);
                 m_FrameUnLoadedKnowdeIdString += clientKnowdeId + ','
               }
               
              if((m_strFrameSelectedKnowdeID == knowdeId || m_strFrameSelectedKnowdeID == clientKnowdeId)
              && m_strFrameSelectedKnowdeContext == '')
              {
                  m_strFrameSelectedKnowdeContext = pathContext;
              }
               
               //for scrolling position detection debug only//
               //content = pathContext + '<br>' + content; 
              
               m_FrameKnowdePathString += pathContext + ',';
               
                    var divHtml = "<div id='" + pathContext + "' kid='" + clientKnowdeId + "' title='" + knowdeTitle + "' isLoaded='" + loaded + "' width='100%'>";
                    //if (content.indexOf(m_textViewTickerSelectionHighlightColor) > -1)
                      //content = ReturnUnhighlightedTickerText(content);
                    
                    // directly add content can't deal with not proper formatted HTML
                    // like  missing ticker span close tag etc and then cause iframe's innerHTML 
                    // to be auto corrected later on by added a </span> in the end 
                    // so causing problem because childNodes is not right anymore
                    //divHtml += content; 
                    var tempDiv = document.createElement("div");
                    tempDiv.innerHTML = content; // the content will be auto corrected and guanrantee the ifram only contains divs as first level child nodes
                    divHtml += tempDiv.innerHTML; 
                    divHtml += "</div>";
                      
                    frameDivHtml += divHtml;
                 
             }
            
          }
        }
      }
    }// end while
    
    var MapHelpBox = document.getElementById("KGHelpControlID1");
    m_HelpFrame.contentWindow.document.write("<html><head><base target='_blank'><link href='CSS/KGHelpControl.css' type='text/css' rel='stylesheet'/><link href='CSS/TextViewDocument.css' type='text/css' rel='stylesheet'/></head><body class='PersonalisedScrollBar' style='overflow:scroll;' onscroll='parent.HelpFrameScrollTimeOut(\"HelpFrame\")'>");
    m_HelpFrame.contentWindow.document.write(frameDivHtml);
    m_HelpFrame.contentWindow.document.write("</body></html>");
     
  } // end if
  else
  {
    
    // need to find out where the knowde is
    var knowdeFrame = '';
      
    // patial load text views
    if(_loadedContentList && _loadedContentList != ''
      && m_HelpFrame != null)
    {
       // loop through each textview content
        var sidx = _loadedContentList.indexOf('<HKTextView');
        var sidx2 = _loadedContentList.indexOf('>', sidx);
        var sidx3 = _loadedContentList.indexOf('</HKTextView>', sidx2);
        while(sidx != -1 && sidx2 != -1 && sidx3 != -1)
        {
          var content = _loadedContentList.substr(sidx2+1, sidx3-(sidx2+1));
          var kid = _loadedContentList.substr(sidx+11,sidx2-(sidx+11));
          
          if((m_FrameLoadedKnowdeIdString.indexOf(kid+',') != 0)
          && (m_FrameLoadedKnowdeIdString.indexOf(','+kid+',') == -1))
          {
            m_FrameLoadedKnowdeIdList.push(kid);
            m_FrameLoadedKnowdeIdString += kid + ',';
            
            // remove from unloaded list
            if(m_FrameUnLoadedKnowdeIdString.indexOf(kid+',') == 0)
              m_FrameUnLoadedKnowdeIdString = m_FrameUnLoadedKnowdeIdString.substring(kid.length+1);
            else
              m_FrameUnLoadedKnowdeIdString = m_FrameUnLoadedKnowdeIdString.replace(','+kid+',', ',');
              
            // load all the unloaded textviews for this knowde to the given content
            var bidx = content.toLowerCase().indexOf('<body');
            var bidx2 = content.indexOf('>');
            var bidx3 = content.toLowerCase().indexOf('</body>');
            if(bidx != -1 && bidx2 > bidx && bidx3 > bidx2)
               content = content.substr(bidx2+1, bidx3-(bidx2+1));
               
            var method = function(el){if(el.getAttribute('kid') == kid) return true; return false;};
            //var frameDivs = YAHOO.util.Dom.getElementsBy(method,null,m_HelpFrame.contentWindow.document.body);   
            var frameDivs = YAHOO.util.Dom.getChildrenBy(m_HelpFrame.contentWindow.document.body,method);   
            for(var iCounter = 0; iCounter < frameDivs.length; iCounter++)
            {
                  var childDiv = frameDivs[iCounter];
                  
                  if(content == '')
                      content = childDiv.innerHTML.replace(m_notLoadedText, m_noTextViewFoundContent);
                  else
                  {
                    content = TrimTickerSpans(content);
                    if (content.indexOf(m_textViewTickerSelectionHighlightColor) > -1)
                      content = ReturnUnhighlightedTickerText(content);
                      
                    //for scrolling position detection debug only//
                    //content = childDiv.id + '<br>' + content; 
                    
                    // check whether it has an existing title, if not, add the title manually
                    var ckid = childDiv.getAttribute('kid');
                    var ktitle = childDiv.getAttribute('title');
                    if(CheckTextViewHasTitle(ckid, ktitle, content) == false)
                      content = WrapTextViewContentWithTitle(ckid, ktitle, content);
                  }
                  

                  if(childDiv != null && childDiv.getAttribute('kid') == kid && (childDiv.getAttribute('isLoaded') == 0 || childDiv.getAttribute('isLoaded') == '0'))
                  {
                    childDiv.innerHTML = content;
                    childDiv.setAttribute('isLoaded', 1);
                  }
             }      

            
          }
          
                         
            _loadedContentList = _loadedContentList.substr(sidx3+13);
            sidx = _loadedContentList.indexOf('<HKTextView');
            sidx2 = _loadedContentList.indexOf('>', sidx);
            sidx3 = _loadedContentList.indexOf('</HKTextView>', sidx2);
          
        }    // end while
      
    }
  }
  
    // Copy the text view to the docked window if it exists
    var dockedText = document.getElementById("DockedHelpWindow");
    
    if (dockedText != null)
    {
      dockedText.contentWindow.document.open();
      dockedText.contentWindow.document.write("");
      dockedText.contentWindow.document.close();

      dockedText.contentWindow.document.write("<html><head><base target='_blank'><link href='CSS/KGHelpControl.css' type='text/css' rel='stylesheet'/><link href='CSS/TextViewDocument.css' type='text/css' rel='stylesheet'/></head><body class='PersonalisedScrollBar' style='overflow:scroll;' onscroll='parent.HelpFrameScrollTimeOut(\"DockedHelpWindow\")'>");
      dockedText.contentWindow.document.write(m_HelpFrame.contentWindow.document.body.innerHTML);
      dockedText.contentWindow.document.write("</body></html>");
    }

  
  window.setTimeout("SetupHelpFrameKnowdeTextViewDivs()",200);
  window.setTimeout("helpText = m_HelpFrame.contentWindow.document.body.innerHTML;", 300);
}*/

/*function HandleNewWindowTextViewLoadAll(_knowdeSequenceInfo, _loadedContentList, _selectedKnowdeContext)
{
  var newWindowFrame =  m_newTextViewWindow.document.getElementById('NewWindowHelpFrame');
      
    // patial load text views
    if(_loadedContentList && _loadedContentList != ''
      && newWindowFrame != null)
    {
       // loop through each textview content
        var sidx = _loadedContentList.indexOf('<HKTextView');
        var sidx2 = _loadedContentList.indexOf('>', sidx);
        var sidx3 = _loadedContentList.indexOf('</HKTextView>', sidx2);
        while(sidx != -1 && sidx2 != -1 && sidx3 != -1)
        {
          var content = _loadedContentList.substr(sidx2+1, sidx3-(sidx2+1));
          var kid = _loadedContentList.substr(sidx+11,sidx2-(sidx+11));
          
                          
            // load all the unloaded textviews for this knowde to the given content
            var bidx = content.toLowerCase().indexOf('<body');
            var bidx2 = content.indexOf('>');
            var bidx3 = content.toLowerCase().indexOf('</body>');
            if(bidx != -1 && bidx2 > bidx && bidx3 > bidx2)
               content = content.substr(bidx2+1, bidx3-(bidx2+1));
            // Yahoo getElementsBy too slow in IE
            var method = function(el){if(el.getAttribute('kid') == kid) return true; return false;};
            //var frameDivs = YAHOO.util.Dom.getElementsBy(method,null,newWindowFrame.contentWindow.document.body);   
            var frameDivs = YAHOO.util.Dom.getChildrenBy(newWindowFrame.contentWindow.document.body,method);   

            for(var iCounter = 0; iCounter < frameDivs.length; iCounter++)
            //for(var iCounter = 0; iCounter < newWindowFrame.contentWindow.document.body.childNodes.length; iCounter++)
            {
               //if(newWindowFrame.contentWindow.document.body.childNodes[iCounter].getAttribute('kid') == kid)
               //{   
                  //var childDiv = newWindowFrame.contentWindow.document.body.childNodes[iCounter]; 
                  var childDiv = frameDivs[iCounter];
                  
                  if(content == '')
                      content = childDiv.innerHTML.replace(m_notLoadedText, m_noTextViewFoundContent);
                  else
                  {
                    content = TrimTickerSpans(content);
                    if (content.indexOf(m_textViewTickerSelectionHighlightColor) > -1)
                      content = ReturnUnhighlightedTickerText(content);
                      
                    //for scrolling position detection debug only//
                    //content = childDiv.id + '<br>' + content; 
                    
                    // check whether it has an existing title, if not, add the title manually
                    var ckid = childDiv.getAttribute('kid');
                    var ktitle = childDiv.getAttribute('title');
                    if(CheckTextViewHasTitle(ckid, ktitle, content) == false)
                      content = WrapTextViewContentWithTitle(ckid, ktitle, content);

                  }
                  
                  if(childDiv != null && childDiv.getAttribute('kid') == kid && (childDiv.getAttribute('isLoaded') == 0 || childDiv.getAttribute('isLoaded') == '0'))
                  {
                    childDiv.innerHTML = content;
                    childDiv.setAttribute('isLoaded',1);
                  }
                //}
             }      
                         
            _loadedContentList = _loadedContentList.substr(sidx3+13);
            sidx = _loadedContentList.indexOf('<HKTextView');
            sidx2 = _loadedContentList.indexOf('>', sidx);
            sidx3 = _loadedContentList.indexOf('</HKTextView>', sidx2);257
          
        }    // end while
        
        // scroll to the right place
        if(_selectedKnowdeContext != null && _selectedKnowdeContext != '')
        {
            var method = function(el){if(el.id == _selectedKnowdeContext) return true; return false;};
            //var frameDivs = YAHOO.util.Dom.getElementsBy(method,null,newWindowFrame.contentWindow.document.body);   
            var frameDivs = YAHOO.util.Dom.getChildrenBy(newWindowFrame.contentWindow.document.body,method);   
            if(frameDivs.length > 0)
            {
              newWindowFrame.contentWindow.document.body.scrollTop  = frameDivs[0].offsetTop - 10;
            }
        }
      
    }
    
    // hide loading div
    var loadingDiv = m_newTextViewWindow.document.getElementById('NewWindowTextViewLoadingDiv');
    if(loadingDiv != null)
        loadingDiv.style.display = 'none';
}*/

/*function SetupHelpFrameKnowdeTextViewDivs()
{
  //debugger;
  m_HelpFrame = document.getElementById("HelpFrame");
  var adiv = null;
  m_DockedHelpFrame = document.getElementById("DockedHelpWindow");
  var dockedadiv = null;
  
  if(m_HelpFrame != null)
    adiv = m_HelpFrame.contentWindow.document.body;
  if(m_DockedHelpFrame != null)
    dockedadiv = m_DockedHelpFrame.contentWindow.document.body;

  m_FrameDivIDArray = new Array();
  m_FrameDivPathArray = new Array();
  m_FrameDivHeightArray = new Array();
  // m_FrameKnowdePathString  = '';

  var pos = 0;
  if(m_HelpFrame != null && adiv != null)
  {
     if(m_strFrameSelectedKnowdeContext == '' && m_strFrameSelectedKnowdeID != '')
     {
        var method = function(el){if(el.getAttribute('kid') == m_strFrameSelectedKnowdeID) return true; return false;};
        //var frameDivs = YAHOO.util.Dom.getElementsBy(method,null,adiv);  
        var frameDivs = YAHOO.util.Dom.getChildrenBy(adiv,method);   
        if(frameDivs.length > 0)
          m_strFrameSelectedKnowdeContext = frameDivs[0].id;
     }
                
        if(m_strFrameCentreKnowdeContext != '')
        {
          var method = function(el){if(el.id == m_strFrameCentreKnowdeContext) return true; return false;};
          //var frameDivs = YAHOO.util.Dom.getElementsBy(method,null,adiv);  
          var frameDivs = YAHOO.util.Dom.getChildrenBy(adiv,method);   
          if(frameDivs.length > 0)
          {
            // make sure scroll to this position
            m_bHelpFrameManualScroll = true;
            
            var scrollTopValue = frameDivs[0].offsetTop - m_HelpFrame.offsetHeight/2;
            //scrollTopValue = scrollTopValue - m_frameScrollTopOffSet;
            if(scrollTopValue < 0)
              scrollTopValue = 0;
            adiv.scrollTop  = scrollTopValue;
          }
          // for docked frame
          if(dockedadiv != null)
          {
            //frameDivs = YAHOO.util.Dom.getElementsBy(method,null,dockedadiv);  
            frameDivs = YAHOO.util.Dom.getChildrenBy(dockedadiv,method);   
            if(frameDivs.length > 0)
            {
              // make sure scroll to this position
              m_bHelpFrameManualScroll = true;
              
              var scrollTopValue = frameDivs[0].offsetTop - m_DockedHelpFrame.offsetHeight/2;
              //scrollTopValue = scrollTopValue - m_frameScrollTopOffSet;
              if(scrollTopValue < 0)
                scrollTopValue = 0;
              dockedadiv.scrollTop  = scrollTopValue;
            }
          }
        }
        
        if(m_strFrameSelectedKnowdeContext != '')
        { 
          if(m_previousHighLightedPath != '')
          {
              // unhighlight
            var method = function(el){if(el.id == m_previousHighLightedPath) return true; return false;};
            //var frameDivs = YAHOO.util.Dom.getElementsBy(method,null,adiv);  
            var frameDivs = YAHOO.util.Dom.getChildrenBy(adiv,method);   
            if(frameDivs.length > 0)
            {
              //frameDivs[0].style.backgroundColor = 'white';
              frameDivs[0].style.borderLeft = 'none';
              frameDivs[0].style.paddingLeft = '0px';
              frameDivs[0].style.marginLeft = '0px';
            }
            // for docked frame
            if(dockedadiv != null)
            {
              //frameDivs = YAHOO.util.Dom.getElementsBy(method,null,dockedadiv);  
              frameDivs = YAHOO.util.Dom.getChildrenBy(dockedadiv,method);   

              if(frameDivs.length > 0)
              {
                //frameDivs[0].style.backgroundColor = 'white';
                frameDivs[0].style.borderLeft = 'none';
                frameDivs[0].style.paddingLeft = '0px';
                frameDivs[0].style.marginLeft = '0px';
              }
            }
          }
          
          // highlight
          var method = function(el){if(el.id == m_strFrameSelectedKnowdeContext) return true; return false;};
          //var frameDivs = YAHOO.util.Dom.getElementsBy(method,null,adiv);  
          var frameDivs = YAHOO.util.Dom.getChildrenBy(adiv,method);   
          if(frameDivs.length > 0)
          {
            if(m_strFrameCentreKnowdeContext == '')
            {
              // make sure scroll to this position
              // m_bHelpFrameManualScroll = true;
              var scrollTopValue = frameDivs[0].offsetTop - (m_frameScrollTopOffSet + 20);
              if(scrollTopValue < 0)
                scrollTopValue = 0;
              m_helpFrameScrollMoreOnTopTimeOut = window.setTimeout("ScrollMoreFromTop('HelpFrame'," + scrollTopValue + ", 0)", m_helpFrameScrollDelay);
              //adiv.scrollTop  = scrollTopValue;
            }
            
            // now get rid of the empty <P> tags in the end which makes the next div overlay a bit with the current div
            var content = frameDivs[0].innerHTML;
            content = content.replace(/(<p\/>|<p><\/p>|<p \/>|<p><br \/><\/p>|<p><br\/><\/p>)+$/i,'');//remove trailing empty paragraph
            content = content.replace(/(<p\/>|<p><\/p>|<p \/>|<p><br \/><\/p>|<p><br\/><\/p>)<\/div>+$/i,'</div>');//remove trailing empty paragraph
            frameDivs[0].innerHTML = content;

            //frameDivs[0].style.backgroundColor = m_helpFrameHighlightColor;
            frameDivs[0].style.borderLeft = m_helpFrameHighlightBorderLeftStyle;
            frameDivs[0].style.paddingLeft = m_helpFrameHighlightBorderLeftPadding + 'px';
            frameDivs[0].style.marginLeft = '-' + m_helpFrameHighlightBorderLeftPadding + 'px';
            
           m_previousHighLightedPath = frameDivs[0].id;
         }
          
         // for docked frame
        if(dockedadiv != null)
        {
          //frameDivs = YAHOO.util.Dom.getElementsBy(method,null,dockedadiv);  
          frameDivs = YAHOO.util.Dom.getChildrenBy(dockedadiv,method);   
          if(frameDivs.length > 0)
          {
            if(m_strFrameCentreKnowdeContext == '')
            {
              // make sure scroll to this position
              // m_bHelpFrameManualScroll = true;
              var scrollTopValue = frameDivs[0].offsetTop - m_frameScrollTopOffSet;
              if(scrollTopValue < 0)
                scrollTopValue = 0;
                
              m_dockedFrameScrollMoreOnTopTimeOut = window.setTimeout("ScrollMoreFromTop('DockedFrame'," + scrollTopValue + ", 0)", m_helpFrameScrollDelay);
              //dockedadiv.scrollTop  = scrollTopValue;
            }
            
            // now get rid of the empty <P> tags in the end which makes the next div overlay a bit with the current div
            var content = frameDivs[0].innerHTML;
            content = content.replace(/(<p\/>|<p><\/p>|<p \/>|<p><br \/><\/p>|<p><br\/><\/p>)+$/i,'');//remove trailing empty paragraph
            content = content.replace(/(<p\/>|<p><\/p>|<p \/>|<p><br \/><\/p>|<p><br\/><\/p>)<\/div>+$/i,'</div>');//remove trailing empty paragraph
            frameDivs[0].innerHTML = content;
            
            //frameDivs[0].style.backgroundColor = m_helpFrameHighlightColor;
            frameDivs[0].style.borderLeft = m_helpFrameHighlightBorderLeftStyle;
            frameDivs[0].style.paddingLeft = m_helpFrameHighlightBorderLeftPadding + 'px';
            frameDivs[0].style.marginLeft = '-' + m_helpFrameHighlightBorderLeftPadding + 'px';
          }
        }
 
     }
    
  }
  
}*/

/*function ScrollMoreFromTop(_target, _scrollTop, _amount)
{
  //debugger;
  var div = null;
  m_HelpFrame = document.getElementById("HelpFrame");
  var adiv = null;
  m_DockedHelpFrame = document.getElementById("DockedHelpWindow");
  var dockedadiv = null;
  
  if(m_HelpFrame != null)
    adiv = m_HelpFrame.contentWindow.document.body;
  if(m_DockedHelpFrame != null)
    dockedadiv = m_DockedHelpFrame.contentWindow.document.body;

  if(_target == 'HelpFrame')
  {
    clearTimeout(m_helpFrameScrollMoreOnTopTimeOut);
    m_helpFrameScrollMoreOnTopTimeOut = null;
    div = adiv;
  } else if(_target == 'DockedFrame')
  {
    clearTimeout(m_dockedFrameScrollMoreOnTopTimeOut);
    m_dockedFrameScrollMoreOnTopTimeOut = null;
    div = dockedadiv;
  }
  //debugger;
  if(div != null)
  {
    //alert(_scrollTop + '|' + _amount + '|' + div.scrollTop);

    if(_scrollTop < 0)
      _scrollTop = 0;
      
    if(_amount <= 0)
    {
      // calculate scroll amount
      var diff = Math.abs(_scrollTop - div.scrollTop);
      if(diff == 0)
        return;
      else if(diff < 100)
      {
        _amount = Math.ceil(diff/2); // minum 2 times
      }
      else if(diff <= 500)
        _amount = 50;
      else
      {
        _amount = Math.ceil(diff/10); // maximum do it 10 times
      }
      if(_amount <= 0)
        _amount = 10;
    }
    
      var scrollTo = div.scrollTop;
      if(div.scrollTop > _scrollTop)
      {
        scrollTo -=  _amount;
        if(scrollTo < _scrollTop)
          scrollTo = _scrollTop;
      }else if(div.scrollTop < _scrollTop)
      {
        scrollTo += _amount;
        if(scrollTo > _scrollTop)
          scrollTo = _scrollTop;
      }
      // now scroll to the position
      m_bHelpFrameManualScroll = true;
      div.scrollTop = scrollTo;
      // if we have scroll to the desire location, and also haven't reach the end 
      if(div.scrollTop != _scrollTop && div.scrollTop == scrollTo)
      {
        if(_target == 'HelpFrame')
        {
          m_helpFrameScrollMoreOnTopTimeOut = window.setTimeout("ScrollMoreFromTop('HelpFrame'," + _scrollTop + "," + _amount + ")", m_helpFrameScrollDelay);
        }else if(_target == 'DockedFrame')
        {
          m_dockedFrameScrollMoreOnTopTimeOut = window.setTimeout("ScrollMoreFromTop('DockedFrame'," + _scrollTop + "," + _amount + ")", m_helpFrameScrollDelay);
        }
      }
  }    
}*/

/*function ChangeSelectedHelpFrameKnowde(_selectedKnowdeID, _selectedKnowdePath)
{
  if(m_strFrameSelectedKnowdeID != _selectedKnowdeID)
  {
    if(_selectedKnowdePath == null)
      _selectedKnowdePath = '';
    m_strFrameSelectedKnowdeContext = _selectedKnowdePath;
    m_strFrameSelectedKnowdeID = _selectedKnowdeID;
    return true;
  }
  else
    return false;
}*/


/*function GetHelpWindowCallBackArgs(_kgId)
{
  m_HelpFrame = document.getElementById("HelpFrame");
  var kgid = Active_KGID;
  if(_kgId != null && _kgId > 0)
    kgid = _kgId;
  var args = "|KGId=" + kgid + "|ViewMode=" + m_currentTextViewViewMode;
  
  var loadamount = m_HelpFrame.offsetHeight/40/2;
    if(m_textViewPreLoadAmount > loadamount)
      loadamount = m_textViewPreLoadAmount;
  args += "|PreLoadAmount=" + loadamount;
  
  if(m_bHelpFrameLoadSiblingKnowde == true)
  {
    args += "|LoadSiblingKnowde=true";
    var toLoadDivs = '';
    var knowdeContext = m_strFrameSelectedKnowdeContext;
    
    toLoadDivs = GetPreLoadDivsForHelpFrameSelectedKnowde(m_tickerKnowdeID, knowdeContext, loadamount);       
    
    args += '|KnowdeId=' + m_tickerKnowdeID + '|KnowdePathContext=' + knowdeContext + '|KnowdeIdList=' + toLoadDivs;;
    
    if(toLoadDivs == '')
      args += "|KnowdeLoaded=true";
    else
      args += "|KnowdeLoaded=false";
  }else
  {
    // assume each text view has minimum 40px height
    args += "|KnowdeLoaded=false";
  }
  
  return args;
}*/


/*function FindSelectedHelpFrameKnowdePathContext(_knowdeID)
{
  //debugger;
  var pathContext = '';
  
  if(_knowdeID != null && m_strFrameSelectedKnowdeDBID != '')
  {
    var knowdeID = _knowdeID;
    if(knowdeID < 0)
    {
      // find the knowdeID  instead
      for(var ki = 0; ki < m_FrameKnowdeClientIdsArray.length; ki++)
      {
        if(m_FrameKnowdeClientIdsArray[ki] == knowdeID)
        {
          knowdeID = m_FrameKnowdeIdsArray[ki];
          break;
        }
      }
    }
    
    if(knowdeID > 0 && knowdeID != m_strFrameSelectedKnowdeDBID)
    {
      // basic logic to find possible knowde context and locate the correct text view if knowde is reused
      // might need to be improved later on
      var pathStr = '';
      // in text view assocations:
      // new selected knowde is walked after the previous selected knowde
      var re = new RegExp('(\\[' + m_strFrameSelectedKnowdeDBID + '\\]([^,]+)\\['+knowdeID+'\\])', 'gi');
      // new selected knowde is walked before the previous selected knowde
      var re2 = new RegExp('(\\[' + knowdeID + '\\]([^,]+)\\['+m_strFrameSelectedKnowdeDBID+'\\])', 'gi');
      var matchResult = re.exec(m_FrameKnowdePathString);
      pathStr = m_FrameKnowdePathString;
      if(matchResult == null)
      {
        matchResult = re2.exec(m_FrameKnowdePathString);
      }
      
      if(matchResult != null)
      {
        var foundContext = '';
        var foundIdx = matchResult.index;
        if(foundIdx >= 0)
        {
          var endIdx = pathStr.indexOf(',',foundIdx);
          if(endIdx > 0)
          {
            var pathStr2 = pathStr.substr(0, endIdx);
            var startIdx = pathStr2.lastIndexOf(',');
            if(startIdx == -1)
              foundContext = pathStr2;
            else
              foundContext = pathStr2.substr(startIdx+1);
              
            if(foundContext != '')
            {
              var kidx = foundContext.indexOf('['+knowdeID+']');
              if(kidx != -1)
              {
                foundContext = foundContext.substr(0, kidx + knowdeID.length + 2);
                if(pathStr.indexOf(foundContext + ',') == 0 || pathStr.indexOf(',' + foundContext + ',') != -1)
                  pathContext = foundContext;
              }
            }
          }
        }
      }
    }else if(knowdeID > 0 && knowdeID == m_strFrameSelectedKnowdeDBID)
    {
      pathContext = m_strFrameSelectedKnowdeContext;
    }
    // end if knowdeID > 0
    
  }
  return pathContext;
}*/

/*function GetPreLoadDivsForHelpFrameSelectedKnowde(_knowdeId, _knowdePath, _loadAmount)
{
  // when a knowde is selected in the mapview, find out what knowde text views need to be loaded around it
  var toLoadDivs = '';
  _loadAmount = Math.round(_loadAmount);
  
  if(_knowdePath == '')
  {
      // get the first occurrance of the knowde as default 
      var adiv = m_HelpFrame.contentWindow.document.body;
      
      var method = function(el){if(el.getAttribute('kid') == _knowdeId) return true; return false;};
      //var frameDivs = YAHOO.util.Dom.getElementsBy(method,null,adiv); 
      var frameDivs = YAHOO.util.Dom.getChildrenBy(adiv,method);
         
      if(frameDivs.length > 0)
         _knowdePath = frameDivs[0].id;
  }
    
  if(m_FrameLoadedKnowdeIdString.indexOf(_knowdeId + ',') != 0 &&  m_FrameLoadedKnowdeIdString.indexOf(',' + _knowdeId + ',') == -1)
    toLoadDivs = _knowdeId + ',';
    
  if(_knowdePath != '')
  {
    if(_knowdeId == m_strFrameSelectedKnowdeID)
      m_strFrameSelectedKnowdeContext = _knowdePath;
      
    // unique context found, now need to find out knowdes around the given knowde path
    var pathArray = m_HelpFrame.contentWindow.document.body.childNodes;
    
    var idx = -1;
    for(var icount = 0; icount < pathArray.length; icount++)
    {
      var childDiv = pathArray[icount];
      if(childDiv.id == _knowdePath)
      {
        idx = icount;
        break;
      }
    }
    if(idx >= 0)
    {
      var startIdx = idx - _loadAmount;
      var endIdx = idx + _loadAmount;
      if(startIdx < 0)
        endIdx -= startIdx;
      if(endIdx >= pathArray.length)
        startIdx -= (pathArray.length-1);
      if(startIdx < 0)
        startIdx = 0;
      if(endIdx >= pathArray.length)
        endIdx = pathArray.length - 1;
        
      for(var icount = startIdx; icount <= endIdx; icount++)
      {
        if(pathArray[icount])
        {
          if(m_FrameLoadedKnowdeIdString.indexOf(pathArray[icount].getAttribute('kid') + ',') != 0 &&  m_FrameLoadedKnowdeIdString.indexOf(',' + pathArray[icount].getAttribute('kid') + ',') == -1)
            toLoadDivs += pathArray[icount].getAttribute('kid') + ',';
        }
      }
    }
    
  }
  
  
  return toLoadDivs;
}*/

function HelpFrameDivResize(_frameID)
{
  if(globalShowingWebDoc == false)
  {
    if(navigator.userAgent.indexOf('Safari') != -1)
    {
      var hc = document.getElementById('KGHelpControlID1');
      var row = document.getElementById('HelpControlContent');
      if(hc != null && row != null)
      {
        row.style.height = (hc.style.height.replace('px', '') - 45) + 'px'; //row.parentNode.clientHeight + 'px';
        row.style.width = (hc.style.width.replace('px', '') - 10) + 'px';//row.parentNode.clientWidth + 'px';
      }
    }
      
    /*m_textViewSpanResizeTimeOut = setTimeout('HandleTextViewSpanResize()', 1000); 
   
    if(_frameID == null)
      m_helpFrameScrollTimeOut = setTimeout('HandleHelpFrameScroll()', 1000);
    else
      m_helpFrameScrollTimeOut = setTimeout('HandleHelpFrameScroll("' + _frameID + '")', 1000);*/
  }
}

/*function  SwitchTextViewViewMode_Wrapped(_modeSwitchBtnID, _newMode)
{
  var modeSwitchBtn = document.getElementById(_modeSwitchBtnID);
  var dockedModeSwitchBtn = document.getElementById('DockedTextViewModeSwitch');
  if(_newMode == null)
  {
    if(m_currentTextViewViewMode == "Single")
    {
      // to full text view mode
      m_textViewViewModeChanged = true;
      m_currentTextViewViewMode = "Full";
      m_bHelpFrameLoadSiblingKnowde = false;
      // load full text view
      var currentKnowdeID = m_strFrameSelectedKnowdeID;
      SetSessionProperty('TickerKnowde', currentKnowdeID);
      m_tickerKnowdeID = currentKnowdeID;
      DisplayHintMessage("TextForSpecifiedKnowde"); 
      
      if(modeSwitchBtn != null)
      {
        modeSwitchBtn.className = "ToSingleTextView"; 
      }
      if(dockedModeSwitchBtn != null)
      {
        dockedModeSwitchBtn.className = "ToSingleTextView"; 
      }
    }else if(m_currentTextViewViewMode == "Full")
    {
      // to single text view mode
      //m_textViewViewModeChanged = true;
      m_currentTextViewViewMode = "Single";
      m_bHelpFrameLoadSiblingKnowde = false;
      
      // get the existing seletected knowd div
      var divHtml = '';
      var currentframe = document.getElementById("HelpFrame");
      if(currentframe != null)
      {
        var method = function(el){if(el.getAttribute('kid') == m_strFrameSelectedKnowdeID) return true; return false;};
        var frameDivs = YAHOO.util.Dom.getChildrenBy(currentframe.contentWindow.document.body,method);   
        if(frameDivs.length > 0)
        {
          var childDiv = frameDivs[0];
          divHtml = childDiv.innerHTML;
        }
      }

      // clear frame
      ClearHelpFrame(false);
      
      // set variables like we actually done a callback done
      m_strFrameViewMode = "Single";
      // m_strFrameSelectedKGID, m_strFrameSelectedKnowdeDBID, m_strFrameSelectedKnowdeID remain unchanged
      m_strFrameSelectedKnowdeContext = "";
      m_strFrameCentreKnowdeContext = "";
      
      // load single text view
      if(currentframe != null)
      {
          currentframe.contentWindow.document.write("<html><head><base target='_blank'><link href='CSS/KGHelpControl.css' type='text/css' rel='stylesheet'/><link href='CSS/TextViewDocument.css' type='text/css' rel='stylesheet'/></head><body class='PersonalisedScrollBar' style='overflow:scroll;'>");
          currentframe.contentWindow.document.write(divHtml);
          currentframe.contentWindow.document.write("</body></html>");
      }
      
      helpText = divHtml;
      
      // docked window
      //var dockedDivHtml = '';
      var dockedText = document.getElementById("DockedHelpWindow");
      if (dockedText != null)
      {
       
          dockedText.contentWindow.document.open();
          dockedText.contentWindow.document.write("");
          dockedText.contentWindow.document.close();

          dockedText.contentWindow.document.write("<html><head><base target='_blank'><link href='CSS/KGHelpControl.css' type='text/css' rel='stylesheet'/><link href='CSS/TextViewDocument.css' type='text/css' rel='stylesheet'/></head><body class='PersonalisedScrollBar' style='overflow:scroll;'>");
          dockedText.contentWindow.document.write(helpText);
          dockedText.contentWindow.document.write("</body></html>");
      }
          
      
      if(modeSwitchBtn != null)
      {
        modeSwitchBtn.className = "ToFullTextView"; 
      }
      if(dockedModeSwitchBtn != null)
      {
        dockedModeSwitchBtn.className = "ToFullTextView"; 
      }
    }
  }else
  {
    if(_newMode == "Full")
    {
      // to full text view mode
      m_currentTextViewViewMode = "Full";
      
      if(modeSwitchBtn != null)
      {
        modeSwitchBtn.className = "ToSingleTextView"; 
      }
      if(dockedModeSwitchBtn != null)
      {
        dockedModeSwitchBtn.className = "ToSingleTextView"; 
      }
    }else if(_newMode == "Single")
    {
      // to single text view mode
      m_currentTextViewViewMode = "Single";
      
      if(modeSwitchBtn != null)
      {
        modeSwitchBtn.className = "ToFullTextView"; 
      }
      if(dockedModeSwitchBtn != null)
      {
        dockedModeSwitchBtn.className = "ToFullTextView"; 
      }
    }
  }
}*/

/*function HideOrShowTextViewOptionDiv_Wrapped(_optionDivID, _showOption)
{
//debugger;
  var optionDiv = document.getElementById(_optionDivID);
  var dockedOptionDiv = document.getElementById('DockedHelpWindowTVOptions');
  m_HelpFrame = document.getElementById("HelpFrame");
  if(_showOption != null && _showOption == true)
  {
    if(optionDiv != null)
      optionDiv.style.display = 'block';
    
    if(dockedOptionDiv != null)
      dockedOptionDiv.style.display = 'block';
      
//    if(m_HelpFrame != null)
//      m_HelpFrame.style.height = '95%';

  }
  else
  {
    if(optionDiv != null)
      optionDiv.style.display = 'none';
      
    if(dockedOptionDiv != null)
      dockedOptionDiv.style.display = 'none';
      
//    if(m_HelpFrame != null)
//      m_HelpFrame.style.height = '100%';
  }
  
  //
  // ULTRA IMPORTANT: Showing the option div will resize the iframe.  When this happens, text corruption occurs
  // The below code will refresh the IFrame content.
  //if(!globalShowingWebDoc && document.frames)
     //setTimeout('document.frames[\'HelpFrame\'].location.reload(true)', 1000); 
}*/

/*function HideOrShowHelpControlLoadingDiv_Wrapped(_divId, _show, _message)
{
  if(m_helpFrameLoadingDivTimeOut != null)
  {
    clearTimeout(m_helpFrameLoadingDivTimeOut);
    m_helpFrameLoadingDivTimeOut = null;
  }
  
   var div = null; 
   
   if(_divId != null && _divId != '')
      div = document.getElementById(_divId);
   if(_message == null)
    _message = 'Loading...';
    
   if(_show != null && _show == true && m_helpFrameCallbackStatus != 'trigger')
   {
    // callback done has finished before the trigger time out to show the loading div, 
    // so don't need to show it anymore
    return;
   }
    
   if (div != null)
   {
    if(_show != null && _show == true && div.style.display != 'block')
    {
      var top = 60;
      var left = 172;
      
     // calculate the position based on the textView region
      var parentDiv = div.parentNode;
      
      //if(parentDiv.clientHeight != null && parentDiv.clientHeight != '' && parentDiv.clientHeight > 60)
        //top = 60;
          
      if(parentDiv.clientWidth != null && parentDiv.clientWidth != '' && parentDiv.clientWidth > 0)
        left = parentDiv.clientWidth/2 - 60;
        
      if(left <= 0)
        left = 0;
  
      div.innerHTML = "<img src='Images/LoadingBar.gif' width='21px' height='21px'/>&nbsp;" + _message;
      div.style.top = top + 'px';
      div.style.left = left + 'px';
      div.style.display = 'block';
    }else if(div.style.display != 'none')
    {
      div.style.display = 'none';
      div.innerHTML = '';
      div.style.top = '0px';
      div.style.left = '0px';
    }
   }
   
   // if docked window exists
   var docked = document.getElementById("DockedHelpWindowContainer")
   var dockedText = document.getElementById("DockedHelpWindow");
   if (dockedText != null)
   {
     var dockedLoadingDiv = document.getElementById('DockedHelpWindowLoadingDiv');
     if(dockedLoadingDiv != null)
     {
      if(_show != null && _show == true && dockedLoadingDiv.style.display != 'block')
      {
        var top = 60;
        var left = 50;
        
       // calculate the position based on the textView region
        var parentDiv = div.parentNode;
        
        if(parentDiv.clientWidth != null && parentDiv.clientWidth != '' && parentDiv.clientWidth > 0)
          left = parentDiv.clientWidth/2 - 60;
          
        if(left <= 0)
          left = 0;
    
        dockedLoadingDiv.innerHTML = "<img src='Images/LoadingBar.gif' width='21px' height='21px'/>&nbsp;" + _message;
        dockedLoadingDiv.style.top = top + 'px';
        dockedLoadingDiv.style.left = left + 'px';
        dockedLoadingDiv.style.display = 'block';
      }else if(dockedLoadingDiv.style.display != 'none')
      {
        dockedLoadingDiv.style.display = 'none';
        dockedLoadingDiv.innerHTML = '';
        dockedLoadingDiv.style.top = '0px';
        dockedLoadingDiv.style.left = '0px';
      }
     }
   }

}*/

/*function PreviewFullTextView()
{
  // hide the button
  KGButtonToolbar_hideOrShowPreviewFullTVButton(false);
  
  // set the view mode to full document
  SwitchTextViewViewMode("Full");

  DisplayHintMessage('TextView', '', 'true', Active_KGID);
    
  var MapHelpBox = document.getElementById("KGHelpControlID1");
  if(MapHelpBox != null)
    MapHelpBox.title = "Associated Text";  
}


function HelpFrameScrollTimeOut(_frameID)
{
  if(m_helpFrameScrollTimeOut != null)
  {
      clearTimeout(m_helpFrameScrollTimeOut);
      m_helpFrameScrollTimeOut =  null;
  }
  if(m_bHelpFrameManualScroll == true)
  {
    m_bHelpFrameManualScroll = false;
    return;
  }
  // if in full text view mode and has unloaded textviews, then trigger partial loading
  if(m_FrameUnLoadedKnowdeIdString != '' && globalShowingWebDoc == false && m_strFrameViewMode == "Full")
  {
    if(_frameID == null)
      m_helpFrameScrollTimeOut = setTimeout('HandleHelpFrameScroll()', 2000);
    else
      m_helpFrameScrollTimeOut = setTimeout('HandleHelpFrameScroll("' + _frameID + '")', 2000);
  }
}*/

/*function HandleHelpFrameScroll(_frameID)
{
  if(globalShowingWebDoc == true) //not text view
    return;
    
  //debugger;
  
  if(m_helpFrameScrollTimeOut != null)
  {
      clearTimeout(m_helpFrameScrollTimeOut);
      m_helpFrameScrollTimeOut =  null;
  }
  
    
  //debugger;
  var frameType = '';
  m_HelpFrame = document.getElementById("HelpFrame");
  var helpFrameDiv = null;
  m_DockedHelpFrame = document.getElementById("DockedHelpWindow");
  var dockedFrameDiv = null;
  
  // get frame info and decide which frame to do the partial loading
  var helpFrameWidth = -1;
  var dockedFrameWidth = -1;
  if(m_HelpFrame != null)
  {
    helpFrameDiv = m_HelpFrame.contentWindow.document.body;
    helpFrameWidth = m_HelpFrame.offsetWidth;;
  }
  if(m_DockedHelpFrame != null)
  {
    dockedFrameDiv = m_DockedHelpFrame.contentWindow.document.body;
    dockedFrameWidth = m_DockedHelpFrame.offsetWidth;
  }
  
  var frameDiv = null;
  var frame = null;
  if(_frameID != null && _frameID != '')
    frame = document.getElementById(_frameID);
    
  if(frame == null)
  {
    if(dockedFrameDiv != null && dockedFrameWidth != -1)
    {
      frameType = 'Docked';
      frameDiv = dockedFrameDiv;
      frame = m_DockedHelpFrame;
    }else if(helpFrameDiv != null && helpFrameWidth != -1)
    {
      frameType = 'Popup';
      frameDiv = helpFrameDiv;
      frame = m_HelpFrame;  
    }
  }else
  {
    frameDiv = frame.contentWindow.document.body;
  }
    
  if(frameDiv != null)
  {
    // clear the knowde hover scroll timeout because user now manually scrolling
    clearTimeout(m_helpFrameScrollMoreOnTopTimeOut);
    clearTimeout(m_dockedFrameScrollMoreOnTopTimeOut);

    var scrollTop = frameDiv.scrollTop;
    var visibleStartPosition = scrollTop;
    var visibleEndPosition = scrollTop + frame.offsetHeight;
    var centrePosition = visibleStartPosition + frame.offsetHeight/2;
    
    // also preload stuff that fall into 100px ouside the visible range
    if(visibleStartPosition - 60 <= 0)
      visibleStartPosition = 0
    else
      visibleStartPosition -= 60;
    
    if(visibleEndPosition + 60 >= frameDiv.scrollHeight + 30)
      visibleEndPosition = frameDiv.scrollHeight + 30
    else
      visibleEndPosition += 60;
        
    // check which divs are in visible area
    var visibleDivs = '';
    var toLoadDivs = '';
    var centreID = '';
    var centrePath = '';
      // might need to load top frame contents
      var pos = 0;
            
      
      for(var dividx = 0; dividx < frame.contentWindow.document.body.childNodes.length; dividx++)
      {
        var childDiv = frame.contentWindow.document.body.childNodes[dividx];
        
        if((childDiv.offsetHeight + childDiv.offsetTop >= visibleStartPosition && childDiv.offsetTop <= visibleEndPosition))
        {
          visibleDivs += childDiv.getAttribute('kid') + ',';
          if(childDiv.offsetTop <= centrePosition && childDiv.offsetTop + childDiv.offsetHeight >= centrePosition)
          {
            centreID = childDiv.getAttribute('kid');
            centrePath = childDiv.id;
          }else if(childDiv.offsetTop > centrePosition && centreID == '')
          {
            // the middle point fall into the gap between two divs, sometimes there is a 19px gap between
            centreID = childDiv.getAttribute('kid');
            centrePath = childDiv.id;
          }
          // check whether need to load this div
          if((m_FrameUnLoadedKnowdeIdString.indexOf(childDiv.getAttribute('kid')+',') == 0)
          || (m_FrameUnLoadedKnowdeIdString.indexOf(','+childDiv.getAttribute('kid')+',') != -1))
          {
            toLoadDivs += childDiv.getAttribute('kid') + ',';
          }
        }else if(centreID != '')
          break;
      }

    //alert(centreID + '|' + centrePath + '#' + visibleDivs);
    // store the centre knowde path context
    m_strFrameCentreKnowdeContext = centrePath;
    //alert('Center: ' + centrePath);
        
    if(toLoadDivs != '')
    {
      if(centreID == '' || centrePath == '')
      {
        alert('Invalid centre ID and Path.');
        //debugger;
      }
      else
      {
        m_bHelpFrameLoadSiblingKnowde = true;
        // trigger callback to partial load
        var args = "|KGId=" + m_strFrameSelectedKGID + '|KnowdeId=' + m_strFrameSelectedKnowdeID + '|KnowdePathContext=' + m_strFrameSelectedKnowdeContext + '|KnowdeTitle=|CentreKnowdePathContext=' + centrePath + '|KnowdeIdList=' + toLoadDivs;
        args += "|LoadSiblingKnowde=true";
        args += "|KnowdeLoaded=false";
        args += "|LoadTrigger=Scrolling";
        args += "|ViewMode=Full";
        
        if(m_helpFrameScrollTimeOut != null) // been scroll again
        {
            //clearTimeout(m_helpFrameScrollTimeOut);
            // m_helpFrameScrollTimeOut =  null;
        }else
          KGHelpControl_CallbackTrigger('TextView', args); //, globalHelpTopicParams); //We're no longer using the xml help
      }
    }
    
  }
}*/

/*function SwitchHelpControlMode(_editable)
{
  //debugger;
   
  // open in new window button
  var openWinBtn = document.getElementById("SiteOverlays_KGHelpControl1_OpenInNewWindowButton")
		
  if(_editable != null && _editable == true && globalShowingWebDoc == false)
  {
    // text view edit mode
    var row = document.getElementById('HelpControlContent');
    if(row != null && row.parentNode != null)
    {
      row.parentNode.style.display = 'none';
    }
    var rowt = document.getElementById('TextViewControlContent');
    if(rowt != null && rowt.parentNode != null)
    {
      rowt.parentNode.style.display = 'block';
      rowt.parentNode.style.height = '100%';
      rowt.style.display = 'block';
      rowt.style.height = '99%';
      
      if(navigator.userAgent.indexOf('Safari') != -1)
      {
        // need to assign fix height and width
        rowt.style.height = rowt.parentNode.clientHeight - 2 + 'px';
      }
    }
    
    if(openWinBtn != null)
		  openWinBtn.style.display = "none";
  }
  else
  {
    var rowt = document.getElementById('TextViewControlContent');
    if(rowt != null && rowt.parentNode != null)
    {
      rowt.parentNode.style.display = 'none';
    }
    var row = document.getElementById('HelpControlContent');
    if(row != null && row.parentNode != null)
    {
      row.parentNode.style.display = 'block';
      row.parentNode.style.height = '100%';
      row.style.display = 'block';
      row.style.height = '99%';
      
      if(navigator.userAgent.indexOf('Safari') != -1)
      {
        row.style.height = (row.parentNode.clientHeight - 10) + 'px';
        row.style.width = (row.parentNode.clientWidth - 10) + 'px';
      }
    }
    
    if(openWinBtn != null)
		  openWinBtn.style.display = "";

    
  }
}*/



