/************************************ REVISION LOG ENTRY Revision By: Mihai Filimon ( mfl@exontrol.com ) Created on 3/12/2018 10:00:00 AM Comments: faq.js, faq.css This code may be used in compiled form in any way you desire. This file may not be redistributed modified or unmodified without the authors written consent. ************************************/ var bDisableShowFilterBoxInfo = false; var filterFrameParam = "FR"; var filterParam = "F"; var filterQuestionOnlyParam = "Q"; var filterWordOnlyParam = "W"; var expandParam = "E"; var vtQuestionOnlyClass = "question-only"; var vtWordOnlyClass = "word-only"; var scrollToQuestion = null; var expandFirstItem = null; window.onload = loadPage; window.onclick = clickWindow; window.onresize = resizeWindow; window.onscroll = scrollWindow; if ( !hasFilter() ) document.onreadystatechange = readyStateChange; var collapsedSections = new Array(); var collapsedSectionsInitialized = false; function getURLHash( sURL ) { var i = sURL.indexOf('#'); if ( i > 0 ) return sURL.substr( i + 1 ); return null; } function removeURLHash(sURL) { var i = sURL.indexOf( "#" ); if ( i >= 0 ) sURL = sURL.substr( 0, i ); return sURL; } function getURLParam( sURL, Param ) { var i = sURL.indexOf('#'); sURL = i === -1 ? sURL : sURL.substr(0, i); if (sURL.indexOf("?") > 0 ) { var arrParams = sURL.split("?"); var arrURLParams = arrParams[1].split("&"); var arrParamNames = new Array(arrURLParams.length); var arrParamValues = new Array(arrURLParams.length); var i = 0; for (i = 0; i < arrURLParams.length; i++) { var sParam = arrURLParams[i].split("="); arrParamNames[i] = sParam[0]; if (sParam[1] != "") arrParamValues[i] = unescape(sParam[1]); else arrParamValues[i] = ""; } for ( i = 0 ; i < arrURLParams.length; i++) if (arrParamNames[i] == Param) return arrParamValues[i]; } return null; } function addURLParam(sURL, Param, Value) { return updateURLParameter( sURL, Param, Value ); } function removeURLParam(sURL, Param) { return updateURLParameter( sURL, Param, null ); } function updateURLParameter(uri, key, value) { var i = uri.indexOf('#'); var hash = i === -1 ? '' : uri.substr(i); uri = i === -1 ? uri : uri.substr(0, i); var re = new RegExp("([?&])" + key + "=.*?(&|$)", "i"); var separator = uri.indexOf('?') !== -1 ? "&" : "?"; if ( value ) { value = value.trim(); if (uri.match(re)) uri = uri.replace(re, '$1' + key + ( value.length ? ("=" + value) : "" ) + '$2'); else uri = uri + separator + key + ( value.length ? ("=" + value) : "" ); } else { uri = uri.replace( new RegExp("[?&]?" + key + "=[^&]*", "i"), '' ); if (uri.slice(-1) === '?') uri = uri.slice(0, -1); if (uri.indexOf('?') === -1) uri = uri.replace(/&/, '?'); // replace first occurrence of & by ? if no ? is present } return uri + hash; } function getIFrameURL( sURL ) { if ( sURL ) { var bGeneralFAQ = sURL.indexOf("/gfaq.jsp") == 0; if ( bGeneralFAQ ) sURL = sURL.replace("/gfaq.jsp", "/content/support/faq/" ); else { bGeneralFAQ = ( sURL.indexOf("/sg.jsp?content=support/faq/") == 0 ); if ( bGeneralFAQ ) sURL = sURL.replace("/sg.jsp?content=support/faq/", "/content/support/faq/"); } if ( bGeneralFAQ ) { if ( sURL.search( /(\\|\/)$/ ) < 0 ) // no \ / adds one sURL += "/"; sURL += "index.jsp"; } } return sURL; } function fixURLQuery( sURL ) { if ( sURL ) { sURL = sURL.replace("?","&"); var i = sURL.indexOf( "&" ); if ( i >= 0 ) sURL = sURL.substr( 0, i ) + "?" + sURL.substr( i + 1 ); } return sURL; } function getURL( sURL ) { if ( sURL ) { if ( sURL.indexOf("/content/products/") >= 0 ) { sURL = sURL.replace("?","&"); sURL = sURL.replace("/content/products/","/howto.jsp?product="); sURL = sURL.replace("/howto/how_to_do_","&lang="); sURL = sURL.replace(".htm", ""); sURL = fixURLQuery( sURL ); } else if ( sURL.indexOf("/content/support/faq/") >= 0 ) { sURL = sURL.replace("?","&"); sURL = sURL.replace("/content/support/faq/index.jsp","/gfaq.jsp"); sURL = sURL.replace("/content/support/faq/","/sg.jsp?content=support/faq/"); sURL = sURL.replace("index.jsp",""); sURL = fixURLQuery( sURL ); } } return sURL; } function getURLFAQ() { var sURL = document.URL.toString(); sURL = removeURLParam( sURL, filterFrameParam ); sURL = getURL( sURL ); return sURL; } function clickPage(anchor) { var f = Filter.value; if ( f.length != 0 ) if ( f != "Filter for..." ) anchor.href += "?F=" + f; } function nextID(el) { var c = el.nextElementSibling; if ( c ) { while ( c && ( el.id != c.id ) ) c = c.nextElementSibling; return c; } var c = el.nextSibling; while ( c && ( ( c.nodeType != 1 ) || ( el.id != c.id ) ) ) c = c.nextSibling; return c; } function isFrameFilterFor() { var fr = getURLParam( document.URL, filterFrameParam ); if ( fr != null ) return fr != ""; return false; } function isFilterForQ() { var frQ = getURLParam( document.URL, filterQuestionOnlyParam ); if ( frQ != null ) return frQ == "only"; return false; } function isFilterForW() { var frW = getURLParam( document.URL, filterWordOnlyParam ); if ( frW != null ) return frW == "only"; return false; } function getFilterFor( e ) { var o = e.textContent; if ( o != null ) return o; return e.innerText; } function getFilterForQ( e ) { var c = e.children; return getFilterFor(c[0]) + getFilterFor( c[1].firstElementChild ); } function filterFor(text) { onLayoutHeader(); CollapseAll( document.getElementById("toggleAllImage") ); var nResults = 0; var o = document.getElementById("question"); if ( text.length == 0 ) { while ( o != null ) { o.style.display = ""; o = nextID(o); } if ( !isFrameFilterFor() ) { var p = document.getElementById("pages"); if ( p != null ) p.style.display = ""; var c = document.getElementById("continue"); if ( c != null ) { c.innerHTML = ""; c.style.display = "none"; } } } else { // Shows only the items that match text = text.toLowerCase(); var rgFilter = new Array(); var rgAlternatives = text.split(","); var aCount = rgAlternatives.length; for ( var a = 0; a < aCount; a++ ) { var rgAlternative = new Array(); var rgFields = rgAlternatives[a].split(" "); var fCount = rgFields.length; for ( var f = 0; f < fCount; f++ ) { var sField = rgFields[f].replace(" ",""); if ( sField.length ) rgAlternative.push( sField ); } if ( rgAlternative.length ) rgFilter.push( rgAlternative ); } var l = rgFilter.length; if ( l > 0 ) { var bFilterForQ = isFilterForQ(), bFilterForW = isFilterForW(); while ( o != null ) { var s = bFilterForQ ? getFilterForQ(o) : getFilterFor(o); s = s.toLowerCase(); var bVisible = false; for ( var j = 0; !bVisible && ( j < l ); j++ ) { var i = 0, iCount = rgFilter[j].length; for ( i = 0; i < iCount; i++ ) { var w = rgFilter[j][i]; if ( bFilterForW ) { if ( s.search("\\b" + w + "\\b") == -1 ) break } else if ( s.indexOf(w) == -1) break; } bVisible = i == iCount; } o.style.display = bVisible ? "" : "none"; if ( bVisible ) nResults++; o = nextID(o); } } // Show additional information if ( !isFrameFilterFor() ) { /* var p = document.getElementById("pages"); if ( p != null ) p.style.display = "none"; */ var c = document.getElementById("continue"); if ( c != null ) { var iFrame = ""; { var f = Filter.value, iFrames = 0; if ( f.length != 0 ) { var p = document.getElementById("page"); while ( p != null ) { if (p.id=="page" ) { var s = p.getAttribute("href"); if ( s ) if ( s.length ) { s = getIFrameURL( s ); s += ( ( s.indexOf("?") > 0 ) ? "&" : "?" ) + filterFrameParam + "=" + f; if ( isFilterForQ() ) s += "&" + filterQuestionOnlyParam + "=only"; if ( isFilterForW() ) s += "&" + filterWordOnlyParam + "=only"; iFrame += ""; iFrames++; } } p = nextID(p); } try { localStorage.setItem("mainSectionFrames", iFrames ); startFilterFrames(); if ( iFrames == 0 ) endFilterFrames(); } catch (err) { } } } c.innerHTML = iFrame; c.style.display = ""; } } } var footer = document.getElementById("footerInfo"); if ( footer != null ) { var info = "", oInfo = "

<%INFO%>

"; var nURL = getURLFAQ(); if ( nURL.length > 0 ) { nURL += ( nURL.indexOf("?") > 0 ) ? "&" : "?"; nURL += "F="+ escape(text); if ( isFilterForQ() ) { nURL += ( nURL.indexOf("?") > 0 ) ? "&" : "?"; nURL += filterQuestionOnlyParam + "=only"; } if ( isFilterForW() ) { nURL += ( nURL.indexOf("?") > 0 ) ? "&" : "?"; nURL += filterWordOnlyParam + "=only"; } nURL = updateGlobalURL( nURL ); } if ( text.length != 0 ) { if ( nResults == 0 ) info = "no result(s)"; else info += nResults.toString() + " result(s)"; if ( nURL.length > 0 ) info += ", at " + nURL + ""; } oInfo = oInfo.replace( "<%INFO%>", info ); footer.outerHTML = oInfo; } } function wait() { } function InitCollapsedSections() { var i = 0; var imageId = Load("imageValue" + i); while (imageId != null) { collapsedSections[imageId] = "not expanded"; i++; imageId = Load("imageValue" + i); } } var noReentry = false; function OnLoadImage() { if (noReentry) return; if (!collapsedSectionsInitialized) { InitCollapsedSections(); collapsedSectionsInitialized = true; } elem = event.srcElement; if (ShouldExpand(elem)) { noReentry = true; try { elem.src = collapseImage.src; ExpandSection(elem); RemoveCollapsedItem(elem.id); collapsedSections[elem.id] = "expanded"; } catch (e) { } noReentry = false; } } function ShouldExpand(elem) { return (collapsedSections[elem.id] == null) || (Load("IsFirstPage") == null); } /* ********** ********** Begin ********** */ function LoadFrame(frame) { var doc = null; try { doc = frame.contentDocument || frame.contentWindow.document; } catch ( e ) { } if ( doc != null ) frame.style.height = getMainSectionHeight(doc); else { try { frame.style.height = localStorage.getItem("mainSectionHeight"); } catch ( e ) { } } try { frame.style.visibility = "visible"; if ( doc != null ) { try { var rgA = doc.getElementsByTagName("A"); if ( rgA ) { for ( var i = 0; i < rgA.length; i++ ) { var a = rgA[i]; if ( a.getAttribute("target") == null ) a.setAttribute( "target", "_top" ); } } } catch( err ) { } } var iFrames = localStorage.getItem("mainSectionFrames"); if ( iFrames ) { iFrames--; localStorage.setItem("mainSectionFrames", iFrames); if ( iFrames == 0 ) endFilterFrames(); } } catch(err) { } } function startFilterFrames() { var mainSection = document.getElementById("mainSection"); if ( mainSection ) { //mainSection.style.opacity = .5; var bottomTable = document.getElementById("bottomTable"); if ( bottomTable ) { //bottomTable.style.opacity = .5; var wait = document.getElementById("wait"); if ( wait == null ) { var newImage = document.createElement("IMG"); newImage.id = "wait"; newImage.className = "wait"; newImage.src = "http://www.exontrol.com/images/wait.gif"; newImage.style.top = Math.max( 32, mainSection.offsetTop ) + "px"; mainSection.parentElement.insertBefore( newImage, mainSection ); } else { wait.style.display = "block"; wait.style.top = mainSection.offsetTop + "px"; } } } } function endFilterFrames() { resetFilterFrames(); } function resetFilterFrames() { var mainSection = document.getElementById("mainSection"); if ( mainSection ) { mainSection.style.opacity = 1; var bottomTable = document.getElementById("bottomTable"); if ( bottomTable ) bottomTable.style.opacity = 1; var wait = document.getElementById("wait"); if ( wait != null ) wait.style.display = "none"; } onLayoutHeader(); } function getMainSectionHeight( doc ) { var h = 0, e; e = doc.getElementById("mainSection"); if ( e ) h += e.clientHeight; return h + "px"; } function addLineNumbers() { var pre = document.getElementsByTagName('pre'), pl = pre.length; for (var i = 0; i < pl; i++) addLineNumber( pre[i] ); } function addLineNumber( p ) { p.innerHTML = p.innerHTML.trim(); var num = p.innerText.replace(/\s+$/g, "").split(/\n/).length; if ( num > 1 ) { if ( num > 16 ) p.className += " lesscode"; p.innerHTML = '' + p.innerHTML; var j = 0; for (j = 0; j < num; j++) { var line_num = p.getElementsByTagName('span')[0]; line_num.innerHTML += '' + (j + 1) + ''; } if ( num > 16 ) { try { var rgBold = p.getElementsByTagName("B"); if ( rgBold ) if ( rgBold.length > 0 ) p.scrollTop = Math.max( 0, (rgBold[0].offsetTop - p.offsetTop) - p.clientHeight/2 ); // scrolls the highligted elements to the center of the
			}
			catch( err )
			{
			}
		}
	}
}

