// JavaScript Document by Matej Tomčík
// All rights reserved
// Copyright © Matej Tomčík
// Start of JavaScript
function changeLangIcon(id,lg,to){
  var id, lg;
  if(to=="2"){
    document.getElementById(id).src = "siteimages/lang_" + lg + "2.png";
  }
  if(to=="1"){
    document.getElementById(id).src = "siteimages/lang_" + lg + ".png";
  }
}

function changeArrow(mousePosition,blueORgreen,elementBI){

var blue_arrow1="siteimages/blue_arrow.gif";
var blue_arrow2="siteimages/blue_arrow_over.gif";
var green_arrow1="siteimages/green_arrow.gif";
var green_arrow2="siteimages/green_arrow_over.gif";
var orange_arrow1="siteimages/orange_arrow.gif";
var orange_arrow2="siteimages/orange_arrow_over.gif";

  if(blueORgreen=="blue"){
    if(mousePosition=="mouseDown"){
    document.getElementById(elementBI).src = blue_arrow2;
    }
    if(mousePosition=="mouseUp"){
    document.getElementById(elementBI).src = blue_arrow1;
    }
    if(mousePosition=="mouseOut"){
    document.getElementById(elementBI).src = blue_arrow1;
    }
  }
  if(blueORgreen=="green"){
    if(mousePosition=="mouseDown"){
    document.getElementById(elementBI).src = green_arrow2;
    }
    if(mousePosition=="mouseUp"){
    document.getElementById(elementBI).src = green_arrow1;
    }
    if(mousePosition=="mouseOut"){
    document.getElementById(elementBI).src = green_arrow1;
    }
  }
  if(blueORgreen=="orange"){
    if(mousePosition=="mouseDown"){
    document.getElementById(elementBI).src = orange_arrow2;
    }
    if(mousePosition=="mouseUp"){
    document.getElementById(elementBI).src = orange_arrow1;
    }
    if(mousePosition=="mouseOut"){
    document.getElementById(elementBI).src = orange_arrow1;
    }
  }
}

function pushImage(imageId,mousePos,main,exp){
  var imageId,mousePos,main,exp;
  switch(mousePos){
    case 'over':
      document.getElementById(imageId).src = main + '.' + exp;
    break;
    case 'down':
      document.getElementById(imageId).src = main + '_down.' + exp;
    break;
  }
}
  
function openSite(name, url, left, top, width, height, toolbar, menubar, statusbar, scrollbar, resizable, fullscreen)
{
  toolbar_str = toolbar ? 'yes' : 'no';
  menubar_str = menubar ? 'yes' : 'no';
  statusbar_str = statusbar ? 'yes' : 'no';
  scrollbar_str = scrollbar ? 'yes' : 'no';
  resizable_str = resizable ? 'yes' : 'no';
  fullscreen_str = fullscreen ? 'yes' : 'no';
  window.open(url, name, 'left='+left+',top='+top+',width='+width+',height='+height+',toolbar='+toolbar_str+',menubar='+menubar_str+',status='+statusbar_str+',scrollbars='+scrollbar_str+',resizable='+resizable_str+',fullscreen='+fullscreen_str+',location=no,personalbar=no');
}

function showCalledWindow(name){
  var name;
  if(name=="shutdown"){
    document.getElementById('shutdownDIV').style.display = "";
  }
}

function accept(withWhat){
  var withWhat;
  if(withWhat=="conditions"){
    document.getElementById('conditions').style.display = 'none';
    document.getElementById('createnewuser').style.display = '';
  }
}
function notAllowedToDownload(){
  window.alert("Na tejto stránke nie ste prihlásený alebo zaregistrovaný.\nProsím prihláste alebo zaregistrujte sa.");
}

function Reset(what){
  var what;
  if(what=="settings"){
    parent.location = 'index.php?show=settings';
  }
  if(what=="usersettings"){
    parent.location = 'users.php';
  }
  if(what=="usersearch"){
    parent.location = 'usersSearch.php';
  }
  if(what=="profileloader"){
    parent.location = 'profile_loader.php';
  }
}

function Disabler(torf){
if(torf){
  document.getElementById('blacklist_delete_ip').disabled = "true";
}else{
  document.getElementById('blacklist_delete_ip').disabled = "";
}
}

