function match(index)
{
	var str = document.forms[1].str.value.toLowerCase(); // what the user entered
	var all = document.forms[1].all[0].checked;
	var i, j;

	str = str.replace(/'/g, ""); // remove '

	var S = str.split(/[\s\-\,]/); // breaks it up into an array at white space - and ,
	var C = p[index].code.toLowerCase();
	var T = p[index].title.toLowerCase().split(" "); // breaks up title of pic into an array
	var D = p[index].desc.toLowerCase().split(" "); // breaks up description of pic into an array
	var K = p[index].keywords.toLowerCase().split(" "); // breaks up keywords of pic into an array

	var matched = false;
	for (j=0; j<S.length; j++)
	{
		if (S[j]=="" || S[j]==" ") continue;
		var singular = (S[j].length > 2 && S[j].charAt(S[j].length-1=="s"))? S[j].substring(0, S[j].length-1): "potato";
		var plural = S[j].length > 2 ? S[j].concat("s"): "potato";

		var matchedC = false;
		if (C==S[j])
		{
			matchedC = true;
		}
		var matchedT = false;
		for (i=0; i<T.length; i++)
		{
			if (T[i]==S[j] || T[i]==singular || T[i]==plural)
			{
				matchedT = true;
				continue;
			}
		}
		var matchedD = false;
		for (i=0; i<D.length; i++)
		{
			if (D[i]==S[j] || D[i]==singular || D[i]==plural)
			{
				matchedD = true;
				continue;
			}
		}
		var matchedK = false;
		for (i=0; i<K.length; i++)
		{
			if (K[i]==S[j] || K[i]==singular || K[i]==plural)
			{
				matchedK = true;
				continue;
			}
		}
		matched = matchedC || matchedT || matchedD || matchedK;

		if (all && !matched) return false;
		if (!all && matched) return true;
	}
	return matched;
}
