sort array by pseudorank & fixed course input bug

uses sean's pseudorank algorithm to sort order of array, instead of just
priority.
fixed the course select bug where placeholder and popup wasn't working.
general code cleanup in database function javascript.