function replaceURL( sURL )
{
	try
	{
		window.history.replaceState(null,null,sURL);
		sURL = getURL( sURL );
		window.parent.history.replaceState(null,null,sURL);
	}
	catch( err )
	{
	};
}

function SetFilterPlaceHolder()
{
	var vtFilter = document.getElementById("Filter");
	if ( vtFilter )
	{
		vtFilter.placeholder = "Filter For...";
		vtFilter.value = "";
		vtFilter.title = "The space separator indicates AND between words, while comma specifies OR between words.";
		vtFilter.onkeypress = function(e) {
			if ( e )
				if ( e.keyCode == 13 )
				{
					filterFor( this.value );
					onClickGo();
				}
		}

		var vtFilterQuestionOnly = document.getElementById("btnFilterQuestionOnly");
		if ( vtFilterQuestionOnly == null )
		{
			var x = document.createElement("SPAN");
				x.appendChild( document.createTextNode("Full") );
			x.name = "btnFilterQuestionOnly";
			x.title = "The filter is applied to the full content, else the filter is applied to the visible-content only.";
			x.id = "btnFilterQuestionOnly";
			x.className = isFilterForQ() ? "" : vtQuestionOnlyClass;
			x.onclick = function( e ){
					if ( e )
						if ( e.target )
						{
							var sURL = document.URL;
								if ( e.target.className == vtQuestionOnlyClass )
									sURL = addURLParam( sURL, filterQuestionOnlyParam, "only" );
								else
									sURL = removeURLParam( sURL, filterQuestionOnlyParam );
							replaceURL( sURL );				

							var xClass = "";
							if ( e.target.className.indexOf( vtQuestionOnlyClass ) < 0 )
								xClass = vtQuestionOnlyClass;
							e.target.className = xClass;
						}
				};

			vtFilter.parentElement.insertBefore( x, document.getElementById("btnFilter") );
		}

		var vtFilterWordOnly = document.getElementById("btnFilterWordOnly");
		if ( vtFilterWordOnly == null )
		{
			var x = document.createElement("SPAN");
				x.appendChild( document.createTextNode("Word") );
			x.name = "btnFilterWordOnly";
			x.title = "The filter searches for any, else it searches for the exact word.";
			x.id = "btnFilterWordOnly";
			x.className = isFilterForW() ? vtWordOnlyClass : "";
			x.onclick = function( e ){
					if ( e )
						if ( e.target )
						{
							var sURL = document.URL;
								if ( e.target.className != vtWordOnlyClass )
									sURL = addURLParam( sURL, filterWordOnlyParam, "only" );
								else
									sURL = removeURLParam( sURL, filterWordOnlyParam );
							replaceURL( sURL );				

							var xClass = "";
							if ( e.target.className.indexOf( vtWordOnlyClass ) < 0 )
								xClass = vtWordOnlyClass;
							e.target.className = xClass;
						}
				};

			vtFilter.parentElement.insertBefore( x, document.getElementById("btnFilter") );
		}

	}
}

