 // Create the Table of Contents (TOC) Structure
			
				//alert00 = "text array length=" + engtext.length + " Last entry=" + activeText[engtext.length-1];
				//console.log(alert00);
    function createTOC() {
	var idx = -1;						// Paper number index
	//var tidx = -1;						// Title idx
	paper_start_idx = new Array (197);	// Index into the activeTextArray for the start of a paper's actual text
	titleRow = -1;
	restOfEntry = "";
	rowType = "";
	srt_no = "";
	
	//alert("@16 script02 createTOC begun");
	// Set activetext to activeWindow language
		//switch (activeWindow)
		//{
			//case 1: switchLanguage(Col1Language,0); break;
			//case 2: switchLanguage(Col2Language,0); break;
			//case 3: switchLanguage(Col3Language,0); break;
			//default: alert("script02:20-This should never happen");
		//}
	
	tocHtml = "<div id=\"paperTOC\" class=\"paperTOCclass\">";
	 
 	for (var j = 0; j < activeText.length; j++)
		{
			
			srt_no = parse_row(activeText[j]);				// Get srt_no and restofEntry
			
			// Look for Paper titles and update the index array and create the TOC html
						
				if (rowType == "T")										// It's a TITLE/New Paper
						{	
						idx++;
						paper_start_idx[idx] = j;
						threeDigitSRT = srt_no;
						if(threeDigitSRT.length == 1){threeDigitSRT = "00" + threeDigitSRT;}
						if(threeDigitSRT.length == 2){threeDigitSRT = "0" + threeDigitSRT;}
						if(threeDigitSRT == "000"){threeDigitSRT = "FWD";}						
						switch (threeDigitSRT)
						{
							case "001": tocHtml+="&nbsp;<span class=\"tocPart\">&nbsp;PART I&nbsp;</span> "; break;
							case "032": tocHtml+="&nbsp;<span class=\"tocPart\">&nbsp;PART II&nbsp;</span> "; break;
							case "057": tocHtml+="&nbsp;<span class=\"tocPart\">&nbsp;PART III&nbsp;</span> "; break;
							case "120": tocHtml+="&nbsp;<span class=\"tocPart\">&nbsp;PART IV&nbsp;</span> "; break;
						}

						tocHtml+= " <a href=\"#Col" + activeWindow + srt_no + "\"" + " class=\"tooltip tocItem\">&nbsp;" + threeDigitSRT + "&nbsp;</a>"

						}
											
			// End of TOC entry creation
			}
		tocHtml+= "</div>";		

		//srt_no = parse_row(activeText[j]);
				
		document.getElementById("toc_body").innerHTML=tocHtml;
		
		//console.log("tocHtml=" + tocHtml);
		
	return;
    };
		
 // End TOC Structure Creation
 
 // Create the TOC Title Tables for the Tooltipster

    function createTOCtitletables() {
	var idx = -1;						// Paper number index
	var tidx = -1;						// Title idx
	TitleArray = new Array (2000);		// All Paper and Section Titles			
 	TitleIdxArray = new Array (197);	// Starting location/pointer into TitleArray (used to facilitate performance)
	titleRow = -1;
	restOfEntry = "";
	rowType = "";
	srt_no = "";
	
	//alert("@82 script02: createTOCtitles begun, activeWindow=" + activeWindow + " Col1Language=" + Col1Language);
	
	tocHtml = "<div id=\"paperTOC\" class=\"paperTOCclass\">";
	 
 	for (var j = 0; j < activeText.length; j++)
		{
			
			srt_no = parse_row(activeText[j]);				// Get srt_no and restofEntry
			
			// Create TitleArray and TitleArrayIdx entries depending on the row type (Part, Paper Title, or Section Title)
						
				if (rowType == "T")										// It's a TITLE/New Paper
						{	
						idx++;
						paper_start_idx[idx] = j;
						tidx++;
						TitleIdxArray[idx] = tidx;							// Add index to Title Index Array
						TitleArray[tidx] = srt_no + "|" + restOfEntry;		// Add Title to the Title Array
						}
							
				if (rowType == "S")										// It's a SECTION
						{
						tidx++;
						TitleArray[tidx] = srt_no + "|" + restOfEntry;			// Add entry to Title Index Array
						}
					
			// End of TOC entry creation
			}
		
		//for (u = 0; u<10; u++) {console.log("TitleIdxArray[u]=" + u + " Entry=" + TitleIdxArray[u]);}
		//for (v = 0; v<100; v++) {console.log("TitleArray[v]="    + v + " Entry=" + TitleArray[v]);}
		
	return;
    };
 // End Create the TOC Title Tables for the Tooltipster
 
 // Load the Forward based on the array selected in the Language dropdown, or startup default (2nd entry, if multiple languages present)
 
 	function loadForeword(targetCol){
		
		targetCol = Number(targetCol);
		if (targetCol == 0)		// Do nothing
			{}
			else				// Normal Processing
			{
		
			
			if (loadThisPaper != "0")			// If a url variable was passed to load a specific paper?
				{
				start_at = get_Idx(loadThisPaper);
				loadThis = loadThisPaper;
				}
			else
				{
				start_at = get_Idx("0");
				loadThis = "0";
				}
					
			switch(targetCol)
				{
					
				case 1: {
							//alert("@106 script02:Loading Foreword into col1, title=" + pTitle + " start_at=" +start_at );
					      	document.getElementById("Col1").innerHTML=format_paper(loadThis,start_at,targetCol); // Load the Foreword
							document.getElementById("Col1Title").innerHTML=pTitle;  // Load the Paper title
							
							window.scrollTo(0, 0);
							document.getElementById('Col1').scrollTop = 0;
							break;
					}	
				case 2: {
					
					      	document.getElementById("Col2").innerHTML=format_paper(loadThis,start_at,targetCol); // Load the Foreword
							document.getElementById("Col2Title").innerHTML=pTitle;
							
							window.scrollTo(0, 0);
							document.getElementById('Col2').scrollTop = 0;
							break;
						  }
				case 3: {
					      	document.getElementById("Col3").innerHTML=format_paper(loadThis,start_at,targetCol); // Load the Foreword
							document.getElementById("Col3Title").innerHTML=pTitle;
							
							window.scrollTo(0, 0);
							document.getElementById('Col3').scrollTop = 0;
							break;
						   }
				}
			}
			return;
			}
