﻿// Copyright (c) 1997-2009 Wolfgang Henderkes
// http://www.eTOK.de - HomePage of eTraining Operating Kit.
// Lizenz - license: Creative Commons, see http://creativecommons.org/licenses/by-nc-sa/3.0/de/ *
   // * Autor/Rechteinhaber ist Wolfgang Henderkes. - Author/licensor is Wolfgang Henderkes, Germany.
   // * Der Kopf in den Quelltexten muss unverändert erhalten bleiben. - The header of all sources must not be changed.
   // * Das eTOK-Logo muss unverändert erhalten bleiben. - The eTOK-Logo must not be changed.
// Version 2.8 (30.03.2009)


// Global variables.
var bBrowser1 = false; // W3C-Browser.
var bBrowser2 = false; // Microsoft Internet Explorer.
var bTotalEvaluationMCT1; // Set in »book.js«, if "MCT" was activated during export.
var bTextSearch1; // Set in »book.js« and »pedia.js«, if "Search" was activated during export.
var bIndexSearch1; // Set in »book.js« and »pedia.js«, if "Search" was activated during export.
var oDiv1; // Reference on div "NavBar".
var oDiv3; // Reference on div "Options".
var vAppTyp1; // Application type: "b" for a Book, "p" for a Pedia.
var vToC1; // Table of content. Set in »book.js« and in »pedia.js«.
var vDesign1 = "01"; // Start value for a design due to the desired format_xx.css. Value is stored in a cookie.
var vDivWidth1; // Width of div "NavBar".
var vDivHeigth1;  // Distance of div "NavBar" from bottom.
var vHelp1 = "on"; // Start value for the help status. Value is stored in a cookie.
var vLastPage1; // Set in »book.js« and in »pedia.js«. Last page of application will be generated during export of eTOK. 
var vNavBar1 = '<table id="NavBarTable"><tr><td class="OuterTableLeft"><a href="javascript:previousPage()" onMouseover="changeImage(&quot;PreviousPage&quot;, &quot;o&quot;);return true;" onMousedown="changeImage(&quot;PreviousPage&quot;, &quot;d&quot;)" onMouseup="changeImage(&quot;PreviousPage&quot;, &quot;&quot;)" onMouseout="changeImage(&quot;PreviousPage&quot;, &quot;&quot;);return true;"><img src="ref/previouspage_01.gif" id="PreviousPage"></a></td><td class="InnerTable">';
var vNavBar2 = '</td><td class="OuterTableRight"><a href="javascript:nextPage()" onMouseover="changeImage(&quot;NextPage&quot;, &quot;o&quot;);return true;" onMousedown="changeImage(&quot;NextPage&quot;, &quot;d&quot;)" onMouseup="changeImage(&quot;NextPage&quot;, &quot;&quot;)" onMouseout="changeImage(&quot;NextPage&quot;, &quot;&quot;);return true;"><img src="ref/nextpage_01.gif" id="NextPage"></a></td></tr></table>';
var vPageNumber1; // Actual page number.
var vPedia1 = "V1"; // Start value for the desired pedia variant. Value is stored in a cookie.
var vTotalMCT1 = ""; // Keeps all MCT evaluations during session. Used in »mct.js«


// Start.
geteTOKDesign(); // Get the selected design.
geteTOKHelp(); // Get help status.
if (self.name.indexOf("Variant") > -1) document.write('<link rel=stylesheet type="text/css" href="ref/format_' + vDesign1 + '.css">');
else document.write('<link rel=stylesheet type="text/css" href="ref/format.css">'); // start.htm uses own CSS.
getPageNumber(); // Get the actual page number out of the file name.