function imagePreview(absImageName){
  imgpw = window.open('','imagePreviewWin','left=345, top=280, width=420, height=320, toolbar=0, menubar=0, status=0, scrollbars=1, resizable=0');
  imgpw.document.write('<html><head><title>.:Aloha Image Viewer</title><link rel="stylesheet" type="text/css" href="embed/style_ie.css" /></head>');
  imgpw.document.write('<body bottommargin="0" leftmargin="0" marginheight="0" marginwidth="0" rightmargin="0" topmargin="0"><div class="imgvwtop">' + absImageName + '</div><br />&nbsp;&nbsp;<img src="' + absImageName + '" border="0" alt=" ' + absImageName + '" /><br /><br />&nbsp;&nbsp;<input type="button" class="gwagButton" style="background-image: url(' + "'siteimages/gwagbut.png'" + ');" value="Zavrieť" onClick="javascript:window.close()" /><br /></body></html>');
}

function OpenWindow(name, url, left, top, width, height, toolbar, menubar, statusbar, scrollbar, resizable)
{
  toolbar_str = toolbar ? 'yes' : 'no';
  menubar_str = menubar ? 'yes' : 'no';
  statusbar_str = statusbar ? 'yes' : 'no';
  scrollbar_str = scrollbar ? 'yes' : 'no';
  resizable_str = resizable ? 'yes' : 'no';
  window.open(url, name, 'left='+left+',top='+top+',width='+width+',height='+height+',toolbar='+toolbar_str+',menubar='+menubar_str+',status='+statusbar_str+',scrollbars='+scrollbar_str+',resizable='+resizable_str);
}

function ChangeLangSelector(to){
  var to;
  if(to=="dynamic"){
    document.getElementById('langSelectorDynamic').style.display = '';
    document.getElementById('langSelectorStatic').style.display = 'none';
  }
  if(to=="static"){
    document.getElementById('langSelectorDynamic').style.display = 'none';
    document.getElementById('langSelectorStatic').style.display = '';
  }
}

function ChangeLanguage(url,lang){
  var url, lang;
  var local = url + "?lang=" + lang;
  parent.location = local;
}

function showHelpMsg(hclass){
  var hclass;
  switch(hclass){
    case 'quotes':
      window.alert("Ak si prajete vložiť znak >< tak #[><]");
    break;
    default:
      window.alert("No help for this item");
    break;
  }
}

function createUserWindow(width,height,usePanels){
  var width,height,usePanels,string;
  var ie6 = document.all && document.fireEvent && document.createComment;
  if(usePanels=="no"){
    string = 'toolbar=no,menubar=no,status=no,scrollbars=no,resizable=no';
  }else{
    string = 'toolbar=yes,menubar=yes,status=yes,scrollbars=yes,resizable=yes';
  }
  if(ie6){
    var newwin = window.open("","userwindow",'width='+width+',height='+height+','+string);
    startElements(newwin);
  }else{
    window.alert("Váš internetový prehliadač nepodporuje túto akciu.\n\nERROR: JavaScript compiled for Microsoft Internet Explorer ver. 6");
  }
}

function Show(what){
  switch(what){
    default:
      document.getElementById(what).style.display = '';
    break;
    case "avss_mainscript":
      if(document.getElementById("avss_mscript").style.display==''){
        Hide("avss_mscript");Hide("avss_mscriptt");
        UnBold("but_show_mscript");
        document.getElementById('easc').style.color = '#003399';
        document.getElementById('avss_mse').value = 'false';
      }else{
        con = window.confirm("Pri používaní main scriptu bude dočasne zrušená funkcia\nEasy-Add-Show-Command. Prajete si upraviť main-script súbor?");
        if(con==true){
        document.getElementById("avss_mscript").style.display = '';
        document.getElementById("avss_mscriptt").style.display = '';
        Bold("but_show_mscript");
        document.getElementById('easc').style.color = '#cc0033';
        document.getElementById('avss_mse').value = 'true';
      }
      }
    break;
  }
}

function Hide(what){
  var what;
  document.getElementById(what).style.display = 'none';
}

function Bold(what){
  switch(what){
    default:
      document.getElementById(what).style.fontWeight = 'bold';
    break;
  }
}

function UnBold(what){
  document.getElementById(what).style.fontWeight = 'normal';
}

