doing this through js will really not have any effect insofar as google is concerned. you need to do it in the page source so php.
i have been fishing a solution for 3 days now.. no luck, does anyone here have a better luck than me?
ask on the php forum. you can sort of do it but you need to use a templating system / buffer output and regex the links before outputting - or you can try some php dom tools, might work. either way, this is the javscript forum, good luck to you.