﻿//写cookies函数
function SetCookie(name, value)//两个参数，一个是cookie的名子，一个是值
{
    var Days = 30; //此 cookie 将被保存 30 天
    var exp = new Date();    //new Date("December 31, 9998");
    exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
    document.cookie = name + "=" + escape(value) + ";path=/;expires=" + exp.toGMTString();
}
function GetCookie(name) {
    var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
    if (arr != null) return unescape(arr[2]); return null;

}
//写cookies函数
function SetIeCookie(name, value)//两个参数，一个是cookie的名子，一个是值
{
    document.cookie = name + "=" + escape(value) + ";path=/;";
}
//str.trim()
String.prototype.trim = function() {
    return this.replace(/(^s*)|(s*$)/g, "");
}
function subshop() {
    var url = encodeURIComponent(window.location.href);
    var para = "../user/ShopingCart.aspx?subPath=" + url;
    window.location.href = para;
}
function delCookie(name) {
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval = getCookie(name);
    if (cval != null) document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
}
//编码程序： 
function CodeCookie(str) {
    var strRtn = "";
    for (var i = str.length - 1; i >= 0; i--) {
        strRtn += str.charCodeAt(i);
        if (i) strRtn += "|||"; //用a作分隔符 
    }
    return strRtn;
}
function UrlDecode(str) {
    var ret = "";
    for (var i = 0; i < str.length; i++) {
        var chr = str.charAt(i);
        if (chr == "+") {
            ret += " ";
        } else if (chr == "%") {
            var asc = str.substring(i + 1, i + 3);
            if (parseInt("0x" + asc) > 0x7f) {
                ret += asc2str(parseInt("0x" + asc + str.substring(i + 4, i + 6)));
                i += 5;
            } else {
                ret += asc2str(parseInt("0x" + asc));
                i += 2;
            }
        } else {
            ret += chr;
        }
    }
    return ret;
}
//url: "/webservice/mbmemberWS.asmx/Login",
function login() {
    var path = decodeURIComponent(QueryString("path"));
    var tempURL = window.location.href;
    var username = $("#tb_username").val();
    var password = $("#tb_password").val();

    if (username == "" || username == "帐号") { $("#userPannel-Tips").html("&nbsp;请输入用户名"); return; }
    if (password == "" || password == "密码") { $("#userPannel-Tips").html("&nbsp;请输入密码"); return; }

    $.ajax({
        type: "POST",
        contentType: "application/json;utf-8",
        url: "/webservice/mbmemberWS.asmx/Login",
        data: "{username:'" + username + "',password:'" + password + "'}",
        dataType: "json",
        success: function(result) {
            if (result.d.indexOf("_") > 0) {
                try {
                    var uservalue = result.d.split("_");
                    pageTracker._setCustomVar(2, "LoginUser_Marriage", uservalue[0], 1);
                    pageTracker._setCustomVar(3, "LoginUser_Gender", uservalue[1], 1);
                    pageTracker._setCustomVar(4, "LoginUser_Age", uservalue[2], 1);
                    pageTracker._setCustomVar(5, "LoginUser_Occupation", uservalue[3], 1);
                    pageTracker._setCustomVar(1, "Member", "Login", 1);
                    pageTracker._trackPageview("/loginSucc");
                }
                catch (err) { }
                if (path == ''|| path == 'null') {
                    window.location.href = tempURL;
                    //"/user/" + path;
                }
                else {
                    window.location.href = path;
                }
            }
            else {
                if(result.d == "你的账户未经过邮件认证")
                    window.location.href="/other/message.aspx?r=3";
                else
                    $("#userPannel-Tips").html("&nbsp;" + result.d);
            }
        }
    });
}

function loginnew() {
    var path = decodeURIComponent(QueryString("path"));
    var tempURL = window.location.href;
    var username = $("#tb_username").val();
    var password = $("#tb_password").val();

    if (username == "" || username == "帐号") { $("#userPannel-Tips").html("&nbsp;请输入用户名"); return; }
    if (password == "" || password == "密码") { $("#userPannel-Tips").html("&nbsp;请输入密码"); return; }

    $.ajax({
        type: "POST",
        contentType: "application/json;utf-8",
        url: "/webservice/mbmemberWS.asmx/Login",
        data: "{username:'" + username + "',password:'" + password + "'}",
        dataType: "json",
        success: function(result) {
            if (result.d.indexOf("_") > 0) {
                try {
                    var uservalue = result.d.split("_");
                    pageTracker._setCustomVar(2, "LoginUser_Marriage", uservalue[0], 1);
                    pageTracker._setCustomVar(3, "LoginUser_Gender", uservalue[1], 1);
                    pageTracker._setCustomVar(4, "LoginUser_Age", uservalue[2], 1);
                    pageTracker._setCustomVar(5, "LoginUser_Occupation", uservalue[3], 1);
                    pageTracker._setCustomVar(1, "Member", "Login", 1);
                    pageTracker._trackPageview("/loginSucc");
                }
                catch (err) { }
                if (path == '') {
                    window.location.href = tempURL;
                    //"/user/" + path;
                }
                else {
                    window.location.href = path;
                }
            }
            else {
                if(result.d == "你的账户未经过邮件认证")
                    window.location.href="/other/message.aspx?r=3";
                else
                    $("#userPannel-Tips").html("&nbsp;" + result.d);
            }
        }
    });
}

function loginen() {
    var path = QueryString("path");
    var username = $("#tb_username").val();
    var password = $("#tb_password").val();

    if (username == "" || username == "username") { $("#userPannel-Tips").html("&nbsp;Please input username"); return; }
    if (password == "" || password == "password") { $("#userPannel-Tips").html("&nbsp;Please input password"); return; }

    $.ajax({
        type: "POST",
        contentType: "application/json;utf-8",
        url: "/webservice/mbmemberWS.asmx/Loginen",
        data: "{username:'" + username + "',password:'" + password + "'}",
        dataType: "json",
        success: function(result) {
            if (result.d.indexOf("Invalid") == -1) {
                try {
                    var uservalue = result.d.split("_");
                    pageTracker._setCustomVar(2, "LoginUser_Marriage", uservalue[0], 1);
                    pageTracker._setCustomVar(3, "LoginUser_Gender", uservalue[1], 1);
                    pageTracker._setCustomVar(4, "LoginUser_Age", uservalue[2], 1);
                    pageTracker._setCustomVar(5, "LoginUser_Occupation", uservalue[3], 1);
                    pageTracker._setCustomVar(1, "Member", "Login", 1);
                    pageTracker._trackPageview("/loginSucc");
                }
                catch (err) { }
                if (path == '' || path==null) {
                    window.location.href = window.location.href;
                }
                else {
                    window.location.href = path;
                }
            }
            else {                
                if(result.d == "noactive")
                    window.location.href="/other/messageneweng.aspx?r=1";
                else
                    $("#userPannel-Tips").html("&nbsp;" + result.d);
            }
        }
    });
}
function Logout() {
    $.ajax({
        type: "POST",
        contentType: "application/json;utf-8",
        url: "../webservice/mbmemberWS.asmx/Logout",
        data: "{}",
        dataType: "json",
        success: function() {
            //window.location.reload();
            SetCookie("ShoppingCart", "");//清空购物车
            SetCookie("ShoppingCartSH", "");//清空购物车
            location.href="/DefaultNew.aspx";
        }
    });
}

