US stock market closes mixed, posts weekly gains