Cleaned up autocomplete. Works better now.

Change-Id: Ib3dbdc7873f9a9f85184538c866042f5719acb4d
diff --git a/client/catalog/js/autocomplete.js b/client/catalog/js/autocomplete.js
index 8ad97fb..df54c17 100644
--- a/client/catalog/js/autocomplete.js
+++ b/client/catalog/js/autocomplete.js
@@ -1,14 +1,14 @@
 /*
  * The following code is a jquery extention written to add autocomplete functionality to bootstrap input groups.
- * 
+ *
  * Usage:
- * 
+ *
  * Then simply call $('.someClass').autoComplete(getSuggestions) on it to enable auto completion.
- * 
+ *
  * getSuggestions returns by calling its callback parameter with an array of valid strings.
- * 
+ *
  * Autocomplete can be manually triggered by triggering the autoComplete event.
- * 
+ *
  */
 (function(){
   "use strict";
@@ -71,8 +71,20 @@
 
       element.bind('click', 'a', function(){
         input.val($(event.target).text());
+        getSuggestions(getValue(), setAutoComplete);
+        input.focus();
       });
 
+      var updateFromList = function(){
+        var val = input.val(); //Needs to be unfiltered, for filtering existing results.
+        setAutoComplete(lastList.reduce(function(prev, current){
+          if (current.indexOf(val) === 0){
+            prev.push(current);
+          }
+          return prev;
+        }, []));
+      }
+
       this.keydown(function(e){
         switch(e.which){
           case 38: //up
@@ -106,6 +118,7 @@
           if (active.length === 1){
             $(this).val(active.text());
             e.preventDefault();
+            getSuggestions(getValue(), setAutoComplete);
           }
           break;
 
@@ -115,20 +128,27 @@
           break;
 
           default:
-          var val = input.val(); //Needs to be unfiltered, for filtering existing results.
-          setAutoComplete(lastList.reduce(function(prev, current){
-            if (current.indexOf(val) === 0){
-              prev.push(current);
-            }
-            return prev;
-          }, []));
+          updateFromList();
 
         }
 
       })
       .keyup(function(e){
-        if (e.which === 191){
+        switch (e.which){
+
+          case 191:
           getSuggestions(getValue(), setAutoComplete);
+
+          break;
+          case 38:
+          case 40:
+          case 13:
+          case 9:
+          // Do nothing
+
+          break;
+          default:
+          updateFromList();
         }
       });