
	sengin=false; // default no search engine until document.referrer reads one
if(document.referrer){
temp1=document.referrer
if (temp1.indexOf("?"))
sengin=true;}

presently="pos2"; // default start page is pos2
	// SEARCH RESULTS ALWAYS GO TO pos1
maxi = 2; //default maximum size of 'book' unless specified by book
	// in html body declare maxi if different than 2
noPages = 1; //default visible number of pages - open book should be 2...
		// in html body declare noPages if higher than 1

		/*function names are case sensitive -- SPage() and SinglePg()
		Spage() is passed one page number (Highest of Nopages -- if a 'book' has two pages pass the even number page)
		SinglePg() takes a page number and a 1- for show, 2- for hide... this is used for pop-up definitions only...*/
		
function SinglePg(which,status){
	if (status==1){
 	document.getElementById(which).style.visibility="visible";}
 	else {
  document.getElementById(which).style.visibility="hidden";}
 }	
		
function SPage(which) {
	hider=eval(presently.substring(3,presently.length))
	presently=which;
	another=eval(presently.substring(3,presently.length))

// hide the present pages...
	if (noPages > 1){ 
		for (i=0;i<noPages;i++){
 		document.getElementById('pos'+(hider-i)).style.visibility="hidden";
		}
		}
 document.getElementById('pos'+hider).style.visibility="hidden";

// show the pages...
	if (noPages > 1){
		for (i=0;i<noPages;i++){ 
	 document.getElementById('pos'+(another-i)).style.visibility="visible";
		}}
  document.getElementById(which).style.visibility="visible";
// don't follow HREF 
  return false; 
}

function frward() {
// presently where am I - add noPages showing variable
whereto=eval(presently.substring(3,presently.length));
whereto+=noPages;
SPage('pos'+whereto);
}

function backward() {
whereto=eval(presently.substring(3,presently.length));
whereto-=noPages;
SPage('pos'+whereto);
}

function gothere(num) {
// don't allow a number higher than the number of pages
if (num >maxi){num=maxi};

if (num%noPages==0)
	incr=  (num-1)+1;
else
	incr = (num-1)+noPages;
SPage('pos'+incr);

}



function findDiv(str){
  plin=false;
	found=false;
	numf=0;
	kw=0;
	sfound="";
	var s=1;
	str = new Array();
	str[0]="stt";
	sr="<br />";
		temp=document.getElementById('srchfrm').srch.value+" ";
		
		if (!sengin) {space=" ";	}
		else
		{
		space="+";
		starter=temp1.substring(temp1.indexOf("q"),temp1.length);
		temper=starter.substring(starter.indexOf("=")+1,starter.length);
		temp=temper+space;
		}
			while(temp!=""){
			if (str[s-1]!="stt")
			s++;
				if (str[s-1]!=temp){
				str[s-1]=temp.substring(0,temp.indexOf(space,1));
				temp=temp.substring(temp.indexOf(space,1)+1,temp.length);
				kw++;
				}
		  }

document.getElementById('pos1').innerHTML="";
objBody = document.getElementsByTagName('div');
countAttr = objBody.length;
divArray= new Array();
for (k=0;k<countAttr;k++){
	divArray[k]=objBody.item(k).id
	if (divArray[k].substring(0,3)=='pos'){
	j=divArray[k].substring(3,divArray[k].length);
					for (n=0;n<kw;n++){
					if(str[n].length>3){
					//skips page three where I have my TOC.../Search page
					if(j==3){j++}
					if(findInPage(str[n],j)){
					found=true;
					plin=true;
					nex = (j-1)+2;
					sfound+=str[n]+" ";
				if (j%noPages==0){
				pg="pos"+j;}
				else{
				pg="pos"+nex;
				}
									}}}}

			 if(plin && (n==kw)){
			 numf++;
sr+='<a href="" onclick="return SPage(&quot;'+pg+'&quot;);"><span class="sm"><span class="red"> '+sfound+' </span> found on page '+j+'</span></a><br />';
plin=false;
sfound="";
		}		}


didyou=""+str;
	if(sengin){didyou=temp1.substring(0,temp1.lastIndexOf("/")+1)+" Search for "+str;}

if(!found){
document.getElementById('pos1').innerHTML='<img alt="" src="media/swirly2a.gif" class="swirly" /><br /><p>Click on the anchors to navigate the pages. If you prefer a larger/smaller text size, click \'View/Text Size\' in your browser\'s menu.</p><br /><span class="sm">Sorry, Your <span class="red"> '+didyou+' </span> was not found...</span><br />';}


	else{
	
document.getElementById('pos1').innerHTML='<p>Click on the anchors to navigate the pages. If you prefer a larger/smaller text size, click \'View/Text Size\'  in your browser\'s menu.</p><br /><span class="sm">Your search  "<span class="red"> '+didyou+' </span>" was found '+numf+' time(s).</span><br /> '+sr+'<br/>';
temper='pos'+noPages;
SPage(temper);
document.getElementById('toc').innerHTML='Go To <a href="#" onclick="return SPage(temper)"><span class="red">Search Results</span></a>'
if (noPages>1){
document.getElementById('toc').innerHTML+='<br />Go To <br /><a href="#" onclick="SPage(&quot;pos4&quot;)">Table of Contents</a><br />Send Comments to <a href="mailto:John@morewood.net">John@morewood.net </a><br /> &#169; John Grove 2000';}
}

}

function findInPage(str,vwr){

var srchin= new RegExp(str,"i");
var clvwr = document.getElementById('pos'+vwr);
	if(srchin.test(clvwr.innerHTML)){
	return true;
	}
	else
		return false;
		}
		
/*function stoperror(){
return true
}
window.onerror=stoperror
*/			
