function initApplication() {
  setValue("selYearSpan", "vsechna")
  setYearSpanType("vsechna");
  showSection("section_browse");
 
      document.getElementById("vypis_dokumentu").style.visibility = "hidden"
      document.getElementById("vysledky_pocet").innerHTML = "Načítám data&hellip;"
      
      for (var i = 0; i < libitems.length; i++) {
        var doc = new Object();
        
        doc.id = trim(libitems[i].id) 
        doc.art =  trim(libitems[i].art)
        doc.feat = trim(libitems[i].feat);
        doc.title =  trim(libitems[i].title);
        doc.year =  trim(libitems[i].year);
        doc.album =  trim(libitems[i].album);
        doc.txm =  trim(libitems[i].txm );
        if (doc.id == "" ) continue;
        dokumenty.push(doc)
        codes.push( doc.id.substring(0,3))
        alba.push( doc.album )
        if (doc.year != "") {
          var rok = parseInt(doc.year) - 1990
          if (doc.txm =="") years[rok]++
          else years_txm[rok]++
        }
      }
      //alert(result.data.join("|"))  
      document.getElementById("vypis_dokumentu").style.visibility = "visible"
      displayAll()
      
      summarizeCodes();
      summarizeAlba();
      summarizeYears();
      



}

function summarizeYears() {
    
   var vystup = "<table class=\"normal\">"
   vystup += "<tr><th>Rok</th><th>Celkem</th><th>TXM</th></tr>"
   
   var posX = 20;
   var d = 10;
   var m = 15;
   var color1 = "#0df" 
   var color2 = "#f00"
   var minY = 420
   var h = 3
   
    var ctx = document.getElementById('p_roky').getContext('2d');

    ctx.beginPath()
    ctx.moveTo(0, minY); ctx.lineTo(750,minY)
    ctx.moveTo(0, minY-h*20); ctx.lineTo(750,minY-h*20)
    ctx.moveTo(0, minY-h*40); ctx.lineTo(750,minY-h*40)
    ctx.moveTo(0, minY-h*60); ctx.lineTo(750,minY-h*60)
    ctx.moveTo(0, minY-h*80); ctx.lineTo(750,minY-h*80)
    ctx.moveTo(0, minY-h*100); ctx.lineTo(750,minY-h*100)
    ctx.moveTo(0, minY-h*120); ctx.lineTo(750,minY-h*120)
    ctx.stroke()
    
    ctx.textAlign = "left"
    ctx.fillStyle = "#000";
    ctx.font="12px Arial";
    ctx.fillText( 20, 5, minY-h*20-5);
    ctx.fillText( 40, 5, minY-h*40-5);
    ctx.fillText( 60, 5, minY-h*60-5);
    ctx.fillText( 80, 5, minY-h*80-5);
    ctx.fillText( 100, 5, minY-h*100-5);
    //ctx.fillText( 120, 5, minY-h*120-5);
    
    ctx.fillText( "celkový počet písní v daném roce", 40, 20);
    ctx.fillText( "počet písní zařazených v TXM", 40, 40);
    
    ctx.fillStyle= color1
    ctx.fillRect(20, 10, 15, 12 )
    ctx.strokeRect(20, 10, 15, 12 )
    
    ctx.fillStyle= color2
    ctx.fillRect(20, 30, 15, 12 )
    ctx.strokeRect(20, 30, 15, 12 )
     /*
     ctx.beginPath();
      ctx.arc(12.5+j*25,12.5+i*25,10,0,Math.PI*2,true);
      ctx.stroke();
      */
      //ctx.strokeRect(50,50,50,50);
   
   for (var i = 0; i < years.length; i++) {
    var pocet = years[i] + years_txm[i] 
    var pocet_txm = years_txm[i]
    vystup += "<tr>"
    vystup += "<td>" + (i+1990) + "</td>"
    vystup += "<td>" + pocet  + "</td>"
    vystup += "<td>" + pocet_txm + "</td>"
    vystup += "</tr>"
    
   
    
    ctx.fillStyle= color1
    ctx.fillRect(posX, minY-h*pocet, d, h*pocet )
    ctx.strokeRect(posX, minY-h*pocet, d, h*pocet )
    posX += d
    
    ctx.textAlign = "center"
    ctx.fillStyle = "#000";
    ctx.font="12px Arial";
    ctx.fillText( (i+1990), posX, minY + 15);
    
    ctx.fillStyle= color2
    ctx.fillRect(posX, minY-h*pocet_txm, d, h*pocet_txm )
    ctx.strokeRect(posX, minY-h*pocet_txm, d, h*pocet_txm )
    posX += d + m
   }
    
   vystup += "</table>"
  document.getElementById("p_pocty").innerHTML = vystup 
}

