function send_xmlhttprequest(obsluha, method, url, content, headers) {
	var xmlhttp = (window.XMLHttpRequest ? new XMLHttpRequest : (window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : false));

	if (!xmlhttp)
		return false;

	xmlhttp.open(method, url);

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

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

	xmlhttp.send(content);
	return true;
}

function open_popup(dokument, sirka, vyska, scrollbars) {
	so = screen.width;
	vo = screen.height;
	zleva = ((so - sirka) / 2) - 13;
	shora = 120;
	popup_win = window.open(dokument,"popup_okno","width="+sirka+",height="+vyska+",left="+zleva+",top="+shora+",location=0,menubar=0,resizable=1,scrollbars="+scrollbars+",status=0,titlebar=0,toolbar=0");
	popup_win.focus();
}

function Show(id, show) {
  if (show)
    document.getElementById(id).style.visibility='visible';
  else
    document.getElementById(id).style.visibility='hidden';
}

function mute(m) {
    if ((m == "on") || (m == "off"))
        send_xmlhttprequest(null, "GET", "/audio_mute.php?mute=" + m);
}


function reload_confirm_image() {
	var d = new Date();
	var obj = document.getElementById('confirm_data_image_image');

	if (obj)
		obj.src = '/confirm_number.php?new&time=' + d.getTime();
}

function change_confirm_style(second) {
	var obj1 = document.getElementById('confirm_data_image');
	var obj2 = document.getElementById('confirm_data_flash');

	if (second) {
		obj1.style.display = 'none';
		obj2.style.display = 'block';
	} else {
		obj2.style.display = 'none';
		obj1.style.display = 'block';
	}
}

function on_off(_id) {
    var elem = document.getElementById(_id);

    if (elem == null)
        return;

    if (elem.style.display == "none")
        elem.style.display = "block";
    else
        elem.style.display = "none";
}

function anonym_email(formular, profile, language) {
	var email = formular.email.value;

	if (!send_xmlhttprequest(anonym_email_r, 'GET', '/index.php?ma=ajax&sid=aemail&p=' + profile + '&l=' + language + '&e=' + email)) {
		return true;
	}

	return false;
}

function hide_selects_ie6() {
    reg = /^.*MSIE 6.*$/;
    if (reg.test(navigator.appVersion)) {
        var sel = document.body.getElementsByTagName("SELECT");
        for (var i = 0; i < sel.length; i++)
            sel[i].style.visibility = "hidden";
    }
}

function anonym_email_r(xmlhttp) {
	if (xmlhttp.readyState == 4) {
		document.getElementById('dark_bg').style.display = 'block';
		document.getElementById('matwindow').style.display = 'block';
		document.getElementById('matwindow_in').style.display = 'block';
		document.getElementById('matwindow_in').innerHTML = xmlhttp.responseText;

		hide_selects_ie6();
	}
}

function close_matwindow() {
	var obj = document.getElementById('matwindow');
    var obj2 = document.getElementById('matwindow_in');
    var obj3 = document.getElementById('dark_bg');

	if (obj) {
		obj2.innerHTML = '';
		obj.style.display = 'none';
		obj2.style.display = 'none';
	}

	if (obj3)
		obj3.style.display = 'none';

    /*reg = /^.*MSIE 6.*$/;
    if (reg.test(navigator.appVersion)) {
        var sel = document.body.getElementsByTagName("SELECT");
        for (var i = 0; i < sel.length; i++)
            sel[i].style.visibility = "visible";
    }*/
}

function row_highlight(_id) {
    /*this.wr = document.getElementById(_id);
    if (this.wr == null) {
        alert("row_highlight error: bad id");
        return false;
    }

    this.set_events = function (_elem) {
        _elem.onblur = function () {
            this.parentNode.parentNode.className = "";
        }
        _elem.onclick = function () {
            this.parentNode.parentNode.className = "highlight";
        }
    }

    this.inputs = this.wr.getElementsByTagName("INPUT");
    this.selects = this.wr.getElementsByTagName("SELECT");

    for (var i = 0; i < this.inputs.length; i++)
        if (this.inputs[i].type == "text")
            this.set_events(this.inputs[i]);

    for (var i = 0; i < this.selects.length; i++)
        this.set_events(this.selects[i]);*/
}

