Please attach the actual file instead of copying and pasting the content. Then just describe the error in the message text.
I'm not sure what I'm looking at here, so please update the post using that format so I can follow.
Include the error message if any and information about when the problem occurs in the post, then attach the actual file to the post for me to review. I can't follow the code when it is pasted in to the field itself like this without more description.