function hideElement(id){
   
   document.getElementById("chapterID_"+id).style.display = "inline";
}



function showElement(id){
  
  var auxArea = document.getElementById("aux_area");
  var chapArea = document.getElementById("chap_area");
  var lastChapter = document.getElementById("chapterID_"+lastSelectedChapter);
  var newChapter = document.getElementById("chapterID_"+id);
  
  if (lastChapter != null)
    auxArea.appendChild(lastChapter)
    chapArea.appendChild(newChapter)
}

var lastSelectedChapter = 1;
var actualChapter = 1

function selectChapter(which, count){
  
  document.getElementById("chapterNavigation_"+lastSelectedChapter).className=""
  
  document.getElementById("chapterNavigation_"+which).className="actualChapter"
  
  if (count>1) {
    document.getElementById("chapterHeading_"+lastSelectedChapter).className=""
    document.getElementById("chapterHeading_"+which).className="actualChapter"
    }

  //schovat predchozi u prvni stranky
  document.getElementById("chapterNavigation_previous").style.display="inline"
  if (which == 1) {
    document.getElementById("chapterNavigation_previous").style.display="none"
  }  
  
  //schovat dalsi u posledni stranky
  document.getElementById("chapterNavigation_next").style.display="inline"
  if (which == count) {
    document.getElementById("chapterNavigation_next").style.display="none"
  }
  
  actualChapter = which;
  
//  hideElement(lastSelectedChapter)
  
  showElement(which)
  lastSelectedChapter = which

  __visualChapterCounterUpdate(count)
  
}




function selectPreviousChapter(count){
  if(lastSelectedChapter==1)
    return

  //schovat predchozi u prvni stranky a pripadne obnovit dalsi
  if (lastSelectedChapter == count) {
    document.getElementById("chapterNavigation_next").style.display="inline"
  }
  if (lastSelectedChapter == 2) {
    document.getElementById("chapterNavigation_previous").style.display="none"
  }    

  document.getElementById("chapterNavigation_"+lastSelectedChapter).className=""
  document.getElementById("chapterHeading_"+lastSelectedChapter).className=""

  //hideElement(lastSelectedChapter)
  actualChapter--
  
  showElement(actualChapter)    
  lastSelectedChapter--
  document.getElementById("chapterNavigation_"+lastSelectedChapter).className="actualChapter"
  document.getElementById("chapterHeading_"+lastSelectedChapter).className="actualChapter"

  __visualChapterCounterUpdate(count)
}


function selectNextChapter(count){
  if(lastSelectedChapter==count)
    return

  //schovat dalsi u posledni stranky a pripadne obnovit predchozi
  if (lastSelectedChapter == 1) {
    document.getElementById("chapterNavigation_previous").style.display="inline"
  }
  if (lastSelectedChapter == count-1) {
    document.getElementById("chapterNavigation_next").style.display="none"
  }    

  document.getElementById("chapterNavigation_"+lastSelectedChapter).className=""
  document.getElementById("chapterHeading_"+lastSelectedChapter).className=""

  actualChapter++
  
  showElement(actualChapter)    
  lastSelectedChapter++
  document.getElementById("chapterNavigation_"+lastSelectedChapter).className="actualChapter"
  document.getElementById("chapterHeading_"+lastSelectedChapter).className="actualChapter"
  
  __visualChapterCounterUpdate(count)
}

function __visualChapterCounterUpdate(count){

  if(lastSelectedChapter==1){
    document.getElementById("chapterNavigation_previous").className="normalChapter"
    //document.getElementById("chapterNavigation_previous").removeAttribute("href")
    

  } else {
    document.getElementById("chapterNavigation_previous").className=""
    //document.getElementById("chapterNavigation_previous").setAttribute("href","#")
    
    
  }

  if(lastSelectedChapter==count){
    document.getElementById("chapterNavigation_next").className="normalChapter"
    
  } else {
    document.getElementById("chapterNavigation_next").className=""
  }
}

function showImage(src, title){
   
    var img=new Image();
    img.title = title;
    img.onload = __showImage;
    img.onerror = __showError;
    img.src=src;
    //alert('aaa: ' + src);
}

function __showImage(){
    
    var scrollX = false;
    var scrollY = false;
    
    var title = this.title
    var width = this.width;
    var height = this.height;
    var strFileName = this.src
    delete src
    
    
    // 'cose of scrollbars
    //width+=40
    //height+=40
    if(height > screen.availHeight) {
        height = screen.availHeight - 100
	scrollY=true
    }
    
    if(width > screen.availWidth) {
        width = screen.availWidth - 100
	scrollX=true
    }
    
    width += scrollY && !scrollX ? 16 : 0; 
    height += scrollX && !scrollY ? 16 : 0; 
    
    var left = (screen.availWidth - width) / 2;
    var top = (screen.availHeight - height) / 2;

    var w = window.open('', '_blank', 'directories=no, status=no, resizable=yes, menubar=no, top='+top+', left='+left+', width='+width+', height='+height+(scrollX || scrollY ? ',scrollbars=yes' : ''));
    w.document.write('<html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1250"><title>'+title+'</title></head><body margin="0" padding="0" style="margin:0;padding:0;">')
    w.document.write('<img style="cursor: hand" onclick="self.close()" src="'+strFileName+'" alt="Klikněte pro zavření">');
    w.document.write('</body></html>');
    w.document.close();

}
function __showError(){
    //alert(); 
    var scrollX = false;
    var scrollY = false;
    
    var title = this.title
    var width = this.width;
    var height = this.height;
    var strFileName = this.src
    delete src
    
    
    // 'cose of scrollbars
    //width+=40
    //height+=40
    if(height > screen.availHeight) {
        height = screen.availHeight - 100
	scrollY=true
    }
    
    if(width > screen.availWidth) {
        width = screen.availWidth - 100
	scrollX=true
    }
    
    width = 300; 
    height = 300; 
    
    var left = (screen.availWidth - width) / 2;
    var top = (screen.availHeight - height) / 2;

    var w = window.open(this.src, '_blank', 'directories=no, status=no, resizable=yes, menubar=no, top='+top+', left='+left+', width='+width+', height='+height+(scrollX || scrollY ? ',scrollbars=yes' : ''));
/*
    w.document.write('<html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1250"><title>'+title+'</title></head><body margin="0" padding="0" style="margin:0;padding:0;">')
    w.document.write('<img style="cursor: hand" onclick="self.close()" src="'+strFileName+'" alt="Klikněte pro zavření">');
    w.document.write('</body></html>');
    w.document.close();
*/    

function traExttraining_addNewTextBoxes(){
    // is any term selected?
    if(traExttraining_selectedTerm==null){
        alert("Nejprve vyberte prosím termín!");
        return;
    }

    traExttraining_termChanged = true;
    traExttraining_addRegistered();    
}



}