function GetElem(_id) {
	var e = document.getElementById(_id);
	if (e == null) {
		//alert("bad id '" + _id +"'");
		return null;
	} else
		return e;
}

// vrati index prvniho nalezeneho prvku, jinak -1
function InArray(_item, _array) {
    var i = 0, f = -1;

    for (i = 0; i < _array.length; i++)
        if (_item == _array[i]) {
            f = i;
            break;
        }

    return f;
}

function AddClass(_el, _cl) {
	if (_el != null)
		_el.className += " " + _cl;
}

function RemoveClass(_el, _cl) {
	if (_el == null) return;
	var ta = _el.className.split(' ');
	var idx = InArray(_cl, ta);
	if (idx != -1) {
		ta.splice(idx, 1);
		_el.className = ta.join(' ');
	}
}

var rsdfsdf = /^.*Microsoft.*$/;
var IE = 0;
if (rsdfsdf.test(navigator.appName))
	IE = 1;
/**
 * Vrati externi styl prvku
 */
function GEStyle(_e) {
	if (!IE)
		return document.defaultView.getComputedStyle(_e, "");
	else
		return _e.currentStyle;
}

/**
 * Vrati styl prvku, bud inline nebo externi.
 */
function GetStyle(_e, _s) {
	if ((_e.style[_s] != "") && (_e.style[_s] != undefined))
		return _e.style[_s];
	else {
	 	var es = GEStyle(_e);
		if ((es[_s] != "") && (es[_s] != undefined))
			return es[_s];
	}

	return 0;
}

/**
 * Trida, simulujici select. Navaze se na normalni select, pricemz puvodni
 * select se jenom schova, takze jeho normalni funkcnost je zachovana. Co se deje s MSelectem,
 * deje se i s puvodnim selectem. (i udalost onchange).
 * MSelect se da vytvorit i normalne bez navazani na nejaky normalni select - metoda AddOption ...
 * _sel - id selectu
 * _tam - element, do ktereho mam vlozit novy select (nepovinny parametr - nezadam-li, novy select se prida pred puvodni select)
 * TODO: kdyz bude nejake <option> disabled, tak neklikatelne ...
 */
