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 = '/index.php?ma=cnumber&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 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;

        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 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 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}, 280);
		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}, 280);
			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 ie6_hover(_id, _cl) {
	if (SJEL.ie != 6)
		return;

	var cl = SJEL.$A(_id, "class", _cl);
	for (var i = 0; i < cl.length; i++) {
		cl[i].onmouseover = function() {
			SJEL.AddClass(this, _cl + "hover");
		}
		cl[i].onmouseout = function() {
			SJEL.RemoveClass(this, _cl + "hover");
		}
	}
}
