﻿$(document).ready(function() {
    var timeoutId;
    
    $(document).keydown(function(event) {  //这里如果写成$(window)，在ie下面就不会起作用
        if (event.keyCode == 13) {
            if (document.activeElement.id == "home_search_input") {
                $("#home_search_submit").click();
                return false;
            }
        }
    });

    $(".user-message").hover(function() {
        clearTimeout(timeoutId);
        $("#user-message").show();
        var position = $(this).position();
        var width = $("#user-message").width();
        var height = $("#user-message").height();
        var _left = position.left - 20;
        var _top = position.top - height - 12;
        $("#user-message").css({ left: _left, top: _top });
        var id = $(this).attr("id");
        var url = "";
        if (id.indexOf("-") > 0) {
            url = "/goods/message/" + id + "?rd=" + Math.random();
        }
        else {
            url = "/user/message/" + id + "?rd=" + Math.random();
        }
        $.get(url, function(data) {
            $("#user-message").html(data);
        });
    }, function() {
        timeoutId = setTimeout(hidediv, 50);
    }).mouseout();
    $("#user-message").hover(function() {
        clearTimeout(timeoutId);
    }, function() {
        timeoutId = setTimeout(hidediv, 50);
    }).mouseout();

    // 投票按钮显示/隐藏处理
    $(".report_panel").mouseenter(function() {
        $(this).find(".votectrl").show();
    });
    $(".report_panel").mouseleave(function() {
        $(this).find(".votectrl").hide();
    });
    
    /*
     * 次主菜单相关 >>>>>>>>>>>>>>>>>>>>>>>>
     */
    $('#allcategory').mousemove(function() {
        $("#categorycontent").show();
        //$("#categorycontent").slideDown();
    });
    $('#allcategory').mouseleave(function() {
        $("#categorycontent").hide();
        //$("#categorycontent").slideUp();
    });
    $('#categorycontent').mousemove(function() {
        $("#categorycontent").show();
    });
    $('#categorycontent').mouseleave(function() {
        $("#categorycontent").hide();
    });
    
    $('.category-li').mousemove(function() {
        $(this).find(".cate_item").removeClass("cate_item_noshow");
        $(this).find(".cate_item").addClass("cate_item_show");
        $(this).find(".pop_div_outter").show();
    });
    $('.category-li').mouseleave(function() {
        $(this).find(".cate_item").removeClass("cate_item_show");
        $(this).find(".cate_item").addClass("cate_item_noshow");
        $(this).find(".pop_div_outter").hide();
    });
    
    /*
     * 次主菜单相关 <<<<<<<<<<<<<<<<<<<<<<<<<
     */
    
    /*
     * 新搜索控件相关 >>>>>>>>>>>>>>>>>>>>>>>>>>
     */
    $("#df_seachtxt").click(function() {
        $("#df_seachtxt").addClass("seach-hide");
        $("#home_search_input").focus();
    });
    $("#home_search_input").blur(function() {
        var seach = $("#home_search_input").val();
        if (seach == null || seach == "") {
            $("#df_seachtxt").removeClass();
        }

    });
    /*
     * 新搜索控件相关 <<<<<<<<<<<<<<<<<<<<<<<<<
     */
     
    /*
     * 型号/区域输入框相关 >>>>>>>>>>>>>>>>>>>>>>>>>>
     */
    $("#comment-wrap-area").click(function() {
        select_area_dialog();
    });
    $("#comment-wrap-model").click(function() {
        select_model_dialog();
    });

    $(".input-wrap").click(function() {
        $(this).addClass("focus");
        $(this).find("label").addClass("hide");
        $(this).find("input-text").focus();
        
        if ($(this).is("#input-model")) {
            select_model_dialog();
        }
        else if ($(this).is("#input-area")) {
            select_area_dialog();
        }
    });
    $(".input-text").blur(function() {
        $(this).parent().removeClass("focus");
        
        /* 先不必恢复label提示
        var input_data = $(this).val();
        if (input_data == null || input_data == "") {
            $(this).parent().find("label").removeClass("hide");
        }
        */
    });
    // 选中区域事件
    $("#dialog-modal-area td").click(function() {
        if ($(this).hasClass("headcol")) { return; }
        if ($(this).html() == "") { return; }
        $("#input_area_txt").val($(this).html());
        $( "#dialog-modal-area" ).dialog( "destroy" );
    });

    // 选中车型事件
    $(".selection-item-a").click(function() {
        $("#input_model_txt").val($(this).html());
        $("#input_model_id").val($(this).parent().find(".modelId").html());
        $( "#dialog-modal-model" ).dialog( "destroy" );
    });
    // 价格validate
    $("#input_price_txt").keyup(function() {
        var price = $(this).val();
        //var ret = parseInt(num);
        //var regu = /^\d+$/;
        if (isNaN(price) /*|| !regu.test(price) */) {
            $(this).parent().find(".tip").show();
        }
        else {
            $(this).parent().find(".tip").hide();
        }
    });
    $("#analysis_form").submit(function(e){
        if (analysis_data_validate()) {
            return true;
        }
        e.preventDefault();
        return false;
    });
    /*
     * 输入框相关 <<<<<<<<<<<<<<<<<<<<<<<<<
     */
});
function welcome_search() {
    var value = $("#home_search_input").val();
    var url = "/search";
    if (value == "搜索车型") {
        value = "";
    }
    else {
        url = url + "?q=" + escape(value);
    }
    var eid = document.activeElement.id;
    if (eid == "home_search_submit" || eid == "home_search_input" || eid == "") {
        self.location = url;
    }
}