function MSelect(_sel,_tam) {
	// budu ukladat jednotlive instance kvuli situaci, kdyz je otevreny nejaky select
	// a ja otevru jiny, tak aby se ten puvodni zavrel
	if (MSelect.instances == undefined)
		MSelect.instances = new Array();

	if (MSelect.numInstances == undefined)
		MSelect.numInstances = 0;
	else
		MSelect.numInstances++;

	this.id = MSelect.numInstances;
	MSelect.instances[this.id] = this;

	if (MSelect.opened == undefined)
		MSelect.opened = -1;  // opened - id otevreneho selectu, -1 => zadny neni otevreny

	this.tam = null;
	this.sel = null;

	if (typeof(_sel) == "string") {
		if (!(this.sel = GetElem(_sel))) {
			alert("MSelect: bad id '" + _sel + "'");
			return;
		}
	} else
		this.sel = _sel;

	if ((_tam != undefined) && (typeof(_tam) == "string")) {
		if (!(this.tam = GetElem(_tam))) {
			alert("MCheckBox: bad id '" + _tam + "'");
			return;
		}
	}

	this.GetOptionIndex = function(_opts, _opt) {
		var idx = -1;
		var cn = _opts.childNodes;
		for (var i = 0; i < cn.length; i++)
			if (cn[i] == _opt)
				idx = i;
		return idx;
	}

	this.selected = null;
	this.firstOption = true;
	this.onChangeFunc = this.p1 = this.p2 = this.p3 = null;

	if (this.sel) {
		this.onChangeFunc = this.sel.onchange;
		this.sel.style.display = "none";
	}

	/* takhle vypada select:
		<div class="nsel">
			<div class="sel_title">
				<div class="item"></div>
				<div class="decor"></div>
			</div>
			<div class="options">
				<div class="item [selected]"></div>
				...
			</div>
		</div>
	*/

	//this.tam.style.display = "block";
	this.nsel = document.createElement("div");  // drzi novy select
	this.nsel.className = "nsel";

	// toto je kvuli zasranym IE6, IE7, ..., jinak by 1 select neprekryl 2.
	// samozrejme to nebude fungovat ve vsech pripadech
	if (IE) {
		this.nsel.style.position = "relative";
		this.nsel.style.zIndex = 100 - this.id;
	}

	this.options = document.createElement("div");
	this.options.className = "options";
	this.selTitle = document.createElement("div");
	this.selTitle.className = "sel_title";
	this.selItem = document.createElement("div");
	this.selItem.className = "item";
	this.selDecor = document.createElement("div");
	this.selDecor.className = "decor";

	// je-li na puvodnim selectu trida, vytahne z ni sirku a nastavi ji
	// neni-li v te classe zadana sirka, tak v normalnich prohlizecich vezme puvodni sirku!
	if (this.sel && this.sel.className) {
		var w = parseInt(GetStyle(this.sel, "width"));
		if (w) {
			this.nsel.style.width = w + "px";
			this.options.style.width = w - 2 + "px";
		}
	}

	this.GetSelectedValue = function() {
		return this.selected.value;
	}

	this.SetOnChange = function(_func, _p1, _p2, _p3) {
		if (typeof(_func) == "function") {
			this.onChangeFunc = _func;
			this.p1 = _p1;
			this.p2 = _p2;
			this.p3 = _p3;
		}
	}

	this.Select = function(_opt) {
		RemoveClass(this.selected, "selected");
		AddClass(_opt, "selected");
		this.selItem.innerHTML = _opt.innerHTML;
	}

	// _v - value, _t - text (innerHTML), _s - selected, _d - disabled
	this.AddOption = function(_v, _t, _s, _d) {
		var it = document.createElement("div");
		it.ref = this;
		it.className = "item";
		it.value = _v;
		if (_d != undefined)
			it.disabled = _d;
		else
			it.disabled = false;

		if (it.disabled)
			AddClass(it, "disabled");

		if (!_t)
			it.innerHTML = "&nbsp";
		else
			it.innerHTML = _t;

		if (this.firstOption) {
			this.Select(it);
			this.selected = it;
			this.firstOption = false;
		}
		if (((_s != undefined) && (_s == true))) {
			this.Select(it);
			this.selected = it;
		}
		it.onclick = function() {
			if (this.disabled)
				return;

			MSelect.opened = -1;
			this.ref.Select(this);
			this.ref.options.style.display = "none";
			if (this.ref.sel)
				this.ref.opts[this.ref.GetOptionIndex(this.ref.options, this.ref.selected)].selected = false;
			this.ref.selected = this;
			if (this.ref.sel)
				this.ref.opts[this.ref.GetOptionIndex(this.ref.options, this.ref.selected)].selected = true;
			if ((this.ref.onChangeFunc != undefined) && (this.ref.p1 != null))
				this.ref.onChangeFunc(this.ref.p1, this.ref.p2, this.ref.p3);
			else if (this.ref.onChangeFunc != undefined)
				this.ref.onChangeFunc();
		}
		it.onmouseover = function() {
			if (!this.disabled)
				AddClass(this, "item_over");
		}
		it.onmouseout = function() {
			RemoveClass(this, "item_over");
		}
		this.options.appendChild(it);
	}

	this.RemoveAllOptions = function() {
		this.options.innerHTML = "";
		this.selItem.innerHTML = "";
		this.firstOption = true;
	}

	if (this.sel) {
		this.opts = this.sel.getElementsByTagName("option");
		for (var i = 0; i < this.opts.length; i++) {
			var opt = this.opts[i];
			this.AddOption(opt.value, opt.innerHTML, opt.selected, opt.disabled);
		}
	}

	this.selTitle.ref = this;
	this.selTitle.onclick = function() {
		if ((this.ref.options.style.display == "") || (this.ref.options.style.display == "none")) {
			this.ref.options.style.display = "block";
			if (MSelect.opened > -1)
				MSelect.instances[MSelect.opened].options.style.display = "none";  // zavreme otevreny select
			MSelect.opened = this.ref.id;
		} else {
			this.ref.options.style.display = "none";
			MSelect.opened = -1;
		}
	}
	this.selTitle.onmouseover = function() {
		AddClass(this, "title_over");
	}
	this.selTitle.onmouseout = function() {
		RemoveClass(this, "title_over");
	}

	this.selTitle.appendChild(this.selItem);
	this.selTitle.appendChild(this.selDecor);
	this.nsel.appendChild(this.selTitle);
	this.nsel.appendChild(this.options);
	if (this.tam == null)
		this.sel.parentNode.insertBefore(this.nsel, this.sel);
	else
		this.tam.appendChild(this.nsel);
}

