        //-----------------------------
        function trapenter(p_event)
        {
			p_event = (window.event?window.event:p_event);
	    	if (p_event.keyCode == 13)
			{
	    		if (document.form1.p_word.value == g_word)
				{
					document.form1.p_word.value = g_word
				}
				else if (document.form1.p_word.value == "")
				{
					document.form1.p_word.value = g_word
				}
				else
				{
            		document.form1.p_page.value = "1"
				}
				document.form1.action = g_index_page 
				document.form1.p.value = "s" 
           	 	document.form1.p_book_name.value = g_book_name
            	document.form1.p_chapter.value = g_chapter
            	submit()
				return false
			}
        }
		//-----------------------------
		function toggle_links()
		{
			var l = document.form1.p_links.value
			var h = document.getElementById("disp_links")
		if (l == "off")
		{
			   document.form1.p_links.value = "on"
			   h.innerText = "On"
		}
			else
		{
			   document.form1.p_links.value = "off"
			   h.innerText = "Off"
		}
			document.form1.p.value = g_pgm
			document.form1.p_word.value = g_word
			submit()
		}
        //-----------------------------
        function toggle_help()
        {
            var h = document.getElementById("help")
	    if (h.style.display == "inline")
               h.style.display = "none"
           else
               h.style.display = "inline"
        }
        //-----------------------------
        function close_help()
        {
	    var h = document.getElementById("help")
               if (h)
                   h.style.display = "none"
        }
		//-----------------------------
		function rotate_language()
		{
			var l = document.form1.p_language.value
			var d = document.getElementById("disp_lang")
			if (l == "e")
			{
   				document.form1.p_language.value = "h"
	   			d.innerText = "Hebrew"
 		   	}
			else if (l == "h")
			{
				 document.form1.p_language.value = "he"
  				 d.innerText = "Hebrew/English"
			}
			else
			{
   				document.form1.p_language.value = "e"
	   			d.innerText = "English"
			   //hide_keyboard()
			}
   			document.form1.p.value = g_pgm
	 		document.form1.p_word.value = g_word
	 		submit()
		}
        //-----------------------------
        function toggle_keyboard()
        {
            var k = document.getElementById("keyboard")
	    if (k.style.display == "inline")
               k.style.display = "none"
           else
               k.style.display = "inline"
        }
        //-----------------------------
        function hide_keyboard()
        {
	    var k = document.getElementById("hide_keyboard")
               if (k)
                   k.style.display = "none"
        }
        //-----------------------------
        function close_keyboard()
        {
	    var k = document.getElementById("keyboard")
               if (k)
                   k.style.display = "none"
        }
        //-----------------------------
        function submit()
        {
			if (g_submitted == false)
			{
				g_submitted = true
            	document.form1.submit()
			}
        }
        //-----------------------------
        function goto_home()
        {
            document.form1.action = g_index_page
			document.form1.p.value = "h" 
            submit()
        }
        //-----------------------------
        function goto_toc()
        {
			document.form1.action = g_index_page 
			document.form1.p.value = "t" 
            submit()
        }
        //-----------------------------
        function gch(p_bk,p_ch,p_hi_ch,p_hi_vrs)
        {
            document.form1.p_book_name.value = p_bk
            document.form1.p_chapter.value = p_ch
            document.form1.p_parsha.value = ""
			if (p_hi_ch)
            	document.form1.p_hilite_chapter.value = p_hi_ch
			else
            	document.form1.p_hilite_chapter.value = ""
			if (p_hi_vrs)
			{
            	document.form1.p_hilite_verse.value = p_hi_vrs
				document.form1.p.value = "v" 
				if (p_hi_ch == '1')
				{
            		document.form1.action = g_index_page + "#" + p_hi_vrs; 
				}
				else
				{
            		document.form1.action = g_index_page; 
				}
			}
			else
			{
            	document.form1.p_hilite_verse.value = ""
				document.form1.p.value = "c" 
           		document.form1.action = g_index_page; 
			}
            submit()
        }
        //-----------------------------
        function goto_parsha(p_bk,p_parsha,p_hi_ch,p_hi_vrs)
        {
            document.form1.action = g_index_page 
			document.form1.p.value = "p" 
            document.form1.p_book_name.value = p_bk
            document.form1.p_chapter.value = ""
            document.form1.p_parsha.value = p_parsha
            document.form1.p_hilite_chapter.value = p_hi_ch
            document.form1.p_hilite_verse.value = p_hi_vrs
            submit()
        }
        //-----------------------------
        function gser_heb(p_wd)
        {
            document.form1.p_word.className = "h"
            gser(p_wd)
        }
        //-----------------------------
        function gser_eng(p_wd)
        {
            document.form1.p_word.className = "e"
            gser(p_wd)
        }
        //-----------------------------
        function gser(p_wd)
        {
            if (p_wd != "")
                document.form1.p_word.value = p_wd
            document.form1.action = g_index_page 
			document.form1.p.value = "s" 
            document.form1.p_book_name.value = g_book_name
            document.form1.p_chapter.value = g_chapter
            document.form1.p_page.value = "1"
            submit()
        }
        //-----------------------------
        function goto_pageno(p_pg)
        {
            document.form1.p_page.value = p_pg
			document.form1.p.value = "s" 
            document.form1.p_word.value = g_word
            submit()
        }
        //-----------------------------
        function init()
        {
			init_help()
			init_focus()
        }
        //-----------------------------
        function init_focus()
        {
			if (document.form1.p_word)
			{
				document.form1.p_word.focus()
			}
        }
        //-----------------------------
        function init_help()
        {
            var h = document.getElementById("help")
			var g_sp4 = '&nbsp;&nbsp;&nbsp;&nbsp;'
			if (h)
			{
				h.innerHTML = 
					'<table cellpadding="0" cellspacing="0" border="0">' +
						'<tr>' + 
							'<td bgcolor="#d3d3d3">' + g_sp4 + '</td>' + 
							'<td bgcolor="#d3d3d3">' + g_sp4 + '</td>' + 
							'<td bgcolor="#d3d3d3">' + g_sp4 + '</td>' + 
							'<td style="background-color:#d3d3d3;text-align:right;white-space:nowrap;"><a href="javascript:close_help()">Close Help</a></td>' +
							'<td bgcolor="#d3d3d3">' + g_sp4 + '</td>' + 
						'</tr><tr>' + 
							'<td bgcolor="#d3d3d3">' + g_sp4 + '</td>' + 
							'<td bgcolor="#eeffdd">' + g_sp4 + '</td>' + 
							'<td bgcolor="#eeffdd" style="text-align:left;">' + 
								'<br>' +
								'There are several ways to use this Bible tool. ' +
								'You may read sequentially starting at any book or chapter. ' +
								'You may also look for a specific word, phrase, or passage. ' +
								'To begin, scroll down or <a href="javascript:close_help()">close this Help box</a>.' +
								'<br><br>' +
								'Guidelines:' +
								'<br>' +
								'<ul>' +
									'<li>' + 'To browse, select one of the main sections (Torah, Prophets, Writings, or the New Testament). ' + '</li>' +
									'<li>' + 'Select a book. ' + '</li>' +
									'<li>' + 'Select a chapter. ' + '</li>' +
									'<li>' + 'Select a verse. ' + '</li>' +
									'<li>' + 'Browse across sections, books, and chapters, by selecting the "Next Chapter" or "Previous Chapter" icon. ' + '</li>' +
									'<li>' + 'Browse a single verse or a range of verses by selecting the "Next Verse" or "Previous Verse" icon. ' + '</li>' +
									'<li>' + 'To search for a word or phrase, enter the phrase in the input area, then select "Search". ' + '</li>' +
									'<li>' + 'When Text Links are "On", proper names of people, places, and things are searchable by selecting the hyperlinked name. ' + '</li>' +
									'<li>' + 'Note: You may toggle Text Links "On" and "Off" by selecting the "Text Links" link. ' + '</li>' +
								'</ul>' +
								'Advanced Search:' +
								'<br>' +
								'<ul>' +
									'<li>' + 'Enter a <b>book</b>, <b>chapter</b>, or <b>verse</b>, like "Genesis", "Exodus 20", "Numbers 21:8", or "Deut 6:4-9" ' +
											'to view that passage. ' +
									'<li>' + 'Enter a question, statement, or brief phrase like "moses born" to view related verses. ' +
									'<li>' + 'Enter an <b>exact phrase</b> like <b>"</b>generation to generation<b>"</b> enclosed within double-quotes (") ' +
											'to view only verses containing that exact phrase. ' +
									'<li>' + 'You may use <b>wildcards</b> in your search as in "Sara<b>?</b>" or "Abra<b>*</b>m". ' +
									'<li>' + 'You may use <b>Booleans</b> (and, or, not) as in "Adam or Eve" or "mountain and river" or "gold not silver". ' +
									'<li>' + 'You may enter your search as a <b>logical</b> expression as in "(Egypt + (Moses|Aaron)) - Pharaoh", ' +
											'where "+" means "and", "|" means "or", and "-" means "not". ' +
											'This search produces verses which contains the word "Egypt" ' +
											'and either of "Moses" or "Aaron", but does not mention "Pharaoh". ' +
									'<li>' + 'Hint: Use parentheses to remove ambiguity in complex searches, as in "A  or (B and C)". ' +
								'</ul>' +
							'</td>' + 
							'<td bgcolor="#eeffdd">' + g_sp4 + '</td>' + 
							'<td bgcolor="#d3d3d3">' + g_sp4 + '</td>' + 
						'</tr><tr>' + 
							'<td bgcolor="#d3d3d3" colspan=5>' + g_sp4 + '</td>' + 
						'</tr>' + 
					'</table>';
			}
        }
        //-----------------------------
        function append_search_arg(p_start,p_end,p_str,p_chr)
        {
	    var v_out
	    v_out = p_str.substr(0,p_start)
	    v_out += p_chr
	    v_out += p_str.substr(p_end)
	    return v_out
        }
        //-----------------------------
        function append(p_chr)
        { 
	    var v_tmp
	    var v_str
            if (document.form1.p_word)
            {
        	document.form1.p_word.className="h"
        	document.form1.p_word.focus()
	        var v_range = document.selection.createRange()
	        var v_start = Math.abs(document.selection.createRange().moveStart("character", -1000000)) 
	        var v_end   = Math.abs(document.selection.createRange().moveEnd("character", -1000000))
		if (v_end < v_start)
		{
		    v_tmp = v_start
		    v_start = v_end
		    v_end = v_tmp
		}
                v_str = document.form1.p_word.value
                if (p_chr == "Space")        
		    if (v_start == 0 && v_end == 0)
			document.form1.p_word.value += " "
		    else
		    {
	                document.form1.p_word.value = append_search_arg(v_start,v_end,v_str," ")
	                v_range.moveEnd("character",v_start + 1)
	                v_range.moveStart("character",v_start + 1)
		        v_range.collapse()
	                v_range.select()
  		    }
                else if (p_chr == "Clear")        
		{
	            document.form1.p_word.value = ""
	            document.form1.p_word.caret = ""
		}
                else if (p_chr == "BkSp")        
		{
      	    	    if (v_start == v_end)
	            {
		        if (v_start > 0)
		        {
	    	            v_tmp = v_str.substr(0,v_start - 1)
		            v_tmp += v_str.substr(v_end)
	                    document.form1.p_word.value = v_tmp
    			    v_range.moveStart("character",v_start - 1)
           		    v_range.collapse()
	            	    v_range.select()
		        }
	            }
	            else
	            {
	    	        v_tmp = v_str.substr(0,v_start)
		        v_tmp += v_str.substr(v_end)
	                document.form1.p_word.value = v_tmp
			v_range.moveStart("character",v_start)
           		v_range.collapse()
	            	v_range.select()
	            }
		}
                else        
		{
		    if (v_start == 0 && v_end == 0)
{
			document.form1.p_word.value += p_chr
}
else
		    {
	                document.form1.p_word.value = append_search_arg(v_start,v_end,v_str,p_chr)
	                v_range.moveEnd("character",v_start + 1)
	                v_range.moveStart("character",v_start + 1)
		        v_range.collapse()
	                v_range.select()
  		    }
		}
        	document.form1.p_word.focus()
            }
        }

