This is the Mitzvah of comforting mourners. It is considered more important than visiting sick people, for it enables you to honor both the dead and the living. One may visit Avelim on any of the Shivah days, but it is best, if possible, to visit after the first three days. During the first three days the mourner's grief is so great that he cannot really be comforted, and therefore usually only best friends and relatives are present at that time.
On the visit it is not accepted to say hello to the mourner. You must wait for the mourners to turn to you, and only then should you try comforting them. There is nothing "right" or "wrong" to say, but instead it is advisable to listen to the mourner, who often feels the need to talk. The purpose of comforting mourners is not to make them forget their grief or ignore it, but to let them know that they have the support of their friends, and help them deal with their loss.
During the visit try and notice when the mourners want you to leave, in order to avoid making them feel uncomfortable. Never tell a mourner to "sit down", because the mourning is referred to as "sitting Shivah". Therefore by telling a mourner to sit it is as though you are telling them to continue mourning. Finally, when you leave, do not say "good-bye". Instead, it is customary to say "May God comfort you amongst the mourners of Zion and Jerusalem".