// Connect to Atlas adserver

// Page ID
apnpageNum = Math.round(Math.random() * 100000000000); /* need 12 digit for DoubleClick */

// bServer call 
function SetupAds(strSite,strArea,adArr,keyword){ 

    // Cache-busting and pageid value
    var aamRnd = Math.round(Math.random() * 100000000000);
    
    // Adserver URL
    adserver = "http://ads.apn.co.nz/bserver";
    
    // Ad tag targeting values which will be appended to each ad request section in the bserver ad call

    var site = strSite;
    var area = strArea;
    
    allAdTags = "/AAMALL/acc_random=" + aamRnd + "/pageid=" + apnpageNum + site + area + keyword; 

    //loop through adArr with all the ad call strings provided
    if(adArr.length > 0 && typeof(adArr[0]) != 'undefined'){
        
        var adStr = '';
        
        for(i=0;i<adArr.length;i++){
            
            adStr = adStr + adArr[i];
            
            
        }

        document.write('<SCR' + 'IPT SRC="' + adserver + allAdTags  + adStr + '?" type="text/JavaScript" language="JavaScript">');
        document.write('</SCR' + 'IPT>');
        
     }

}


function checkId (elementId)
{
	myObj = document.getElementById(elementId);
	if (myObj != null)
	// check the rendering divs before calling ads
{
		return true;
	}
	else
	{
		return false;
	}
}