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 Show2(_id, _show) {
    var el = document.getElementById(_id);
    if (el == null)
        return false;
        
    if (_show)
        el.style.display = 'block';
    else
        el.style.display = 'none';
}

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 comparing(produkt) {
    var chb = document.getElementById('idpr_' + produkt);
    var parameter = 'dcp';
    if(chb.checked == true){
        parameter = 'acp';
    } 
	if (!send_xmlhttprequest(get_comparing_service, 'GET', '/add_to_compare.php?idp=' + produkt + '&' + parameter)) {
		return false;
	}

	return true;
}

function get_comparing_service(xmlhttp) {
	if (xmlhttp.readyState == 4) {
		var odpovedi = xmlhttp.responseXML.getElementsByTagName('compare')[0].childNodes;
		var count_comparing = document.getElementById('comparing_info');
        
		if(count_comparing != null && xmlhttp.responseXML.getElementsByTagName('compare_info') != null && xmlhttp.responseXML.getElementsByTagName('compare_info')[0])    
		  count_comparing.innerHTML = xmlhttp.responseXML.getElementsByTagName('compare_info')[0].firstChild.data;

        if (xmlhttp.responseXML.getElementsByTagName('info') != null && xmlhttp.responseXML.getElementsByTagName('info')[0]) {		  
            //cntin = document.getElementById("content-in");
            cntin = document.getElementById("idcobl");
            goodm = document.getElementById("goodm");
            if (goodm != null) {  // hlaska uz existuje
                cntin.removeChild(goodm);
            }

            gm = document.createElement("div");
            gm.className = "good_message";
            gm.id = "goodm";

            gmi = document.createElement("div");
            gmi.className = "good_message_in";
            gmi.innerHTML = xmlhttp.responseXML.getElementsByTagName('info')[0].firstChild.data;

            gm.appendChild(gmi);

            cntin.insertBefore(gm, cntin.firstChild);  // na zacetek content-in
		}
	}
}