Have you tried contacting the person who wrote this?
Frankly, it looks like a mess. I wouldn't bother copying this from someone.
Also, I don't have good experience trying to troubleshoot code from a third party with someone who didn't write it. It too quickly boils down to trying to retrace all the steps of the mystery author and that's tedious work.
Let's take one step back - what are you trying to do?