$(document).ready(function()
	{
	checkBrowser();
	document.getElementById('NavBar').innerHTML = vNavBar1 + vPageNumber1 + vNavBar2;
	getNavBarDimension();
	setEnvironment();

	// Blind effect for ToC in variant 2.
	$("#ToC").click(function()
		{
		$(".BlindFx").toggle("blind", {direction: "vertical"}, 800);
		});

	// Shows total MCT evaluation for variant 2 in current page.
	$("#TotalEvaluationMCT").click(function()
		{
		showTotalEvaluationMCT();
		});


	// Hide ToC in V1 and scroll ToC V2 to 0 px.
	if (self.name.indexOf("Variant2") > -1)
		{
		$('#TreeMenu').SimpleTree({animate: true, autoclose:true, click:function(el){alert($(el).text());}});

		$(".BlindFx").toggle("blind", {direction: "vertical"}, 0); // Div height is 0 so the blind effect is invisible.

		// Set desired values instead of format_xx.css.
		document.getElementById("V2ToC").style.height = "460px";
		document.getElementById("V2ToC").style.padding = "10px 0 0 0"; // Needed for IE 7.
		document.getElementById("V1ToC").style.width = "0px";
		document.getElementById("V1ToC").style.visibility = "hidden";
		document.getElementById("Content").style.margin = "0 12em 1em 0em";
		}

	// Show ToC in V1.
	if (self.name.indexOf("Variant1") > -1)
		{
		// Set desired values instead of format_xx.css.
		document.getElementById("V1ToC").style.width = "18em";
		vToC1 += '<ul>';
		if (bTextSearch1) vToC1 += '<li class="SearchToC"><a href="#" onClick="startTextSearch();">' + vDOK55 + '</a></li>';
		if (bTotalEvaluationMCT1) vToC1 += '<li class="TotalEvaluationMCTToC"><a href="#" onClick="showTotalEvaluationMCT();">' + vDOK37 + '</a></li>';
		vToC1 += '</ul>';
		document.getElementById("V1ToC").innerHTML = vToC1;
		document.getElementById("V1ToC").style.visibility ="visible";
		document.getElementById("Content").style.margin = "0 12em 1em 16em";
		}

	$("div.roundedCorner").corner("10px"); // Round corners of all divs class="roundedcorner".
	$("#ImageShow").draggable(); // 
	$("#Controls").draggable(); 
	if (document.getElementById("Tabs")) 
		{
		$('#Tabs > ul').tabs({ selected: null, unselect: true });
		}
	});


// Shows total MCT evaluation in current page.
function showTotalEvaluationMCT()
	{
	if (document.getElementById('TotalEvaluation').style.visibility=="hidden")
		{
		// Slide out existings divs.
		if (self.name.indexOf("Variant1") > -1) $("#V1ToC").toggle("slide", {direction: "left"}, 500);
		$("#Info").toggle("slide", {direction: "right"}, 500);
		setTimeout('$("#Content").toggle("slide", {direction: "down"}, 500)', 500);
		setTimeout('$("#Header").toggle("slide", {direction: "up"}, 500)', 1000);

		// Manipulate div "TotalEvaluation".
		getTotalEvaluationMCT(); // Calls function in »mct.js«.
		setTimeout('document.getElementById("TotalEvaluation").style.visibility="visible"', 1500);
		if (self.name.indexOf("Variant1") > -1) document.getElementById("TotalEvaluation").style.margin = "0 0 0 18em";
		setTimeout('document.getElementById("TotalEvaluation").innerHTML = vTotalMCT1', 1500); // Fills div.

		// Slide in div ToC.
		setTimeout('$("#V1ToC").toggle("slide", {}, 500)', 2000);
		}
	else
		{
		// Slide out divs "ToC" and "TotalEvaluation".
		if (self.name.indexOf("Variant1") > -1) $("#V1ToC").toggle("slide", {direction: "left"}, 500);
		$("#TotalEvaluation").toggle("blind", {}, 500); // Scale empty div to 0.
		setTimeout('document.getElementById("TotalEvaluation").innerHTML = ""', 1000); // Clear div.
		setTimeout('$("#TotalEvaluation").toggle("blind", {}, 0)', 1000); // Scale div to normal size.
		setTimeout('document.getElementById("TotalEvaluation").style.visibility="hidden"', 1000); // Set it hidden.

		// Slide in existings divs.
		setTimeout('$("#Header").toggle("slide", {direction: "up"}, 500)', 1000);
		setTimeout('$("#Info").toggle("slide", {direction: "right"}, 500)', 1500);
		if (self.name.indexOf("Variant1") > -1) setTimeout('$("#V1ToC").toggle("slide", {}, 500)', 1500);
		setTimeout('$("#Content").toggle("scale", {}, 0)', 2000);
		}
	}


