/* Generated by KSW */
/* DO NOT CHANGE THIS CODE MANUALLY */
     
// top.right.document.URL	:
//					IE6		:	file://D:\Web Tests\FAR\home.htm
//					Firefox	:	file:///D:/Web%20Tests/FAR/home.htm

// top.right.location.href	:
//					IE6		:	file:///D:/Web%20Tests/FAR/home.htm
//					Firefox	:	file:///D:/Web%20Tests/FAR/home.htm

// location.href			:
//					IE6		:	file:///D:/Web%20Tests/FAR/frameset_toc.htm
//					Firefox	:	file:///D:/Web%20Tests/FAR/frameset_toc.htm

/*
aref = el.getAttribute('href');	// returns the full href in Explorer
								// returns the attribute value in Firefox
					IE6		:	file:///D:/Web%20Tests/FAR/copy%20right.htm
					Firefox	:	copy right.htm	// not encoded!
*/

// unescape is reliable: correctly decodes both 2-digit and 4-digit (Unicode)
// in both IE and Firefox; JS handles Unicode all browsers

// do not use Mark of the Web; it breaks hierarchy functionality local test

var aSelected = null;	// last link (A element) selected
						// clicked or selected programmatically
var timerCount = 0;		// limit autoSync to 200 tries
						// resert to 0 after timerCoumt == 200 or after success

//pre-load hierarchy node images
var imgEmpty = new Image();
var imgMinus = new Image();
var imgPlus = new Image();
var imgDot = new Image();
imgEmpty.src = 'empty.gif';
imgMinus.src = 'minus.gif';
imgPlus.src = 'plus.gif';
imgDot.src = 'dot.gif';

function findFolder(el)	// el = any element (anchor, image, span, div)
						// find first folder that contains el
{
     while (el.id != 'wrap')
     {
          if (el.className == 'folder')
          	break;
          else
          	el = el.parentNode;				// DOM parent
     }
     return el;
}

function selectLink(aEl)	// aEl = A element; unselect last and select aEl
							// aEl only can be in a leaf (a div with class leaf)
{
	if (aSelected != null)	// unselect last link
		aSelected.className = 'unselected';

	aEl.className = 'selected';
	aSelected = aEl;
	aEl.blur();				// remove keyboard focus from this A link
}

function expandCollapse(el)	//  el = any element (image, span)
							//	expand/collapse parent folder of this el
							//	called when image or span is clicked on a folder
{
	var folder = findFolder(el);
	var imgEl = new Image();	// img el of folder
	var child;
	var i = 0;
	
	if (el == null || folder.id == 'wrap')	// should not happen
		return;

	for(i = 0; i < folder.childNodes.length; i++)
	{										// childNodes list may contain empty text nodes
		child = folder.childNodes[i];
		if (child.src)		// false if child.src == null
		{					// from now on imgEl refers img of this folder
			imgEl = child;	// requires img be the first element node
		}
		else if (child.className == 'subnodesHidden')
		{					// folder has div that wraps leaves; the only child with such classname
			child.className = 'subnodesShow';
			imgEl.src = 'minus.gif';
			showOnExpand(folder);
			break;
		}
		else if (child.className == 'subnodesShow')
		{
			child.className = 'subnodesHidden';
			imgEl.src = 'plus.gif';
			break;
		}
	}
}

function showOnExpand(el)	// el = a div with class folder
							// when expand by click, show as much of the folder as it fits
{
     var mainDiv = document.getElementById('mainDiv');	// scrolling div
     
     var viewportTop;		// distance (always positive, clicked node is visible) between
     						// top of folder div and top of the mainDiv's viewport
     						
     var y;	// height of el that is bellow the bottom of viewport
     				
     var ua = window.navigator.userAgent.toLowerCase(); // browser class
		
     // upward scroll so that expanded div (el) shows as much as it fits
     if (ua.indexOf('msie') != -1)
     	viewportTop = el.offsetTop - mainDiv.scrollTop;
     else if (ua.indexOf('gecko') != -1)	// mozilla, firefox
     	viewportTop = el.offsetTop - mainDiv.offsetTop - mainDiv.scrollTop;
     else 
     	return;	// other browsers: do not scroll at all
     	
     y = viewportTop + el.offsetHeight - mainDiv.clientHeight;
     
     if (y + 13 > 0)
     {
     	if (viewportTop <= y + 18)
     		mainDiv.scrollTop += viewportTop - 5;
     	else
     		mainDiv.scrollTop += y + 13;
     }
}

function expand(el)	//  el = any element; as called, el is always a div with class folder
					//	expand parent folder of this el
					//	called when synchronizing
{
	var folder = findFolder(el);
	var imgEl = new Image();	// img el of folder
	var child;
	var i = 0;
								// not null or 'wrap' when called
	for(i = 0; i < folder.childNodes.length; i++)
	{
		child = folder.childNodes[i];
		if (child.src)		// false if child.src == null
		{					// from now on imgEl refers img of this folder
			imgEl = child;	// requires img be the first element node
		}
		if (child.className == 'subnodesHidden')
		{
			child.className = 'subnodesShow';
			imgEl.src = 'minus.gif';
			break;
		}	// if no subnodesHidden, this func does nothing
	}
}

function runSyncFunctions(href)	// href = full url of the page on the right
								// calls findAEl and selectAndShow
{
	var aEl;
        
	// find among wrap div's A elements
	// 1. find first A element with matching href (incl params and bookmark)
	// 2. if none, find first A element with matching filename and no params 
	// or bookmark
	// 3. if none, return null (by design, all bookmark topics must have a
	// parent topic with no bookmark/params)
	aEl = findAEl(document.getElementById('wrap'), href);

	// select found A element and scroll it into view																
	if (aEl != null)
		selectAndShow(aEl);
}

