function HttpRequest()
{
    this.request;
    this.callbackObject;
    this.callbackMethod;
    this.responseAsXml;
    
    this.createRequest = function()
    {
        if (window.XMLHttpRequest)
        {
          return new XMLHttpRequest()
        }
        else if (window.ActiveXObject)
        {
          return new ActiveXObject("Microsoft.XMLHTTP")
        }
        return null;
    }
    
    this.setCallback = function(callback, callbackThis, responseAsXml)
    {
        this.callback = callback;
        this.callbackThis = callbackThis;
        this.responseAsXml = responseAsXml;
    }
    
    this.sendRequest = function(url, query, post)
    {
        if (this.request == undefined)
        {
            this.request = this.createRequest();
        }
        if (this.request != null)
        {
            cms.event.attach(this.request, 'readystatechange', this.onResponse, this, true);
            
            if (typeof query == "object")
            {
                var queryString = "";
                for (var property in query)
                {
                    if (queryString.length > 0)
                    {
                        queryString += "&";
                    }
                    queryString += property + "=" + escape(query[property]);
                }
                query = queryString;
            }

            // Koppel de query data aan de GET url
            if (!post)
            {
                url += '?' + query;
            }

            this.request.open((post)? "POST" : "GET", url, true);
            if (post)
            {
                this.request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
            }
            
            // Verzend de request
            this.request.send(post ? query : null);
        }
    }
    
    this.onResponse = function()
    {
        if (this.request.readyState == 4 && this.request.status == 200)
        {
            var response = (this.responseAsXml)? this.request.responseXML : this.request.responseText;

            if (this.callback != undefined)
            {
                if (this.callbackThis == undefined)
                {
                    this.callback(response, this);
                }
                else
                {
                    this.callback.call(this.callbackThis, response, this);
                }
            }
        }
    }
}

cms.core.httpRequest = HttpRequest;