/////////////////////////////////////////////////////////////////////////////
// RoboHELP® Navigator Bar for WebHelp
// Copyright © 1999-2000 eHelp Corporation.  All rights reserved.

// Version= 4.00

// Warning:  Do not modify this file.  It is generated by RoboHELP® and changes will be overwritten.

// This file is used to support Navigator bar in WebHelp
// The main functions are Sync toc. Show or Hide Navigator Panel. 

// call onBsscNavHide() from bsscright frame.
// Hide the bsscleft frame(Nav). and show the current topic.

// call onBsscNavShow() from any frame except bsscright.
// Show the bsscleft frame(Nav). and show the current topic in the bsscright frame. and sync toc.

// call onBsscNavSync() from bsscright frame.
// there will be two situation.
// 1. Nav is visible.  Just Sync the toc.( show the Contents panel and highlight the related topic).
// 2. Nav is invisible. First Show the Nav panel. and then Sync the toc.


// onBsscNavSync(strRelHomePage) strRelHomePage is the Relative Path of the First Page, from the current page's view.
// other function will be called by onContent(). do not call them directly.

// onBsscNavSync is modified from onContents() in SyncFromTopic.js. add support DHTML sync. 

// BsscNavHasNavFrame() determine the Nav frame exists or not


var gbDHTML = false;

var strAgent   = navigator.userAgent.toLowerCase();
var strVersion = navigator.appVersion.toLowerCase();

var gnVerMajor = parseInt(strVersion);
var gnVerMinor = parseFloat(strVersion);

var gbNS     = ((strAgent.indexOf("mozilla") != -1) && ((strAgent.indexOf('spoofer') == -1) && (strAgent.indexOf('compatible') == -1)));
var gbIE     = (strAgent.indexOf("msie") != -1);
var gbOpera  = (strAgent.indexOf("opera") != -1);
var gbHotJava= (strVersion.indexOf("hotjava") != -1);

var gbWin16   = ((strVersion.indexOf("win16") != -1) || (strVersion.indexOf("windows 3.1") != -1));
var gbWindows = ((strAgent.indexOf("win") != -1) || (strAgent.indexOf("16bit") != -1));
var gbMac     = (strAgent.indexOf("mac") != -1);
var gbWebTV   = (strAgent.indexOf("webtv") != -1);
var gbSunOS   = (strAgent.indexOf("sunos") != -1);

var gbNS2         = ((gbNS) && (gnVerMajor == 2));
var gbNS3         = ((gbNS) && (gnVerMajor == 3));
var gbNS4         = ((gbNS) && (gnVerMajor >= 4));
var gbIE4         = ((gbIE) && (gnVerMajor >= 4));
var gbIE3         = ((gbIE) && (gnVerMajor <= 3));
var gbIE302before = ((gbIE3) && ((strAgent.indexOf("3.00") != -1)||(strAgent.indexOf("3.0a") != -1)||(strAgent.indexOf("3.0b")!=-1)||(strAgent.indexOf("3.01")!=-1))); 

var gbIE5	  = ((gbIE4) && (strAgent.indexOf("msie 5") != -1));

var nViewFrameType = 2;  //1: DTHTML 2:Applet 3: HTML2 list

if (gbIE4 && gbDHTML) nViewFrameType = 1;
if (gbIE4 && gbSunOS) nViewFrameType = 1;

if (gbWin16)          nViewFrameType = 3;
if (gbIE3 && gbMac)   nViewFrameType = 3;
if (gbNS2)            nViewFrameType = 3;
if (gbNS3 && gbMac)   nViewFrameType = 3;
if (gbOpera)          nViewFrameType = 3;
if (gbHotJava)        nViewFrameType = 3;
if (gbWebTV)          nViewFrameType = 3;
if (gbIE302before)    nViewFrameType = 3;

if ((gbNS4) && (window.screen) && (window.screen.colorDepth == 4))
{
   nViewFrameType = 3;
}

function BsscNavIsList() {
	return (nViewFrameType == 3 || (gbIE4 && !gbIE5 && gbMac));
}