function showMenu(e,num,curid){
  if(document.getElementById){
    elm=document.getElementById(num)
    if (document.all && !window.opera) {
      x = event.clientX + document.body.scrollLeft + 10;
      y = event.clientY + document.body.scrollTop + 0;  
    }else{
      x = e.pageX + 10;
      y = e.pageY + 0;   
    }
    if (document.all && !window.opera) {
      elm.style.left = x;
      elm.style.top = y;
    }else{
      elm.style.left = x + "px";
      elm.style.top = y + "px";
    }
    elm.style.display = "";
  }
}   

function closeMenu(num){
  if(document.getElementById){
    elm=document.getElementById(num)
    elm.style.display="none";
  }
}

function alrt(why){
  var why;
  if(why=="bl_del"){
    parent.location = 'blacklist.php';
  }
  if(why=="ntd"){
    window.alert("Nothing to do!");
  }
}

function InsertURLIntoComWeb(what){
  var what;
  document.getElementById('comment_web').value = what;
}

function trry(num){
  var num;
  window.alert(num);
}

function rewrite(){
  var data = document.getElementById('sfile').value;
  document.getElementById('soundfile').value = data;
}
function detectWindows(td,em,boa){
  var td, em, boa;
  var index = td.lastIndexOf(em);
  if(index){
    if(boa=="b"){
      var mark = td.substring(0, index).toLowerCase();
    }
    if(boa=="a"){
      var mark = td.substring(index + 1).toLowerCase();
    }
    window.status = mark;
  }
}
function nav(){
  var o,n,v;
  a=navigator.userAgent;
  p=navigator.platform;
  av=navigator.appVersion;
  t=0;
  if(!p.indexOf("Mac"))
  o="mac";
  else if(!p.indexOf("Win"))
  o="win";
  else if(!p.indexOf("Linux"))
  o="linux";
  else o=p;
  if(a.indexOf("Opera")>=0){
  n="opera";
  v=parseFloat(a.substr(a.lastIndexOf("Opera")+6));
  if(v>=7)t=1;
  else	t=2;
  }else if(a.indexOf("MSIE")>0){
  n="msie";
  v=parseFloat(a.substr(a.indexOf("MSIE")+5));
  t=0;
  }else if(a.indexOf("Konqueror")>0){
  n="konqueror";
  v=parseFloat(av);
  t=1 ;
  }else if(a.indexOf("Safari")>0){
  n="safari";
  v=parseFloat(av);
  t=1;
  }else if(a.indexOf("Gecko")>0){
  t=1;
  if(a.indexOf("Netscape")>0)
  n="netscape";
  else n="firefox";
  v=parseInt(navigator.productSub);
  }
}

var oWindow;

function showDialog(sPage, iWidth, iHeight, sT){
  var sTitle;
	var sDialogArgs = "help:no;status:no;dialogHeight:" + iHeight + "px;dialogWidth:" + iWidth + "px";

	if (oWindow != null) oWindow.close();
	sTitle = sT;

	oWindow = showModelessDialog(sPage, sTitle, sDialogArgs);
}

function generateFileName(mainStr, putInto){
  if(mainStr!=""){
  var newstr,other,i;
  j = 0;
  do{
  if(j==0){
  newstr = mainStr.replace("\\","/");
  other = mainStr.substr(mainStr.indexOf("/"));
  }else{
  newstr = newstr.replace("\\","/");
  other = newstr.substr(newstr.indexOf("/"));
  }
  j += 1;
  }while(other.indexOf("\\")>0);
  var msbstr = newstr.substr(newstr.lastIndexOf("/")+1,32);
  if(newstr.substr(newstr.lastIndexOf("/")+1).length>32){
    window.alert("Only 32 chars word are avaiable.\nAloha will edit this filename.");
  }
  if(putInto=="newuser_fptmp"){
    document.getElementById(putInto).value = newstr;
  }else if(putInto=="nd_filename"){
    document.getElementById(putInto).value = newstr;
  }else{
    document.getElementById(putInto).value = msbstr;
  }
  }
}

