This post has a nice bit of code which should help you.