var gbstrNavnAgent   = navigator.userAgent.toLowerCase();

var gbNavnNS    = false;
var gbNavnIE	= false;
gbNavnNS 	= ((gbstrNavnAgent.indexOf("mozilla") != -1) && ((gbstrNavnAgent.indexOf('spoofer') == -1) && (gbstrNavnAgent.indexOf('compatible') == -1)));
gbNavnIE    	= (gbstrNavnAgent.indexOf("msie") != -1);

function BsscNavHasNavFrame()
{
	var bHomePage = false;
	if(gbNavnIE)
	{
		// IE
		if ((parent) && ("object" == typeof(parent.document)) && (parent.document.frames) && (parent.document.frames.length > 1))
			if (parent.document.frames[0].name.indexOf("bsscleft") == 0) {
				bHomePage=true;
			}

	} 
	if(gbNavnNS)
	{
		// Netscape 
		if((parent)&&(parent.window.myname == "webhelp"))
			bHomePage=true;
	}
	return bHomePage;
}

// call onBsscNavHide() from bsscright frame.
// Hide the bsscleft frame(Nav). and show the current topic.
function onBsscNavHide()
{
	
	if (BsscNavHasNavFrame()) {
		var strURL = document.URL;
		if (strURL.toLowerCase().indexOf("file://") == 0) {
			strURL = _bsscnBarReplaceSpecialChar(strURL);
		}
		parent.window.location.replace(strURL);
	}
}

// call onBsscNavShow() from any frame except bsscright.
// Show the bsscleft frame(Nav). and show the current topic in the bsscright frame. and sync toc.
function onBsscNavShow(strRelHomePageShow)
{
	if (!BsscNavHasNavFrame()) {
		var strRelHomePage = _bsscnBarReplaceSlash(strRelHomePageShow);
	
		var strCurrentURL = document.URL;
		var strCurrentURL = _bsscnBarReplaceSlash(strCurrentURL);
	
		var strCurrentPath = _bsscnBarGetPath(strCurrentURL);
		var strCurrentFile = _bsscnBarGetFileName(strCurrentURL);
	
		var strAbsHomePageURL = _bsscnBarGetAbsoluteHomePageURL(strRelHomePage, strCurrentPath);
	
		var strAbsHomePagePath = _bsscnBarGetPath(strAbsHomePageURL);
		var strAbsHomePagePath = strAbsHomePagePath + "/";
	
		var startpos  = strCurrentURL.indexOf(strAbsHomePagePath);
		if (startpos != -1) {
			strRelativeURL = strCurrentURL.substring(startpos + strAbsHomePagePath.length, strCurrentURL.length);
			if (strAbsHomePageURL.toLowerCase().indexOf("file://") == 0) 
				strAbsHomePageURL = _bsscnBarReplaceSpecialChar(strAbsHomePageURL);
			location.replace(strAbsHomePageURL+"#" + strRelativeURL);
		}
	}
}

