var _title = null;
RunningAJAX = false;
/* stvori ajax objekt */
function CreateAJAX() {
	if (!RunningAJAX) {RunningAJAX = true;}else {return false;}
	var _ajax = null;
	try {
		_ajax = new XMLHttpRequest();
	}
	catch (ee) {
		try {
			_ajax = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				_ajax = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {
				alert('Browser ne podržava ajax?! Ma daj...');
				return false;
			}
		}
	}
	return _ajax;
}
/*
	najjednostavniji output sto moze biti
*/
function AjaxGet(_a, _url, _h, _function, _timeout) {
	_function = (typeof(_function) == 'function') ? _function : null;
	_timeout = (_timeout) ? _timeout : null;
	_h = (typeof(_h) != 'object') ? getEL(_h) : _h;
	if (!_a || !_url || !_h) {return '';}
	_a.open("GET", _url, true);
	_a.setRequestHeader("Content-Type", "text/html; charset=uft-8");
	_h.className = 'loading-div';
	_h.innerHTML = '<span>učitava se...</span>';
	_a.onreadystatechange = function() {
		if (_a.readyState == 4) {
			_h.className = '';
			var result_out = null;
			result_out = _a.responseText;
			//result_out = result_out.replace(/\+/g, " ");
			result_out = unescape(result_out);
			RunningAJAX = false;
			// postavi podatke
			_data = result_out.split('<hr id="PageBreak" />');
			_title = _data[0];
			_data = _data[1];
			//alert(typeof(_title)+'\n'+typeof(_data));
			if (typeof(_title) != "undefined" && typeof(_data) != "undefined") {
				popup.set_title(_title);
				_h.innerHTML = _data;
			}
			else {
				popup.set_title('Greška!');
				_h.innerHTML = result_out;
			}
			// ako ima koja funkcija za izvršit
			if (_function) {
				if (_timeout) {
					setTimeout(_function, _timeout);
				}
				else {
					_function();
				}
			}
			_data = _h = _title = result_out = null;
		}
	}
	_a.send(null);
}
/*
	ajax post
*/
function AjaxPost(_a, _url, _h, _podaci, _function, _timeout) {
	if (_function != 'refresh') {
		_function = (typeof(_function) == 'function') ? _function : null;
	}
	_timeout = (_timeout) ? _timeout : null;
	if (_h) {
		_h = (typeof(_h) != 'object') ? getEL(_h) : _h;
		if (!_h) {return false;}
	}
	_h.className = 'loading-div';
	_h.innerHTML = '<span>učitava se...</span>';
	if (!_a || !_url || !_h || !_podaci) {return '';}
	_a.open("POST", _url, true);
	_a.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=utf-8");
	_a.setRequestHeader("Content-length", _podaci.length);
	//_h.className += ' ajax-loader';
	_a.onreadystatechange = function() {
		if (_a.readyState == 4) {
			_h.className = '';
			var result_out = null;
			result_out = _a.responseText;
			//result_out = result_out.replace(/\+/g, " ");
			result_out = unescape(result_out);
			//_h.className = _h.className.replace(' ajax-loader', '');
			RunningAJAX = false;
			// postavi podatke
			_data = result_out.split('<hr id="PageBreak" />');
			_title = _data[0];
			_data = _data[1];
			//alert(typeof(_title)+'\n'+typeof(_data));
			if (typeof(_title) != "undefined" && typeof(_data) != "undefined") {
				popup.set_title(_title);
				_h.innerHTML = _data;
			}
			else {
				popup.set_title('Greška!');
				_h.innerHTML = result_out;
			}
			// ako ima koja funkcija za izvršit
			if (_function) {
				if (_timeout) {
					setTimeout(_function, _timeout);
				}
				else if (_function == 'refresh') {
					window.location.href = window.location;
				}
				else {
					_function();
				}
			}
		}
	}
	_a.send(_podaci);
	_podaci = null;
}