Refactoring Advanced Search JavaScript