﻿//评论 1顶，2踩
function commup(cid, sta) {
    jQuery.ajax({ url: '/plug/js/comm.ashx?type=1&sta=' + sta + '&cid=' + cid,
        cache: false,
        type: 'GET',
        dataType: 'html',
        timeout: 20000,
        error: function() { alert('error'); },
        success: function(html) {
            if (html == "0") {
                alert('评论过了哦');
            }
            else {
                alert('评论成功！');
                if (sta == 1) {
                    jQuery('#spanup' + cid).html(html);
                } else {
                    jQuery('#spandown' + cid).html(html);
                }
            }
        }
    });
};
//digg发表
function postDigg(digid, hidid) {
    jQuery.ajax({
        url: '/plug/js/comm.ashx?type=2&digip=1&digid=' + digid,
        cache: false,
        type: 'GET',
        dataType: 'html',
        timeout: 20000,
        error: function() { },
        success: function(html) {
            if (html == "0") {
                alert("已经顶过了");
                return false;
            }
            else {
                jQuery('#diggNum' + digid).html(html);
                return true;
            }
        }
    });
}

//会员是否登录
function CheckIsLogin() {
    jQuery.ajax({
        url: '/plug/js/comm.ashx?type=islogined', cache: false,
        type: 'GET', dataType: 'html',
        timeout: 20000, error: function() { },
        success: function(html) {
            if (html == "true") {
                return true;
            }
            return false;
        }
    });
}

//会员登录状态
function CheckLogin(fid, hid) {
    jQuery.ajax({
        url: '/plug/js/comm.ashx?type=loginsta', cache: false,
        type: 'GET', dataType: 'html',
        timeout: 20000, error: function() { },
        success: function(html) {
            if (html.length > 0) {
                jQuery("#" + fid).html(html);
                if (hid != "")
                    jQuery("#" + hid).hide();
            } else {
                jQuery("#" + fid).hide();
                if (hid != "")
                    jQuery("#" + hid).show();
            }
        }
    });
}

//添加到购物车
function AddCar(pid, url, affix) {
    if (jQuery("#pnum").val() == "") {
        alert('购买数量不能为空！');
        jQuery("#pnum").focus();
        return;
    }
    if (!/^[0-9]+$/.test(jQuery("#pnum").val())) {
        alert('购买数量必须为大于零的数字！');
        jQuery("#pnum").focus();
        return;
    } else {
        if (jQuery("#pnum").val() == "0") {
            alert('购买数量必须为大于零的数字！');
            jQuery("#pnum").focus();
            return;
        }
    }
    if (affix == undefined)
        affix = "";
    jQuery.ajax({
        url: '/plug/js/comm.ashx?type=addcar&pid=' + pid + '&pnum=' + jQuery("#pnum").val() + '&url=' + escape(url) + '&affix=' + escape(affix), cache: false,
        type: 'GET', dataType: 'html', async: false,
        timeout: 20000, error: function() { },
        success: function(html) {
            if (html == "inventory") {
                alert("库存不足");
                return;
            }
            window.open('/member/shop/shopcar.aspx');
        }
    });
}

//添加收藏夹
function AddStow(pid, url) {
    jQuery.ajax({
        url: '/plug/js/comm.ashx?type=addstow&pid=' + pid + '&url=' + url, cache: false, async: false,
        type: 'GET', dataType: 'html',
        timeout: 20000, error: function() { },
        success: function(html) {
            if (html == "ok") {
                window.open('/member/infor/vipstow.aspx');
            } else {
                alert('您还没有登录！');
            }
        }
    })
}

//显示购物车产品
function showcarpri() {
    jQuery.ajax({
        url: '/plug/js/comm.ashx?type=shopcarcount', cache: false,
        type: 'GET', dataType: 'html',
        timeout: 20000, error: function() { },
        success: function(html) {
            if (html.indexOf(',') != -1) {
                jQuery("#carcount").html(html.split(',')[0]);
                jQuery("#carprice").html(html.split(',')[1]);
            }
        }
    });
};

//获取广告 编号，绑定对象
function getad(adid, obj) {
    jQuery.ajax({
        url: '/plug/js/comm.ashx?type=getad&id=' + adid, cache: false,
        type: 'GET', dataType: 'html',
        timeout: 20000, error: function() { },
        success: function(html) {
            jQuery("#"+obj).html(html);
        }
    });
}
//提交投票
function votesubmit(voteid,obj) {
    var poststr = "";
    $("#"+obj+" :input").each(function(i) {
        if (this.id != "votesubmit"+voteid) {
            if (this.name == "voteradio"+voteid) {
                if (this.checked == true) {
                    poststr += (this.name + "=" + this.value + "&");
                }
            }
            if (this.name.indexOf("votecheckbox"+voteid)!=-1) {
                poststr += (this.name + "=" + this.value + "&");
            }
        }
    });
    jQuery.ajax({
        type: "POST", cache: false,
        url: "/plug/vote.aspx?voteid="+voteid,
        data: poststr, timeout: 20000, error: function() { },
        success: function(msg) {
            if (msg.indexOf("_") != -1) {
                $("#"+obj+" a").html("查看投票").attr("href", "/plug/vote.aspx?show=" + msg.split('_')[1]);
                alert(msg.split('_')[0]);
            } else {
                alert(msg);
            }
            $("#votesubmit"+voteid).attr("disabled", "disabled");
        }
    });
}

//获取投票
function getvote(voteid, obj) {
    jQuery.ajax({
        url: '/plug/js/comm.ashx?type=getvote&bind=' + voteid+'&obj='+obj, cache: false,
        type: 'GET', dataType: 'html',
        timeout: 20000, error: function() { },
        success: function(html) {
            jQuery("#" + obj).html(html);
        }
    });
}
//发表帖子
function sendtopic(obj, isform) {
    if (jQuery("#topictitle").val() == "" || jQuery("#topicmessage").val() == "") {
        obj.disabled = false
        alert('请完成标题或内容');
        return;
    }
    if (isform != "") {
        document.forms[isform].submit();
        return;
    }
    jQuery.ajax({
        type: "POST", cache: false,
        url: "/plug/js/comm.ashx?type=addtopic",
        data: "fid=" + jQuery("#forumsid").val() + "&message=" + escape(jQuery("#topicmessage").val()) + "&title=" + escape(jQuery("#topictitle").val()),
        timeout: 20000, error: function() { },
        success: function(msg) {
            if (msg == "ok") {
                alert("帖子发表成功！");
                window.location.reload();
            } else {
                obj.disabled = false
                alert(msg);
            }
        }
    });
}

//添加回复
function sendpost(obj, isform) {
    if (jQuery("#postmessage").val() == "") {
        obj.disabled = false
        alert('请完成回复内容');
        return;
    }
    if (isform != "") {
        document.forms[isform].submit();
        return;
    }
    jQuery.ajax({
        type: "POST", cache: false,
        url: "/plug/js/comm.ashx?type=addpost",
        data: "fid=" + jQuery("#forumsid").val() + "&tid=" + jQuery("#topicsid").val() + "&message=" + escape(jQuery("#postmessage").val()) + "&title=" + escape(jQuery("#posttitle").val()),
        timeout: 20000, error: function() { },
        success: function(msg) {
            if (msg == "ok") {
                alert("帖子发表成功！");
                window.location.reload();
            } else {
                obj.disabled = false
                alert(msg);
            }
        }
    });
}


