function alertContents(http_request, adDiv) {

    //    alert(http_request.status)
    //    alert(http_request.readyState)

    if (http_request.readyState == 4) {
	if (http_request.status == 200) {

	    adDiv.innerHTML = http_request.responseText;

	} /*else {
	    alert('There was a problem with the request.');

	    } */
    }

}

String.prototype.endsWith = function(str)
{
    return (this.match(str+"$")==str)
}

var adDiv = document.getElementById('ad-block');

if (adDiv) {
    //        alert('Hi?');

//var adDiv = document.getElementById('ad-block');

// Just grab the first one
//    alert('Found one!');
//var iframeTag = document.createElement('iframe');

//iframeTag.location = document.location.href + '/getAdContainerUrl';
//iframeTag.src = document.location.href + '/getAdContainerUrl';
//iframeTag.name = 'adcontainer';
//iframeTag.width = '100%';
//iframeTag.height = '100%';
//iframeTag.frameborder = 'no';
//iframeTag.scrolling = 'no';

//adDiv.appendChild(iframeTag)

//adDiv.innerHTML = '<iframe src="' +  document.location.href + '/getAdContainerUrl"' + ' name="adcontainer" width="100%" height="100%" frameborder="no" scrolling="no"></iframe>';

//adDiv.innerHTML = document.location.href + '/getAdHTML';    
    
//    var iframeTag = iframeTags[0];
    
// set the attributes
//    iframeTag.setAttribute('src', document.location.href + '/getAdContainerUrl');
//    iframeTag.setAttribute('name', 'adcontainer');
//    iframeTag.setAttribute('width', '100%');
//    iframeTag.setAttribute('height', '100%');
//    iframeTag.setAttribute('frameborder', 'no');
//    iframeTag.setAttribute('scrolling', 'no');

    if (window.XMLHttpRequest)	{ // Mozilla, Safari, ...
	http_request = new XMLHttpRequest();
	if (http_request.overrideMimeType) {
	    http_request.overrideMimeType('text/plain');
	    // See note below about this line
	}
    }
    else if (window.ActiveXObject) { // IE
	try {
	    http_request = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e)  {
	    try {
		http_request = new ActiveXObject("Microsoft.XMLHTTP");
	    }
	    catch (e) {}
	}
    }

    if (!http_request) {
	alert('Giving up :( Cannot create an XMLHTTP instance');
    }
    else {
	if (!document.location.href.endsWith('discussion_reply_form')) {
		http_request.onreadystatechange = function() { alertContents(http_request, adDiv); };
		http_request.open('GET', document.location.href + '/getAdHTML', true );
	
		http_request.send(null);
	    }
	 }
    }

