I have a script that runs a floating ad (layer ad) but i am having some weird problem with it work when i call a JS from inside the JS that has already been called.

Here is how it works....

Code:
<script language='JavaScript' type='text/javascript' src="http://www.my-site.com/newlay.php?client=1&t=0&l=0"></script>
This code calls the file that includes everything to make the layer work.

Code:
<?php

echo '
var CLIENT_ID = '.$_REQUEST['client'].';
var bTOP = '.$_REQUEST['t'].';
var bLEFT = '.$_REQUEST['l'].';

document.write(\'<style type="text/css">\');
document.write(\'<!--\');
document.write(\'#sponsorAdDiv {position:absolute; height:1; width:1px; top:0; left:0;}\');
document.write(\'-->\');
document.write(\'</style>\');

adTime=1300; 
chanceAd=1; 

var ns=(document.layers);
var ie=(document.all);
var w3=(document.getElementById && !ie);
var calunit=ns? "" : "px"
adCount=0;
function initAd(){
   if(!ns && !ie && !w3) return;
   if(ie)        adDiv=eval(\'document.all.sponsorAdDiv.style\');
   else if(ns)    adDiv=eval(\'document.layers["sponsorAdDiv"]\');
   else if(w3)    adDiv=eval(\'document.getElementById("sponsorAdDiv").style\');
   randAd=Math.ceil(Math.random()*chanceAd);
       if (ie||w3)
       adDiv.visibility="visible";
       else
       adDiv.visibility ="show";
   if(randAd==1) showAd();
}
function doMax() {
window.moveTo(0,0); window.resizeTo(screen.availWidth,screen.availHeight);
}
function showAd(){
if(adCount<adTime*10){adCount+=1;
   if (ie){documentWidth  =truebody().offsetWidth/2+truebody().scrollLeft-20;
   documentHeight =truebody().offsetHeight/2+truebody().scrollTop-20;}    
   else if (ns){documentWidth=window.innerWidth/2+window.pageXOffset-20;
   documentHeight=window.innerHeight/2+window.pageYOffset-20;} 
   else if (w3){documentWidth=self.innerWidth/2+window.pageXOffset-20;
   documentHeight=self.innerHeight/2+window.pageYOffset-20;} 
   adDiv.left=documentWidth-350+calunit;adDiv.top =documentHeight-150+calunit;
   setTimeout("showAd()",100);}else closeAd();
}

function closeAd(){
if (ie||w3)
adDiv.display="none";
else
adDiv.visibility ="hide";
}

function truebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}
function phpads_deliverActiveX(content)
{
	document.write(content);	
}
window.onload=initAd;

document.write(\'<div id="sponsorAdDiv" style="position:absolute;visibility:show;left:'.bLEFT.'px;top:'.bTOP.'px;width:198;height:200;background-color:#F5F5F5;background:none;z-index:99;">\');
document.write(\'<div id="close" align="left" style="visibility:hidden;"><a href="javascript:closeAd()">Close this advertisement</a></div>\');
';



echo '
if (!document.phpAds_used) document.phpAds_used = \',\';
phpAds_random = new String (Math.random()); phpAds_random = phpAds_random.substring(2,11);
document.write ("<" + "script language=\'JavaScript\' type=\'text/javascript\' src=\'");
document.write ("http://my-site.com/display/adjs.php?n=" + phpAds_random);
document.write ("&amp;what=zone:" + CLIENT_ID);
document.write ("&amp;exclude=" + document.phpAds_used);
if (document.referrer) document.write ("&amp;referer=" + escape(document.referrer));
document.write ("\'><" + "/script>");
document.write("<script>window.moveTo(0,0); window.resizeTo(screen.availWidth,screen.availHeight);</script>");
document.write(\'<script>window.moveTo(0,0); window.resizeTo(screen.availWidth,screen.availHeight);</script>\'); 
setTimeout("doMax()",750);

';

?>
Now that should work fine but for some reason this part of the code is causing problems.

Code:
if (!document.phpAds_used) document.phpAds_used = \',\';
phpAds_random = new String (Math.random()); phpAds_random = phpAds_random.substring(2,11);
document.write ("<" + "script language=\'JavaScript\' type=\'text/javascript\' src=\'");
document.write ("http://my-site.com/display/adjs.php?n=" + phpAds_random);
document.write ("&amp;what=zone:" + CLIENT_ID);
document.write ("&amp;exclude=" + document.phpAds_used);
if (document.referrer) document.write ("&amp;referer=" + escape(document.referrer));
document.write ("\'><" + "/script>");
If i replace that code with an iframe it works fine, anything but that javascript code. What happens is it shows the banner it produces in the top of the page with the page under it, where if i have an iframe code it shows it floating on top like it should.

Anyone got any ideas on how i can get this to work?