function hidediv() {
    $("#user-message").hide();
}
function add_goods(id) {
    $.get("/Favorate/add/" + id + "?rd=" + Math.random(), function(result) {
        initgoods(id);
        if (result == "1") {
            //dialog("添加关注成功 !");
        }
        else if (result == "0") {
            //dialog("添加关注失败 !");
        }
        else {
            dialog(result);
        }
    });
}
function cancel_goods(id) {
    $.get("/Favorate/cancel/" + id + "?rd=" + Math.random(), function(result) {
        initgoods(id);
        if (result == "1") {
            //dialog("取消关注成功 !");
        }
        else if (result == "0") {
            //dialog("添加关注失败 !");
        }
        else {
            dialog(result);
        }
    });
}


function cancel_goods_re(id) {
    $.get("/Favorate/cancel/" + id + "?rd=" + Math.random(), function(result) {
        if (result == "1") {
            $("#fo_addgoods_" + id).html("已取消关注");
            /*
            var href = "<a href=\"javascript:void(0);\" onclick=\"<%=add %>\">添加关注</a>";
            $("#focus_goods_" + id).html(href);
            dialog("取消关注成功 !");
            */
        }
        else if (result == "0") {
            //dialog("添加关注失败 !");
        }
        else {
            dialog(result);
        }
        //document.location.reload();
    });
}
function initgoods(id) {
    var add = "<input type=\"button\" onclick=\"add_goods('" + id + "')\" class=\"addfocus\" value=\"\" title=\"加关注\" />";
    var del = "<input type=\"button\" onclick=\"cancel_goods('" + id + "')\" class=\"delfocus\" value=\"\" title=\"取消关注\"/>";
    var url = "/favorate/isfavorate/" + id + "?rd=" + Math.random();
    $.get(url, function(data) {
        if (data == "0") {
            $("#addgoods_" + id).html(add);
        }
        else if (data == "1") {
            $("#addgoods_" + id).html(del);
        }
    });
}
function dialog(msg) {
    if (msg != "") {
        $("#dialog-message").html(msg);
        $("#dialog-message").dialog({
            modal: true,
            resizable: false
        });
    }
}
function dialogConfirm(msg, url) {
    if (msg != "") {
        $("#dialog-message").html(msg);
        $("#dialog-message").dialog({
            modal: true,
            resizable: false,
            buttons: {
                "确定": function() {
                    window.location.href = url;
                },
                "取消": function() {
                    $(this).dialog("close");
                }
            }
        });
    }
}
//msg:显示消息;tag:YES/NO; flag:标记是用户操作:0；还是管理员操作:1；
function dialogConfirm3(msg, id, tag, flag) {
    if (msg != "") {
        $("#dialog-message").html(msg);
        $("#dialog-message").dialog({
            modal: true,
            resizable: false,
            buttons: {
                "确定": function() {
                    //                    window.location.href = url;
                    if (flag == "1") {
                        setAdmin(id, tag);
                    } else if (flag == "0") {
                        setApprove(id, tag);
                    }

                },
                "取消": function() {
                    $(this).dialog("close");
                }
            }
        });
    }
}
//设置管理员
function setAdmin(id, tag) {
    $.get("/admin/user/SetAdmin/" + id + "?tag=" + tag + "&rd=" + Math.random(), function(result) {
        if (result == "0") {
            if (tag == "1") {
                $("#sp_ad_" + id).html("<a href='javascript:void(0);' onclick='setAdmin(" + id + ",0)' id='a_ad_" + id + "'> 取消管理员</a>&nbsp;");
            } else if (tag == "0") {
                $("#sp_ad_" + id).html("<a href='javascript:void(0);' onclick='setAdmin(" + id + ",1)' id='a_ad_" + id + "'> 设为管理员</a>&nbsp;");
            }
        }
        document.location.reload();
    });
}

