An accurate density-functional method for the study of magnetic properties. The PBE0 model