﻿
 
function GetIpAddress() {
    var now = new Date();
    var num = Math.random() * now.getSeconds();
    $.ajax({
        type: "POST",
        url: 'AjaxInfo.ashx?do=GetCustomerIp&Random=' + num,
        dataType: "text",
        success: function (data) {
            if (data != "") {
                return data;
            }
            else {
                return "192.168.1.112";
            }
        }
    });
}

//出价按钮变化
function ShowButton(paiproductid, customerid, type) {
    $('#PaiImg_' + paiproductid).hover(
    function () {
        PaiLogin(paiproductid, customerid, type);
    },
    function () {
        PaiDefault(paiproductid, customerid, type); //paiproductid, customerid, type
    });

}
//未登录时出价按钮变成登录
function PaiLogin(paiproductid, customerid, type) {
    var imgSrc = $("#PaiImg_" + paiproductid).attr("src");
    if (type == "0") {
        if (customerid == 0 && imgSrc != "images/ms/ms-cj-menu2-1_03.gif") {
            imgSrc = "images/ms/ms-cj-menu2.gif";
        }
    }
    else {
        if (customerid == 0 && imgSrc != "images/ms/ms-cj-menu-top-show.gif") {
            //置顶登录按钮变化
            imgSrc = "images/ms/ms-cj-menu-top-login.gif";
        }
    }
    $("#PaiImg_" + paiproductid).attr("src", imgSrc);
}

//登录了显示出价按钮
function PaiDefault(paiproductid, customerid, type) {
    var imgSrc = $("#PaiImg_" + paiproductid).attr("src");
    if (type == "0") {
        //普通出价按钮变化
        if (customerid == 0 && imgSrc != "images/ms/ms-cj-menu2-1_03.gif") {
            imgSrc = "images/ms/ms-cj-menu2.jpg";
        }
    }
    else {
        if (customerid == 0 && imgSrc != "images/ms/ms-cj-menu-top-show.gif") {
            //置顶出价按钮变化
            imgSrc = "images/ms/ms-cj-menu.gif";
        }
    }
    $("#PaiImg_" + paiproductid).attr("src", imgSrc);
}
//竞拍产品方法
function Pai(paiproductid, customerid, type) {
    if (customerid == 0) {
        document.getElementById("gologin").click();
    }
    else {
        var now = new Date();
        var num = Math.random() * now.getSeconds();
        $.getJSON("http://paiserver.866.cn/Default.aspx?PaiProductId=" + paiproductid + "&CustomerId=" + customerid + "&CustomerIP=" +GetIpAddress()+ "&Random=" + num + "&jsoncallback=?", function (result) {
            var data = result.Msg;
            if (data != "") {
                if (data == "0") {
                    //竞拍完成产品跳转页面
                    window.location.href = "paiproduct.aspx?PaiProductId=" + paiproductid;
                }
                else if (data == "-1") {
                    alert("您的积分不够，请及时充值！");
                }
                else if (data == "-2") {
                    alert("不能重复出价！");
                }
                else {

                }

            }
            else {
                alert("网络延迟！");
            }
        });
//        $.ajax({
//            type: "POST",
//            url: 'AjaxInfo.ashx?PaiProductId=' + paiproductid + '&CustomerId=' + customerid + "&Random=" + num,
//            dataType: "text",
//            success: function (data) {
//                
//                if (data != "") {
//                    if (data == "0") {
//                        //竞拍完成产品跳转页面
//                        window.location.href = "paiproduct.aspx?PaiProductId=" + paiproductid;
//                    }
//                    else if (data == "-1") {
//                        alert("您的积分不够，请及时充值！");
//                    }
//                    else if (data == "-2") {
//                        alert("不能重复出价！");
//                    }
//                    else {
//                        
//                    }

//                }
//                else {
//                    alert("网络延迟！");
//                }
//            },
//            error: function (data) {
//             
//            }

//        });
    }
}

