in reply to
Should I write your code ?
After reading the whole thread and the nodes I have this to say:
Unless you preface broken code with This Code Is Broken you shouldn't post it.
No one is helped by fixing one thing and leaving others broken (as was the case with your situation.) If you are going to take the time to help, help all the way. Or isolate the specific problem you are addressing and post the new working code.
That's what I (currently) think.
There's more than one way to do it, but only some of them actually work.