/**
 * Zmeni vsechny selecty v elementu danem id _cont
 */
function ChangeSelects(_cont) {
	this.cont = null;

	if (!(this.cont = GetElem(_cont))) {
		alert("MCheckBoxes: bad id '" + _cont + "'");
		return;
	}

	var sels = document.getElementsByTagName("select");
	for (var i = 0; i < sels.length; i++) {
		new MSelect(sels[i]);
	}
}

function MCheckBox(_chkb, _tam) {
	this.tam = null;
	this.chkb = null;

	if (typeof(_chkb) == "string") {
		if (!(this.chkb = GetElem(_chkb))) {
			alert("MCheckBox: bad id '" + _chkb + "'");
			return;
		}
	} else
		this.chkb = _chkb;

	if ((_tam != undefined) && (typeof(_tam) == "string")) {
		if (!(this.tam = GetElem(_tam))) {
			alert("MCheckBox: bad id '" + _tam + "'");
			return;
		}
	}

	/* takhle vypada checkbox:
		<span class="nchkb [checked]">&nbsp</span>
	*/

	this.nchkb = document.createElement("span");  // drzi novy checkbox
	this.nchkb.innerHTML = "&nbsp;";
	this.nchkb.className = "nchkb";
	this.nchkb.ref = this;

	this.checked = false;
	this.value = null;
	this.onClickFunc = this.p1 = this.p2 = this.p3 = null;

	this.Set = function(_v, _c) {
		this.value = _v;
		if ((_c != undefined) && _c) {
			this.checked = true;
			AddClass(this.nchkb, "checked")
		}
	}

	if (this.chkb) {
		this.onClickFunc = this.chkb.onclick;
		this.Set(this.chkb.value, this.chkb.checked);
		this.chkb.style.display = "none";
	}

	this.nchkb.onclick = function() {
		if (this.ref.checked) {
			this.ref.checked = false;
			RemoveClass(this.ref.nchkb, "checked")
		} else {
			this.ref.checked = true;
			AddClass(this.ref.nchkb, "checked")
		}
		this.ref.chkb.checked = this.ref.checked;
		if (this.ref.onClickFunc)
			this.ref.onClickFunc(this.ref.p1, this.ref.p2, this.ref.p3);
	}

	if (this.tam == null)
		this.chkb.parentNode.insertBefore(this.nchkb, this.chkb);
	else
		this.tam.appendChild(this.nchkb);
}

/**
 * Zmeni vsechny checkboxy a input text (password) v elementu danem id _cont
 */
function ChangeCheckboxesAndITs(_cont) {
	this.cont = null;

	if (!(this.cont = GetElem(_cont))) {
		alert("ChangeCheckboxesAndITs: bad id '" + _cont + "'");
		return;
	}

	var chs = document.getElementsByTagName("input");
	for (var i = 0; i < chs.length; i++) {
		if (chs[i].type == "checkbox")
			new MCheckBox(chs[i]);
		else if ((chs[i].type == "text") || (chs[i].type == "password"))
			chs[i].className += " i_text";
	}
}

