  Massive black-hole binaries (MBHBs) are thought to be the main source of
gravitational waves (GWs) in the low-frequency domain surveyed by ongoing and
forthcoming Pulsar Timing Array campaigns and future space-borne missions, such
as {\it eLISA}. However, many low-redshift MBHBs in realistic astrophysical
environments may not reach separations small enough to allow significant GW
emission, but rather stall on (sub)pc-scale orbits. This "last-parsec problem"
can be eased by the appearance of a third massive black hole (MBH) -- the
"intruder" -- whose action can force, under certain conditions, the inner MBHB
on a very eccentric orbit, hence allowing intense GW emission eventually
leading to coalescence. A detailed assessment of the process, ultimately driven
by the induced Kozai-Lidov oscillations of the MBHB orbit, requires a general
relativistic treatment and the inclusion of external factors, such as the
Newtonian precession of the intruder orbit in the galactic potential and its
hardening by scattering off background stars. In order to tackle this problem,
we developed a three-body Post-Newtonian (PN) code framed in a realistic
galactic potential, including both non-dissipative 1PN and 2PN terms, and
dissipative terms such as 2.5PN effects, orbital hardening of the outer binary,
and the effect of the dynamical friction on the early stages of the intruder
dynamics. In this first paper of a series devoted at studing the dynamics of
MBH triplets from a cosmological perspective, we describe, test and validate
our code.
