Copy the original script. Put this "function scan_event;" at the top.

Also, post the errors you are getting. I have no idea how to begin to fix your problems unless you post the errors.