/**
 * Zmeni vsechny textarea prvky v elementu danem id _cont
 */
function ChangeTextareas(_cont) {
	this.cont = null;

	if (!(this.cont = GetElem(_cont))) {
		alert("ChangeTextareas: bad id '" + _cont + "'");
		return;
	}

	var chs = document.getElementsByTagName("textarea");
	for (var i = 0; i < chs.length; i++) {
		chs[i].className += " i_textarea";
	}
}

/**
 * Zmeni vsechny prvky v elementu danem id _cont
 */
function ChangeFormElements(_cont) {
	ChangeCheckboxesAndITs(_cont);
	ChangeSelects(_cont);
	ChangeTextareas(_cont);
}

/**
 * menu prepinatko, trida
 * _id - id obalovaciho elementu
 * _class - trida (obv. active), ktera se prida k tabu, je-li na nej kliknuto (aktivni tab)
 *        - je-li tato trida jiz pridana defaultne na tabu, pak se tento na pocatku neschova
 * _h - povoli schovavani elementu pri kliknuti na jiz vysviceny tab
 */
function MenuSwitcher(_id, _class, _h) {
	this.el = null;
	if (!(this.el = GetElem(_id))) {
		alert("MenuSwitcher: bad id '" + _id + "'");
		return;
	}

	if (_h != undefined)
		this.hideSelf = _h
	else
		this.hideSelf = false;
	this.el.className = this.el.className + " menu_switcher";

	this.classActive = _class;
	this.buts = new Array();
	this.boxes = new Array();

	this.AddPair = function (_but, _box) {
		var but = box = null;
		if (!(but = GetElem(_but))) return;
		if (!(box = GetElem(_box))) return;

		var ta = but.className.split(' ');
		if (InArray(this.classActive, ta) == -1)
			box.style.display = "none";

		but.ref = this;
		but.onclick = function () {
			var idx = -1;
			var ta = null;
			//alert(this.ref.hideSelf);
			for (var i = 0; i < this.ref.buts.length; i++) {
				if ((this.ref.buts[i] != this) || (this.ref.hideSelf && (this.ref.boxes[i].style.display == "block"))) {
					this.ref.boxes[i].style.display = "none";
					ta = this.ref.buts[i].className.split(' ');
					idx = InArray(this.ref.classActive, ta);
					if (idx != -1) {
						ta.splice(idx, 1);
						this.ref.buts[i].className = ta.join(' ');
					}
				} else {
					this.ref.boxes[i].style.display = "block";
					this.className += " " + this.ref.classActive;
				}
			}
		}

		this.buts.push(but);
		this.boxes.push(box);
	}
}

function IeLinks (_id) {
	if (!IE) return;

	var el = GetElem(_id);
	if (!el) return;

	var as = document.getElementsByTagName("a");
	for (var i = 0; i < as.length; i++) {
		as[i].onclick = function () {
			window.location=this.href;
			//return false;
		}
	}
}

function CreateBookmarkLink() {
	var title = "Eroticcity";
	var url = "http://www.eroticcity.cz";

	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite( url, title); }
	else if(window.opera && window.print) { // Opera Hotlist
		return true; }
 }

/**
 * _w - wrap
 * _t - title
 * _c - content
 */
