

function Ajax(server) {
    this.version    = '0.1'; //debug
    this.appendTime = true;
    this.server     = server || '/server/ajax.php';
    this.initialize();
}
Ajax.prototype = {
    initialize: function() {
        this.http = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Msxml2.XMLHTTP');
        if (!this.http) alert('Cannot create an XmlHttp instance.');
    },
    load: function(query) {
        this.url = this.server + '?' + query + (this.appendTime ? '&' + new Date().getTime() : '');
        //alert(this.url);
        this.http.open('GET', this.url, false);
        this.http.send(null);
        if (this.http.status == 200) return this.http.responseText;
        return 'Error ' + this.http.status + ': ' + this.http.responseText;
    },
    exec: function(query, callback) {
        this.callback = callback || alert;
        var self = this;
        this.url = this.server + '?' + query + (this.appendTime ? '&' + new Date().getTime() : '');
        //alert(this.url);
        this.http.open('GET', this.url, true);
        this.http.onreadystatechange = function() {
            if ((self.http.readyState == 4) && (self.http.status == 200) && (self.http.responseText)) {
                if (self.callback) {
                    self.callback(self.http.responseText);
                } else {
                    alert(self.http.responseText);
                }
            }
        }
        this.http.send(null);
    },
    fromJson: function(json) {
        return eval('(' + json + ')');
    }
}
