function sort_lib_by_name() {
    //include 20902 chinese words, Unicode(19968-40869)
    var strChineseFirstPY = "[encoded data, 20902 characters]";
    var id = $(this).attr('id'), by, other,
        table = $(this).closest('table'),
        repo_items = $('tr:gt(0)', table);

    if (id.indexOf('up') != -1) {
        by = function(a, b) { return a.name.toLowerCase() < b.name.toLowerCase() ? -1 : 1 };
        other = $('#' + id.replace('up', 'down'));
    } else {
        by = function(a, b) { return a.name.toLowerCase() < b.name.toLowerCase() ? 1 : -1 };
        other = $('#' + id.replace('down', 'up'));
    }
    var name_list = [], cn_name_list = [];
    repo_items.each(function() {
        var name = $(this).attr('data-repo_name');
        //get unicode
        var uni = name.charCodeAt(0);
        //not a Chinese character
        if (uni > 40869 || uni < 19968) {
            name_list.push({'name': name, 'element': this});
        } else {
            //get Chinese character's PinYin
            cn_name_list.push({'name': strChineseFirstPY.charAt(uni - 19968), 'element': this});
        }
    });

    name_list.sort(by);
    cn_name_list.sort(by);
    repo_items.detach();

    if (id.indexOf('up') != -1) {
        $(name_list).each(function(index, item) {
            table.append(item.element);
        });
        $(cn_name_list).each(function(index, item) {
            table.append(item.element);
        });
    } else {
        $(cn_name_list).each(function(index, item) {
            table.append(item.element);
        });
        $(name_list).each(function(index, item) {
            table.append(item.element);
        });
    }
    $(this).addClass('hide');
    other.removeClass('hide');
};

function sort_lib_by_time() {
    var id = $(this).attr('id'), by, other, sort_list = [],
        table = $(this).closest('table'),
        repo_items = $('tr:gt(0)', table);

    if (id.indexOf('up') != -1) {
        by = function(a, b) { return a.time < b.time ? -1 : 1 };
        other = $('#' + id.replace('up', 'down'));
    } else {
        by = function(a, b) { return a.time < b.time ? 1 : -1 };
        other = $('#' + id.replace('down', 'up'));
    }

    repo_items.each(function() {
        sort_list.push({'time':$(this).data('time'), 'element':this});
    });

    sort_list.sort(by);

    repo_items.detach();

    $(sort_list).each(function(index, item) {
        table.append(item.element);
    });

    $(this).addClass('hide');
    other.removeClass('hide');
}
