function log(msg)
{
    if(window.console)
	window.console.log(msg);
    else
	alert(msg);
}

function getActiveX(name)
{
    try       { return new ActiveXObject(name); }
    catch (e) { return false; }
}

function Comm(timeoutMs)
{
    this.timeoutMs = timeoutMs;

    if (window.XMLHttpRequest) 
        this.ua = new XMLHttpRequest();

    else if (window.ActiveXObject) 
	this.ua = (getActiveX("Microsoft.XMLHTTP") ||
		   getActiveX("Msxml2.XMLHTTP"));

    else
	this.ua = null;

    if (!this.ua)
        commsError("Could not create communication object.");
}

function commsError(msg)
{
    //alert("Communications problem:" + msg);
}

Comm.prototype.post = function(url, content)
{
    return this._suck(url, "POST", content);
}

Comm.prototype.get = function(url)
{
     return this._suck(url, "GET");
}

Comm.prototype.getXML = function(url)
{
     return this._suck(url, "GET", null, true);
}

Comm.prototype._suck = function(url, method, content, wantXML)
{
    if (!this.ua)
        commsError("Communication object not available.");

    var toId = setTimeout("commsError('No response from remote source " +
			  url +
			  "')",
			  this.timeoutMs);

    this.ua.open(method, url, false);
    this.ua.setRequestHeader('If-Modified-Since',
			     'Sat, 29 Oct 1994 00:00:01 GMT');
    this.ua.send(content);

    clearTimeout(toId);

    if (this.ua.status > 299 && this.ua.status != 304)
    {
	commsError(this.ua.status + ": " + this.ua.statusText +
		   "\nresponse:\n" + this.ua.responseText);
	return "";
    }

    return wantXML ? this.ua.responseXML : this.ua.responseText;
}
