function tmDisplayBanner(banners, divName, width, height, defaultSize) {
	if (!defaultSize) defaultSize = "300x250";
	var size = width + 'x' + height;
	var adDiv = document.getElementById(divName);
	
	// Loop through all the banners
	for (var i=0;i<banners.length;i++) {

		var banner = banners[i];
		// Find the correct sized one
		var bannerSize = banner.size ? banner.size : banner._size;
		if ((bannerSize == null) || (bannerSize == "undefinedxundefined") || (bannerSize == "NaNxNaN"))
			bannerSize = defaultSize;
				
		if (bannerSize == size) {
			// Remove old ads
			tmRemove(adDiv);
			
			// If there is a iframe, use it
			var htmlUrl = banner.htmlUrl ? banner.htmlUrl : banner._htmlUrl;
			var swfUrl = banner.swfUrl ? banner.swfUrl : banner._swfUrl;
			var imageUrl = banner.imageUrl ? banner.imageUrl : banner._imageUrl;
			var clickUrl = banner.clickUrl ? banner.clickUrl : banner._clickUrl;
			if (htmlUrl) {
				// Create the iframe
				var iframe = document.createElement("iframe");
				iframe.setAttribute("id", "acudeo_iframe");
				iframe.style.width = width + "px";
				iframe.style.height = height + "px";
				iframe.style.border = "0";
				iframe.scrolling = "no";
				iframe.marginWidth = "0";
				iframe.marginHeight = "0";        
				iframe.frameBorder = "no";
				adDiv.appendChild(iframe);

				// IE has a weird caching issue, so we have to append the 
				// iframe, then set the src
				//adDiv.getElementById("acudeo_iframe");
				var new_iframe = getElement(adDiv, "acudeo_iframe");
				new_iframe.src = htmlUrl;
				new_iframe.frameborder = "no";
			// Otherwise if there is a SWF URL, use that
			} else if (swfUrl) {
				// Get the object HTML
				var objHtml = '<object';
				objHtml += ' classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="' + width + '" height="' + height+ '" id="acudeo_swf">';
				objHtml += '<param name="movie" value="' + swfUrl + '" />';
				objHtml += '<param name="quality" value="high" />';
				objHtml += '<param name="wmode" value="transparent" />';
				objHtml += '<param name="allowfullscreen" value="true" />';
				objHtml += '<param name="allowscriptaccess" value="always" />';
				objHtml += '<!--[if !IE]>-->';
				objHtml += '<object type="application/x-shockwave-flash" data="' + swfUrl + '" width="' + width + '" height="' + height + '" id="acudeo_swf">';
				objHtml += '<param name="quality" value="high" />';
				objHtml += '<param name="wmode" value="transparent" />';
				objHtml += '<param name="allowfullscreen" value="true" />';
				objHtml += '<param name="allowscriptaccess" value="always" />';
				objHtml += '<!--<![endif]-->';
				objHtml += '<a href="http://www.adobe.com/go/getflashplayer">';
				objHtml += '<img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />';
				objHtml += '</a>';
				objHtml += '<!--[if !IE]>-->';
				objHtml += '</object>';
				objHtml += '<!--<![endif]-->';
				objHtml += '</object>';
		
				// Create a span to hold the
				var span = document.createElement("span");
				span.setAttribute("id", "acudeo_span");
				
				// Append the span and set the HTML
				if (navigator.appName.indexOf("Microsoft") != -1) {
					adDiv.appendChild(span);
					var span = getElement(adDiv, "acudeo_span");
					span.outerHTML = objHtml;
				} else {
					span.innerHTML = objHtml;
					adDiv.appendChild(span);
				}
				
			// Otherwise if there is an image, use that
			} else if (imageUrl) {

				// Create the anchor tag
				var a = document.createElement("a");
				a.setAttribute("href", clickUrl);
				a.setAttribute("target", "_blank");
				a.setAttribute("id", "acudeo_a");
				
				// Create the image tag
				var img = document.createElement("img");
				img.setAttribute("src", imageUrl);
				img.setAttribute("border", 0);
				img.setAttribute("width", width);
				img.setAttribute("height", height);
				a.appendChild(img);

				// Add the tag
				adDiv.appendChild(a);
      }
		}
	}
}

function tmRemoveBanner(divName) {
	var adDiv = document.getElementById(divName);
	tmRemove(adDiv);
}

function tmRemove(adDiv) {
	var old_iframe = getElement(adDiv, "acudeo_iframe");
	if (old_iframe) {
		adDiv.removeChild(old_iframe);
	}
	var old_span = getElement(adDiv, "acudeo_span");
	if (old_span) {
		adDiv.removeChild(old_span);
	}
	var old_a = getElement(adDiv, "acudeo_a");
	if (old_a) {
		adDiv.removeChild(old_a);
	}		
}

function getElement(div, childId) {
	if (div.hasChildNodes()) {
		for(i=0;i<div.childNodes.length;i++){ 
			if(div.childNodes[i].nodeType == 1) {
	   		if (div.childNodes[i].id == childId) {
	   			return div.childNodes[i];
	   		}
	   }
	  }
		
	} else {
		return null;
	}	
}