// End of TOC & Foreword creation/load

// Set activeText array based on Language Selection
 
			function switchLanguage(languageSelected, targetCol){
				activeLanguage = languageSelected;	// Set new activeLanguage
				switch(languageSelected)
				{
				case 1: {
					activeText = rusuftext;
					//alert("@145 script02: About to loadForeword" + "..targetCol=" + targetCol + activeText);
					if (targetCol != 0){loadForeword(targetCol);}  // Load Foreword
					break;
					}
				case 2: {
					activeText = engtext;
					if (targetCol != 0){loadForeword(targetCol);}  // Load Foreword
					break;
					}
				case 3: {
					activeText = rusnytext;
					if (targetCol != 0){loadForeword(targetCol);}  // Load Foreword
					break;
					}
				case 4: {
					activeText = fretext;
					if (targetCol != 0){loadForeword(targetCol);}  // Load Foreword
					break;
					}
				case 5: {
					activeText = spatext;
					if (targetCol != 0){loadForeword(targetCol);}  // Load Foreword
					break;
					}
				case 6: {
					activeText = portext;
					if (targetCol != 0){loadForeword(targetCol);}  // Load Foreword
					break;
					}
				case 7: {
					activeText = rustext;
					if (targetCol != 0){loadForeword(targetCol);}  // Load Foreword
					break;
					}
				case 8: {
					activeText = turtext;
					if (targetCol != 0){loadForeword(targetCol);}  // Load Foreword
					break;
					}
				case 9: {
					activeText = fastext;
					if (targetCol != 0){loadForeword(targetCol);}  // Load Foreword
					break;
					}
				case 10: {
					activeText = nldtext;
					if (targetCol != 0){loadForeword(targetCol);}  // Load Foreword
					break;
					}
				case 11: {
					activeText = esttext;
					if (targetCol != 0){loadForeword(targetCol);}  // Load Foreword
					break;
					}
				case 12: {
					activeText = fintext;
					if (targetCol != 0){loadForeword(targetCol);}  // Load Foreword
					break;
					}
				case 13: {
					activeText = gertext;
					if (targetCol != 0){loadForeword(targetCol);}  // Load Foreword
					break;
					}
				case 14: {
					activeText = grctext;
					if (targetCol != 0){loadForeword(targetCol);}  // Load Foreword
					break;
					}
				case 15: {
					activeText = huntext;
					if (targetCol != 0){loadForeword(targetCol);}  // Load Foreword
					break;
					}
				case 16: {
					activeText = itatext;
					if (targetCol != 0){loadForeword(targetCol);}  // Load Foreword
					break;
					}
				case 17: {
					activeText = littext;
					if (targetCol != 0){loadForeword(targetCol);}  // Load Foreword
					break;
					}
				case 18: {
					activeText = poltext;
					if (targetCol != 0){loadForeword(targetCol);}  // Load Foreword
					break;
					}
				case 19: {
					activeText = routext;
					if (targetCol != 0){loadForeword(targetCol);}  // Load Foreword
					break;
					}
				case 20: {
					activeText = swetext;
					if (targetCol != 0){loadForeword(targetCol);}  // Load Foreword
					break;
					}
				case 21: {
					activeText = koruftext;
					if (targetCol != 0){loadForeword(targetCol);}  // Load Foreword
					break;
					}
				case 22: {
					activeText = aratext;
					if (targetCol != 0){loadForeword(targetCol);}  // Load Foreword
					break;
					}
				case 23: {
					activeText = korcmtext;
					if (targetCol != 0){loadForeword(targetCol);}  // Load Foreword
					break;
					}
				case 24: {
					activeText = rusuftext;
					if (targetCol != 0){loadForeword(targetCol);}  // Load Foreword
					break;
					}
				default: {
					//alert("weird default logic entered");
					}
								
				}

				currentLang = languageSelected;
				return;
				}