//刷新产品方法
function refreshPai(refreshproductid, type, page) {
    var now = new Date();
    var num = Math.random() * now.getSeconds();
    $.getJSON("http://paiserver.866.cn/Default.aspx?IdList=" + refreshproductid + "&Random=" + num + "&jsoncallback=?", function (result) {
        var data = result.Msg;
        if (data != "") {
            var bigarray = data.split("|");
            for (var i = 0; i < bigarray.length; i++) {
                if (bigarray[i] != "") {
                    var array = bigarray[i].split(",");
                    if ($("#productprice_" + array[6]).text() != array[0].toString()) {
                        //此处看到价格颜色变化
                        if (type == "0") {
                            ChangePriceFont(array[6], "name7 bold");
                            setTimeout("ChangePriceFont('" + array[6] + "','name4 bold')", 500);
                        }
                        else {
                            ChangePriceFont(array[6], "name10 bold");
                            setTimeout("ChangePriceFont('" + array[6] + "','pm-text')", 500);
                        }
                    }

                    $("#productprice_" + array[6]).html(array[0]);
                    $("#paicustomer_" + array[6]).text(array[1]);
                    timem1(array[2].toString(), array[3].toString(), array[4].toString(), array[6]);
                    if (array[5].toString() == "1") {
                        //倒计时10s样式
                        if (type == "0") {
                            ChangeTimeFont(array[6], "name9 bold");
                        }
                        else {
                            ChangeTimeFont(array[6], "name12 bold");
                        }
                    }
                    if (array[5].toString() == "2") {
                        //倒计时3s样式
                        if (type == "0") {
                            ChangeTimeFont(array[6], "name8 bold");
                        }
                        else {
                            ChangeTimeFont(array[6], "name11 bold");
                        }
                    }
                    if (array[5].toString() == "3" || array[5].toString() == "4") {
                        if (type == "0") {
                            ChangeTimeFont(array[6], "name9 bold");
                        }
                        else {
                            ChangeTimeFont(array[6], "name12 bold");
                        }
                        $("#paitime_" + array[6]).html("已结束");
                        if (type == "0") {
                            $("#PaiImg_" + array[6]).attr("src", "images/ms/ms-cj-menu2-1_03.gif");
                        }
                        else {
                            $("#PaiImg_" + array[6]).attr("src", "images/ms/ms-cj-menu-top-show.gif");
                        }
                        if (page == "index" && array[5].toString() == "4") {
                            GetCompletedPai(8);
                        }
                    }
                }
            }
        }
    });
//    $.ajax({
//        type: "POST",
//        url: 'AjaxInfo.ashx?RefreshProductId=' + refreshproductid + "&Random=" + num,
//        dataType: "text",
//        success: function (data) {
//            if (data != "") {
//                var bigarray = data.split("|");
//                for (var i = 0; i < bigarray.length; i++) {
//                    if (bigarray[i] != "") {
//                        var array = bigarray[i].split(",");
//                        if ($("#productprice_" + array[6]).text() != array[0].toString()) {
//                            //此处看到价格颜色变化
//                            if (type == "0") {
//                                ChangePriceFont(array[6], "name7 bold");
//                                setTimeout("ChangePriceFont('" + array[6] + "','name4 bold')", 500);
//                            }
//                            else {
//                                ChangePriceFont(array[6], "name10 bold");
//                                setTimeout("ChangePriceFont('" + array[6] + "','pm-text')", 500);
//                            }
//                        }

//                        $("#productprice_" + array[6]).html(array[0]);
//                        $("#paicustomer_" + array[6]).text(array[1]);
//                        timem1(array[2].toString(), array[3].toString(), array[4].toString(), array[6]);
//                        if (array[5].toString() == "1") {
//                            //倒计时10s样式
//                            if (type == "0") {
//                                ChangeTimeFont(array[6], "name9 bold");
//                            }
//                            else {
//                                ChangeTimeFont(array[6], "name12 bold");
//                            }
//                        }
//                        if (array[5].toString() == "2") {
//                            //倒计时3s样式
//                            if (type == "0") {
//                                ChangeTimeFont(array[6], "name8 bold");
//                            }
//                            else {
//                                ChangeTimeFont(array[6], "name11 bold");
//                            }
//                        }
//                        if (array[5].toString() == "3") {
//                            if (type == "0") {
//                                ChangeTimeFont(array[6], "name9 bold");
//                            }
//                            else {
//                                ChangeTimeFont(array[6], "name12 bold");
//                            }
//                            $("#paitime_" + array[6]).html("已结束");
//                            if (type == "0") {
//                                $("#PaiImg_" + array[6]).attr("src", "images/ms/ms-cj-menu2-1_03.gif");
//                            }
//                            else {
//                                $("#PaiImg_" + array[6]).attr("src", "images/ms/ms-cj-menu-top-show.gif");
//                            }
//                            if (page == "index") {
//                                GetCompletedPai(8);
//                            }
//                        }
//                    }
//                }
//            }
//        }
//    });
    setTimeout("refreshPai('" + refreshproductid + "','" + type + "','" + page + "')", 1000);
}

