I've heard that beer can stay in the primary for several weeks, but I continue to rack to a secondary. I usually do it as soon as the head has died down and I'm pretty sure it's not going to flare up again in the carboy. I like to get the beer away from the grungy primary and get the primary cleaned. (I use a plastic pail for primary, and glass carboy for secondary.) And I like to do it quite early so that there will be plenty of CO2 still coming out of the beer to force the 02 out of the carboy. I usually let it sit a days or two, and then top it up with water.
I think there is still plenty enough yeast in suspension to do the clean-up mentioned by Jeff L.
I often bottle 2 or 3 weeks later. And though I know I probably don't need to use a secondary at all in those cases, I like to do it anyway. It's party aesthetic.