I also suffer from similar cramps, when at school our games teacher told us that cramp was caused by a lack of salt and made us lick ready salted crisps to alleviate the problem when it occured. So my solution is to drink a glass of salty water which seems to work pretty well
I get them really bad as well and have been told it's through lack of potassium and you should eat bananas of fish that are high in potassium (rather than eating too much salt, which can be harmful). Some sports drinks are also a good source of potassium, I'm currently trying to find out more about it myself (after a few sleepless nights walking around the room to see if the damn thing would go!). I'll keep you posted if I find out something meanigful.