function SetActivePage()
{
	var pages = document.getElementById("pages");
	if ( pages )
	{
		var sURL = document.URL.toString(), p = pages.children;
		for ( var i = 0; i < p.length; i++ )
		{
			var hP = p[i].getAttribute("href");
			if ( sURL.indexOf( hP ) >= 0 )
			{
				p[i].removeAttribute("href");
				p[i].removeAttribute("title");
				p[i].className = "active";
			}
		}
	}
}

function getToggleCount()
{
	var vtResult = 0;
	expandFirstItem = null;
	try
	{
		var rgToggle = document.getElementsByClassName("toggle");
		vtResult = rgToggle.length;
		if ( vtResult > 0 )
			if ( vtResult < 16 )
				expandFirstItem = rgToggle[0];
	}
	catch( err )
	{
	}
	return vtResult;
}

function SetFilterBoxInfo()
{
	var btnFilter = document.getElementById("btnFilter");
	if ( btnFilter )
	{
		var newSpan = document.createElement("SPAN");
			var textnode = document.createTextNode( "Enter here the keywords you are looking for, separated by spaces or commas, and then press Enter key or click the Go button." );
			newSpan.appendChild(textnode);  
		newSpan.className = "arrow-box";
		newSpan.id = "filter-arrow-box";
		btnFilter.parentElement.insertBefore( newSpan, btnFilter );

		if ( getToggleCount() > 16 )
		{
			var filterFor = document.getElementById("Filter");
			if ( filterFor )
				setTimeout(function(){ showFilterBoxInfo(); }, 1000);
		}
	}
}

