
function showDetailImage(obj)
{
  var pImg = new String(document.getElementById(obj).src);
  sImg = pImg.substr(0,pImg.length-5) + "L.jpg";

  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>Základní škola JIH a Mateřská škola - Detail fotografie</title>');
  image.document.write('<script language="javascript"> var NS = (navigator.appName=="Netscape") ? true:false; function FitPic() { iWidth = (NS)?window.innerWidth:document.body.clientWidth; iHeight = (NS)?window.innerHeight: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();" title="Kliknutím zavřete obrázek"><img src="' + sImg + '" alt="Základní škola JIH a Mateřská škola - Detail fotografie" border="0" /></a></body></html>');
  image.document.close();
}


// AJAX - ankety

AJAXHandler = function()
{
}

AJAXHandler.prototype.send_request = function(url, handler)
{
    var xmlhttp = (window.XMLHttpRequest ? new XMLHttpRequest : (window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : false));
    if (!xmlhttp) {
        return false;
    }
    xmlhttp.open('GET', url);
    xmlhttp.onreadystatechange = function()
    {
        if (xmlhttp.readyState == 4) handler(xmlhttp);
    }

    xmlhttp.send(null);
}

function inquiry_vote(answer, inquiry, lang)
{
    var url = '/inquiry.php?inquiry=' + inquiry + '&answer=' + answer + '&lang=' + lang + '&date=' + new Date();
    var ajax = new AJAXHandler();
    ajax.send_request(url, inquiry_handler);
}

function inquiry_handler(xmlhttp)
{
    inquiry = xmlhttp.responseXML.getElementsByTagName('inquiry');
    var inquiryID = inquiry[0].getAttribute('id');
    var lang = inquiry[0].getAttribute('lang');

    var question = xmlhttp.responseXML.getElementsByTagName('question');

    var content = '<h3>' + question[0].firstChild.data + '</h3>';

    var answers = xmlhttp.responseXML.getElementsByTagName('answer');
    for (var i=0; i < answers.length; i++)
    {
        content += '<a href="javascript:inquiry_vote(' + answers[i].getAttribute('id') + ', ' + inquiryID + ', \'' + lang + '\'); void(0);">' + answers[i].firstChild.data + '&nbsp;' + answers[i].getAttribute('perc') + '%</a>' +
                   '<span><img src="/images/enq.png" alt="' + answers[i].firstChild.data + '" style="width: ' + (Math.round(200 * answers[i].getAttribute('perc') / 100)) + 'px;" /></span>';
    }

    document.getElementById('enq'+inquiryID).innerHTML = content;
}