

keywords = new Object();
desc = new Object();
links= new Object();
matched= new Object();
searchwords= new Object();
found= new Object();
var temp=0;

// # of keywordss present in the my so-called DB
keywords[0]=10
//number of searchwords after parsing
searchwords[0]=0
//number of  matches found.
found[0]=0



keywords[1]="Solar System planets mars venus earth saturn neptune mercury jupiter uranus sun moon"
desc[1]="Information on all 9 planets in our solar system. "
links[1]="http://www.littlebear-observatory.com/new/ssystem.htm"
matched[1]=0

keywords[2]="meade telescope vendor camera scope orion celestron sbig software Accessories Oceanside Photo"
desc[2]="All the top amateur astronomy vendors. "
links[2]="http://www.littlebear-observatory.com/new/vendors.htm"
matched[2]=0

keywords[3]="Meade LX200 equipment Celestron c8 telescope"
desc[3]="The equipment at Littlebear Observatory. "
links[3]="http://www.littlebear-observatory.com/new/equip.htm"
matched[3]=0

keywords[4]="Littlebear Astronomy Web Rings Webrings LUNAR UNDERGROUND"
desc[4]="Littlebear Astronomy Web Rings. "
links[4]="http://www.littlebear-observatory.com/new/rings.htm"
matched[4]=0

keywords[5]="'planetary society' organizations ida 'auckland astronomical society' variable 'star observers'"
desc[5]="Organizations that Littlbear belongs to or supports. "
links[5]="http://www.littlebear-observatory.com/new/organizations.htm"
matched[5]=0

keywords[6]="space flight mars astronomy galaxy"
desc[6]="Littlebear Astronomy Links. "
links[6]="http://www.littlebear-observatory.com/new/astrolinks.htm"
matched[6]=0

keywords[7]="references Exploratorium physics 'drift alignment' imaging CFITSIO 'light polution' astronmomical telescopes"
desc[7]="Littlebear References. "
links[7]="http://www.littlebear-observatory.com/new/references.htm"
matched[7]=0

keywords[8]="observatory observatories 'deep space'"
desc[8]="Littlebear Observatory Links. "
links[8]="http://www.littlebear-observatory.com/new/observatories.htm"
matched[8]=0

keywords[9]="weather time viewing atomic 'atomic time'"
desc[9]="Littlebear Observatory Weather and Time. "
links[9]="http://www.littlebear-observatory.com/new/weather.htm"
matched[9]=0

keywords[10]="nudge star galaxy nebula st-237 Robofocus"
desc[10]="Cosmic Controls "
links[10]="http://www.cosmiccontrols.com"
matched[10]=0



//Don't forget to increment Joel!!

function search(){
var sSearchword=document.searchengine.searchwords.value.toLowerCase();
var check=1;
var pos=0;
var i=0;
var j=0;
var  itemp=0;
var config='';

while (true)
	{
	if (sSearchword.indexOf("+") == -1 )
		{
		searchwords[check]=sSearchword;
		break;
		}
	pos=sSearchword.indexOf("+");
	if (sSearchword !="+")	
	{
	searchwords[check]=sSearchword.substring(0,pos);
	check++;
	}
	else
	{
	check--;
	break;
	}
	sSearchword=sSearchword.substring(pos+1, sSearchword.length);	
	if (sSearchword.length ==0)
		{
		check--;
		break;
		}
			 
	}
// the searchwords have been put in searchwords object.
searchwords[0]=check;

// matching and storing the matches in matched
for ( i=1; i<=searchwords[0];i++)
	{
	for (j=1;j<=keywords[0];j++)
		{
		if (keywords[j].toLowerCase().indexOf(searchwords[i]) > -1 )
			{
			  matched[j]++;
			}
		}	
	}
// putting all the indexes of the matched records  in found

for (i=1;i<=keywords[0];i++)
{
	if (matched[i] > 0 )
		{
		  found[0]++;
		// increment the found 	
		  found[found[0]]=i;
			
		}	
}



for (i=1;i<=found[0]-1;i++)
	{
	for(j=i+1;j<=found[0];j++)
		{
		if ( matched[found[i]]< matched[found[j]] )
			{
			temp= found[j];
			found[j]=found[i];
			found[i]=temp;
			}
		}
	}

// end of sort

output = self;
output.document.write('<html>');
output.document.write('<head>');
output.document.write('<script>');
output.document.write('window.onerror=new Function("return true")');
output.document.write('<\/script>');
output.document.write('<title> Littlebear Observatory Search Results </title>');
output.document.write('</head>');
output.document.write('<BODY bgcolor=#ffffff  text=#000000  link=#990099 vlink =#339966 >');

output.document.write('<center> <h1>  </h1></center>');    
output.document.write('<br>');
output.document.write(' You searched for: '.big() )
for (i=1;  i<=searchwords[0]; i++)
	{
	output.document.write( searchwords[i].bold() +"   ");
	}
output.document.write('<br>');

if (found[0]==0)
	{
	//alert(found[0]);
	output.document.write('<br>');
	output.document.write("<font color='red'><b>No Matches</b></font><br><small><i><b>Getting the best results in your search:</b> To search for pages that contain two words with no direct association, you should connect the words with a '+' sign. For instance 'mars+telescope'. Words that go together such as 'Astronomical Society' or 'Drift Alignment' should be searched as is. <br><A HREF='index.htm'><font color='darkblue'>Back to Home Page</font></A></i></small> <br>");
	output.document.write("<br>");
	output.document.write("<br>");
	output.document.write("<i><small>Note: If you wish to search the web outside of Littlebear, <a href='http://www.hotbot.com'><font color='darkblue'>click here</font></a>.</small></i>");

	}
else
	{
	// data has been found
	output.document.write(" <hr> <b> </b>  ");
	output.document.write( found[0] +"  Result(s) found  ".italics());
	output.document.write("<table border=1 width=100%>");
	for (i=1; i<=found[0];i++)
		{
		output.document.write("<tr><td valign=top bgcolor=gray>");
		output.document.write("<h3>" +i +"</h3>");
		output.document.write("<td valign=top>");
		itemp=found[i];
		output.document.write(desc[itemp].bold() +"<br>" +
		links[itemp].link(links[itemp])+"<br>");
		temp= (matched[itemp]/searchwords[0])*100
		output.document.write("<i> Matched  with your search: " +temp+" %  </i>" );
		matched[itemp]=0
		} 
	found[0]=0;
	output.document.write("</table>");
	}
output.document.write ('');
output.document.write ("<br>");
//output.document.write ("<form><center>"); 
output.document.write("<center><center>");
//output.document.write ("<input type='button' value='Start Another Search' onClick = 'self.close()'"); 
//output.document.write ("<center></form>");

output.document.write ("</body></html>"); 
output.document.close();
}