function checkAllowedExpression(fpath,dtid,utid){
  if(fpath!=""){
  var i,j;
  j = 0;
  var allowed_exp = new Array("bmp","png","jpg","jpeg","gif");
  var lastRpos = fpath.lastIndexOf("/");
  var fname = fpath.substr(lastRpos + 1);
  var expr = fname.substr(fname.lastIndexOf(".")+1);
  for(i=0;i<allowed_exp.length;i+=1){
    if(expr.toLowerCase()==allowed_exp[i]){
      j += 1;
    }
  }
  if(j!=1){
    window.alert("Nesprávny formát alebo prípona súboru.");
    document.getElementById(utid).value = "";
    return false;
  }
  }
}

function tty(fn,sn,tn){
  //fn - first number
  //sn - second number
  //tn - third number
  var fn,sn,tn;
  var fm,sm,tm;
  var fip,sip,tip;
  var ivof,ivos,ivot;
  var op,all,aip;
  fm = eval(fn);
  sm = eval(sn);
  tm = eval(tn);
  all = fm+sm+tm;
  op = all/100;
  fip = fm/op;
  sip = sm/op;
  tip = tm/op;
  //ivof - first number in procent
  //ivos - second number in procent
  //ivot - third number in procent
  //ivoa - ivof and ivos and ivot in procent
  ivof = fip.toFixed(3);
  ivos = sip.toFixed(3);
  ivot = tip.toFixed(3);
  ivoa = eval(ivof) + eval(ivos) + eval(ivot) + " %";
  window.alert("~ " + ivof + " %\n~ " + ivos + " %\n~ " + ivot + " %\n\n~ " + ivoa);
}

function isPin(what){
  var norsValue = document.getElementById(what).value;
  testWith = /^[0-9]{4,8}$/;
  tbr = testWith.test(norsValue);
  return tbr;
}

function checkIP(sta){
  var iptpl,ps,stt,sta,dt;
  stt = document.getElementById(sta).value;
  iptpl = /^[0-9]+.[0-9]+.[0-9]+.[0-9]{1,3}$/;
  ps = stt;
  dt = iptpl.test(ps);
  if(!dt){
    window.alert("Cannot add this IP adress: " + stt + "\n\nThe format of this adress is not valid!")
    document.getElementById('blacklist_entry').value = "false";
  }
}

function checkLoginExists(checkFrom){
  var login = document.getElementById(checkFrom).value;
  if(login!=""){
  OpenWindow('searchUser', 'usersSearch.php?do=check&login=' + login, 307, 220, 415, 305, 0, 0, 0, 1, 0);
  }
}

function checkSelected(list_a){
  var list_a,selectedValue,chckd;
  selectedValue = document.getElementById(list_a).value;
  chckd = document.getElementById('blacklist_delete_all_true').checked;
  if(selectedValue=="none" && chckd!=true){
    window.alert("Select an item first.")
    document.getElementById('blacklist_entry').value = "false";
  }
}

function ClearTextarea(textareaid){
  document.getElementById(textareaid).value = "";
}

function doWithArticle(wtd){
  var wtd;
  switch(wtd){
    case "add":
      parent.location = "articles.php?show=addart";
    break;
    case "edit":
      parent.location = "articles.php?show=edit";
    break;
    case "remove":
      parent.location = "articles.php?show=remart";
    break;
  }
} 

function checkChars(){
  var perex = document.getElementById('na_perex');
  var pnum = document.getElementById('perexchnum');
  var article = document.getElementById('na_article');
  var anum = document.getElementById('artchnum');
  var perexNNE = document.getElementById('perex_nne');
  var perexNNEATT = document.getElementById('perex_nne_att');
  var articleNNE = document.getElementById('article_nne');
  var articleNNEATT = document.getElementById('article_nne_att');
  var max = new Array('255','65535');
  var alert = new Array('50','1000');
  pnum.innerHTML = max[0] - perex.value.length;
  anum.innerHTML = max[1] - article.value.length;
  if(perex.value.length>max[0]){
    window.alert("Not enought chars for perex\nMax-" + max[0] + " Used-" + perex.value.length);
    perex.value = perex.value.substring(0, max[0]);
    pnum.innerHTML = max[0] - perex.value.length;
  }
  if(article.value.length>max[1]){
    window.alert("Not enought chars for article\nMax-" + max[1] + " Used-" + article.value.length);
    article.value = article.value.substring(0, max[1]);;
    anum.innerHTML = max[1] - article.value.length;
  }
  if(perex.value.length>=(max[0] - alert[0])){
    perexNNE.style.display = '';
    perexNNEATT.innerHTML = max[0] - perex.value.length;
  }else{
    perexNNE.style.display = 'none';
    perexNNEATT.innerHTML = max[0] - perex.value.length;
  }
  if(article.value.length>=(max[1] - alert[1])){
    articleNNE.style.display = '';
    articleNNEATT.innerHTML = max[1] - article.value.length;
  }else{
    articleNNE.style.display = 'none';
    articleNNEATT.innerHTML = max[1] - article.value.length;
  }
}

