I had a similiar problem with a betta I bought from PetSmart. Turned out to be a type of fungus, and the meds they suggested were useless. The meds seemed to work at first, for him and the other fish in his community tank (who sadly caught it from him), but then they all died, one by one. I only have 3 survivors from that tank, after trying everything. I lost 10 fish to it.
Surprisingly - while I would definately look into meds - I realized added aquarium salt to their tanks helped more than anything. I separated them all from eachother into smaller "hospital" tanks and made sure to watch them, feed them regularly, clean the bowls twice as much as usual. I always put salt in the tanks with every water change, and it seemed to keep them healthy. But to keep it from coming back, you'll have to soak and hand wash everything (no soap, just your hands and maybe a clean rag) or he'll get it again and again until it's too late to save him.
Also, make sure you change the filter, because it may hold traces of the sickness and release it back into the water, even if it isn't really dirty.