Rearranged login javascript