//竞拍时更改价格样式
function ChangePriceFont(paiproductid, className) {
    //$("pricefont_" + paiproductid).removeClass();
    //$("pricefont_" + paiproductid).css("class",className);
    document.getElementById("pricefont_" + paiproductid).className = className;
}

//竞拍成功记录
function GetCompletedPai(painum) {
    var now = new Date();
    var num = Math.random() * now.getSeconds();
    $.ajax({
        type: "POST",
        url: 'AjaxInfo.ashx?CompletedPai=' + painum + "&Random=" + num,
        dataType: "text",
        success: function (data) {
            if (data != "") {
                $("#ms_nowcompletedpai").html(data);
            }
            else {
            }
        }
    });
}

//竞拍产品记录即时
function RefreshPaiNote(paiproductid,type, painum) {
    var now = new Date();
    var num = Math.random() * now.getSeconds();
    $.ajax({
        type: "POST",
        url: 'AjaxInfo.ashx?NotPaiProductId=' + paiproductid + '&paiNum=' + painum + '&Random=' + num,
        dataType: "text",
        success: function (data) {
            if (data != "") {
                $("#news_con_0").html(data);
            }
            else {

            }
        }
    });
    if (type == 0) {
        //setTimeout("RefreshPaiNote('" + paiproductid + "','" + type + "','" + painum + "')", 1000);
    }
}
//刷新时间方法。提供结束时间和id,
function timem1(HH, MM, SS, id) {

    $("#paitime_" + id).html("<span> " + HH + " </span>:<span>" + MM + " </span>:<span>" + SS + " </span>");
}
//修改竞拍时间样式
function ChangeTimeFont(refreshproductid, className) {
    document.getElementById("paitime_" + refreshproductid).className = className;
}

/////////////////////////////////////////////////////////////////首页js///////////////////////////////////////////////////////////
//首页竞拍
function GetIndexPai() {
    var now = new Date();
    var num = Math.random() * now.getSeconds();
    $.ajax({
        type: "POST",
        url: 'AjaxInfo.ashx?do=ShowIndexPai&Random=' + num,
        dataType: "text",
        success: function (data) {
            if (data != "") {
                $("#IndexPai").html(data);
            }
            else {

            }
        }
    });

}

//首页限时抢购
function GetIndexChang() {
    var now = new Date();
    var num = Math.random() * now.getSeconds();
    $.ajax({
        type: "POST",
        url: 'AjaxInfo.ashx?do=ShowIndexQiang&Random=' + num,
        dataType: "text",
        success: function (data) {
            if (data != "") {
                var indexdata = data.split("|");
                $("#divScareBuying").html(indexdata[0]);
                timem(indexdata[1]);
            }
            else {
                $("#divScareBuying").html("<img src=\"images/common/scareBuying.gif\" alt=\"抢购活动尚未开始\" />");
            }
        }
    });
}

//头部文件登录状态
function GetIndexLoginStatus() {
    var now = new Date();
    var num = Math.random() * now.getSeconds();
    $.ajax({
        type: "POST",
        url: 'AjaxInfo.ashx?do=ShowIndexLoginStatus&Random=' + num,
        dataType: "text",
        success: function (data) {
            if (data != "") {
                $("#IndexLoginStatus").html(data);
            }
            else {

            }
        }
    });
}

/*
*获取生活服务部分内容
*/
function GetShengHuoHtml() {
    var now = new Date();
    var num = Math.random() * now.getSeconds();
    $.ajax({
        type: "POST",
        url: 'AjaxInfo.ashx?do=ShengHuoUrl&Random=' + num,
        dataType: "text",
        success: function (data) {
            if (data != "") {
                $("#divShengHuo").html(data);
            }
            else {

            }
        }
    });
}

//头部文件购物车
function GetIndexHeader() {
    var now = new Date();
    var num = Math.random() * now.getSeconds();
    $.ajax({
        type: "POST",
        url: 'AjaxInfo.ashx?do=ShowIndexHeader&Random=' + num,
        dataType: "text",
        success: function (data) {
            if (data != "") {
                $("#IndexHeader").html(data);
            }
            else {

            }
        }
    });
}

//首页会员信息（控件）
function GetIndexMemberInfo() {
    var now = new Date();
    var num = Math.random() * now.getSeconds();
    $.ajax({
        type: "POST",
        url: 'AjaxInfo.ashx?do=ShowIndexMemberInfo&Random=' + num,
        dataType: "text",
        success: function (data) {
            if (data != "") {
                $("#IndexMemberInfo").html(data);
            }
            else {

            }
        }
    });
}
 