function getNavBarDimension()
	{
	vDivHeigth1 = "40";
	vDivWidth1 = "200";
	document.getElementById('NavBarTable').style.width = vDivWidth1 + "px";
	}


// Check browser.
function checkBrowser()
	{
	if (navigator.userAgent.indexOf("Opera")>-1)
		{
		bBrowser1 = true;
		}
	else
		{
		if (navigator.appName=="Microsoft Internet Explorer")
			{
			bBrowser2 = true;
			}
		else
			{
			if (document.getElementById)
				{
				bBrowser1 = true;
				}
			else
				{
				alert(vDOK5);
				}
			}
		}
	}


function seteTOKDesign(v1)
	{
	var vCookie1 = "eTOKDesign";
	oDate1 = new Date(); 
	oDate1.setTime (oDate1.getTime() + (1000 * 60 * 60 * 24 * 2922)); // Cookie lasts 8 years.
	document.cookie = vCookie1 + "=" + escape (v1) + "; expires=" + oDate1.toGMTString();
	}


function geteTOKDesign()
	{
	var vCookie1 = "eTOKDesign";
	var vCookieContent1 = document.cookie.split(/;/);
	for (var i=0; i<vCookieContent1.length; i++)
		{
		vCookieContent1[i] = vCookieContent1[i].split(/=/);
		if (unescape(vCookieContent1[i][0]).indexOf(vCookie1) > -1) vDesign1 = unescape(vCookieContent1[i][1]);
		}
	}


function seteTOKHelp(v1)
	{
	var vCookie1 = "eTOKHelp";
	oDate1 = new Date(); 
	oDate1.setTime (oDate1.getTime() + (1000 * 60 * 60 * 24 * 2922)); // Cookie lasts 8 years.
	document.cookie = vCookie1 + "=" + escape (v1) + "; expires=" + oDate1.toGMTString();
	}


function geteTOKHelp()
	{
	var vCookie1 = "eTOKHelp";
	var vCookieContent1 = document.cookie.split(/;/);
	for (var i=0; i<vCookieContent1.length; i++)
		{
		vCookieContent1[i] = vCookieContent1[i].split(/=/);
		if (unescape(vCookieContent1[i][0]).indexOf(vCookie1) > -1) vHelp1 = unescape(vCookieContent1[i][1]);
		}
	}


function seteTOKPedia(v1)
	{
	var vCookie1 = "eTOKPedia";
	oDate1 = new Date(); 
	oDate1.setTime (oDate1.getTime() + (1000 * 60 * 60 * 24 * 2922)); // Cookie lasts 8 years.
	document.cookie = vCookie1 + "=" + escape (v1) + "; expires=" + oDate1.toGMTString();
	}


function geteTOKPedia()
	{
	var vCookie1 = "eTOKPedia";
	var vCookieContent1 = document.cookie.split(/;/);
	for (var i=0; i<vCookieContent1.length; i++)
		{
		vCookieContent1[i] = vCookieContent1[i].split(/=/);
		if (unescape(vCookieContent1[i][0]).indexOf(vCookie1) > -1) return unescape(vCookieContent1[i][1]);
		else 
			{
			if (self.name.indexOf("Variant1") > -1) return "V1";
			if (self.name.indexOf("Variant2") > -1) return "V2";
			}
		}
	}


// Called from »mct.js«.
function seteTOKTotalMCT(v1)
	{
	var vCookie1 = "eTOKMCT";
	v1 = geteTOKTotalMCT() + v1 + ";;";
	oDate1 = new Date(); 
	oDate1.setTime (oDate1.getTime() + (1000 * 60 * 60 * 24 * 1)); // Cookie lasts 24 hours.
	document.cookie = vCookie1 + "=" + escape (v1) + "; expires=" + oDate1.toGMTString();
	}


