function doSearch() {
	// Retrieve default separator for query elements
	var QuerySeparator = " and";
	var matchType = document.forms[0].MatchType; // Radio choices
	if ( matchType != null ) {
		// Loop through radio choices -- determine which one was selected
		for (var i=0; i < matchType.length; i++) {
			if ( matchType[i].checked ) {
				if ( matchType[i].value == "All" ) {
					QuerySeparator = " and ";
				} else if ( matchType[i].value == "Any" ) {
					QuerySeparator = " or ";				
				} else if ( matchType[i].value == "Exact" ) {
					QuerySeparator = "";				
				}				
			}
		}
	}
	
	// Retrieve Query String
	var QueryVar = new String(document.forms[0].Query.value);
	if (QueryVar.indexOf("\"", 0) == -1) { //only do this if the search string is not in quotes -- exact phrase
		while (QueryVar.indexOf("&", 0) !== -1) {
			QueryVar = QueryVar.replace("&", "and");  //otherwise "&" will throw a domino error  [updated by Chris Crompton 11/1/2003]
			}
		}
	if (QueryVar == "") {
		if ( document.forms[0].subQuery != null ){
			QueryVar = document.forms[0].subQuery.value;
			if ( QueryVar == "" ){
				alert("Search String cannot be Empty. Please enter a Query to Search.");
				return false;
			}
		}
	}

		var QueryValue = QueryVar.toLowerCase();

		// Remove extra spaces -- match one or more spaces and replace it with one space
		QueryValue = QueryValue.replace(/\s+/g, " ");
		QueryArrayRaw = QueryValue.match(/([^"\s\(\)]*(\))*\s)|(\(+"[^"]*"\)*)|(\(+[^"\s]*(\s|$))|("[^"]*"(\))*)|([^"\s]*(\))*$)/g);		
		// Build Query array by removing blank elements
		//    and eliminating trailing spaces
		QueryArray = new Array();
		var count = 0;
		//if (jdebug) alert('TESTING INTERNALLY');
		for (var i=0; i < QueryArrayRaw.length; i++) {
			//if (jdebug) alert(QueryArrayRaw[i]);
			// Remove spaces at the end of each element
			var element = QueryArrayRaw[i].replace(/\s$/, "");
			// Remove blank elements = Add non-blank elements only
			if ( element != "" ) {
				QueryArray[count] = element;
				count++;
			}
		}
// alert( QueryArray.toString() + "-end" );		
// example: c    or    b   "a or b "   f   "  c   d   "                 
		var submitflag = 0;
		for (var i=0; i < QueryArray.length; i++) {
			if  (( QueryArray[i] == 'and'  || QueryArray[i] == 'or'  || QueryArray[i] == 'not' ) &&  (QueryArray.length == 1)) {
				alert('Please enter a valid Query to Search.');
				submitflag = 1;
				return false;
			}
			
			if (( QueryArray[i] == 'and'  || QueryArray[i] == 'or'  || QueryArray[i] == 'not' ) && ( i+1 == QueryArray.length )) {
				alert('Please enter a valid Query text After the Boolean Operator');
				submitflag = 1;
				return false;
			}


			if (( QueryArray[i] == 'and'  || QueryArray[i] == 'or'  || QueryArray[i] == 'not' ) && (i == 0) && ( QueryArray.length > 0) ) {
				alert('Please enter a valid Query text Before the Boolean Operator');
				submitflag = 1;				
				return false;
			}

			// test for multiple conjunctions together
			//if ((i>0) &&  ( QueryArray[i] == 'and'  || QueryArray[i] == 'or'  || QueryArray[i] == 'not' ) &&  ( QueryArray[i-1] == 'and'  || QueryArray[i-1] == 'or'  || QueryArray[i-1] == 'not' ) ) {
			if ((i>0) &&  ( QueryArray[i] == 'and'  || QueryArray[i] == 'or' ) &&  ( QueryArray[i-1] == 'and'  || QueryArray[i-1] == 'or' ) ) {
				alert('There are two Boolean Operators listed together in your query.  Please remove one.');
				submitflag = 1;				
				return false;
			}
		
			// append an "or" to joined terms if one is not present
			if ((i>0) &&  !( QueryArray[i] == 'and'  || QueryArray[i] == 'or'  || QueryArray[i] == 'not' ) &&  !( QueryArray[i-1] == 'and'  || QueryArray[i-1] == 'or'  || QueryArray[i-1] == 'not' ) ) {
				QueryArray[i-1] = QueryArray[i-1] + QuerySeparator;
			}

		}

		if (	submitflag == 0 ) {
			// reconstruct query string including extra "ands" if needed
	         var queryString = '';
			for (var i=0; i < QueryArray.length; i++) {
                    if (queryString == '') {
                    	queryString = QueryArray[i];
                    }
                    else if (queryString != ' ') {
	 			     queryString = queryString + ' ' + QueryArray[i];
			     }
			}
			var itemCatalog = '';
			//itemCatalog = document.forms[0].SearchCatalog.options[document.forms[0].SearchCatalog.selectedIndex].value;			
			var searchForm;
			var searchParams;
			//remove quotes from querystring
			queryString = replaceSubstring(queryString, '\"', '');
						
 			document.forms[0].Query.value = queryString;
 			
 			//if (itemCatalog == "All" || itemCatalog == 'ALL') {
 				searchForm = 'SearchALL?OpenForm';
 				searchParams = '';
 				itemCatalog = '';
 			//}else{
 				//searchForm = 'Search' + '?SearchView';
 				//searchParams = '&SearchWV=1&Start=1&Count=10'; 				
			//}
				//var site = 'http://www3.best-in-class.com'	
				var url = thisDB + "/" + searchForm + '&Query=(' + queryString + ')' +
				itemCatalog + searchParams + '&AQ=' + QueryVar;
				//alert(url);
				window.top.location.href = url;	
		}

}
//


function replaceSubstring(inputString, fromString, toString) {
   // Goes through the inputString and replaces every occurrence of fromString with toString
   var temp = inputString;
   if (fromString == "") {
      return inputString;
   }
   if (toString.indexOf(fromString) == -1) { // If the string being replaced is not a part of the replacement string (normal situation)
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
        var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } else { // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
      var midStrings = new Array("~", "`", "_", "^", "#");
      var midStringLen = 1;
      var midString = "";
      // Find a string that doesn't exist in the inputString to be used
      // as an "inbetween" string
      while (midString == "") {
         for (var i=0; i < midStrings.length; i++) {
            var tempMidString = "";
            for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
            if (fromString.indexOf(tempMidString) == -1) {
               midString = tempMidString;
               i = midStrings.length + 1;
            }
         }
      } // Keep on going until we build an "inbetween" string that doesn't exist
      // Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + midString + toTheRight;
      }
      // Next, replace the "inbetween" string with the "toString"
      while (temp.indexOf(midString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(midString));
         var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } // Ends the check to see if the string being replaced is part of the replacement string or not
   return temp; // Send the updated string back to the user
} // Ends the "replaceSubstring" function