// JavaScript Document
/****************************************************************************/
/* Funkce na počet znaků do textarea*/
/****************************************************************************/

function progressbar(element,dlzka) {       
        var text;
        var pocet;
        var info1;
        var info2;
        var info3;
        var velkost;
        
        text = document.komentar_pis.komentar_pole.value;
        pocet = text.length;
        if (pocet > dlzka) { document.komentar_pis.komentar_pole.value = text.substr(0,dlzka); }
        velkost = Math.round((pocet * 100) / dlzka);
        document.getElementById(element).style.width = velkost + "%";
        info_1 = "Napsáno: " + pocet + " znaků";
        info_2 = " | Ještě můžete napsat: " + (dlzka - pocet) + " znaků";
        info_3 = " | Zaplnili jste: " + velkost + "%";
        document.getElementById('vypis_komentar_znaku').innerHTML = info_1 + info_2 + info_3;
        window.setTimeout("progressbar('" + element + "','" + dlzka + "')", 10);
}
/****************************************************************************/
/* Vypíše smajla do textarea */
/****************************************************************************/


function napisSmajla(cislo) {
      /*
      
      var range = document.selection.createRange();
      var len = range.text.length;
      range.moveStart('textedit', -1);
      var selectionStart = range.text.length - len;
      
      var or;
      or = text.substr(-selectionStart, document.komentar_pis.komentar_pole.value);
      ar = text.substr(-selectionStart + len, document.komentar_pis.komentar_pole.value);
      document.komentar_pis.komentar_pole.value = or + " *" + cislo + "* " + ar;

      */

    
        var text;
 
        text = document.komentar_pis.komentar_pole.value + " *" + cislo + "* ";
        document.komentar_pis.komentar_pole.value = text;  

}
/****************************************************************************/
/* Zvaliduje forumulář před odesláním */
/****************************************************************************/

function validace(formular) {

        if(formular.nick.value=='') {
        alert('Musíte vyplnit přezdívku');
        formular.nick.focus();
        return false;
        }
        
        else if(formular.pass.value=='') {
        alert('Musíte vyplnit heslo');
        formular.pass.focus();
        return false;
        }
        
        else if(formular.pass2.value != formular.pass.value) {
        alert('Hesla se neshodují');
        formular.pass2.focus();
        return false;
        }
        
        else if(formular.email.value=='') {
        alert('Musíte vyplnit e-mail, na který vám bude posláno potvrzení registrace');
        formular.email.focus();
        return false;
        }
        
        else if(formular.kodol.value=='') {
        alert('Musíte správně opsat kód z obrázku');
        formular.kodol.focus();
        return false;
        }
        
        else if(window.RegExp) {
        re = new RegExp('^.+@.+(\..+)+$');
          if(!re.test(formular.email.value)) {
            alert('Neplatný e-mail');
            formular.email.focus();
            return false;    
          }
        
        
        else
          return true;
        }
      else
        return true;
  
}


/****************************************************************************/
/* Označí všechny neoznačené buňky checkbox ve formulaři */
/****************************************************************************/

