// body onload doesn't fire in non IE browsers, so the following window onload function is used instead
// (this one doesn't fire in IE...)
window.onload = function(){windowLoad();};
window.onresize = windowResize;  

// move from MapView.js to here in case the merged mapview js loaded too late
// for partial editing
var Map_TextEditOnly = 0;
// for multi verson text view
var Map_MultiVersionTextView = 0;
// allow other user to add whats to published KG
var AllowWhatEditOnly = 0;

var globalHideDockButton = false;
var Active_KGID = ""; // must be predefined
var MapViewJSLoaded = 0;

var mSignInControlDivId = "";
var mNewKGControlDivId = "";
var globalSplitterSetting = "single";
var globalFeaturedCategory;
var globalBubbleFullText = "";
var globalEditTimeOut = "";
var global_reloadApp = "true";
var _globalCookieTestResult = new Boolean(true);
var globalBrowserSessionSet = new Boolean(false);
var globalHideIndexedDocs = true;

var mvcCallbackTimeout;
var tabwinCallbackTimeout;

var m_catCookieExpiration = 8760; // cookie expiration date in hours from current time. 8760 = 1 year

// Delay MapView script loading, for performance purpose
if (!window.MapViewDefaultFocus)
{
    function MapViewDefaultFocus(){}; // will get written over when the Mapjs is loaded
}
if (!window.drawInitialMap)
{function drawInitialMap(){}; // will get written over when the Mapjs is loaded
}
if (!window.MapViewControl_ShowLoadingIcon)
{function MapViewControl_ShowLoadingIcon(){}; // will get written over when the Mapjs is loaded
}
if (!window.mouseupMain)
{function mouseupMain(){}; // will get written over when the Mapjs is loaded
}  
if (!window.MapViewControl_CallbackDone_Wrapped)// will get written over when the Mapjs is loaded, then timeout calls the right one
{
  function MapViewControl_CallbackDone_Wrapped(args)
  {
    // Check for a session time out before completing the callback
    if (CheckSessionTimeout())
      return;
    
    if (args != null)
      globalTempArgs=args;
    setTimeout("MapViewControl1_CallbackDone()",100); 
  }
}
// This next little bit of code tests whether the user accepts cookies.
var WM_acceptsCookies = false;
if(document.cookie == '') 
{
	document.cookie = 'WM_acceptsCookies=yes'; // Try to set a cookie.
  if(document.cookie.indexOf('WM_acceptsCookies=yes') != -1) 
  {
		WM_acceptsCookies = true; 
  }
} 
else 
{
  document.cookie = 'WM_acceptsCookies_test2=yes'; // Try to set a cookie.
  if(document.cookie.indexOf('WM_acceptsCookies_test2=yes') != -1) 
  {
		WM_acceptsCookies = true; 
  }
}

function WM_readCookie(name) 
{
	if(document.cookie == '') 
	{ 
		// there's no cookie, so go no further
		return false; 
  } 
  else 
  {
		// there is a cookie
		var firstChar, lastChar;
		var theBigCookie = document.cookie;
		firstChar = theBigCookie.indexOf(name);	// find the start of 'name'
		var NN2Hack = firstChar + name.length;
		if((firstChar != -1) && (theBigCookie.charAt(NN2Hack) == '=')) 
		{ 
			// if you found the cookie
	    firstChar += name.length + 1; // skip 'name' and '='
	    lastChar = theBigCookie.indexOf(';', firstChar); // Find the end of the value string (i.e. the next ';').
	    if(lastChar == -1)
				lastChar = theBigCookie.length;
				return unescape(theBigCookie.substring(firstChar, lastChar));
		} 
		else 
		{ 
			// If there was no cookie of that name, return false.
	    return false;
		}
	}	
}

// This next little bit of code tests whether the user accepts cookies.
var WM_sessionCookie = true;
if(WM_readCookie('WM_sessionCookie') != false) 
{
		WM_sessionCookie = false; 
} 
else 
{
	document.cookie = 'WM_sessionCookie=yes';
  WM_sessionCookie = true;
}

var m_bEditable = false;
var global_newKGCreated = false;
var global_newKGCreatedSplitViewSet = false;
var globalTempArgs = null;
var m_triggerMapCallbackOnload = false;
var m_triggerMapCallbackOnload_IsSet = false;
var m_mapViewCallBackWaitCount = 0;
var m_tabbedWindowCallBackWaitCount = 0;

var globalUpdateBubble = null;

function Set_triggerMapCallbackOnload(_value)
{
  m_triggerMapCallbackOnload_IsSet = true;
  //m_triggerMapCallbackOnload = _value;
  if (_value == "true" || _value == true)
		m_triggerMapCallbackOnload = true;
	else
		m_triggerMapCallbackOnload = false;

}

// walk around for the pending callback error //WebForm_CallbackComplete_SyncFixed
function WebForm_CallbackComplete_SyncFixed() {
     // the var statement ensure the variable is not global
     for (var i = 0; i < __pendingCallbacks.length; i++) {
        qcallbackObject = __pendingCallbacks[i];
        if (callbackObject && callbackObject.xmlRequest && (callbackObject.xmlRequest.readyState == 4)) {
            // SyncFixed: line move below // WebForm_ExecuteCallback(callbackObject);
            if (!__pendingCallbacks[i].async) { 
                __synchronousCallBackIndex = -1;
            }
            __pendingCallbacks[i] = null;
            var callbackFrameID = "__CALLBACKFRAME" + i;
            var xmlRequestFrame = document.getElementById(callbackFrameID);
            if (xmlRequestFrame) {
                xmlRequestFrame.parentNode.removeChild(xmlRequestFrame);
            }
            // SyncFixed: the following statement has been moved down from above;
            WebForm_ExecuteCallback(callbackObject);
        }
    }
}

// window load event handler
function windowLoad()
{
	try
	{
		detect();
		initialiseOverlays();
  }
  catch(e)
  {
		alert('windowLoad() error');
  }
}

var HCCResizeTimer;

// window resize event handler
function windowResize()
{
	try
	{
		// only attempt to adjust the height if the splitter exists
		if (window.Splitter1 && window.Splitter1.Panes)
		{
			// Adjust Splitter Heights
			if(PanesAreSplit())
			{
				setTimeout("DoExpandMapViewPane('split');", 110);
			}
			else
			{
				AdjustSplitterHeight();
				setTimeout('resetHeights()',100);
			}	
		}
		if (window.MapViewDefaultFocus)
			setTimeout('MapViewDefaultFocus()',105);
		if(window.TextViewDivResize)
			setTimeout('TextViewDivResize()',110);
		if(window.HandleTextTabResize)
			setTimeout('HandleTextTabResize()',115);
	  if(m_globalFullDocked  == true)
	    setTimeout('AdjustFullyDockedControlSize()',120);
		if(window.HelpFrameDivResize)
			setTimeout('HelpFrameDivResize()',130);
		if(window.HorizontalCategoriesControl_Resize)
			setTimeout("HorizontalCategoriesControl_Resize(null);", 100);
  }
  catch(e)
  {
  }
}

// shows the sign in and new kg overlays on page load (when needed)
function initialiseOverlays()
{
	if (mSignInControlDivId == "" && window.getSignInControlDivId)
	{
		// get the sign in control div ID
		mSignInControlDivId = getSignInControlDivId();
	}
	if (mNewKGControlDivId == "" && window.getNewKGControlDivId)
	{
		// get the newKG control div ID
		mNewKGControlDivId = getNewKGControlDivId();
	}

  var divSignIn = document.getElementById(mSignInControlDivId);

  if (divSignIn != null)
  {  
    if (divSignIn.attributes.getNamedItem("ShowOverlayOnPageLoad") != null)
    {
      // Toggle Login control if it needs to be shown, or if it is visible when it shouldn't be
      if ( (divSignIn.attributes.getNamedItem("ShowOverlayOnPageLoad").nodeValue == "true" && divSignIn.className == "OverlayPositionHidden")
          || (divSignIn.attributes.getNamedItem("ShowOverlayOnPageLoad").nodeValue == "false" && divSignIn.className == "OverlayPosition") )
      {
        var cookieLoginStatus = WM_readCookie("LoginStatus");

        if(cookieLoginStatus != null && cookieLoginStatus == "NotActivated")
        {
          var resendBtn = document.getElementById("SiteOverlays_LoginView1_KGSignInControl1_ResendBtn");
          if(resendBtn != null)
            resendBtn.className = "ShowResendButton";				      
        }

        wait("ToggleLoginControl();", 1000);
      }
    }
  }
}

var waitFunctionTimer="";

function wait(_exp2execute, _timeDelay)
{
    clearTimeout(waitFunctionTimer);

    if(__pendingCallbacks[0] == null)
    {
	    eval(_exp2execute);
    }
    else
    {
	    waitFunctionTimer = setTimeout("wait('" + _exp2execute + "'," + _timeDelay + ")", _timeDelay);
    }
}

function returnFromEditView()
{
	if(m_bEditable)
	{
		// if the user was in full view before they started editing, put it back to full view
		if (!WM_readCookie('SplitView'))
			SwitchToFullView();
	}
}

function detect()
{
  // Check for a session time out before completing the callback
  if (CheckSessionTimeout())
    return;
  
	_globalCookieTestResult = true;
	//	browser detect
	SetSessionProperty("Browser",navigator.appName);
	globalBrowserSessionSet = true;
	
	if(WM_acceptsCookies == false)
	{
		_globalCookieTestResult = false;
		if(document.getElementById("Splitter1") != null)
		{
			Splitter1.disabled = true;
			window.ComponentArt_Splitter_Loaded = false;
		}
		var BrowserDiv = document.createElement("span");
		var CookieContainerDiv = document.createElement("div");
		var CookieDiv = document.createElement("img");

		var width = screen.availWidth;
		var height = screen.availHeight;
		
		BrowserDiv.style.width = width;
		BrowserDiv.style.height = height;
		BrowserDiv.className = "BrowserDiv";
		
		CookieContainerDiv.style.width = width;
		CookieContainerDiv.style.height = height;
		CookieContainerDiv.className = "CookieContainerDiv";
		CookieContainerDiv.appendChild(CookieDiv);
		if (navigator.appName == "Microsoft Internet Explorer")
		{
			CookieDiv.src = "Images/HomePage/CookiesMsg.png";
			CookieDiv.className = "CookieDiv";
		}
		else
		{
			CookieDiv.src = "Images/HomePage/CookiesMsgNonIE.png";
			CookieDiv.className = "CookieDivNonIE";
		}
		
		var page = document.getElementById("Form1");
		page.appendChild(BrowserDiv);
		page.appendChild(CookieContainerDiv);
	}
	
	if(window.HorizontalCategoriesControl_Render)
	  setTimeout("HorizontalCategoriesControl_Render();", 200);
}

function setActiveStyleSheet(title) 
{
	var si, a, main;
	for(si=0; (a = document.getElementsByTagName("link")[si]); si++) 
	{
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) 
		{
			a.disabled = true;
			if(a.getAttribute("title") == title || a.getAttribute("title") == "default") 
			{
				a.disabled = false;
			}
		}
	}
}

// adjust the splitter fill height  
function AdjustSplitterHeight()
{
  // sets the height adjustment attribute on the splitter to the difference between the window height and the splitter height
  // find the top position of the splitter and add this to the heightAdjustment attribute
  var SplitterPos = findPosNoAdjust(document.getElementById('Splitter1'));
  Splitter1.HeightAdjustment = -(Splitter1.WindowHeight - Splitter1.AvailableHeight - SplitterPos[1]);
}

// Counts the number of times the short string _str appears in the _fullString
function countStringOccurances(_str, _fullString)
{
  var count = 0;
  
  while (_fullString.indexOf(_str) > -1)
  {
    _fullString = _fullString.replace(_str,"")
    count = count + 1;
  }
  
  return count;
}

