
function ignore_word(s)
{
	nignore=ignore_arr.length;
	for (iign=0;iign<nignore;iign++) {
		if (s==ignore_arr[iign])
			return(true);
	}
	return(false);
}

function search_data(search_table,search_name) {
	nfiles=path_arr.length;

	// get the search portion of the URL
	args=window.location.search.split("?");
	search_str=args[1];
	search_arg=search_str.split("=");
	// extract the word list from the search_str argument list

	split_search_str=search_arg[1].split("+");

	word_list=new Array();
	skip_list=new Array();

	for (iword=0;iword<split_search_str.length;iword++) {
		if (split_search_str[iword]=="") {
			// don't insert empty strings
		} else if (ignore_word(split_search_str[iword])) {
			// don't search for ignore words
			skip_list.push(split_search_str[iword]);
		} else {
			word_list.push(split_search_str[iword]);
		}
	}
	
	// alias for the length of the word list
	nwords=word_list.length;
	
	// lowercase each string in the word list
	for (iword=0;iword<nwords;iword++) {
		word_list[iword]=word_list[iword].toLowerCase();
	}

	// the hit list array
	hit_list=new Array(nwords);


	// create one hit list per word with nentries slots
	for (i=0;i<hit_list.length;i++) {
		hit_list[i]=new Array(nfiles);
	}
	
	document.write("<CENTER>\n");
	document.write("<A HREF=\"../index.htm\">Sacred-texts</A>&nbsp;");
	document.write("<A HREF=\"index.htm\">Catalog</A>&nbsp;");
	document.write("<A HREF=\"index.htm#search\">Another Search</A>");
	document.write("</CENTER>\n");
	document.write("<HR>\n");
	document.write("<h1 align=\"center\">" + search_name + " Search</h1>");
	for (i=0;i<skip_list.length;i++)
		document.write("skipping " + skip_list[i] + "...<BR>");
	document.write("<TABLE WIDTH=\"100%\" BORDER=\"1\">\n");
	document.write("<TR>\n");
	document.write("<TD VALIGN=\"TOP\" WIDTH=\"50%\">\n");
	document.write("<P ALIGN=\"CENTER\"><B>Matches for any word:</P></B>\n");

	// fill in each hit list
	hits=0;
	for (iword=0;iword<nwords;iword++) {
		document.write("<P><B>"+ word_list[iword] + ":</B></P>");
		for (ientry=0;ientry<nentries;ientry++) {
			// compare the word list with this keyword entry
			if (word_list[iword]==search_table[ientry][0]) {
				ifile=search_table[ientry][1];
				hit_list[iword][ifile]=1;
				hits++;
				path=path_arr[ifile][0];
				title=path_arr[ifile][1];
				document.write(
					"<A HREF=\"../" + path + "\">" + title + "</A><BR>");
			}
		}
	}
	document.write("<HR>");
	document.write(hits + " hit(s)<BR>");

	// in the second column display 'and' hits
	document.write("</TD>\n");
	document.write("<TD VALIGN=\"TOP\" WIDTH=\"50%\">\n");
	if (!hits) {
		// not much use continuing
		document.write("No matching keywords!");
	} else {
	
		document.write(
			"<P ALIGN=\"CENTER\"><B>Matches for all words:</B></P>\n");
		// look for hits which match all search words
		matches=0;
		for (ifile=0;ifile<nfiles;ifile++) {
			and_all=1;	// until proven innocent
			for (iword=0;and_all && iword<nwords;iword++) {
				// must match all
				if (!hit_list[iword][ifile])
					and_all=0;
			}
			if (and_all) {
				// display the match
				path=path_arr[ifile][0];
				title=path_arr[ifile][1];
				document.write(
					"<A HREF=\"../" + path + "\">"+ title + "</A><BR>");
				matches++;
			}
		}
		document.write("<HR>");
		document.write(matches + " matche(s)<BR>");
	}
	
	document.write("</TR>\n");
	document.write("</TD>\n");
	document.write("</TABLE>\n");
}