function Logoutnew() {
    $.ajax({
        type: "POST",
        contentType: "application/json;utf-8",
        url: "../webservice/mbmemberWS.asmx/Logout",
        data: "{}",
        dataType: "json",
        success: function() {
            //window.location.reload();
            location.href="/DefaultNew.aspx";
        }
    });
}

function Vote(str) {
    $.ajax({
        type: "POST",
        contentType: "application/json;utf-8",
        url: "/webservice/LoginLogWS.asmx/BannerClick",
        data: "{yn:'" + str + "'}",
        dataType: "json",
        success: function() {
        }
    });
}
function SubmitKeyClick(btnName) {
    e = getEvent();
    if (e.keyCode == 13) {
        if (e && e.preventDefault)
        //阻止默认浏览器动作(W3C) 
            e.preventDefault();
        else
        //IE中阻止函数器默认动作的方式 
            window.event.returnValue = false;
        document.getElementById(btnName).click();
    }
}
//------------------
getEvent = function() {
    if (document.all) return window.event;
    func = this.getEvent.caller;
    while (func != null) {
        var arg0 = func.arguments[0];
        if (arg0) {
            if ((arg0.constructor == Event || arg0.constructor == MouseEvent) || (typeof (arg0) == "object" && arg0.preventDefault && arg0.stopPropagation)) {
                return arg0;
            }
        }
        func = func.caller;
    }
    return null;
}
//-------------------
//解码程序： 
function DecodeCookie(str) {
    var strArr;
    var strRtn = "";
    strArr = str.split("|||");
    for (var i = strArr.length - 1; i >= 0; i--)
        strRtn += String.fromCharCode(eval(strArr[i]));
    return strRtn;
}

//在URL地址上添加随机参数
function GetRandomURL() {
    var tempurl = window.location.toString();
    var randonnum = Math.ceil(Math.random() * 100);
    if (tempurl.indexOf("#") != -1) {
        window.location.reload();
    }
    else {
        if (tempurl.substring(tempurl.length - 4, tempurl.length) == "aspx" || tempurl.substring(tempurl.length - 4, tempurl.length) == "html" || tempurl.substring(tempurl.length - 3, tempurl.length) == "htm" || tempurl.indexOf("?t=") != -1) {
            if (tempurl.indexOf("?t=") != -1) {
                window.location = tempurl.substring(0, tempurl.indexOf("?t=")) + "?t=" + randonnum;
            }
            else {
                window.location = tempurl + "?t=" + randonnum;
            }
        }
        else {
            if (tempurl.substring(tempurl.length - 1, tempurl.length) == "/") {
                window.location = tempurl + "?t=" + randonnum;
            }
            else {
                if (tempurl.indexOf("&t=") != -1) {
                    window.location = tempurl.substring(0, tempurl.indexOf("&t=")) + "&t=" + randonnum;
                }
                else {
                    window.location = tempurl + "&t=" + randonnum;
                }
            }
        }
    }
}
//验证E-mail地址有效性
function isEmail(email) {
    var emailReg = /^[-_A-Za-z0-9+.]+@([_A-Za-z0-9]+\.)+[A-Za-z0-9]{2,3}$/;
    return emailReg.test(email);
}
function TopSearch() {
    var url = "/other/search__" + encodeURI(document.getElementById("ctl00_tb_keyword").value) + "______.htm";
    window.location.href = url;
}
function winPop() {
    var win = window.open('/user/protocol.aspx', 'pop3', 'height=486px, width=523px, top=50, left=40, toolbar=no, menubar=no, scrollbars=yes, resizable=no,location=no, status=no');
    win.focus();
}
function QueryString(sName) {
    var sSource = String(window.document.location);
    var sReturn = "";
    var sQUS = "?";
    var sAMP = "&";
    var sEQ = "=";
    var iPos;
    iPos = sSource.indexOf(sQUS);
    var strQuery = sSource.substr(iPos, sSource.length - iPos);
    var strLCQuery = strQuery.toLowerCase();
    var strLCName = sName.toLowerCase();
    iPos = strLCQuery.indexOf(sQUS + strLCName + sEQ);
    if (iPos == -1) {
        iPos = strLCQuery.indexOf(sAMP + strLCName + sEQ);
        if (iPos == -1)
            return "";
    }
    sReturn = strQuery.substr(iPos + sName.length + 2, strQuery.length - (iPos + sName.length + 2));
    var iPosAMP = sReturn.indexOf(sAMP);
    if (iPosAMP == -1)
        return sReturn;
    else {
        sReturn = sReturn.substr(0, iPosAMP);
    }
    return sReturn;
}
jQuery.fn.setSelectedText = function(text) {
    var objSelect = jQuery(this).get(0);
    for (var i = 0; i < objSelect.options.length; i++) {
        if (objSelect.options[i].text == text) {
            objSelect.options[i].selected = true;
            break;
        }
    }
}
function GetRedioValue(cname) {
    var Age = document.getElementsByName(cname);
    var AgeV = "";
    for (i = 0; i < Age.length; i++) {
        if (Age[i].checked)
            AgeV = Age[i].value;
    }
    return AgeV;
}
function InitCityStore(CityControl, StoreControl, cityName, storeName) {
    $.ajax({
        type: "POST",
        contentType: "application/json;utf-8",
        url: "/webservice/storeWS.asmx/GetCityOptions",
        async: false,
        data: "{cityName:'" + cityName + "'}",
        dataType: "json",
        success: function(result) {
            $("#" + CityControl).html(result.d);
            InitStoreByCity(CityControl, StoreControl, storeName);
        }
    });
}
function InitStoreByCity(CityControl, StoreControl, storeName) {
    var cityId = $("#" + CityControl).val();
    $.ajax({
        type: "POST",
        contentType: "application/json;utf-8",
        url: "/webservice/storeWS.asmx/GetStoreOptions",
        async: false,
        data: "{cityID:'" + cityId + "',storeName:'" + storeName + "'}",
        dataType: "json",
        success: function(result) {
            $("#" + StoreControl).html(result.d);
        }
    });
}
function addFav(type, oid) {
    var message = "";
    var messageen = "";
    var content = "";
    $.ajax({
        type: "POST",
        contentType: "application/json;utf-8",
        url: "../webservice/LoginLogWS.asmx/AddFav",
        data: "{favType:" + type + ",favId:" + oid + "}",
        dataType: "json",
        success: function(result) {
            switch (result.d) {
                case -1:
                    message = "请您登陆！";
                    messageen = "Your attempt was not successful. Please login.";
                    content = "对不起,您尚未登陆请在<strong>登陆</strong>后再进行操作。";
                    break;
                case 0:
                    message = "您已收藏过此项目！";
                    messageen = "This item has been added to your list.";
                    content = "您已收藏过此项目!您可以前往<a href='/user/myfav.aspx' class='colorRed'>您的收藏夹</a>查看您的收藏信息。";
                    break;
                default:
                    message = "成功加入收藏！";
                    messageen = "This item was successfully added to your list.";
                    content = "祝贺你！您已经成功将此项目加入您的收藏夹!您可以前往<a href='/user/myfav.aspx' class='colorRed'>您的收藏夹</a>查看您的收藏信息。";
                    break;
            }
            popBox.show('../pop/pop-favorites.html'
                    , function() {
                        $('#sp_message').html(message);
                        $('#sp_messageen').html(messageen);
                        $('#p_content').html(content)
                    });
        }
    });
}
function Judge(pid, pna, pcout) {
    $.ajax({
        type: "POST",
        contentType: "application/json;utf-8",
        url: "../webservice/myProductXiangXiCaChe.asmx/AddProductAttr",
        data: "{PromoProduct_ID:" + pid + ",Name_CN:'" + pna + "',ShuLiang:" + pcout + "}",
        dataType: "json",
        success: function(result) {
            if (result.d == "0") {
                window.location = "../other/message.aspx?path=<%=strLoginBackUrl %>";
            }
            else {
                var tempMess = result.d;
                if (tempMess == "继续") {
                    ProductAdd(pid, pna);
                }
                else {
                    PrintProductList(6, 1);
                }
            }
        }
    });
}
//-----------------------------------------------------------------最新添加“JYT”---------------------------------------------------------------------//
//商品详细页中的商品评论
var ispinglun;
function AddProductPingLun(userid,content,productid,pingfen) {
    if (content == "") {
        popBox.show('/pop/popmsg.htm', function() {
            $('#divMsg').html("评论内容不能为空！");
        });
        return;
    }
    popBox.removeAll();
     //判断是否评论过
    $.ajax({
        type: "POST",
        contentType: "application/json;utf-8",
        url: "../webservice/myProductXiangXiCaChe.asmx/IsPingLunProduct",
        data: "{ProductID:" + productid + ",UserID:" + userid + "}",
        dataType: "json",
        success: function(result) {
            if (result.d == "1")//每个商品每人只能评论一次
            {
                //alert('您已经评论过此商品，不能重复评论！');
                content="您已经评论过此商品，不能重复评论！";
                 popBox.show('/pop/popmsg.htm', function() {
                    $('#divMsg').html(content);
                });
                ispinglun = 1;
                return;
            }
            else {
                ispinglun = 0;
                $.ajax({
                    type: "POST",
                    contentType: "application/json;utf-8",
                    url: "../webservice/myProductXiangXiCaChe.asmx/AddProductPingLun",
                    data: "{PromoProduct_ID:" + productid + ",Content:'" + content + "',PingFen:" + pingfen + ",UserID:" + userid + "}",
                    dataType: "json",
                    success: function(result) {
                        if (result.d == "0") {
                            //alert('商品评论发布失败！');
                            content="商品评论发布失败！";
                             popBox.show('/pop/popmsg.htm', function() {
                                $('#divMsg').html(content);
                            });
                        }
                        else {
                            //alert('商品评论发布成功--谢谢您的支持，请等待审核！');
                            content="商品评论发布成功--谢谢您的支持，请等待审核！";
                            popBox.show('/pop/popmsg.htm', function() {
                                $('#divMsg').html(content);
                            });
                        }
                        
                    }
                });
            }
        }
    });
}

