I don't know the origin of your error, but I must ask why you enclosed your script in a function. And you really should consider removing the vars in strings. Might you also place your code in between the code tags so it makes it a little easier to read.

BTW: What is the error?