function summarizeCodes() {
  codes = codes.sort();
  var unCodes = new Array();
   var vypis = document.getElementById("summary_codes").tBodies[0];
   
  unCodes.push([codes[0], 1])
  
  for (var i=1; i < codes.length; i++) {
    if (codes[i] == unCodes[unCodes.length-1][0] ) unCodes[unCodes.length-1][1]++;
    else { 
      
      var radek = vypis.insertRow(vypis.rows.length)
          
      var bunka = radek.insertCell(0);
      bunka.className = "docid"
      bunka.setAttribute("data_id", unCodes[unCodes.length-1][0]);
      bunka.innerHTML = unCodes[unCodes.length-1][0];
      
      bunka = radek.insertCell(radek.cells.length);
      bunka.className = "doctitle"
      bunka.innerHTML = unCodes[unCodes.length-1][1];
      
      unCodes.push( [codes[i], 1] )         
      }
   //if (i == codes.length-1) {  }
  }
  var radek = vypis.insertRow(vypis.rows.length)
          
      var bunka = radek.insertCell(0);
      bunka.className = "docid"
      bunka.setAttribute("data_id", unCodes[unCodes.length-1][0]);
      bunka.innerHTML = unCodes[unCodes.length-1][0];
      
      bunka = radek.insertCell(radek.cells.length);
      bunka.className = "doctitle"
      bunka.innerHTML = unCodes[unCodes.length-1][1];
   
   var radek = vypis.insertRow(vypis.rows.length)
      radek.className = "suma"   
      var bunka = radek.insertCell(0);
      bunka.className = "docid"
      bunka.setAttribute("data_id", unCodes[unCodes.length-1][0]);
      bunka.innerHTML = unCodes.length + "&#160;unikátních&#160;kódů";
      
      bunka = radek.insertCell(radek.cells.length);
      bunka.className = "doctitle"
      bunka.innerHTML = codes.length + "&#160;skladeb" 
}

function summarizeAlba() {
  alba = alba.sort(compareFrenchIgnoreCase);
  var unAlba = new Array();
   var vypis = document.getElementById("summary_alba").tBodies[0];
   
  unAlba.push([alba[0], 1])
  
  for (var i=1; i < alba.length; i++) {
    if (alba[i] == unAlba[unAlba.length-1][0] ) unAlba[unAlba.length-1][1]++;
    else { 
      
      var radek = vypis.insertRow(vypis.rows.length)
          
      var bunka = radek.insertCell(0);
      bunka.className = "docid"
      bunka.setAttribute("data_id", unAlba[unAlba.length-1][0]);
      bunka.innerHTML = unAlba[unAlba.length-1][0];
      
      bunka = radek.insertCell(radek.cells.length);
      bunka.className = "doctitle"
      bunka.innerHTML = unAlba[unAlba.length-1][1];
      
      unAlba.push( [alba[i], 1] )         
      }
   //if (i == codes.length-1) {  }
  }
  var radek = vypis.insertRow(vypis.rows.length)
          
      var bunka = radek.insertCell(0);
      bunka.className = "docid"
      bunka.setAttribute("data_id", unAlba[unAlba.length-1][0]);
      bunka.innerHTML = unAlba[unAlba.length-1][0];
      
      bunka = radek.insertCell(radek.cells.length);
      bunka.className = "doctitle"
      bunka.innerHTML = unAlba[unAlba.length-1][1];
      
   var radek = vypis.insertRow(vypis.rows.length)
      radek.className = "suma"   
      var bunka = radek.insertCell(0);
      bunka.className = "docid"
      bunka.innerHTML = unAlba.length + " alb,";
      
      bunka = radek.insertCell(radek.cells.length);
      bunka.className = "doctitle"
      bunka.innerHTML = alba.length + "&#160;skladeb" ;
}