//商品管理的 认证/未认证
function appcheck(gid, app, url) {
    $.get("/admin/goods/Update_App?gid=" + gid + "&app=" + app + "&rd=" + Math.random(), function(result) {
        if (result == "0") {
            if (app == "1") {
                $("#a_ap_" + gid).html(" <a href='javascript:void(0)' onclick='appcheck(" + gid + ",0," + url + ")' id='a-ap-" + gid + "'>已认证</a>&nbsp;");
            } else if (app == "0") {
                $("#a_ap_" + gid).html(" <a href='javascript:void(0)' onclick='appcheck(" + gid + ",1," + url + ")' id='a-ap-" + gid + "'>未认证</a>&nbsp;");
            }
        }
        var refurl = url + "&type=" + $("#seltype").val();
        document.location.href = refurl;
    });
}


//设置是否允许/禁止用户
function setApprove(id, tag) {
    $.get("/admin/user/SetApprove/" + id + "?tag=" + tag + "&rd=" + Math.random(), function(result) {
        if (result == "0") {
            if (tag == "0") {
                $("#sp_ap_" + id).html("<a href='javascript:void(0);' onclick='setApprove(" + id + ",1)' id='a_ap_" + id + "'> 禁止</a>&nbsp;");
            } else if (tag == "1") {
                $("#sp_ap_" + id).html("<a href='javascript:void(0);' onclick='setApprove(" + id + ",0)' id='a_ap_" + id + "'> 允许</a>&nbsp;");
            }
        }
        document.location.reload();
    });
}

function ApproveReview(id, approve) {
    $.get("/admin/review/Approve/" + id + "?rd=" + Math.random(), function(result) {
        document.location.reload();
    });
}

function AppComment(id, approve) {
    $.get("/admin/note/Approve/" + id + "?approve=" + approve + "&rd=" + Math.random(), function(result) {
        if (approve == "1") {
            $("#ls_" + id).html("");
            $("#ls_" + id).html(" <a href='javascript:void(0);' onclick='AppComment(" + id + ",0,0)' id='a_ac_" + id + "'>已审核</a>");
        } else {
            $("#ls_" + id).html("");
            $("#ls_" + id).html(" <a href='javascript:void(0);' onclick='AppComment(" + id + ",0,1)' id='a_ac_" + id + "'>未审核</a>");
        }
        document.location.reload();
    });
}

