var bannerServiceUri = "http://" + document.domain + "/BannerWS/BannerService.aspx?q=GetBanner&id=";

var banner = {
	"json": null,
	"generateHTML": function(index) {
		var innerHTML = "";
		
		if (this.json.Section.length > 0) {
			if (index >= 0 && index < this.json.Section.length) {
				if (this.json.Section[index].id != null) {
					innerHTML = "<img border=\"0\" alt=\"Pasang iklan di PakeTelor.com hubungi support@paketelor.com\" width=\"" + this.json.Section[index].width + "\" src=\"" + this.json.Section[index].src + "\" />";
						
					if (this.json.Section[index].href.length > 12) {
						var target = "";
						
						if (this.json.Section[index].target) {
							target = " target=\"_blank\"";
						}
						
						innerHTML = "<a id=\"" + this.json.Section[index].id + "\" href=\"" + this.json.Section[index].href + "\"" + target + ">" + innerHTML + "</a>";
					}
				}
			} else {
				for (var i = 0; i < this.json.Section.length; i++) {
					innerHTML += this.generateHTML(i);
				}
			}
		}
		
		return innerHTML;
	}
}

function generateBanner(target, id) {
	var xhr;

	try	{ xhr = new XMLHttpRequest(); }
	catch (e) {
		try	{ xhr = new ActiveXObject('Msxml2.XMLHTTP'); }
		catch (e2) {
			try	{ xhr = new ActiveXObject('Microsoft.XMLHTTP'); }
			catch(e3) {	xhr = false; }
		}
	}

	xhr.onreadystatechange  = function() {
		if(xhr.readyState  == 4) {
			if(xhr.status  == 200) {
				banner.json = eval('(' + xhr.responseText + ')');
				document.getElementById(target).innerHTML = banner.generateHTML();
			}
			
			xhr = null;
		}
	}; 

	xhr.open("GET", bannerServiceUri + id,  true);
	xhr.send(null);
}