function op_register (id_name, normal_src, over_src, down_src)
{
    if (over_src == null)   over_src = normal_src;
    if (down_src == null)   down_src = over_src;

    op_temp_variable = new Array
      (id_name, true, new Image(), new Image(), new Image());
    op_temp_variable[2].src = normal_src;
    op_temp_variable[3].src = over_src;
    op_temp_variable[4].src = down_src;
    eval ("op_item_" + id_name + " = op_temp_variable");
}

function op_set_normal (id_name)
{
    var reg_item = eval ("op_item_" + id_name);
    if (reg_item[1])
      document.getElementById(id_name).src = reg_item[2].src;
}
    
function op_set_over (id_name)
{
    var reg_item = eval ("op_item_"+id_name);
    if (reg_item[1])
      document.getElementById(id_name).src = reg_item[3].src;
}

function op_set_down (id_name)
{
    var reg_item = eval ("op_item_" + id_name);
    if (reg_item[1])
      document.getElementById(id_name).src = reg_item[4].src;
}


function show(id) {
    el=document.getElementById(id).style;
    el.display='block';
}

function hide(id) {
    el=document.getElementById(id).style;
    el.display='none';
 
}

function OpenImage(src, alt)
{
  image = window.open('','image','left=50, top=50, width=400, height=400, toolbar=no, menubar=no, status=no, resizable=no, scrollbars=no');
  image.focus();
  image.document.write('<html><head><title>' + alt + '</title>');
  image.document.write('<script language="javascript"> function FitPic() { iWidth = document.body.clientWidth; iHeight = document.body.clientHeight; iWidth = document.images[0].width - iWidth; iHeight = document.images[0].height - iHeight; window.resizeBy(iWidth, iHeight); self.focus(); } </script>');
  image.document.write('</head><body onload="FitPic();" topmargin="0" leftmargin="0" marginwidth="0" marginheight="0" align="center"><a href="javascript: window.close();"><img src="'+src+'" alt="'+alt+'" border="0" /></a></body></html>');
  image.document.close();
}

// AJAX - anketa

var inquiryID = 0;

function send_xmlhttprequest(handler, protocol, url, content, headers)
{
    var xmlhttp = (window.XMLHttpRequest ? new XMLHttpRequest : (window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : false));
    if (!xmlhttp) {
        return false;
    }
    xmlhttp.open(protocol, url);
    xmlhttp.onreadystatechange = function() {
        handler(xmlhttp);
    };
    if (headers) {
        for (var key in headers) {
            xmlhttp.setRequestHeader(key, headers[key]);
        }
    }
    xmlhttp.send(content);
    return true;
}

function inquiry_vote(answer, lang)
{
    if (!send_xmlhttprequest(inquiry_handler, 'GET', '/inquiry.php?inquiry=' + inquiryID + '&answer=' + answer + '&lang=' + lang))
    {
        return false;
    }

    // informace o ukladani hlasovani
    return true;
}

function inquiry_handler(xmlhttp)
{
    if (xmlhttp.readyState == 4)
    {
        var inquiry = xmlhttp.responseXML.getElementsByTagName('inquiry');
        inquiryID = inquiry[0].getAttribute('id');
        lang = inquiry[0].getAttribute('lang');

        var question = xmlhttp.responseXML.getElementsByTagName('question');
        
        var content = '<p>' + question[0].firstChild.data + '</p>';
        
        var answers = xmlhttp.responseXML.getElementsByTagName('answer');
        for (var i=0; i < answers.length; i++)
        {
            content += '<a href="javascript:inquiry_vote(' + answers[i].getAttribute('id') + ', \'' + lang + '\'); void(0);">' + answers[i].firstChild.data + '&nbsp;' + answers[i].getAttribute('perc') + '%</a>' +
                       '<span><img src="/images/enq' + (i+1) + '.png" alt="' + answers[i].firstChild.data + '" style="width: ' + (Math.round(150 * answers[i].getAttribute('perc') / 100)) + 'px;" /></span>';
        }
        
        document.getElementById('enq').innerHTML = content;
    }
}