//添加浏览商品记录（非登录的用户）
function AddView(p_ProID) {
    $.ajax({
        type: "POST",
        contentType: "application/json;utf-8",
        url: "../webservice/ProductHistory.asmx/AddProductLiuLan",
        data: "{p_ProductID:" + p_ProID + ",Comment:0}",
        dataType: "json",
        success: function(result) {
             
        }
    });
}
//商品列表页中的加减数量按钮
function GetShuLiang(shu) {
    if (shu > 0) {
        $("#txtShuLiang").val(parseInt($("#txtShuLiang").val()) + 1);
    }
    else {
        if ($("#txtShuLiang").val() > 1) {
            $("#txtShuLiang").val(parseInt($("#txtShuLiang").val()) - 1);
        }
    }
}
//关闭评论层
function GuanBiPingLun() {
//    if (confirm('确定要取消评论吗?')) {
        $(".product_score_pop").hide();
//    }
}
//我购买过的商品和订单详细页中的关闭评论层
function extiPingLun() {
//    if (confirm('确定要取消评论吗?')) {
        $(".review_product_pop").hide();
    //}
}
//商品详细中评论点击事件
function PingLun(userid, productid,productname,buyshuliang,buyshijian) {
    $.ajax({
        type: "POST",
        contentType: "application/json;utf-8",
        url: "../webservice/myProductXiangXiCaChe.asmx/PanDuanProductIsCurrCity",
        data: "{ProductID:" + parseInt(productid)+"}",
        dataType: "json",
        success: function(result) {
            SubMitCurrentCityProductXiangXi(result.d,userid,productid,productname, buyshuliang, buyshijian);
        },
        error:function(result){ //目前程序执行这里
            SubMitCurrentCityProductXiangXi(result.d,userid,productid,productname,buyshuliang,buyshijian);
        }
    });
    
}

function SubMitCurrentCityProductXiangXi(result,userid,productid,productname,buyshuliang,buyshijian)
{
    if(result==0)
    {
        popBox.show('/pop/popmsg.htm', function() {
            $('#divMsg').html("当前商品不属于当前城市不能进行评论！");
        });
    }
    else
    {
        if (userid > 0)// 判断用户判断先登录才能发布评论
        {
            if ($("#ctl00_ContentPlaceHolder2_hidShiFouGouMai").val() == "0")//判断用户有没有购买过此商品
            {
                var content="对不起您没有购买此商品不能进行评论！";
                    popBox.show('/pop/popmsg.htm', function() {
                        $('#divMsg').html(content);
                    });
            }
            else {
                $.ajax({
                    type: "POST",
                    contentType: "application/json;utf-8",
                    url: "../webservice/myProductXiangXiCaChe.asmx/IsPingLunProduct",
                    data: "{ProductID:" + productid + ",UserID:" + userid + "}",
                    dataType: "json",
                    success: function(result) {
                        if (result.d == "1")//每个商品每人只能评论一次
                        {
                            var content="您已经评论过此商品，不能重复评论！";
                            popBox.show('/pop/popmsg.htm', function() {
                                $('#divMsg').html(content);
                            });
                            return;
                        }
                        else {
                            popBox.show('/pop/poppinglun.htm', function() {ChangeStarColor();$('#lblProductNameNew').html(productname);$('#lblShuLiangNew').html(buyshuliang);$('#lblGouMaiShiJianNew').html(buyshijian);$('#hidUserID').val(userid);$('#hidProductID').val(productid);});
                        }
                    }
                });
            }
        }
        else {
            var content="请您先<a href='javascript:fcnLogin();' style='color:blue;'>登陆</a>在进行评论,谢谢！";
            popBox.show('/pop/popmsg.htm', function() {
                $('#divMsg').html(content);
            });
        }
    }
}

