function getHTTPObject()
{
	// re organized to better support htmlunit
	var xmlhttp = false;

	try {
		xmlhttp = new XMLHttpRequest(); 
	} catch (e) {
		xmlhttp = false;
	}

	if ( xmlhttp == false) {
	try {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");	
	} catch (e) {
	try {
		xmlhttp = new ActiveXObject("MSXML2.XMLHTTP");
	} catch (E){
		xmlhttp = false;
	}
		}
	}

	return xmlhttp;
}

var _http = null;
var _callback = null;
var _arguments = null;

function send()
{
    _http = getHTTPObject();
    _callback = arguments[0];
    _arguments = new Array();
    var templateParam = getParamTemplate();

    var hasTemplate = false;
    for (i = 1; arguments != null && i < arguments.length; i = i + 1)
    {
        _arguments[i - 1] = arguments[i];
        if ( arguments[i] == templateParam )
        {
            hasTemplate = true;
        }
    }

    // jss: added protocol and host
    var url = document.location.protocol + '//' + document.location.host + getCallbackURL() + '?';

    for (i = 1; arguments != null && i < arguments.length; i = i + 2)
    {
        url = url + encodeURIComponent(arguments[i]) + '=' +  encodeURIComponent(arguments[i + 1]) + '&';
    }

    if ( ! hasTemplate )
    {
        url = url + encodeURIComponent(templateParam) + '=' +  encodeURIComponent(getTemplate()) + '&';
    }

    _http.open("GET", url, true);
    _http.onreadystatechange = handleSend;
    _http.send(null);
}

function handleSend()
{
    try
    {
        if (_http.readyState == 4)
        {
            // safari can get undefined for the status if the request is cached or returns an empty string,
            // so we also do the callback in that case
            if (_http.status == 200 || (_http.status == undefined && navigator.userAgent.toLowerCase().indexOf("safari") >= 0) )
            {
                try
                {
                    _callback(_http.responseText, _arguments);
                }
                catch(e)
                {
                    alert(getXmlHttpError()+" "+ e);
                }
            }
        }
    }
    catch (e2)
    {
        // this can happen because of a network error.  ignore in this case
        // http://radio.javaranch.com/pascarello/2006/02/07/1139345471027.html
    }
}