function reportFile(strnm,to,rewrite,useCaret){
  try{
  if(useCaret!=true){
  if(rewrite==true){
    opener.document.getElementById(to).value = strnm;
  }else{
    opener.document.getElementById(to).value += strnm;
  }
  opener.focus();
  opener.document.getElementById(to).focus();
  }else{
  AddToTextareaByWinOpen(to,strnm);
  }
  window.close();
  }
  catch(e){
    window.alert("Chyba\n" + e.description);
  }
}

function statusOnLoad(){
  window.status = 'Welcome to the .:Aloha website';
}

function onLoadFocus(docid){
  document.getElementById(docid).focus();
}

function AvssCheckType(selected){
  if(selected!="ifile"){ document.getElementById('ifile').style.display = 'none';} else {document.getElementById('ifile').style.display = '';}
  if(selected!="contoser"){ document.getElementById('contoser').style.display = 'none';} else {document.getElementById('contoser').style.display = '';}
  if(selected!="runphpf"){ document.getElementById('runphpf').style.display = 'none';document.getElementById('runphpff').style.display = 'none';} else {document.getElementById('runphpf').style.display = '';document.getElementById('runphpff').style.display = '';}
  if(selected!="runjsf"){ document.getElementById('runjsf').style.display = 'none';document.getElementById('runjsff').style.display = 'none';} else {document.getElementById('runjsf').style.display = '';document.getElementById('runjsff').style.display = '';}
}

function AddToTextarea(textareaid,what) {
	var txtarea = document.getElementById(textareaid);
	text = what;
	if (txtarea.createTextRange && txtarea.caretPos) {
		var caretPos = txtarea.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? caretPos.text + text + ' ' : caretPos.text + text;
		txtarea.focus();
	} else {
		txtarea.value += text;
		txtarea.focus();
	}
}

function AddToTextareaByWinOpen(textareaid,what) {
	var txtarea = opener.document.getElementById(textareaid);
	text = what;
	if (txtarea.createTextRange && txtarea.caretPos) {
		var caretPos = txtarea.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? caretPos.text + text + ' ' : caretPos.text + text;
		txtarea.focus();
	} else {
		txtarea.value += text;
		txtarea.focus();
	}
}

function writeSelectedImage(){
  var woi = (document.getElementById('imgbrow_soe').checked) ? 'soe' : (document.getElementById('imgbrow_uts').checked) ? 'uts' : 'ioi';
  switch (woi){
    case 'soe':
      var imgf = document.getElementById('imgbrow_select').value;
      if(imgf!="" && imgf!="none"){
        var imageString = " [img]images/" + imgf + "[/img] ";
        AddToTextareaByWinOpen('na_article',imageString);
        window.close();
      }
    break;
    case 'uts':
      var imgf = document.getElementById('').value;
      if(imgf!=""){
        var imageString = "[img]images/" + imgf + "[/img]";
      }
    break;
  }
}

function checkCharInText(textid,charC,formEntryName){
  var textid,charC,formEntryName,goOut;
  var whereTF = document.getElementById(textid).value;
  if(charC=="quote"){
    charC = '"';
  }
  if(whereTF.indexOf(charC)>-1){
    goOut = true;
  }else{
    goOut = false;
  }
  if(formEntryName!="empty"){
    if(document.getElementById(formEntryName)){
      if(goOut==true){
        document.getElementById(formEntryName).value = "false";
      }else{
        document.getElementById(formEntryName).value = "true";
      }
    }
  }
  if(goOut==true){
    window.alert("Text nesmie obsahovať tento znak: " + charC);
  }
}