//控制商品详细页中的评论弹出层回调改变星的着色
function ChangeStarColor()
{
    // 切换星星显示隐藏
    $('#score_contentnew img').eq(0).mouseover(function() {
        $(this).attr("src", "../images/sales/solidstar_big.gif");
        $("#score_contentnew img:gt(0)").attr("src", "../images/sales/hollowstar_big.gif");
        $("#score_contentnew>span").text("1分");
        $("#hidPingFen").val("1");
    });
    $('#score_contentnew img').eq(1).mouseover(function() {
        $(this).attr("src", "../images/sales/solidstar_big.gif");
        $("#score_contentnew img:lt(1)").attr("src", "../images/sales/solidstar_big.gif");
        $("#score_contentnew img:gt(1)").attr("src", "../images/sales/hollowstar_big.gif");
        $("#score_contentnew>span").text("2分");
        $("#hidPingFen").val("2");
    });
    $('#score_contentnew img').eq(2).mouseover(function() {
        $(this).attr("src", "../images/sales/solidstar_big.gif");
        $("#score_contentnew img:lt(2)").attr("src", "../images/sales/solidstar_big.gif");
        $("#score_contentnew img:gt(2)").attr("src", "../images/sales/hollowstar_big.gif");
        $("#score_contentnew>span").text("3分");
        $("#hidPingFen").val("3");
    });
    $('#score_contentnew img').eq(3).mouseover(function() {
        $(this).attr("src", "../images/sales/solidstar_big.gif");
        $("#score_contentnew img:lt(3)").attr("src", "../images/sales/solidstar_big.gif");
        $("#score_contentnew img:gt(3)").attr("src", "../images/sales/hollowstar_big.gif");
        $("#score_contentnew>span").text("4分");
        $("#hidPingFen").val("4");
    });
    $('#score_contentnew img').eq(4).mouseover(function() {
        $(this).attr("src", "../images/sales/solidstar_big.gif");
        $("#score_contentnew img:lt(4)").attr("src", "../images/sales/solidstar_big.gif");
        $("#score_contentnew img:gt(4)").attr("src", "../images/sales/hollowstar_big.gif");
        $("#score_contentnew>span").text("5分");
        $("#hidPingFen").val("5");
    });
}

//我购买过的商品和订单详细页中的评论点击事件
function OrderPingLun(userid,productid, productname, shuliang, shijian, rowindx) {
    $("#shopcart_content").hide();
    $.ajax({
        type: "POST",
        contentType: "application/json;utf-8",
        url: "../webservice/myProductXiangXiCaChe.asmx/PanDuanProductIsCurrCity",
        data: "{ProductID:" + parseInt(productid)+"}",
        dataType: "json",
        success: function(result) {
            SubMitCurrentCityProduct(result.d,userid,productid,productname, shuliang, shijian, rowindx);
        },
        error:function(result){ //目前程序执行这里
            SubMitCurrentCityProduct(result.d,userid,productid,productname, shuliang, shijian, rowindx);
        }
    });
    
}

function SubMitCurrentCityProduct(result,userid,productid,productname, shuliang, shijian, rowindx)
{
    if(result==0)
    {
        popBox.show('/pop/popmsg.htm', function() {
            $('#divMsg').html("当前商品不属于当前城市不能进行评论！");
        });
    }
    else
    {
        popBox.show('/pop/poporderpinglun.htm', function() {ChangeStarColor();$('#lblProductNameNew').html("商品名称："+productname);$('#lblShuLiangNew').html("购买数量："+shuliang);$('#lblGouMaiShiJianNew').html("购买时间："+shijian);$('#hidUserID').val(userid);$('#hidProductID').val(productid);});
    }
}
//添加我购买过的商品和订单详细页中的评论内容
function AddOrderProductPingLun(userid, content,productid,pingfen) {
    if (content == "") {
         popBox.show('/pop/popmsg.htm', function() {
            $('#divMsg').html("请填写评论内容！");
        });
        return;
    }
    $.ajax({
        type: "POST",
        contentType: "application/json;utf-8",
        url: "../webservice/myProductXiangXiCaChe.asmx/AddProductPingLun",
        data: "{PromoProduct_ID:" + productid + ",Content:'" + content + "',PingFen:" + pingfen + ",UserID:" + userid + "}",
        dataType: "json",
        success: function(result) {
            GetOrderResult(result.d,productid);
        },
        error:function(result){ //目前程序执行这里
            GetOrderResult(result.d,productid);
        }
    });
}

function GetOrderResult(result,productid)
{
    if (result == "0") {
         popBox.show('/pop/popmsg.htm', function() {
            $('#divMsg').html("商品评论发布失败！");
        });
    }
    else {
        var ordercount = $(".sortlist_content ul").length;
        for (var orderindx = 0; orderindx < ordercount; orderindx++) {
            if ($("#txtProID" + orderindx).val() == productid) {
                $("#pinglun" + orderindx).hide();
            }
            //订单详细页是否评论过此商品可见不可见
        }
        popBox.removeAll();
         popBox.show('/pop/popmsg.htm', function() {
            $('#divMsg').html("商品评论发布成功--谢谢您的支持，请等待审核！");
        });
    }
}

//商品详细页中上传图片点击事件
function AddUpPic(userid,productname) {
    var count = $("#ctl00_ContentPlaceHolder2_picuploadcount").val();
    var productid=$("#ctl00_ContentPlaceHolder2_hidProductID").val();
    if (userid > 0) {
        if (count > 0 && count < 4) {
            var content='您对此商品已上传' + count + '张图片,还能上传' + (4 - count) + '张！';
            popBox.show('/pop/popmsg.htm', function() {
                $('#divMsg').html(content);
                $('.pop-btn').click(function(){
                    popBoxNew.show('/pop/popuploadpic.aspx?productid='+productid+'&name='+productname,'type=iframe&width=479&height=288');
                });
                $('.close').click(function(){
                    popBoxNew.show('/pop/popuploadpic.aspx?productid='+productid+'&name='+productname,'type=iframe&width=479&height=288');
                });
            });
            return;
        }
        if (count == 4) {
            var content="报歉，您对此商品已上传够4张图片，不能在上传！";
             popBox.show('/pop/popmsg.htm', function() {
                $('#divMsg').html(content);
            });
        }
        else {
            popBoxNew.show('/pop/popuploadpic.aspx?productid='+productid+'&name='+productname,'type=iframe&width=479&height=288');
        }
    }
    else {
        var content="请您先<a href='javascript:fcnLogin();' style='color:blue;'>登陆</a>在进行上传商品图片,谢谢！";
        popBox.show('/pop/popmsg.htm', function() {
            $('#divMsg').html(content);
        });
    }
}
//商品详细页中关闭上传图片层
function GuanBiUpPic() {
    document.getElementById('MyFile').innerHTML = "";
    var str = '文件：<input id="File1" type="file" name="File" style="width: 350px;height:25px;"/>';
    document.getElementById('MyFile').insertAdjacentHTML("beforeEnd", str);
    $("#trPic").show();
}



    //商品详细页上传图片层中的上传点击事件触发后台的事件
function objClick() {
    var picurl=$('#File1').val();
    if(typeof picurl =="undefined" || picurl.trim().length==0)
    {
        $('#sptip').show();
    }
    else
    {
        $('#sptip').hide();
    }
}   



//判断收藏属性
function panduanshoucangshuxing(productid, productno, ispropertys, userid) {
    if (userid == 0) {
        var content="对不起,您尚未登陆请在<a href='javascript:fcnLogin();' style='color:blue;'>登陆</a>后再进行操作。";
        popBox.show('/pop/popmsg.htm', function() {
            $('#divMsg').html(content);
        });
        SetCookie("ShouCangID",productid);
        return;
    }
    addShouCang(productid, productno);
}

function fcnLogin()
{
    popBox.removeAll();
    CF.common.userPannel.showPrompt('#userPannel-userLogin');
}