function Vyjizdec (_w, _t, _c, _t2) {
	/*if (SJEL.ie) {
		this.w = SJEL.$(_w);
		SJEL.RemoveClass(this.w, "nojs");
		var ms = new MenuSwitcher(_w, '', true);
		ms.AddPair(_t, _c);
		return;
	}*/
	this.w = SJEL.$(_w);
	this.t = SJEL.$(_t);
	this.c = SJEL.$(_c);
	this.t2 = null;
	if (_t2 != undefined)
		this.t2 = SJEL.$(_t2);
	if (!this.w || !this.t || !this.c)
		return;

	var cc = this.c;
    this.mo = new SJEL.Morph();
    this.ch = 0;
    this.o = false;  // otevreny

	SJEL.RemoveClass(this.w, "nojs");

	this.Close = function () {
		this.mo.Init(this.c, {opacity: 0.0}, 180);
		this.mo.OnMorphFinished(function(){SJEL.SStyle(cc, {display: "none"});});
		this.mo.Morph();
		this.o = false;
	}

	this.t.ref = this;
	this.t.onclick = function () {
		if (!this.ref.o) {
			SJEL.AddClass(this, "arr");
			SJEL.RemoveClass(this, "arr2");
			SJEL.SStyle(this.ref.c, {display: "block", opacity: 0.0, overflow: "hidden"});
			this.ref.mo.Init(this.ref.c, {opacity: 1.0}, 180);
			this.ref.mo.OnMorphFinished(function(){});
			this.ref.mo.Morph();
			this.ref.o = true;
		} else {
			SJEL.RemoveClass(this, "arr");
			SJEL.AddClass(this, "arr2");
			this.ref.Close();
		}
	}

	if (this.t2 != null) {
		this.t2.ref = this;
		this.t2.onclick = function () {
			if (this.ref.o)
				this.ref.Close();
		}
	}
}

function FixIELinks (_id) {
	if ((SJEL.ie == 6) || (SJEL.ie == 7)) {
		var as = SJEL.$T(SJEL.$(_id), "a");
		for (var i = 0; i < as.length; i++) {
			as[i].onclick = function () {
				window.location=this.href;
			}
		}
	}
}

function ShowImg(_id) {
	var e = SJEL.$T(SJEL.$(_id), "tr");

	for (var i = 0; i < e.length; i++) {
		e[i].onmouseover = function() {
			SJEL.AddClass(this, "showimg");
		}
		e[i].onmouseout = function() {
			SJEL.RemoveClass(this, "showimg");
		}
	}
}

function data() {
    var ic = document.getElementById('id_ic').value;

	if (!send_xmlhttprequest(data_r, 'GET', '/index.php?ma=ajax&sid=ares_message&ic=' + ic)) {
		return true;
	}

	return false;
}

function data_r(xmlhttp) {

	if (xmlhttp.readyState == 4) {
            var error = xmlhttp.responseXML.getElementsByTagName('error')[0];
            if(error != null) {
                mattwindow_message(error.childNodes[0].data);
            } else {
        	    var odpovedi = xmlhttp.responseXML.getElementsByTagName('message')[0].childNodes;

        	    for (var i = 0; i < odpovedi.length; i++) {

        			if (odpovedi[i].childNodes.length > 0) {
        				var obj = document.getElementById(odpovedi[i].nodeName);

        				if (obj)
        					obj.value = odpovedi[i].childNodes[0].data;
        			}
        		}
            }
	    }

}

function mattwindow_message(message) {

	var db = document.getElementById('dark_bg');
	db.style.display = 'block';
	var mw = document.getElementById('matwindow');
	mw.style.display = 'block';
	document.getElementById('matwindow_in').style.display = 'block';
	var mi = document.getElementById('matwindow_in');
	mi.innerHTML = message;
	var kr = document.createElement("div");
	kr.className = "krizek";
	kr.onclick = function() {
		db.style.display = "none";
		mw.style.display = "none";
	}
	mi.appendChild(kr);
	//hide_selects_ie6();
}

function close_matwindow() {
	var obj = document.getElementById('matwindow');
    var obj2 = document.getElementById('matwindow_in');
    var obj3 = document.getElementById('dark_bg');

	if (obj) {
		obj2.innerHTML = '';
		obj.style.display = 'none';
		obj2.style.display = 'none';
	}

	if (obj3)
		obj3.style.display = 'none';

    reg = /^.*MSIE 6.*$/;
    if (reg.test(navigator.appVersion)) {
        var sel = document.body.getElementsByTagName("SELECT");
        for (var i = 0; i < sel.length; i++)
            sel[i].style.visibility = "visible";
    }
}