function setSessionItem( item, value )
{
	try
	{
		window.sessionStorage.setItem(item, value);
	}
	catch( err )
	{
	};
}

function getSessionItem( item )
{
	try
	{
		return window.sessionStorage.getItem( item );
	}
	catch( err )
	{
	};
	return null;
}

function removeSessionItem( item )
{
	try
	{
		window.sessionStorage.removeItem( item );
	}
	catch( err )
	{
	};
}

function showFilterBoxInfo()
{
	if ( getSessionItem("showFilterBoxInfo") == null )
	{
		if ( !bDisableShowFilterBoxInfo )
		{
			var bContinue = true, filterFor = document.getElementById("Filter");
			if ( filterFor )
				bContinue = filterFor != document.activeElement;

			if ( bContinue )
			{
				var filterInfo = document.getElementById("filter-arrow-box");
				if ( filterInfo )
				{
					setSessionItem("showFilterBoxInfo", "show");
					filterInfo.className = "arrow-box-show";
					setTimeout(function(){ hideFilterBoxInfo(); }, 6000);
				}
			}
		}
	}
}

function hideFilterBoxInfo()
{
	var filterInfo = document.getElementById("filter-arrow-box");
	if ( filterInfo )
		filterInfo.className = "arrow-box-hide";
}

function hasFilter()
{
    return getURLParam(document.URL, filterParam) || getURLParam(document.URL, filterFrameParam);
}

