/******************************************************************************
*
*    $RCSfile: mzrt_bsihelp.js,v $
*   $Revision: 1.14 $
*     $Author: Steve.Harned $
*       $Date: 2010/05/14 13:58:05 $
*
* Copyright (c) 2001;  Bentley Systems, Inc., 690 Pennsylvania Drive, 
*                      Exton PA, 19341-1136, USA.  All Rights Reserved.
*
*
* JavaScript functions for Bentley Systems, Inc. Documentation Group
*	written: April 20, 2001   author: Steve Harned
*
* These functions are used in the online help file to implement the search
* feature in the Tool Index. One additional required function is in the help
* file named toolindex.html, this is the function fnGetObjCount().
******************************************************************************/


function fnToggleDisplay(currElem)
{
	var docObj = 'parent.tindex.document.all'
	var styleObj = '.style'
	var re, patrn, tempstr, tstr
	var toolname, chosen, dom
	var f = document.form1
	var findstr = f.FilterField.value
	if (findstr.length > 1) {
                tstr = findstr
                findstr = tstr.replace ('*', '.')
		tempstr = ""
	} else {
		if (findstr == "*") {
			findstr = "."
			tempstr = ""
		} else {
			tempstr = "^"
		}
	}
	patrn = tempstr.concat(findstr)
	re = new RegExp(patrn, "i")
	dom = eval(docObj + '.' + currElem + styleObj)
	toolname = dom.toolname
	chosen = re.test(toolname)
	if (!chosen) {
		dom.display = "none"
	}
	else {
		dom.display = "inline"
	}
}

function fnToggleAll()
{
	var str1 = "obj"
	var i
	var count = parent.tindex.fnGetObjCount()
	for (i=0; i < count; i++) {
		nxtObj = str1.concat(i.toString())
		fnToggleDisplay(nxtObj)
	}
}

function Clear()
{
	var f = document.form1
	f.FilterField.value=""
	fnToggleAll()
}


function getLocalFile(fn) {
        var X, Y, sl, a, ra, link, baseloc, regexp;
        ra = /mk:/;                                             // It's looking for the (mk:) characters.
        baseloc = location.href;
        a = location.href.search(ra);                           // It searches the location of the current document
        if (a == 0)                                             // If it finds mk:@MSITStore:D 
        {
                X = 14;                                         // the location of the CHM begins with char 14
                sl="\\";
        }
        else                                                    // else it starts with the 7th character.
        {
                X = 8;
                sl = "/";                                       // It then looks for the last backslash character
        }
        Y = location.href.lastIndexOf(sl)+1;                    // it includes that character as the last in the dir.
	ra = /http:/;
	a = location.href.search(ra);
	if (a == 0)
	{
		link = baseloc.substring(0, Y) + fn;
	}
	else
	{
	        link = 'file:///' + baseloc.substring(X, Y) + fn;  // It returns the path found, plus the passed in file name.
		link = unescape(link);
	}
        return link;                   
}

function openLocalFile (fname) {
	var lclfile = getLocalFile(fname);
	window.open(lclfile, 'winname', 'status=yes,resizable=yes,scrollbars=yes,height=480,width=640', false);
}

function riSwitch (sIdVar, bOpen)
{
	var oImg = document.all.item('pm_'+sIdVar);
        if (bOpen)
        {
		if (oImg!=null)
			oImg.src="figures/rdOpen.gif";
        }
        else
        {
		if (oImg!=null)
			oImg.src="figures/rdClosed.gif";
        }
}

function showPane (idVariable)
{

	var oDiv = document.getElementById(idVariable);

        //display the section if it's not displayed, hide it if it is displayed
        if (oDiv.style.display=="none")
        {
                oDiv.style.display="inline";
		riSwitch(oDiv.id, true);
	}
        else
        {
                oDiv.style.display="none";
		riSwitch(oDiv.id, false);
        }
}

function kiShareLink (helpString)
{
        var X, Y, link, baseloc;

        baseloc = location.href;
        X=baseloc.lastIndexOf("\\")+1;
        Y=baseloc.lastIndexOf("::");
        link = baseloc.substring(X, Y);

        kiSharedLink.innerHTML="<OBJECT ID='kiLink' TYPE='application/x-oleobject'" +
                        "CLASSID='clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11'>" +
                        "<param name='Command' value='Related Topics'>" +
                        "<param name='Window' value='$global_mainWindow'>" +
                        "<param name='Item1' value='title;ms-its:" + link + "::/" + helpString + "'>" +
                        "</OBJECT>";
        kiLink.Click(); 
}

function tiShareLink (helpString)
{
        tiSharedLink.innerHTML="<OBJECT ID='tiLink' TYPE='application/x-oleobject'" +
                        "CLASSID='clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11'>" +
                        "<param name='Command' value='ALink'>" +
			"<param name='Flags' value=',,1'>" +
                        "<param name='Window' value='$global_mainWindow'>" +
			"<param name='Item1' value=''>" +
                        "<param name='Item2' value='" + helpString + "'>" +
                        "</OBJECT>";
        tiLink.Click(); 
}

function fnFindNext()
{
	var cNum, nextNum, nextPage;
	cNum = getPageNum();
	nextNum = cNum + 1;
	if ( nextNum <= PageMax )
	{
		nextPage = getProdName() + nextNum.toString() + ".html";
		window.navigate (nextPage);
	}
}

function fnFindPrev()
{
	var cNum, prevNum, prevPage;
	cNum = getPageNum();
	prevNum = cNum - 1;
	prevPage = getProdName() + prevNum.toString() + ".html";
	window.navigate (prevPage);
}