function addfocus(id) {
    $.get("/friends/add/" + id + "?rd=" + Math.random(), function(result) {
        init(id);
        if (result == "1") {
            //                    alert("添加信赖成功 !");
        }
        else if (result == "0") {
            //$("#dialog-message").html("添加关注失败 !");
        }
        else {
            dialog(result);
        }
    });
}
function delfocus(id) {
    $.get("/friends/cancel/" + id + "?rd=" + Math.random(), function(result) {
        init(id);
        if (result == "1") {
            //                    alert("取消信赖成功 !");
        }
        else if (result == "0") {
            ///$("#dialog-message").html("取消关注失败 !");
        }
        else {
            dialog(result);
        }
    });
}

function init(id) {
    var add = "<input type=\"button\" onclick=\"addfocus('" + id + "')\" class=\"addfocus\" value=\"\" title=\"加关注\" />";
    var del = "<input type=\"button\" onclick=\"delfocus('" + id + "')\" class=\"delfocus\" value=\"\" title=\"取消关注\"/>";
    //var id = $("#addfocus").attr("title");
    var url = "/blog/focus/" + id + "?rd=" + Math.random();
    $.get(url, function(data) {
        if (data == "0") {
            $("#addfocus_" + id).html(add);
        }
        else if (data == "1") {
            $("#addfocus_" + id).html(del);
        }
    });
}

//关闭消息框
function hidemsg() {
    $(".field-message-error").hide();
}
//获取评论数
function getReviewCount(cmid) {
    var url = "/review/count";
    var data = "cmid=" + cmid + "&rd=" + Math.random();
    $.post(url, data, function(json) {
        $("#review_" + cmid).html(json.cnt);
        if (json.cnt == "0") {
            $("#sp_review_" + cmid).html("评论(<span id='review_" + cmid + ">'>" + json.cnt + "</span>)");
        }
    });
}

//提交评论 : 帖子列表中
function sub(id) {
    //alert(id);
    //var id = $(this).attr("name");
    var url = "/review/add";
    var val = $("#tt-" + id).val();
    var data = "cid=" + id + "&content=" + escape(val);
    if (val == "") {
        dialog("请输入评论内容 !");
        return;
    }
    $.post(url, data, function(msg) {
        update(id);
        $("#tt-" + id).val("");
        dialog(msg);
    });
    getReviewCount(id);
}
//提交评论 : 单个帖子画面中
function post_review(id) {
    var url = "/review/add";
    var val = $("#review_content").val();
    var data = "cid=" + id + "&content=" + escape(val);
    if (val == "") {
        dialog("请输入评论内容 !");
        return;
    }
    $.post(url, data, function(msg) {
        if (msg != "") {
            dialog(msg);
        }
        else {
            window.location.href = "/t/" + id + "#review_list"; //?rd=" + Math.random();
            window.location.reload();
        }
    });
}
//商品页面---评论
function review(cmid) {
    if ($("#a_b_" + cmid).html() != "收起评论") {
        $("#a_b_" + cmid).html("收起评论");
    }
    else {
        $("#a_b_" + cmid).html("评论(<span id=\"review_" + cmid + "\"></span>)");
        getReviewCount(cmid);
    }
    $("#ls-review-" + cmid).toggle();
    if ($("#ls-review-" + cmid).css("display") == "block") {
        update(cmid);
    }
}

//帖子 商品面包屑
function goodsmap(id, gid) {

    $.get("/admin/note/GoodsMap/" + gid + "?rd=" + Math.random(), function(data) {

        $("#gmap-" + id).html(data);
    });
}


//商品页面---评论
function update(cmid) {
    $.get("/review/index/" + cmid + "?rd=" + Math.random(), function(data) {
        //alert(data);
        $("#ls-review-list-" + cmid).html(data);
    });
}