function loadPage()
{
    if ( true )
    {
		var bApplyFilter = false, vtFilter = document.getElementById("Filter");
		var sF = hasFilter();
		if ( sF != null )
			if ( sF.length > 0 )
				bApplyFilter = (vtFilter != null);

		SetActivePage();
		SetFilterPlaceHolder();
		SetCollapseAll();
		ExpandCollapseAll( document.getElementById("toggleAllImage") );
		if ( bApplyFilter )
		{
			vtFilter.value = sF;
			filterFor(sF);
		}

		if ( !bApplyFilter )
			SetFilterBoxInfo();
	}
    else
		SetToggleAllLabel( false );
    
    // vs70.js did this to allow up/down arrow scrolling, I think
    try { mainSection.setActive(); } catch(e) { }

    // make body visible, now that we're ready to render
	var sBody = "";
	if ( isFrameFilterFor() )
	{
		if ( document.getElementById("error") != null )
			sBody = "none";
		else
		{
			var h = document.getElementById("header");
			if ( h != null )
				h.style.display = "none";
			var f = document.getElementById("footer");
			if ( f != null )
				f.style.display = "none";
		}
	}
    document.body.style.display = sBody;
	parent.document.body.onhashchange = hashChange;
    
	if ( isFrameFilterFor() )
	{
		try
		{
			localStorage.setItem("mainSectionHeight", getMainSectionHeight( document ) );
		}
		catch (e)
		{
		}
	}

	onLayoutHeader();
	ensureVisibleHash();

}

function ensureVisibleHash()
{
	try
	{
		var sURL = parent.document.URL, sHash = getURLHash(sURL);
		
		var e = getURLParam( sURL, expandParam ), eID = null;
		if ( e )
			eID = "Img" + e;
		
		if ( sHash )
		{
			var vtElementsHash = parent.document.getElementsByName(sHash), bFound = false;
			if ( vtElementsHash.length )
			{
				var vtTR = vtElementsHash[0];
				while ( vtTR && vtTR.tagName != "TR" )
					vtTR = vtTR.parentElement;
				if ( vtTR )
					if ( vtTR.id == "question" )
					{
						var eIMG = vtTR.firstElementChild.firstElementChild;
						if ( eIMG )
							if ( eIMG.tagName == "IMG" )
							{
								eID = eIMG.id;
								bFound = true;
							}
					}
			}
			if ( !bFound )
				if ( e == null )
					eID = "Img" + sHash;

		}

		if ( eID )
		{
			var img = parent.document.getElementById( eID );
			if ( img )
			{
				img.parentElement.parentElement.style.display = ""; // if hash inside the page, and it is filter, it requires to be visible!
				ExpandItem( img );
				scrollToQuestion = img.parentElement.parentElement;
				if ( scrollToQuestion )
				{
					setTimeout( function()
							{
								try
								{
									if ( scrollToQuestion )
										parent.window.scrollTo( 0, scrollToQuestion.offsetTop );
									scrollToQuestion = null;
								}
								catch (err)
								{
								}
							}, 100 );
				}
			}
		}
		else
			if ( expandFirstItem != null ) // set by getToggleCount
			{
				ExpandItem(expandFirstItem);
				expandFirstItem = null;
			}

	}
	catch (err)
	{
	}
}

function onLayoutHeader()
{
/*
	var header = document.getElementById("header");
	if ( header )
	{
		var mainSection = document.getElementById("mainSection");
		if ( mainSection )
		{
			var headerTableRow2 = document.getElementById("headerTableRow2");
			if ( headerTableRow2 )
			{
				var pages = document.getElementById("pages");
				if ( 1 || window.pageYOffset || getURLParam( document.URL, expandParam ) || document.getElementById("Filter").value || headerTableRow2.style.whiteSpace.length )
				{
					if ( pages )
					{
						pages.style.cssFloat = "right";
						pages.style.position = "relative";
						pages.style.marginBottom = "-" + (pages.clientHeight) + "px";
						pages.style.borderBottom = "0px";
					}

					headerTableRow2.style.whiteSpace = "nowrap";
					header.style.position = "fixed";

					// offsets-down all from mainSection
					var e = mainSection, t = header.clientHeight + "px";
					while ( e )
					{
						e.style.position = "relative";
						e.style.top = t;

						e = e.nextElementSibling;
					}
				}
				else
				{
					if ( pages )
					{
						pages.style.cssFloat = "";
						pages.style.position = "";
						pages.style.marginBottom = "";
						pages.style.borderBottom = "";
					}
					headerTableRow2.style.whiteSpace = "";
					header.style.position = "";
					mainSection.style.position = "";
					mainSection.style.top = "";
				}
			}
		}
	}
*/
}