function row_highlight(_id) {
    this.wr = document.getElementById(_id);
    if (this.wr == null) {
        alert("row_highlight error: bad id");
        return false;
    }

    this.set_events = function (_elem) {
        _elem.onblur = function () {
            this.parentNode.parentNode.className = "";
        }
        _elem.onclick = function () {
            this.parentNode.parentNode.className = "highlight";
        }
    }

    this.inputs = this.wr.getElementsByTagName("INPUT");
    this.selects = this.wr.getElementsByTagName("SELECT");

    for (var i = 0; i < this.inputs.length; i++)
        if (this.inputs[i].type == "text")
            this.set_events(this.inputs[i]);

    for (var i = 0; i < this.selects.length; i++)
        this.set_events(this.selects[i]);
}

function KMSA(_id) {
	this.superblock = null;

	this.GetScrollXY = function () {
        var scrX = 0;
        var scrY = 0;

        if (typeof(window.pageYOffset) == 'number') {
            scrX = window.pageXOffset;
            scrY = window.pageYOffset;
        } else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
            scrX = document.body.scrollLeft;
            scrY = document.body.scrollTop;
        } else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
            scrX = document.documentElement.scrollLeft;
            scrY = document.documentElement.scrollTop;
        }

        return [scrX, scrY];
    }

    this.GetWindowWH = function () {
        var width = 0;
        var height = 0;

        if(typeof(window.innerWidth) == 'number') {
            width = window.innerWidth;
            height = window.innerHeight;
        } else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
            width = document.documentElement.clientWidth;
            height = document.documentElement.clientHeight;
        } else if(document.body && (document.body.clientWidth || document.body.clientHeight)) {
            width = document.body.clientWidth;
            height = document.body.clientHeight;
        }

        return [width, height];
    }

    this.obsluhaAJAX = function (method, url, reference) {
		xmlhttp = (window.XMLHttpRequest ? new XMLHttpRequest : (window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : false));

		if (!xmlhttp)
			return false;

		xmlhttp.open(method, url);

		/*if (obsluha != null)
			xmlhttp.onreadystatechange = function() {
				obsluha(xmlhttp, reference);
			};*/

		xmlhttp.onreadystatechange = function() {
			reference.ref.getDataStatus(xmlhttp, reference);
		};

		xmlhttp.send(null);

		return true;
	}

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

			//ref.toolBox.removeChild(ref.ref.loading);

			if (data.length > 0) {
				ref.toolBox.innerHTML = data[0].firstChild.data;
			}
		}
	}

	this.init = function () {
		var itemos = this.el.getElementsByTagName('a');
		var delka = itemos.length;

		this.loading = document.createElement("img");
        this.loading.src = "/images/loading.gif";

		for (var n = 0; n < delka; n++) {
			if (itemos[n].id == '')
				continue;

			itemos[n].toolBox = null;
        	itemos[n].ref = this;

			itemos[n].onmousemove = function (_event) {
				if (_event == undefined)
                    _event = window.event;

                if (this.toolBox == null) {
                    this.toolBox = document.createElement("span");
                    this.toolBox.className = "tool_box";
                    this.toolBox.appendChild(this.ref.loading);
                    var adresa = '/index.php?ma=ajax&sid=category&id=' + this.id.substring(3);

					this.ref.obsluhaAJAX('GET', adresa, this);

                    document.body.appendChild(this.toolBox);
                }

                this.ref.scrollXY = this.ref.GetScrollXY();
                this.ref.windowSize = this.ref.GetWindowWH();
                this.ref.mx = _event.clientX + this.ref.scrollXY[0];
                this.ref.my = _event.clientY + this.ref.scrollXY[1];
                var offsetL = 0;
                var offsetT = 0;
                if (this.ref.mx > this.ref.windowSize[0])
                    offsetL = this.ref.windowSize[0] - (this.ref.mx + 80);

                this.toolBox.style.left = this.ref.mx + offsetL + 20 + "px";
                this.toolBox.style.top = this.ref.my - offsetT +  20 + "px";
                this.toolBox.style.display = "block";
			};

			itemos[n].onmouseout = function () {
				this.toolBox.style.display = "none";
			};
		}
	};

	this.el = document.getElementById(_id);

	if (this.el)
		this.init();
}