function potvrd(co){
            msg = "";
            //obj = document.getElementsByName("hromadneZpravy[]");
            obk = document.getElementsByName("vzkazy_del[]");
            
            k = 0;
            /*for ( var i=0; i<obj.length; i++ ) {
                if (obj[i].checked == true){
                    j++;
                }
            }*/
            for (var i=0; i<obk.length; i++ ) {
                if (obk[i].checked == true){
                    k++;
                }
            }
            switch (co){
                case 1:
                    msg = 'Smazat vybrané vzkazy?';
                    break;
                 case 2:
                    msg = 'Ignorovat vybrané uživatele?';
                    break;
                 
            }
            if (k > 0){
                return confirm(msg);
            } else {
                    alert('Nejsou vybrány žádné vzkazy.');
                return false;
            }
        }
        
        
        function oznac(){
            oznacBox(document.getElementsByName("vzkazy_del[]"));
            //oznacBox(document.getElementsByName("hromadneZpravy[]"));
            document.getElementById("oznacBox").checked = false;
        }
        
        
        function oznacBox(obj)
        {
            for (i=0; i<obj.length; i++) {
                obj[i].checked = !(obj[i].checked);
            }
        }

        function del_msg(num){
          var msg = "";
          switch (num){
                case 1:
                    msg = 'Smazat tento vzkaz?';
                    break;
                 case 2:
                    msg = 'Ignorovat tohoto uživatele?';
                    break;
                case 3:
                    msg = 'Schválit tuto fotku?';
                    break;
                case 4:
                    msg = 'Zamítnout tuto fotku?';
                    break;
                case 5:
                    msg = 'Změnit údaje toho uživatele?';
                    break;
                case 6:
                    msg = 'Opravdu chcete vypnout celý server? Po vypnutí serveru bude možné jej opět zapnout pouze přes databázi.';
                    break;
                case 7:
                    msg = 'Smazat tuto fotografii?';
                    break;
                case 8:
                    msg = 'Smazat toto album?';
                    break;
                case 9:
                    msg = 'Schválit toto fórum?';
                    break;
                case 10:
                    msg = 'Zamítnout toto fórum?';
                    break;
                case 11:
                    msg = 'Smazat tuto zprávu?';
                    break;
                case 12:
                    msg = 'Udělit tomuto uživateli zákaz psaní na fórum?';
                    break;
                case 13:
                    msg = 'Povolit tomuto uživateli opět psát na fórum?';
                    break;
                       
          }
                  
          return  confirm(msg);              
        }







     
        function forum_win(w,h,ids) {
           
           var we;
           var he;
           
           we = w*1 + 20;
           he = h*1 + 200;
           
         
           newwin = window.open("./index.php?action=forum&insert=" + ids,"_blank","Toolbar = no, top = 120, left = 120, status = no, menubar = no, scrollbars = yes, width = " + we + ", height = " + he + ", resizable = yes");
       
           return false;
        }
       
        


     
        function forum_rewin(w,h,ids,idk) {
           
           var we;
           var he;
           
           we = w*1 + 20;
           he = h*1 + 200;
           
         
           newwin = window.open("./index.php?action=forum&re=" + ids + "&msg=" + idk,"_blank","Toolbar = no, top = 120, left = 120, status = no, menubar = no, scrollbars = yes, width = " + we + ", height = " + he + ", resizable = yes");
       
           return false;
        }
       
     
        function forum_editwin(w,h,ids,idk) {
           
           var we;
           var he;
           
           we = w*1 + 20;
           he = h*1 + 200;
           
         
           newwin = window.open("./index.php?action=forum&edit=" + ids + "&msg=" + idk,"_blank","Toolbar = no, top = 120, left = 120, status = no, menubar = no, scrollbars = yes, width = " + we + ", height = " + he + ", resizable = yes");
       
           return false;
        }
       
        function open_win(url,w,h,title,made,prew,next,ids) {
           
           var we;
           var he;
           
           we = w*1 + 20;
           he = h*1 + 200;
           
           if(we > 750) {we = 750;}
           if(we < 650) {we = 650;}
           
            
           newwin = window.open("http://www.czechtrams.com/shifter_gallery.php?what=" + ids,"_blank","Toolbar = no, top = 120, left = 120, status = no, menubar = no, scrollbars = yes, width = " + we + ", height = " + he + ", resizable = yes");
       
           
           return false;
        }
       
        
        function close_win() {
          window.close();
        }
    


        function micro(id,max)
        {
        var vis = "micro_" + id;
        var exit = 0;
            
            for(i=1;i<=max;i++)
            {
                var date = "kalendar_td_" + i;
                if(document.getElementById(date).style.backgroundColor=='#a46f42' || document.getElementById(date).style.backgroundColor=='rgb(164, 111, 66)')
                {
                    var exit = 1;
                    break;
                }        
            }
            
            if(exit == 0)
            {    
                for(i=1;i<=max;i++)
                {
                    var end = "micro_" + i;
                    
                    document.getElementById(end).style.display='none';
                }
                document.getElementById(vis).style.display='block';
            }
        }

        // zjistí barvu pozadí objektu
        
        function barva(id)
        {
            var c = document.getElementById("kalendar_td_" + id).style.backgroundColor;
            document.write(c);
        }

        // zafixuje jedno políčko v klanedáři
        function key(id,max)
        {
            
            // jméno objektu
            var names;
            names = "kalendar_td_" + id;
                     
            
            // objekt zamčení
            var obj;
            obj = document.getElementById(names);
            
            
            // nastavení všech zbarvených políček na původní barvu
            
            
            for(i=1;i<=max;i++)
            {
                var end = "kalendar_td_" + i;
                
                var dark = document.getElementById(end);
                
                if(dark.style.backgroundColor != "rgb(49, 49, 49)" && dark.style.backgroundColor != "#313131" && dark != obj)
                {
                    dark.style.backgroundColor = "#353535";
                }
              
              
            }           
            
            
            // změna barvy políčka
            
            /*
            var color = obj.style.backgroundColor;
            document.write(color);
            */
            
            if((obj.style.backgroundColor=="rgb(53, 53, 53)") || (obj.style.backgroundColor=="#353535"))
            {
                obj.style.backgroundColor='#a46f42';
            }
            else
            {
                obj.style.backgroundColor='#353535';
            }
            
            // nastavení viditelnosti kliknutého políčka v akcích
            
                for(i=1;i<=max;i++)
                {
                    var end = "micro_" + i;
                    
                    document.getElementById(end).style.display='none';
                }
                
                document.getElementById("micro_" + id).style.display='block';
            
        }





        function upload(input,div)
        {
        
            var browser = navigator.appName;
            
            if(browser == 'Netscape')
            {   
                   
                re = new RegExp(' ');
                while(re.test(input)) {
                input = input.replace(" ","%20");
                }
                /*
                req = new RegExp('');
                while(req.test(input)) {
                input = input.replace("c","d");
                }
                */
                
          
              //  document.write(input);
              
              
            }
            //document.write(input);
            document.getElementById(div).innerHTML = '<img src=\'' + input + '\' alt=\'\' style=\'width:100px;margin-top:20px;margin-bottom:5px;\' />';
        
        
        }



  
  
  
  
  function stars_up(num)
  {
      
      
      for(i=1;i<=10;i++)
      {
          var starName = "star_" + i;
          if(i<=num)
          {
              document.getElementById(starName).src="http://www.czechtrams.com/data/star2.gif";
          }
          else
          {
              document.getElementById(starName).src="http://www.czechtrams.com/data/star0.gif";
          }
          
      }
  
  }
  
  
    
  function stars_out(num)
  {
      
      
      for(i=1;i<=10;i++)
      {
          var starName = "star_" + i;
          if(i<=num)
          {
              document.getElementById(starName).src="http://www.czechtrams.com/data/star1.gif";
          }
          else
          {
              document.getElementById(starName).src="http://www.czechtrams.com/data/star0.gif";
          }
          
      }
  
  }
  
  
  

  
  
  
  

