Religion is set in place to do two things, I beleive. One is to try to explain those that we cannot explain ourselves. In Greek religion, myths were used to explain the origin of man, and the reasons were are here, and why was the human species more advanced than others.
In modern day, Chrisianity has it's ways of explaining that too. The story of Adam and Eve try to explain where we came from and why there is "evil" in the world.
The second reason is to, like everybody has been saying, to keep order among a culture. Like Ender said, it sets up a class system. Maybe not as much as today does religion set up the class system, but that's how I believe it was.
Now, I have studied some religions and some ideas I agree with. So it seems to me that some insightful people had some good ideas and decided to expand and try to explain things with gods and myths.