var timer_but;
var odp_time;

// Vklada reklamu
function insert_rekl(cis) {
  if(cis==1) {
    document.write('<center><iframe name="hlb" style="height: 60px; width: 468px; border: 0px; " marginwidth="0" marginheight="0" scrolling="no" frameborder="0" src="http://www.hofyland.cz/hlb.php?hlr=1"></iframe></center>');
  }
  if(cis==2) {
    document.write('<center><iframe name="hlb" style="height: 250px; width: 250px; border: 0px; " marginwidth="0" marginheight="0" scrolling="no" frameborder="0" src="http://www.hofyland.cz/hlb.php?hlr=2"></iframe></center>');
  }
  if(cis==3) {
    document.write('<center><iframe name="hlb" style="height: 60px; width: 468px; border: 0px; " marginwidth="0" marginheight="0" scrolling="no" frameborder="0" src="http://www.hofyland.cz/hlb.php?hlr=3"></iframe></center>');
  }
}

// Hlidani CapsLocku
function capsDetect(e, cis) {
  if( !e ) { e = window.event; } if( !e ) { MWJ_say_Caps(false, cis); return; }
	//what (case sensitive in good browsers) key was pressed
	var theKey = e.which ? e.which : ( e.keyCode ? e.keyCode : ( e.charCode ? e.charCode : 0 ) );
	//was the shift key was pressed
	var theShift = e.shiftKey || ( e.modifiers && ( e.modifiers & 4 ) ); //bitWise AND
	//if upper case, check if shift is not pressed. if lower case, check if shift is pressed
	MWJ_say_Caps((theKey>64 && theKey<91 && !theShift) || (theKey>96 && theKey<123 && theShift), cis);
}

function MWJ_say_Caps(oC, cis) {
  if(oC) {
    var elem = document.getElementById('caps'+cis);
    if(elem) {
      elem.innerHTML='&nbsp;&nbsp;!&nbsp;&nbsp;';
    }
  }
}

function hidecaps(cis) {
  var elem = document.getElementById('caps'+cis);
  if(elem) {
    elem.innerHTML='';
  }
}

// Ctrl + Enter - odeslani formulare
function KeyRet(e, cis) {
  var kod;
  var ctrl=false;
  if (!e) var e=window.event;
  if (e.ctrlKey) { ctrl=true; }
  if (e.keyCode) { 
    kod=e.keyCode; 
  } else {
    if (e.which) {
      kod=e.which;
    }
  }
  if (kod==10 || (ctrl && kod==13)) {
    if(cis==1) { document.hlclub1.hlsend_send_post.click(); } // klub
    if(cis==2) { document.hlmail.hlsend_send_mail.click(); } // posta
    if(cis==3) { document.hlfriend.hlsend_add_friend.click(); } // pratele
    if(cis==4) { document.hlmemo.hlsend_add_memo.click(); } // memo
  }
}

// Pokud na strance stiskneme ESC tak zavri bublinu
function getESC(e) {
  var kC = (window.event) ? event.keyCode : e.keyCode;
  var Esc = (window.event) ? 27 : e.DOM_VK_ESCAPE;
  if(kC==Esc) { hl_buble_kill(); }
}

function setCursorPosition(field, caretPos) {
//    var elem = document.getElementsByName(field);
    var elem = field;

    if(elem != null) {
      if (elem.setSelectionRange) { 
        elem.focus(); 
        elem.setSelectionRange(caretPos, caretPos); 
      } else { 
        if(elem.createTextRange) {
          var range = elem.createTextRange();
          range.move('character', caretPos);
          range.select();
        } else {
          if(elem.selectionStart) {
            elem.focus();
            elem.setSelectionRange(caretPos, caretPos);
          } else {
            elem.focus();
          }
        }
      }
    }
}

function reply(nick, a1, datum) {
  document.hlclub1.hlpost_text.focus();
  if(document.hlclub1.hlpost_text.value) {
    document.hlclub1.hlpost_text.value=document.hlclub1.hlpost_text.value+" <b>"+nick+"</b> [ GOTOREPLY:"+a1+";"+datum+" ]: ";
  } else {
    document.hlclub1.hlpost_text.value=document.hlclub1.hlpost_text.value+"<b>"+nick+"</b> [ GOTOREPLY:"+a1+";"+datum+" ]: ";
  }
  window.location = "#hl-top";
  document.hlclub1.hlpost_text.focus();
  setCursorPosition(document.hlclub1.hlpost_text, document.hlclub1.hlpost_text.value.length);
}

function link(a1) {
  document.hlclub1.hlpost_text.focus();
  if(document.hlclub1.hlpost_text.value) {
    document.hlclub1.hlpost_text.value=document.hlclub1.hlpost_text.value+" GOTOPR:"+a1+" ";
  } else {
    document.hlclub1.hlpost_text.value=document.hlclub1.hlpost_text.value+"GOTOPR:"+a1+" ";
  }
  window.location = "#hl-top";
  document.hlclub1.hlpost_text.focus();
  setCursorPosition(document.hlclub1.hlpost_text, document.hlclub1.hlpost_text.value.length);
}

