var xmlhttp

if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	try {
		xmlhttp = new XMLHttpRequest();
	}
	catch (e) {
		xmlhttp=false
	}
}

function myXMLHttpRequest() {
	var xmlhttplocal;
	try {
		xmlhttplocal= new ActiveXObject("Msxml2.XMLHTTP")
	}
	catch (e) {
		try {
			xmlhttplocal= new ActiveXObject("Microsoft.XMLHTTP")
		}
		catch (E) {
			xmlhttplocal=false;
		}
	}

	if (!xmlhttplocal && typeof XMLHttpRequest!='undefined') {
		try {
			var xmlhttplocal = new XMLHttpRequest();
		}
		catch (e) {
			var xmlhttplocal=false;
			//  alert('couldn\'t create xmlhttp object');
		}
	}
	return(xmlhttplocal);
}

var AdCode = SIWAD[8];
document.write("<div id='" + AdCode + "'></div>");


var ad_args = "x0=" + SIWAD[0];
for (i = 1; i <= 7; i++) {
	if (SIWAD[i] != null) {
		ad_args += "&x" + i + '=' + SIWAD[i];
	}
}

xmlhttp.open('get', '../AdServe/AJAXGetAd.asp?' + ad_args);
xmlhttp.onreadystatechange = handleResponseLive;
xmlhttp.send(null);	


function handleResponseLive() {
	if(xmlhttp.readyState == 4) {
		if (xmlhttp.status == 200) {
        	var response = xmlhttp.responseText;	            
	        if (response.length > 50)
	        	document.getElementById(AdCode).innerHTML = response;
			else {
	        	document.getElementById(AdCode).innerHTML = getDefaultAds(SIWAD[0].toUpperCase(), SIWAD[1], SIWAD[2]);
			}	
		}
		else {
	       	document.getElementById(AdCode).innerHTML = getDefaultAds(SIWAD[0].toUpperCase(), SIWAD[1], SIWAD[2]);
		}
	}
}

function getDefaultAds(URL, NUMADS, LOCATION) {
	var defads = "";
	if (LOCATION == "SIDEBAR") {
		defads = "<table width='100%' border='0' cellspacing='1' cellpadding='0'>"
		
		if (NUMADS >= 1 && URL != "38I.BIZ") {
			defads += "<tr><td align='center'><a href='http://38i.biz' target='_blank'><img src='http://SmalliWorld.com/USERADS/2-38i_ad_236x60.jpg' alt='' width='237' height='60' border='0'></a></td></tr>";
		}
		if (NUMADS >= 2 && URL != "JUSTIPHONEAPPS.COM") {
			defads += "<tr><td align='center'><a href='http://justiphoneapps.com' target='_blank'><img src='http://SmalliWorld.com/USERADS/2-JIPA236.jpg' alt='' width='236' height='30' border='0'></a></td></tr>";
		}
		if (NUMADS >= 3 && URL != "JESTEROFCOMEDY.COM") {
			defads += "<tr><td align='center'><a href='http://jesterofcomedy.com' target='_blank'><img src='http://SmalliWorld.com/USERADS/2-JOC236.jpg' alt='' width='236' height='40' border='0'></a></td></tr>";
		}
		if (NUMADS >= 4 && URL != "UNMOTIVATEME.COM") {
			defads += "";
		}
		if (NUMADS >= 5 && URL != "WACKYLIBS.COM") {
			defads += "<tr><td align='center'><a href='http://wackylibs.com' target='_blank'><img src='http://SmalliWorld.com/USERADS/2-WACKYLibs236.jpg' alt='' width='236' height='40' border='0'></a></td></tr><tr>";
		}
		if (NUMADS >= 6 && URL != "LIBBERATED.COM") {
			defads += "";
		}
		if (NUMADS >= 7 && URL != "THETOPMP3DOWNLOADS.COM") {
			defads += "<tr><td align='center'><a href='http://thetopmp3downloads.com' target='_blank'><img src='http://SmalliWorld.com/USERADS/2-TopMP3236.jpg' alt='' width='236' height='45' border='0'></a></td></tr>";
		}
		if (NUMADS >= 8 && URL != "FREEWEBCARTOONS.COM") {
			defads += "<tr><td align='center'><a href='Http://freewebcartoons.com' target='_blank'><img src='http://SmalliWorld.com/USERADS/2-FWC236.jpg' alt='' width='236' height='53' border='0'></a></td></tr>";
		}
		defads += "<tr><td align='center'><a href='Http://SmalliWorld.com' target='_blank'><img src='http://SmalliWorld.com/images/adsbysmalliworld.png' border='0'></a></td></tr></table>"
	}
	if (LOCATION == "BANNER") {
		// CAN ONLY HAVE ONE AD
		
	}

	return defads;
}