//支持/不支持
function voteinit(cmid, type) {
    $.post("/vote/init?cid=" + cmid + "&rd=" + Math.random(), function(data) {
        if (data.status == "") {
            $("#agr_" + cmid).html("<input type='button' class='btn-agr votectrl' value='' title='称赞一下，您会得到1分，作者也会得到1分。称赞多于鄙视时本价格才会有效。' onclick='agree(\"" + cmid + "\");'/>");
            $("#ags_" + cmid).html("<input type='button' class='btn-ags votectrl' value='' title='鄙视一下，您会得到1分，作者将会失去1分。鄙视多于称赞时本价格将会无效。' onclick='agst(\"" + cmid + "\");' />");
        }
        else {
            $("#agr_" + cmid).html("<input type='button' class='btn-agr-none votectrl' value='' title='您已投票或不可投票'/>");
            $("#ags_" + cmid).html("<input type='button' class='btn-ags-none votectrl' value='' title='您已投票或不可投票'/>");
        }
        $("#nagr_" + cmid).html(data.Agree);
        $("#nags_" + cmid).html(data.Agst);
        $("#price_" + cmid).removeAttr("style");

        if (Number(data.Agree) < Number(data.Agst)) {
            $("#price_" + cmid).attr("style", "color: #888;");
        }
    });
}
//支持
function agree(cmid) {
    $.get("/vote/agree?cid=" + cmid + "&rd=" + Math.random(), function(data) {
        if (data != "") {
            dialog(data);
        } else {
            voteinit(cmid);
        }
    });
}
//不支持
function agst(cmid) {
    $.get("/vote/agst?cid=" + cmid + "&rd=" + Math.random(), function(data) {
        if (data != "") {
            dialog(data);
        }
        else {
            voteinit(cmid);
        }
    });
}
//统计图表
function chart_line(id) {
    $.post("/goods/data/" + id + "?rd=" + Math.random(), function(data) {
        var myChart = new FusionCharts(
            "/Content/PlugIn/FusionCharts/Line2.swf"
            , "myChartId"
            , "100%"
            , "100%"
            , "0"
            , "1");
        myChart.setJSONData(data);
        myChart.render("chartContainer");
    });
}
//统计图表
function chart_bar(id) {
    $.post("/goods/data_bar/" + id + "?rd=" + Math.random(), function(data) {
        var myChart = new FusionCharts(
            "/Content/PlugIn/FusionCharts/Column2D.swf"
            , "myChartId"
            , "100%"
            , "100%"
            , "0"
            , "1");
        myChart.setJSONData(data);
        myChart.render("chartContainerbar");
    });
}
function smsRead(id) {
    $.get("/sms/read/" + id + "?rd=" + Math.random(), function(data) {
        if (data == "0") {
            $("#sms_ico_" + id).html('<img src="/content/images/gr_center_05.gif" width="14" height="11"  style="cursor: pointer;" onclick="smsNonRead(\'' + id + '\')" title="标记为未读"/>');
        }
    });
}

function setRead(id) {
    $.get("/admin/ContactUs/update/" + id + "?isread=1&rd=" + Math.random(), function(data) {
        if (data == "1") {
            $("#a_rd_" + id).attr("src", " /content/images/gr_center_05.gif");
            document.location.reload();
        }
    });
}
function setNoRead(id) {
    $.get("/admin/ContactUs/update/" + id + "?isread=0&rd=" + Math.random(), function(data) {
        if (data == "1") {
            $("#a_rd_" + id).attr("src", " /content/images/gr_center_04.gif");
            document.location.reload();
        }
    });
}

function delContactUs(id) {
    $.get("/admin/ContactUs/del/" + id + "?rd=" + Math.random(), function(data) {
        document.location.reload();
    });
}
function smsNonRead(id) {
    $.get("/sms/nonread/" + id + "?rd=" + Math.random(), function(data) {
        if (data == "0") {
            $("#sms_ico_" + id).html('<img src="/content/images/gr_center_04.gif" width="14" height="11" style="cursor: pointer;" onclick="smsRead(\'' + id + '\')" title="标记为已读"/>');
        }
    });
}
function fileFun(event, queueID, fileObj, response, data) {
    //$("#invoice").hide();
    if (response != "") {
        $("#invoiceId").val(response);
        var url = "/uploadimage/get?imgid=" + response + "&rd=" + Math.random();
        $.get(url, function(src) {
            $("#invoice").attr("src", src);
            $("#invoice").show();
            $("#invoicedel").show();
        });
    }
    else {
        dialog("文件上传出错");
    }
}
function delinvoice() {
    $("#invoicedel").hide();
    $("#invoice").hide();
    $("#invoiceId").val("0");
}

