// JavaScript script00.js
			
		//SET DEFAULTS FOR STARTUP
		    $("select#Col1country_id").val("1");				// Clear select lists for Firefox
			$("select#Col2country_id").val("2");				// Clear select lists for Firefox
			$("select#Col3country_id").val("4");				// Clear select lists for Firefox
			$("select#partSelector_id").val("1");				// Clear select lists for Firefox
			$("select#typeSelector_id").val("0");				// Clear select lists for Firefox
			$('#srtPap').val('');
			$('#srtSec').val('');
			$('#srtPar').val('');		
		
			var ver = "v1.0";			
			$('#version').text(ver);		// set the version number
									
			sPart  = "All";
			sType  = "All";
			sEntry = "All";		
			localize(1);			
						
			firstUse = "Y";					// Set to clear the search box on first focus (ONLY)
			$('#search_terms').focus(function(){
				if (firstUse == "Y")
				{firstUse = "N";
				$('#search_terms').val('');
				}
			});				
			
			// CHECK IF A URL PARAMETER(S) WAS PASSED, e.g., a paper number
			 loadThisPaper = "0";
			 var urlString = window.location.search.substring(1);
			 var urlArray = urlString.split('&');
			  for(var i = 0; i < urlArray.length; i++)
			  {
				var KeyValuePair = urlArray[i].split('=');
				if (KeyValuePair[0] == "paper")
				{loadThisPaper = KeyValuePair[1]}
    		  }
			
			// SET CURRENT STATE PARAMETERS - used throughout various user selections to drive the results
			activeWindow = 1;
			activeLanguage = 1;
			resultsLangId = 1;
			Col1languageName = "Русский: UF-RUS-001World-2005-3-edition";
			Col1Language = 1;
			Col2Language = 2;
			Col3Language = 3;
			Col1Paper = 0;
			Col2Paper = 0;
			Col3Paper = 0;
			defaultLangIdx = 1;
			languageSelected = 1;
			targetCol = 1;
			pTitle = "";
			id = "0";   // Initial srt
			paper_start_idx = 0;			// Used by the createTOC process
			tooltipPaperTitleMenu = "Default tooltip ";
					
			document.getElementById('Col1').scrollTop = 0;
				
			//$('html, body').animate({scrollTop: 0 }, 'slow');
			 
			var ev = document.getElementById("Col1country_id"); // Get language selection list object
			defaultLangIdx = Number(ev.options[0].value);
			Col1Options = $('select#Col1country_id option').length
			
			if(Col1Options == 1)					// This is a one-language version so set view to 1 column
			{
				$('#Col2Wrapper').css('display', 'none');
				$('#Col3Wrapper').css('display', 'none');
				$('#Col1Wrapper').css('width', '99%');
				$('#vo0').css('border', 'solid Navy  1px');
				$('#vo0').css('background-color', '#ede4d6');
			}
			else									// Set column 2 to the second language
			{
				$('#vo1').css('border', 'solid Navy  1px');
				$('#vo1').css('background-color', '#ede4d6');			
			}
			
			languageSelected = defaultLangIdx;
			activeText = engtext;
			
		// END OF CURRENT STATE PARAMETERS
		
		// INITIATION PROCESSING		
			createTOC();						// Load the TOC structure 
			switchLanguage(defaultLangIdx, 1);	// Load Foreword into col1	
			localize(defaultLangIdx); 			// Localize the interface
			
			if(Col1Options != 1)				// If multiple texts are included
			{
				var Col2lan = document.getElementById("Col2country_id"); // Get language selection list object
				secondLangIdx = Number(Col2lan.options[2].value);
				switchLanguage(secondLangIdx, 2);	// Load Secondary Language FWD (or url-requested paper) into col2
				//loadThisPaper = "0";
				$("select#Col2country_id").val(secondLangIdx);	// Set select list for Col2 language
				Col2Language = secondLangIdx; // Set default language for Col2
				Col2languageName = $("#Col2country_id option:selected").text();

                var Col3lan = document.getElementById("Col3country_id"); // Get language selection list object
				thirdLangIdx = Number(Col3lan.options[3].value);
				switchLanguage(thirdLangIdx, 3);	// Load Third Language FWD (or url-requested paper) into col2
				//loadThisPaper = "0";
				$("select#Col3country_id").val(thirdLangIdx);	// Set select list for Col3 language
				Col3Language = thirdLangIdx; // Set default language for Col3
				Col3languageName = $("#Col3country_id option:selected").text();

				if(secondLangIdx == 8)
				{
					$("#broadCastMsg").html("(Translation in Progress, some files missing)");
					$('#broadCastMsg').css('display', 'inline');
				}
				//alert("secondLangIdx=" + secondLangIdx);
				if (secondLangIdx == 9 || secondLangIdx == 22)  // RTL direction for Arabic and Farsi
					{
						$("#Col2").attr({'dir':'rtl'});

					}




				switchLanguage(1, 0);	// Restore English as the default
			}
			
		$(document).ready(function() {
				
			$('.tooltip').tooltipster({	
				animation: 'fade',
				content: $(tooltipPaperTitleMenu),
				interactive: true,
				interactiveTolerance: 1000,
				offsetY: -8,
				position: 'bottom',
				timer: 7000,
				functionBefore: function(origin, continueTooltip) {

			// Build the Paper Menu for the tooltip display
				
					tooltipPaperTitleMenu = "";	// Content to be placed into the #paperTitles div for tooltipster
	
					tocPaper = $(origin).text().substring(1,4);		// Get the Paper number
					if (tocPaper == "FWD"){ tocPaper = "0";}
					if (tocPaper.length > 1) {tocPaper = tocPaper.replace(/^0+/, '');}		// Strip leading zero(es)
					tocPaperNum = Number(tocPaper);				

;			// Strip leading zeroes
				//alert("functionBefore ALERT, tocPaper=" + tocPaper);
	
					q = TitleIdxArray[tocPaperNum];		// Get Paper Titles starting entry in the Title Array
					titleClass = "tocTitleItem";
		
					while (q < 1626 && TitleArray[q].substring(0,tocPaper.length) == tocPaper) // Until max title entries reached
					{
						parse_row(TitleArray[q]);

						tooltipPaperTitleMenu += "<b><a href=\"#Col" + activeWindow + srt + "\" class=\"" + titleClass + "\" >" + restOfEntry + "<br/>"	
						titleClass = "tocSectionItem";				// The rest will be titles
						q++;
					}


					origin.tooltipster('update', $(tooltipPaperTitleMenu).html());
					continueTooltip();
					} 			
			});	
		
		// Scroll to the TOC title clicked in the tooltipster
		$(document).on('mousedown','.tocTitleItem,.tocSectionItem',function (e) {
	
			begin_at = get_Idx(tocPaper);

			switch(activeWindow)
			{
				case 1: if(Col1Paper != tocPaperNum)
						{
							//alert("format_paper started for paper=" + tocPaperNum + "begin_at=" + begin_at + "col1");
							switchLanguage(Col1Language,1);						
							document.getElementById("Col1").innerHTML=format_paper(tocPaper,begin_at,1);
							Col1Paper = tocPaperNum;
							//alert("format_paper completed=");
						}
						break;
				case 2: if(Col2Paper != tocPaperNum)
						{
							//alert("format_paper started for paper=" + tocPaperNum + "begin_at=" + begin_at + "col2");
							switchLanguage(Col2Language,2);		
							document.getElementById("Col2").innerHTML=format_paper(tocPaperNum,begin_at,2);
							Col2Paper = tocPaperNum;
						}
						break;
				case 3: if(Col3Paper != tocPaperNum)
						{
							switchLanguage(Col3Language,3);		
							document.getElementById("Col3").innerHTML=format_paper(tocPaperNum,begin_at,3);
							Col3Paper = tocPaperNum;
						}
						break;
		}		
				
			scrollToId = $(this).attr("href");
			scrollToId = scrollToId.substring(5);
			scrollToId = scrollToId.replace(":", "_"); scrollToId = scrollToId.replace(".", "_"); 
			scrollToId = "p_" + scrollToId; scrollToId = scrollToId.replace("#", "");
			scrollToId = "#Col" + activeWindow + scrollToId;
			activeCol= "#Col" + activeWindow;
			
			//alert("activeCol=" + activeCol + " scrollToId=" + scrollToId);
			$(activeCol).scrollTo($(scrollToId),400);		
		});
		

						
		// Expand/collapse the TOC div and create the initial TOC
		//alert("@60 script00: About to createTOC");
			$("#toc_body").hide();
        	$("#show_hide").show(function(){
				
			// Create the Toc Title Tables for the TOC Tooltipster when the TOC +/- is clicked (or at startup)
			
				createTOCtitletables();

			});
 
    		$('#show_hide').click(function(){
    			$("#toc_body").slideToggle();
				 if ($('a.rotator').hasClass('plus'))
				 {
					 $('a.rotator').removeClass('plus');
					 $('a.rotator').addClass('minus');
				 }
				 else
				 {
					 $('a.rotator').removeClass('minus');
					 $('a.rotator').addClass('plus');
				 }

 			});
				


		$('body').addClass('has-js');
        $('.label_check, .label_radio').click(function(){
            setupLabel();
        });
					
		$('.error').hide();		// Hide the empty text box error message
				
		// View Option Logic
		
			$('#vo0').click(function() {
   			$(this).css('background-color', '#ede4d6');
			$(this).css('border', 'solid Navy  1px');
			$('#vo1,#vo2,#vo3,#vo4,#vo5').css('background-color', '#ccc');
			$('#vo1,#vo2,#vo3,#vo4,#vo5').css('border', 'dotted grey 1px');
			$('#Col2Wrapper').css('display', 'none');
			$('#Col3Wrapper').css('display', 'none');
			$('#Col1Wrapper').css('width', '99%');
			//$('#Col2Wrapper').css('display', 'inline');
			//$('#Col1Hdr,#Col2Hdr').css('width', '50%');
			activeWindow = 1;
			switchLanguage(Col1Language,0);
			createTOCtitletables();
 			});
		
		$('#vo1').click(function() {
   			$(this).css('background-color', '#ede4d6');
			$(this).css('border', 'solid Navy  1px');
			$('#vo0,#vo2,#vo3,#vo4,#vo5').css('background-color', '#ccc');
			$('#vo0,#vo2,#vo3,#vo4,#vo5').css('border', 'dotted grey 1px');
			$('#Col3Wrapper').css('display', 'none');
			$('#Col1Wrapper').css('width', '49%');
			$('#Col2Wrapper').css('width', '49%');
			$('#Col2Wrapper').css('display', 'inline');
			//$('#Col1Hdr,#Col2Hdr').css('width', '50%');
			activeWindow = 1;
			switchLanguage(Col1Language,0);
			createTOCtitletables();
 			});
		$('#vo2').click(function() {
   			$(this).css('background-color', '#f3d9bc');
			$(this).css('border', 'solid Navy 1px');
			$('#vo0,#vo1,#vo3,#vo4,#vo5').css('background-color', '#ccc');
			$('#vo0,#vo1,#vo3,#vo4,#vo5').css('border', 'dotted grey 1px');
			$('#Col3Wrapper').css('display', 'none');
			$('#Col1Wrapper').css('width', '49%');
			$('#Col2Wrapper').css('width', '49%');
			$('#Col2Wrapper').css('display', 'inline');
			//$('#Col1Hdr,#Col2Hdr').css('width', '50%');
			activeWindow = 2;
			switchLanguage(Col2Language,0);
			createTOCtitletables();
 			});
		$('#vo3').click(function() {
   			$(this).css('background-color', '#ede4d6');
			$(this).css('border', 'solid Navy 1px');
			$('#vo0,#vo1,#vo2,#vo4,#vo5').css('background-color', '#ccc');
			$('#vo0,#vo1,#vo2,#vo4,#vo5').css('border', 'dotted grey 1px');
			$('#Col1Wrapper').css('width', '32%');
			$('#Col2Wrapper').css('width', '32%');
			$('#Col3Wrapper').css('width', '32%');
			//$('#Col1Hdr').css('width', '33%');
			//$('#Col3Hdr').css('width', '33%');
			//$('#Col2Hdr').css('width', '33%');
			$('#Col3Wrapper').css('display', 'inline');
			$('#Col3Wrapper').show;
			activeWindow = 1;
			switchLanguage(Col1Language,0);
			createTOCtitletables();
 			});
		$('#vo4').click(function() {
   			$(this).css('background-color', '#f3d9bc');
			$(this).css('border', 'solid Navy 1px');
			$('#vo0,#vo1,#vo2,#vo3,#vo5').css('background-color', '#ccc');
			$('#vo0,#vo1,#vo2,#vo3,#vo5').css('border', 'dotted grey 1px');
			$('#Col1Wrapper').css('width', '32%');
			$('#Col2Wrapper').css('width', '32%');
			$('#Col3Wrapper').css('width', '32%');
			//$('#Col1Hdr').css('width', '33%');
			//$('#Col3Hdr').css('width', '33%');
			//$('#Col2Hdr').css('width', '33%');
			$('#Col3Wrapper').css('display', 'inline');
			$('#Col3Wrapper').show;
			activeWindow = 2;
			switchLanguage(Col2Language,0);
			createTOCtitletables();
 			});
		$('#vo5').click(function() {
   			$(this).css('background-color', '#ededed');
			$(this).css('border', 'solid Navy 1px');
			$('#vo0,#vo1,#vo2,#vo3,#vo4').css('background-color', '#ccc');
			$('#vo0,#vo1,#vo2,#vo3,#vo4').css('border', 'dotted grey 1px');
			$('#Col1Wrapper').css('width', '32%');
			$('#Col2Wrapper').css('width', '32%');
			$('#Col3Wrapper').css('width', '32%');
			//$('#Col1Hdr').css('width', '33%');
			//$('#Col3Hdr').css('width', '33%');
			//$('#Col2Hdr').css('width', '33%');
			$('#Col3Wrapper').css('display', 'inline');
			$('#Col3Wrapper').show;
			activeWindow = 3;
			switchLanguage(Col3Language,0);
			createTOCtitletables();
 			});
		
			// Re-enable Right-click functionality upon dialog box close
			$(document).on( "dialogclose", function( event, ui ) {$(document)[0].oncontextmenu = function() {return true;}} );
		
			  // Disabled pending a resolution about font-size reversion after any div reload
/*
		  	  // Fontsize increase/decrease/reset logic follows
		  	  // Reset Font Size
		  	  var originalFontSize = $('html').css('font-size');
			  $(".resetFont").click(function(){
			  $('html').css('font-size', originalFontSize);
			  });
			  // Increase Font Size
			  $(".increaseFont").click(function(){
				var curFontSize = $('.title').css('font-size');
				//console.log('curFontSize=' + curFontSize);
				var curFontSizeNum = parseFloat(curFontSize, 10);
				if ( curFontSizeNum < 22 ) {
				$('.title').css('font-size', parseInt(curFontSize)+2);
				$('.section').css('font-size', parseInt($('.section').css('font-size'))+2);
				$('.paragraph').css('font-size', parseInt($('.paragraph').css('font-size'))+2);
				$('.pClass').css('font-size', parseInt($('.pClass').css('font-size'))+2);
				$('.sClass').css('font-size', parseInt($('.sClass').css('font-size'))+2);
				$('.tClass').css('font-size', parseInt($('.tClass').css('font-size'))+2);
				}
				return false;
			  });
			  
			  // Decrease Font Size
			  $(".decreaseFont").click(function(){
				var curFontSize = $('.title').css('font-size');
				var curFontSizeNum = parseFloat(curFontSize, 10);
				console.log('curFontSize=' + curFontSize);
				if ( curFontSizeNum > 14 ) {
				$('.title').css('font-size', parseInt(curFontSize)-2);
				$('.section').css('font-size', parseInt($('.section').css('font-size'))-2);
				$('.paragraph').css('font-size', parseInt($('.paragraph').css('font-size'))-2);
				$('.pClass').css('font-size', parseInt($('.pClass').css('font-size'))-2);
				$('.sClass').css('font-size', parseInt($('.sClass').css('font-size'))-2);
				$('.tClass').css('font-size', parseInt($('.tClass').css('font-size'))-2);
				}
				return false;
			  });
*/

			
			document.getElementById('Col1').scrollTop = 0;			
			$(this).scrollTop(0);		// Scroll to top after browser refresh


			$('#search_terms').val("Введите свой запрос...").addClass("mClass");  // Set for 1st use


		// partSelector Change
			$("#partSelector_id").change(function() {
				var e = document.getElementById("partSelector_id");
				partSelected = Number(e.options[e.selectedIndex].value);
				switch (partSelected)
					{
					case 1: sPart = "All"; break;
					case 2: sPart = "FWD"; break;
					case 3: sPart = "I"; break;
					case 4: sPart = "II"; break;
					case 5: sPart = "III"; break;
					case 6: sPart = "IV"; break;
					};
			});

			
			// Search typeSelector Change
			$("#typeSelector_id").change(function() {
				var e = document.getElementById("typeSelector_id");
				typeSelected = Number(e.options[e.selectedIndex].value);
				switch (typeSelected)
					{
					case 0: sType = "All"; break;
					case 1: sType = "Exact"; break;
					case 2: sType = "Most"; break;
					case 3: sType = "Any"; break;
					};
					//alert("WhichPart=" + sType);
			});
			
		// Language Selection Change Col1
			$("#Col1country_id").change(function() {
    			var e = document.getElementById("Col1country_id");
				languageSelected = Number(e.options[e.selectedIndex].value);
				Col1languageName = $("#Col1country_id option:selected").text();
				Col1Language = languageSelected;
				Col1Paper = 0;
				targetCol = "1";
				
				// $('#resultsDiv').text('');					// Clear the results
				//clicked_Result = '#0';
				
				localize(languageSelected); 	// Localize the interface
				$('#search_terms').val(Loc11).addClass("mClass");
				$('#resultsMsg').html("Search Results &raquo;");  // Reinitialize Result Count
			
			// Set language direction based on selection
			if (languageSelected == "9" || languageSelected == "22")
			{
				$('html').attr({'dir':'rtl'});
			}
			else
			{
				$('html').attr({'dir':'ltr'});

			}
						
			switchLanguage(languageSelected, targetCol);		// Switch language based on user selection
			$('#Col1').animate({scrollTop: 0 }, 'slow');
			
			if (activeWindow == 1) {createTOCtitletables();	}	// Recreate the TOCtitleArray
			//alert("resultsLangId=" + resultsLangId);
			//switchLanguage(resultsLangId, 0);			// Reset activeText to resultsLangID	
								
			});			// End of Language Change Functions

		// Language Selection Col2
			$("#Col2country_id").change(function() {
    			var e = document.getElementById("Col2country_id");
				languageSelected = Number(e.options[e.selectedIndex].value);
				Col2languageName = $("#Col2country_id option:selected").text();
				Col2Language = languageSelected;
				Col2Paper = 0;
				targetCol = "2";
				
				// $('#resultsDiv').text('');					// Clear the results
				//clicked_Result = '#0';
				
				localize(languageSelected); 	// Localize the interface
				$('#search_terms').val(Loc11).addClass("mClass");
				$('#resultsMsg').html("Search Results &raquo;");  // Reinitialize Result Count
			
			
			// Set language direction based on selection
			if (languageSelected == "9" || languageSelected == "22")
			{
				$('html').attr({'dir':'rtl'});
			}
			else
			{
				$('html').attr({'dir':'ltr'});

			}
			
			
			switchLanguage(languageSelected, targetCol);		// Switch language based on user selection
			$('#Col2').animate({scrollTop: 0 }, 'slow');
			
			if (activeWindow == 2) {createTOCtitletables();	}	// Recreate the TOCtitleArray								
			//alert("resultsLangId=" + resultsLangId);
			//switchLanguage(resultsLangId, 0);			// Reset activeText to resultsLangID						
			});			// End of Language Change Functions
			
			// Language Selection Col3
			$("#Col3country_id").change(function() {
    			var e = document.getElementById("Col3country_id");
				languageSelected = Number(e.options[e.selectedIndex].value);
				Col3languageName = $("#Col3country_id option:selected").text();
				Col3Language = languageSelected;
				Col3Paper = 0;
				targetCol = "3";
				
				// $('#resultsDiv').text('');					// Clear the results
				//clicked_Result = '#0';
				
				localize(languageSelected); 	// Localize the interface
				$('#search_terms').val(Loc11).addClass("mClass");
				$('#resultsMsg').html("Search Results &raquo;");  // Reinitialize Result Count
			
			
			// Set language direction based on selection
			if (languageSelected == "9" || languageSelected == "22")
			{
				$('html').attr({'dir':'rtl'});
			}
			else
			{
				$('html').attr({'dir':'ltr'});

			}
			
			switchLanguage(languageSelected, targetCol);		// Switch language based on user selection
			$('#Col3').animate({scrollTop: 0 }, 'slow');
			if (activeWindow == 3) {createTOCtitletables();	}	// Recreate the TOCtitleArray
			//alert("resultsLangId=" + resultsLangId);
			//switchLanguage(resultsLangId, 0);			// Reset activeText to resultsLangID							
			});			// End of Language Change Functions


			// Scroll all columns to a clicked Title, Section, or paragraph in any Column
			
			$(document).on('click','.pItem,.sItem,.tItem',function (e) {
				
				clickedId = $(this).attr("id");
				//alert("294.clickedId=" + clickedId);
				colClicked = clickedId.substring(3,4);
				scrollId   = clickedId.substring(4);
				
				scrollId1 = "#Col1" + scrollId;
				scrollId2 = "#Col2" + scrollId;
				scrollId3 = "#Col3" + scrollId;
					
				//alert("colClicked=" + colClicked + "..." + scrollId1 + "..." + scrollId2 + "..." + scrollId3);
				
				colClicked = Number(colClicked);	
				switch(colClicked)
				{
					
					case 1: 
					//alert("Column1item clicked..." + clickedId + "...Col1Paper=" + Col1Paper + "...Col2Paper=" + Col2Paper + "...Col3Paper=" + Col3Paper);							
							if (Col2Paper != Col1Paper) 
								{
									switchLanguage(Col2Language,0);			// Set the current col2 language appropriately
									start_at = get_Idx(Col1Paper);			// get Paper's starting idx in the text array
									Col2output = format_paper(PaperToLoad,start_at,2);
									$('#Col2').html(Col2output);
									Col2Paper = Col1Paper;					// Change Paper number in Col2
									//alert("**********col2output=" + Col2output);									
								}
							if (Col3Paper != Col1Paper) 
							{
									switchLanguage(Col3Language,0);			// Set the current col3 language appropriately
									start_at = get_Idx(Col1Paper);			// get Paper's starting idx in the text array
									Col3output = format_paper(PaperToLoad,start_at,3);
									$('#Col3').html(Col3output);
									Col3Paper = Col1Paper;					// Change Paper number in Col3
									//alert("***********col3output=" + Col3output);		
							}
							
						break;
						
					case 2:
					//alert("Column2item clicked..." + clickedId + "...Col1Paper=" + Col1Paper + "...Col2Paper=" + Col2Paper + "...Col3Paper=" + Col3Paper);		
							if (Col1Paper != Col2Paper) 
								{
									switchLanguage(Col1Language,0);			// Set the current col1 language appropriately
									start_at = get_Idx(Col2Paper);			// get Paper's starting idx in the text array
									Col1output = format_paper(PaperToLoad,start_at,1);
									$('#Col1').html(Col1output);
									Col1Paper = Col2Paper;					// Change Paper number in Col1
									//alert("***********col1output=" + Col1output);										
								}
							if (Col3Paper != Col2Paper) 
							{
									switchLanguage(Col3Language,0);			// Set the current col3 language appropriately
									start_at = get_Idx(Col2Paper);			// get Paper's starting idx in the text array
									Col3output = format_paper(PaperToLoad,start_at,3);
									$('#Col3').html(Col3output);
									Col3Paper = Col2Paper;					// Change Paper number in Col3
									//alert("***********col3output=" + Col3output);			
							} 
							
						break;
						
					case 3:
					//alert("Column3item clicked..." + clickedId + "...Col1Paper=" + Col1Paper + "...Col2Paper=" + Col2Paper + "...Col3Paper=" + Col3Paper);		
							 if (Col1Paper != Col3Paper) 
								{
									switchLanguage(Col1Language,0);			// Set the current col1 language appropriately
									start_at = get_Idx(Col3Paper);			// get Paper's starting idx in the text array
									Col1output = format_paper(PaperToLoad,start_at,1);
									$('#Col1').html(Col1output);
									Col1Paper = Col3Paper;					// Change Paper number in Col1
									//alert("***********col1output=" + Col1output);										
								}
							if (Col2Paper != Col3Paper) 
							{
									switchLanguage(Col2Language,0);			// Set the current col2 language appropriately
									start_at = get_Idx(Col3Paper);			// get Paper's starting idx in the text array
									Col2output = format_paper(PaperToLoad,start_at,2);
									$('#Col2').html(Col2output);
									Col2Paper = Col3Paper;					// Change Paper number in Col2
									//alert("***********col2output=" + Col2output);			
							} 
							
						break;

				}
				
				//alert("scrollId1..." + scrollId1 + "...scrollId2..." + scrollId2 + "...scrollId3..." + scrollId3);
				
				$('#Col1').scrollTo($(scrollId1),400);
				$('#Col2').scrollTo($(scrollId2),400);				
				$('#Col3').scrollTo($(scrollId3),400);
				$('html, body').animate({scrollTop: 0 }, 'slow');
				
			});


		// Srt Display Processing
		$('#srtSubmit').submit(function(event){	
			event.preventDefault();	
			srtError = false;		 
			srtPaper = $('#srtPap').val();
			srtSection = $('#srtSec').val();
			srtParagraph = $('#srtPar').val();
			srtPapNum = Number(srtPaper);
			srtSecNum = Number(srtSection);
			srtParNum = Number(srtParagraph)
			
			$('#srtPap,#srtSec,#srtPar').css('border-style', 'solid');
			$('#srtPap,#srtSec,#srtPar').css('border-color', 'grey');			// Clear prior error indicator
			if (isNaN(srtPaper) || Number(srtPaper) > 196) {$('#srtPap').css('border-color', '#F00'); $('#srtPap').css('border-style', 'solid'); srtError = true;}
			if (isNaN(srtSection)) {$('#srtSec').css('border-color', '#F00'); $('#srtSec').css('border-style', 'solid'); srtError = true;}
			if (isNaN(srtParagraph)) {$('#srtPar').css('border-color', '#F00');$('#srtPap').css('border-style', 'solid'); srtError = true;}			
			
			if (!srtError)
			{
			
			begin_at = get_Idx(srtPaper);

			switch(activeWindow)
			{
				case 1: //alert("format_paper started for paper=" + tocPaperNum + "begin_at=" + begin_at + "col1");				
							switchLanguage(Col1Language,0);
							document.getElementById("Col1").innerHTML=format_paper(srtPapNum,begin_at,1);
							Col1Paper = srtPapNum;
							//alert("format_paper completed=");
						break;
				case 2: //alert("format_paper started for paper=" + tocPaperNum + "begin_at=" + begin_at + "col2");
							switchLanguage(Col2Language,0);
							document.getElementById("Col2").innerHTML=format_paper(srtPapNum,begin_at,2);
							Col2Paper = srtPapNum;
						break;
				case 3: 	switchLanguage(Col3Language,0);
							document.getElementById("Col3").innerHTML=format_paper(srtPapNum,begin_at,3);
							Col3Paper = srtPapNum;
						break;
		}		
			srtAnchor = srtPaper;
			if (srtSection != "") {srtAnchor = srtAnchor + ":" + srtSection;}
			if (srtParagraph != "") {srtAnchor = srtAnchor + "." + srtParagraph;}

			scrollToId = "#" + srtAnchor;
			scrollToId = scrollToId.replace(":", "_"); scrollToId = scrollToId.replace(".", "_");
			scrollToId = "p_" + scrollToId; scrollToId = scrollToId.replace("#", "");
			scrollToId = "#Col" + activeWindow + scrollToId;
			activeCol= "#Col" + activeWindow;

			$(activeCol).scrollTo($(scrollToId),400);		
			
			}
			}); 


		// Searchbox Housekeeping
		$('#clearSB').click(function(){							// Clear textbox when requested
			 $('#search_terms').val('');
			 $("input:text:visible:first").focus();				// Set focus on searchbox
			 });   
		
		// Checkbox Click logic
		/*$('#checkbox-pAll').click(function(){
		//	$('#checkbox-pFwd,#checkbox-pI,#checkbox-pII,#checkbox-pIII,#checkbox-pIV').prop('checked', false);
		//	sPart = "All";			
		//	});
		$('#checkbox-pFwd').click(function(){
			$('#checkbox-pAll,#checkbox-pI,#checkbox-pII,#checkbox-pIII,#checkbox-pIV').prop('checked', false);
			sPart = "FWD";			
			});
		$('#checkbox-pI').click(function(){
			$('#checkbox-pAll,#checkbox-pFwd,#checkbox-pII,#checkbox-pIII,#checkbox-pIV').prop('checked', false);
			sPart = "I";			
			});
		$('#checkbox-pII').click(function(){
			$('#checkbox-pAll,#checkbox-pFwd,#checkbox-pI,#checkbox-pIII,#checkbox-pIV').prop('checked', false);
			sPart = "II";			
			});
		$('#checkbox-pIII').click(function(){
			$('#checkbox-pAll,#checkbox-pFwd,#checkbox-pI,#checkbox-pII,#checkbox-pIV').prop('checked', false);
			sPart = "III";			
			});
		$('#checkbox-pIV').click(function(){
			$('#checkbox-pAll,#checkbox-pFwd,#checkbox-pI,#checkbox-pII,#checkbox-pIII').prop('checked', false);
			sPart = "IV";			
			}); 
		$('#checkbox-tExact').click(function(){
			$('#checkbox-tAll,#checkbox-tMost,#checkbox-tAny').prop('checked', false);
			sType = "Exact";			
			});
		$('#checkbox-tAll').click(function(){
			$('#checkbox-tExact,#checkbox-tMost,#checkbox-tAny').prop('checked', false);
			sType = "All";			
			});
		$('#checkbox-tMost').click(function(){
			$('#checkbox-tExact,#checkbox-tAll,#checkbox-tAny').prop('checked', false);
			sType = "Most";			
			});
		$('#checkbox-tAny').click(function(){
			$('#checkbox-tExact,#checkbox-tAll,#checkbox-tMost').prop('checked', false);
			sType = "Any";			
			});*/

		$('#Col1Up').click(function(){
			document.getElementById('Col1').scrollTop = 0;			
			});
		$('#Col2Up').click(function(){
		document.getElementById('Col2').scrollTop = 0;			
		});				
		$('#Col3Up').click(function(){
		document.getElementById('Col3').scrollTop = 0;			
		});	

		$('#Col1Down').click(function(){
  		var height = $('#Col1')[0].scrollHeight;
  		$('#Col1').scrollTop(height);	
			});
		$('#Col2Down').click(function(){
  		var height = $('#Col2')[0].scrollHeight;
  		$('#Col2').scrollTop(height);			
		});				
		$('#Col3Down').click(function(){
  		var height = $('#Col3')[0].scrollHeight;
  		$('#Col3').scrollTop(height);		
		});	

		// TOC element scroll & capture. Use 'on' b/c of DOM changes during language selection							
		//$('.liSec').click(function() {
		$('#toc').on('click','.liSec',function() {				
				document.getElementById('Col1').scrollTop = 0;
				clicked_Result = $(this).attr("href");   // Set so that scrolling to the Eng text PopUp will work correctly
				//console.log('clicked_Result=' + clicked_Result);
		});	
		
		// Start search if Search Button clicked		
		$("#search_button").click(function() {	
					
 			
			if (activeWindow == "2" && $('#Col2country_id').val() == 0) {alert("No language selected for Active Window");}
			if (activeWindow == "3" && $('#Col3country_id').val() == 0) {alert("No language selected for Active Window");}		
			
 
      			terms = $("input#search_terms").val();
				
				if (terms.length != 0) 
				{
					
				//alert("Terms=" + terms); 
					
				// Clean up search terms
				
				var cleanedTermsArray = cleanTerms(terms);			// Regex to strip unwanted characters
								
				var matchesFound = searchText(cleanedTermsArray);	
	            
				//alert("CleanedTerms=" + resultsArray.length + " Cleaned Terms=" + cleanedTermsArray);
				}
				else {alert(Loc16);				// No terms entered, Display the error msg
				}
			

  				}); 

				 
		// Start search if Enter Key (13) was clicked		
			$("#search_terms").keypress(function(e) {
				code = e.keyCode ? e.keyCode : e.which;     // Req'd for cross-browser support?
        		//alert ('search box focus set=' + code.toString());
	 			
			if (activeWindow == "2" && $('#Col2country_id').val() == 0) {alert("No language selected for Active Window");}
			if (activeWindow == "3" && $('#Col3country_id').val() == 0) {alert("No language selected for Active Window");}					
				
				
				if(code.toString() == 13) {
            	e.preventDefault();
				terms = $("input#search_terms").val(); 
				var cleanedTermsArray = cleanTerms(terms);			// Regex to strip unwanted characters
								
				var matchesFound = searchText(cleanedTermsArray);	
				
        		}
    		});

		});