function SetSessionProperty( _strPropertyName, _strValue, _multiKeyValues)
{
	try
	{
    var localTime = new Date();
    var utc = localTime.getTime() + (localTime.getTimezoneOffset() * 60000 );
    
    var queryStrings = _strPropertyName + '=' + _strValue;
    if(_multiKeyValues == true)
    {
      queryStrings = '';
      var keys = _strPropertyName.split('|');
      var values = _strValue.split('|');
      
      for(var qsidx = 0; qsidx < keys.length; qsidx++)
      {
        if(qsidx < values.length)
        {
          if(keys[qsidx].length > 0)
          {
            if(queryStrings.length > 0)
              queryStrings += '&';
            queryStrings += keys[qsidx] + '=' + values[qsidx];
          }
        }
      }
    }
    var sessionASHXUrl = strSessionPropertiesASHX + '?' + queryStrings + '&utc=' + utc;
    
    if (window.XMLHttpRequest) // Mozilla, Safari, IE7 ...
    {
      var req = new XMLHttpRequest();
      req.open('GET', sessionASHXUrl, false); // third param = asynchronous
      //req.onerror = function(){if (confirm('ssp error, debug?')) debugger;};
      //req.onabort = function(){if (confirm('ssp abort, debug?')) debugger;};
      //req.mozBackgroundRequest = true; // don't cancel it if the  window is closed (maybe for redirect also?)
      req.send(null);
    
      //check the error code that comes back to see if there is anything wrong. If there is then don't do anything
      if(req.status != 0) // 0 if url doesn't have http, 200 if it does
      {}
    }
    else
    {
      var xmlIsland = document.getElementById('HKSetSessionProperties_xmlIsland');
      if( typeof(xmlIsland) == 'object' && xmlIsland != null )
      {
        //set up so we're ready for the load. Including constructing the URL to use
        var dataIsland = xmlIsland.XMLDocument;
        dataIsland.async = false;
        //do the actual load
        dataIsland.load( sessionASHXUrl );
        //check the error code that comes back to see if there is anything wrong. If there is then don't do anything
        var error = dataIsland.parseError;
        if( error.errorCode == 0 )
        {}
      }
    }
  }
  catch(e)
  {
		//alert('SetSessionProperty() error:' + _strPropertyName + ', ' + _strValue);
		//debugger;
  }
}

var strSessionPropertiesASHX = 'ASHX/SessionProperties.ASHX';

function GetHtmlFromAshx(_url, _xmlIsland)
{
  var newHtml = '';
  if (window.XMLHttpRequest) // Mozilla, Safari, IE7 ...
  {
    var req = new XMLHttpRequest();
    req.open('GET', _url, false); // third param = asynchronous
    req.send(null);
    
    //check the error code that comes back to see if there is anything wrong. If there is then don't do anything
    if(req.status == 200)
      newHtml = req.responseText;
    else
      newHtml = 'error';
  }
  else // IE6
  {
    if (!_xmlIsland)
    {
      _xmlIsland = document.createElement("xml");
      _xmlIsland.id = "knowdeId1";
      _xmlIsland.innerHTML = "<span></span>";
      document.body.appendChild(_xmlIsland);
    }
    
   // PL08Dec06 - Added to solved a strange bug where, after a sequence of 
   // quick knowde clicks and floating overs, the XMLDocument attribute is not
   // created when the knowde is created. see Bug 716 
    if(_xmlIsland.XMLDocument == null)
    { 
      _xmlIsland.XMLDocument = new ActiveXObject("Microsoft.XMLDOM");
    }
 
    var dataIsland = _xmlIsland.XMLDocument;
    dataIsland.async = false;

    dataIsland.load(_url); 
  
    if (dataIsland.parseError.errorCode != 0)
      newHtml = 'error';
    else
      newHtml = dataIsland.xml;
  }
  
  return newHtml;
}
    
function LoadMapTabbedView()
{
	try
	{
	  setPaneSize();
		
		// show the more text tab
		/*var Tab = document.getElementById("TSC_moretext");
		var WidgetTab = document.getElementById("TSC1_moretext");
		if(Tab != null)
			ShowTab(Tab, WidgetTab);*/
		// For production 
		//importScript('MapViewMinified.js');
		importScript('MapViewControl.js');
		importScript('MapEditing.js');
		
		SrmControl_RecordTimes(0);
	  
		var srmIndex = SrmControl_SetInitial('InitialCallbackToKGTabbedWindows');
	  
	  if (m_triggerMapCallbackOnload == false)
	  {
	    if (isAuthenticated() == true)
			{
  			var userID = WM_readCookie('UserID');
				var category = WM_readCookie('User' + userID + '_category');
	    }
	  }
	  var splitter = document.getElementById("Splitter1_pane_0");
		if (global_newKGCreated == true)
		{
			global_newKGCreated = false;
			global_newKGCreatedSplitViewSet = true;
			SwitchToSplitView(false, true); //don't set the cookie 
		}
		else if (m_triggerMapCallbackOnload == true)
		{
			//if the pane is expanded and the map view is not editable, trigger map view callback
			if (m_bEditable == false && splitter.clientHeight > 0)
			{
				setTimeout('MapViewControl1_CallbackTrigger()',1); // timeout for importScript
				globalMapViewControlLoaded = true;
			}
		}
		else if (m_triggerMapCallbackOnload_IsSet == false)
		{
		  if (m_bEditable == false && splitter.clientHeight > 0)
		  {
        m_mapViewCallBackWaitCount = 0;
		    mvcCallbackTimeout = setTimeout('TriggerMapViewCallBackTimeOut()',500);
		  } 
		}
		//ProceedWithTour();
	}
  catch(e)
  {
		alert('LoadMapTabbedView() error');
  }
}

function TriggerMapViewCallBackTimeOut()
{
  if(m_triggerMapCallbackOnload == true)
  {
    m_mapViewCallBackWaitCount = 0;
	  MapViewControl1_CallbackTrigger();
	}
	else if (m_triggerMapCallbackOnload_IsSet == false && m_mapViewCallBackWaitCount < 120)
	{
	   // wait again
	   m_mapViewCallBackWaitCount++;
	   clearTimeout(mvcCallbackTimeout);
		 mvcCallbackTimeout = setTimeout('TriggerMapViewCallBackTimeOut()',500); 
	}else if(m_triggerMapCallbackOnload_IsSet == false && m_mapViewCallBackWaitCount >= 120)
	{
	  //alert('m_triggerMapCallbackOnload still havenot been set yet [' + m_mapViewCallBackWaitCount + ' attemps], no mapview will be loaded.');
	  m_mapViewCallBackWaitCount = 0;
	}
}

function TriggerTabbedWindowCallBackTimeOut()
{
  /*if(m_triggerMapCallbackOnload_IsSet == true)
  {
    m_tabbedWindowCallBackWaitCount = 0;
    if(m_triggerMapCallbackOnload == false)
    {
	    KGTabbedWindowsControl_CallbackTrigger('TabSelected');
	    globalHideIndexedDocs = false;
	  }
	}
	else if (m_triggerMapCallbackOnload_IsSet == false && m_tabbedWindowCallBackWaitCount < 120)
	{
	   // wait again
	   m_tabbedWindowCallBackWaitCount++;
	   clearTimeout(tabwinCallbackTimeout);
		 tabwinCallbackTimeout = setTimeout('TriggerTabbedWindowCallBackTimeOut()',500); 
	}else if(m_triggerMapCallbackOnload_IsSet == false && m_tabbedWindowCallBackWaitCount >= 120)
	{
	  //alert('m_triggerMapCallbackOnload still havenot been set yet [' + m_tabbedWindowCallBackWaitCount + ' attemps], no tabbedwindow callback will be performed.');
	  m_tabbedWindowCallBackWaitCount = 0;
	}*/
}

function findPos(obj) 
{
  var curleft = curtop = 0;
  if (obj.offsetParent) 
  {
	  curleft = obj.offsetLeft
	  curtop = obj.offsetTop
	  while (obj = obj.offsetParent) 
	  {
		  if (obj.id == 'scrolling-section' || obj.id == 'moving-section') // don't want to offset for the HorizontalCategoriesControl outside the splitter
	    {
	      curleft += obj.offsetLeft
	      //curtop -= obj.offsetTop ;
	    }
  	  
	    if (obj.id != 'Splitter1' && obj.id.indexOf('Splitter1') == -1 && obj.id != 'MapContainer' && obj.id != 'scrolling-section' && obj.id != 'moving-section') // don't want to offset for the HorizontalCategoriesControl outside the splitter
	    {
	      curleft += obj.offsetLeft
	      curtop += obj.offsetTop
	    }
	  }
  }
  return [curleft,curtop];
}

function findPosNoAdjust(obj) 
{
  var curleft = curtop = 0;
  if (obj.offsetParent) 
  {
	  curleft = obj.offsetLeft
	  curtop = obj.offsetTop
	  while (obj = obj.offsetParent) 
	  {
	    curleft += obj.offsetLeft
	    curtop += obj.offsetTop
	  }
  }
  return [curleft,curtop];
}

var m_MapHelpBox = null;
var globalHelpTopicKey = null;
var globalHelpTopicParams = null;
var helpWindowTopicKey = null;
var m_Bubble = null;
var globalLastBubbleAction = null;  
//This is also declared in a script at the bottom of home.aspx so for that page it can be assigned any existing session variable.  JPC.

////////////////////////////////////
// Handle's the HelpLink_Clicked event
function HelpLinkClicked(_undock, _firstLoadHelp, e)
{
	try
	{
	  var HelpControl_Callback = false;
    // if we are going to check the visibility of the help control before updating we need to set it up here ready to receive the objective help if necessary
    m_MapHelpBox = document.getElementById("KGHelpControlID1");
    
    if(!globalShowingWebDoc && document.frames)
      document.frames['HelpFrame'].location.reload(true);
    
    //If the control exists on the page
    if (m_MapHelpBox != null)
    {
      // Populate the box   
      //m_bHelpFrameLoadSiblingKnowde = false; 
      var params = GetHelpWindowCallBackArgs();  
      KGHelpControl_CallbackTrigger(globalHelpTopicKey, globalHelpTopicParams + params);
      HelpControl_Callback = true;
      
      // see whether we need to hide the dock button
      var hideDockButton = false;
      if(m_bEditable == true)
        hideDockButton = true;
 
      //if(_undock == true)
      OpenHelpControl(hideDockButton);
      //else
        //DockInPageKGHelpControl();
      
	
			// find x & y coords of all drop lists - hide list if there is an overlay.
			if(navigator.appVersion.match("MSIE 7.0") != "MSIE 7.0" && navigator.appName == "Microsoft Internet Explorer")
			{
				if(m_MapHelpBox.className != "OverlayPositionHidden")
				{
					// find elements x & y coords
					var elemCoords = findElementCoords(m_MapHelpBox);
					var elemCoordsAndWidth = m_MapHelpBox.clientWidth + elemCoords[0];
					var elemCoordsAndHeight = m_MapHelpBox.clientHeight + elemCoords[1];
				}
				// retrieve and hide all droplists.
				var droplist = document.getElementsByTagName("SELECT");
				for(var num=0;num<droplist.length;num++)
				{
					//only hide the visible boxes
					if(droplist[num].className == "list_dropList")
					{
						var dropCoords = findElementCoords(droplist[num])
						var dropCoordsAndWidth = droplist[num].clientWidth + dropCoords[0];
						var dropCoordsAndHeight = droplist[num].clientHeight + dropCoords[1];
						
						if((dropCoords[0] >= elemCoords[0] || dropCoordsAndWidth >= elemCoords[0]) && (dropCoords[0] <= elemCoordsAndWidth || dropCoordsAndWidth <= elemCoordsAndWidth))
						{
							//overlays in the x-range
							if((dropCoords[1] >= elemCoords[1] || dropCoordsAndHeight >= elemCoords[1]) && (dropCoords[1] <= elemCoordsAndHeight || dropCoordsAndHeight <= elemCoordsAndHeight))
							{
								//overlays in the x & y ranges
								droplist[num].style.display = "none";
							}
						}
					}
				}
			}
		
			//check to see if it is the first load 'Help'... if so - reposition & grey the background
			if(_firstLoadHelp)
			{
				m_MapHelpBox = document.getElementById("KGHelpControlID1");
				m_MapHelpBox.style.top = screen.height/5;
				m_MapHelpBox.style.height = screen.height/2;
				m_MapHelpBox.style.left = "30%";
				m_MapHelpBox.style.width = "45%";
				
				var GreyDiv = document.createElement("span");
				
				var width = screen.availWidth;
				var height = screen.availHeight;
				
				GreyDiv.style.width = width;
				GreyDiv.style.height = height;
				GreyDiv.className = "GreyDiv";
				GreyDiv.id = "GreyDiv";
				
				document.getElementById("miniGlobe").className = "firstLoadLogo";
				document.getElementById("m_cookieDiv").className = "m_cookieDiv";
				
				var page = document.getElementById("Form1");
				page.appendChild(GreyDiv);
			}
			else
			{
				m_MapHelpBox.style.top = screen.height/4;//"30%"; //screen.height/3;
				m_MapHelpBox.style.height = screen.height/2;
				
				// in Firefox maintain the previous resize size, otherwise the inner table will go out of place
			  if(resizeInnerEl == null)
			  {
				  m_MapHelpBox.style.left = "5%";
				  m_MapHelpBox.style.width = "45%";
        }
				
			  /*if(resizeInnerEl != null)
        {
          resizeInnerEl.width = '100%';
          resizeInnerEl.height = '100%';
        }*/
			}
      
      // If the box has scrollbars we need to move the buttons into place so they're not hidden.
      if (m_MapHelpBox.clientHeight < m_MapHelpBox.scrollHeight || m_MapHelpBox.clientWidth < m_MapHelpBox.scrollWidth)
      {
        var resizeButton = document.getElementById("ResizeButton");
        
        if (m_MapHelpBox.clientHeight < m_MapHelpBox.scrollHeight)  //There's a vertical scrollbar
        {
          if (resizeButton != null)
            resizeButton.style.bottom = "2px";    
        }
        if (m_MapHelpBox.clientWidth < m_MapHelpBox.scrollWidth)  //There's a horizontal scrollbar
        { 
          if (resizeButton != null)
            resizeButton.style.right = "2px";
            
          var closeButton;
          var method = function(el){if(el.id == "CloseButton_Div_ID") return true; return false;};
          var result = YAHOO.util.Dom.getElementsBy(method,null,m_MapHelpBox);
          closeButton = result[0];
          if (closeButton != null)
            closeButton.style.right = "2px";
        }  //end adjust for width
      } // end check for scrollbars
    }
    CancelBubble(e);
    
    return HelpControl_Callback;
	}
	catch(e)
	{
		alert('HelpLinkClicked() error');
	}
}

