Code cleanup of search js

Refactor of _layouts/search.html.  Mostly a javascript refactor, but also moved "if page.lang" block out of the js  to the top of the file.

This is a quick refactor.  More is needed.  Plus some tests. Testing was done by comparing behavior on the live site with my local site.