A generalization of Bertrand's theorem to surfaces of revolution