// AJAX pro nacitani dynamickych selectu bez reloadu stranky

url = document.location.href;
xend = url.lastIndexOf("/") + 1;
var base_url = window.location.protocol + '//' + window.location.host + '/';

var ajax_get_error = false;

function ajax_do(url) {

	// Create new JS element
	var jsel = document.createElement('SCRIPT');
	jsel.type = 'text/javascript';
	jsel.src = url;
	// Append JS element (therefore executing the 'AJAX' call)
	document.body.appendChild(jsel);

	return true;
}

function ajax_get(url, el, aim) {
	// Does URL begin with http?
	if (url.substring(0, 4) != 'http') {
		url = base_url + url;
	}

	if (el != 0) {
		// Has element been passed as object or id-string?
		if (typeof(el) == 'string') {
			el = document.getElementById(el);
		}

		// Valid el?
		if (el == null) {
			alert('Element nenalezen!');
			return false;
		}

		val = el.value;

		url = url.replace("value", val);
	}

	// Create getfile URL
	getfile_url = base_url + 'js/get_ajax.php?url=' + escape(url) + '&el=' + escape(el.id) + '&aim=' + aim;

	// Do Ajax
	ajax_do (getfile_url);

	return true;
}