// return x and y coords
function findElementCoords(obj) 
{
	var curleft = curtop = 0;
	if (obj.offsetParent) 
	{
		curleft = obj.offsetLeft;
		curtop = obj.offsetTop;
		while (obj = obj.offsetParent) 
		{
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop - obj.scrollTop;
		}
	}
	return [curleft,curtop];
}

// return x and y coords
function findBRElementCoords(obj) 
{
	var curleft = curtop = 0;
	if (obj.offsetParent) 
	{
		curleft = obj.offsetLeft + obj.offsetWidth;
		curtop = obj.offsetTop + obj.offsetHeight;
		while (obj = obj.offsetParent) 
		{
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop - obj.scrollTop;
		}
	}
	return [curleft,curtop];
}

////////////////////////////////////
// Displays a message in the hint box
// _message: the message to be displayed, taken from the vars defined in MapHints.js
function DisplayHintMessage(_message, _params, _openText, _kgId)
{
  // Test if the help box is visible
  // YES: Set the global variable for HelpTopicKey 
  //      Do Callback Trigger to update the Help Box
  //  NO: Set the global variable for HelpTopicKey only
  if( _message == "Help")
  {
		if(m_Bubble == null)
			m_Bubble = document.getElementById("KGBubbleControl1");
	        
		if(m_Bubble != null)
		{
			if (_message == "TextView")
				KGBubbleControl_CallbackTrigger("KnowdeSelected");
			if (_message == "TextForSpecifiedKnowde")
				KGBubbleControl_CallbackTrigger("TextForSpecifiedKnowde");
			if (_message == "Help")
				KGBubbleControl_CallbackTrigger('');  // cause Bubble to look up session variable
		}
		return;
  }
  
  if (!(_message == "TextView" ||  _message=="TextForSpecifiedKnowde" || _message.indexOf('ReloadTextView') != -1))
    return;//We're no longer using the xml help

  //debugger;
  /*globalHelpTopicKey = _message;
  //globalHelpTopicParams = _params;  //We're no longer using the xml help

  if (helpWindowTopicKey != "TextView" || _message=="TextForSpecifiedKnowde" || _message.indexOf('ReloadTextView') != -1)
    helpWindowTopicKey = _message;
  
  if(m_MapHelpBox == null)
    m_MapHelpBox = document.getElementById("KGHelpControlID1");
  
  var HelpControl_Callback = false;
  if(_openText == 'true')
  {
    //  by default 
    HelpControl_Callback = HelpLinkClicked();
    //DockInPageKGHelpControl();
    //document.getElementById(_kgId).innerHTML = "Now showing the Map and document";
  }
  
  if(_message.indexOf('ReloadTextView') != -1)
  {
    SwitchTextTabControlMode(true);
    SwitchTextViewViewMode("Single");
  }
  else
    SwitchTextTabControlMode(false);

  if(!HelpControl_Callback &&
  (((m_MapHelpBox != null && m_MapHelpBox.className == "OverlayPosition") || document.getElementById("DockedHelpWindow") !=null) 
    && (globalHelpTopicKey == "TextView" || globalHelpTopicKey == "TextForSpecifiedKnowde" || globalHelpTopicKey.indexOf("ReloadTextView") != -1)))
{
    m_bHelpFrameLoadSiblingKnowde = false;
     var kgid = Active_KGID;
    if(_kgId != null && _kgId > 0)
      kgid = _kgId;
    var params = '';
    if(_message=="TextForSpecifiedKnowde" || _message == "TextView")
    {
      if(m_textViewViewModeChanged == false && m_currentTextViewViewMode == "Full" && m_strFrameSelectedKGID != '' && m_strFrameSelectedKGID == kgid )
        //&& ((m_strFrameSelectedKnowdeID != '' && m_strFrameSelectedKnowdeID == m_tickerKnowdeID) || (m_strFrameSelectedKnowdeDBID != '' && m_strFrameSelectedKnowdeDBID == m_tickerKnowdeID)))
      {
        m_bHelpFrameLoadSiblingKnowde = true;
      }
      
      if(m_tickerKnowdeID != '')
      {
        var kndPathContext = FindSelectedHelpFrameKnowdePathContext(m_tickerKnowdeID);
        var knowdeChanged = ChangeSelectedHelpFrameKnowde(m_tickerKnowdeID, kndPathContext);  
      }
      ///debugger;
      params = GetHelpWindowCallBackArgs(_kgId);
    }
    
     // No point in reloading the text if its already being displayed!
     if(_message.indexOf('ReloadTextView') != -1 || (m_tickerKnowdeID != Active_KnowdeID_Text || m_currentTextViewViewMode == 'Full'))
     {
        KGHelpControl_CallbackTrigger(helpWindowTopicKey, params); //, globalHelpTopicParams); //We're no longer using the xml help
     }
     
   }    
   
  if(HelpControl_Callback == false)
  {
    globalLastTickerAction = "";
  }
   
  // reset the value 
  m_textViewViewModeChanged = false;
  
  //debugger;
  if(globalHideDockButton == true || m_bEditable == true) //globalSplitterSetting == "single" || 
	{
		// hide dock in window option
		var dockInPage = document.getElementById("SiteOverlays_KGHelpControl1_DockInPageButton")
		
		if(dockInPage != null)
		  dockInPage.style.display = "none";
		  
		if(_message == "TextForSpecifiedKnowde")  
		  globalHideDockButton = false;
		
	}
	else 
	{
		// show dock in window option
		document.getElementById("SiteOverlays_KGHelpControl1_DockInPageButton").style.display = "";
	}
	*/
}

function EvalRegisterJavaScripts(javaScripts)
{
  // does the same as RegisterClientScriptBlock at the server, 
  // required because RegisterClientScriptBlock doesn't work in callbacks
  // use this instead of just eval(javaScripts) to give functions global scope
  
  // first split by 'function ' to separate each function
  //   make sure 'function ' isn't written in javaScripts in unusual places, e.g. as a comment/variable
  //   for startup scripts, add 'function ' to the start, so 'function <script>$scriptText$</script>
  
  // start with function $functionName$($parameters$){$functionText$}
  // change to $functionName$ = function($parameters$){$functionText$}
  // using var functionScript = ($parameters$){$functionText$}
  
  // also for start up scripts <script>$scriptText$</script>
  // just eval $scriptText$
  
  var functions = javaScripts.split('function ');
  for (var y = 1; y < functions.length; y++) // start from 1 - functions[0] = '' from the split
  {
    var functiony = functions[y];
    var posScript = functiony.indexOf('<script');
    if (posScript > -1) //Startup script
    {
      var scripts = functiony.split('<script'); // there can be more than one script block
      for (var x = 1; x < scripts.length; x++)
      {
        var scriptx = scripts[x];
        var posStart = scriptx.indexOf('>') + 1;
        var posEnd = scriptx.indexOf('</script>');
        scriptx = scriptx.substring(posStart,posEnd); // lose the start and end <script> tags
        scriptx = scriptx.replace(/var/g,''); //global replace of var to give variables defined here global scope
        eval(scriptx);
      }
    }
    else
    {
      var pos1 = functiony.indexOf('(');
      if (pos1 > 0)
      {
        var functionName = functiony.substring(0,pos1);
        {
          var functionScript = functiony.substring(pos1);
          var newFunction = functionName + '= function' + functionScript;
          eval(newFunction);
        }
      }
      else
        alert('Failed to add function: ' + functiony);
    }
  }
}

function isAuthenticated()
{
  var c_name = 'SignedIn';
  
  // Test if the cookie has been set during the sign in process
  // YES: User has already signed in 
  //  NO: User has not been signed in or does not have an account
  if(document.cookie.length > 0)
  {
    var cookie_content = WM_readCookie(c_name);
    
    if(cookie_content != null && cookie_content.length > 0)
    {
      return true;
    }
    else
    {
      return false; 
    }
  }
  else
    return false;
}

function redirectToSignInSignUpPage(_actionToken, _objectId, _knowdeID)
{
  var returnURL;
  //debugger;
  if(_actionToken.toLowerCase().indexOf('kgid=') == 0)
  {
    // redirect back to Home page and preload the map
    UpdateTour(4);
    returnURL = "home.aspx?" + _actionToken.toLowerCase();
  }
  else
  {
    switch(_actionToken)
    {
      case "AddToMyHK":
        // New format on the return URL parameter
        // action: the action the user is trying to carry out 
        // p: parameters in this format: <CategoryID>.<KGID>
        
        var categoryControlMenu = eval(HorizontalCategoriesControl_getMenuID());
        
        var categoryID = categoryControlMenu.SelectedItem.ID;
        var kgId       = _objectId;

        //remove any existing query string first
        var loc = getNoQueryStringLocation();
          
        returnURL = escape(loc + "?kgid="+kgId+"&action=addToMyHK&p="+categoryID+"."+kgId);
        break;
      case "AddPrivateSpace":
        returnURL = escape(window.location.toString());
        break;
      case "CreateNewKG":
        returnURL = "home.aspx?action=CreateNewKg";
        break;
      case "AddCommunityLink":
        var kgId = _objectId;
        var knowdeId = _knowdeID;
        
        var loc = getNoQueryStringLocation();
        
        returnURL = escape(loc + "?kgid="+kgId+"&knowde="+knowdeId+"&t=communities");
        break;
      default:
        returnURL = escape(window.location.toString());
        break;
    }
  }
  
  // Save the current URL on Session for returning to
  SetSessionProperty("ReturnURL", returnURL);
  
  // Redirect the user to the Sign In / Sign Up Page 
   var currentLocation = window.location.href;
   var hostURL = currentLocation.substring(0, currentLocation.lastIndexOf('/') + 1);
   window.location = hostURL + "SignInSignUp.aspx";
}

function getNoQueryStringLocation()
{
  var loc = window.location.toString();
  if (loc.indexOf('?') > -1)
    loc = loc.substring(0,loc.indexOf('?'));
  return loc;
}

function processRedirection()
{
  var rawQueryString = window.location.search.substring(1);
  
  if(rawQueryString.length > 0)
  {
    var queryStrings = rawQueryString.split("&");
           
    var actionName = queryStrings[0].split("=")[0];
    var actionValue = queryStrings[0].split("=")[1];
    
    if(actionName == "action")
    {
      switch(actionValue)
      {
        case "addToMyHK":
          var locatorParams = queryStrings[1].split(".");
          
          // This is to allow for the "p=" sequence and need to remove that 
          // from the categoryID
          var categoryID = locatorParams[0].split("=")[1];
          var pageNumber = locatorParams[1];
          var ownerKey   = locatorParams[2];
          var kgId       = locatorParams[3];
          
          LoadMapTabbedView();
          initialiseOverlays();
					//globalUpdateBubble = 'Home Page Load';
          break;
        default:
          LoadMapTabbedView(); 
          initialiseOverlays();
         // globalUpdateBubble = 'Home Page Load';
          break;
      }
    }
    else
    {
      LoadMapTabbedView(); 
      initialiseOverlays(); 
      //globalUpdateBubble = 'Home Page Load';
    }
  }
  else
  {
    LoadMapTabbedView();
    initialiseOverlays();
    //globalUpdateBubble = 'Home Page Load';
  }
}