//添加收藏
function addShouCang(productid, productno) {
    //得到商品详细页中的商品属性值
    var propertys = $("#txtProperty").val();
    if (typeof propertys == "undefined") {
        propertys = "";
    }
    else {
        propertys = "";
    }
    var content = "";
    $.ajax({
        type: "POST",
        contentType: "application/json;utf-8",
        url: "../webservice/myProductXiangXiCaChe.asmx/AddShouCangJia",
        data: "{ProductID:" + productid + ",ProductNo:'" + productno + "',Propertys:'" + propertys + "'}",
        dataType: "json",
        success: function(result) {
            switch (result.d) {
                case -1:
                    content = "对不起,您尚未登陆请在<a href='javascript:fcnLogin();' style='color:blue;'>登陆</a>后再进行操作。";
                    //CF.common.userPannel.showPrompt('#userPannel-userLogin');
                    SetCookie("ShouCangID",productid);
                    break;
                case -2:
                    content = "您已收藏过此项目！";
                    break;
                default:
                    content = "收藏成功！";
                    break;
            }
            popBox.show('/pop/popmsg.htm', function() {
                $('#divMsg').html(content);
            });
        }
    });
}
//删除收藏夹信息
function DelShouCang(userid, indx) {
    var str = "";
    $(":checkbox:checked").each(function(){
        str += $(this).val() + ",";
    })
    if (str.length == 0) {
        //alert('请选择要删除的收藏列表！'); 
        var content="请选择要删除的收藏列表！";
         popBox.show('/pop/popmsg.htm', function() {
            $('#divMsg').html(content);
        });
        return;
    }
    
    var content="确定要删除收藏此商品吗? ";
    popBox.show('/pop/popmsgalter.htm', function() {
        $('#hidProductID').val(str);
        $('#hidProperty').val(userid);
        $('#hidClear').val("1");
        $('#divMsg').html(content);
    });
}
//最后新加的单个删除功能
function DelShouCangDan(userid,productid) {
    productid=productid+";;,";
    var content="确定要删除收藏此商品吗? ";
    popBox.show('/pop/popmsgalter.htm', function() {
        $('#hidProductID').val(productid);
        $('#hidProperty').val(userid);
        $('#hidClear').val("0");
        $('#divMsg').html(content);
    });
}

var zhanshiindx = 0;
function ShouCangZhanShi(indx) {
    if (indx > 0) {
        zhanshiindx = indx;
    }
    if (indx == -1 && zhanshiindx > 0) {
        zhanshiindx = zhanshiindx - 1;
    }
    if (indx == 0 && zhanshiindx >= 0) {
        zhanshiindx = zhanshiindx + 1;
    }
    if (zhanshiindx == 1) {
        $("#span1").css("color", "red");
        $("#span2").css("color", "blue");
        $("#span3").css("color", "blue");
        alert('主题收藏');
    }
    if (zhanshiindx == 2) {
        $("#span2").css("color", "red");
        $("#span1").css("color", "blue");
        $("#span3").css("color", "blue");
        alert('期刊收藏');
    }
    if (zhanshiindx == 3) {
        $("#span3").css("color", "red");
        $("#span1").css("color", "blue");
        $("#span2").css("color", "blue");
        alert('门店收藏');
    }

}

//如果先点了全选最后又取消一个复选但是全选还是在选择呢
function panduanxuanzhong(obj) {
    if (!obj.checked) {
        $('#btnSelAll').attr("checked", false);
    }
}

function panduanshopcartxuanzhong(obj) {
    if (!obj.checked) {
        $('#SelAll').attr("checked", false);
    }
}

