Optical study of the charge-density-wave mechanism in 2H-TaS2 and NaxTaS2