I must have missed the last part of the post.
anyway a quick search turned this up which seems to work ok.

http://stackoverflow.com/questions/2...ancel-function