﻿var fCallBack;
$(document).ready(function() {
    $("#btnSearch").click(function(e) {
        e.preventDefault();
    })
})
function showLogin() {
    if ($("#dlfancybox").size() == 0) {
        $("body").append('<a id="dlfancybox" href="###"></a>');
    }
    $("a#dlfancybox").addClass("iframe").attr('href', 'http://blog.chinaaet.com/My/poplogin.aspx').fancybox({ 'hideOnContentClick': false, 'overlayShow': false, 'frameWidth': 434, 'frameHeight': 260 }).trigger('click');
}

function closPop(a, b) {
    $("#fancy_outer").hide();
    $.fn.fancybox.close;
    if (typeof fCallBack === 'function')
        fCallBack();
}

function message(msg) {
    $.facebox.settings.fadeout = 2000;
    $.facebox.loading()
    $.facebox.reveal("<span style=\"color:#666666;font-weight:800;\">"+msg+"</span>");
}

function DelPost(postid) {
    if (confirm("确定要删除这篇文章吗?")) {
        $.ajax({
            url: "/ajax.aspx",
            data: "otype=delpost&id=" + postid,
            dataType: "json",
            success: function(data) {
                alert(data.message);
                if (data.isok) { location.href = location.href; }
            }
        })
    }
}

function DelTopic(id) {
    if (confirm('确定要删除此话题吗?')) {
        $.ajax({
            type: "post",
            url: "/ajax.aspx",
            data: "otype=deltopic&id=" + id,
            dataType: "json",
            success: function(data) {
                message(data.message)
                if (data.isok)
                    setTimeout(function() { location.reload(); }, 1000);
            }
        });
    }
}

function SetBest(topicid) {
    $.ajax({
        type: "post",
        url: "/ajax.aspx",
        data: "otype=setbest&id=" + topicid,
        dataType: "json",
        success: function(data) {
            message(data.message);
            if (data.isok)
                setTimeout(function() { location.reload(); }, 1000);
        }
    });
}

function SetTopicTop(topicid, istop) {
    $.ajax({
        type: "post",
        url: "/ajax.aspx",
        data: "otype=settop&istop=" + istop + "&id=" + topicid,
        dataType: "json",
        success: function(data) {
            message(data.message);
            if (data.isok)
                setTimeout(function() { location.reload(); }, 1000);
        }
    });
}

function QuitGroup(groupid) {
    if (confirm("确定要退出本小组?")) {
        $.ajax({
            type: "post",
            url: "/ajax.aspx",
            data: "otype=quitgroup&id=" + groupid,
            dataType: "json",
            success: function(data) {
                message(data.message);
                if (data.isok)
                    setTimeout(function() { location.reload(); }, 1000);
            }
        });
    }
}

function JoinGroup(groupid) {
    $.ajax({
        type: "post",
        url: "/ajax.aspx",
        data: "otype=joingroup&id=" + groupid,
        dataType: "json",
        success: function(data) {
            message(data.message);
            if (data.isok)
                setTimeout(function() { location.reload(); }, 1000);
        }
    });
}

//删除回复
function DelReply(id) {
    if (confirm('确定要删除此评论吗?')) {
        $.ajax({
            type: "post",
            url: "/ajax.aspx",
            data: "otype=delreply&id=" + id,
            dataType: "json",
            success: function(data) {
                message(data.message);
                if (data.isok)
                    setTimeout(function() { location.reload(); }, 1000);
            }
        });
    }
}

function PostReply(id) {
    var uname = '回复:' + $("#div_" + id).find("a.cblue3:first").text();
    var word = $("#div_" + id + " li").eq(1).html();
    var nw = '<fieldset><legend>' + uname + '</legend><div>' + word + '</div></fieldset>';
    $("#reply-text").val(nw);
    CKEDITOR.instances["post-comment-text"].focus();
}

function Search() {  
    var key = document.getElementById("keyword");
    var aim = document.getElementById("search-aid");
    if (key.value != '' && key.value != '请输入关键字') {
        location.href = aim.value + escape(key.value);
    } else {
    alert("请输入关键字");
    key.focus();
    return false;
    }
}     

//$("#post-comment-text").keyup(function() {
//    var text = $(this).val();
//    var len = text.length
//    var info = "";
//    if (len < 200) {
//        info = "还能输入<b>" + (200 - parseInt(len)) + "</b>个字符"
//    } else { info = "你的评论字数已达到上限"; $(this).val(text.substring(0, 200)) }
//    $(this).next(".info").html(info);
//});         