function checkICQpartNum(pointer,val){
  var pointer,val,icqnum,acc,icqacc;
  switch (pointer){
    case 'reguser_icqn1':
      if(val.length==3){
        document.getElementById('reguser_icqn2').focus();
      }
    break;
    case 'reguser_icqn2':
      if(val.length==3){
        document.getElementById('reguser_icqn3').focus();
      }
    break;
    case 'setus_icqn1':
      if(val.length==3){
        document.getElementById('setus_icqn2').focus();
      }
    break;
    case 'setus_icqn2':
      if(val.length==3){
        document.getElementById('setus_icqn3').focus();
      }
    break;
    case 'reguser_icqn3':
      if(val.length==3){
        icqnum = document.getElementById('reguser_icqn1').value + document.getElementById('reguser_icqn2').value + document.getElementById('reguser_icqn3').value;
        acc = /^[0-9]{9,9}$/;
        icqacc = acc.test(icqnum);
        if(!icqacc){
          window.alert("This is not valid ICQ number\n\nThe right format is xxx-xxx-xxx\nwhere x variable is a number.");
          document.getElementById('reguser_icqn1').value = '';
          document.getElementById('reguser_icqn2').value = '';
          document.getElementById('reguser_icqn3').value = '';
          document.getElementById('reguser_icqn1').focus();
        }
      }
    break;
    case 'setus_icqn3':
      if(val.length==3){
        icqnum = document.getElementById('setus_icqn1').value + document.getElementById('setus_icqn2').value + document.getElementById('setus_icqn3').value;
        acc = /^[0-9]{9,9}$/;
        icqacc = acc.test(icqnum);
        if(!icqacc){
          window.alert("This is not valid ICQ number\n\nThe right format is xxx-xxx-xxx\nwhere x variable is a number.");
          document.getElementById('setus_icqn1').value = '';
          document.getElementById('setus_icqn2').value = '';
          document.getElementById('setus_icqn3').value = '';
          document.getElementById('setus_icqn1').focus();
        }
      }
    break;  }
}

function viewFacePhotoNDC(){
  document.getElementById('userphotoview').src = "file:///" + document.getElementById('newuser_facephoto').value;
  window.alert(document.getElementById('newuser_facephoto').value);
}

function deleteUserConfirm(){
  var delcon = window.confirm("Naozaj si prajete zmazať všetky vaše údaje\nz databázy stránky Aloha?");
  if(delcon==true){
    parent.location = 'users.php?show=deluser';
  }else{
    return false;
  }
}

function checkMSNAdress(){
  var msndomain;
  var email = document.getElementById('reguser_email').value;
  var np = document.getElementById('reguser_netpassport').value;
  if(np==""){
  msndomain_no = /^[_a-zA-Z0-9\.\-]+@msn.[_a-zA-Z0-9\.\-]{2,3}$/;
  msndomain_ns = /^[_a-zA-Z0-9\.\-]+@hotmail.[_a-zA-Z0-9\.\-]{2,3}$/;
  uqo_no = msndomain_no.test(email);
  uqo_ns = msndomain_ns.test(email);
  if(uqo_no || uqo_ns){
    ques = window.confirm("The e-mail adress that you typed is valid with\n.NET Passport which is using by Hotmail, MSN, Windows Live, ...\nDo you want to place this adress to MSN (Hotmail) data?");
    if(ques){
      document.getElementById('reguser_netpassport').value = email;
    }
  }
  }
}

function gotoWithCursor(where){
  if(document.getElementById(where)){
  document.getElementById(where).focus();
  }
}

function storeCaret(textEl) {
	if (textEl.createTextRange) textEl.caretPos = document.selection.createRange().duplicate();
}

function changeSelectedIB(toselect){
  document.getElementById(toselect).checked = 'checked';
}

function showSelectedImage(){
  var imgbrs = document.getElementById('imgbrw_thumb');
  var woi = (document.getElementById('imgbrow_soe').checked) ? 'soe' : 'ioi';
  switch (woi){
    case 'soe':
      if(document.getElementById('imgbrow_select').value!="none")
      imgbrs.src = "images/" + document.getElementById('imgbrow_select').value;
    break;
    case 'ioi':
      imgbrs.src = document.getElementById('imgbrow_io').value;
    break;
  }
}

function setSelectedImage(imgname){
  document.getElementById('imgbrw_thumb').src = "images/" + imgname;
}

