var xmlHttpAds;

function createXMLHttpRequest(x) {
	if(window.ActiveXObject) {
		x = new ActiveXObject("Microsoft.XMLHTTP");
		}
	else if (window.XMLHttpRequest) {
		x = new XMLHttpRequest();
		}
	else x = null;
	return x;
}
function trim(str)
{ return str.replace(/^\s*|\s*$/g,"");
}
function getArgs(str) {
	var args = new String(trim(location.search));
	var n = args.length;
	if(n > 0) args = str+args.substring(1, n);
	else args = "";
	return args; 
}
function getAds(ads)
{
	var src = new String("ndxAds.php?ads="+ads)
	// alert(src);
	xmlHttpAds = createXMLHttpRequest(xmlHttpAds);
  	xmlHttpAds.onreadystatechange = displayAds;
	xmlHttpAds.open("GET", src, true);
	xmlHttpAds.send(null);
}
function displayAds() { 
	if(xmlHttpAds.readyState == 4) { 
		if(xmlHttpAds.status == 200) {
			var ads = xmlHttpAds.responseText.split("===");
			for(var i = 0; i < ads.length; ++i) {
				var ad = ads[i].split("|||");
				// alert("ndx("+ad[0]+") length("+ad.length+")");
				var el = document.getElementById("divAd"+ad[0]);
				if(el) el.style.display = 'block';
				var adImage = new String("");
				var adText = new String("");
				for(var j = 1; j < ad.length; ) {
					adImage += ad[j++];
					// adText += ad[j++];
				}
				el = document.getElementById("divAdImage"+ad[0]);
				if(el) el.innerHTML = adImage;
				/* el = document.getElementById("divAdText"+ad[0]);
				if(el) {
					el.innerHTML = adText;
					el.style.display = 'block';
				} */
			}
		}
	}
}
