Sorting javascript for extended search