function resizeWindow( e )
{
	onLayoutHeader();
}

function scrollWindow( e )
{
	onLayoutHeader();
	hideFilterBoxInfo();
}

function readyStateChange(e)
{
	document.body.style.display = "block";
}

function hashChange()
{
	ensureVisibleHash();
}

function clickWindow( e )
{
	var bHideFilterBoxInfo = true;

	var tag = e.target.tagName;
	if ( tag )
	{
		if ( tag == "INPUT" )
		{
			var name = e.target.name;
			if ( name )
				if ( name == "btnFilter" )
				{
					bHideFilterBoxInfo = false;
					onClickGo();
				}
				else
					if ( name == "btnClear" )
						onClickClear();
		}
		else
			if ( tag == "IMG" )
			{
				var p = e.target.parentElement.parentElement;
				if ( p != null )
					if ( p.className == "code" )
						previewImg( e.target );
			}
			else
			{
				if ( e.offsetY < 8 )
				{
					if ( tag == "PRE" ) // select code
						selectCode(e.target);
					else
						if ( tag == "P" ) // toggle preview
							previewImg( e.target.firstElementChild );
				}
				else
					if ( tag == "PRE" )
					{
						if ( e.offsetY > e.target.clientHeight - 8 ) // copy
							copyToClipboard( e.target );
					}
					else
						if ( tag == "DIV" ) // share code
							if ( e.offsetY > e.target.clientHeight )
								shareCode( e.target );
			}
	}

	if ( bHideFilterBoxInfo )
		hideFilterBoxInfo();

	bDisableShowFilterBoxInfo = true;

}

function onClickGo()
{
	var sURL = document.URL, sOURL = sURL;
	var filterFor = document.getElementById("Filter").value;
	if ( ( filterFor == null ) || ( filterFor.length == 0 ) )
	{
		bDisableShowFilterBoxInfo = false;
		removeSessionItem("showFilterBoxInfo");
		showFilterBoxInfo();
		sURL = removeURLParam(sURL, filterParam);
	}
	else
		sURL = addURLParam(sURL, filterParam, filterFor);
	if ( sOURL != sURL )
		replaceURL( sURL );				
}

function onClickClear()
{
	resetFilterFrames();
	window.scrollTo( 0, 0 );

	var sURL = document.URL;
		sURL = removeURLHash(sURL);
		sURL = removeURLParam(sURL, filterParam);
		sURL = removeURLParam(sURL, expandParam);
	replaceURL( sURL );				
}

function selectURL( sURL )
{
	if ( sURL )
	{
		try
		{
			window.parent.parent.location = sURL;
		}
		catch ( err )
		{
		}
	}
}

function updateGlobalURL( sURL )
{
	if ( sURL )
	{
		try
		{
			var sProduct = "product";
			var vtProduct = getURLParam( window.parent.parent.location.href, sProduct );
			if ( vtProduct )
				sURL = addURLParam( sURL, sProduct, vtProduct );
/*
			var sContent = "content";
			var vtContent = getURLParam( window.parent.parent.location.href, sContent );
			if ( vtContent )
				sURL = addURLParam( sURL, sContent, vtContent );
*/
		}
		catch ( err )
		{
		}
	}
	return sURL;
}


function shareCode( div )
{
	if ( div )
	{
		try
		{
			var sURL = getURL( location.href.replace( filterFrameParam+"=",filterParam+"=" ) ); /*replace the FR with F*/
			sURL = removeURLHash(sURL);

			// shares the hash, in case it contains 
			var sHash = null;
			if ( div.children.length )
			{
				var a = div.children[0];
				if ( a.tagName == "A" )
				{
					sHash = a.getAttribute("name");
					if ( sHash )
						if ( sHash.length )
							sURL += "#" + sHash;
				}
			}

			if ( sHash == null ) // shares the E instead
			{
				var sE = div.parentElement.parentElement.firstElementChild.innerText.replace(":","").replace(" ","");
				sURL = addURLParam( sURL, expandParam, sE );
			}

			if ( isFilterForQ() )
				sURL = addURLParam( sURL, filterQuestionOnlyParam, "only" );

			if ( isFilterForW() )
				sURL = addURLParam( sURL, filterWordOnlyParam, "only" );

			sURL = updateGlobalURL(sURL);

			selectURL( sURL );
		}
		catch ( err )
		{
		}
	}
}

function previewImg( img )
{
	if ( img )
	{
		img.className = img.className.length == 0 ? "preview" : "";
/*
		if ( img.style.height == "auto" )
		{
			img.style.maxHeight = e.target.style.height;
			img.style.height = e.target.style.height;
			img.style.opacity = 0.5;
		}
		else
		{
			img.style.maxHeight = "600%";
			img.style.height = "auto";
			img.style.opacity = 1;
		}
*/
	}
}

