var timeout;

function dispatch(adsID)
{
   var theAdsID = ""+adsID;
   clearTimeout(timeout);
   jsrsExecute("jsrs.php?action=adsdispatch", dispatchCall, "adsdispatch", Array(theAdsID), false);
}

function dispatchCall(link)
{
  if(link != "")
  {
      document.location.href = link;
  }
  else
  {
      document.location.href = "#";
  }
}

function nextAd(divName, centreID, interval, adCategory)
{
   var theCentreID = ""+centreID; //needs to be a string i think...

   if(interval > 0)
   {
      jsrsExecute("jsrs.php?action=ads", showad, "ads", Array(divName, theCentreID, adCategory), false);
   }
}

function showad(cbstring)
{
   var piece = cbstring.split("|");
   var thediv = piece[0];
   var newtag= piece[1];
   var newid = piece[2];
   var newcentre = piece[3];
   var newheading = piece[4];
   var newcontent = piece[5];
   var newlink= piece[7];
   var newlink_address = piece[8];
   var newpicture = piece[9];
   var newAdType = piece[13];
   var newinterval = piece[16];   
   var target = document.getElementById(thediv);

   if (newAdType == 'banner')
   {
   target.innerHTML = "<a title="+newheading+" href='#' onClick='dispatch("+newid+")'><img alt='"+newheading+"' hspace='0' src='../web_images/"+newpicture+"' align='baseline' border='0' /></a>";
   }
   else
   {
   target.innerHTML = newcontent;
   }

   if(newinterval > 0)
   {
      timeout = setTimeout("nextAd('adspace', "+newcentre+", "+newinterval+", '"+newtag+"')", newinterval);
   }
}