function showSection(sid) {
  
  for (var i=0; i < sections.length; i++) {
      var section = document.getElementById(sections[i]);
      var tabid = "tab" + sections[i].substring(sections[i].indexOf("_"));
      var tab = document.getElementById(tabid);
       
      if (sid == sections[i]) {
         section.style.display = "block";
         tab.className = "tab_actual" 
      }
      else {
         section.style.display = "none";
         tab.className = ""
      }
      
      
  }
}

function showSubsection(sid) {
  
  for (var i=0; i < subsections.length; i++) {
      var section = document.getElementById(subsections[i]);
            
      if (sid == subsections[i]) {
         section.style.display = "block";
        
      }
      else {
         section.style.display = "none";
       
      }
      
      
  }
}

// rozbalovani/sbalovani podseznamu
function toggle(nodeId) {
var list = document.getElementById("menutree").getElementsByTagName("UL");

for (var i= 0; i < list.length; i++) {
  if (list[i].getAttribute("id") == nodeId) {
    list[i].style.display = ( list[i].style.display == "block" ) ? "none"  : "block"
    var parent = list[i].parentNode
    parent.className = (parent.className == "opened") ? "closed" : "opened" 
    }
  else {
    list[i].style.display = "none"
    list[i].parentNode.className = "closed"
    }
  }
}



//var dokumenty = new Array(); //pole se všemi záznamy dokumentů
var selectedList = new Array() // pole vybraných dokumentů (ve vyhledávání)
var yearSpanType = "vsechna" // časové období pro vydhledávání, hodnoty: vsechna, rok, od_roku, do_roku 

var cathegories = new Array(); // pole kategorii dokumentu
var actualCathegory = 0;
var actualSubcathegory = 0;

var keywordlist  = new Array();
var keywordnames  = new Array();


// třdící funkce podle titulu 
function sortByTitle(doc1, doc2) {
var t1 = doc1.title.toLowerCase();
var t2 = doc2.title.toLowerCase();
var y1 = doc1.year;
var y2 = doc2.year;

var srvTitles = compareCzech(t1,t2)
	if (srvTitles == 0 && y1 == y2 ) return 0;
	if (y1 > y2 && srvTitles == 0 ) return 1;
	if (y1 < y2 && srvTitles == 0 ) return -1;  
	return srvTitles;
}

// třídící funkce podle data 
function sortByDate(doc1, doc2) {
var t1 = doc1.title.toLowerCase(); 
var t2 = doc2.title.toLowerCase();
var y1 = doc1.year;
var y2 = doc2.year;
var srvTitles = compareCzech(t1,t2)

	if (y1 > y2 ) return 1
	if (y1 < y2 ) return -1
	if (y1 == y2) return srvTitles 

}
// srovnávání řetězců podle českých pravidel
function compareCzech(retez1, retez2, ignoreCase) {
var srv = " .,aábcčdďeéěfghchiíjklmnňoópqrřsštťuúvwxyýzž"
  var kratsi = Math.min(retez1.length,retez2.length)
  var i1 = 0;
  var i2 = 0;
  if (ignoreCase) {
  retez1 = retez1.toLowerCase()
  retez2 = retez2.toLowerCase()
  }
  while (i1 < kratsi) {
    var r1 = retez1.charAt(i1)
    if (retez1.charAt(i1) == "c" && retez1.charAt(i1+1) == "h") {
      r1 = "ch"; i1++;
      }
    var r2 = retez2.charAt(i2)
    if (retez2.charAt(i2) == "c" && retez2.charAt(i2+1) == "h") {
      r2 = "ch"; i2++;
      }
      i1++; i2++;
  if (srv.indexOf(r1) < srv.indexOf(r2)) return -1
  if (srv.indexOf(r1) > srv.indexOf(r2)) return 1 
  }
return 0;
}

