Effects of horizontal gradients on thermohaline instabilities in a thick porous layer