function HomeLinkClicked()
{
	if(isAuthenticated())
	{
		SetSessionForHomeClick();
	  
		SetSessionProperty('Home_Link_Clicked', 'true');
	  
		//if (window.KGTabbedWindowsControl_SelectTabById)
		//	KGTabbedWindowsControl_SelectTabById('Indexed Documents');
	  
		// new default map will be load, clear old session
		SetSessionProperty('SelectedKnowdeSiblingInfo', '');	
	  
		WM_killCookie('category');
	  
	  
	    
	    var currentLocation = window.location.href;
        var hostURL;
        var currentPage;
        
        if(currentLocation.indexOf("orderSuccessful") > 0)
        {
          currentPage = currentLocation.substring(currentLocation.indexOf("orderSuccessful"));
          hostURL = currentLocation.substring(0, currentLocation.indexOf("orderSuccessful"));
        }
        else if (currentLocation.indexOf("orderFailed") > 0)
        {
          currentPage = currentLocation.substring(currentLocation.indexOf("orderFailed"));
          hostURL = currentLocation.substring(0, currentLocation.indexOf("orderFailed"));
        }
        else
        {
		    //var currentLocation = window.location.href;
		    currentPage = currentLocation.substring(currentLocation.lastIndexOf('/')+1, currentLocation.length).toLowerCase();
		    hostURL = currentLocation.substring(0, currentLocation.lastIndexOf('/') + 1);		    
        }
        window.location = hostURL + 'home.aspx';
  }
  else
  {
		SetSessionForHomeClick();
		var currentLocation = window.location.href;
		var currentPage = currentLocation.substring(currentLocation.lastIndexOf('/')+1, currentLocation.length).toLowerCase();
		var hostURL = currentLocation.substring(0, currentLocation.lastIndexOf('/') + 1);
		window.location = hostURL + 'Welcome.aspx';
  }
}

function SetSessionForHomeClick()
{
  var keys = 'KG_RedirectFrom|Topics_SelectedTopicName|Topics_SelectedTopicGroupId|GenesTabMode|GenesSearch_PhraseName|CurrentKnowdeIDForTab|WebTabMode|WebSearch_PhraseName|Topics_HomeJustClicked|IndexedDocListMode|KGMapViewCollapsed';
	var values = 'HomeLinkClicked|null|-1||||||true|MyHyperknowledge|false';
  SetSessionProperty(keys, values, true);

}

function PageRedirect(page)
{
	var currentLocation = window.location.href;
	var hostURL = currentLocation.substring(0, currentLocation.lastIndexOf('/') + 1);
	window.location = hostURL + page;
}

function UpdateBubble(action)
{ 
  globalUpdateBubble = null;
  if (action == 'Load TextView' && globalLastBubbleAction == 'Add Objective')
    return;
  
  if (action == 'Home Page Load' && globalLastBubbleAction == 'View Indexed Docs')
    return; //Don't want the page load to overwrite the Bubble
  
  if (action == 'Hover Map' && m_IsEditFromNewKnowde == true)
    return;
        
  if (action == 'Home Page Load')
  {   
    if (isAuthenticated() == true)
        action = 'Load Home In';
    else
        action = 'Load Home Out';
  }   
  
  if (action == 'Search Click')
  {
    if (isAuthenticated() == true)
        action = 'Search In';
    else
        action = 'Search Out';
  }
  
  if (action == 'Suggestions Open')
  {
    if (isAuthenticated() == true)
        action = 'Suggestion In';
    else
        action = 'Suggestion Out';
  }
  
  // Bubble control trigger 
  SetSessionProperty('TickerAction', action);
  globalLastBubbleAction = action;
  
  var authorBubble = document.getElementById("AuthorTour1");
	if(authorBubble != null)
	{
		if(authorBubble.style.display == "block")
		{
			if(action != "Objective Hover" && action != "How Hover" && action != "Why Hover" && action != "AddChildBoxHow Hover" && action != "AddChildBoxWhy Hover")
				DisplayHintMessage("Help");
		}
		else
		{
			DisplayHintMessage("Help");
		}
	}
	else
	{
		DisplayHintMessage("Help");
  }
}

function highlight_Link(e)
{
  if (!e) var e = window.event;
	var targ = e.target || e.srcElement;
	targ.style.color = "black";
	targ.style.textDecoration = "underline";
}

function unhighlight_Link(e, _color)
{
  if (!e) var e = window.event;
	var targ = e.target || e.srcElement;
	if(_color != 'false')
		targ.style.color = ""; //back to css default
	targ.style.textDecoration = "";
}

var globalHoverUpdateTimerDelay = 400;
var HoverTimerForBubble = null

function setUpBubble()
{
	// just for the cookies stuff
	if(WM_readCookie('TourBubble') == false)
	{
		WM_setCookie('TourBubble','on');
		ShowTourBubble();
	}
	else if(WM_readCookie('TourBubble') == "off")
	{
		HideTourBubble();
	}
	else if(WM_readCookie('TourBubble') == "on")
	{
		ShowTourBubble();
	}

  if (window.HideBubble)
    HideBubbleContainer();
}

// bubble code is for db to know what text to display
// e is the event or the element (element in _editoverride == true case)
// _editoverride is for map editing (slightly diff rules apply)
function bubbleMouseOver(e, _bubbleCode, _editOverride)
{	
	if(!window.HideBubble)
	  return;
	
	var Bubble = document.getElementById("KGBubbleControl1_HelpBubble");
  if(Bubble)
  {
		if(_bubbleCode != "How Hover" && _bubbleCode != "Why Hover")
			HideBubble('true');
		//browser type - for altered positioning
	  var ie = 'true'; 
	  if (navigator.appName != "Microsoft Internet Explorer")
		  ie = 'false';
		  
	  // if help is switched off... dont process.
	  var performBubble = document.getElementById("KGBubbleControl1_BubbleVisibilityContainer");
	  if(performBubble)
	  {
		  if(performBubble.style.display == "none")
		  {
				// dont process
			  return;
		  }
		  else
			{
				// if on, we need some logic for the tour / help combination. Hopefully only a temp sln.
				var authorBubble = document.getElementById("AuthorTour1");
				if(authorBubble != null)
				{
					if(_bubbleCode != null && _bubbleCode != "Add Objective" && _bubbleCode != "How Hover" && _bubbleCode != "Why Hover")
					{
						authorBubble.style.display = "none";
						if(_bubbleCode == "HideAuthor")
						{
							return;
						}
					}
				}
			} 
		}
		// some variables used for specific cases. 
		// Lots of different positioning types.
	  var force;
	  var targElement;
	  if (_editOverride == 'true')
		  targElement = e;
	  else
		  targElement = e.target||e.srcElement;
	  // find coordinates here...
	  var TopLeftPositionArray = findElementCoords(targElement);
	  var BottomRightPositionArray = findBRElementCoords(targElement);
	  var suggBox = "";
	  var borderOffset = 'false';
	  var autoScrollOffset = 'false';
	  if(ie == 'false')
	  {
		  //alternate browser precise positioning
		  if(_editOverride != 'true')
		  {
				switch(_bubbleCode)
				{
					// special cases that require specific coordinate adjustments
					case "Hover Search Item":
						suggBox = document.getElementById("KGSuggestionControl_Div_ID");
						TopLeftPositionArray[0] = suggBox.offsetLeft;
						TopLeftPositionArray[1] = e.clientY;
						BottomRightPositionArray[0] = suggBox.offsetLeft;
						BottomRightPositionArray[1] = e.clientY;	
						break
					case "Semantic Tree Hover":
						TopLeftPositionArray[0] = 250;
						TopLeftPositionArray[1] = 250;
						BottomRightPositionArray[0] = 250;
						BottomRightPositionArray[1] = 250;	
						break
					default:
						// for non-ie browsers... bubble appears at cursor
						TopLeftPositionArray[0] = e.clientX;
						TopLeftPositionArray[1] = e.clientY;
						BottomRightPositionArray[0] = e.clientX;
						BottomRightPositionArray[1] = e.clientY;	
						break;
				}
		  }
	  }
	  
	  // the text boxes on a knowde in edit
	  // some bubble in help wont appear when editing a knowde due to wanting the author bubble up.
	  var editBoxCheck = document.getElementById("MapViewTextBox");
	  
	  // update bubble will callback into the bubble code with correct action.
	  switch(_bubbleCode)
	  {
			// each case handles a different bubble event
			// there are coordinate / positioning adjustments for individual bubbles
		  case "Bookmark Hover":
			  if(ie == 'true')
			  {
				  borderOffset = 'true';
			  }
			  //stop the bubble from covering the menu by pushing it left to the refer icon
			  if (window.BookmarkingControl_GetBkmkText)
			  {
			    var topBkmkText = BookmarkingControl_GetBkmkText();
			    if (topBkmkText)
			    {
			      TopLeftPositionArray = findElementCoords(topBkmkText);
			      TopLeftPositionArray[1] = 50;
	          BottomRightPositionArray = findBRElementCoords(topBkmkText);
	          BottomRightPositionArray[1] = 72;
	          force = 'tr';
			    }
			  }
			  HoverTimerForBubble = setTimeout("UpdateBubble('Bookmark Hover')",globalHoverUpdateTimerDelay);
			  break;
		  case "Referral Hover":
			  if(ie == 'true')
			  {
				  borderOffset = 'true';
			  }
			  //stop the bubble from covering the menu by pushing it left to the bookmark text
			  if (window.BookmarkingControl_GetReferText)
			  {
			    var topReferText = BookmarkingControl_GetReferText();
			    if (topReferText)
			    {
			      var referHolder = topReferText.parentNode;
			      TopLeftPositionArray = findElementCoords(referHolder);
			      TopLeftPositionArray[1] = 50;
	          BottomRightPositionArray = findBRElementCoords(referHolder);
	          BottomRightPositionArray[1] = 72;
	          force = 'tr';
			    }
			  }
			  HoverTimerForBubble = setTimeout("UpdateBubble('Referral Hover')",globalHoverUpdateTimerDelay);
			  break;
		  case "Private Space Hover":
			  HoverTimerForBubble = setTimeout("UpdateBubble('Private Space Hover')",globalHoverUpdateTimerDelay);
			  break;
			case "Web Coach Hover":
			  HoverTimerForBubble = setTimeout("UpdateBubble('Web Coach Hover')",globalHoverUpdateTimerDelay);
			  break;
			case "SignInUp Hover":
			  HoverTimerForBubble = setTimeout("UpdateBubble('SignInUp Hover')",globalHoverUpdateTimerDelay);
			  break;
			case "SignOut Hover":
			  HoverTimerForBubble = setTimeout("UpdateBubble('SignOut Hover')",globalHoverUpdateTimerDelay);
			  break;
			case "HideAuthor":
			  return;
			  break;
			case "SignInUp Welcome":
				if(ie == 'true')
				{
					TopLeftPositionArray[1] = TopLeftPositionArray[1] + 100;
					BottomRightPositionArray[1] = BottomRightPositionArray[1] + 100;	
				}
			  HoverTimerForBubble = setTimeout("UpdateBubble('SignInUp Hover')",globalHoverUpdateTimerDelay);
			  break;
			case "Semantic Tree Title":
			  HoverTimerForBubble = setTimeout("UpdateBubble('Semantic Tree Title')",globalHoverUpdateTimerDelay);
			  break;
			case "PDF Hover":
				force = 'tr';
			  HoverTimerForBubble = setTimeout("UpdateBubble('PDF Hover')",globalHoverUpdateTimerDelay);
			  break;
			case "Print Hover":
				force = 'tr';
			  HoverTimerForBubble = setTimeout("UpdateBubble('Print Hover')",globalHoverUpdateTimerDelay);
			  break;
			case "Key Concepts Hover":
			  HoverTimerForBubble = setTimeout("UpdateBubble('Key Concepts Hover')",globalHoverUpdateTimerDelay);
			  break;
			case "Single View Hover":
			  HoverTimerForBubble = setTimeout("UpdateBubble('Single View Hover')",globalHoverUpdateTimerDelay);
			  break;
			case "Split View Hover":
			  HoverTimerForBubble = setTimeout("UpdateBubble('Split View Hover')",globalHoverUpdateTimerDelay);
			  break;
			case "Reset Hover":
			  HoverTimerForBubble = setTimeout("UpdateBubble('Reset Hover')",globalHoverUpdateTimerDelay);
			  break;
		  case "Index Docs Hover":
			  if(ie == 'false' && _editOverride != 'true')
			  {
				  TopLeftPositionArray[0] = (screen.availWidth / 10) * 6;
				  BottomRightPositionArray[0] = TopLeftPositionArray[0];
				  // for corner position (pointer direction)
				  force = 'bl';
			  }
			  HoverTimerForBubble = setTimeout("UpdateBubble('Index Docs Hover')",globalHoverUpdateTimerDelay);
			  break;
		  case "Indexed Docs Hover":
		  if(ie == 'false' && _editOverride != 'true')
			  {
				  TopLeftPositionArray[0] = (screen.availWidth / 10) * 6;
				  BottomRightPositionArray[0] = TopLeftPositionArray[0];
				  force = 'bl';
			  }
			  HoverTimerForBubble = setTimeout("UpdateBubble('Indexed Docs Hover')",globalHoverUpdateTimerDelay);
			  break;
		  case "Search Click":
				suggBox = document.getElementById("KGSuggestionControl_Div_ID");
				if(suggBox.className == "OverlayPosition")
				{
					return;
				}
			  HoverTimerForBubble = setTimeout("UpdateBubble('Search Click')",globalHoverUpdateTimerDelay);
			  break;
		  case "Hover Search":
				suggBox = document.getElementById("KGSuggestionControl_Div_ID");
				if(suggBox.className == "OverlayPosition")
				{
					return;
				}
			  HoverTimerForBubble = setTimeout("UpdateBubble('Hover Search')",globalHoverUpdateTimerDelay);
			  break;
			case "Hover Search Item":
			  HoverTimerForBubble = setTimeout("UpdateBubble('Hover Search Item')",globalHoverUpdateTimerDelay);
			  break;
			case "Semantic Tree Hover":
				TopLeftPositionArray[0] = 250;
				TopLeftPositionArray[1] = 250;
				BottomRightPositionArray[0] = 250;
				BottomRightPositionArray[1] = 250;	
			  HoverTimerForBubble = setTimeout("UpdateBubble('Semantic Tree Open')",globalHoverUpdateTimerDelay);
			  break;
		  case "Create KG":
			  HoverTimerForBubble = setTimeout("UpdateBubble('Create KG')",globalHoverUpdateTimerDelay);
			  break;
		  case "View Indexed Editing":
			  HoverTimerForBubble = setTimeout("UpdateBubble('View Indexed Editing')",globalHoverUpdateTimerDelay);
			  break;
		  case "Load Profile Self":
			  HoverTimerForBubble = setTimeout("UpdateBubble('Load Profile Self')",globalHoverUpdateTimerDelay);
			  break;
		  case "Load Profile Other":
			  HoverTimerForBubble = setTimeout("UpdateBubble('Load Profile Other')",globalHoverUpdateTimerDelay);
			  break;
			case "Category Hover":
			  HoverTimerForBubble = setTimeout("UpdateBubble('Category Hover')",globalHoverUpdateTimerDelay);
			  break;
			case "MyHK Hover":
			  HoverTimerForBubble = setTimeout("UpdateBubble('MyHK Hover')",globalHoverUpdateTimerDelay);
			  break;
		  case "Show Semantic Tree Other":
			  HoverTimerForBubble = setTimeout("UpdateBubble('Show Semantic Tree Other')",globalHoverUpdateTimerDelay);
			  break;
		  case "Objective Hover":
				if(authorBubble)
					if(authorBubble.style.display == "block")
						return;
				if(editBoxCheck != null)
					if(editBoxCheck.style.visibility == "visible" && editBoxCheck.style.display == "block")
						return;
				HideBubble('true');
			  autoScrollOffset = 'true';
			  HoverTimerForBubble = setTimeout("UpdateBubble('Objective Hover')",globalHoverUpdateTimerDelay);
			  break;
		  case "How Hover":
				if(authorBubble)
					if(authorBubble.style.display == "block")
						return;
				if(editBoxCheck != null)
					if(editBoxCheck.style.visibility == "visible" && editBoxCheck.style.display == "block")
						return;
				HideBubble('true');
			  autoScrollOffset = 'true';
			  HoverTimerForBubble = setTimeout("UpdateBubble('How Hover')",globalHoverUpdateTimerDelay);
			  break;
		  case "Why Hover":
				if(authorBubble)
					if(authorBubble.style.display == "block")
						return;
				if(editBoxCheck != null)
					if(editBoxCheck.style.visibility == "visible" && editBoxCheck.style.display == "block")
						return;
				HideBubble('true');
			  autoScrollOffset = 'true';
			  HoverTimerForBubble = setTimeout("UpdateBubble('Why Hover')",globalHoverUpdateTimerDelay);
			  break;
		  case "AddChildBoxHow Hover":	
				if(authorBubble)
					if(authorBubble.style.display == "block")
						return;
				if(editBoxCheck != null)
					if(editBoxCheck.style.visibility == "visible" && editBoxCheck.style.display == "block")
						return;
				HideBubble('true');
			  autoScrollOffset = 'true';
			  HoverTimerForBubble = setTimeout("UpdateBubble('AddChildBoxHow Hover')",globalHoverUpdateTimerDelay);
			  break;
		  case "AddChildBoxWhy Hover":
				if(authorBubble)
					if(authorBubble.style.display == "block")
						return;
				if(editBoxCheck != null)
					if(editBoxCheck.style.visibility == "visible" && editBoxCheck.style.display == "block")
						return;
				HideBubble('true');
			  autoScrollOffset = 'true';
			  HoverTimerForBubble = setTimeout("UpdateBubble('AddChildBoxWhy Hover')",globalHoverUpdateTimerDelay);
			  break;
		  case "WhatIs Highlighted":
			  autoScrollOffset = 'true';
			  HoverTimerForBubble = setTimeout("UpdateBubble('WhatIs Highlighted')",globalHoverUpdateTimerDelay);
			  break;
		  case "What Highlighted":
			  autoScrollOffset = 'true';
			  HoverTimerForBubble = setTimeout("UpdateBubble('What Highlighted')",globalHoverUpdateTimerDelay);
			  break;
		  case "Add Objective":
				authorBubble.style.display = "block";
				HideBubble();
				return;
		  case "Add MyHK":
			  HoverTimerForBubble = setTimeout("UpdateBubble('Add MyHK')",globalHoverUpdateTimerDelay);
			  break;
	  }
	  // updateBubblePosition
	  updateBubblePosition(TopLeftPositionArray, BottomRightPositionArray, borderOffset, autoScrollOffset, force, ie);
	}
}

