

var ajax = {
    initialize: function() {
        if (window.XMLHttpRequest) {
            this.http = new XMLHttpRequest();
        } else if (window.ActiveXObject) {
            this.http = new ActiveXObject('Msxml2.XMLHTTP');
        }
        if (!this.http) alert('Cannot create an XmlHttp instance.');
        if (this.http.overrideMimeType) this.http.overrideMimeType('text/xml');
    },
    exec: function(method, url, params, callback) {
        params = params || '';
        this.callback = callback || null;
        if ((method == 'GET') && (params != '')) {
            url    = url + (url.indexOf('?') > -1 ? '&' : '?') + params;
            params = null;
        }
        url = url + (url.indexOf('?') > -1 ? '&' : '?') + new Date().getTime();
        var self = this;
        //url = 'https://' + location.host + url;
        //alert(url);
        this.http.open(method, url, (this.callback == null ? false : true));
        this.http.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
        if (method == 'POST') {
            this.http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
            this.http.setRequestHeader('Content-length', params.length);
            this.http.setRequestHeader('Connection', 'close');
        }
        if (this.callback != null) {
            this.http.onreadystatechange = function() {
                if (self.http.readyState == 4) {
                    return self.callback(self.http.responseText, self.http.status);
                }
            }
        }
        this.http.send(params);
        if (this.callback == null) return this.http.responseText;
    },
    eval: function(json) {
        return eval('(' + json + ')');
    }
}
ajax.initialize();

