function klikz(ids){
	$('.post').css('display', 'none');
	$('#post_'+ids).css('display', '');
}
function gomenu(){
    $('#gomenu').css('display', '');
}

$(document).mouseup(function (e){
    var div = $('.post');
    var div2 = $('#gomenu');
    var div3 = $('#onliuses2');
    if (!div.is(e.target) && div.has(e.target).length === 0) {
        $('.post').fadeOut(1);
    }
    if (!div2.is(e.target) && div2.has(e.target).length === 0) {
        $('#gomenu').fadeOut(1);
    }
    if (!div3.is(e.target) && div3.has(e.target).length === 0) {
        $('#onliuses2').fadeOut(1);
    }
});

$(document).ready(function() {  
    var $result = $('#search_box-result');
    
    $('#search').on('keyup', function(){
        var search = $(this).val();
        if ((search != '') && (search.length > 1)){
            $.ajax({
                type: "POST",
                url: "/ajax/ajax_search.php",
                data: {'search': search},
                success: function(msg){
                    $result.html(msg);
                    if(msg != ''){  
                        $result.fadeIn();
                    } else {
                        $result.fadeOut(100);
                    }
                }
            });
         } else {
            $result.html('');
            $result.fadeOut(100);
         }
    });
 
    $(document).on('click', function(e){
        if (!$(e.target).closest('.search_box').length){
            $result.html('');
            $result.fadeOut(100);
        }
    });
});
function liker(id) {
    $.ajax({
        url: "/ajax/likers.php", 
        type: 'POST', 
        data: {likes: 'like',id: id}, 
        cache: false, 
        success: function(html) {
            obj = jQuery.parseJSON(html); 
            $('#diz_'+id).removeClass('lisss');
            if (obj.type == 'success') {
                $('#liker_'+id).html(obj.colik); 
                if(obj.dell == 0){
                    $('#lik_'+id).addClass('lisss');
                }else{
                    $('#lik_'+id).removeClass('lisss');
                }
            }else{
                alert(obj.message);
            }
        } 
    }); 
}
function dezliker(id) {
    $.ajax({
        url: "/ajax/likers.php", 
        type: 'POST', 
        data: {likes: 'dezlike',id: id}, 
        cache: false, 
        success: function(html) {
            obj = jQuery.parseJSON(html); 
            if (obj.type == 'success') {
                $('#lik_'+id).removeClass('lisss');
                $('#liker_'+id).html(obj.colik); 
                if(obj.dell == 0){
                    $('#diz_'+id).addClass('lisss');
                }else{
                    $('#diz_'+id).removeClass('lisss');
                }
            }else{
                alert(obj.message);
            }
        } 
    }); 
}
function uslink(timer) {
    var vvvod = $('#vvod').val();
    if (vvvod == ''){
        $('.redank10').css('background-color', '');  
    }else{
        $.ajax({
            type: 'POST', 
            url: '/ajax/uslink.php', 
            data: { 
                vvod: vvvod
            }, 
            success: function(data) {
                var obj = jQuery.parseJSON(data); 
                if(obj.type == 'success'){
                    $('.redank10').css('background-color', '#e7ffee');
                    $('#savesss').prop('disabled', false);
                }else if(obj.type == 'error'){
                    $('.redank10').css('background-color', '#ffefef');
                    $('#savesss').prop('disabled', true);
                } 
            } 
        }); 
    }
}
function usonl(){
    if ($('#onliuses2').css('display') == 'none'){
        var $result = $('#onliuses2');
        $('#onliuses2').show();
        $.ajax({
            type: "POST",
            url: "/ajax/usonl.php",
            data: {},
            success: function(msg){
                $result.html(msg);
                if(msg != ''){  
                    $result.fadeIn();
                } else {
                    $result.fadeOut();
                }
            }
        });
    } else {
        $('#onliuses2').hide();
    }
}