var globalHideBubbleTime;
				
function bubbleMouseOut(e)
{
	// clear hover timeout & hide the bubble.
	clearTimeout(HoverTimerForBubble);
	if(window.HideBubble)
	  globalHideBubbleTime = setTimeout("HideBubble('true');", globalHoverUpdateTimerDelay);
}

var globalBubbleBottom = "false";

function updateBubblePosition(_TLPosition, _BRPosition, _borderOffset, _autoScrollOffset, _force, _ie)
{
	//debugger;
	HideBubble();
	var leftOffset = 0;
	var rightOffset = 0;
	var mapViewControlDiv = document.getElementById("main-window"); 
	if(mapViewControlDiv)
	{
		leftOffset = mapViewControlDiv.scrollLeft;
	}
	if(_autoScrollOffset == 'false')
		leftOffset = 0;
	var Bubble = document.getElementById("KGBubbleControl1_HelpBubble");
	var BubblePointer = document.getElementById("KGBubbleControl1_bubblePointer");
	// find width & height midpoint.
	var horizontalMidPoint = (_TLPosition[0] + _BRPosition[0]) / 2;
	var verticalMidPoint = (_TLPosition[1] + _BRPosition[1]) / 2;
	// find what screen quarter that mid-point is in
	var screenHorizontalMidPoint = screen.availWidth / 2;
	var screenVerticalMidPoint = screen.availHeight / 2;
	var route;
	
	
	if(_force)
	{
		route = _force;
		if(route == 'bl')
			if(verticalMidPoint <= screenVerticalMidPoint)
				route = 'tl';
	}
	else
	{
		// load correct bubble shape for that quarter
		if(horizontalMidPoint >= screenHorizontalMidPoint)
		{
			if(verticalMidPoint <= screenVerticalMidPoint)
			{
				//top right
				route = 'tr';
			}
			else
			{
				//bottom right
				if(_force != 'bl')
					route = 'br';
			}
		}
		else
		{
			if(verticalMidPoint <= screenVerticalMidPoint)
			{
				//top left
				route = 'tl';
			}
			else
			{
				//bottom left
				route = 'bl';
			}
		}
	}

	switch(route)
	{
		case 'tr':
			// top right quarter
			var bubbleHeightOffset = 20 + _BRPosition[1];
			Bubble.style.left = _TLPosition[0] - 310 - leftOffset;
			if(_borderOffset == 'true')
				Bubble.style.left = _TLPosition[0] - 310 + 100;
			Bubble.style.top = bubbleHeightOffset;
			globalBubbleBottom = "false";
			break;
		case 'br':
			// bottom right quarter
			var bubbleHeightOffset = _TLPosition[1] - 20;
			Bubble.style.left = _TLPosition[0] - 310 - leftOffset;
			Bubble.style.top = bubbleHeightOffset;
			globalBubbleBottom = "true";
			break;
		case 'tl':
			// top left quarter
			var bubbleHeightOffset = 20 + _BRPosition[1];
			Bubble.style.left = _BRPosition[0] + 10 - leftOffset;
			if(_borderOffset == 'true')
				Bubble.style.left = _BRPosition[0] + 10 + 100;
			Bubble.style.top = bubbleHeightOffset;
			globalBubbleBottom = "false";
			break;
		case 'bl':
			// bottom left quarter
			var bubbleHeightOffset = _TLPosition[1] - 20;
			Bubble.style.left = _BRPosition[0] + 10 - leftOffset;
			Bubble.style.top = bubbleHeightOffset;
			globalBubbleBottom = "true";
			break;
	}
}

function importScript(_fileName)
{
  var tag = document.createElement("script");
  tag.type="text/javascript";
  tag.src = 'JavaScript/' + _fileName;
  document.body.appendChild(tag);
}

function WM_setCookie(name, value, hours, path, domain, secure) 
{
	if (WM_acceptsCookies) 
	{ 
		// Don't waste your time if the browser doesn't accept cookies.
		var not_NN2 = (navigator && navigator.appName 
		       && (navigator.appName == 'Netscape') 
		       && navigator.appVersion 
		       && (parseInt(navigator.appVersion) == 2))?false:true;

		if(hours && not_NN2) 
		{ // NN2 cannot handle Dates, so skip this part
	    if ( (typeof(hours) == 'string') && Date.parse(hours) ) 
	    {
				// already a Date string
				var numHours = hours;
	    } 
	    else if (typeof(hours) == 'number') 
	    { 
				// calculate Date from number of hours
				var numHours = (new Date((new Date()).getTime() + hours*3600000)).toGMTString();
	    }
		}
		document.cookie = name + '=' + escape(value) + ((numHours)?(';expires=' + numHours):'') + ((path)?';path=' + path:'') + ((domain)?';domain=' + domain:'') + ((secure && (secure == true))?'; secure':''); // Set the cookie, adding any parameters that were specified.  
	}
} // WM_setCookie

function WM_killCookie(name, path, domain) {
  var theValue = WM_readCookie(name); // We need the value to kill the cookie
  if(theValue) {
      document.cookie = name + '=' + theValue + '; expires=Fri, 13-Apr-1970 00:00:00 GMT' + ((path)?';path=' + path:'') + ((domain)?';domain=' + domain:''); // set an already-expired cookie
  }
} // WM_killCookie

function helpBubbleToggle(e)
{

      try

      {

            var toggleElement = document.getElementById("BubbleTourToggle");

            var Element;

 

            switch(toggleElement.className)

            {

                  case "TourBubbleOn" :

                        toggleElement.className = "TourBubbleOff";

                        WM_setCookie('TourBubble','off', m_helpCookieExpiration);

                        ProceedWithTour();

                        break;

                  case "TourBubbleOff" :

                        toggleElement.className = "TourBubbleOn";

                        WM_setCookie('TourBubble','on', m_helpCookieExpiration);

                        ProceedWithTour();

                        break;

            }

      }

      catch(e)

      {

            alert("Exception in helpBubbleToggle(): " + e);

      }

}


function ShowTourBubble()
{
  var toggle = document.getElementById("BubbleTourToggle");
  if (toggle)
  {
    toggle.className = "TourBubbleOn";
  }
}
		
function HideTourBubble()
{
  var toggle = document.getElementById("BubbleTourToggle");
  if (toggle)
  {
    toggle.className = "TourBubbleOff";
  }
}

function TourBackOneStep(_stepToGoTo)
{
  // need to take the tour back one step
  try
  {
    switch(_stepToGoTo)
    {
      case 1:
				WM_setCookie('TourStep', 'step1');
				ProceedWithTour(true);
				break;      

      case 2:
				WM_setCookie('TourStep', 'step2');
				ProceedWithTour(true);
				break; 
				
      case 3:
				WM_setCookie('TourStep', 'step3');
				ProceedWithTour(true);
				break; 
				
      case 4:
				WM_setCookie('TourStep', 'step4');
				ProceedWithTour(true);
				break; 								
				
      case 5:
				WM_setCookie('TourStep', 'step5');
				ProceedWithTour(true);
				break; 				

      case 6:
				WM_setCookie('TourStep', 'step6');
				ProceedWithTour(true);
				break;
				
			case 7:
				WM_setCookie('TourStep', 'step7');
				ProceedWithTour(true);
				break;
				
			case 8:
				WM_setCookie('TourStep', 'step8');
				ProceedWithTour(true);
				break;
    
    }
  }
  catch(e)
	{
		alert("Exception in TourBackOneStep(): " + e);
	}
}

