/* stvori ajax objekt */
function CreateAJAX() {
	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) {
	_h = (typeof(_h) != 'object') ? getEL(_h) : _h;
	if (!_a || !_url || !_h) {return '';}
	_url = _url.replace(/&amp;/g, '&');
	_a.open("GET", _url, true);
	_a.setRequestHeader("Content-Type", "text/html; charset=uft-8");
	_h.className = (_h.className) ? _h.className+' loading-div' : 'loading-div';
	_h.innerHTML = '';
	_a.onreadystatechange = function() {
		if (_a.readyState == 4) {
			_h.className = _h.className.replace(' loading-div', '');
			_h.className = _h.className.replace('loading-div', '');
			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;
			}
			_data = _h = _title = result_out = null;
		}
	}
	_a.send(null);
}
/*
	ajax post
*/
function AjaxPost(_a, _url, _h, _podaci) {
	if (_h) {
		_h = (typeof(_h) != 'object') ? getEL(_h) : _h;
		if (!_h) {return false;}
	}
	if (!_a || !_url || !_h || !_podaci) {return '';}
	_url = _url.replace(/&amp;/g, '&');
	_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 = (_h.className) ? _h.className+' loading-div' : 'loading-div';
	_h.innerHTML = '';
	_a.onreadystatechange = function() {
		if (_a.readyState == 4) {
			_h.className = _h.className.replace(' loading-div', '');
			_h.className = _h.className.replace('loading-div', '');
			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;
			}
			_h = result_out = _title = _data = null;
		}
	}
	_a.send(_podaci);
	_podaci = null;
}
/*
	postavi loading klasu na element
*/
function set_loader(el, _w) {
	_w = _w || false;
	el = typeof(el) != 'object' ? getEL(el) : el;
	if (!el) {return;}
	klasa = 'loader-item';
	// ako se dodaje loading klasa
	if (_w) {
		el.className = (el.className) ? el.className+' '+klasa : klasa;
		el.innerHTML = '';
	}
	else {
		el.className = el.className.replace(' '+klasa, '');
		el.className = el.className.replace(klasa, '');
	}
	klasa = el = _w = null;
}