

//function to test whether a given frame is in scope
function isFrame(frameName) 
{
    for (var i=0;i<parent.frames.length;i++) {
         if (parent.frames[i].name == frameName)
             return true;
    }
    return false;
}

function clearToc() {
	if (isFrame("dh_masthead") == false)
	{
        try{
                if (top.toc) {
                        if (top.toc.contentsPage==0) {
                                top.toc.clearHighlighting();
                        }
                }
        }
        catch(e) {

        }
	}
}

function loadPage() {
	if (top.frames['dh_masthead'])
	{}
	else
	{
		//if the browser is Opera and the URL is other than HTTP, do not load the frameset.
		// Opera 7.5.4 fixed a security vulnerability, and that seems to prevent accessing file URLs
		try {
			var isOpera = navigator.userAgent;
			if (isOpera.indexOf('Opera') > -1 && self.location.href.indexOf('http') == -1) {

			}
			else {
				if (top.location == self.location) {
					//open the current page#hash within the frameset
					var sPath = self.location.pathname;
					//substring base filename from pathname
					var nIx = sPath.lastIndexOf("/")+1;
					sPageName = sPath.substring(nIx);
					var nIx = sPageName.lastIndexOf("\\")+1;
					sPageName = sPageName.substring(nIx);
					//use basename to display page in frameset
					urlPath = "frameset.htm?" + sPageName + self.location.hash;
					self.location.replace(urlPath);
				}
				tryTogglingMastheadButtons(0)
			}
			//if browser is IE, then highlight if the page was loaded as a search result
			if (navigator.appName.indexOf("Microsoft") > -1) {
				//filter out Opera 
				if (isOpera.indexOf('Opera') < 0 ) {
					var tocpagename = top.toc.location.pathname;
					if (tocpagename.indexOf('srchrslt.htm') != -1) {
						if (top.toc.srcMode==1) {
							highlightHits();
						}
					}
				}
			}
		self.focus();
		}
		catch(e) {

		}
	}
}

function tryTogglingMastheadButtons(lastTry) {
	if (top.masthead) {
		try {
			top.masthead.toggleNextButton();
			top.masthead.togglePrevButton();
		}
		catch(e) {
			//if masthead functions are unavailable, handle error and call function again
			setTimeout("tryTogglingMastheadButtons(1)", 6000);
		}
	}
	else{
		if (lastTry == 0) {
			//if masthead hasn't yet loaded, call this function once more
			setTimeout("tryTogglingMastheadButtons(1)", 6000);
		}
	}
}

//scroll the TreeView TOC to the current entry
function scrollToTocEntry(linkID) {
	try {
		//run the code only if the TOC tab has focus, otherwise an error will occur
		if (parent.tabInNavPane==1) {
			var folderObj;
			docObj = parent.toc.findObj(linkID);
			docObj.forceOpeningOfAncestorFolders();
			parent.toc.updateTocLink(linkID,docObj.link,'content');
			parent.toc.scrollBy(-2000,0);
		}
	}
	catch(e) {

	}
}

//function to highlight search terms
function highlightHits() {
	try {
		var str = top.toc.querytxt;
		//if exact phrase, highlight only phrase
		if (top.toc.srctype=="phrase") {
			var rng = document.body.createTextRange();
			for (var j=0; rng.findText(str,1000000,2) != false; j++) {
				rng.select();
				document.execCommand("BackColor","false","yellow");
				if (j==0) {
					//bookmark the first hit in the page
					var rngMark = rng.getBookmark();
				}
				rng.collapse(false);  
				rng.select(); 
			}
			//move to the range containing the first hit in the page
			rng.moveToBookmark(rngMark);
			rng.collapse(false);
			rng.select(); 
		}
		//highlight all terms for an all or any words search
		else {
			var querywrds = str.split(" ");
			for (var i = 0; i < querywrds.length; i++) {
				var rng = document.body.createTextRange();
				for (var j=0; rng.findText(querywrds[i],1000000,2) != false; j++) {
					rng.select();
					document.execCommand("BackColor","false","yellow");
					if (j==0) {
						//bookmark the first hit in the page
						var rngMark = rng.getBookmark();
					}
					rng.collapse(false);  
					rng.select(); 
				}
				//move to the range containing the first hit in the page
				rng.moveToBookmark(rngMark);
				rng.collapse(false);
				rng.select(); 
			}
		}
		top.toc.setSearchModeFlag(0);
	}
	catch(e) {

	}
}
 

