Magnetic interactions in transition-metal-doped ZnO: An ab initio study