function ProduktovyNaseptavac(obj, url) {
	var ref = this;

	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;

		if (!this.obsluhaAJAX(this.getZIPStatus, 'GET', decodeURI(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.innerHTML = 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);
				}

				var cleaner = document.createElement("span");
				cleaner.className = "cleaner";
				ref.naseptavac.appendChild(cleaner);
			}
			
			link = xmlhttp.responseXML.getElementsByTagName('link');
			if (link.length > 0) {
				var det_search = document.createElement("span");
				det_search.className = "det_search";
				det_search.innerHTML = link[0].firstChild.data;
				det_search.onmouseover = function() {
					ref.obj.onblur = '';
				}
				det_search.onmouseout = function() {
					ref.obj.onblur = ref.zrusNaseptavac;
				}
				ref.naseptavac.appendChild(det_search);
			}
		}
	}

	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.naseptavacWrap1 = document.createElement('div');
		this.naseptavacWrap1.className = 'divos_wrap';
		this.naseptavacWrap2 = document.createElement('div');
		this.naseptavacWrap2.className = 'divos_wrap_in';
		this.naseptavacWrap3 = document.createElement('div');
		this.naseptavacWrap3.className = 'divos_wrap_in_in';
		this.naseptavac = document.createElement('div');
		this.naseptavac.className = 'divos';

		this.naseptavacWrap3.appendChild(this.naseptavac);
		this.naseptavacWrap2.appendChild(this.naseptavacWrap3);
		this.naseptavacWrap1.appendChild(this.naseptavacWrap2);

		this.mStaff.appendChild(this.naseptavacWrap1);

		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.naseptavacWrap1.parentNode != null) {
			obj.naseptavacWrap1.parentNode.removeChild(obj.naseptavacWrap1);
		}

		obj.obj.onkeydown = '';

		obj.mtfk = false;
	}

	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) {
			ref.zpracujPosunuti(true);
		} else if (key == 40) {
			ref.zpracujPosunuti(false);
		} else if (key == 27) {
			ref.zrusNaseptavac();
		} else if (key == 13) {
			ref.zrusNaseptavac();
		} else {
			ref.zrusNaseptavac();
			ref.getZIP();
		}

		return false;
	}

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

	this.tmpstring = '';
	this.obj = obj;
	this.naseptavacWrap1 = document.createElement('div');
	this.naseptavacWrap2 = document.createElement('div');
	this.naseptavacWrap3 = document.createElement('div');
	this.naseptavac = document.createElement('div');
	this.mStaff = document.createElement('div');
	this.url = url;

	this.obj.parentNode.insertBefore(this.mStaff, this.obj);
	this.mStaff.appendChild(this.obj);
	this.mStaff.className = 'septy';

	this.obj.ref = this;
	this.obj.onkeyup = this.odchytavacKlavesnice;
}

function repair_zindexes_for_ie67 (_id) {
	if ((SJEL.ie != 6) && (SJEL.ie != 7))
		return;

    this.wr = SJEL.$(_id);
    this.trs = SJEL.$T(this.wr, "TR");
    this.zi = 100;

    for (var i = 0; i < this.trs.length; i++) {
        	this.trs[i].style.position = "relative";
        	this.trs[i].style.zIndex = this.zi--;
    }
}
