You should keep document.write's on single lines, end each with a semi-colon, and escape the quotation marks. Something like this should work, but I'm a big groggy:
document.write('<a href=\"' +adlinks[num]+ '\" target=\"_blank\">');
document.write('<img src=\"' +ads[num]+ '\" border=\"0\"></a>');
If it doesn't work, View Source on my site, near the top you should see the BANNER ROTATION script I'm using -- modified, it should work for you...