function UpdateTour(_stepCompleted)
{
	try
	{
		if(WM_readCookie('TourBubble') == "on")
		{
			var stepNumber = WM_readCookie('TourStep');
			switch(_stepCompleted)
			{
				case 1:
					if(stepNumber == "step1")
					{
						WM_setCookie('TourStep', 'step2');
						ProceedWithTour(false);
					}
					else if(stepNumber == "step2")
					{
						WM_setCookie('TourStep', 'step3');
						ProceedWithTour(false);
					}
					break;
				case 2:
					if(stepNumber == "step2")
					{
						WM_setCookie('TourStep', 'step3');
						ProceedWithTour(false);
					}
					break;
				case 3:
					if(stepNumber == "step3")
					{
						WM_setCookie('TourStep', 'step4');
						ProceedWithTour(false);
					}
					break;
				case 4:
					if(stepNumber == "step4")
					{
						WM_setCookie('TourStep', 'step5');
						ProceedWithTour(false);
					}
					break;
				case 5:
					if(stepNumber == "step5")
					{
						WM_setCookie('TourStep', 'step6');
						ProceedWithTour(false);
					}
					break;
				case 6:
					if(stepNumber == "step6")
					{
						WM_setCookie('TourStep', 'step7');
						ProceedWithTour(false);
					}
					break;
				case 7:
					if(stepNumber == "step7")
					{
						WM_setCookie('TourStep', 'step8');
						ProceedWithTour(false);
					}
					break;
				case 8:
					if(stepNumber == "step8")
					{
						WM_setCookie('TourStep', 'step9');
						ProceedWithTour(false);
					}
					break;
				case 8:
					if(stepNumber == "step8")
					{
						WM_setCookie('TourStep', 'step1');
						ProceedWithTour(false);
					}
					break;
			}
		}
	}
	catch(e)
	{
		alert("Exception in UpdateTour(): " + e);
	}
}

function ProceedWithTour(_bBack)
{
	try
	{
		var currentLocation = window.location.href;
		var currentPage = currentLocation.substring(currentLocation.lastIndexOf('/')+1, currentLocation.length).toLowerCase();
		var previousBubble;
		var tourBubble;
		var authorBubble = document.getElementById("AuthorTour1");
		var stepNumber = WM_readCookie('TourStep');
		if(currentPage == "" || currentPage.toLowerCase().match("home") == "home")
		{
			if(m_bEditable == true && Map_TextEditOnly == 0)
			{
				// Hide non author bubbles
				switch(stepNumber)
				{
					case "step1":
					  if ( _bBack == false )
  						previousBubble = document.getElementById("Tour7");
  				  else
  						previousBubble = document.getElementById("Tour2");  				  
						previousBubble.style.display = "none";
						tourBubble = document.getElementById("Tour1");
						tourBubble.style.display = "none";
						break;
					case "step2":
					  if ( _bBack == false )
  						previousBubble = document.getElementById("Tour1");
  				  else
  						previousBubble = document.getElementById("Tour3");  				  
						previousBubble.style.display = "none";
						tourBubble = document.getElementById("Tour2");
						tourBubble.style.display = "none";
						break;
					case "step3":
					  if ( _bBack == false )
  						previousBubble = document.getElementById("Tour2");
  				  else
  						previousBubble = document.getElementById("Tour4");  				  
						previousBubble.style.display = "none";
						tourBubble = document.getElementById("Tour3");
						tourBubble.style.display = "none";
						break;
					case "step4":
					  if ( _bBack == false )
  						previousBubble = document.getElementById("Tour3");
  				  else
  						previousBubble = document.getElementById("Tour5");  				  
						previousBubble.style.display = "none";
						tourBubble = document.getElementById("Tour4");
						tourBubble.style.display = "none";
						break;
					case "step5":
					  if ( _bBack == false )
  						previousBubble = document.getElementById("Tour4");
  				  else
  						previousBubble = document.getElementById("Tour6");  				  
						previousBubble.style.display = "none";
						tourBubble = document.getElementById("Tour5");
						tourBubble.style.display = "none";
						break;
					case "step6":
					  if ( _bBack == false )
  						previousBubble = document.getElementById("Tour5");
  				  else
  						previousBubble = document.getElementById("Tour7");  				  
						previousBubble.style.display = "none";
						tourBubble = document.getElementById("Tour6");
						tourBubble.style.display = "none";
						break;
					case "step7":
					  if ( _bBack == false )
  						previousBubble = document.getElementById("Tour6");
  				  else
  						previousBubble = document.getElementById("Tour8");  				  
						previousBubble.style.display = "none";
						tourBubble = document.getElementById("Tour7");
						tourBubble.style.display = "none";
						break;
					case "step8":
					  if ( _bBack == false )
  						previousBubble = document.getElementById("Tour7");
  				  else
  						previousBubble = document.getElementById("Tour9");  				  
						previousBubble.style.display = "none";
						tourBubble = document.getElementById("Tour8");
						tourBubble.style.display = "none";
						break;
					case "step9":
						previousBubble = document.getElementById("Tour6");
						previousBubble.style.display = "none";
						tourBubble = document.getElementById("Tour9");
						tourBubble.style.display = "none";
						break;
					/*case "step8":
						previousBubble = document.getElementById("Tour7");
						previousBubble.style.display = "none";
						tourBubble = document.getElementById("Tour8");
						tourBubble.style.display = "none";
						break;*/
					default:
						tourBubble = document.getElementById("Tour1");
						tourBubble.style.display = "none";
						WM_setCookie('TourStep','step1');
						break;
				}
				if(WM_readCookie('TourBubble') == "on")
				{
					// Show the authoring bubble
					authorBubble.style.display = "block";
					// update first author cookie (first new kg)
					if(currentLocation.toLowerCase().match("createnewkg") == "createnewkg" && WM_readCookie('FirstAuthor') != "true")
					{
						WM_setCookie('FirstAuthor','true', m_helpCookieExpiration);
					}
				}
				else
				{
					// if creating a new gene turn tour on
					if(currentLocation.toLowerCase().match("createnewkg") == "createnewkg" && WM_readCookie('FirstAuthor') != "true")
					{
						WM_setCookie('FirstAuthor','true', m_helpCookieExpiration);
						var toggle = document.getElementById("BubbleTourToggle");
						if (toggle)
						{
							authorBubble.style.display = "block";
							toggle.className = "TourBubbleOn";
							WM_setCookie('TourBubble','on', m_helpCookieExpiration);
						}
					}
					else
					{
						// Hide the authoring bubble
						authorBubble.style.display = "none";
					}
				}
			}
			else
			{
				authorBubble.style.display = "none";
				if(WM_readCookie('TourBubble') == "on")
				{
					// read cookie for Tour Steps
					switch(stepNumber)
					{
						case "step1": 
					    if ( _bBack == false )
  						  previousBubble = document.getElementById("Tour7");
  				    else
  						  previousBubble = document.getElementById("Tour2");  				  
							previousBubble.style.display = "none";				
							tourBubble = document.getElementById("Tour1");
							tourBubble.style.display = "block";
							break;
						case "step2":
					    if ( _bBack == false )
  						  previousBubble = document.getElementById("Tour1");
  				    else
  						  previousBubble = document.getElementById("Tour3");  				  
							previousBubble.style.display = "none";
							tourBubble = document.getElementById("Tour2");
							tourBubble.style.display = "block";
							break;
						case "step3":
					    if ( _bBack == false )
  						  previousBubble = document.getElementById("Tour2");
  				    else
  						  previousBubble = document.getElementById("Tour4");  				  
							previousBubble.style.display = "none";
							tourBubble = document.getElementById("Tour3");
							tourBubble.style.display = "block";
							break;
						case "step4":
					    if ( _bBack == false )
  						  previousBubble = document.getElementById("Tour3");
  				    else
  						  previousBubble = document.getElementById("Tour5");  				  
							previousBubble.style.display = "none";
							tourBubble = document.getElementById("Tour4");
							tourBubble.style.display = "block";
							break;
						case "step5":
					    if ( _bBack == false )
  						  previousBubble = document.getElementById("Tour4");
  				    else
  						  previousBubble = document.getElementById("Tour6");  				  
							previousBubble.style.display = "none";
							tourBubble = document.getElementById("Tour5");
							tourBubble.style.display = "block";
							break;
						case "step6":
					    if ( _bBack == false )
  						  previousBubble = document.getElementById("Tour5");
  				    else
  						  previousBubble = document.getElementById("Tour7");  				  
							previousBubble.style.display = "none";
							tourBubble = document.getElementById("Tour6");
							tourBubble.style.display = "block";
							break;
						case "step7":
					    if ( _bBack == false )
  						  previousBubble = document.getElementById("Tour6");
  				    else
  						  previousBubble = document.getElementById("Tour8");  				  
							previousBubble.style.display = "none";
							tourBubble = document.getElementById("Tour7");
							tourBubble.style.display = "block";
							break;
						case "step8":
					    if ( _bBack == false )
  						  previousBubble = document.getElementById("Tour7");
  				    else
  						  previousBubble = document.getElementById("Tour9");  				  
							previousBubble.style.display = "none";
							tourBubble = document.getElementById("Tour8");
							tourBubble.style.display = "block";
							break;
						case "step9":
							previousBubble = document.getElementById("Tour8");
							previousBubble.style.display = "none";
							tourBubble = document.getElementById("Tour9");
							tourBubble.style.display = "block";
							break;
						/*case "step8":
							previousBubble = document.getElementById("Tour7");
							previousBubble.style.display = "none";
							tourBubble = document.getElementById("Tour8");
							tourBubble.style.display = "block";
							break;*/
						default:
							tourBubble = document.getElementById("Tour1");
							tourBubble.style.display = "block";
							WM_setCookie('TourStep','step1');
							break;
					}
				}
				else
				{
					// read cookie for Tour Steps
					switch(stepNumber)
					{
						case "step1": 
					    if ( _bBack == false )
  						  previousBubble = document.getElementById("Tour7");
  				    else
  						  previousBubble = document.getElementById("Tour2");  				  
							previousBubble.style.display = "none";
							tourBubble = document.getElementById("Tour1");
							tourBubble.style.display = "none";
							break;
						case "step2":
					    if ( _bBack == false )
  						  previousBubble = document.getElementById("Tour1");
  				    else
  						  previousBubble = document.getElementById("Tour3");  				  
							previousBubble.style.display = "none";
							tourBubble = document.getElementById("Tour2");
							tourBubble.style.display = "none";
							break;
						case "step3":
					    if ( _bBack == false )
  						  previousBubble = document.getElementById("Tour2");
  				    else
  						  previousBubble = document.getElementById("Tour4");  				  
							previousBubble.style.display = "none";
							tourBubble = document.getElementById("Tour3");
							tourBubble.style.display = "none";
							break;
						case "step4":
					    if ( _bBack == false )
  						  previousBubble = document.getElementById("Tour3");
  				    else
  						  previousBubble = document.getElementById("Tour5");  				  
							previousBubble.style.display = "none";
							tourBubble = document.getElementById("Tour4");
							tourBubble.style.display = "none";
							break;
						case "step5":
					    if ( _bBack == false )
  						  previousBubble = document.getElementById("Tour4");
  				    else
  						  previousBubble = document.getElementById("Tour6");  				  						
							previousBubble.style.display = "none";
							tourBubble = document.getElementById("Tour5");
							tourBubble.style.display = "none";
							break;
						case "step6":
					    if ( _bBack == false )
  						  previousBubble = document.getElementById("Tour5");
  				    else
  						  previousBubble = document.getElementById("Tour7");  				  						
							previousBubble.style.display = "none";
							tourBubble = document.getElementById("Tour6");
							tourBubble.style.display = "none";
							break;
						case "step7":
					    if ( _bBack == false )
  						  previousBubble = document.getElementById("Tour6");
  				    else
  						  previousBubble = document.getElementById("Tour8");  				  						
							previousBubble.style.display = "none";
							tourBubble = document.getElementById("Tour7");
							tourBubble.style.display = "none";
							break;
						case "step8":
					    if ( _bBack == false )
  						  previousBubble = document.getElementById("Tour7");
  				    else
  						  previousBubble = document.getElementById("Tour9");  				  						
							previousBubble.style.display = "none";
							tourBubble = document.getElementById("Tour8");
							tourBubble.style.display = "none";
							break;
						case "step9":
							previousBubble = document.getElementById("Tour8");
							previousBubble.style.display = "none";
							tourBubble = document.getElementById("Tour9");
							tourBubble.style.display = "none";
							tourBubble = document.getElementById("Tour1");
							tourBubble.style.display = "none";
							WM_setCookie('TourStep', 'step1');
							break;
						/*case "step8":
							previousBubble = document.getElementById("Tour7");
							previousBubble.style.display = "none";
							tourBubble = document.getElementById("Tour8");
							tourBubble.style.display = "none";
							tourBubble = document.getElementById("Tour1");
							tourBubble.style.display = "none";
							WM_setCookie('TourStep', 'step1');
							break;*/
						default:
							tourBubble = document.getElementById("Tour1");
							tourBubble.style.display = "none";
							WM_setCookie('TourStep','step1');
							break;
					}
				}
			}
		}
	}
	catch(e)
	{
		alert("Exception in ProceedWithTour(): " + e);
	}
}