// ceske trideni bez ohled una velikost pismen
function compareCzechIgnoreCase(retez1, retez2) {
var srv = " .,aábcčdďeéěfghchiíjklmnňoópqrřsštťuúvwxyýzž"
  var kratsi = Math.min(retez1.length,retez2.length)
  var i1 = 0;
  var i2 = 0;

  retez1 = retez1.toLowerCase()
  retez2 = retez2.toLowerCase()
  while (i1 < kratsi) {
    var r1 = retez1.charAt(i1)
    if (retez1.charAt(i1) == "c" && retez1.charAt(i1+1) == "h") {
      r1 = "ch"; i1++;
      }
    var r2 = retez2.charAt(i2)
    if (retez2.charAt(i2) == "c" && retez2.charAt(i2+1) == "h") {
      r2 = "ch"; i2++;
      }
      i1++; i2++;
  if (srv.indexOf(r1) < srv.indexOf(r2)) return -1
  if (srv.indexOf(r1) > srv.indexOf(r2)) return 1 
  }
return 0;
}
                
// srovnávání řetězců podle francouzských pravidel
function compareFrench(retez1, retez2, ignoreCase) {
var srv = " .,aâáàbcçdeèéêfghiìîïjklmnoœópqrstuùûüvwxyz"

  var kratsi = Math.min(retez1.length,retez2.length)
  var i1 = 0;
  var i2 = 0;
  if (ignoreCase) {
  retez1 = retez1.toLowerCase()
  retez2 = retez2.toLowerCase()
  }
  while (i1 < kratsi) {
    var r1 = retez1.charAt(i1)
    
    var r2 = retez2.charAt(i2)
    
      i1++; i2++;
  if (srv.indexOf(r1) < srv.indexOf(r2)) return -1
  if (srv.indexOf(r1) > srv.indexOf(r2)) return 1 
  }
  if (retez1.length > retez2.length) return 1
  if (retez1.length < retez2.length) return -1
return 0;
}

// ceske trideni bez ohled una velikost pismen
function compareFrenchIgnoreCase(retez1, retez2) {
var srv = " .,aâáàbcçdeèéêfghiìîïjklmnoœópqrstuùûüvwxyz"
  var kratsi = Math.min(retez1.length,retez2.length)
  var i1 = 0;
  var i2 = 0;

  retez1 = retez1.toLowerCase()
  retez2 = retez2.toLowerCase()
  while (i1 < kratsi) {
    var r1 = retez1.charAt(i1)
    
    var r2 = retez2.charAt(i2)
    
      i1++; i2++;
  if (srv.indexOf(r1) < srv.indexOf(r2)) return -1
  if (srv.indexOf(r1) > srv.indexOf(r2)) return 1 
  }
  if (retez1.length > retez2.length) return 1
  if (retez1.length < retez2.length) return -1
return 0;
}

// sestavení seznamu dokumentů řazeného podle data
function listByDate(asc) {
  selectedList = selectedList.sort(sortByDate)
  if (!asc) selectedList = selectedList.reverse();
  showList()
  
}

// sestavení seznamu dokumentů řazeného podle kodu
function listByCode(asc) {
  selectedList = selectedList.sort(sortByCode)
  if (!asc) selectedList = selectedList.reverse();
  showList()
  
}

