var adsTimeDelay = 60; // change delay time in seconds
adsTimeDelay *= 1000;

function startRecentAds() {
    retrieveRecentAds();
  setInterval("retrieveRecentAds()", adsTimeDelay);
}

function retrieveRecentAds() {

	var xmlHttp;
	var ajaxValid = true;
	
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
	}
	catch (e) {
		// Internet Explorer
		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	    }
		catch (e) {
			try {
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {
				alert("Your browser does not support AJAX!");
				ajaxValid = false;
			}
	    }
	}
	
	if (ajaxValid) {
		String.prototype.trim = function () {
		    return this.replace(/^\s*/, "").replace(/\s*$/, "");
		}
		xmlHttp.onreadystatechange = function() {
			if (xmlHttp.readyState == 4) {
				var placeHolder = document.getElementById('recentAdsDiv');
				if (placeHolder) {
					var count = xmlHttp.responseText.trim();
					if (count != "") {
		    			placeHolder.innerHTML = '&nbsp;' + xmlHttp.responseText.trim();
		    		}
		    	}
			}
		}
		xmlHttp.open("GET", "/viewRecentAds.html?ajax=true", true);
		xmlHttp.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
		xmlHttp.setRequestHeader("Cache-Control", "no-cache");
		xmlHttp.send(null);
	}

}