function findAEl(node, href)	// find among 'node's A elements
	// href = full url to search for
	// JS strings are passed by value, location.href won't get changed !
	// 1. find first A element with matching href (incl params and bookmark)
	// 2. if none, find first A element with matching filename and no params 
	// or bookmark
	// 3. if none, return null (by design, all bookmark topics must have a
	// parent topic with no bookmark/params)
// params (?par1=1&par2=2) and bookmark (#bkm) are part of full url
// so they must match in order for the full href to match
{
	var el;			// A element to be tested
	var aref = '';	// A element href attribute to be tested
	var anchors = node.getElementsByTagName('A');
	var len = anchors.length;
	var i = 0;

	href = unescape(href);				// Scrub embedded codes

	for (i = 0; i < len; i++)
	{
		el = anchors[i];
		
		aref = el.getAttribute('href');	// returns the full href in Explorer
										// returns the attribute value in Firefox

		if (aref.substring(0, 3) == '../')	// relative href in Firefox
		{
			aref = aref.slice(2);			// leave the slash
			aref = baseLoc + aref;
		}
		
		aref = unescape(aref);				// scrub embedded codes

		if (aref == href)
			return el;
	}

	href = scrubParBkm(href);	// remove params and bookmark, in order to test 
								// for filename only
	if (href == null)
		return null;	// no params or bookmark, no need for extra test

	for (i = 0; i < len; i++)
	{
		el = anchors[i];
		
		aref = el.getAttribute('href');
		if (hasParBkm(aref) == true)
			continue;	// aref has params or bookmark, skip
										
		if (aref.substring(0, 3) == '../')	// relative href in Firefox
		{
			aref = aref.slice(2);			// leave the slash
			aref = baseLoc + aref;
		}
		
		aref = unescape(aref);				// scrub embedded codes

		if (aref == href)
			return el;
	}

	return null;
}

function selectAndShow(anode)	// anode = an A element (DOM node)
								// selects anode and scrolls it into view
{
	var folder = findFolder(anode);		// the folder div that holds the A element
	
	var mainDiv = document.getElementById('mainDiv');	// scrolling div
	
	var viewportTop;		// distance (positive or negative) between
							// top of anode and top of the mainDiv's viewport
						
	var viewportBottom;		// distance (positive or negative) between
							// bottom of anode and bottom of the mainDiv's viewport
						
	var ua = window.navigator.userAgent.toLowerCase(); // browser class
	
	selectLink(anode);
	
	if (folder != null) 
	{
		// wrap is the root div (not visible) that holds all visible nodes
		if (folder.id != 'wrap')
		{
     		do 
     		{
     			expand(folder);
     			folder = findFolder(folder.parentNode);	// parentNode may be intermidiary wrapper div
     		} while (folder != null && folder.id != 'wrap')
     	}
		
		// vertically scroll anode element into view
		if (ua.indexOf('msie') != -1)
		{
			viewportTop = anode.offsetTop - mainDiv.scrollTop;
			viewportBottom = mainDiv.clientHeight - viewportTop - anode.offsetHeight;
		}
		else if (ua.indexOf('gecko') != -1)	// mozilla, firefox
		{
			viewportTop = anode.offsetTop - mainDiv.offsetTop - mainDiv.scrollTop;
			viewportBottom = mainDiv.clientHeight - viewportTop - anode.offsetHeight;
		}
		else 
		{
			return;	// other browsers: do not scroll into view
		}
		
		if (viewportTop < 0)
		{
			mainDiv.scrollTop += viewportTop - 18;
			return;
		}
		if (viewportBottom < 0)
		{
			mainDiv.scrollTop -= viewportBottom - 18;
			return;
		}
	}
}

function scrubParBkm(url)	// url may be full or relative
							// params (?par1=1&par2=2) and bookmark (#bkm)
							// params before or after bookmark
{
	var par = url.lastIndexOf('?');
	var bkm = url.lastIndexOf('#');
	var idx;				// upper cut-off index in url
	
	if (par == -1 && bkm == -1)
		return null;		// don't need a filename anymore
	else if (par == -1 && bkm != -1)
		idx = bkm;
	else if (par != -1 && bkm == -1)
		idx = par;
	else if (par != -1 && bkm != -1)
		idx = Math.min(par, bkm);
		
	return url.substring(0, idx);
}

function hasParBkm(url)		// url may be full or relative
							// params (?par1=1&par2=2) and bookmark (#bkm)
							// params before or after bookmark
{
	var par = url.lastIndexOf('?');
	var bkm = url.lastIndexOf('#');
	
	if (par != -1 || bkm != -1)
		return true;
	else
		return false;
}

// links to other domains normally won't work because of browser security
function syncTOC()
{
	if (	window.parent.frames[1] == null					||
			window.parent.frames[1] == undefined			||
			typeof(top.right.location.href) != 'string'		||
			top.right.location.href.indexOf(baseLoc) == -1	)
		{
          	if (aSelected != null)					// unselect last link
          		aSelected.className = 'unselected';
          		
          	return false;
		}
		else
			runSyncFunctions(top.right.location.href);
}

function autoSync()	// waits for topic to load
{
	if (	window.parent.frames[1] == null					||
			window.parent.frames[1] == undefined			||
			typeof(top.right.location.href) != 'string'		||
			top.right.location.href.indexOf(baseLoc) == -1	)
	{
		timerCount++;
		if (timerCount == 100)	// max wait time is 2 seconds
		{						// after which is will not sync at all
			timerCount = 0;
			return;
		}
			
		setTimeout(autoSync, 20);
			return;
	}

	timerCount = 0;
	syncTOC();
}
