All three major U.S. stock indexes closed in positive territory after struggling for direction in early trading and all three notched weekly gains