Kev543 has provided an excellent overview.
That being said, the most common cause of "charlie horses" is hypocalcemia, or low blood calcium. The co-factor is often vitamin D3 deficiency. D3 is necessary for the calcium to be absorbed in the intestine. D3 is manufactured when the skin is exposed to sunlight. Thus additional sunlight exposure or a vitamin D3 supplement, together with a glass of milk or two may solve the problem.
At one time quinine sulfate pills were sold over the counter (for over 100 years) to control such cramps, however the FDA recently restricted their distribution because of several alleged deaths due to inteference with the electrical activity of the heart. They are still available on the shelves of some health food stores.
These muscle cramps can have many possible causes including hormonal imbalances, dehydration, low levels of potassium or calcium in the blood, side effects of medication, or, more seriously, diseases such as amyotrophic lateral sclerosis and neuropathy.[6] They are also a common complaint during pregnancy or for the elderly.[7] most of the time it is from extreme workouts. more common reasons would be dehydration and low potassium or calcium. eat a banana, drink some milk and see if that helps.