//页面加载完毕后执行
$(function() {
    var count = $(".sortlist_content ul").length + 1;
    //收藏夹全选          
    $('.btnSelAll').click(function() {
        if ($('.btnSelAll').text() == "全选") {
            for (var i = 1; i < count; i++) {
                $('#checkAll' + i).attr("checked", true);
            }
            $(".btnSelAll").text("反选");
        }
        else {
            for (var a = 1; a < count; a++) {
                $('#checkAll' + a).attr("checked", false);
            }
            $(".btnSelAll").text("全选");
        }
    });

    //控制收藏夹列表中的加入购物车按钮是否可见
    for (var j = 1; j < count; j++) {
        if (parseInt($("#txtonshow" + j).val()) == 1) {
            $("#AddCache" + j).show();
        }
        else {
            $("#AddCache" + j).hide();
        }
    }

    // 订单详情中的全选input复选框
    $(".select_all").click(function() {
        var txt = $(".select_all").text();
        if (txt == "全选") {
            $(".sortlist_content>ul>li>input:checkbox").attr("checked", true);
            $(".select_all").text("反选");
        }
        else {
            $(".sortlist_content>ul>li>input:checkbox").attr("checked", false);
            $(".select_all").text("全选");
        }
    });
    //更多购物车中的全选
    $(".SelAll").click(function() {
        if ($(".SelAll").text() == "全选") {
            $("#shopping_cart input:checkbox").attr("checked", true);
            $(".SelAll").text("反选");
        }
        else {
            $("#shopping_cart input:checkbox").attr("checked", false);
            $(".SelAll").text("全选");
        }

    });

    //控制订单对应商品列表的加入购物车按钮是否可见
    var ordercount = $(".sortlist_content ul").length;
    for (var orderindx = 0; orderindx < ordercount; orderindx++) {
        if (parseInt($("#txtorderonshow" + orderindx).val()) == 1) {
            $("#AddOrderCache" + orderindx).show();
        }
        else {
            $("#AddOrderCache" + orderindx).hide();
             $("a#sortlist_contentli_second"+orderindx).attr("href","javascript:"); 
             $("a#sortlist_contentli_img"+orderindx).attr("href","javascript:");
             $("a#sortlist_contentli_second"+orderindx).attr("target",""); 
             $("a#sortlist_contentli_img"+orderindx).attr("target","");
             
            if (orderindx < 10) {
                $("#ctl00_ContentPlaceHolder2_rptOrderXiangXi_ctl0" + orderindx + "_lblGouMaiPrice").html("下架");
                $("#ctl00_ContentPlaceHolder2_rptOrderXiangXi_ctl0" + orderindx + "_lblGouMaiPrice").css("color", "red");
                $("#ctl00_ContentPlaceHolder2_rptOrderXiangXi_ctl0" + orderindx + "_lblGouMaiPrice").css("font-weight", "bold");
            }
            else {
                $("#ctl00_ContentPlaceHolder2_rptOrderXiangXi_ctl" + orderindx + "_lblGouMaiPrice").html("下架");
                $("#ctl00_ContentPlaceHolder2_rptOrderXiangXi_ctl" + orderindx + "_lblGouMaiPrice").css("color", "red");
                $("#ctl00_ContentPlaceHolder2_rptOrderXiangXi_ctl" + orderindx + "_lblGouMaiPrice").css("font-weight", "bold");
            }
        }

        //订单详细页是否评论过此商品可见不可见
        var shifoupinglun;
        if (orderindx < 10) {
            shifoupinglun = $("#ctl00_ContentPlaceHolder2_rptOrderXiangXi_ctl0" + orderindx + "_hidPingLun").val();
        }
        else {
            shifoupinglun = $("#ctl00_ContentPlaceHolder2_rptOrderXiangXi_ctl" + orderindx + "_hidPingLun").val();
        }
        if (shifoupinglun == "1")//评论过
        {
            $("#pinglun" + orderindx).hide();
        }
        else {
            $("#pinglun" + orderindx).show();
        }
    }


    // 切换星星显示隐藏
    $("#score_content img").eq(0).mouseover(function() {
        $(this).attr("src", "../images/sales/solidstar_big.gif");
        $("#score_content img:gt(0)").attr("src", "../images/sales/hollowstar_big.gif");
        $("#score_content>span").text("1分");
    });
    $("#score_content img").eq(1).mouseover(function() {
        $(this).attr("src", "../images/sales/solidstar_big.gif");
        $("#score_content img:lt(1)").attr("src", "../images/sales/solidstar_big.gif");
        $("#score_content img:gt(1)").attr("src", "../images/sales/hollowstar_big.gif");
        $("#score_content>span").text("2分");
    });
    $("#score_content img").eq(2).mouseover(function() {
        $(this).attr("src", "../images/sales/solidstar_big.gif");
        $("#score_content img:lt(2)").attr("src", "../images/sales/solidstar_big.gif");
        $("#score_content img:gt(2)").attr("src", "../images/sales/hollowstar_big.gif");
        $("#score_content>span").text("3分");
    });
    $("#score_content img").eq(3).mouseover(function() {
        $(this).attr("src", "../images/sales/solidstar_big.gif");
        $("#score_content img:lt(3)").attr("src", "../images/sales/solidstar_big.gif");
        $("#score_content img:gt(3)").attr("src", "../images/sales/hollowstar_big.gif");
        $("#score_content>span").text("4分");
    });
    $("#score_content img").eq(4).mouseover(function() {
        $(this).attr("src", "../images/sales/solidstar_big.gif");
        $("#score_content img:lt(4)").attr("src", "../images/sales/solidstar_big.gif");
        $("#score_content img:gt(4)").attr("src", "../images/sales/hollowstar_big.gif");
        $("#score_content>span").text("5分");
    });
    if (GetCookie("City") != null && (GetCookie("City").toString() == "北京" || GetCookie("City").toString() == "åäº¬" || GetCookie("City").toString() == "ä¸æµ·" || GetCookie("City").toString() == "上海")) {
        //得到购物车信息ä¸æµ·
        try
        {
            getBottomShoppingCart();
            cartshopkuang();
        }
        catch(ex)
        {
        }
    }    //判断是否是首页，如果是首页让下拉可见否则不可见
    //var listxianshi = $("#hidpanduanlistenable");
    //if (typeof listxianshi.val() != 'undefined') {
        //$("#product-sale-bg").show();
        //$("#product-sale-close").hide();
   // }
    //促销和最新图片样式
    $("#divPromotionAndNew img").eq(0).hover(function(){
        $(this).attr("src", "../images/promotion_index_on.gif");
        if($("#ctl00_ContentPlaceHolder2_Sales_ContentLeft1_hidIsClass").val()!="2")
        {
            $("#divPromotionAndNew img").eq(1).attr("src", "../images/new_index_b.gif");
        }
    });
    $("#divPromotionAndNew img").eq(1).hover(function(){
        $(this).attr("src", "../images/new_index_on.gif");
        if($("#ctl00_ContentPlaceHolder2_Sales_ContentLeft1_hidIsClass").val()!="0")
        {
            $("#divPromotionAndNew img").eq(0).attr("src", "../images/promotion_index_b.gif");
        }
    });
    //促销和最新图片样式鼠标移开效果
    $("#divPromotionAndNew img").eq(0).mouseout(function(){
        if($("#ctl00_ContentPlaceHolder2_Sales_ContentLeft1_hidIsClass").val()!="0")
        {
            $(this).attr("src", "../images/promotion_index_b.gif");
        }
        
    });
    $("#divPromotionAndNew img").eq(1).mouseout(function(){
        if($("#ctl00_ContentPlaceHolder2_Sales_ContentLeft1_hidIsClass").val()!="2")
        {
            $(this).attr("src", "../images/new_index_b.gif");
        }
        
    });

   //让商品列表页中左边的促销图标变亮
    if($("#ctl00_ContentPlaceHolder2_Sales_ContentLeft1_hidIsClass").val()=="0")
   {
        $("#divPromotionAndNew img").eq(0).attr("src", "../images/promotion_index_on.gif");
        $("#hrefPromotion").css("color","#5cb6e4");
   }
    //让商品列表页中左边的最新图标变亮
    if($("#ctl00_ContentPlaceHolder2_Sales_ContentLeft1_hidIsClass").val()=="2")
   {
        $("#divPromotionAndNew img").eq(1).attr("src", "../images/new_index_on.gif");
        $("#hrefNew").css("color","#5cb6e4");
   }
   
    
    
});

    
function SelShoppingCart() {
    $("#shopcart_content").show();
}

//点击订单详细页中的购买按钮
function OrderBuy() {
    //判断当前订单是不是当前城市的
    var cityx=$("#ctl00_ContentPlaceHolder2_CityX").val();
    var cityy=$("#ctl00_ContentPlaceHolder2_CityY").val();
    if(cityx!=cityy)
    {
        var content="此订单不属于当前城市，不能加入购物车！";
        popBox.show('/pop/popmsg.htm', function() {
            $('#divMsg').html(content);
        });
        return;
    }
    $("#divmessage").html("");
    $("#shopcart_content").hide();
    var str = "";
    $(":checkbox:checked").each(function(){
        str += $(this).val() + ",";
    })
    if (str.length == 0) {
        //alert('请选择要购买的商品！');
        var content="请选择要购买的商品！";
         popBox.show('/pop/popmsg.htm', function() {
            $('#divMsg').html(content);
        });
        return;
    }
    var strSplt = str.split(',');
    for (var i = 0; i < strSplt.length - 1; i++) {
        var productid = strSplt[i].split(';')[0];
        var indx=strSplt[i].split(';')[1];
        var productname = strSplt[i].split(';')[2];
        var propertys = strSplt[i].split(';')[3];
        var maxbuyshu = $("#hidMaxBuyShu"+indx).val();
        btnOrderShownew(productid, 1, maxbuyshu, productname, propertys);
    }
    //$("#shopcart_content").show();
}

//订单详细、购买过的商品的购买点击添加购物车
function btnOrderShownew(productid, intShuLiang, maxbuyshu, productname, propertys) {
    var isflat = false;
    var panduanshu = 0;
    var strproduct="";
    //判断购物车中大小五条的购物车中是是否存在此商品
    $.ajax({
        type: "POST",
        contentType: "application/json;utf-8",
        url: "../webservice/ShoppingCarts.asmx/PanDuanCunZaiProduct",
        data: "{Product_ID:" + productid + ",Propertys:'" + propertys + "'}",
        dataType: "json",
        success: function(result) {
            if(result.d=="-1")//管理员有没有删除商品表中的此商品信息或下架
            {
                strproduct +="商品：<<"+productname+">>已经下架,加入购物车失败；<br />";
                $("#divmessage").append(strproduct);
            }
            else
            {
                if(result.d=="-2")//判断当前加入购物车的商品是否下架
                {
                    strproduct +="商品：<<"+productname+">>已缺货,加入购物车失败；<br />";
                    $("#divmessage").append(strproduct);
                }
                else if(result.d=="-3")
                {
                    strproduct +="商品：<<"+productname+">>不属于当前城市商品,加入购物车失败；<br />";
                    $("#divmessage").append(strproduct);
                }
                else
                {
                    if(result.d=="1" || result.d==1)//购物车中是否存在此商品
                    {
                       isflat=true;
                       panduanshu = parseInt(maxbuyshu) - parseInt(intShuLiang);
                       if(panduanshu==0)
                        {
                            //alert('购买失败，此商品最大购买数量为'+maxbuyshu);
                            var content="商品：<<"+productname+">>购买失败，此商品最大购买数量为"+maxbuyshu;
                            popBox.show('/pop/popmsg.htm', function() {
                                $('#divMsg').html(content);
                            });
                        }
                        else
                        {
                            ordershifoucunzai(isflat, panduanshu, maxbuyshu, productid, productname, intShuLiang, propertys);
                        }
                    }
                    else
                    {
                        ordershifoucunzai(isflat, panduanshu, maxbuyshu, productid, productname, intShuLiang, propertys);
                    }
                }
            }
        }
    });
    
}

