Finally found a solution that actually works.
First you get the postscribe.js and htmlparser.js files from https://github.com/krux/postscribe
Next you create a separate script file for each ad:
google_ad_client = "pub-9999999999999999";
google_ad_slot = "9999999999";
google_ad_width = 300;
google_ad_height = 250;
Now you can place a div tag where you want the ad to appear:
and the following script tags just before the </body> tag:
If you want more ads then just create an ad2.js file for it similar to the first one, add a div where that ad is to appear and add one extra script tag to the bottom of the page. Repeat for additional ads (the postscribe call must be the last line in the script or it doesn't insert the ad properly before reading further parameters and jumbling the ad info).
Thankyou for your original post about this - I had looked for something to do this ages ago and hadn't been able to find anything. Your post reminded me to look again and this time I was successful - its a lot of code just because Google hasn't updated their code to get rid of the long obsolete document.write statements though.