A Genetic Explanation For Religion
I'm an atheist, but it seems that religious belief is genetic. I think religion can be explained as an evolutionary trait.
A violent man is more likely to be killed before he has children and passes on his violent genes, and similarly a promiscuous man is less likely to raise his children in a stable environment. In a lawless society, people with a moral framework would therefore have a genetic advantage over those who were immoral. In these conditions a genetic moral code would emerge, religion.
The most important influence of religion therefore is to provide a moral framework, particulary telling people to avoid violence and promiscuity. Death, injury or a sexual disease and a stable relationship can be important factors in evolution so in a society without law, religious individuals will have a genetic advantage.
A religion has other facets however, including belief in gods, fate or an afterlife. These beliefs might impart a slight genetic advantage over non-religious people for example calmness and self belief, and a brotherhood of fellow believers to call upon for social support. Social support an social work by religious individuals may have been very important in states that did not or do not provide such support.
In a society with laws and law enforcement however, the morality advantage is lost because all individuals should avoid violence and promiscuity equally (there are probably more laws to prohibit violence than promiscuity so one could speculate that in lawful societies a religion that forbids promiscuity but not violence will emerge). A moral code enforced by law could lead to the decline of religion, especially if the secondary facets also exist in law such as a brotherhood (in socialist societies) and self belief (successful capitalists often have strong self-belief, this trait can be imparted into children). It should also be noted that most human societies historically have been lawless.
If calmness due to self-belief in a better future, a moral code and a supporting brotherhood produced positive biological traits then one could imagine an ideal religion or ideal society. Members would not engage in any violence or promiscuity, believe that things would turn out positively in the end (for whatever reason), and give special treatment to other members.