window.onload = function(){

	$("#treeview").treeview({
			persist: "location"
     });


     /// vyska okna right ///
     var vyska_l = $("div#left").height();
     var vyska_r = $("div#right").height();
     if(vyska_l > vyska_r) {
          $("div#right").height(vyska_l);
     }     
     //// otevreni odkazu v novem okne //
     $("a.new_window").click(function(){
          window.open(this.href);
          return false;
     });

     //// otevreni odkazu v novem okne z fora //
     $(".treeview .teloLink a").click(function(){
          window.open(this.href);
          return false;
     });

     //// otevreni odkazu v novem okne Odpoved //
     $("a.newWinOdpoved").click(function(){
          window.open(this.href,'_blank','scrollbars=yes,width=700,height=600,menubar=no,toolbar=no,location=no,resizable=yes');
          return false;
     });

     //// Potvrzeni pri mazani //
     $("a").filter(".delete").click(function(){
          return confirm('Chete položku opravdu smazat?');
     });
     //// po kliknuti na reklamu spustit pocitani kliku ////
     $("a").filter(".reklama").click(function(){ 
          var data = this.rel;
          $.ajax({
               type:   "POST",
               url:    "/libs/inzerce_stat.php",
               data:   data
          });
          return false;
     } );

	// po najeti misi ukazu cely text //
	$("a.showUsers").mouseover(function(e){
		$('#ajax').load('/templates/_generated/onlineUsers.php');
		$("#ajax").css('display','block');
		$('#ajax').show();
		$("#ajax").css('top',e.pageY - 100);
		$("#ajax").css('left',e.pageX - 25);
		return false;
	});
	$("#ajax").mouseout(function(){
		$("#ajax").hide();
	});     
     
     //// po najeti misi ukazu cely text ////
     $("td").filter(".showText").mouseover(function(e){ 
          var text = $(this).children("small").attr('title');
          $("#user_img").text(text);
          $("#user_img").show();

     	$("#user_img").css('display','block');                 
     	$("#user_img").css('top',e.pageY + 10);          
     	$("#user_img").css('left',e.pageX - 50);  
          return false;
     } );
    $("td").filter(".showText").mousemove(function(e){
        	$("#user_img").css('top',e.pageY + 10);          
         	$("#user_img").css('left',e.pageX - 50);           
    });        
    $("td").filter(".showText").mouseout(function(){
          $("#user_img").hide();
    }); 

     //// po najeti misi na usra zobraz img ////
     $("a").filter(".show_img").mouseover(function(e){ 
          var data = this.rel;
          $("#user_img").load("/libs/show_user_img.php?data=" + data);
          $("#user_img").show();

     	$("#user_img").css('display','block');          
     	$("#user_img").css('top',e.pageY + 10);          
     	$("#user_img").css('left',e.pageX - 50);  
          return false;
     } );
    $("a").filter(".show_img").mousemove(function(e){
        	$("#user_img").css('top',e.pageY + 10);          
         	$("#user_img").css('left',e.pageX - 50);           
    });        
    $("a").filter(".show_img").mouseout(function(){
          $("#user_img").hide();
          $("#user_img").load("/libs/show_user_img.php");
    }); 

     //// po kliknuti na anketu v threatu se pricte hlas ////
     $("a").filter(".anketa").click(function(){ 
          var url = this.href;
          $.ajax({
               url:    url
          });
          var top_id = this.rel;
          $("#anketa").load("/libs/renew_anketa.php?top_id=" + top_id);
          return false;
     } );

     //// vybrani kategorie pro fotogalerii ////
     $("select.fotoKat").change(function(){ 
          var typ = this.value;
          if(typ == 98){
               $('div#fotoB').css('display','block');
          } else {
               $('div#fotoA').css('display','block');
          }
          $('input#typf').attr('value',typ);

          return false;
     } );
     //// smazani fotky z editace ////
     $("a.fotoDel").click(function(){ 
          var id = this.rel;
          $('input#foto_name_' + id).attr('value','');
          $('div#image_holder_' + id).html('');
          $('input#komentar_' + id).attr('value','');
          return false;
     } );
     
     //// po kliknuti na bookmarky,blokace a zamek zaslat na zpracovani ////
     $("a.set_atr").click(function(){ 
          var url = this.href;

          var src = $("span",this).text();
          var src_pole=src.split('_');
          
          if(src == 'Povolit obsah tohoto příspěvku')     { new_src='Blokovat obsah tohoto příspěvku';  }
          else if(src == 'Blokovat obsah tohoto příspěvku') { new_src='Povolit obsah tohoto příspěvku'; }
                         
          $("span",this).text(new_src);

          if(src_pole[1] == 'off.gif')     { new_src=src_pole[0] + '_on.gif';  }
          else if(src_pole[1] == 'on.gif') { new_src=src_pole[0] + '_off.gif'; } 
          $("img",this).attr('src',new_src);
          
          
          if(this.rel){
               var text_id = this.rel;
               $("div."+text_id+" div").toggleClass("dnone");
          }     

          url_new=this.href.replace(/_on/,'_off');
          if(url_new == url){          
               url_new=this.href.replace(/_off/,'_on');
          }
          this.href=url_new;
          
          $.ajax({
               url:    url
          });
          return false;

     } );


     //// vycentrovat obrazek v sekci NASTAVENI
     var user_width  = $("img").filter(".foto_user").width();
     var user_height = $("img").filter(".foto_user").height();
     var margin_top  = (150-user_height)/2;
     var margin_left = (150-user_width)/2;
     $("img").filter(".foto_user").css('margin-top',margin_top);
     $("img").filter(".foto_user").css('margin-left',margin_left);
    
}

function validate_form(form) {
     for (var i = 0; i < form.elements.length; i++) {
          if (form.elements[i].id.substr(0, 2) == "M_") {
               if (form.elements[i].value == "") {
                    var str = form.elements[i].id.replace(/M_/g, " ");
                    alert("Prosíme vyplňte povinné pole: " + str.replace(/_/g, " "));
                    form.elements[i].focus();
                    return false;
               }
          }
     }
     mail=/^.+@.+\..{2,4}$/
     if(mail.test(document.getElementById('M_E-mail').value)==false && document.getElementById('M_E-mail').value!=''){
          alert("Neplatný e-mail!");
          document.getElementById('M_E-mail').focus();
          return false;
     }
       
     return true;
}

function set_confirm(text,location) {
     if(confirm(text)){
          return true;
     }
     else{
          location.href=location;
          return false;
     }
}