// Called from »mct.js«.
function geteTOKTotalMCT()
	{
	var vCookie1 = "eTOKMCT";
	var vCookieContent1 = document.cookie.split(/;/);
	for (var i=0; i<vCookieContent1.length; i++)
		{
		vCookieContent1[i] = vCookieContent1[i].split(/=/);
		if (unescape(vCookieContent1[i][0]).indexOf(vCookie1) > -1) return unescape(vCookieContent1[i][1]);
		else return "";
		}
	}


// Set start conditions.
function setEnvironment()
	{
	changeImage();
	initMovableDivs(); 

	if (self.name.indexOf("Variant2") > -1)
		{
		setOptions(); 
		oDiv3.visibility = "visible";
		}
	}


// Called from div "NavBar".
function previousPage()
	{
	// Local variables.
	var vValue1;
	var vValue2;

	// Start value.
	vValue1 = vPageNumber1 - 1;

	if (vValue1<0) alert(vDOK3);
	else
		{
		vValue2 = escape(vValue1).length;
		if (vValue2=="1") vValue1 = "000" + vValue1;
		if (vValue2=="2") vValue1 = "00" + vValue1;
		if (vValue2=="3") vValue1 = "0" + vValue1;
		document.location.href = vAppTyp1 + "_" + vValue1 + ".htm";
		}
	}


// Called from div "NavBar".
function nextPage()
	{
	// Local variables.
	var vValue1;
	var vValue2;

	// Start value.
	vValue1 = vPageNumber1 + 1;

	if (vValue1>vLastPage1) alert(vDOK3);
	else
		{
		vValue2 = escape(vValue1).length;
		if (vValue2=="1") vValue1 = "000" + vValue1;
		if (vValue2=="2") vValue1 = "00" + vValue1;
		if (vValue2=="3") vValue1 = "0" + vValue1;
		document.location.href = vAppTyp1 + "_" + vValue1 + ".htm";
		}
	}


// Called from function setEnvironment().
// Get the actual page number and the application type out of the filename.
// Stored both in global variables.
function getPageNumber()
	{
	// Local variables.
	var vPath1;
	var vPathLength1;
	var vSeparator1 = "_";
	var vSeparator2 = ".";
	var vNumber1;
	var vNumber2;
	var vNumber3;

	// Start values.
	vPath1 = document.location.pathname;
	vPathLength1 = vPath1.length;

	for(i=1; i<=50; i++) 
		{
		vNumber1 = vPath1.charAt(vPathLength1-i);
		if (vNumber1==vSeparator1) 
			{
			vNumber2 = vPathLength1 - i;
			vAppTyp1 = vPath1.charAt(vPathLength1-i-1);
			break;
			}
		}

	for(i=1; i<=50; i++) 
		{
		vNumber1 = vPath1.charAt(vPathLength1-i);
		if (vNumber1==vSeparator2)
			{
			vNumber3 = (vPathLength1-i);
			break;
			}
		}

	vPageNumber1 = vPath1.substring(vNumber2+1, vNumber3);
	vPageNumber1 = parseFloat(vPageNumber1);
	}