// parent.insertAdjacentElement is an IE method, this is w3
function InsertAdjacentElement(_parent, _where, _element) 
{
  if (_parent.insertAdjacentElement) // may aswell use the IE method if we can
    return _parent.insertAdjacentElement(_where, _element);
  
  switch (_where.toLowerCase()) 
  {
	  case "beforebegin":
		  _parent.parentNode.insertBefore(_element, _parent);
		  break;
	  case "afterbegin":
		  _parent.insertBefore(_element, _parent.firstChild);
		  break;
	  case "beforeend":
		  _parent.appendChild(_element);
		  break;
	  case "afterend":
		  _parent.parentNode.insertBefore(_element, _parent.nextSibling);
		  break;
  }	
  return _element;
}

// Firefox, Opera and Safari include text nodes (nodeType == 3) after some elements (e.g. before and after divs for the break)
function hkNextSibling(_element)
{
  var ns = _element.nextSibling;
  while (ns && ns.nodeType == 3)
    ns = ns.nextSibling;
  return ns;
}

function hkFirstChild(_element)
{
  var ns = _element.firstChild;
  while (ns && ns.nodeType == 3)
    ns = ns.nextSibling;
  return ns;
}

function hkLastChild(_element)
{
  var ns = _element.lastChild;
  while (ns && ns.nodeType == 3)
    ns = ns.previousSibling;
  return ns;
}

function CancelBubble(e)
{
  e = e || window.event;
  if (e)
  {
    e.cancelBubble = true;
    if (e.stopPropagation) e.stopPropagation();
  }
  //else
    //alert('cancel bubble but no event');
}

function GetInnerText(_element)
{
  //var txt = verb.textContent || verb.innerText; //this won't work if the innerText is an empty string
  if (_element.textContent || _element.textContent == '')
    return _element.textContent;
  else
    return _element.innerText;
}

function SetInnerText(_element, _txt)
{
  if (_element.textContent || _element.textContent == '')
    _element.textContent = _txt;
  else
    _element.innerText = _txt;
}

function GetPixelWidth(_element)
{
  if (_element.pixelWidth) // ie only
    return _element.pixelWidth;
    
  var width = _element.style.width;
  if (width.indexOf('px') > -1)
    return parseInt(width);
    
  return _element.offsetWidth;
}

function GetPixelHeight(_element)
{
  if (_element.pixelHeight) // ie only
    return _element.pixelHeight;
    
  var height = _element.style.height;
  if (height.indexOf('px') > -1)
    return parseInt(height);
    
  return _element.offsetHeight;
}

function GetPixelLeft(_element)
{
  if (_element.pixelLeft) // ie only
    return _element.pixelLeft;
    
  var left = _element.style.left;
  if (left.indexOf('px') > -1)
    return parseInt(left);
    
  return _element.offsetLeft;
}

function GetPixelTop(_element)
{
  if (_element.pixelTop) // ie only
    return _element.pixelTop;
    
  var top = _element.style.top;
  if (top.indexOf('px') > -1)
    return parseInt(top);
    
  return _element.offsetTop;
}

function SetOuterHtml(_el, _html)
{
  if (_el.outerHTML)
    _el.outerHTML = _html;
  else
  {
    var newEl = document.createElement("div");
    newEl.innerHTML = _html;
    _el.parentNode.replaceChild(newEl.firstChild, _el);
  }
}


function purge(d) 
{
    var a = d.attributes, x, l, n;
    if (a) 
    {
        l = a.length;
        for (var x = 0; x < l; x += 1) 
        {
            n = a[x].name;
            if (typeof d[n] == 'function') 
            {
                d[n] = null;
            }
        }
    }
    a = d.childNodes;
    if (a) 
    {
        l = a.length;
        for (x = 0; x < l; x += 1) 
        {
            purge(d.childNodes[x]);
        }
    }
}
function HideDropLists()
{
  // retrieve and hide all droplists.
  var droplist = document.getElementsByTagName("SELECT");
  for(var num=0;num<droplist.length;num++)
  {
	  //only hide the visible boxes
	  if(droplist[num].className == "list_dropList")
		  droplist[num].style.display = "none";
  }
}

function ShowDropLists()
{
  // retrieve and show all droplists.
  var droplist = document.getElementsByTagName("SELECT");
  for(var num=0;num<droplist.length;num++)
  {
    if(droplist[num].className == "list_dropList")
	    droplist[num].style.display = "inline";
  }
}

function HCatDiv_MouseEnter()
{
  var editFrameDiv = document.getElementById('TextViewEditFrameDiv');
  if(editFrameDiv != null && window.TextViewControl_onMouseOut)
  {
    TextViewControl_onMouseOut(); // auto save
  }
}

function SiteHeaderDiv_MouseEnter()
{
  var editFrameDiv = document.getElementById('TextViewEditFrameDiv');
  if(editFrameDiv != null && window.TextViewControl_onMouseOut)
  {
    TextViewControl_onMouseOut(); //auto save
  }
}

function UpdateMapViewForApp(_knowdeid)
{   
	global_reloadApp = "false";
	
	var keys = 'SelectedKGID|MapViewDisplayMode|ReloadApplicationControl';
	var values = _knowdeid + '|KGMapView|false';
  SetSessionProperty(keys, values, true);

  //SetSessionProperty('SelectedKGID', _knowdeid);
  //SetSessionProperty('MapViewDisplayMode', 'KGMapView');
  //SetSessionProperty('ReloadApplicationControl', 'false');
  MapViewControl1_CallbackTrigger();
  //KGTabbedWindowsControl_CallbackTrigger('KnowdeSelected');
  DoExpandMapViewPane("fully");
}

function RepopulateProfilePageKGLists()
{
  // repopulate the KGUserObjectSummaryControl
  if (window.Pfl_KGUserObjectSummaryControl_CallbackTrigger)
    Pfl_KGUserObjectSummaryControl_CallbackTrigger('action=refresh|kgId=0');
  
  // repopulate the KGMyKnowledgeControl
  if (window.Pfl_KGMyKnowledgeControl_CallbackTrigger)
    Pfl_KGMyKnowledgeControl_CallbackTrigger('Action=repopulate');
}

function CheckSessionTimeout()
{
  // Check for cookie which tells us if the session has expired
  var cookie_content = WM_readCookie('sessionExpired');
  
  if(cookie_content != null && cookie_content.length > 0)
  {
    // clear cookies
    WM_setCookie('SignedIn', "");
    WM_setCookie('sessionExpired', "");
    WM_killCookie('SignedIn')
    WM_killCookie('sessionExpired');
    window.location = "SessionTimeout.aspx";
    return true;
  }
  else
    return false;
}

function RSS_Check()
{
	//browser check
	if(navigator.appVersion.match("MSIE 6") == "MSIE 6" && navigator.appName == "Microsoft Internet Explorer")
	{
		window.location = "RSSReaderRequired.aspx";
	}
	else
	{
		window.location = "http://blogs.knowledgegenes.com/home/atom.xml";
	}
}

function delayedRedirect(_path, _delay)
{
  setTimeout("window.location = '" + _path + "';", _delay);
}

function CallbackTrigger_Wrapped(_args, _cbReference)
{
  var args = _args;
  if(_cbReference != null && _cbReference != "")
    eval(_cbReference);
}

function BkmkCheckStatus()
{
  // if a map and/or profile is visible (returns an array with both variables)
  var mapVisible = false; 
  var profileVisible = false; 
  var profileTab;
  
  // if it's the options.aspx page, a profile is visible and a map isn't
  // if it's the home page, a map and/or profile may be visible
  // if it's any other page, neither a map nor a profile will be visible
  
  var currentLocation = window.location.href;
	var currentPage = currentLocation.substring(currentLocation.lastIndexOf('/')+1, currentLocation.length).toLowerCase();
  
	if (currentPage.indexOf('home') > -1 || currentPage.length == 0)
	{
	  var mapCollapsed;
	  if (window.Active_KGID && window.Active_KGName) //otherwise either there's no map or the map hasn't loaded yet
	  {
	    mapCollapsed = PaneBStatus(); //if false or null then map is visible
	    if (!mapCollapsed) 
	      mapVisible = true;
	  }
	  
    // profile is visible if the tabbed windows are visible and the selected tab is the community tab
    // first check the selected tab - it's easier and usually not true, so we don't have to 
    if (globalVisibleTab == "TSC_myprofile")
      profileTab = "Profile";
    else if (globalVisibleTab == "TSC_communities" && globalCommunityVisibleTab == "User")
      profileTab = "Community";
    else
      profileTab = null; // selected tab isn't a profile tab
    
    // now check whether the tab is hidden by the splitter
    if (profileTab)
    {
      if (mapCollapsed) // if map is collapsed, tabbed windows must be visible, then can avoid more splitter checks
        profileVisible = true;
      else
      {
        if (Splitter1.Panes)
        {
          var PaneC = Splitter1.Panes[1]
          if(PaneC.element.style.display != "none") //copied this check from SplitterPaneHandler.js SplitterControl
            profileVisible = true;
        }
      }
    }
	}
	
	return [mapVisible,profileVisible];

}

var m_bkmkMenu;
function BookmarkingOptionControl_ShowMenu_Wrapped(_siteName, _bkmkUrl, _bkmkId, _mapVisible, _profileVisible, _controlDivId, _siteRowId, _mapRowId, _knowdeRowId, _userRowId)
{
  BkmkHighlightTopText(_bkmkUrl);
  if (!m_bkmkMenu)
    m_bkmkMenu = document.getElementById(_controlDivId);
  
  if(m_bkmkMenu)
  {
    var siteRow = document.getElementById(_siteRowId);
    siteRow.title = BkmkGetTooltip('site', _siteName)
    // show/hide the map row
    var mapRow = document.getElementById(_mapRowId);
    if (mapRow)
    {
      if (_mapVisible)
      {
        mapRow.style.display = ''; //default to table row display
        mapRow.title = BkmkGetTooltip('Knowledge Gene', _siteName)
      }
      else
        mapRow.style.display = 'none';
    }

    // show/hide the knowde row
    var knowdeRow = document.getElementById(_knowdeRowId);
    if (knowdeRow)
    {
      if (_mapVisible  && currentMapViewType == MAP_TYPE_KNOWDE)
      {
        knowdeRow.style.display = ''; //default to table row display
        knowdeRow.title = BkmkGetTooltip('Knowde', _siteName)
      }
      else
        knowdeRow.style.display = 'none';
    }
            
    // show/hide the user row
    var userRow = document.getElementById(_userRowId);
    if (userRow)
    {
      if (_profileVisible)
      {
        // get the member name
        var memberNameCtlId;
        if (globalVisibleTab == "TSC_communities" && window.Com_KGProfileHeaderControl_GetMemberNameControlId)
          memberNameCtlId = Com_KGProfileHeaderControl_GetMemberNameControlId();
        else if (globalVisibleTab == "TSC_myprofile" && window.Pfl_KGProfileHeaderControl_GetMemberNameControlId)
          memberNameCtlId = Pfl_KGProfileHeaderControl_GetMemberNameControlId();
          
        if (memberNameCtlId)
        {
          var memberNameCtl = document.getElementById(memberNameCtlId);
          if (memberNameCtl)
          {
            var name = GetInnerText(memberNameCtl);
            m_bkmkMenu.userName = name;
            //SetInnerText(userRow.cells[0], name);
          
            userRow.style.display = ''; //default to table row display
            userRow.title = BkmkGetTooltip('person', _siteName)
          }
          else // memberNameCtl hasn't loaded yet
            userRow.style.display = 'none';
        }
        else // memberNameCtl hasn't loaded yet
          userRow.style.display = 'none';
      }
      else // not profileVisible
        userRow.style.display = 'none';
    }
  
    m_bkmkMenu.bkmkUrl = _bkmkUrl; //save the bookmarking url (e.g. ...facebook.com...) for use in the onclick methods
    
    //position the menu
    
    // top of the menu lines up with the bottom of the hcc
    var topText = BookmarkingControl_GetReferText();
    if (topText)
    {
      var y = findBRElementCoords(topText)[1] + 2;
      m_bkmkMenu.style.top = y + 'px';
    }
    
    //left of menu lines up with bookmarker icon
    var x;
    bkmk = document.getElementById(_bkmkId);
    if (bkmk)
    {
      x = findElementCoords(bkmk)[0]; 
      m_bkmkMenu.style.left = x + 'px';
    }
    
    // show the menu - show before maxX for clientWidth
    m_bkmkMenu.style.display = 'block';
    //make sure the control isn't off the page (m_bkmkMenu.lastChild is the table; m_bkmkMenu.clientWidth is the whole screen)
    var maxX = document.body.clientWidth - m_bkmkMenu.lastChild.clientWidth - 2;  
    if (maxX > 0 && x > maxX) // but don't let it go off the page
      m_bkmkMenu.style.left = maxX + 'px';
  }
}

