/************************************************************************************
**
**	AJAX Request
**	============
**	
**	Author: Dawid Kujawa [dawid.kujawa@mru510.info]
**
**	Usage:
**		new doAjax(url_string, updated_element, on_ready_function);
**
*/

function ajaxRequest(url, element, readyfunc) {
	this._element = (element) ? element : null;
	this._readyfunc = (readyfunc) ? readyfunc : null;
	try {
		this.request = new XMLHttpRequest();
	} catch (e) {
		try {
			this.request = new ActiveXObject('Msxml2.XMLHTTP');
		} catch (e) {
			this.request = new ActiveXObject('Microsoft.XMLHTTP');
		}
	}
	if (this.request) {
		this.request.owner = this;
		this.request.onreadystatechange = function () {
			if (((this.readyState == 4) || (this.readyState == 'complete')) && (this.status == 200)) {
				if (this.owner._element)
					this.owner._element.innerHTML = this.responseText;
				if (this.owner._readyfunc)
					this.owner._readyfunc(this.responseText);
			}
		}
		var _url = url + ((url.search(/\?/) == -1) ? '?' : '&') + '_sid=' + Math.random();
		this.request.open('GET', _url, true);
		this.request.send(null);
	}
};

function doAjax(url, element, readyfunc) {new ajaxRequest(url, element, readyfunc);}