// Called from div "NavBar" and function setEnvironment().
// v1 = id of the image, i.e "previouspage" or "nextpage".
// v2 = the type of the image, i.e. "" and "01" = standard, "o" and "01o" = mouseover, "d" and "01d" = mousedown, "e" and "01e" = end.
// v1 and v2 = null, when called from function setEnvironment().
function changeImage(v1, v2)
	{
	if (v1=="PreviousPage" || v1=="NextPage") v2 = vDesign1 + v2;
	var oImage1;
	oImage1 = document.getElementById(v1);
	if (oImage1) 
		{
		v1 = v1.toLowerCase();
		if (vPageNumber1!=vLastPage1 && vPageNumber1!=0)
			{
			oImage1.src = "ref/" + v1 + "_" + v2 + ".gif";
			}
		else
			{
			if (vPageNumber1==0)
				{
				if (v1!="previouspage") oImage1.src = "ref/" + v1 + "_" + v2 + ".gif";
				if (v1=="previouspage") document.getElementById("PreviousPage").src = "ref/previouspage_" + vDesign1 + "e" + ".gif";
				}
			if (vPageNumber1==vLastPage1)
				{
				if (v1!="nextpage") oImage1.src = "ref/" + v1 + "_" + v2 + ".gif";
				if (v1=="nextpage") document.getElementById("NextPage").src = "ref/nextpage_" + vDesign1 + "e" + ".gif";
				}
			}
		}
	else
		{
		if (vPageNumber1==0)
			{
			document.getElementById("PreviousPage").src = "ref/previouspage_" + vDesign1 + "e" + ".gif";
			document.getElementById("NextPage").src = "ref/nextpage_" + vDesign1 + ".gif";
			}
		if (vPageNumber1==vLastPage1)
			{
			document.getElementById("PreviousPage").src = "ref/previouspage_" + vDesign1 + ".gif";
			document.getElementById("NextPage").src = "ref/nextpage_" + vDesign1 + "e" + ".gif";
			}
		if (vPageNumber1!=vLastPage1 && vPageNumber1!=0)
			{
			document.getElementById("PreviousPage").src = "ref/previouspage_" + vDesign1 + ".gif";
			document.getElementById("NextPage").src = "ref/nextpage_" + vDesign1 + ".gif";
			}
		}
	}


// Called from setEnvironment().
// Initialize movable div NavBar.
function initMovableDivs()
	{
	if (bBrowser2)
		{
		oDiv1 = document.all.NavBar.style;
		oDiv3 = document.all.Options.style;
		}
	else
		{
		if (bBrowser1)
			{
			oDiv1 = document.getElementById("NavBar").style;
			oDiv3 = document.getElementById("Options").style;
			}
		}
	setPositionNavBar();
	}
  

function getXOffset()
	{
	if (bBrowser1) return window.pageXOffset;
	if (bBrowser2)
		{
		if (document.documentElement && document.documentElement.clientHeight)
			{
			return document.documentElement.scrollLeft; // >= IE 7.
			}
		else
			if (document.body)
				{
				return document.body.scrollLeft; // <= IE 6.
				}
		}
	}


function getYOffset()
	{
	if (bBrowser1) return window.pageYOffset;
	if (bBrowser2)
		{
		if (document.documentElement && document.documentElement.clientHeight)
			{
			return document.documentElement.scrollTop; // >= IE 7.
			}
		else
			if (document.body)
				{
				return document.body.scrollTop; // <= IE 6.
				}
		}
	}


function getBrowserWidth()
	{
	if (bBrowser1) return window.innerWidth;
	if (bBrowser2)
		{
		if (document.documentElement && document.documentElement.clientHeight)
			{
			return document.documentElement.clientWidth; // >= IE 7.
			}
		else
			if (document.body)
				{
				return document.body.clientWidth; // <= IE 6.
				}
		}
	}


function getBrowserHeigth()
	{
	if (bBrowser1) return window.innerHeight;
	if (bBrowser2)
		{
		if (document.documentElement && document.documentElement.clientHeight)
			{
			return document.documentElement.clientHeight; // >= IE 7.
			}
		else
			if (document.body)
				{
				return document.body.clientHeight; // <= IE 6.
				}
		}

	}


// Move div after scrolling or resizing window.
// Called by setPositionNavBar().
function moveNavBar(v1, v2)
	{
	if (bBrowser1)
		{
		oDiv1.left = v1 + "px";
		oDiv1.top = v2 + "px";
		}
	else
		{
		if (bBrowser2)
			{
			oDiv1.posLeft = v1;
			oDiv1.posTop = v2;
			}
		}
	}


// Set position of div "NavBar" and start timer to keep position when scrolling or resizing window.
// Called from showOnlineHelp() and initMovableDivs().
function setPositionNavBar()
	{
	moveNavBar(Math.round((getBrowserWidth() + getXOffset() - vDivWidth1) / 2), getBrowserHeigth()  + getYOffset() - vDivHeigth1 - 20);
	setTimeout("setPositionNavBar()", 1000);
	}