function add_smile(what, kam) {
  if(kam==1) {
    document.hlclub1.hlpost_text.focus();
    document.hlclub1.hlpost_text.value=document.hlclub1.hlpost_text.value+what+" ";
    document.hlclub1.hlpost_text.focus();
  } else {
    document.hlmail.hlmail_text.focus();
    document.hlmail.hlmail_text.value=document.hlmail.hlmail_text.value+what+" ";
    document.hlmail.hlmail_text.focus();
  }
}

function dReply(reply_text) {
  if(document.mainForm.text) {
    document.mainForm.text.focus();
    document.mainForm.text.value+=reply_text;
  }
}

function sms(form) {
  x=form.fastsms.selectedIndex;
  if (x>0) {
    adresa="http://"+form.fastsms.options[x].value;
    window.open(adresa,"_blank");
  }
}

function ClearICO() {
  document.getElementsByName("proiko").item(0).src="images/noikonka.gif";
  document.hlmail.hlsend_send_mail.disabled=false;
  if(iconka=="") { document.hlmail.hlsend_send_mail.disabled=true; }
}

function ChngProIko(images) {
//  if(images) {
    var iconka=document.hlmail.hlmail_pro.value.toLowerCase();
    var adr=iconka.charAt(0);
    img=document.getElementsByName("proiko").item(0).src="images/ikons/"+adr+"/"+iconka+".gif";
//  }
  document.hlmail.hlsend_send_mail.disabled=false;
  if(iconka=="") { document.hlmail.hlsend_send_mail.disabled=true; }
}

function mailto(prokoho, idm, datum, img, nefokus) {
  document.hlmail.hlmail_pro.value=prokoho;
  if((idm>0) && (idm!=null) && (datum!=null)) {
    document.hlmail.hlmail_text.value=document.hlmail.hlmail_text.value+"[ MREPLY:"+idm+";"+datum+" ]: ";
  }
  ChngProIko(!img);
  if(nefokus==0) {
    window.location = "#hl-top";
    document.hlmail.hlmail_text.focus();
    setCursorPosition(document.hlmail.hlmail_text, document.hlmail.hlmail_text.value.length);
  }
}

function editfr(koho, popis, img) {
  document.hlfriend.hlfriend_add.value=koho;
  document.hlfriend.hlfriend_text.value=popis;
  changeFriend(!img);
  document.hlfriend.hlfriend_text.focus();
}

function findObject(id) {
	if(document.getElementById)
		return document.getElementById(id);
	if(document.all)
		return document.all[id];
	return { style: {} };
}

function expandIt(objId) {
 	var obj = findObject(objId);
	obj.style.display = (obj.style.display == "none" ) ? "" : "none";
}

// NEW PRISPEVKY


var JumpToNew = true; // skoci na prvni neprecteny prispevek po nahrani stranky
var ShowNewCounter = false; // Zobrazi celkovy pocet novych prispevku po nacteni klubu
var NewCounterTimeout = 2500; // Určuje počet milisekund, po kterych ukazatel poctu novych zmizi.

// zmena Prijemce mailu
function gotoMail(obj) {
  document.hlmailto.hlzmena.value=true;
  document.hlmailto.hlmail_pro.value=obj.options[obj.selectedIndex].value;
  document.hlmailto.submit();
}

// zmena URL pomoci Fast Menu
function gotoURL(obj) {
  page = obj.options[obj.selectedIndex].value; 
  if(page!='nourl') { 
    window.location.href=page
  }
}

// zmena URL pomoci Fast Menu
function gotoPAGE(url) {
  if(url!='') { 
    window.location.href=url;
  }
}

// zmena pritele
function changeFriend(images) {
//  if(images) {
    var iconka=document.hlfriend.hlfriend_add.value.toLowerCase();
    var adr=iconka.charAt(0);
    document.getElementsByName("proiko").item(0).src="images/ikons/"+adr+"/"+iconka+".gif";
//  }
  document.hlfriend.hlsend_add_friend.disabled=false;
  if(iconka=="") { document.hlfriend.hlsend_add_friend.disabled=true; }
}

// zmena Prijemce mailu
function changeMailPro() {
  document.hlmail.hlzmena.value=true;
  document.hlmail.submit();
}

// zmena Pritele na mail prijemce
function changeMailfr() {
  current = document.hlmail.hlmail_fr.selectedIndex;
  if(current>0) {
    document.hlmail.hlmail_pro.value = document.hlmail.hlmail_fr[current].text;
    ChngProIko();
  }
}

// zmena RPG postavy
function changeRPG() {
  adresar = "images/characters/";
  current = document.hlrpg.hlchar.selectedIndex;
  document.images.postavaimg.src = adresar+document.hlrpg.hlchar[current].value+".gif";
  document.images.postavaimg.title = document.hlrpg.hlchar[current].text;
}

// zmena Rodoveho erbu
function changeERB() {
  adresar = "images/erby/";
  current = document.hlrod.hlerb.selectedIndex;
  document.images.erbimg.src = adresar+document.hlrod.hlerb[current].value+".gif";
  document.images.erbimg.title = document.hlrod.hlerb[current].text;
}

