﻿
function showMessage(obj,str)
{
    $('<div class="quick-alert">'+ str +'</div>')
                    .insertAfter( $(obj) )
                    .fadeIn('slow')
                    .animate({opacity: 1.0}, 1000)
                    .fadeOut('slow', function() {
                        $(this).remove();
                    });
            
}

function SavePdf(pdfid, pdftype, obj)
{
    PdfListController.SavePdf(pdfid,pdftype, function(result){
    showMessage(obj, result);
    });
}

function AddFriend(uid,obj)
{
    UserController.AddFriend(uid, function(result){
        showMessage(obj, result);
    }
    );
}
function Readmsg(id,stat,body)
{
    if(stat == 0)
    {
    $('#b' + id).html("<img src='/Content/images/loading.gif'>");
        MsgController.ReadMsg(id, function(result){
            if  (result != "" && result != null)
            {
                if  ($('#b' + id).html().length < 84)
                    {
                        $('#b' + id).html(result).fadeIn('slow');
                    }
                    else
                    {
                        $('#b' + id).html($('#b' + id).html().substr(0,80)).fadeIn('slow');
                    }
                $('#new' + id).fadeOut('slow', function() {
                            $(this).remove();
                            });
            }
            else if (result == null)
            {
                location.reload();
            }
            else
            {
                $('#b' + id).html("数据读取失败");
            }
        });
    }
    else
    {
        if  ($('#b' + id).html().length < 84)
        {
            $('#b' + id).html(body).fadeIn('slow');
        }
        else
        {
            $('#b' + id).html($('#b' + id).html().substr(0,80)).fadeIn('slow');
        }
    }
}

function DeleteMsg(id, obj)
{
    $('#b' + id).html("<img src='/Content/images/loading.gif'>");
    MsgController.DeleteMsg(id, function(result){
        if (result != null)
        {
            if (result == "true")
            {
                showMessage(obj, "您已成功删除消息！");
                 $(obj).fadeOut('slow', function() {
                        $('#c' + id).remove();
                    });
            }
            else
            {
            showMessage(obj, result);
            } 
        }
        else
        {
            location.reload();
        }
     });
}


function DeleteFriend(id, obj)
{
    UserController.DeleteFriend(id, function(result){
        if (result != null)
        {
            if (result == "true")
            {
            showMessage(obj, "您已成功删除好友！");
            $(obj).fadeOut('slow', function() {
                        $('#l' + id).remove();
                    });
            }
            else
            {
                 showMessage(obj, result);
            }
            
        }
        else
        {
            location.reload();
        }
     });
}


var goto_top_type = -1;
var goto_top_itv = 0;

function goto_top_timer()
{
    var y = goto_top_type == 1 ? document.documentElement.scrollTop : document.body.scrollTop;
    var moveby = 15;

    y -= Math.ceil(y * moveby / 100);
    if (y < 0) {
    y = 0;
    }

    if (goto_top_type == 1) {
    document.documentElement.scrollTop = y;
    }
    else {
    document.body.scrollTop = y;
    }

    if (y == 0) {
    clearInterval(goto_top_itv);
    goto_top_itv = 0;
    }
}

function goto_top()
{
    if (goto_top_itv == 0) {
        if (document.documentElement && document.documentElement.scrollTop) {
            goto_top_type = 1;
        }
        else if (document.body && document.body.scrollTop) {
            goto_top_type = 2;
        }
        else {
            goto_top_type = 0;
        }
        if (goto_top_type > 0) {
            goto_top_itv = setInterval('goto_top_timer()', 30);
        }
    }
}
