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 open_popup2(dokument, sirka, vyska) {
	var iframe = SJEL.CE("iframe");
	iframe.style.visibility = "hidden";  // schovame iframe, protoze behem loadingu je tam bile pozadi, ktereho se nejde zbavit
	iframe.src = dokument;
	iframe.width = sirka - 30;
	iframe.height = vyska - 30;
	iframe.setAttribute("frameborder", 0);  // ie8 to potrebuje, jinak vykresluje ramecek
	// az se iframe nahraje, tak ho zobrazime
	SJEL.AddEvent(iframe, "load", function(_e){var th = SJEL.$ET(_e); th.style.visibility = "visible";});
	SWindow.Open(sirka, vyska, iframe, 'popup_swin');
}

function Vyjizdec (_w, _t, _c, _t2, _ro) {
	/*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) && (_t2 != null))
		this.t2 = SJEL.$(_t2);

	this.rol = _ro||false;
	if (this.rol) {
		SJEL.SStyle(this.c, {display: "block"});
		this.cHe = this.c.offsetHeight;
		SJEL.SStyle(this.c, {display: "none"});
	}

	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 () {
		//if (!SJEL.ie) {
			if (this.rol)
				this.mo.Init(this.c, {opacity: 0.0, height: "0px"}, 280);
			else
				this.mo.Init(this.c, {opacity: 0.0}, 280);
	
			this.mo.OnMorphFinished(function(){SJEL.SStyle(cc, {display: "none"});});
			this.mo.Morph();
		/*} else
			SJEL.SStyle(cc, {display: "none"});*/
			
		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"});
			if (this.ref.rol) {
				SJEL.SStyle(this.ref.c, {height: "0px"});
				this.ref.mo.Init(this.ref.c, {opacity: 1.0, height: this.ref.cHe + "px"}, 280);
			} else
				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 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", "/scripts/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.style.display == "none")
        elem.style.display = "block";
    else
        elem.style.display = "none";
}

function linkos() {
    var id = 0;
    
    var obj1 = document.getElementById('id_supervariants');
    
    for(i = 0; i < obj1.options.length; i++) {
        
        if(obj1.options[i].selected == true) { 
            id = obj1.options[i].value;
        }
        
    }

    send_xmlhttprequest(linkos_service, 'GET', '/scripts/get_linkos.php?idp=' + id);
}

function linkos_service(xmlhttp) {
	if (xmlhttp.readyState == 4) {
		var link = xmlhttp.responseXML.getElementsByTagName('link')[0].firstChild.data;

		if (link != '')
			window.location = link;
	}
}