function onBsscNavSync(strRelHomePageSync)
{
	var strRelHomePage = _bsscnBarReplaceSlash(strRelHomePageSync);
	
	var strCurrentURL = document.URL;
	var strCurrentURL = _bsscnBarReplaceSlash(strCurrentURL);
	
	var strCurrentPath = _bsscnBarGetPath(strCurrentURL);
	var strCurrentFile = _bsscnBarGetFileName(strCurrentURL);
	
	var strAbsHomePageURL = _bsscnBarGetAbsoluteHomePageURL(strRelHomePage, strCurrentPath);
	
	var strAbsHomePagePath = _bsscnBarGetPath(strAbsHomePageURL);
	var strAbsHomePagePath = strAbsHomePagePath + "/";
	
	var startpos  = strCurrentURL.indexOf(strAbsHomePagePath);
	
	if (startpos != -1) {
		strRelativeURL = strCurrentURL.substring(startpos + strAbsHomePagePath.length, strCurrentURL.length);
		if (BsscNavHasNavFrame()) {
			if(gbNavnIE) {// IE
				if (parent.document.frames[0].document.applets.length > 0) {
					if (typeof(parent.document.frames[0].document.applets["webhelp"]) != "undefined") {
						parent.document.frames[0].document.applets["webhelp"].Command("SyncToc", strRelativeURL);
					}
				}
				else {
					// probably DHTML
					if (typeof(parent.document.frames[0].document.frames["Tabs"]) != "undefined") {
						var tabFrame = parent.document.frames[0].document.frames["Tabs"];
						_bsscnBarSelectTOC(strRelativeURL);
					} 
					else { // it must be list
					}
				}
			}
			else { // Probably Netscape.
				if (parent.frames[0].document.applets.length > 0) {
					if (typeof(parent.frames[0].document.applets["webhelp"]) != "undefined") {
						parent.frames[0].document.applets["webhelp"].Command("SyncToc", strRelativeURL);
					}
				}
				else {
					// probably DHTML
					if (typeof(parent.document.frames[0].document.frames["Tabs"]) != "undefined") {
						_bsscnBarSelectTOC(strRelativeURL);
					}
					else { // it must be list
					}
				}
			}
		}
		else
			//location.replace(strAbsHomePageURL+"#" + strRelativeURL);
			onBsscNavShow(strRelHomePage);
	}
}


// replace %20 to ' '
function _bsscnBarReplaceSpecialChar(strURL)
{	
	var strReplacedURL = "";
	for (i = 0; i < strURL.length; i ++ )
	{
		if (strURL.charAt(i) == '%') {
			if (strURL.substring(i + 1, i + 3) == "20") {
				strReplacedURL = strReplacedURL + " ";
				i += 2;
			}
		}
		else
		    strReplacedURL = strReplacedURL + strURL.charAt(i);
	}
	return strReplacedURL;
}


// replace \\ to /
function _bsscnBarReplaceSlash(strURL)
{	
	var strReplacedURL = "";
	for (i = 0; i < strURL.length; i ++ )
	{
		if (strURL.charAt(i) == '\\') 
			strReplacedURL = strReplacedURL + "/"
		else
		    strReplacedURL = strReplacedURL + strURL.charAt(i);
	}
	return strReplacedURL;
}

// generate absolute URL for the first page.
function _bsscnBarGetAbsoluteHomePageURL(strRelHomePage, strCurrentPath)
{
	if (strCurrentPath.charAt(strCurrentPath.length - 1) == '/') 
		strCurrentPath = strCurrentPath.substring(0, strCurrentPath.length -1);
	for (;;) {
		upDirPos = strRelHomePage.indexOf("../")
		if (upDirPos == 0) {
			DirPos = strCurrentPath.lastIndexOf("/")
			if (DirPos != -1) {
			strCurrentPath = strCurrentPath.substring(0, DirPos)
			}
			strRelHomePage = strRelHomePage.substring(3, strRelHomePage.length);
		}
		if (upDirPos != 0) break;
	}
	return strCurrentPath + "/" + strRelHomePage;
}

function _bsscnBarGetPath(strURL)
{
	pathpos = strURL.lastIndexOf("/");
	if (pathpos > 0)
		return strURL.substring(0, pathpos);
	else 
		return "";
}

function _bsscnBarGetFileName(strURL)
{
	pathpos = strURL.lastIndexOf("/");
	if (pathpos > 0)
		return strURL.substring(pathpos + 1, strURL.length);
	else
		return strURL;
}

function _bsscnBarGetTabFrame()
{
	if(gbNavnIE) {// IE
		return parent.document.frames[0];
	}
	else { // Netscape
		return parent.frames[0];
	}
}

function _bsscnBarSelectTOC(strRelativeURL)
{
	var TabFrame = _bsscnBarGetTabFrame();
	if ("function" == typeof(TabFrame.syncToc))
		TabFrame.syncToc(strRelativeURL);
}


function _bsscnBarOnError(message)
{
	if(-1 != message.indexOf("denied") 
		|| -1 != message.indexOf("Object required"))
	 return true;
}

onerror = _bsscnBarOnError;


