﻿function framedimension(id) {
  var iframeref;
  iframeref = document.getElementById(id);

  iframeref.height = window.screen.availHeight - 300;
  iframeref.width = window.screen.availWidth - 230;

}

function createCookie(name,value) {
	var date = new Date();
	date.setTime(date.getTime()+(24*60*60*1000));
	var expires = "; expires="+date.toGMTString();
	document.cookie = name+"="+value+expires+"; path=/";
}

function showlayers(id,action) {
  var div;
  div = document.getElementById(id).style;
  if (div.display == "none"){
    div.display = "block";
  } else if (div.display == "block"){
    div.display = "none";
  }
}

function showandchange(idl,ida) {
  div = document.getElementById(idl).style;
  if (div.display == "none"){
    div.display = "block";
    document.getElementById(ida).src = "ico/collapse.png";
  } else if (div.display == "block"){
    div.display = "none";
    document.getElementById(ida).src = "ico/expand.png";
  }
}

function menu(idl,ida,itemscount,action) {
  if (action == "open") {
    var state = "1";
  } else {
    var state = "0";
  }
  if (idl == "user") {
    createCookie("menuuser",state);
  } else {
    createCookie("menuadmin",state);
  }
  for (i=0;i<itemscount;i++) {
    li = document.getElementById(idl+i).style;
    if (li.display == "none"){
      li.display = "block";
      document.getElementById(ida).src = "ico/open.gif";
    } else if (li.display == "block"){
      li.display = "none";
      document.getElementById(ida).src = "ico/close.gif";
    }
  }
}

function createinputs(){
  var count,item,i,str;
  item = document.getElementById("inputs_count");
  count = item.value;
  str='<br>Zde napiště každou možnou odpověď';
  for (i=1;i<=count;i++) {
    str=str+'<br><input name="node'+i+'" type="text">';
  }
  
  div=document.getElementById("inputsdiv");
  div.innerHTML=str;
}

function createfileinputs(){
  var count,item,i,str;
  item = document.getElementById("inputs_count");
  count = item.value;
  str='<br>Zde vložte každou stránku';
  for (i=1;i<=count;i++) {
    str=str+'<br><input name="node'+i+'" type="file">';
  }
  
  div=document.getElementById("inputsdiv");
  div.innerHTML=str;
}

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);
        xmlhttp.onreadystatechange = function() {
            obsluha(xmlhttp);
        };
        if (headers) {
            for (var key in headers) {
                xmlhttp.setRequestHeader(key, headers[key]);
            }
        }
        xmlhttp.send(content);
        //return true;
}
    
function processRequest(httpRequest){
	var width;
	var max;
    if (httpRequest.readyState == 1) {
      document.getElementById("status_bar").innerHTML = 'Načítám ... <img alt="loader" src="ajax-loader.gif" align="abmiddle">';
    }
    if (httpRequest.readyState == 4)
    {
      if(httpRequest.status == 200)
      {
        var odpovedi = httpRequest.responseXML.getElementsByTagName('votes');
        var all = httpRequest.responseXML.getElementsByTagName('all');
        max = 0;
        for (var i=0; i < odpovedi.length; i++) {
          if (max < parseInt(odpovedi[i].firstChild.data)) {
            max = parseInt(odpovedi[i].firstChild.data);
          }
        }
        for (var i=0; i < odpovedi.length; i++) {
            width = 150*parseInt(odpovedi[i].firstChild.data)/max;
            document.getElementById("n"+i).innerHTML = "<img src=\"anketa.gif\" height=\"6\" width=\""+width.toString()+"\">&nbsp;"+odpovedi[i].firstChild.data;
            document.getElementById("a"+i).href = "#";      
        }
        document.getElementById("status_bar").innerHTML = "Celkový počet hlasů: "+all[0].firstChild.data;
      }
    }
}

function anketaRequest(httpRequest){
    if (httpRequest.readyState == 1) {
      document.getElementById("anketa_load").innerHTML = 'Načítám ... <img alt="loader" src="ajax-loader.gif" align="abmiddle">';
    }
    if (httpRequest.readyState == 4)
    {
      if(httpRequest.status == 200)
      {
        var odpovedi = httpRequest.responseXML.getElementsByTagName('state');

        for (var i=0; i < odpovedi.length; i++) {
            if (odpovedi[i].firstChild.data=="1") {
              document.getElementById("anketa_text").innerHTML = "Anketa je aktivní";
            } else {
              document.getElementById("anketa_text").innerHTML = "Anketa není aktivní";
            }
            //document.getElementById("n"+i).innerHTML = "<img src=\"anketa.gif\" height=\"6\" width=\""+width.toString()+"\">&nbsp;"+odpovedi[i].firstChild.data;
            //document.getElementById("a"+i).href = "#";      
        }
        document.getElementById("anketa_load").innerHTML = "";
        //document.getElementById("status_bar").innerHTML = "Celkový počet hlasů: "+all[0].firstChild.data;
      }
    }
}