function addTogglePreview( img )
{
	if ( img )
	{
		var p = img.parentElement;
		if ( p )
			if ( p.tagName == "P" )
				if ( p.className.length == 0 )
					if ( img.height > 128 )
						p.className = "preview";
	}
}

function selectCode( e )
{

	var sel = window.getSelection();
	if (sel)
	{
		sel.removeAllRanges();

		var range = document.createRange();

		try
		{
			var span = e.firstChild, s = span;
			if ( span )
				if ( span.tagName == "SPAN" )
					if ( span.className == "line-number" )
						s = span.nextSibling;
			range.setStartBefore(s);
			range.setEndAfter(e.lastChild);

		}
		catch( er )
		{
			var span = e.firstChild;
			if ( span )
				if ( span.tagName == "SPAN" )
					if ( span.className == "line-number" )
						span.style.display = "none";

			range.selectNodeContents(e);
		};
		sel.addRange(range);
	}
}

function copyToClipboard(e)
{
	var bSuccess = false;
	var sel = window.getSelection();
	if (sel)
	{
		selectCode(e);
		if ( bSuccess = document.execCommand('copy') )
			sel.removeAllRanges();
	}
	return bSuccess;
}

var collapsedItems = new Array();

function ExpandItem(imageItem)
{
	if ( imageItem )
	{
		imageItem.src = collapseImage.src;
		ExpandSection(imageItem);
		RemoveCollapsedItem(imageItem.id);

		onExpandCollapse();
	}
}

function CollapseItem(imageItem)
{
	if ( imageItem )
	{
		imageItem.src = expandImage.src;
		CollapseSection(imageItem);
		AddCollapsedItem(imageItem.id);

		onExpandCollapse();
	}
}

function onExpandCollapse()
{
	SetCollapseAll();

	if ( isFrameFilterFor() )
	{
		try
		{
			var f = window.frameElement;
			if ( f != null )
				f.style.height = getMainSectionHeight( document );
		}
		catch (e)
		{
		}
	}
}

function ExpandCollapse(imageItem)
{
	if ( imageItem )
	{
		var bContinue = true;
		try
		{
			if ( event )
				if ( event.target.tagName == "DIV" ) // share code
					if ( event.offsetY > event.target.clientHeight )
						bContinue = false;
		}
		catch( err )
		{
		};

		if ( bContinue )
		{
			noReentry = true; // Prevent entry to OnLoadImage
    
			if( ItemCollapsed(imageItem.id) == true )
				ExpandItem( imageItem );
			else
				CollapseItem( imageItem );
		
			noReentry = false;
		}
	}
}

function CollapseAll(imageItem)
{
    noReentry = true; // Prevent entry to OnLoadImage
    
    var imgElements = document.getElementsByName("toggleSwitch");
    var i;
	
	imageItem.src = expandAllImage.src;
	AddCollapsedItem(imageItem.id);
	for(i = 0; i < imgElements.length; ++i)
	{
		wait();
		imgElements[i].src = expandImage.src;
		CollapseSection(imgElements[i]);
		AddCollapsedItem(imgElements[i].id);
	}
	SetToggleAllLabel(true);
	
    noReentry = false;
}

function ExpandHeaderInfo(e,b)
{
	e.className = b ? "" : "collapsed";
}

function isLoading()
{
	try
	{
		return event.type == "load";
	}
	catch( err )
	{
	}
	return false;
}

function ExpandHeaderInfos()
{
	if ( !isLoading() )
	{
		var rgInfos = document.getElementsByName("infos");
		if ( rgInfos )
		{
			for ( var iInfo = 0; iInfo < rgInfos.length; iInfo++ )
				ExpandHeaderInfo( rgInfos[iInfo], true );
		}
	}
}

function CollapseHeaderInfos()
{
	if ( !isLoading() )
	{
		var rgInfos = document.getElementsByName("infos");
		if ( rgInfos )
		{
			for ( var iInfo = 0; iInfo < rgInfos.length; iInfo++ )
				ExpandHeaderInfo( rgInfos[iInfo], false );
		}
	}
}

function ExpandCollapseAll(imageItem)
{
	if ( imageItem )
	{
		noReentry = true; // Prevent entry to OnLoadImage
    
		var imgElements = document.getElementsByName("toggleSwitch");
		var i;
		
		if(ItemCollapsed(imageItem.id) == true)
		{
			ExpandHeaderInfos();
			imageItem.src = collapseAllImage.src;
			RemoveCollapsedItem(imageItem.id);
			for(i = 0; i < imgElements.length; ++i)
			{
				wait();
				imgElements[i].src = collapseImage.src;
				ExpandSection(imgElements[i]);
				RemoveCollapsedItem(imgElements[i].id);
			}
			SetToggleAllLabel(false);
		}
		else
		{
			CollapseHeaderInfos();
			imageItem.src = expandAllImage.src;
			AddCollapsedItem(imageItem.id);
			for(i = 0; i < imgElements.length; ++i)
			{
				wait();
				imgElements[i].src = expandImage.src;
				CollapseSection(imgElements[i]);
				AddCollapsedItem(imgElements[i].id);
			}
			SetToggleAllLabel(true);
		}
		
		noReentry = false;
	}
}

