//ajax objekt
imos.ajax = {
    //XMLHttpRequest Objekt
    XMLHttpRequest: function() {
        try {
            return new ActiveXObject('Msxml2.XMLHTTP');
        } catch (e) {};

        try {
            return new ActiveXObject('MSXML2.XMLHTTP');
        } catch(e) {};

        try {
            return new XMLHttpRequest();
        } catch (e) {};
        return false;
    }
};

//request
imos.ajax.request = function(url, newInstance) {
    if (typeof newInstance == 'undefined') {
        return new imos.ajax.request(url, true);
    }
    this.options = {
        method:         'GET',
        asynchronous:   true,
        parameters:     ''

    }
    this.headers = {};
    this.url = url;
    this.XMLHttpRequest = imos.ajax.XMLHttpRequest();
}

imos.ajax.request.prototype = {
    addRequestHeader: function (index, value) {
        this.headers[index] = value;
    },
    send: function (data) {
        data = typeof data == 'undefined'?null:data;

        this.XMLHttpRequest.open(this.options.method, this.url, this.options.asynchronous);

        //request Header
        for (index in this.headers) {
            this.XMLHttpRequest.setRequestHeader(index, this.headers[index]);
        }
        this.XMLHttpRequest.onreadystatechange = this.onStateChange.bind(this);
        this.XMLHttpRequest.send(data);
    },

    onStateChange: function() {
        this.readyState = this.XMLHttpRequest.readyState;
        if (this.XMLHttpRequest.readyState == 4) {
            if (this.XMLHttpRequest.status >= 200 && this.XMLHttpRequest.status < 300 && typeof this.onSuccess == 'function') {
                this.onSuccess();
            } else if ((this.XMLHttpRequest.status < 200 || this.XMLHttpRequest.status >= 300) && typeof this.onFailure == 'function') {
                this.onFailure();
            }

        }
    }

}