// END: Set activeText array based on Language Selection

// Create Context Menu Popup
	function contextMenu(resultClicked){

	//console.log('resultClicked=' + resultClicked);
	 
	var refSep = resultClicked.indexOf(" ");		// Idx of first blank that separates the ref# from the text
	var refStr = resultClicked.substring(0,refSep);
	var refText = 	resultClicked.substring(refSep);

	var htmlout = "<table width =\"100%\"><tr>";		 
	htmlout += "<td align=center class=\"printSelected\"><a href=\"#\" title=\"Print\"><img src=\"images/printerIcon.png\" alt=\"PRINT\" title=\"PRINT\"></a></td>"
	var selectedResult = "<td align=center ><a href=\"mailto:?subject=Urantia Book Quote&body=" + refStr + " " + refText + "\"  ><img src=\"images/emailIcon.png\"  height=\"24\" width=\"30\" title=\"Email\"  alt=\"Email\"  width=\"30\" height=\"24\"></a></td></tr></table><br/><br/>";
	htmlout += selectedResult;
	htmlout += " <div id=\"printThis\"><span style=\"font-size:10px; color:#006; font-weight: bold\">" + refStr + " <span style=\"font-size:12px; color:#006; font-weight: normal\">" + refText + "</span></div>";

			// Create Original English Dialog Box Options
			var dbOpt = {
				autoOpen: false,
				modal: false,
				width:285,
				height:325,
				title: 'Selected Text Options',
				show: 'slow',
				position: 'right'
				};

     $('#engText').html(htmlout);					// load the appropriate paper into the hidden div
	 $('#engText').dialog(dbOpt).dialog("open");		// Open the dialog box (w/ Modal set to false to allow main window scrolliing)
	//alert("DialogBox s/b open now!");
	return;
	}
	
	function hilites(source, find) {
  		hiLocs = [];
  		for(i=0;i<source.length; ++i) {

    	if (source.substring(i, i + find.length) == find) 
		{
      	hiLocs.push(i);
    	}
  }
  return hiLocs;
}