You can't expect to have good relations with the AI civs if you don't work with them. However, at times it is hard to choose between allies. If it is late in your game and everyone hates you, you may be in for a rough finish. If it is still early or midway through the game, you can take some drastic steps to improve relations.
First thing you can do is pick your allies. Look at the Civs that can offer you the most for your friendship. Tradeable resources, size and power, strategic location and so forth can give you an idea of which civs to work with. Improving relations is a SLOW process, and sometimes you have to give and not get in return in hopes that eventually things will improve. Open borders and a history of beneficial trade will go a long way to improving things. Next, you want to do what you can to gain the religious benefit... switch to their religion (especially if a few powerful civs follow the same religion), or cultivate relations and spread your own religion to them. This is a very slow process, and it doesn't always work.
Open borders is of course a two-edged sword, because while it improves relations and fosters trade, it also gives the computer AI access to move troops through your territory for whatever purposes they may have. Sometimes you have to make the sacrifice though if you truly want to improve relations - if you always refuse the computer's offers and don't trade with them or offer open borders, then you can pretty much rest assured they won't like you.
I have never been totally hated in a game of Civ IV, but I do remember a game of Civ III as the English where I was at war with more than half the world (8 of 14 civs) at one time - it was non-stop war almost the entire game, I had fought every single civ on my continent (6 total besides me) in at least one war, often two or three, and while I was technologically advanced and militarily strong, getting dog-piled by the computer civs made for a long and boring game. The odd thing was that I didn't really do anything to make the other civs mad, it was just a tangle of military alliances and quite possibly it was "Pick on the Redcoats" day.