function getLinkTarget()
{
  passedURL = location.href;
  aryPassedURL = passedURL.split("#");
  linkTarget = aryPassedURL[1];
  return linkTarget;
}

function showLinkTarget()
{
  var passedURL, aryPassedURL, linkTarget;
  var oTarget, oTargParentS2, aryS2list, s2Item, s2Enum, i;
  var oSelect, oSelTextRange;
  passedURL = location.hash;

  if (passedURL != "")
  {
	linkTarget = passedURL.substr(1);
	oTarget = document.anchors(linkTarget);
	aryS2list = document.getElementsByTagName("DIV");
	s2Enum = new Enumerator (aryS2list);
	i = 0;
	for ( ; !s2Enum.atEnd(); s2Enum.moveNext() ) {
		i = i + 1;
		s2Item = s2Enum.item();
		if (s2Item.contains (oTarget)) {
			riSwitch(s2Item.id, true);
			s2Item.style.display = "inline";
		}
	}
  }
}

function fnShowAllHidnSects()
{
  var aryHidnSects, sectEnum, sectItem, showbtn, hidebtn, classType;
  aryHidnSects = document.getElementsByTagName("DIV");
  sectEnum = new Enumerator(aryHidnSects);
  for (; !sectEnum.atEnd(); sectEnum.moveNext() ) {
	sectItem = sectEnum.item();
	classType = sectItem.getAttribute("className");
	switch (classType) {
		case "hidden_object":
			sectItem.style.display = "none";
			break;
		case "hidden_footnote":
			sectItem.style.display = "none";
			break;
		default:
			sectItem.style.display = "inline";
			riSwitch(sectItem.id, true);
	}
  }
  showbtn = document.getElementById("showallbtn");
  //showbtn.detachEvent('onclick', fnShowAllHidnSects);
  showbtn.style.display = "none";
  hidebtn = document.getElementById("hideallbtn");
  hidebtn.attachEvent('onclick', fnRollUpAllHidnSects);
  hidebtn.style.display = "inline";
}


function fnRollUpAllHidnSects()
{
  var aryHidnSects, sectEnum, sectItem, classType, showbtn, hidebtn;
  aryHidnSects = document.getElementsByTagName("DIV");
  sectEnum = new Enumerator(aryHidnSects);
  for (; !sectEnum.atEnd(); sectEnum.moveNext() ) {
	sectItem = sectEnum.item();
	classType = sectItem.getAttribute("className");
	switch (classType) {
		case "hidden_sect2":
			sectItem.style.display = "none";
			riSwitch(sectItem.id, false);
			break;
		case "hidden_sect3":
			sectItem.style.display = "none";
			riSwitch(sectItem.id, false);
			break;
		case "hidden_sect4":
			sectItem.style.display = "none";
			riSwitch(sectItem.id, false);
			break;
		case "hidden_procedure":
			sectItem.style.display = "none";
			riSwitch(sectItem.id, false);
			break;
		case "hidden_toolset":
			sectItem.style.display = "none";
			riSwitch(sectItem.id, false);
			break;
		case "hidden_dlgctrl":
			sectItem.style.display = "none";
			riSwitch(sectItem.id, false);
			break;
		case "hidden_footnote":
			sectItem.style.display = "none";
			break;
	}
  }
  showbtn = document.getElementById("showallbtn");
  //showbtn.detachEvent('onclick', fnRollUpAllHidnSects);
  //showbtn.attachEvent('onclick', fnShowAllHidnSects);
  hidebtn = document.getElementById("hideallbtn");
  hidebtn.style.display = "none";
  showbtn.style.display = "inline";
  //showbtn.title = "Show All";
}


function fnPageSetup()
{
  var aryHidnSects, sectEnum, sectItem, classType;
  var showbtn, needShowAllBtn;
  needShowAllBtn = "false";
  aryHidnSects = document.getElementsByTagName("DIV");
  sectEnum = new Enumerator(aryHidnSects);
  for (; !sectEnum.atEnd(); sectEnum.moveNext() ) {
	sectItem = sectEnum.item();
	classType = sectItem.getAttribute("className");
	switch (classType) {
		case "hidden_sect2":
			needShowAllBtn = "true";
		case "hidden_procedure":
			needShowAllBtn = "true";
		case "hidden_toolset":
			needShowAllBtn = "true";
		case "hidden_dlgctrl":
			needShowAllBtn = "true";
	}
  }

  showbtn = document.getElementById("showallbtn");
  if (needShowAllBtn == "true") {
	showbtn.style.display = "inline";
  	showbtn.attachEvent("onclick", fnShowAllHidnSects);
	showbtn.title = "Show All";
  } else {
	if (showbtn) {
		showbtn.style.display = "none";
	}
  }
}

var mouseState = 0;

function fnInitPage() {
	fnPageSetup();
	showLinkTarget();
}

function fnSelChange() {
 	if (document.selection.type != "none" && mouseState == 0) {
		var trItem = document.selection.createRange();
		if (trItem.text != "") {
			var trParnt = trItem.parentElement();
			trParnt.scrollIntoView(true);
		}
	}
	
}

function fnMsUp() {
	mouseState = 0;
}
function fnMsDn() {
	mouseState = 1;
}

function fnShowInfo(sMsg) {
	var oDiv = document.createElement("DIV");
	document.body.appendChild(oDiv);
	oDiv.innerHTML = "<br>" + sMsg + "<br>";
}


document.attachEvent('onselectionchange', fnSelChange);
document.attachEvent('onmousedown', fnMsDn);
document.attachEvent('onmouseup', fnMsUp);

window.attachEvent('onload', fnInitPage);
window.attachEvent('onfocus', showLinkTarget);

