LOL, I think that if a person asks for some script it is because of 2 reasons.
1. they don't know how to do it 2. they don't want to re-do it
I think asking them to code it themselves kind of goes against what this Community is about. He obviously would not have asked the question if 1 of the two above criteria were met.
However, I would have asked this question in another section. This section is for MODS. I have a good portion of the script you are looking for that was part of even a better mod courtesy of Work_Mule (which is the webmaster of the site you found this). I will disect the code for you and return with the routine. Should be rather simple.
Sorry about the post here, where should I post these questions? And to answer crash's question, I know the code already exists and didn't want to re-invent the wheel ;)