﻿function BoxShow(elm, wid, hei) {
    $("<div id=\"mtWins_PaOve\"></div>").appendTo("body").click(function() { $("#mtWins_PaOve,#mtWins_PaBox").remove(); });
    $("<div id=\"mtWins_PaBox\"></div>").appendTo("body").click(function() { $("#mtWins_PaOve,#mtWins_PaBox").remove(); }).css({ width: wid, height: hei, top: $(window).scrollTop() + ($(window).height() - hei) / 2, left: $(window).scrollLeft() + ($(window).width() - wid) / 2 }).append(elm);
}


function InfoViewLnk(idx) {
    $("#ViewLnk").show().addClass("read").html("正在读取联系信息，请稍候……");
    $.get(CombActPath("InfoViewLnk&idx=" + idx), function(txt) { if (IsZero(txt.substr(0, 1))) { $("#ViewLnk").html("读取联系方式失败"); } else { $("#ViewLnk").removeClass("read").html(txt.substr(1, txt.length)); } });
}

function InfoViewFav(idx) {
    $.get(CombActPath("UserPack&kid=1&idx=" + idx), function(txt) {
        switch (parseInt(txt)) { case 1: $("#DoFav").html("取消收藏"); break; case 2: $("#DoFav").html("收藏信息"); break; default: $("#DoFav").html("操作失败"); break; }
    });
}

function InfoMark(idx) {
    var infoText = $("#msTxt").val();
    if (IsNull(infoText)) {
        ShowIdeWarn("msErr", 0, "请输入评论内容");
    } else {
        $.post(CombActPath("InfoMarkAdd"), { nID: idx, nText: infoText, nAlert: $("#msAlert:checked").val() }, function(txt) {
                if (IsZero(txt.substr(0, 1))) {
                    ShowIdeWarn("msErr", 0, txt.substr(1, txt.length));
                } else {
                    window.location = window.location.href.replace(window.location.hash, "") + "#a" + txt.substr(1, txt.length);
                    window.location.reload();
                }
        });
    }
}

function InfoMarkRev(idx, act) {
    switch (act) {
        case 1: if (confirm("你确定要删除这个咨询么？")) { $.get(CombActPath("InfoMarkRev&idx=" + idx), function(txt) { if (!IsZero(txt)) { window.location = window.location.href.replace(window.location.hash, "") + "#a" + txt.substr(1, txt.length); window.location.reload(); } }); } break;
        case 2: $("#imr_" + idx).remove(); break;
        case 3: $.post(CombActPath("InfoMarkRev"), { mID: idx, mText: $("#msrTxt_" + idx).val() }, function(txt) {
            if (!IsZero(txt.substr(0, 1))) { window.location = window.location.href.replace(window.location.hash, "") + "#a" + txt.substr(1, txt.length); window.location.reload(); }
        }); break;
        default: var sTxt = ""; if ($("#im_" + idx).find("blockquote").length > 0) { sTxt = $("#im_" + idx + " blockquote p").html().replace("<br>", "\r\n"); } $("#im_" + idx).append("<div id=\"imr_" + idx + "\"><textarea class=\"msrTxt\" id=\"msrTxt_" + idx + "\" cols=\"69\" rows=\"2\">" + sTxt + "</textarea><br /><a href=\"javascript:InfoMarkRev(" + idx + ",3);\">回复</a>&nbsp;&nbsp;&nbsp;<a href=\"javascript:InfoMarkRev(" + idx + ",2);\">取消</a></div>"); break;
    }
}

function ShowSed() {
    var sOffset = $("#DoSed").offset();
    $("#ShowSed").css({ left: sOffset.left - 7 + "px", top: sOffset.top + $("#DoSed").height() - 2 + "px" }).toggle();
}

function InfoWarn(kid, idx) {
    $.get(CombActPath("InfoWarn&kid=" + kid + "&idx=" + idx), function(txt) {
        $("#DoSed").replaceWith(ToInte(txt) != 1 ? "<span>已举报过</span>" : "<span>举报成功</span>");
        $("#ShowSed").hide();
    });
}

function winShow(elm, wid, hei) {
    $("<div id=\"mtWins_PaOve\"></div>").appendTo("body");
    $("<div id=\"mtWins_PaBox\"></div>").appendTo("body").css({ width: wid, height: hei, top: $(window).scrollTop() + ($(window).height() - hei) / 2, left: $(window).scrollLeft() + ($(window).width() - wid) / 2 }).append(elm);
}

function winHide() {
    $("#mtWins_PaOve,#mtWins_PaBox").remove();
}

function PostEmail(idx) {
    winShow("<div id=\"SendMail\" class=\"usn\"><form id=\"smForm\" name=\"smForm\" method=\"post\" action=\"javascript:SendMail();\"><p class=\"ite\"><label>邮箱地址：</label><input type=\"text\" name=\"smMail\" id=\"smMail\" value=\"\" size=\"25\" /></p><p class=\"ite\"><label>邮件内容：</label><textarea name=\"smText\" id=\"smText\" cols=\"51\" rows=\"7\"></textarea></p><p id=\"ideWarn\">输入内容和你的邮箱地址，以便发布人回信给你</p><p class=\"btn\"><input type=\"hidden\" name=\"smID\" id=\"smID\" value=\"" + idx + "\" /><input type=\"submit\" name=\"smPost\" id=\"smPost\" value=\"&nbsp;发送邮件&nbsp;\" />&nbsp;&nbsp;<input type=\"button\" name=\"smCancel\" id=\"smCancel\" value=\"&nbsp;取消&nbsp;\" onclick=\"winHide();\" /></p><p class=\"msg\">中国农业信息分类发布平台没有验证全部发布人邮箱地址的真实性，发布人可能收不到您写的信。</p></form></div>", 390, 360);
}

function SendMail() {
    var smMail = $("#smMail").val(), smText = $("#smText").val();
    if (IsNull(smMail)) {
        ShowIdeWarn("ideWarn", false, "请输入邮箱地址");
    } else if (IsNull(smText)) {
        ShowIdeWarn("ideWarn", false, "请输入邮件内容");
    } else {
        ShowIdeWarn("ideWarn", true, "正在发送邮件……");
        $.post(CombActPath("InfoPostMail"), { smID: $("#smID").val(), smMail: smMail, smText: smText }, function(txt) {
            if (ToInte(txt.substr(0, 1)) == 0) {
                ShowIdeWarn("ideWarn", false, txt.substr(1, txt.length));
            } else {
                $("#SendMail").html(txt.substr(1, txt.length));
            }
        });
    }
}

$(document).ready(function() {
    $("img.Image").each(function() {
        if (ToInte($(this).attr("width")) > 600) {
            var oIMA = new Image(); oIMA.src = $(this).attr("src"); var tWid = oIMA.width; oIMA = null; $(this).css({ 'width': (tWid > 600) ? 600 : tWid, 'display': 'inline' });
        }
        $(this).attr("title", "点击查看全图").click(function() {
            var oIMA = new Image(); oIMA.src = $(this).attr("src"); BoxShow(oIMA, oIMA.width, oIMA.height); oIMA = null;
        });
    });
});