//订单详细、购买过的商品的购买点击添加购物车时判断购物车中是否存在此商品
function ordershifoucunzai(isflat, panduanshu, maxbuyshu, productid, productname, intShuLiang, propertys) {
    var shuxing = "";
    if (propertys.length > 0) {
        shuxing = "(" + propertys + ")";
    }
    if (isflat) {
        //判断购物车中大小五条的购物车中是是否存在此商品
        if (panduanshu > maxbuyshu) 
        {
            //alert('您最多购买<' + productname + shuxing + '>商品数量为' + maxbuyshu);
            var content="您最多购买<"+productname+shuxing+">商品数量为"+maxbuyshu;
            popBox.show('/pop/popmsg.htm', function() {
                $('#divMsg').html(content);
            });
        }
        else {
            var timer = setTimeout("show()",300);
            AddShoppingCart(productid, intShuLiang, propertys);
            clearTimeout(timer);
        }
    }
    else {
        AddShoppingCart(productid, intShuLiang, propertys);
    }
}
//空方法(有用不要删除,延时用)
function show()
{
$("#shopcart_content").show();
}

//点击商品收藏页中的加入购物车
function OrderBuyFavorite() {
    ClearToop();
    $("#divmessage").html("");
    $("#shopcart_content").hide();
    var str = "";
    $(":checkbox:checked").each(function(){
        str += $(this).val() + ",";
    })
    if (str.length == 0) {
        var content="请选择要加入购物车的商品！";
        popBox.show('/pop/popmsg.htm', function() {
            $('#divMsg').html(content);
        });
        return;
    }
    var strSplt = str.split(',');
    for (var i = 0; i < strSplt.length - 1; i++) {
        var productid = strSplt[i].split(';')[0];
        var propertys = strSplt[i].split(';')[1];
        var indx=strSplt[i].split(';')[2];
        var productname = strSplt[i].split(';')[3];
        var maxbuyshu = $("#hidMaxBuyShu"+indx).val();
        btnOrderShownew(productid, 1, maxbuyshu, productname, propertys);
    }
}

//订单详细页激活此订单
function ActionTheOrder(orderid) {
        //判断当前订单是不是当前城市的
        var cityx=$("#ctl00_ContentPlaceHolder2_CityX").val();
    var cityy=$("#ctl00_ContentPlaceHolder2_CityY").val();
    if(cityx!=cityy)
    {
        var content="此订单不属于当前城市，不能加入购物车！";
        popBox.show('/pop/popmsg.htm', function() {
            $('#divMsg').html(content);
        });
        return;
    }
        popBox.show('/pop/popmsg.htm', function() {
            $(".popBox-main").html("&nbsp;&nbsp;");
            $('#divMsg').html("此订单正在激活中，请稍候...");
        });
    ////$(".sortlist_content input:checkbox[name='checkboxyincang']").attr("checked",true); 
    //if (confirm('确认要激活此订单吗？')) {
        var ordercount = $(".sortlist_content ul").length;
        if (ordercount == 0) {
            //alert('此订单中没有商品！');
            var content="此订单中没有商品！";
             popBox.show('/pop/popmsg.htm', function() {
                $('#divMsg').html(content);
            });
            return;
        }
        
        //判断得到下架的商品
        var strOffMessage="";
        var offindex=0;
        var message="";
        for(var i=0;i<ordercount;i++)
        {
            if (parseInt($("#txtorderonshow" + i).val()) != 1) //下架
            {
                strOffMessage +=$("#sortlist_contentli_second"+i).html()+";";
                offindex++;
            }
        }
        if(offindex<ordercount)
        {
            $.ajax({
                type: "POST",
                contentType: "application/json;utf-8",
                url: "../webservice/ShoppingCarts.asmx/ActionOrderToShoppingcart",
                data: "{OrderID:" + orderid + "}",
                dataType: "json",
                success: function(result) { //不会进这里，因为这里用的是cookie，使用多个时提示未实例化
                    if (result.d == "0") {
                        message="此订单激活失败";
                         popBox.show('/pop/popmsg.htm', function() {
                            $('#divMsg').html(message);
                        });
                    }
                    else {
                        message="此订单激活成功";
                        if(strOffMessage.length>0)
                        {
                            //alert(message+",商品：<<"+(strOffMessage.substr(0,strOffMessage.length-1))+">>已经下架，没有加入购物车中！");
                            var content=message+",商品：<<"+(strOffMessage.substr(0,strOffMessage.length-1))+">>已经下架，没有加入购物车中！";
                             popBox.show('/pop/popmsg.htm', function() {
                                $('#divMsg').html(content);
                            });
                        }
                        else
                        {
                             popBox.show('/pop/popmsg.htm', function() {
                                $('#divMsg').html(content);
                            });
                        }
                        if(offindex<ordercount)
                        {
                            peisong();
                        }
                    }
                },
                error:function(result){ //目前程序执行这里
                     if(parseInt(GetCookie("ActionState"))==(ordercount-offindex))
                     {
                        SetCookie("ActionState","0");
                        message="此订单激活成功";
                        if(strOffMessage.length>0)
                        {
                            var content=message+",商品：<<"+(strOffMessage.substr(0,strOffMessage.length-1))+">>已经下架，没有加入购物车中！";
                           // $("#divMsg").append(content);
                           $("#divmessage").append(content);
                            //alert($("#divMsg").html());
                        }
                        else
                        {
                              popBox.show('/pop/popmsg.htm', function() {
                                    $('#divMsg').html(message);
                                });
                        }
                        if(offindex<ordercount)
                        {
                            if(offindex==0)
                            {
                                peisong();
                            }
                            else
                            {
                                popBox.show('/pop/popmsg.htm', function() {
                                    $('#divMsg').html($("#divmessage").html());
                                });
                                peisong();
                            }
                        }
                     }
                     else
                     {
                        //alert('此订单激活失败');
                        message="此订单激活失败！";
                         popBox.show('/pop/popmsg.htm', function() {
                            $('#divMsg').html(message);
                        });
                     }
                }
            });
        }
        else
        {
            message="此订单激活失败，该订单中的商品全部下架";
            $(".pop_small p").html(message);
            $(".pop_small").show();
        }
}

function peisong() {
    location.href = "../sales/ShoppingCart-PeiSongXinXi.aspx";
}

