refactored permissions and put all search javascript functions in
search.js.