function searchForImage(){
  parent.location = 'imgbrow.php?searchfor=' + document.getElementById('imgbrow_search').value;
}

function showCookies(){
    cks = document.cookie.split(";");
    for (i in kukiny){
        document.write(cks[i]);
    }
}

function doCheckForCheckboxes(sum){
if(sum != "")
{
  var itms = sum.split(";");
  if(document.getElementById('email_checkall').checked){
  for(i=0;i<itms.length;i++){
    document.getElementById('email_check_' + itms[i]).checked = 'checked';
  }
  }else{
  for(i=0;i<itms.length;i++){
    document.getElementById('email_check_' + itms[i]).checked = '';
  }
  }
  }
}

function redirWithId(id,adds){
  parent.location = adds + document.getElementById(id).value;
}

function NewDownloadLicenceNewCheck(value){
  if(value=="04"){
    parent.location = 'index.php?show=settings';
  }
}

function doArticle(def){
  parent.location = document.getElementById(def).value;
}

function prepareReload(additions){
  if(additions==""){
    setInterval("javascript:location.reload()",1000);
  }else{
    setInterval("javascript:parent.location='" + additions + "'",1000);
  }
}

function OpenCloseDiv(openerHandle, divHandle){
  if(document.getElementById(openerHandle).src.indexOf("plus") > 0){
    document.getElementById(divHandle).style.display = "";
    document.getElementById(openerHandle).src = "siteimages/minus.png";
  }else{
    document.getElementById(divHandle).style.display = "none";
    document.getElementById(openerHandle).src = "siteimages/plus.png";
  }
}

function openProfileLoader(userId, thisPassword){
  user = document.getElementById(userId);
  password = document.getElementById(thisPassword);
  if(user.value != "" && password.value != ""){
    OpenWindow('profile_loader', 'profile_loader.php?user=' + user.value + '&password=' + password.value + '', 250, 50, 550, 550, 0, 0, 0, 1, 0);
  }else{
    window.alert("You have to type the name of user you want to sign-in and your password!");
  }
}

function switchUserAction(user_name_id,user_pass_id){
  var user_name_id;
  var user_pass_id;
  meno = document.getElementById(user_name_id);
  heslo = document.getElementById(user_pass_id);
  if(meno.style.display == 'none')
  {
    meno.style.display = '';
    heslo.style.display = 'none';
  }
  else
  {
    meno.style.display = 'none';
    heslo.style.display = '';
  }
}

function InsertTag(type,to)
{
  switch(type)
  {
    case "link":
      var link,target,title,name,compiled;
      link = window.prompt('odkaz na',"http://");
      if(link != null)
      {
        target = window.prompt('cieľ okna',"_blank");
        title = window.prompt('titulok',"");
        name = window.prompt('názov odkazu',"");
        if(name != null)
        {
          compiled = '<a href="' + link + '"' + (target!=null ? (' target="' + target + '"') : "") + (title!=null ? (' title="' + title + '"') : "") + '>' + name + '</a>';
          AddToTextarea(to,compiled);
        }
      }
    break;
    case "image":
      var link,compiled,alt,border;
      link = window.prompt('cesta k obrázku',"http://");
      if(link != null)
      {
        alt = window.prompt('titulok obrázka',"");
        compiled = '<img src="' + link + '" border="0"' + (alt!=null ? (' alt="' + alt + '"') : "") + ' align="left" valign="top" />';
        AddToTextarea(to,compiled);
      }
    break;
    case "kotva":
      var link;
      link = window.prompt('ID kotvy (bez medzier)',"");
      if(link != null)
      {
        compiled = '<div id="' + link + '"></div>';
        AddToTextarea(to,compiled);
      }
    break;
    case "odkaznak":
      var link;
      var temp = separateIDFromLinkH(getSelText()) != null ? separateIDFromLinkH(getSelText()) : getSelText();
      link = window.prompt('ID kotvy (bez medzier)',temp);
      var name = window.prompt('Názov odkazu',"");
      if(link != "" && link != null)
      {
        compiled = '<a href="manual.php#' + link + '">' + name + '</a>';
        AddToTextarea(to,compiled);
      }
    break;
    default:
      window.alert("Nothing to insert");
    break;
  }
}

