﻿function commentReady() {
    $('#formComment').submit(function () {

        if ($('#txtContent').text() == "")
            $('#txtContentError').text('请填写内容');
        jQuery.ajax({
            url: "/SumbitComment",
            data: $('#formComment').serialize(),
            type: "POST",
            datatype: "json",
            beforeSend: function () {
                $('#btnSubmit').attr({ "disabled": "disabled" });
                $('#txtContentError').text('');
                $('#formComment').mask("发布中...");
            },
            error: function (request) {
                $('#txtContentError').text('发生一个未知错误,极大可能性是系统挂了.');
                $('#btnSubmit').removeAttr("disabled");
                $("#formComment").unmask();
            },
            success: function (data) {

                $('#btnSubmit').removeAttr("disabled");
                $("#formComment").unmask();

                if (data.result == "true") {
                    $('#txtContent').text(' ');
                    var _t = $('.commentlist').html();
                    $('.commentlist').html(_t + '<li class="comment byuser comment-author-admin bypostauthor even thread-even depth-1"><div class="comment-author vcard">由你刚刚发表,等待核审中...</div><div class="comment-body">' + data.content + '</div></li>');

                }
                else if (data.result == "time") {
                    $('#txtContentError').text('发表过快,还需要等待' + data.content + '秒');
                }
                else if (data.result == "duplicate") {
                    $('#txtContentError').text('请不要多次提交相同内容');
                }
                else {
                    $('#txtContentError').text('请填写内容');
                }

            }
        });
        return false;
    }
    );
}

function vote(id, o, obj) {
    jQuery.ajax({
        url: "/SubmitVote/" + id + "/" + o,
        datatype: "json",
        beforeSend: function () {
            $(obj).text('处理中');
        },
        error: function (request) {
            $(obj).text('失败:(');
        },
        success: function (data) {
            $('#item' + id).unmask();
            if (data.result == "true") {
                $(obj).text(data.votevalue + (o == 1 ? ' 顶' : ' 踩'));
            }
            else {
                $(obj).text((o == 1 ? ' 已顶过' : ' 已踩过'));
            }


        }
    });
}

var main_domain = 'http://www.woleigeca.com';

function getItemTitle() {
    var a = $(".jsitemtitle");
    return a.text();
}
function getItemID() {
    var a = $(".jsitemid");
    return $.trim(a.text());
}
function getItemContent() {
    var a = $(".jsitemcontent");
    return a.text();
}


$(document).ready(function () {
    $(".b_xn").click(function () {

        var a = "http://share.xiaonei.com/share/buttonshare.do?link=" + encodeURIComponent(main_domain + "/" + getItemID()) + "&title=" + encodeURIComponent(getItemTitle());

        if (!window.open(a, "xiaonei", "toolbar=0,resizable=1,scrollbars=yes,status=1,width=626,height=436")) {
            location.href = a
        }
    }),
    $(".b_kx").click(function () {
        var b = getItemTitle();
        var a = "http://www.kaixin001.com/repaste/share.php?rtitle=" + encodeURIComponent(b) + "&rurl=" + encodeURIComponent(main_domain + "/" + getItemID()) + "&rcontent=" + encodeURIComponent( b)
        if (!window.open(a, "kaixin")) {
            location.href = a
        }
    }),

     $(".b_db").click(function () {
         var a = "http://www.douban.com/recommend/?url=" + encodeURIComponent(main_domain + "/" + getItemID()) + "&title=" + encodeURIComponent(getItemTitle());
         if (!window.open(a, "douban", "toolbar=0,resizable=1,scrollbars=yes,status=1,width=450,height=330")) {
             location.href = a
         }
     }),

//     $(".b_qz").click(function () {
//         var a = "http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=" + encodeURIComponent(main_domain + "/" + getItemID);
//         if (!window.open(a, "qzone")) {
//             location.href = a
//         }
//     })

 $(".b_sh").click(function () {
        var a = "http://bai.sohu.com/share/blank/addbutton.do?from=tudou&link=" + main_domain + "/" + getItemID() + "&title=" + getItemTitle();
        if (!window.open(a, "sohu")) {
            location.href = a
        }
    }),
        $(".b_wb").click(function () {
        var c = "http://v.t.sina.com.cn/share/share.php",
            d = {
                c: "spr_web_bd_tudou_weibo",
                url: main_domain + "/" + getItemID(),
                title: getItemTitle(),
                source: "三八婆",
                sourceUrl: "http://www.woleigeca.com/",
                content: "gb2312",
                pic: ""
            },
            b = c + "?" + $.param(d);
        if (!window.open(b, "mb", "toolbar=0,resizable=1,scrollbars=yes,status=1,width=440,height=430,left=" + (screen.width - 440) / 2 + ",top=" + (screen.height - 430) / 2)) {
            location.href = b
        }
    })


});













(function (a) { a.fn.mask = function (c, b) { a(this).each(function () { if (b !== undefined && b > 0) { var d = a(this); d.data("_mask_timeout", setTimeout(function () { a.maskElement(d, c) }, b)) } else { a.maskElement(a(this), c) } }) }; a.fn.unmask = function () { a(this).each(function () { a.unmaskElement(a(this)) }) }; a.fn.isMasked = function () { return this.hasClass("masked") }; a.maskElement = function (d, c) { if (d.data("_mask_timeout") !== undefined) { clearTimeout(d.data("_mask_timeout")); d.removeData("_mask_timeout") } if (d.isMasked()) { a.unmaskElement(d) } if (d.css("position") == "static") { d.addClass("masked-relative") } d.addClass("masked"); var e = a('<div class="loadmask"></div>'); if (navigator.userAgent.toLowerCase().indexOf("msie") > -1) { e.height(d.height() + parseInt(d.css("padding-top")) + parseInt(d.css("padding-bottom"))); e.width(d.width() + parseInt(d.css("padding-left")) + parseInt(d.css("padding-right"))) } if (navigator.userAgent.toLowerCase().indexOf("msie 6") > -1) { d.find("select").addClass("masked-hidden") } d.append(e); if (c !== undefined) { var b = a('<div class="loadmask-msg" style="display:none;"></div>'); b.append("<div>" + c + "</div>"); d.append(b); b.css("top", Math.round(d.height() / 2 - (b.height() - parseInt(b.css("padding-top")) - parseInt(b.css("padding-bottom"))) / 2) + "px"); b.css("left", Math.round(d.width() / 2 - (b.width() - parseInt(b.css("padding-left")) - parseInt(b.css("padding-right"))) / 2) + "px"); b.show() } }; a.unmaskElement = function (b) { if (b.data("_mask_timeout") !== undefined) { clearTimeout(b.data("_mask_timeout")); b.removeData("_mask_timeout") } b.find(".loadmask-msg,.loadmask").remove(); b.removeClass("masked"); b.removeClass("masked-relative"); b.find("select").removeClass("masked-hidden") } })(jQuery);



