Planar, Toroidal and projective commuting and non-commuting graphs