4191ee2e337a3d376489df88a8f537f4f07c5816
larrym
  Tue Jun 26 16:22:55 2012 -0700
use suggestBox
diff --git src/hg/js/hgGateway.js src/hg/js/hgGateway.js
index afe130e..c465eab 100644
--- src/hg/js/hgGateway.js
+++ src/hg/js/hgGateway.js
@@ -1,59 +1,28 @@
 $(document).ready(function()
 {
-    $('input#suggest').autocomplete({
-        delay: 500,
-        minLength: 2,
-        // XXXX necessary still? autowidth: true,
-        source: ajaxGet(function () {return document.orgForm.db.value;}, new Object),
-        open: function(event, ui) {
-            var pos = $(this).offset().top + $(this).height();
-            if (!isNaN(pos)) {
-                var maxHeight = $(window).height() - pos - 30;  // take off a little more because IE needs it
-                var auto = $('.ui-autocomplete');
-                var curHeight = $(auto).children().length * 21;
-                if (curHeight > maxHeight)
-                    $(auto).css({maxHeight: maxHeight+'px',overflow:'scroll'});
-                else
-                    $(auto).css({maxHeight: 'none',overflow:'hidden'});
-            }
-        },
-        select: function (event, ui) {
-            document.mainForm.position.value = ui.item.id;
+    suggestBox.init(document.orgForm.db.value, $('#suggestTrack').length > 0,
+                      function(position) {
+                          $('#positionDisplay').text(position);
+                          $('#position').val(position);
             makeSureSuggestTrackIsVisible();
+                      },
+                      function(position) {
+                          $('#positionDisplay').text(position);
+                          $('#position').val(position);
         }
-    });
+                   );
     // default the image width to current browser window width
     var ele = $('input[name=pix]');
     if(ele.length && (!ele.val() || ele.val().length == 0)) {
         ele.val(calculateHgTracksWidth());
     }
 });
 
-function submitButtonOnClick()
-{
-// onClick handler for the "submit" button.
-// Handles situation where user types a gene name into the gene box and immediately hits the submit button,
-// expecting the browser to jump to that gene.
-    var gene = $('#suggest').val();
-    var db = $('input[name=db]').val();
-    if(gene && gene.length > 0) {
-        var pos = lookupGene(db, gene);
-        if(pos) {
-            makeSureSuggestTrackIsVisible();
-        } else {
-            // turn this into a full text search.
-            pos = gene;
-        }
-        $('input[name=position]').val(pos);
-    }
-    return true;
-}
-
 function makeSureSuggestTrackIsVisible()
 {
 // make sure to show knownGene/refGene track in pack mode (redmine #3484).
     var track = $("#suggestTrack").val();
     if(track) {
         $("<input type='hidden' name='" + track + "'value='pack'>").appendTo($(document.mainForm));
     }
 }