A Variational Analysis of the Toda System on Compact Surfaces