function Naseptavac(obj, url, argumenticekprosim) {
	this.obsluhaAJAX = function (obsluha, method, url, content, headers) {
		xmlhttp = (window.XMLHttpRequest ? new XMLHttpRequest : (window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : false));

		if (!xmlhttp)
			return false;

		xmlhttp.open(method, url);
		franta = this;

		if (obsluha != null)
			xmlhttp.onreadystatechange = function() {
				obsluha(xmlhttp, franta);
			};

		if (headers) {
			for (var key in headers)
				xmlhttp.setRequestHeader(key, headers[key]);
		}

		xmlhttp.send(content);

		return true;
	}

	this.getZIP = function () {
		adresa = this.url + '&q=' + this.obj.value;

		for (x in this.argsFFF) {
			if (x.length != 1)
				continue;

			adresa += '&' + x + '=';

			if (typeof(this.argsFFF[x]) == 'object')
				adresa += this.argsFFF[x].value;
			else
				adresa += this.argsFFF[x];
		}

		if (!this.obsluhaAJAX(this.getZIPStatus, 'GET', adresa))
			return false;

		return true;
	}

	this.getZIPStatus = function (xmlhttp, ref) {
		if (xmlhttp.readyState == 4) {
			data = xmlhttp.responseXML.getElementsByTagName('item');

			if (data.length > 0) {
				ref.vytvorNaseptavac();

				for (var i = 0; i < data.length; i++) {
					bubu = document.createElement('div');
					bubu.className = ''
					bubu.appendChild(document.createTextNode(data[i].firstChild.data));
					bubu.ref = ref;

					bubu.onmouseover = function () {
						this.ref.zneaktivniVsechnyNaseptavaciky();
						this.className = 'f';
						this.ref.obj.onblur = '';
					};

					bubu.onclick = function () {
						this.ref.obj.value = '"' + this.firstChild.data + '"';
						this.ref.zrusNaseptavac();
						this.ref.obj.focus();
					};

					bubu.onmouseout = function () {
						this.ref.obj.onblur = this.ref.zrusNaseptavac;
					};

					ref.naseptavac.appendChild(bubu);
				}
			}
		}
	}

	this.zneaktivniVsechnyNaseptavaciky = function () {
		nodes = this.naseptavac.getElementsByTagName('div');

		maxlength = nodes.length;

		for (var i = 0; i < maxlength; i++) {
			if (nodes[i].className != '')
				nodes[i].className = '';
		}
	}

	this.zpracujPosunuti = function (nahoru) {
		nodes = this.naseptavac.getElementsByTagName('div');

		maxlength = nodes.length;

		if (maxlength == 0)
			return;

		aktivni = -1;

		for (var i = 0; i < maxlength; i++) {
			if (nodes[i].className != '') {
				aktivni = i;
				break;
			}
		}

		if (aktivni == -1) {
			this.tmpstring = this.obj.value;

			if (nahoru) {
				nodes[maxlength - 1].className = 'f';
				this.obj.value = '"' + nodes[maxlength - 1].firstChild.data + '"';
			} else {
				nodes[0].className = 'f';
				this.obj.value = '"' + nodes[0].firstChild.data + '"';
			}
		} else {
			nodes[aktivni].className = '';

			if (nahoru) {
				if (aktivni == 0) {
					this.obj.value = this.tmpstring;
				} else {
					nodes[aktivni - 1].className = 'f';
					this.obj.value = '"' + nodes[aktivni - 1].firstChild.data + '"';
				}
			} else {
				if (aktivni >= maxlength - 1) {
					this.obj.value = this.tmpstring;
				} else {
					nodes[aktivni + 1].className = 'f';
					this.obj.value = '"' + nodes[aktivni + 1].firstChild.data + '"';
				}
			}
		}
	}

	this.vytvorNaseptavac = function () {
		this.naseptavac = null;
		this.naseptavac = document.createElement('div');
		this.naseptavac.className = 'divos';
		this.obj.parentNode.appendChild(this.naseptavac);

		if (this.mamzrusitodeslani) {
			this.obj.onkeydown = function (e) {
				if (e == undefined)
					e = window.event;

				if (e.keyCode == 13)
					return false;
			}
		}
	}

	this.zrusNaseptavac = function () {
		if (this.ref)
			obj = this.ref;
		else
			obj = this;

		if (obj.naseptavac.parentNode != null)
			obj.naseptavac.parentNode.removeChild(obj.naseptavac);

		if (this.mamzrusitodeslani)
			obj.obj.onkeydown = '';
	}

	this.zjistiAktivniElement = function () {
		nodes = this.naseptavac.getElementsByTagName('div');

		maxlength = nodes.length;
		aktivni = -1;

		for (var i = 0; i < maxlength; i++) {
			if (nodes[i].className != '') {
				aktivni = i;
				break;
			}
		}

		return aktivni;
	}

	this.odchytavacKlavesnice = function (e) {
		if (e == undefined)
			e = window.event;

		/*
		ESC		27
		ENTER	13
		UP		38
		DOWN	40
		*/

		key = e.keyCode;

		if (key == 38) {
			this.ref.zpracujPosunuti(true);
		} else if (key == 40) {
			this.ref.zpracujPosunuti(false);
		} else if (key == 27) {
			this.ref.zrusNaseptavac();
		} else if (key == 13) {
			if (this.ref.zjistiAktivniElement() > 0);
				this.ref.zrusNaseptavac();
		} else {
			this.ref.zrusNaseptavac();
			this.ref.getZIP();
		}

		return false;
	}

	this.nastavOdchytavani = function (hodnota) {
		this.mamzrusitodeslani = hodnota;
	}

	// ==========================================

	this.tmpstring = '';
	this.obj = obj;
	this.naseptavac = document.createElement('div');
	this.argsFFF = argumenticekprosim;

	this.url = url;
	this.mamzrusitodeslani = true;
	this.obj.ref = this;
	this.obj.onkeyup = this.odchytavacKlavesnice;
	this.obj.onblur = this.zrusNaseptavac;
}