function smsCount() {
    $.get("/sms/count?rd=" + Math.random(), function(data) {
        if (data != "" && data != "0") {
            $("#newsmsinfo").html("消息(<span style='color:red;'><b>" + data + "</b></span>)");
        }
        else {
            $("#newsmsinfo").html("消息");
        }
    })

}

//ie
function copy_clip(strValue) {
    if (isIE()) {
        clipboardData.setData("Text", strValue);
        alert("您已经复制到剪贴板");
    }
    else {
        prompt('请按"Ctrl+C"复制该文本', strValue);
    }
}

function isIE(number) {
    if (typeof (number) != number) {
        return !!document.all;
    }
}

function copy(text2copy) {
    var flashcopier = 'flashcopier';
    if (!document.getElementById(flashcopier)) {
        var divholder = document.createElement('div');
        divholder.id = flashcopier;
        document.body.appendChild(divholder);
    }
    document.getElementById(flashcopier).innerHTML = '';
    var divinfo = '<embed src="http://www.lxj.name/cases/_clipboard.swf" FlashVars="clipboard=' + text2copy + '" width="0" height="0" type="application/x-shockwave-flash"></embed>'; //这里是关键
    document.getElementById(flashcopier).innerHTML = divinfo;
}
//收件箱
function listcount() {
    $.get("/sms/total?rd=" + Math.random(), function(data) {
        $("#listcount").html(data);
    });
}

//发件箱
function historycount() {
    $.get("/sms/total?type=1&rd=" + Math.random(), function(data) {
        $("#historycount").html(data);
        //alert(data);
    });
}
//获取未度count
function noreadcount() {
    $.get("/Sms/count?rd=" + Math.random(), function(data) {
        if (data == "0" || data == "") {
            //$("#mesc").html("<span >您没有未读消息</span>");
            $("#mesc").hide();
        }
        else {
            $("#mesc").show();
            $("#mesc").html("<span style='height:120px;'><a href='/sms/list' style='text-decoration:none; color:#FC6600;'>您有<br/><b>" + data + "</b><br/>条未读消息</a></span>");
        }
    });
}
function updatemenu() {
    $.get("/goods/update/a?rd=" + Math.random(), function(data) {
        dialog(data);
    });
}
function reviewdel(rid, cmid) {
    $.get("/review/del?rid=" + rid + "&rd=" + Math.random(), function(data) {
        getReviewCount(cmid);
        update(cmid);
    })
}


function adreviewdel(rid, cmid) {
    $.get("/admin/note/DelReview?rid=" + rid + "&rd=" + Math.random(), function(data) {
        getReviewCount(cmid);
        update(cmid);
    });
}

//后台删除评论
function ad_dialogConfirm(msg, reviewid) {
    if (msg != "") {
        $("#dialog-message").html(msg);
        $("#dialog-message").dialog({
            modal: true,
            resizable: false,
            buttons: {
                "确定": function() {
                    //                    window.location.href = url;
                DelReview(reviewid);
                },
                "取消": function() {
                    $(this).dialog("close");
                }
            }
        });
    }
}
function DelReview(reviewid) {
    $.get("/admin/review/delreview?rid=" + reviewid + "&rd=" + Math.random(), function(data) {
        if (data == "1") {
            document.location.reload();
        }
    });
}

//删除
function dialogConfirm2(msg, cmid, url) {
    if (msg != "") {
        $("#dialog-message").html(msg);
        $("#dialog-message").dialog({
            modal: true,
            resizable: false,
            buttons: {
                "确定": function() {
                    //                    window.location.href = url;
                    DelComment(cmid, url);
                },
                "取消": function() {
                    $(this).dialog("close");
                }
            }
        });
    }
}
function DelComment(cmid, url) {

    $.get("/admin/note/DelComment/" + cmid + "?refurl=" + url + "&rd=" + Math.random(), function(data) {
        if (data == "1") {
            document.location.reload();
        }
    });
}


