function show(item){  
  $(item).slideDown(200);
}
function toggle(item){  
  if ($(item).is(":hidden")) {
    $(item).show(200);
  }else{
    $(item).hide(200);
  }
}

// nástěnka

function comment_add(id, typ, idforum){
  if(typ == 'hlavni'){
    var textr = $("#text_hlavni").val();
  }
  if(typ == 'reakce'){
    var textr = $("#text_reakce"+id).val();
  }
  if(textr !=""){
  $.ajax({
   type: "GET",
   url: "../komentar.php?action=add",
   dataType: "html",
   contentType: "application/x-www-form-urlencoded;charset=windows-1250",
   data: ({ 'id': id, 'text': textr, 'typ': typ, 'idforum': idforum  }),
   success: function(MessAdder){
      if(typ == 'hlavni'){
        $('#MessageBoard tr:first').before(MessAdder);
      }
      if(typ == 'reakce'){
        $('#MessageBoard tr#id_com'+id+'_c').before(MessAdder);
      }


  if(typ == 'hlavni'){
    $("#text_hlavni").val("");
  }
  if(typ == 'reakce'){
    $("#text_reakce"+id).val("");
  }      
   
   },
   error: function(xhr) {
    alert ("x: "+xhr);
   }
  });//ajax end
  }
}

function like_add(id, typ){
  $.ajax({
   type: "GET",
   url: "../komentar.php?action=like",
   dataType: "html",
   data: ({ 'id': id, 'typ': typ}),
   success: function(MessAdder){
     $('span#liker_box'+id).html(MessAdder);
   },
   error: function(xhr) {
    alert ("Chyba like button");
   }
  });//ajax end
}
function show_all_comments(id, typ, zobrazeno, celkem, idforum, hl, re){
  $("#all_comments_button"+id).hide(1000);
  $("#all_comments_loader"+id).show(1000);
  $.ajax({
   type: "GET",
   url: "../komentar.php?action=load",
   dataType: "html",
   data: ({ 'id': id, 'typ': typ, 'zobrazeno': zobrazeno, 'celkem': celkem, 'idforum': idforum, 'hl': hl, 're': re }),
   success: function(MessAll){
      if(MessAll != ""){
        $('#MessageBoard tr:last').after(MessAll);
      }else{
        $('#MessageBoard tr:last').after('<tr><td colspan="2">Při načítání přízpěvků se vyskytla chyba</td></tr>');
      }
      $("#all_comments"+id).hide(1000);
   },
   error: function(xhr) {
    alert ("Při načítání přízpěvků se vyskytla chyba");
   }
  });//ajax end
}

function show_likes(id, typ){
  if(typ == "1"){$("#likes"+id+"loader").show();}
  if(typ == "0"){$("#unlikes"+id+"loader").show();}
  $.ajax({
   type: "GET",
   url: "../komentar.php?action=showlikes",
   dataType: "html",
   data: ({ 'id': id, 'typ': typ }),
   success: function(MessAll){
    if(typ == "1"){$("#likes"+id).html(MessAll);}
    if(typ == "0"){$("#unlikes"+id).html(MessAll);}
      
    if(typ == "1"){$("#likes"+id+"loader").hide();}
    if(typ == "0"){$("#unlikes"+id+"loader").hide();}
      
   },
   error: function(xhr) {
    alert ("Při načítání přízpěvků se vyskytla chyba");
   }
  });//ajax end
}


function delete_comments(id, typ){
  $("#delit"+id).hide();
  $("#delit_loader"+id).show();
  $.ajax({
   type: "GET",
   url: "../komentar.php?action=delete",
   dataType: "html",
   data: ({ 'id': id, 'typ': typ }),
   success: function(MessAll){
    if(typ == 'hlavni'){
      if(MessAll != ""){   
        var d = MessAll.split("|");
        var reakce = d[1];
        smaz = reakce.split(",");
        for (var i = 1; i < smaz.length; i++) {  
          $('#id_r'+smaz[i]+'_bb').hide(1000);
        } 
        $('#id_com'+id).hide(1000);
        $('#id_com'+id+'_a').hide(1000);
        $('#id_com'+id+'_b').hide(1000);
        $('#id_com'+id+'_bb').hide(1000);
      }
    }
    if(typ == 'reakce'){
      if(MessAll == "OK"){
        $('#id_r'+id+'_bb').slideUp(200);
      }
    }
   },
   error: function(xhr) {
    alert ("Při mazání se vyskytla chyba");
   }
  });//ajax end
}
