Modularised the search form, updated the javascript

Spent most of the day debugging the javascript search form. Was getting
pretty frustrating for a while. Looks like the base javascript Array
prototype has been changed, and so if you try and use an in loop, it
messes up and starting giving you custom functions.