//经销商列表删除
function dialogConfirm4(msg, id, sid) {
    if (msg != "") {
        $("#dialog-message").html(msg);
        $("#dialog-message").dialog({
            modal: true,
            resizable: false,
            buttons: {
                "确定": function() {
                    //                    window.location.href = url;
                    DelDealer(id, sid);
                },
                "取消": function() {
                    $(this).dialog("close");
                }
            }
        });
    }
}

//删除经销商
function DelDealer(id, sid) {
    $.get("/admin/dealer/del/" + id + "?sid=" + sid + "&rd=" + Math.random(), function(data) {
        if (data == "1") {
            document.location.reload();
        }
    });
}



//经销商列表删除
function dialogConfirm5(msg, id, sid) {
    if (msg != "") {
        $("#dialog-message").html(msg);
        $("#dialog-message").dialog({
            modal: true,
            resizable: false,
            buttons: {
                "确定": function() {
                    //                    window.location.href = url;
                    DelClub(id, sid);
                },
                "取消": function() {
                    $(this).dialog("close");
                }
            }
        });
    }
}

//删除经销商
function DelClub(id, sid) {
    $.get("/admin/club/del/" + id + "?sid=" + sid + "&rd=" + Math.random(), function(data) {
        if (data == "1") {
            document.location.reload();
        }
    });
}

function gactive(id, page) {
    $.get("/home/ucgactive/" + id + "?page=" + page + "&rd=" + Math.random(), function(data) {
        $("#talist").html(data);
    }
                                    );
}

function factive(id, page) {
    $.get("/home/ucfactive/" + id + "?page=" + page + "&rd=" + Math.random(), function(data) {
        $("#talist").html(data);
    }
                                    );
}

//首页 商户动态
function comment_author_over(id) {
    $("#comment_author_" + id).show();
}
function comment_author_out(id) {
    $("#comment_author_" + id).hide();
}






function showad(id) {
    $("#addfocus_fr_" + id).show();
}
function hidead(id) {
    $("#addfocus_fr_" + id).hide();
}
function showfans(id) {
    $("#addfocus_fa_" + id).show();
}
function hidefans(id) {
    $("#addfocus_fa_" + id).hide();
}

function blog_showbtn(id, dname, tg) {
    var add = "<a href=\"javascript:void(0)\" onclick=\"addfocusl('" + id + "','" + dname + "','" + tg + "')\">添加关注</a>&nbsp;<a href=\"/sms/send/" + dname + "\">发私信</a>";
    var del = "<a href=\"javascript:void(0)\" onclick=\"delfocusl('" + id + "','" + dname + "','" + tg + "')\">取消关注</a>&nbsp;<a href=\"/sms/send/" + dname + "\">发私信</a>";
    //var id = $("#addfocus").attr("title");
    var url = "/blog/focus/" + id + "?rd=" + Math.random();
    $.get(url, function(data) {
        if (data == "0") {
            if (tg == "fr") {
                $("#addfocus_fr_" + id).html(add);
            } else if (tg == "fa") {
                $("#addfocus_fa_" + id).html(add);
            }

        }
        else if (data == "1") {
            if (tg == "fr") {
                $("#addfocus_fr_" + id).html(del);
            } else if (tg == "fa") {
                $("#addfocus_fa_" + id).html(del);
            }

        }
    });
}

//fans


function addfocusl(id, dname, tg) {
    $.get("/friends/add/" + id + "?rd=" + Math.random(), function(result) {
        blog_showbtn(id, dname, tg);
        if (result == "1") {
            //                    alert("添加信赖成功 !");
        }
        else if (result == "0") {
            //$("#dialog-message").html("添加关注失败 !");
        }
        else {
            dialog(result);
        }
    });
}


