The example you're referring to is making things a bit to complicated for your particular problem. Here is a ...
stackoverflow.com