JavaScript: get rid of some if statements