Take it back immediately. There is no fix for this. It seems to be a hardware issue.
If its been over a month since you bought it ATT support will try to send you a new battery to fix the problem, tell them you swapped batteries with a friend and it still happened.
I battled it more over a month and even thought maybe the leaked 2.2 FROYO update might cure it. No such luck.
Don't give yourself a headache, get rid of the phone. Either swap for another Captivate or go with something else.