// Called from switchHelp() and div "Options".
function showOnlineHelp(v1)
	{
	geteTOKHelp();
	if (vHelp1=="on")
		{
		// Write the online help into "NavBar".
		if (v1!="")
			{
			document.getElementById('NavBar').innerHTML = '<table width=' + vDivWidth1 + '><tr><td><center><span style="background-color:#FFCF18; padding:0px; font-size: 0.8em;">' + v1 + '</span></center></td></tr></table>';
			}
		}
	}


// Called from switchHelp() and div "Options".
function hideOnlineHelp(v1)
	{
	if (self.name=="Start")
		{
		document.getElementById('NavBar').innerHTML = "";
		}
	else
		{
		document.getElementById('NavBar').innerHTML = vNavBar1 + vPageNumber1 + vNavBar2;
		getNavBarDimension();
		setPositionNavBar();
		changeImage();
		}
	}


// Called from div "Options".
// Toggle online help.
function switchHelp()
	{
	geteTOKHelp();
	if (vHelp1=="on")
		{
		vHelp1 = "off";
		seteTOKHelp("off");
		hideOnlineHelp();
		}
	else 
		{
		vHelp1 = "on";
		seteTOKHelp("on");
		showOnlineHelp(vDOK12);
		}
	}


// Called from setOptions().
// Returns the button for text search, if option was activated during export. Set in »book.js«.
function showTextSearchButton()
	{
	// Local variable.
	var vTextSearch1;

	vTextSearch1 = '<a href="#" onClick="startTextSearch();" onfocus="if(this.blur) this.blur();" onMouseover="showOnlineHelp(vDOK15); changeImage(&quot;Search&quot;, &quot;01o&quot;); return true;" onMousedown="changeImage(&quot;Search&quot;, &quot;01d&quot;)" onMouseup="changeImage(&quot;Search&quot;, &quot;01&quot;)" onMouseout="changeImage(&quot;Search&quot;, &quot;01&quot;); hideOnlineHelp();"><img src="ref/search_01.gif" border="0" id="Search"></a>';
	if (bTextSearch1) return vTextSearch1;
	else return "";
	}


// Called from setOptions().
// Returns the button for MCT evaluation, if option was activated during export. Set in »book.js«.
function showTotalEvaluationMCTButton()
	{
	// Local variable.
	var vTotalEvaluationMCT1;

	vTotalEvaluationMCT1 = '<a href="#" onfocus="if(this.blur) this.blur();" onMouseover="showOnlineHelp(vDOK17); changeImage(&quot;TotalEvaluationMCT&quot;, &quot;01o&quot;); return true;" onMousedown="changeImage(&quot;TotalEvaluationMCT&quot;, &quot;01d&quot;)" onMouseup="changeImage(&quot;TotalEvaluationMCT&quot;, &quot;01&quot;)" onMouseout="changeImage(&quot;TotalEvaluationMCT&quot;, &quot;01&quot;); hideOnlineHelp();"><img src="ref/totalevaluationmct_01.gif" border="0" id="TotalEvaluationMCT"></a>';
	if (bTotalEvaluationMCT1) return vTotalEvaluationMCT1;
	else return "";
	}


function setOptions()
	{
	document.getElementById('Options').innerHTML = '<a href="#" onfocus="if(this.blur) this.blur();" onMouseover="showOnlineHelp(vDOK7); changeImage(&quot;ToC&quot;, &quot;01o&quot;); return true;" onMousedown="changeImage(&quot;ToC&quot;, &quot;01d&quot;);" onMouseup="changeImage(&quot;ToC&quot;, &quot;01&quot;);" onMouseout="changeImage(&quot;ToC&quot;, &quot;01&quot;); hideOnlineHelp(); return true;"><img src="ref/toc_01.gif" border="0" id="ToC"></a>' +
	showTextSearchButton() + showTotalEvaluationMCTButton() + '<div id="V2ToC" class="BlindFx"></div>'; 
	document.getElementById('V2ToC').innerHTML = vToC2;
	}


// Called from $(document).ready(function() and showTextSearchButton().
// Opens the »textsearch.htm« for full text search.
function startTextSearch()
	{
	window.open("textsearch.htm","Search","scrollbars,toolbar=no,menubar=no,resizable,width=265,height=600");
	}


