Homoclinic and heteroclinic bifurcations in the nonlinear dynamics of a beam resting on an elastic substrate