function tajax() {	
	this.xhr = null;
        if (typeof XMLHttpRequest != "undefined") {		
		this.xhr = new XMLHttpRequest();
		//if (this.xhr.overrideMimeType)
		//	this.xhr.overrideMimeType('text/html'); // safari[?]
	}
	else {		
		var IEXHR = ["MSXML2.XMLHttp.5.0", "MSXML2.XMLHttp.4.0", "MSXML2.XMLHttp.3.0", "MSXML2.XMLHttp","Microsoft.XMLHttp"];
		for (var i = 0; i < IEXHR.length; i++) {
			try {
				this.xhr = new ActiveXObject(IEXHR[i]);
				break;
			}
			catch (e) { }
		}
	}
	
	if (this.xhr == null)
		return(null);
	
	var we = this; // ZOMG H4X!
	
	this.timeout = 0;	
	this.onReady = function() { };
	this.onFail = function() { };
	this.onTimeout = function() { };

	this._timeoutRef = null;	
	this.xhr.onreadystatechange = function() {		
		if ((we.xhr.readyState == 4) || (we.xhr.readyState == 'complete')) {
			if (we._timeoutRef) {			
				clearTimeout(we._timeoutRef);
				we._timeoutRef = null;			
			}
			if (we.onReady)
				we.onReady();
		}
		// TODO onfail, też z clearowaniem to!
	}
	var _toFunc = function() {
		alert(we);
		if (!we._timeoutRef)
			return;
		we.xhr.abort();
		//clearTimeout(we._timeoutRef);
		we._timeoutRef = null;
		if (we.onTimeout)
			we.onTimeout();
	}
	this.post = function(url, data) {		
		we.xhr.open('POST', url, true);
		we.xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		we.xhr.setRequestHeader('Content-Length', data.length);
		we.xhr.setRequestHeader('Connection', 'close');
		we.xhr.send(data);
		if (we.timeout > 0)
			we._timeoutRef = setTimeout(_toFunc, we.timeout);
	}
	this.postArray = function(url, dataArr) {
		var data = "";
		for (var id in dataArr)
			data += (data != '' ? '&' : '') + id + '=' + encodeURIComponent(dataArr[id]);
		we.post(url, data);
	}
	this.get = function(url) {
		we.xhr.open('GET', url, true);		
		we.xhr.send(null);
		if (we.timeout > 0)
			we._timeoutRef = setTimeout(_toFunc, we.timeout);		
	}
	this.getArray = function(url, dataArr) {
		var data = "";
		for (var id in dataArr)
			data += (data != '' ? '&' : '') + id + '=' + encodeURIComponent(dataArr[id]);
		we.get(url + '?' + data);
	}	
}

// toruvinn - lain.pl