// Called from a global in a Book page.
// A global link is opened in the Pedia variant last used. If no Pedia has been opened yet, the Pedia will be displayed in the same variant as Book.
function linkToPedia(v1)
	{
	if (vGlobalPedia1 != "") v1 = vGlobalPedia1 + "pedia/" + v1;
	else v1 = "../pedia/" + v1;
	if (geteTOKPedia()=="V1") window.open(v1, "PediaVariant1", "scrollbars,toolbar,menubar,resizable,width=960,height=720");
	if (geteTOKPedia()=="V2") window.open(v1, "PediaVariant2", "scrollbars,toolbar,menubar,resizable,width=960,height=720");
	}


// Index search. //
// Selection of 3 -25 chars will start on mouse up the index search in the pedia. The index search is a kind of auto link for every word.
// The selected chars will be send to the »indexsearch.htm«, opened in the same called "Search" frame like the »textsearch.htm«.
// Search is executed automatically.

if (bIndexSearch1) document.onmouseup = checkClick;

// Check for selected text.
function checkSelection()
	{
	return getSelectedText(window.top);
	}


// Get selected text.
function getSelectedText(o1)
	{
	// Lokal variables.
	var vText1;

	if (window.getSelection) // Opera and Firefox!
		{
		vText1 = escape(o1.window.getSelection());
		if (vText1.substring(vText1.length-3, vText1.length) == "%20") // Filter white spaces at the end.
			{
			vText1 = vText1.substring(0, vText1.length-3)
			}
		if (vText1.substring(0, 3) == "%20") // Filter white spaces at the beginning.
			{
			vText1 = vText1.substring(3, vText1.length)
			}
		}
	else
		{
		if (document.getSelection) // Konqueror!
			{
			vText1 = escape(o1.document.getSelection());
			if (vText1.substring(vText1.length-3, vText1.length) == "%20") // Filter white spaces at the end.
				{
				vText1 = vText1.substring(0, vText1.length-3)
				}
			if (vText1.substring(0, 3) == "%20") // Filter white spaces at the beginning.
				{
				vText1 = vText1.substring(3, vText1.length)
				}
			}
		else
			{
			if (document.selection) // IE.
				{
				vText1 = o1.document.selection.createRange().text;
				if (vText1.substring(vText1.length-1, vText1.length) == " ") // Filter white spaces at the end.
					{
					vText1 = vText1.substring(0, vText1.length-1)
					}
				if (vText1.substring(0, 1) == " ") // Filter white spaces at the beginning.
					{
					vText1 = vText1.substring(1, vText1.length)
					}
				}
			}
		}

	if (vText1)
		{
		return (vText1);
		}
	return "";
	}


function checkClick()
	{
	window.event;
	checkSelection();
	if (checkSelection().length > 3 && checkSelection().length < 25)
		{
		openIndexSearch();
		document.getElementById("Content").focus();
		}
	}


// Open index search..
function openIndexSearch() 
	{
	var vURL1;

	// Path from Book.
	if (vGlobalPedia1 != "") vURL1 = vGlobalPedia1 + "pedia/indexsearch.htm?";
	else vURL1 = "../pedia/indexsearch.htm?";
	if(self.name.substring(0,5)=="Pedia") vURL1 = "indexsearch.htm?";

	if (checkSelection().length > 0)
		{
		vURL1 = vURL1 + checkSelection();
		window.open (vURL1, 'Search', 'scrollbars=1,toolbar=0,menubar=0,resizable=1,width=265,height=600');
		}
	return false;
	}
// End index search. //


// Not in use at this time.
// Option in Variant 1 to hide and show ToC.
function hideV1ToC()
	{
	document.getElementById("V1ToC").style.width= "0px";
	document.getElementById("V1ToC").style.visibility="hidden";
	document.getElementById("Content").style.margin= "0 12em 1em 0em";
	}


function showV1ToC()
	{
	document.getElementById("V1ToC").style.width= "18em";
	document.getElementById("V1ToC").style.visibility="visible";
	document.getElementById("Content").style.margin= "0 12em 1em 16em";
	}

