// SEARCH AND FILTER FUNCTIONALITY =================================================================
   	// Hides titles not matching the user's search query ---------------------------------
	function filterTitles(){
		var foundCount	= xmlProducts.length;
		var filterTxt 	= findObj("searchField").value;
		var originalTxt	= filterTxt;
		
		filterTxt = filterTxt.toUpperCase();
		filterTxt = filterTxt.replace(/[^a-zA-Z 0-9]+/g,'');
		filterTxt = filterTxt.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
		filterTxt = filterTxt.replace(/(\s)\1+/g, ' ');
		filterTxt = filterTxt.split(' ');

		var currentTitle = null;
		for(var i=0; i<xmlProducts.length; i++){
			if(xmlProducts[i][0] != null){
				currentTitle 					= findObj("buyPlate" + xmlProducts[i][0] );
				currentTitle.style.display 		= "block";
				var titValB = "" + xmlProducts[i][2];
				var titValR = "" + xmlProducts[i][3];
				
				titValB = titValB.replace(/[^a-zA-Z 0-9]+/g,'');
				titValR = titValR.replace(/[^a-zA-Z 0-9]+/g,'');
				var aMatch = true;
				var bMatch = true;
				
				for(var j = 0; j < filterTxt.length; j++) {
					var x = new RegExp(filterTxt[j], "i");
					if(titValB.search(x) == -1) aMatch = false;
					if(titValR.search(x) == -1) bMatch = false;
				}
				
				//if(titVal.toUpperCase().indexOf(filterTxt) != 0){ // Use this if matching from front
				if(!aMatch && !bMatch){	// Use this if matching within
					currentTitle.style.display 	= "none";
					foundCount--;
				}
			}
		}
		if(filterTxt != ""){
			findObj("filteredBy").innerHTML = "Displaying: Titles containing <b>'" + originalTxt + "'</b>";
			findObj("xOfY").innerHTML = "Displaying <b>" + foundCount + "</b> of <b>" + (xmlProducts.length) + "</b> titles.";
		}else{			
			findObj("filteredBy").innerHTML = "Displaying: <b>All Titles</b>";
			findObj("xOfY").innerHTML = defaultCount;
		}
	} // EO: filterTitles ----------------------------------------------------------------
	
	// Hides titles not beginning with any of a number of specified letters --------------
	function letterFilter(letterChain){
		letterChain = letterChain.split(',');
		var shownCount = 0;
		for(var i=0; i<xmlProducts.length; i++){
			if(xmlProducts[i][0] != null){
				currentTitle 					= findObj("buyPlate" + xmlProducts[i][0] );
				currentTitle.style.display 		= "none";
				var titValB = "" + xmlProducts[i][2];
				var titValR = "" + xmlProducts[i][3];
				
				for(var j=0; j<letterChain.length; j++){
					if(titValB.toUpperCase().indexOf(letterChain[j]) == 0 || titValR.toUpperCase().indexOf(letterChain[j]) == 0){
						currentTitle.style.display 	= "block";
						shownCount++;
					}
				}
			}
		}
		findObj("filteredBy").innerHTML = "Displaying: Titles beginning with " + (letterChain[0] + "-" + letterChain[letterChain.length-1]);
		findObj("xOfY").innerHTML = "Displaying: <b>" + shownCount + "</b> of <b>" + xmlProducts.length + "</b> titles.";
	} // EO: letterFilter ----------------------------------------------------------------
	
	// Reveals all titles and clears the Search field ------------------------------------
	function clearFilter(){
		findObj("searchField").value = "";
		filterTitles();
	} // EO: clearFilter -----------------------------------------------------------------
// =================================================================================================