Glad to see you cracked it, for me Java script is very much a cut paste and tinker language rather than something I actually have a clue about.
I would love not to use them here, but the site is for someone that will need to update the site on their own, and who is a complete technophobe.
If you / the site manager has a small budget for tools other than note pad you may want to consider
Contribute which seems to do a good job of letting people update sites whilst protecting them from themselves.
Plus and this is probably the truth of it, I was too stubborn to give up once the problem had present itself.
A good trait! IMHO