try to avoid large queries during autocomplete

With this change we don't start searching until the user has typed a
minimum of four characters, unless the user has entered one of the 32
most common four-character substrings, in which case we wait for a
fifth character. These 32 substrings all return more than 200 results,
and in some cases thousands. Result sets that large are quite
difficult to navigate, and take an inordinate amount of time to
retrieve and insert into the page. I'm sure we can speed things up,
but for now this will help the most for the least effort.
rearrange js code for improved readability

and shorter lines