function BookmarkingOptionControl_HideMenu()
{
  if (m_bkmkMenu)
    m_bkmkMenu.style.display = 'none';
  BkmkUnHighlightTopText();
}

function BookmarkingOptionControl_MouseOver()
{
  clearTimeout(Bookmark_HideMenuTimer);
}

var Bookmark_HideMenuTimer;
var Bookmark_ShowMenuTimer;

function Bookmarker_MouseOver(_bkmk, _url, _siteName)
{
  clearTimeout(Bookmark_HideMenuTimer); //clear the timeouts, otherwise we might show it and then hide it later
  
  // if it's still the same bookmarker and the menu's still showing, just stop the menu from hiding and return
  if (m_bkmkMenu && m_bkmkMenu.style.display != 'none' && _url == m_bkmkMenu.bkmkUrl)
    return;
  
  BookmarkingOptionControl_HideMenu();
  
  // test for map/profile visibility
  var visibilities = BkmkCheckStatus();
  var mapVisible = visibilities[0];
  var profileVisible = visibilities[1];

  
  if (mapVisible || profileVisible) // more than one option, so show the menu - no tooltip or onclick
  {
    _bkmk.title = '';
    _bkmk.onclick = null;
    // use timeout so it doesn't show the menu if you just pass over it
    clearTimeout(Bookmark_ShowMenuTimer); // make sure we're only showing one at once (shouldn't be nec)
    var tempVarString = "'" + _siteName + "', '" + _url + "', '" + _bkmk.id + "', " + mapVisible + ", " + profileVisible;
    Bookmark_ShowMenuTimer = setTimeout("BookmarkingOptionControl_ShowMenu(" + tempVarString + ")",300);
  }
  else // only one option, don't show the menu, set tooltip and onclick goes straight through
  {
    _bkmk.title = BkmkGetTooltip('site', _siteName);
    _bkmk.onclick = function(){Bookmark('site', _url)};
  }
}

function BkmkGetTooltip(_toBkmk, _siteName)
{
  //get the tooltip text - put it in it's own function incase the hard-coded text needs to be changed in future
  //_toBkmk should be site, hyperknowledge map or person
  var tooltip;
  if (_siteName == "Referral")
    tooltip = 'Click to refer someone to this ' + _toBkmk;
  else
    tooltip = 'Click to post this ' + _toBkmk + ' to ' + _siteName;
  return tooltip;
}

function Bookmarker_MouseOut(_bkmk)
{
  clearTimeout(Bookmark_ShowMenuTimer);
  Bookmark_HideMenuTimer = setTimeout("BookmarkingOptionControl_HideMenu()", 600);
  if (_bkmk)
  {
    _bkmk.onclick = null;
    _bkmk.title = '';
  }
}

function BookmarkingOptionControl_MouseOut()
{
  Bookmark_HideMenuTimer = setTimeout("BookmarkingOptionControl_HideMenu()", 500);
}

function Bookmark(_type, _url)
{
  //_type should be site, map, knowde or user
  var bkmkUrl;
  if (_url)
  {
    if (_type != 'user') // should only be here for site anyway; 'user' needs the bookmarker control later to get user name
      bkmkUrl = _url;
    else
      return;
  }
  else if (m_bkmkMenu)
  {
    bkmkUrl = m_bkmkMenu.bkmkUrl;
    BookmarkingOptionControl_HideMenu();
  }
  else
    return;
  
  
  if (bkmkUrl.toLowerCase() == 'referral.aspx')
  {
    var referUrl = 'Referral.aspx'
    switch (_type)
    {
      case ('site'):
        break;
      case ('map'):
        referUrl += '?action=MapReferral&kgid=' + Active_KGID + '&groupid=' + GroupID;
        break;
      case ('user'):
        referUrl += '?action=AuthorReferral&authorid=' + GetSelectedProfileId();
        break;
      case ('knowde'):
        referUrl += '?action=MapReferral&kgid=' + Active_KGID + '&knowde=' + returnKnowdeID(globalLastSelectedKnowde) + '&groupid=' + GroupID;
        break;
      default:
        //handle error or just continue?
        break;
    }
    window.location = referUrl;
  }
  else // bookmark to external site
  {
    //var hkUrl = 'http://www.hyperknowledge.com/';
    var hkUrl = window.location.href;
    hkUrl = hkUrl.substring(0, hkUrl.lastIndexOf('/') + 1); //remove the current page and any query string
    var hkTitle = 'Knowledge Genes';
    switch (_type)
    {
      case ('site'):
        break;
      case ('map'):
        hkUrl += 'home.aspx?kgid=' + Active_KGID;
        hkTitle += ' - ' + Active_KGName + ' - ' + Active_KGOwner;
        break;
      case ('knowde'):
        hkUrl += 'home.aspx?kgid=' + Active_KGID + '&knowde=' + returnKnowdeID(globalLastSelectedKnowde) + '&groupid=' + GroupID;
        hkTitle += ' - ' + Active_KGName + ' - ' + Active_KGOwner;
        break;
      case ('user'):
        hkUrl += 'options.aspx?user=' + GetSelectedProfileId();
        hkTitle += ' - ' + m_bkmkMenu.userName;
        break;
      default:
        //handle error or just continue?
        break;
    }
    
    var builtUrl = bkmkUrl + encodeURIComponent(hkUrl) + '&title=' + encodeURIComponent(hkTitle);
    window.open(builtUrl);
    
    //CM Facebook and Digg can use meta tags in the html for the preview, can't do this until the site is open
    //http://www.facebook.com/share_partners.php open the link 'Making Sure the Preview Works'
    //http://digg.com/tools/thumbnails
    //<meta name="title" content="Remembering Evel Knievel" />
    //<meta name="description" content="For 20 years Evel Knievel thrilled crowds with his death-defying stunts and daredevil antics." />
    //<link rel="image_src" href="http://newsimg.bbc.co.uk/media/images/42440000/jpg/_42440347_evel_ap203i.jpg" />
  }
}

function GetSelectedProfileId()
{
  var selectedProfileID;
  if (globalVisibleTab == "TSC_communities" && window.Com_GetSelectedProfileId)
    selectedProfileID = Com_GetSelectedProfileId();
  else if (globalVisibleTab == "TSC_myprofile" && window.Pfl_GetSelectedProfileId)
    selectedProfileID = Pfl_GetSelectedProfileId();
  return selectedProfileID;
}
      
function BkmkHighlightTopText(_url)
{
  var topText = BkmkGetTopText(_url);
  if (topText)
    topText.style.color = 'Black';//back to default in css
}

function BkmkUnHighlightTopText()
{
  // just unhighlight both - it's easier than trying to figure out which it is, e.g. for mouse out of the options control
  var topReferText = BookmarkingControl_GetReferText();
  if (topReferText)
    topReferText.style.color = '';//back to default in css
  var topBkmkText = BookmarkingControl_GetBkmkText();
  if (topBkmkText)
    topBkmkText.style.color = '';//back to default in css
}

function BkmkGetTopText(_bkmkUrl)
{
  var topText;
  if (!_bkmkUrl || _bkmkUrl.toLowerCase() == 'referral.aspx')
    topText = BookmarkingControl_GetReferText();
  else
    topText = BookmarkingControl_GetBkmkText();

  return topText;
}

function BkmkHighlightOptionText(_text)
{
  if (_text)
	  _text.style.background = "#dddddd";
}

function BkmkUnHighlightOptionText(_text)
{
  if (_text)
    _text.style.background = ""; //back to css default
}

//CM temporary code to show a warning message box before posting to an external site
// probably won't need this when we leave beta
////////////////////////START OF TEMPORARY CODE/////////////////////////////////////////////////////////////////////////////////////////////////////
var m_BkmkMsgBox = null;
var CurrentlyShowingMessageBox;

///////////////////////
// Ensures that the delete message box is on the page
function EnsureBkmrkMessage(_parentControlDivId, _siteName, _builtUrl)
{
  m_BkmkMsgBox = document.getElementById("BookmarkMessageBox");
  
  if(m_BkmkMsgBox == null)
  {
    m_BkmkMsgBox = document.createElement("div");
    var parentControlDiv = document.getElementById(_parentControlDivId);
    InsertAdjacentElement(parentControlDiv,"afterEnd", m_BkmkMsgBox);
    
    m_BkmkMsgBox.setAttribute("id", "BookmarkMessageBox");
    m_BkmkMsgBox.style.display = "none";
    m_BkmkMsgBox.style.width = "400px"
    m_BkmkMsgBox.style.height = "120px";
    m_BkmkMsgBox.style.position = "absolute";
  }
  
  var header = 'Please do NOT bookmark this site while we are still in beta';
  var headerStyle = 'color:red;font-weight:bold;background-color:#f0f0f0;text-align:center';
  var line2 = 'Click OK to continue to the ' + _siteName + ' preview page';
  var onclickOk = 'window.open(\"' + _builtUrl + '\"); CloseBkmkMsgBox()';
  m_BkmkMsgBox.innerHTML = "<div style='border:gray solid 1pt;background:white;'><table border='0' cellpadding='5' cellspacing='0'><tr><td colspan='2' style='" + headerStyle + "'>" + header + "</td></tr><tr><td rowspan='2' valign='top'><img src='images/alert.png' height='50' width='50'/></td><td>" + line2 + "</td></tr><tr><td align='right'><button type='button' onclick='" + onclickOk + "'>OK</button><button id = defaultButton type='button' onclick='CloseBkmkMsgBox()'>Cancel</button></td></tr></table></div>";
}

function BkmkTopZIndex()
//Find highest z index in current document and returns this value + 1 (so that
//the control using this value will appear on top of everything currently in  
//the page, but will appear behind everything called subsequently).  JPC.
//(inspired by http://domscripting.com/presentations/atmedia2006/slides/, slide 12)
{
  var maxZindex = 0;
  var elems = document.getElementsByTagName("div");
  
  for (var j=0; j<elems.length; j++)
  {
    if (elems[j].style.zindex > maxZindex)
    {
       maxZindex = parseInt(elems[j].style.zindex);
    }
  }

  return maxZindex + 1;
}

/////////////////////
// Positions the supplied message box relative to the cursor
function PositionBkmkMsgBox()
{
  // display in middle of screen
  m_BkmkMsgBox.style.top = (document.body.clientHeight/2) - (GetPixelHeight(m_BkmkMsgBox)/2);
  m_BkmkMsgBox.style.left = (document.body.clientWidth/2) - (GetPixelWidth(m_BkmkMsgBox)/2);
    
  m_BkmkMsgBox.style.display = "block";
  m_BkmkMsgBox.style.zIndex = BkmkTopZIndex();
  m_BkmkMsgBox.style.visibility = "visible";
  BkmkFocusOn("defaultButton");
  CurrentlyShowingMessageBox = true;
}

function BkmkFocusOn(buttonId)
{
  var focusButton = document.getElementById(buttonId)
  if (focusButton != null)
  {
    // This line is necessary for the code to work with the WhatExists box.  
    // this may be due to my implementation of the box.  JPC
    focusButton.style.visiblity = "visible";  
    try
    {
        focusButton.focus();
    }
    catch(er)
    {
    }
  }
}

//////////////////
// Closes the message box
function CloseBkmkMsgBox()
{
  if(m_BkmkMsgBox != null)
  {
    m_BkmkMsgBox.style.visibility = "hidden";
    m_BkmkMsgBox.style.display = "none";
    CurrentlyShowingMessageBox = false;
  }
}
////////////////////////END OF TEMPORARY CODE/////////////////////////////////////////////////////////////////////////////////////////////////////

function showMore(_type)
{
	switch(_type)
	{
		case "Lead":
			document.getElementById("ShowMoreLeadership").style.display = "none";
			document.getElementById("MoreLeadership").style.display = "block";
			break;
		case "Info":
			document.getElementById("ShowMoreInfo").style.display = "none";
			document.getElementById("MoreInfo").style.display = "block";
			break;
		case "Ops":
			document.getElementById("ShowMoreOps").style.display = "none";
			document.getElementById("MoreOps").style.display = "block";
			break;
		case "Proj":
			document.getElementById("ShowMoreProj").style.display = "none";
			document.getElementById("MoreProj").style.display = "block";
			break;
	}
}

function showLess(_type)
{
	switch(_type)
	{
		case "Lead":
			document.getElementById("ShowMoreLeadership").style.display = "block";
			document.getElementById("MoreLeadership").style.display = "none";
			break;
		case "Info":
			document.getElementById("ShowMoreInfo").style.display = "block";
			document.getElementById("MoreInfo").style.display = "none";
			break;
		case "Ops":
			document.getElementById("ShowMoreOps").style.display = "block";
			document.getElementById("MoreOps").style.display = "none";
			break;
		case "Proj":
			document.getElementById("ShowMoreProj").style.display = "block";
			document.getElementById("MoreProj").style.display = "none";
			break;
	}
}