// vyber vsech checkboxu ve formulari
function selectAll(theElement) {
  var theForm = theElement.form, z = 0;
  for(z=0; z<theForm.length;z++){
    if(theForm[z].type == 'checkbox'){
      theForm[z].checked = !theForm[z].checked;
    }
  }
}

// funkce na opravu chyby zobrazovani objektu v IE
function ie_fix(obj) {
  var el = document.getElementById(obj);
	el.style.display = 'none';
	el.style.display = 'block';
}

// obsluha tooltipu
var sto_handler = null;
var obj1 = null;
var obj2 = null;
var savvel = null;

// Menu user podsebe
function showTooltip(name) {
  obj1=document.getElementById('info');
  savvel=obj1.style.width;
  obj1.style.width = '';
  obj2=document.getElementById(name);
  obj2.style.display = 'block';
}
// Menu user v radku pro minimalizovane menu
function showTooltipi(name) {
  obj1=document.getElementById('info');
  savvel=obj1.style.width;
  obj1.style.width = '';
  obj2=document.getElementById(name);
  obj2.style.display = 'inline';
}
function hideTooltip(name) {
  obj1=document.getElementById('info');
  obj1.style.width = '';
  obj2=document.getElementById(name);
  obj2.style.display = 'none';
}

// Prevod ceskych znaku na UTF8
function uprava_retezec_utf(text) {
  var zn,retezec="";
  for (var i=0; i<text.length;++i) {
    zn=text.charAt(i);
    if(zn==' ') zn = "+";
    else zn = encodeURIComponent(zn);
    retezec += zn;
  }
  return retezec;
}

// Uklada rozepsane veci - TEXTAREA
function hlSave(obj, cis, id) {
  var txt=uprava_retezec_utf(obj.value);
//  var txt=escape(obj.value);
  if(id>0) {
    var url="hlgetpost.php?sets=1&cis="+cis+"&kl="+id+"&data="+txt;
  } else {
    var url="hlgetpost.php?sets=1&cis="+cis+"&data="+txt;
  }
  if(window.ActiveXObject) {
    httpRequest=new ActiveXObject("Microsoft.XMLHTTP");
  } else {
    httpRequest=new XMLHttpRequest();
  }
  httpRequest.open("GET", url, true);
  httpRequest.onreadystatechange= function () { processRequest(jak); } ;
  httpRequest.send(null);
}

function show_kat(ido, ids) {
  var obj = document.getElementById(ido);
 	if(obj==null) {
 	
 	} else {
    stav=obj.style.display;
    if(stav=='block') {
      obj.style.display='none';
    } else {
      obj.style.display='block';
    }
  }
}

function button_odpocet(butid, txt) {
  odp_time=odp_time-1;
  tl=document.getElementById(butid);
  if(odp_time>0) {
    tl.value=txt+' ('+odp_time+')';
//    tl.disabled=true;
  } else {
    clearInterval(timer_but);
    odp_time=0;
    tl.value=txt;
//    tl.disabled=false;
  }
}

/* Funkce ktera nastavi odpocet na tlacitko odeslat prispevek */
function button_enable(butid, val, st_val) {
  odp_time=st_val;
  tl=document.getElementById(butid);
  tl.value=val+' ('+odp_time+')';
  timer_but=setInterval("button_odpocet('"+butid+"','"+val+"');", 1000);
}

// Vypina / zapina vyber kategorii pro klub pokud je docasny / normal
function dis_sekce(sender) {
  target=document.getElementById('hlsekce');
  if(target!=null) {
    target.disabled = sender.checked;
  }
}

// Funkce nastaveuj COOKIES
function hlCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	} else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

// Funkce zobrazuje / skryva input pro prilohu
function zobraz_prilohu() {
  obj = document.getElementById('win-priloha');
  if(obj.style.visibility=="visible") {
    obj.style.visibility = "hidden";
    obj.style.display = "none";
  } else {
    obj.style.visibility = "visible";
    obj.style.display = "block";
  }
}

// Zavre okno s prilohou
function priloha_ok() {
  obj = document.getElementById('win-priloha');
  if(obj!="null") {
    obj.style.visibility = "hidden";
    obj.style.display = "none";
  }
}

// Zavre okno s prilohou a nuluje soubor
function priloha_cancel() {
  obj = document.getElementById('win-priloha');
  inp = document.getElementById('hlpriloha');
  if(obj!="null") {
    obj.style.visibility = "hidden";
    obj.style.display = "none";
    inp.value='';
  }
}

var IE = document.all ? true : false;
document.onkeypress = getESC;
if (document.layers) document.captureEvents(Event.KEYPRESS);

function block_menu() {
  if(hl_buble_visible==true) {
  	hl_buble_aV[STICKY] = true;
		hl_buble_iState &= ~0x4;
    return false;
  } else {
    return true;
  }
}

document.oncontextmenu=block_menu;
window.oncontextmenu = block_menu;