function ExpandCollapse_CheckKey(imageItem)
{
	if ( imageItem )
		if(window.event.keyCode == 13)
    		ExpandCollapse(imageItem);
}

function ExpandCollapseAll_CheckKey(imageItem)
{
	if ( imageItem )
		if(window.event.keyCode == 13)
			ExpandCollapseAll(imageItem);
}

function ExpandSection(imageItem)
{
	if ( imageItem )
		if ( imageItem.parentElement != null )
		{
			var c = imageItem.parentElement.parentElement.children;
			if ( c.length == 2 )
			{

				var cAnswer = c[1].children["answer"];
				if ( cAnswer )
				{
					cAnswer.style.display = "block";
					cAnswer.parentElement.className = "answere";
					c[0].style.background = "#f4f4f4";

					try
					{
						var cQuote = cAnswer.firstElementChild.firstElementChild;
						if ( cQuote )
						{
							try
							{
								// Adds line numbers once the user expands section
								var rgPre = cQuote.getElementsByTagName("PRE");
								if ( rgPre.length )
								{
									for ( var iPre = 0; iPre < rgPre.length; iPre++ )
									{
										var pre = rgPre[iPre];
										if ( pre.getElementsByClassName )
										{
											var ln = pre.getElementsByClassName( "line-number" );
											if ( ln )
												if ( ln.length == 0 )
													addLineNumber( pre );
										}
										else
											break;
									}
								}
							}
							catch( err )
							{
							}

							try
							{
								var rgImg = cQuote.getElementsByTagName("IMG");
								if ( rgImg.length )
								{
									for ( var iImg = 0; iImg < rgImg.length; iImg++ )
										addTogglePreview( rgImg[iImg] );
								}
							}
							catch (err)
							{
							}

						}
					}
					catch( err )
					{
					}
				}
			}
		}
}

function CollapseSection(imageItem)
{
	if ( imageItem )
		if ( imageItem.parentElement != null )
		{
			var c = imageItem.parentElement.parentElement.children;
			if ( c.length == 2 )
			{
				c[0].style.background = "";

				var cAnswer = c[1].children["answer"];
				if ( cAnswer )
				{
					cAnswer.style.display = "none";
					cAnswer.parentElement.className = "";
				}
			}
		}
}

function SetCollapseAll()
{
    var imageElement = document.getElementById("toggleAllImage");
	
    if(imageElement == null)
	return;

    var imgElements = document.getElementsByName("toggleSwitch");
    var allCollapsed = true;
    var i, l = imgElements.length;
		
    for(i = 0; i < l; ++i)
    {
        wait();
        allCollapsed = allCollapsed && ItemCollapsed(imgElements[i].id)
    }
	
    if(allCollapsed)
    {
        imageElement.src = expandAllImage.src;
        AddCollapsedItem(imageElement.id);
    }
    else
    {
    	imageElement.src = collapseAllImage.src;
    	RemoveCollapsedItem(imageElement.id);
    }
	
    SetToggleAllLabel(allCollapsed);

}

function SetToggleAllLabel(allCollapsed)
{
    var labelElement;
    labelElement = document.getElementById("collapseAllLabel");

    if(labelElement == null)
    	return;
		
    labelElement.style.display = "none";
	
    labelElement = document.getElementById("expandAllLabel");
    labelElement.style.display = "none";
	
    if(allCollapsed)
    {
    	labelElement = document.getElementById("expandAllLabel");
    	labelElement.style.display = "";
    }
    else
    {
		labelElement = document.getElementById("collapseAllLabel");
		labelElement.style.display = "";
    }
}

function ItemCollapsed(imageId)
{
    var i;
	
    for(i = 0; i < collapsedItems.length; ++i)
    {
        wait();
        if(imageId == collapsedItems[i])
    	return true;
    }
    return false;
}

function AddCollapsedItem(imageId)
{	
    collapsedItems[collapsedItems.length] = imageId;
}

function RemoveCollapsedItem(imageId)
{
    var i;
	
    for(i = 0; i < collapsedItems.length; ++i)
    {
        wait();
        if(imageId == collapsedItems[i])
	    collapsedItems.splice(i, 1);
    }
}

function OpenSection(imageItem)
{
    if(ItemCollapsed(imageItem.id) == true)
	    ExpandCollapse(imageItem);
}

function ClickHRefInside( e )
{
	if ( e )
	{
		var rgA = e.getElementsByTagName("A");
		if ( rgA.length == 1 )
			selectURL( rgA[0].href );
	}
}

function ExpandHeaderGroup( e )
{
	if ( e )
		e.parentElement.parentElement.className = e.parentElement.parentElement.className.length == 0 ? "collapsed" : "";
}