From the SRD:
Magic Jar
Necromancy
Level: Sor/Wiz 5
Components: V, S, F
Casting Time: 1 action
Range: Medium (100 ft.+10 ft./level)
Target: One creature
Duration: 1 hour/level or until the character returns to the character's body
Saving Throw: Will negates (see text)
Spell Resistance: Yes
By casting magic jar, the character places the character's own soul in a gem or large crystal (known as the magic jar), leaving the character's body lifeless. Then the character can attempt to take control of a nearby body, forcing its soul into the magic jar. The character may move back to the jar (returning the trapped soul to its body) and attempt to possess another body. The spell ends when the character sends the character's soul back to the character's own body (leaving the receptacle empty).
To cast the spell, the magic jar must be within spell range and the character must know where it is, though the character does not need line of sight or effect to it. ...
While in the magic jar, the character can sense and attack any life force within 10 feet per caster level (on the same plane). ...
Attempting to possess a body is a full-round action. It is blocked by protection from evil or a similar ward. ...
As a standard action, the character can shift freely from a host to the magic jar if within range, sending the trapped soul back to its body.
...