function controlElements(id)
{
  var text = document.getElementById(id).value;
  var end = false;
  var count = 0;
  var next = 0;
  var ths;
  do
  {
    ths = text.substr(next).indexOf("[%CODE%]");
    if(ths != -1)
    {
      count += 1;
      next = next + ths + 8;
    }
    else
    {
      end = true;
    }
  } while(end == false);
  if(eval(count)/2 - Math.floor(eval(count/2)) == 0)
  {
    return true;
  }
  else
  {
    window.alert("[%CODE%] element must be closed with another [%CODE%] element!");
    return false;
  }
}

function swapCheckboxes(id)
{
  var This = document.getElementById(id);
  var That = document.getElementById(id + "_text");
  if(This.checked == true)
  {
    That.disabled = '';
    That.focus();
  }
  else
  {
    That.disabled = 'disabled';
    This.focus();
  }
}

function Generate32BaitText(to)
{
  var str = "abcdef0123456789";
  var deb = "";
  var i;
  var rnd;
  for(i=0;i<32;i++)
  {
    rnd = Math.floor(Math.random()*str.length-1);
    deb = deb + str.substr(rnd,1);
  }
  document.getElementById(to).value = deb;
}

function GenerateRandText(to)
{
  var str = "abcdefghijklmnopqrstuvwxyz";
  var deb = "";
  var i;
  var rnd;
  for(i=0;i<16;i++)
  {
    rnd = Math.floor(Math.random()*str.length-1);
    deb = deb + str.substr(rnd,1);
  }
  document.getElementById(to).value = deb;
}

function oznam(kde)
{
  document.getElementById(kde).innerHTML = "Nahrávam na stránku...";
}

function getSelText()
{
    var txt = '';
    if (window.getSelection)
    {
        txt = window.getSelection();
    }
    else if (document.getSelection)
    {
        txt = document.getSelection();
    }
    else if (document.selection)
    {
        txt = document.selection.createRange().text;
    }
    else return null;
    return txt;
}

function separateIDFromLinkH(input)
{
  var ret = null;
  if(input.length >= 11)
  {
    if(input.substr(0,9) == "<div id=\"")
    {
      var end = input.substr(9).indexOf("\"");
      if(end != 0)
      {
        ret = input.substr(9).substr(0,end);
      }
    }
  }
  return ret;
}

function Recalculate(bytes,kilobytes)
{
  var valueBytes = document.getElementById(bytes).value;
  var valueKiloBytes = document.getElementById(kilobytes).value;
  document.getElementById(bytes).value = valueKiloBytes*1000;
  document.getElementById(kilobytes).value = valueBytes/1000;
}

function s_checkChars(name,use){
  var perex = document.getElementById(name);
  var perexNNE = document.getElementById(name + '_wrn');
  var perexNNEATT = document.getElementById(name + '_wrn_txt');
  var max = new Array('255','50');
  var alert = new Array('50','20');
  if(perex.value.length>max[use]){
    window.alert("Nedostatok znakov pre príspevok\nMax-" + max[use] + " Použité-" + perex.value.length);
    perex.value = perex.value.substring(0, max[use]);
    perexNNEATT.innerHTML = max[use] - perex.value.length;
    window.setTimeout("s_clearText('" + name + "'," + use + ")",1);
    return false;
  }
  if(perex.value.length>=(max[use] - alert[use])){
    perexNNE.style.display = '';
    perexNNEATT.innerHTML = max[use] - perex.value.length;
    return true;
  }else{
    perexNNE.style.display = 'none';
    perexNNEATT.innerHTML = max[use] - perex.value.length;
    return true;
  }
}

function s_clearText(name,use){
  var perex = document.getElementById(name);
  var perexNNE = document.getElementById(name + '_wrn');
  var perexNNEATT = document.getElementById(name + '_wrn_txt');
  var max = new Array('255','50');
  var alert = new Array('50','20');
  if(perex.value.length>max[use]){
    perex.value = perex.value.substring(0, max[use]);
    perexNNEATT.innerHTML = max[use] - perex.value.length;
  }
}

function changeImage(sourcePath,w,h)
{
  document.getElementById('zoom').src = sourcePath;
  document.getElementById('target').href = sourcePath;
  document.getElementById('zoom').style.width = w;
  document.getElementById('zoom').style.height = h;
}
// End of JavaScript
