var myTWin = window.myTWin;
function OpenMyWin(link)
{
  link.target = '_MyWin';
  if (myTWin != null && !myTWin.closed)
  {
    myTWin.focus();
    myTWin.location.href = link.href;
  }
  else
  {
    myTWin = window.open(link.href,'_MyWin','toolbar=0,location=0,scrollbars=0,width=300,height=300,resizable=1,top=0,left=0');
    if (myTWin != null)
myTWin.focus();
  }
  return myTWin;
}

// Oblibena polozka
var sFavoriteUrl   = 'http://www.ebf.org';
var sFavoriteTitle = 'EBF - European Baptist Federation';

// Vytvor odkaz pro oblibenou polozku
function AddFavorite(link) {    
    // Kdyz nejsou hodnoty, nactou se aktualni z dokumentu
    sFavoriteUrl   = (sFavoriteUrl == '') ? location.href : sFavoriteUrl;
    sFavoriteTitle = (sFavoriteTitle == '') ? document.title : sFavoriteTitle;
    
    if (window.sidebar)  {
        window.sidebar.addPanel(sFavoriteTitle, sFavoriteUrl,"");
    }
    else if (window.external){
        window.external.AddFavorite(sFavoriteUrl, sFavoriteTitle); 
    }
    else if (window.opera && window.print) {
        link.title = sFavoriteTitle;
        link.href  = sFavoriteUrl;
        return true;
      } 
    else {
        return false;
    }
}

// Vytvoreni oblibene polozky
function LinkFav(sId) {    
    var aTitle = explodeTitle(sId);
    var a=document.createElement('a');

    a.setAttribute('onclick','AddFavorite(this);');
    if (navigator.userAgent.indexOf("Firefox")!=-1){ 
        a.setAttribute('href','#')
    }
    else {
        a.setAttribute('href','javascript:AddFavorite(this);');
    }
    // Pro Operu
    a.setAttribute('title',aTitle[1] ? aTitle[1] : 'Add to favorites');
    if (window.opera && window.print)  {
        a.setAttribute('rel','sidebar');
    }
    var text = document.createTextNode(aTitle[0] ? aTitle[0] : 'Add to favorites');
    // text odkazu
    a.appendChild(text);
    getID(sId).appendChild(a);
    // tisk id elementu, uvnitr ktereho chcete odkaz vytvorit
}

// Vytvoření odkazu pro tisk
function LinkPrint(sId) {
    var aTitle = explodeTitle(sId);
    var a=document.createElement('a');
    // Atributy odkazu
    a.setAttribute('href','javascript:window.print();');
    a.setAttribute('title',aTitle[1] ? aTitle[1] : 'Print this page');
    // text odkazu
    var text=document.createTextNode(aTitle[0] ? aTitle[0] : 'Print');
    a.appendChild(text);
    getID(sId).appendChild(a);
}

function ochrana(){
    getID('question').value = "2"; //zapnuty JS - otazka se zodpovi a policko se vyplni automaticky
    getID('protection').style.display = "none";
}

// Zkraceny zapis pro document.getElementById
function getID(sId) {
    return document.getElementById(sId);
}

// Rozdelit title podle znaku |
function explodeTitle(sId) {
    var aReport = new Array();
	if(getID(sId)) {
		aReport = getID(sId).title.split("|");
	}
	return aReport;
}

// Zpracovani udalosti po nacteni stranky
window.onload = Init;
function Init() {
    getID('print')      ? LinkPrint('print') : false;
    getID('favorite')   ? LinkFav('favorite') : false;
    getID('question')   ? ochrana() : false;
}