function sortByCode( doc1, doc2) {
var t1 = doc1.id;
var t2 = doc2.id; 
 
  if (t1 == t2 ) return 0
  if (t1 > t2) return 1
  else return -1
	
}



// sestavení seznamu dokumentů řazeného podle titulů
function listByTitle(asc) {
  selectedList = selectedList.sort(sortByTitle)
  if (!asc) selectedList = selectedList.reverse();
  showList()
  
}

function sortByTitle( doc1, doc2) {
var t1 = doc1.title;
var t2 = doc2.title; 
 
 return compareFrench(t1, t2, true);
	
}

// sestavení seznamu dokumentů řazeného podle alba
function listByAlbum(asc) {
  selectedList = selectedList.sort(sortByAlbum)
  if (!asc) selectedList = selectedList.reverse();
  showList()
  
}

// třdící funkce podle alba
function sortByAlbum(doc1, doc2) {
var t1 = doc1.title.toLowerCase();
var t2 = doc2.title.toLowerCase();
var g1 = doc1.album;
var g2 = doc2.album;

var srvTitles = compareFrench(t1,t2, true)
	if (g1 == g2 ) return 0;
	if (g1 > g2 ) return 1;
	if (g1 < g2 ) return -1;  
	//return srvTitles;
}

// sestavení seznamu dokumentů řazeného podle data
function listByAuthor(asc) {
  selectedList = selectedList.sort(sortByAuthor)
  if (!asc) selectedList = selectedList.reverse();
  showList()
  
}

// třdící funkce podle autora
function sortByAuthor(doc1, doc2) {
var t1 = doc1.title.toLowerCase();
var t2 = doc2.title.toLowerCase();
var a1 = doc1.art.toLowerCase();
var a2 = doc2.art.toLowerCase();

var srvTitles = compareFrench(t1,t2, true)
var srvAuthors = compareFrench(a1,a2, true)
	if (a1 == a2 ) return srvTitles;
	else return srvAuthors
	//return srvTitles;
}




// výpis záznamu 
function showInfo(kod) {
document.getElementById("vypis_podrobne").style.display = "block"
document.getElementById("vypis_list").style.display = "none"

    var vystup = "";
    
    vystup += "<input class=\"right\" type=\"image\" src=\"design/view_list.png\" title=\"Zpět na seznam\" onclick=\"backToList()\" />" 
var baseurl = "https://is.muni.cz/auth/do/phil/Pracoviste/URJL/rapcor/data/" + kod

var doc = null;

  for (var i = 0; i < dokumenty.length; i++) {
    if (dokumenty[i].id == kod) { doc = dokumenty[i]; break  }
    }

  vystup += "<h2>"+ kod +" " + insertNbsp(doc.title) + "</h2>" // výpis titulu
 
 
/**/
   
 
  vystup += "<p><strong>Interpret:</strong> " + doc.art + "</p>"
  if (doc.feat != "")  vystup += "<p><strong>Feature:</strong> " + doc.feat + "</p>"
  vystup += "<p><strong>Album:</strong> " + doc.album + "</p>"
  vystup += "<p><strong>Rok:</strong> " + doc.year + "</p>"
  vystup += "<hr />"
  vystup += "<ul>"
  vystup += "<li><a href=\"" + baseurl + "\" target=\"_blank\">složka v úložišti</a></li>"
  vystup += "<li><a href=\"" + baseurl + "\/" + kod +"_P.doc\" target=\"_blank\">text skladby (ver. pochette)</a></li>"
  vystup += "<li><a href=\"" + baseurl + "\/" + kod +"_S.doc\" target=\"_blank\">text skladby (přepsaný z nahrávky)</a></li>"
    vystup += "</ul>"
 setHTML("vypis_podrobne", vystup)
 
  
  
}

