Top seed Tommy Haas battled his way into the quarter-finals of the Mercedes Cup with victory over Ernests Gulbis.