/**
 * @author spapp - visit us online @ http://www.spappsite.hu/
 * @copyright 2008
 * @version 1.0.0
 */
var Ajax = function(_opt){
    var _this = this;
    this.version = '1.1.0';
    /**
     *
     */
    var readyStateChange = function(){
        switch (_this.rq.readyState) {
            case 1:
                break;
            case 2:
                break;
            case 3:
                break;
            case 4:
                var s = (_this.rq.status == 200);
                var r = {
                    responseText: _this.rq.responseText || '',
                    responseXML: _this.rq.responseXML || ''
                }
                var o = _this.options.params;
                _this.options.callback(s, r, o);
                break;
        } 
    }
    /**
     *
     */
    var makeUrl = function(){
        if (_this.options.params) {
            var a = 0, u = '';
            for (var key in _this.options.params) {
                if (a == 0) {
                    u = '?';
                    u += key + '=' + _this.options.params[key];
                }
                else {
                    u += '&' + key + '=' + _this.options.params[key];
                }
                a++;
            }
            _this.options.url += u;
        }
    }
    
    /**
     * @param {Object} _params
     */
    this.request = function(_options){
        _this.options = _options;
        makeUrl();
        _this.rq = (window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("MSXML2.XMLHTTP");
		_this.rq.onreadystatechange = readyStateChange;
        _this.rq.open(_this.options.method, _this.options.url, true);
        _this.rq.send(_this.options.url);
    }
	
    if (_opt) {
		this.request(_opt);
	}
    return this;
};