function winOpen(productid) {
    window.open('productmingxi.aspx?product_id=' + productid + '&isref=1', '_blank');
}

function winOpenNoref(productid) {
    window.open('../sales/productmingxi.aspx?product_id=' + productid, '_blank');
}
function winopendefault(productid,protype)
{
    window.open('../sales/productmingxi.aspx?product_id=' + productid+'&protype='+protype, '_blank');
}
//分页跳转
//function UrlTran(val) {
//    var classone = $("#ctl00_ContentPlaceHolder2_hidClassOneID").val();
//    var classtwo = $("#ctl00_ContentPlaceHolder2_hidClassID").val();
//    var classthree = $("#ctl00_ContentPlaceHolder2_hidSubClass").val();
//    location.href = "productlistnew.aspx?ClassOneID=" + escape(classone) + "&class=" + escape(classtwo) + "&subclass=" + escape(classthree) + "&pagesize=12&pageindex=" + val;
//}
//排序
function PagePaiXu(obj) {
    document.getElementById(obj).click();
}

//筛选
function SelectClass(obj,strVal)
{
    $("#ctl00_ContentPlaceHolder2_hidClassName").val(strVal);
    document.getElementById(obj).click();
}

//商品列表页图片等比压缩
var flag = false;
function DrawImage(ImgD) {
    var image = new Image();
    image.src = ImgD.src;
    if (image.width > 0 && image.height > 0) {
        flag = true;
        if (image.width / image.height >= 145 / 145) {
            if (image.width > 145) {
                ImgD.width = 145;
                ImgD.height = (image.height * 145) / image.width;
            } else {
                ImgD.width = image.width;
                ImgD.height = image.height;
            }
        }
        else {
            if (image.height > 145) {
                ImgD.height = 145;
                ImgD.width = (image.width * 145) / image.height;
            } else {
                ImgD.width = image.width;
                ImgD.height = image.height;
            }
        }
    }
}
//商品详细页图片等比压缩
var flagmingxi = false;
function DrawImageMingXi(ImgD) {
    var image = new Image();
    image.src = ImgD.src;
    if (image.width > 0 && image.height > 0) {
        flagmingxi = true;
        if (image.width / image.height >= 284 / 224) {
            if (image.width > 284) {
                ImgD.width = 284;
                ImgD.height = (image.height * 224) / image.width;
            } else {
                ImgD.width = image.width;
                ImgD.height = image.height;
            }
        }
        else {
            if (image.height > 224) {
                ImgD.height = 224;
                ImgD.width = (image.width * 284) / image.height;
            } else {
                ImgD.width = image.width;
                ImgD.height = image.height;
            }
        }
    }
}

//公用的图片等比压缩
var flagall = false;
function DrawImageAll(ImgD, width, height) {
    var image = new Image();
    image.src = ImgD.src;
    if (image.width > 0 && image.height > 0) {
        flagall = true;
        if (image.width / image.height >= width / height) {
            if (image.width > width) {
                ImgD.width = width;
                ImgD.height = (image.height * height) / image.width;
            } else {
                ImgD.width = image.width;
                ImgD.height = image.height;
            }
        }
        else {
            if (image.height > height) {
                ImgD.height = height;
                ImgD.width = (image.width * width) / image.height;
            } else {
                ImgD.width = image.width;
                ImgD.height = image.height;
            }
        }
    }
}
//-----------------------------------------------------------------“JYT”结束---------------------------------------------------------------------//


function ShareLife() {
    var title = $("#tb_title").val();
    var content = $("#tb_content").val();
    if (title == "") {
        alert('请填写标题');
        return;
    }
    if (content == "") {
        alert('请填写内容');
        return;
    }
    $.ajax({
        type: "POST",
        contentType: "application/json;utf-8",
        url: "/webservice/LifeShareWS.asmx/AddShare",
        async: false,
        data: "{title:'" + title + "',content:'" + content + "'}",
        dataType: "json",
        success: function() {
            alert(' 感谢您的分享！');
            popBox.removeAll();
        }
    });
}
function SendLifeType() {
    var type = $("input[name='rd_lifetype']:checked").val();
    if (type == "") {
        alert('请设置您的主题生活');
        return;
    }
    $.ajax({
        type: "POST",
        contentType: "application/json;utf-8",
        url: "/webservice/LifeShareWS.asmx/SetLifeType",
        async: false,
        data: "{lifestyle:" + type + "}",
        dataType: "json",
        success: function(result) {
            if (result.d == "1") {
                window.location.reload();
            }
            else {
                alert("登录已超时，请重新登录");
            }
        }
    });
}

function ZoomImg(img, width, height) {
    try {
        if (img.offsetWidth > img.offsetHeight) {
            if (img.offsetWidth > width) {
                img.style.width = width + 'px'; img.style.height = '';
            }
        }
        else {
            if (img.offsetHeight > height) {
                img.style.height = height + 'px'; img.style.width = '';
            }
        }
    }
    catch (ex) { }
}
function setCheckedValue(radioName, newValue) {
    if (!radioName) return;
    var radios = document.getElementsByName(radioName);
    for (var i = 0; i < radios.length; i++) {
        radios[i].checked = false;
        if (radios[i].value == newValue.toString()) {
            radios[i].checked = true;
        }
    }
}

function ZoomImg(img, width, height) {
    try {

        if (img.offsetWidth > width) {
            if (img.offsetWidth > width) {
                img.style.width = width + 'px';
                img.style.height = '';
            }
        }
        else {

            if (parseInt(img.offsetHeight) >= height) {
                img.style.height = height + 'px';
                img.style.width = '';
            }
        }
    }
    catch (ex) { }
}



//商品列表页中的排序标题不动
(function($){
	$.fn.capacityFixed = function(options) {
		var opts = $.extend({},$.fn.capacityFixed.deflunt,options);
		var FixedFun = function(element) {
			var top = opts.top;
			var right = ($(window).width()-opts.pageWidth)/2+opts.right;
			element.css({
				"right":right,
				"top":top
			});
			$(window).resize(function(){
				var right = ($(window).width()-opts.pageWidth)/2+opts.right;
				element.css({
					"right":right
				});
			});
			$(window).scroll(function() {
				var scrolls = $(this).scrollTop();
				if (scrolls > top) {

					if (window.XMLHttpRequest) {
						element.css({
							position: "fixed",
							top: 0							
						});
					} else {
						element.css({
							top: scrolls
						});
					}
				}else {
					element.css({
						position: "absolute",
						top: top
					});
				}
			});
			element.find(".close-ico").click(function(event){
				element.remove();
				event.preventDefault();
			})
		};
		return $(this).each(function() {
			FixedFun($(this));
		});
	};
	$.fn.capacityFixed.deflunt={
		right : 0,
		top:240,
		pageWidth : 950
	};
})(jQuery);


//自动关闭层
function ClearToop()
{
   // $(".pop_small").hide();
}

function PanDuanProductAndCity()
{
    //判断当前订单是不是当前城市的
    var cityx=$("#ctl00_ContentPlaceHolder2_CityX").val();
    var cityy=$("#ctl00_ContentPlaceHolder2_CityY").val();
    if(cityx!=cityy)
    {
        var content="当前订单不属于当前城市，不能加入购物车！";
        popBox.show('/pop/popmsg.htm', function() {
            $('#divMsg').html(content);
        });
        return;
    }
}



