The Link between Chemical Anomalies along the Red Giant Branch and the Horizontal Branch Extension in Globular Clusters