function getSingerInfo(name) {
  var singer = null;
  
  for (var i =0; i < singers.length; i++) {
    if (singers[i].name == name) {
      singer = singers[i]; break;
      }
  }
  
  var vystup = "<h3>" + name + "</h3>"
  document.getElementById("vysledky_nadpis").innerHTML = "Skladby autora " + name 
  if (singer != null) {
    if (singer.notes != "")  vystup += "<p><a href=\"" + singer.notes + "\" target=\"_blank\">Další informace</a></p>"
    if (singer.date != "") vystup += "<p><strong>Datum narození:</strong> " + singer.date.replace(/\//g,". ") +"</p>"
    
    if (singer.country != "" && singer.town != "") vystup += "<p><strong>Původ:</strong> " + singer.country + ", " + singer.town + "</p>"
    if (singer.region != "" && singer.dpt != "") vystup += "<p><strong>Region, departement:</strong> " + singer.reg + ", " + singer.dpt + "</p>"
    if (singer.com != "") vystup += "<p><strong>Commune:</strong> " + singer.com + "</p>"
    }
  var kody = new Array();
  var kody_txm = new Array();
  selectedList = new Array();
  
  for (var j = 0; j < dokumenty.length; j++)  {
    if (dokumenty[j].art == name) {
    var odkaz ="<a class=\"click\" onclick=\"showInfo('"+ dokumenty[j].id + "')\">" + dokumenty[j].id + "</a>"  
    if (dokumenty[j].txm != "") kody_txm.push(odkaz);
    else kody.push(odkaz)
    selectedList.push(dokumenty[j])
    }
  }
  vystup += "<p class=\"click\" onclick=\"getSingerInfo('" + name + "')\">Zobrazit skladby interpreta</p>"
  vystup += "<dl>"
  vystup += "<dt>Skladby v TXM (" + kody_txm.length + ")</dt><dd>" + kody_txm.join(", ") + "<dd>"
  vystup += "<dt>Ostatní skladby (" + kody.length + ")</dt><dd>" + kody.join(", ") + "<dd>"
  vystup += "</dl>"  
 document.getElementById("singer_info").innerHTML = vystup
 
 showList()
}


function getAlbumInfo(name) {
  var album = null;
  
  for (var i =0; i < singers.length; i++) {
    if (singers[i].name == name) {
      singer = singers[i]; break;
      }
  }
  
  var vystup = "<h3>" + name + "</h3>"
  document.getElementById("vysledky_nadpis").innerHTML = "Album " + name 
  if (singer != null) {
    if (singer.notes != "")  vystup += "<p><a href=\"" + singer.notes + "\" target=\"_blank\">Další informace</a></p>";
     
    
    }
  
  var kody = new Array();
  var kody_txm = new Array();
  selectedList = new Array();
  
  for (var j = 0; j < dokumenty.length; j++)  {
    if (dokumenty[j].art == name) {
    var odkaz ="<a class=\"click\" onclick=\"showInfo('"+ dokumenty[j].id + "')\">" + dokumenty[j].id + "</a>"  
    if (dokumenty[j].txm != "") kody_txm.push(odkaz);
    else kody.push(odkaz)
    selectedList.push(dokumenty[j])
    }
  }
  vystup += "<p class=\"click\" onclick=\"getSingerInfo('" + name + "')\">Zobrazit skladby interpreta</p>"
  vystup += "<dl>"
  vystup += "<dt>Skladby v TXM (" + kody_txm.length + ")</dt><dd>" + kody_txm.join(", ") + "<dd>"
  vystup += "<dt>Ostatní skladby (" + kody.length + ")</dt><dd>" + kody.join(", ") + "<dd>"
  vystup += "</dl>"  
 document.getElementById("singer_info").innerHTML = vystup
 
 showList()
}

// výpis seznamu dokumentů
function showList() {
document.getElementById("vypis_podrobne").style.display = "none"
document.getElementById("vypis_list").style.display = "block"
var vypis = document.getElementById("vypis_dokumentu").tBodies[0];
//alert("vybrano: " + selectedList.length);
while (vypis.rows.length > 0 ) vypis.deleteRow(0)

 for (var i= 0; i< selectedList.length; i++) {
      var entry = selectedList[i];
      
      var radek = vypis.insertRow(vypis.rows.length)
      //radek.className = entry.getType()
      radek.onmouseover = function () {
        this.style.backgroundColor = "#fff5ee"
        this.cells[0].style.textDecoration = "underline"
      }
      radek.onmouseout = function () {
        this.style.backgroundColor = "white"
        this.cells[0].style.textDecoration = "none"
      }
            
      var bunka = radek.insertCell(0);
      bunka.className = "docid click"
      bunka.setAttribute("data_id", entry.id);
      bunka.setAttribute("onclick", "showInfo(this.getAttribute(\"data_id\"))" ) 
      bunka.innerHTML = insertNbsp(entry.id);
      bunka.title = "Zobrazit podrobnosti"
      
      bunka = radek.insertCell(radek.cells.length);
      bunka.className = "doctitle click"
       bunka.setAttribute("data_id", entry.id);
      bunka.setAttribute("onclick", "showInfo(this.getAttribute(\"data_id\"))" ) 
      bunka.innerHTML = insertNbsp(entry.title);
      bunka.title = "Zobrazit podrobnosti"
      
      
      bunka = radek.insertCell(radek.cells.length);
      bunka.innerHTML = entry.art;
      bunka.setAttribute("onclick", "getSingerInfo('" + entry.art+ "')" )
      bunka.className = "doctitle"
      bunka.title = "Zobrazit všechny skladby interpreta"
      
      bunka = radek.insertCell(radek.cells.length);
      bunka.innerHTML = entry.feat;
      //bunka.title = entry.types[entry.type];
      
      bunka = radek.insertCell(radek.cells.length);
      bunka.innerHTML = entry.year;
      
      bunka = radek.insertCell(radek.cells.length);
      bunka.innerHTML = entry.album;
      
      bunka = radek.insertCell(radek.cells.length);
      bunka.innerHTML = entry.txm;
            
      }

 document.getElementById("vysledky_pocet").innerHTML = /*"Nalezeno " + */ selectedList.length //+ " položek." 

}

function backToList() {
 document.getElementById("vypis_podrobne").style.display = "none"
document.getElementById("vypis_list").style.display = "block"
}

// vyhledávání dokumentů
function searchDocs() {

//nastaveni casoveho rozpeti
var lowest_year = Number(getValue("year_lowest"))
var highest_year = Number(getValue("year_highest"))

if (yearSpanType == "vsechna") {
  lowest_year = 0;
  highest_year = 10000;
}
if (yearSpanType == "rok") highest_year = lowest_year;
 
if (yearSpanType == "do_roku") {highest_year = lowest_year; lowest_year = 0;}
if (yearSpanType == "od_roku") {highest_year = 10000};

var hledany = getValue("searched");
var inCodes = document.getElementById("search_codes").checked;
var inTitles = document.getElementById("search_titles").checked;
var inAuthors = document.getElementById("search_authors").checked;
var inAlba = document.getElementById("search_alba").checked;

var inTXM = document.getElementById("search_txm").checked
//var inKeywords = document.getElementById("search_keywords").checked;

document.getElementById("vysledky_nadpis").innerHTML = "Výsledky hledání fráze \"" + hledany + "\""

hledany = hledany.toLowerCase()
selectedList = new Array();
for (var i= 0; i < dokumenty.length; i++ ) {
  var entry = dokumenty[i]
  var year = entry.year
  
  var found = false;
   
  if (year < lowest_year || year > highest_year) continue;
  
  var code = entry.id.toLowerCase()
  var titul = entry.title.toLowerCase()
  var author = entry.art.toLowerCase()
  var album = entry.album.toLowerCase()
  /*
  var comment = entry.getAnnotation().toLowerCase()
  var keywords = entry.listKeywords().toLowerCase()
  */
  
  if (inCodes && code.indexOf(hledany) > -1) { found = true;
    
    } 
  if (inTitles && titul.indexOf(hledany) > -1) { found = true;
    
    }
  if (inAuthors && author.indexOf(hledany) > -1) { 
    found = true;
    
    }
  if (inAlba && album.indexOf(hledany) > -1) {
    found = true;
    
    }
  if (inTXM && entry.txm.toLowerCase() != "x") found = false;
  
  if (found) selectedList.push(entry);
      
  }
//showTab("results")

listByTitle(true);
}

// zobrazení všech dokumentů
function displayAll() {
setYearSpanType("vsechna")

selectedList = new Array();
for (var i = 0; i < dokumenty.length; i++) {
  selectedList.push(dokumenty[i])
}

listByTitle(true);
setValue("selYearSpan","vsechna")
document.getElementById("vysledky_nadpis").innerHTML = "Všechny skladby"

//selectCathegory("all")
}

// nastavení časového rozsahu pro vyhledávání
function setYearSpanType(hodnota) {
  if (hodnota == "mezi_roky") show("year_span");
  else hide("year_span")
  if (hodnota == "vsechna") hide("year_lowest")
  else show("year_lowest")
  yearSpanType = hodnota;
  
}


function clearList(nodeId) {
  var list = document.getElementById(nodeId);
  while (list.options.length > 0) { list.remove(0)}
}
 
function showTab(tabId) {
  for (var i = 0; i < sections.length; i++) {
  if (tabId == sections[i]) {
    document.getElementById("section_" + sections[i]).style.display = "block"
    document.getElementById("tab_" + sections[i]).className = "tab actual"
    }
  else {
    document.getElementById("section_" + sections[i]).style.display = "none"
    document.getElementById("tab_" + sections[i]).className = "tab"
    }
  }
}


String.prototype.getAttribute = function(name) {

  var position = this.indexOf(name + "=");
  var length = name.length;
  if (position == -1) return "";

  return this.substring( position + length + 2, this.indexOf("\"", position + length + 3))
}
 
 
 
 function getValue(nodeId) {
      return document.getElementById(nodeId).value;
    } 
    
    function setValue(nodeId, code) {
      document.getElementById(nodeId).value = code;
    }
    
    function setHTML(nodeId,code) {
      document.getElementById(nodeId).innerHTML = code;
    }
    function getHTML(nodeId) {
      return document.getElementById(nodeId).innerHTML;
    }
    
    function show(nodeId) {
      document.getElementById(nodeId).style.visibility = "visible";
    }
    function hide(nodeId) {
      document.getElementById(nodeId).style.visibility = "hidden";
    }
    
    function hideBlock(nodeId) {
      document.getElementById(nodeId).style.visibility = "hidden";
    }
    
    function showBlock(nodeId) {
      document.getElementById(nodeId).style.display = "block";
    }
    function hideBlock(nodeId) {
      document.getElementById(nodeId).style.display = "none";
    }
  function disable (nodeId) {
    document.getElementById(nodeId).disabled = true;
  }
  function enable (nodeId) {
    document.getElementById(nodeId).disabled = false;
  }

// vynecháhí bílých znaků ze začátku a konce řetězce   
  function trim(retez) {
    while (retez.charCodeAt(0) < 33) {
      retez = retez.substring(1)
      }
    while (retez.charCodeAt(retez.length -1 ) < 33) {
      retez = retez.substring(0, retez.length -1)
      }  
  return retez
    }

// vlozeni pevnych mezer do retezce 
    function insertNbsp (retez) {
    return retez.replace(/(\s)([ksvziuoKSVZIUO])\s/g,"$1$2&nbsp;")
    }