The game is drawn, upon a correct claim by the player having the move, when the same position, for at least the third time (not necessarily by sequential repetition of moves)
is about to appear, if he first writes his move on his scoresheet and declares to the arbiter his intention to make this move, or
has just appeared, and the player claiming the draw has the move.
Positions as in (a) and (b) are considered the same, if the same player has the move, pieces of the same kind and colour occupy the same squares, and the possible moves of all the pieces of both players are the same.
Positions are not the same if a pawn that could have been captured en passant can no longer be captured or if the right to castle has been changed temporarily or permanently.
Taken from FIDE Laws of Chess (http://www.fide.com/official/handbook.asp?level=EE101)