function AJAXRequest() {
    if (window.XMLHttpRequest) {
        this.req = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        this.req = new ActiveXObject("Microsoft.XMLHTTP");
    } else {
        alert("Konnte AJAX-Request nicht initialisieren!");
    }
    
    this.response = null;
    this.handler = null;
    this.method = 'GET';
    this.parse = true;
}

AJAXRequest.handleResponse = function(obj) {
    if (obj.req.readyState == 4) {
        if (obj.req.status == 200) {
            if (this.parse) {
                obj.response = _parse(obj.req.responseXML.documentElement);
            } else {
                obj.response = obj.req.responseText;
            }
            
            if (obj.handler != null) {
                obj.handler.call(obj.response);
            }
        } else {
            alert('There was a problem with the request. (Status='+
                obj.req.status +')');
        }
    }
}

AJAXRequest.prototype.send = function(url) {
    var tempThis = this;
    this.req.onreadystatechange = function () {
        AJAXRequest.handleResponse(tempThis);
    };
    this.req.open(this.method, url, true);
    this.req.send(null);
}

function _parse(doc) {
    switch (doc.nodeName) {
    case 'objectList':
        return _parseList(doc);
        
    case 'objectMap':
        return _parseMap(doc);
        
    case 'object':
        return _parseObject(doc);
    
    default:
        return doc.textContent;
    }
}

function _parseList(doc) {
    var result = new Array()
    result.length = doc.childNodes.length;
    for (var i = 0; i < doc.childNodes.length; i++) {
        result[i] = _parse(doc.childNodes[i]);
    }
    return result;
}

function _parseMap(doc) {
    var result = new Object();
    for (var i = 0; i < doc.childNodes.length; i++) {
        item = doc.childNodes[i];
        result[item.getAttribute('key')] = _parse(item);
    }
    return result;
}

function _parseObject(doc) {
    var result = new Object();
    for (var i = 0; i < doc.childNodes.length; i++) {
        item = doc.childNodes[i];
        result[item.nodeName] = item.textContent;
    }
    return result;
}