function delfocusl(id, dname, tg) {
    $.get("/friends/cancel/" + id + "?rd=" + Math.random(), function(result) {
        blog_showbtn(id, dname, tg);
        if (result == "1") {
            //                    alert("取消信赖成功 !");
        }
        else if (result == "0") {
            ///$("#dialog-message").html("取消关注失败 !");
        }
        else {
            dialog(result);
        }
    });
}


//最新价格的添加关注
function fo_addgoods_show(id) {
    $("#fo_addgoods_" + id).show();
}
function fo_addgoods_hide(id) {
    $("#fo_addgoods_" + id).hide();
}

function select_model_dialog() {
	$( "#dialog:ui-dialog" ).dialog( "destroy" );

	$( "#dialog-modal-model" ).dialog({
	    width: 400,
		height: 450,
		modal: true
	});
}

function select_area_dialog() {
	$( "#dialog:ui-dialog" ).dialog( "destroy" );

	$( "#dialog-modal-area" ).dialog({
	    width: 480,
		height:300,
		modal: true
	});
}

function analysis_data_validate() {
    var price = $("#input_price_txt").val();
    price = jQuery.trim(price);
    
    if (isNaN(price) || price == "") {
        //$("#input_price_txt").parent().find(".tip").show();
        $("#input_price_txt").parent().find(".tip").hide();
        $("#input_price_txt").parent().find(".tip").slideDown();
        return false;
    }
    else {    
        // 小数处理
        var p = price.indexOf(".");
        if (p >= 0) {
            var f = parseFloat(price);
            if (p < 3 && (p - 1) != price.length) {
                price = parseInt(f * 10000).toString();
            }
            else {
                price = parseInt(f).toString();
            }
            $("#input_price_txt").val(price);
        }

        $("#input_price_txt").parent().find(".tip").hide();
    }
    return true;
}

// 进行比价
function HowPrice(goodsid) {
    var url = "/goods/HowPrice/" + goodsid;
    var val_model = $("#input_model_txt").val();
    var val_modelid = $("#input_model_id").val();
    var val_area = $("#input_area_txt").val();

    // 清除选中车型价格表项的背景色
    $(".price-brief tr").css("font-weight", "normal");
    // 设置选中车型价格表项的背景色
    if (val_modelid != null && val_modelid != "") {
        $("#btr_"+val_modelid).css("font-weight", "bold");
    }

    if (!analysis_data_validate()) {
        //e.preventDefault();
        return false;
    }

    var val_price = $("#input_price_txt").val();

    $("#howprice_result").hide();
    $("#goods_price_brief").hide();
    $("#howprice_prompt").html("正在查询...");
    $("#howprice_prompt").show();


    var data = "goodsid=" + escape(goodsid);
    data = data + "&input_model_txt=" + escape(val_model);
    data = data + "&input_model_id=" + escape(val_modelid);
    data = data + "&input_area_txt=" + escape(val_area);
    data = data + "&input_price_txt=" + escape(val_price);

    $.post(url, data, function(json) {
        $("#res_all_comp_str").html(json.all_comp_str);
        $("#res_all_diff_str").html(json.all_diff_str);
        $("#res_purchase_area").html(json.purchase_area);
        $("#res_purchase_model").html(json.purchase_model);
        $("#res_rank_model_area").html(json.rank_model_area);
        $("#res_purchase_area2").html(json.purchase_area);
        $("#res_price_count_model_area").html(json.price_count_model_area);
        $("#res_price_abnormal").html(json.price_abnormal);
        
        if (json.purchase_area != null && json.purchase_area != "" && json.purchase_area != "全国") {
            $("#res_rank_model_all_panel").show();
            $("#res_rank_model_all").html(json.rank_model_all);
            $("#res_price_count_model_all").html(json.price_count_model_all);
        }
        else {
            $("#res_rank_model_all_panel").hide();
        }
        
        $("#howprice_prompt").hide();
        $("#howprice_result").show();
        $("#goods_price_brief").show();
    });
}
