﻿// JScript 文件

var xmlHttp;

//创建XMLHttpRequest对象
function createXmlHttpRequest() {
    if (window.XMLHttpRequest) { 
        xmlHttp = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) {
        try {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e) {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    if (!xmlHttp) {
        window.alert("你的浏览器不支持创建XMLhttpRequest对象");
    }
    return xmlHttp;
}

//添加到购物车，如果当前选择的商品库存为0，则提示没有此商品并询问是否进入缺货登记
function addToCart($p_ID) {
    //精油两件免运费IDS
    var $freeids = "2771,2763,2767,2766,2770,2768,2765,2775,2776,2773,2785,2769,2786,2774,2777,2783,2779,2772,2781,2797,2778,2784,2782,2801,2798,2796,2780,2807,2808,2809,2806,2810,2799,2800,2813,2812,2811";
    $.ajax({
        url: "/ajax.aspx?q=addtocart&p_ID=" + $p_ID + "&time=" + new Date().toString(),
        type: "GET",
        timeout: 30000,
        beforeSend: function() {
            $('#status').show();
        },
        error: function() {
            $("#status").hide();
            ymPrompt.alert({ message: '购买商品失败，请联系管理员！', title: '系统提示', btn: [['确定', 'ok']], handler: null });
        },
        success: function() {
            var $status = arguments[0];
            $("#status").hide();
            if ($status == "1") {
                if ($freeids.indexOf($p_ID, 0) > -1) {
                    ymPrompt.confirmInfo("美香源系列精油 购买二瓶即免运费\r\n(点确定继续挑选,点取消立即结算)", null, null, "系统提示", function(tp) { tp == 'ok' ? continutcheck() : checkout() })
                }
                else {
                    window.location = ("/list/shopcart.shtml");
                }
            }
            else if ($status == "-1")
                ymPrompt.confirmInfo("此商品库存不足，是否添加缺货登记?", null, null, "系统提示", function(tp) { tp == 'ok' ? AddOOS($p_ID) : null })
            else
                ymPrompt.alert({ message: '购买商品失败，请联系管理员！', title: '系统提示', btn: [['确定', 'ok']], handler: null });
        }

    });
}
//继续挑选
function continutcheck() {
   //window.location = ("/SearchResult/%E7%BE%8E%E9%A6%99%E6%BA%90.shtml");
}
//立即结算
function checkout() {
    window.location = ("/list/shopcart.shtml");
}

//添加到购物车，如果当前选择的商品库存为0，则提示没有此商品并询问是否进入缺货登记
function addToCartNored($p_ID) {
    //精油两件免运费IDS
    var $freeids = "2771,2763,2767,2766,2770,2768,2765,2775,2776,2773,2785,2769,2786,2774,2777,2783,2779,2772,2781,2797,2778,2784,2782,2801,2798,2796,2780,2807,2808,2809,2806,2810,2799,2800,2813,2812,2811";
    $.ajax({
        url: "/ajax.aspx?q=addtocart&p_ID=" + $p_ID + "&time=" + new Date().toString(),
        type: "GET",
        timeout: 30000,
        beforeSend: function() {
            $('#status').show();
        },
        error: function() {
            $("#status").hide();
            ymPrompt.alert({ message: '购买商品失败，请联系管理员！', title: '系统提示', btn: [['确定', 'ok']], handler: null });
        },
        success: function() {
            var $status = arguments[0];
            $("#status").hide();
            if ($status == "1") {
                if ($freeids.indexOf($p_ID, 0) > -1) {
                    ymPrompt.alert({ message: '已经添加到您的购物车 \r\n美香源系列精油 购买二瓶即免运费！', title: '系统提示', btn: [['确定', 'ok']], handler: null });
                }
                else {
                    alert("此商品已经加入到您的购物车，您可以继续挑选其他商品！");
                }
            }
            else if ($status == "-1")
                ymPrompt.confirmInfo("此商品库存不足，是否添加缺货登记?", null, null, "系统提示", function(tp) { tp == 'ok' ? AddOOS($p_ID) : null })
            else
                ymPrompt.alert({ message: '购买商品失败，请联系管理员！', title: '系统提示', btn: [['确定', 'ok']], handler: null });
        }

    });
}
//添加到加购的购物车----by franco (2009-8-13日修改，购买流程的修改----2009-11-3 修改运费)
function addToextraCart($p_ID) {
    $.ajax({
        url: "/ajax.aspx?q=addtoextracart&p_ID=" + $p_ID + "&time=" + new Date().toString(),
        type: "GET",
        timeout: 30000,
        beforeSend: function() {
            $('#status').show();
        },
        error: function() {
            $("#status").hide();
            ymPrompt.alert({ message: '加购商品失败，请联系管理员！', title: '系统提示', btn: [['确定', 'ok']], handler: null });
        },
        success: function() {
            var $status = arguments[0];
            $("#status").hide();
            var $DivHtml = $("#extraShoppingCart");

            //加购列表
            $DivHtml.html($status.split('-------')[0]);

            //总价格（包括正常购物的价格)
            var money1 = $status.split('-------')[1];
            var money2 = $status.split('-------')[2];
            if (money2 - 150 < 0) {
                if (money2 != 0) {

                    $("#lblCount").html(money1);
                    $("#tips").html("<br /><font color=\"#ff0000\">您还差<font color=\"#cc3300\">￥" + (150 - money2) + "元</font>即可免运费哦！</font>");
                }
            }
            else {
                $("#lblCount").html(money1);
            }
            $("#lblCounts").html($status.split('-------')[1]);
        }

    });
}

//免费申领添加到加购的购物车----by franco (2009-8-30日修改，购买流程的修改)
//$pid:申领产品的ID
//$p_ID:要加购的产品的ID
function addZSToextraCart($pid, $p_ID) {
    $.ajax({
        url: "/ajax.aspx?q=addzstoextracart&pid=" + $pid + "&p_ID=" + $p_ID + "&time=" + new Date().toString(),
        type: "GET",
        timeout: 30000,
        beforeSend: function() {
            $('#status').show();
        },
        error: function() {
            $("#status").hide();
            ymPrompt.alert({ message: '加购商品失败，请联系管理员！', title: '系统提示', btn: [['确定', 'ok']], handler: null });
        },
        success: function() {
            var $status = arguments[0];
            $("#status").hide();
            var $DivHtml = $("#extraShoppingCart");

            //加购列表
            $DivHtml.html($status.split('-------')[0]);

            //总价格（包括正常购物的价格)
            $("#lblCount").html($status.split('-------')[1]);
        }

    });
}



function AddOOS($p_ID) {
    fdata = "action=add"
            + "&ftitle=''"
            + "&fcontent=''"
            + "&fclass=''"
            + "&flinkman=''"
            + "&fphone=''"
            + "&femail=''"
            + "&pid=" + $p_ID;
    //alert(fdata);
    $.ajax({
        type: "POST",
        url: "/Feedback/FeedBack.ashx",
        data: fdata,
        success: function(d) {
            // alert(d);
        },
        error: function() {
            //alert(fdata);
            //alert(err.responseText);
            alert("添加缺货失败！");
        }
    });
}

//添加到我的收藏夹
function addToFavorite($p_ID) {
    $.ajax({
        url: "/ajax.aspx?q=addtofavorite&p_ID=" + $p_ID + "&time=" + new Date().toString(),
        type: "GET",
        timeout: 30000,
        beforeSend: function() {
            $('#status').show();
        },
        error: function() {
            $("#status").hide();
            ymPrompt.alert({ message: '保存到收藏夹失败，请联系管理员！', title: '系统提示', btn: [['确定', 'ok']], handler: null });
        },
        success: function() {
            var $status = arguments[0];
            $("#status").hide();
            if ($status == "1")
                ymPrompt.win({ message: '/Members/MyAddfavorite-' + $p_ID + '.shtml', width: 600, height: 400, title: '确认收藏', handler: null, maxBtn: false, minBtn: false, iframe: true })
            else if ($status == "-1")
                ymPrompt.win({ message: '/login4Favorite.aspx?pID=' + $p_ID, width: 600, height: 400, title: '系统登录', handler: null, maxBtn: false, minBtn: false, iframe: true })
            else
                ymPrompt.alert({ message: '保存到收藏夹失败，请联系管理员！', title: '系统提示', btn: [['确定', 'ok']], handler: null });
        }

    });
}

function confirmFavorite($p_ID) {
    var $remark = $("#remark").val();
    $.ajax({
        url: "/ajax.aspx?q=confirmfavorite&p_ID=" + $p_ID + "&remark=" + escape($remark) + "&time=" + new Date().toString(),
        type: "GET",
        timeout: 30000,
        beforeSend: function() {
            $('#status').show();
        },
        error: function() {
            $("#status").hide();
            ymPrompt.alert({ message: '保存到收藏夹失败，请联系管理员！', title: '系统提示', btn: [['确定', 'ok']], handler: null });
        },
        success: function() {
            var $status = arguments[0];
            $("#status").hide();
            if ($status == "1") {
                window.alert("保存到收藏列表成功!");
                $("#btnClose").click();
            }
            else
                window.alert('保存到收藏夹失败，请联系管理员！');
        }

    });
}

//删除一条或多条消息
function DelAllFavorite(id) {
    if (id != 0)
        var $ids = id;
    else
        var $ids = $('#NavSptPagingSortx1_NavSptPagingSortx_hiddenCheckedValue').val();
    if ($ids != null && $ids != "") {
        if (confirm("是否删除选中的商品收藏?"))
            $.ajax({
                url: "/ajax.aspx?q=delfavorite&ids=" + $ids + "&time=" + new Date().toString(),
                type: 'GET',
                beforeSend: function() {
                    $('#status').show();
                },
                error: function() {
                    $("#status").hide();
                    ymPrompt.alert({ message: '删除商品收藏失败，请联系管理员！', title: '系统提示', btn: [['确定', 'ok']], handler: null });
                },
                success: function() {
                    if (arguments[0] == 1) {
                        alert("删除商品收藏成功");
                        window.location = ("/Members/Myfavorite.shtml"); //转到收藏列表
                    }
                }
            });
    }
    else
        alert("请选中要删除的收藏");
}

//添加收藏之前的登录界面
function checkfavoriteLogin($p_ID) {
    var $name = $("#txtUserName").val()
    var $password = $("#txtPassWord").val();
    if ($name == "") {
        $("#loginStatus").html("请输入登录用户名");
        $("#txtUserName").focus();
        return false;
    }

    if ($password == "") {
        $("#loginStatus").html("请输入登录用户名");
        $("#txtPassWord").focus();
        return false;
    }
    var $saveStatus = ($("#saveName").checked == true ? 1 : 0)
    $.ajax({
        url: "/ajaxLogin.aspx?saveType=" + $saveStatus + "&name=" + escape($name) + "&password=" + MD5($password) + "&time=" + new Date().toString(),
        type: "GET",
        timeout: 30000,
        beforeSend: function() {
            $("#loginStatus").html("正在登录中");
        },
        error: function() {
            $("#loginStatus").html("登录失败!");
        },
        success: function() {
            var $status = Number(arguments[0]);
            if ($status > 1) {
                //登录成功后，继续提交换购申请
                window.location = ("/Members/MyAddfavorite-" + $p_ID + ".shtml");
            }
            else if ($status == 0) {
                $("#loginStatus").html("用户名不正确");
                $("#txtUserName").focus();
            }
            else if ($status == -1) {
                $("#loginStatus").html("密码不正确");
                $("#txtPassWord").focus();
            }
            else {
                $("#loginStatus").html("帐号已经被删除");
            }
        }
    });
}

//cartpid:购物车cookie标识,加购商品p_ID:加购产品的ID;checkStatus:记录当前复选框的状态：1：加购；0：取消加购 已弃用----------2009-12-18日重新启用
function extraCart(cartpid, p_ID, checkStatus) {
    //在点击按钮取消加购时同时更新checkbox的状态
    var chkp_ID = document.getElementById("chk" + p_ID);
    if (checkStatus == 0)
        chkp_ID.checked = false;
    else
        chkp_ID.checked = true;

    createXmlHttpRequest();
    var url = "/ajax.aspx?q=extracart&cartpid=" + cartpid + "&p_ID=" + p_ID + "&checkStatus=" + checkStatus;

    xmlHttp.open("GET", url, true);

    xmlHttp.onreadystatechange = extraCartResult;

    //防止缓存
    xmlHttp.setRequestHeader("If-Modified-Since", "0");

    xmlHttp.send(null);
}

//返回加购商品的结果
function extraCartResult() {
    //操作成功
    if (xmlHttp.readyState == 4) {
        if (xmlHttp.status == 200) {
            var cartHtml = xmlHttp.responseText;
            //            var cartDiv = document.getElementById("mulu");
            $("#mulu").html(cartHtml.split('-------')[0]);

            //            //显示总价格
            //            var lblCount = document.getElementById("lblCount");
            //            var lblCount1 = document.getElementById("lblCount1");
            $("#lblcount").html(cartHtml.split('-------')[2]);
            $("#lblcount1").html(cartHtml.split('-------')[1]);
        }
    }
}
//加购商品p_ID:加购产品的ID;checkStatus:记录当前复选框的状态：1：加购；0：取消加购   已弃用
function eventextraCart(p_ID, checkStatus) {
    //在点击按钮取消加购时同时更新checkbox的状态
    var chkp_ID = document.getElementById("chk" + p_ID);
    if (checkStatus == 0)
        chkp_ID.checked = false;
    else
        chkp_ID.checked = true;

    createXmlHttpRequest();
    var url = "/ajax.aspx?q=eventextracart&p_ID=" + p_ID + "&checkStatus=" + checkStatus;

    xmlHttp.open("GET", url, true);

    xmlHttp.onreadystatechange = eventextraCartResult;

    //防止缓存
    xmlHttp.setRequestHeader("If-Modified-Since", "0");

    xmlHttp.send(null);
}
//返回加购商品的结果
function eventextraCartResult() {
    //操作成功
    if (xmlHttp.readyState == 4) {
        if (xmlHttp.status == 200) {
            var cartHtml = xmlHttp.responseText;
            var cartDiv = document.getElementById("eventextraShoppingCart");
            cartDiv.innerHTML = cartHtml.split('-------')[0];
            var count = document.getElementById("lblCount");
            count.innerHTML = cartHtml.split('-------')[1];

            //显示总价格                
            //CalculatCount("cntProduct","cntExtraProduct");
        }
    }
}

//确认删除正常购买的产品
function delProduct($p_ID) {
    ymPrompt.confirmInfo("是否要取消此商品？", null, null, "系统提示", function(tp) { tp == 'ok' ? DelProduct($p_ID) : setTextFocus($p_ID) })
}
//取消删除后，focus到原文本框并选中
function setTextFocus($p_ID) {
    $("#txt" + $p_ID).focus();
    $("#txt" + $p_ID).select();
}

//删除购物车中的商品
function DelProduct($p_ID) {
    $.ajax({
        url: "/ajax.aspx?q=delproduct&p_ID=" + $p_ID + "&time=" + new Date().toString(),
        type: "GET",
        timeout: 30000,
        beforeSend: function() {
            $('#status').show();
        },
        error: function() {
            $("#status").hide();
            ymPrompt.alert({ message: '删除商品失败，请联系管理员！', title: '系统提示', btn: [['确定', 'ok']], handler: null });
        },
        success: function() {
            var $status = arguments[0];
            $("#status").hide();
            $("#shoppingCart").html($status.split("-------")[0]);
            var money1 = $status.split('-------')[1];
            var money2 = $status.split('-------')[3];
            if (money2 - 150 < 0) {
                if (money2 != 0) {
                    $("#lblCount").html(money1);
                    $("#tips").html("<br /><font color=\"#ff0000\">您还差<font color=\"#cc3300\">￥" + (150 - money2) + "元</font>即可免运费哦！</font>");
                }
            }
            else {
                $("#lblCount").html(money1);
            }
            // $("#lblCount").html($status.split("-------")[1]);
            $("#lblCounts").html($status.split("-------")[1]);
            $("#lblScore").html($status.split("-------")[2]);
        }
    });
}

//确认删除加购的产品
function delextra($p_ID) {
    ymPrompt.confirmInfo("是否要取消此商品？", null, null, "系统提示", function(tp) { tp == 'ok' ? DelExtra($p_ID) : setTextFocus($p_ID) })
}

//删除购物车中的加购商品
function DelExtra($p_ID) {
    $.ajax({
        url: "/ajax.aspx?q=delextra&p_ID=" + $p_ID + "&time=" + new Date().toString(),
        type: "GET",
        timeout: 30000,
        beforeSend: function() {
            $('#status').show();
        },
        error: function() {
            $("#status").hide();
            ymPrompt.alert({ message: '删除加购商品失败，请联系管理员！', title: '系统提示', btn: [['确定', 'ok']], handler: null });
        },
        success: function() {
            var $status = arguments[0];
            $("#status").hide();
            $("#extraShoppingCart").html($status.split("-------")[0]);
            var money1 = $status.split('-------')[1];
            var money2 = $status.split('-------')[2];
            if (money2 - 150 < 0) {
                if (money2 != 0) {
                    $("#lblCount").html(money1);
                    $("#tips").html("<br /><font color=\"#ff0000\">您还差<font color=\"#cc3300\">￥" + (150 - money2) + "元</font>即可免运费哦！</font>");
                }
            }
            else {
                $("#lblCount").html(money1);
            }
            //$("#lblCount").html($status.split("-------")[1]);
            $("#lblCounts").html($status.split("-------")[1]);
            //$("#lblScore").html($status.split("-------")[2]);
        }
    });
}

//确认删除免费试用加购的产品
//$pid:免费申领的产品类别
//$p_ID:要删除的加购产品的ID
function delzsextra($pid, $p_ID) {
    ymPrompt.confirmInfo("是否要取消此商品？", null, null, "系统提示", function(tp) { tp == 'ok' ? DelZSExtra($pid, $p_ID) : setTextFocus($p_ID) })
}

//删除免费试用购物车中的商品
function DelZSExtra($pid, $p_ID) {
    $.ajax({
        url: "/ajax.aspx?q=delzsextra&pid=" + $pid + "&p_ID=" + $p_ID + "&time=" + new Date().toString(),
        type: "GET",
        timeout: 30000,
        beforeSend: function() {
            $('#status').show();
        },
        error: function() {
            $("#status").hide();
            ymPrompt.alert({ message: '删除加购商品失败，请联系管理员！', title: '系统提示', btn: [['确定', 'ok']], handler: null });
        },
        success: function() {
            var $status = arguments[0];
            $("#status").hide();
            $("#extraShoppingCart").html($status.split("-------")[0]);
            $("#lblCount").html($status.split("-------")[1]);
            //$("#lblCounts").html($status.split("-------")[1]);
            //$("#lblScore").html($status.split("-------")[2]);
        }
    });
}

//更新产品数量-------------------此函数已舍弃
function UpdataShoppCart($count, $p_ID) {
    if (isNumeric($count)) {
        if ($count == 0) {
            //删除商品
            delProduct($p_ID);
            return false;
        }

        $.ajax({
            url: "/ajax.aspx?q=updateproduct&p_ID=" + $p_ID + "&count=" + $count + "&time=" + new Date().toString(),
            type: "GET",
            timeout: 30000,
            beforeSend: function() {
                $('#status').show();
            },
            error: function() {
                $("#status").hide();
                ymPrompt.alert({ message: '更新商品数量失败，请联系管理员！', title: '系统提示', btn: [['确定', 'ok']], handler: null });
            },
            success: function() {
                var $status = arguments[0];
                $("#status").hide();
                if ($status.substring(0, 2) == "-1") {
                    //alert("库存不足，当前库存为"+$status.split(",")[2]+",您最多只能购买"+$status.split(",")[2]);
                    ymPrompt.confirmInfo("此商品库存不足，是否添加缺货登记?", null, null, "系统提示", function(tp) { tp == 'ok' ? AddOOS($p_ID) : null })
                    //库存不足后focus到原文本框
                    $("#txt" + $p_ID).focus();
                    $("#txt" + $p_ID).select();
                    return false;
                }
                $("#shoppingCart").html($status.split("-------")[0]);
                var money1 = $status.split('-------')[1];
                var money2 = money1.substring(1);
                if (money2 - 150 < 0) {
                    $("#lblCount").html(money1);
                    $("#tips").html("<br /><font color=\"#ff0000\">您还差<font color=\"#cc3300\">￥" + (150 - money2) + "元</font>即可免运费哦！</font>");
                }
                else {
                    $("#lblCount").html(money1);
                }
                // $("#lblCount").html($status.split("-------")[1]);
                $("#lblScore").html($status.split("-------")[2]);
            }
        });
    }
}

//更新产品数量
function UpdateShopCart($count, $p_ID) {
    if (isNumeric($count)) {
        if ($count == 0) {
            //删除商品
            delProduct($p_ID);
            return false;
        }

        $.ajax({
            url: "/ajax.aspx?q=updateproduct&p_ID=" + $p_ID + "&count=" + $count + "&time=" + new Date().toString(),
            type: "GET",
            timeout: 30000,
            beforeSend: function() {
                $('#status').show();
            },
            error: function() {
                $("#status").hide();
                ymPrompt.alert({ message: '更新商品数量失败，请联系管理员！', title: '系统提示', btn: [['确定', 'ok']], handler: null });
            },
            success: function() {
                var $status = arguments[0];
                $("#status").hide();
                if ($status.substring(0, 2) == "-1") {
                    //alert("库存不足，当前库存为"+$status.split(",")[2]+",您最多只能购买"+$status.split(",")[2]);
                    ymPrompt.confirmInfo("此商品库存不足，是否添加缺货登记?", null, null, "系统提示", function(tp) { tp == 'ok' ? AddOOS($p_ID) : null })
                    //库存不足后focus到原文本框
                    $("#txt" + $p_ID).val(1);
                    $("#txt" + $p_ID).focus();
                    $("#txt" + $p_ID).select();
                    return false;
                }
                $("#shoppingCart").html($status.split("-------")[0]);
                var money1 = $status.split('-------')[1];
                var money2 = $status.split('-------')[3];
                if (money2 - 150 < 0) {
                    if (money2 != 0) {
                        $("#lblCount").html(money1);
                        $("#tips").html("<br /><font color=\"#ff0000\">您还差<font color=\"#cc3300\">￥" + (150 - money2) + "元</font>即可免运费哦！</font>");
                    }
                }
                else {
                    $("#lblCount").html(money1);
                }
                // $("#lblCount").html($status.split("-------")[1]);
                $("#lblCounts").html($status.split("-------")[1]);
                $("#lblScore").html($status.split("-------")[2]);
            }
        });
    }
}

//更新加购的产品数量
function UpdateextraShopCart($count, $p_ID) {
    if (isNumeric($count)) {
        if ($count == 0) {
            //删除商品
            delextra($p_ID);
            return false;
        }

        $.ajax({
            url: "/ajax.aspx?q=updateextracart&p_ID=" + $p_ID + "&count=" + $count,
            type: "GET",
            timeout: 30000,
            beforeSend: function() {
                $('#status').show();
            },
            error: function() {
                $("#status").hide();
                ymPrompt.alert({ message: '更新商品数量失败，请联系管理员！', title: '系统提示', btn: [['确定', 'ok']], handler: null });
            },
            success: function() {
                var $status = arguments[0];
                $("#status").hide();
                if ($status.substring(0, 2) == "-1") {
                    //alert("库存不足，当前库存为"+$status.split(",")[2]+",您最多只能购买"+$status.split(",")[2]);
                    ymPrompt.confirmInfo("此商品库存不足，是否添加缺货登记?", null, null, "系统提示", function(tp) { tp == 'ok' ? AddOOS($p_ID) : null })
                    //库存不足后focus到原文本框
                    $("#txt" + $p_ID).val(1);
                    $("#txt" + $p_ID).focus();
                    $("#txt" + $p_ID).select();
                    return false;
                }
                $("#extraShoppingCart").html($status.split("-------")[0]);
                var money1 = $status.split('-------')[1];
                var money2 = $status.split('-------')[3];
                if (money2 - 150 < 0) {
                    if (money2 != 0) {
                        $("#lblCount").html(money1);
                        $("#tips").html("<br /><font color=\"#ff0000\">您还差<font color=\"#cc3300\">￥" + (150 - money2) + "元</font>即可免运费哦！</font>");
                    }
                }
                else {
                    $("#lblCount").html(money1);
                }
                // $("#lblCount").html($status.split("-------")[1]);
                $("#lblCounts").html($status.split("-------")[1]);
                //$("#lblScore").html($status.split("-------")[2]);                    
            }
        });
    }
}

//更新免费申领加购的产品数量
function UpdateextraZSShopCart($count, $pid, $p_ID) {
    if (isNumeric($count)) {
        if ($count == 0) {
            //删除商品
            delzsextra($pid, $p_ID);
            return false;
        }

        $.ajax({
            url: "/ajax.aspx?q=updateextrazscart&p_ID=" + $p_ID + "&pid=" + $pid + "&count=" + $count,
            type: "GET",
            timeout: 30000,
            beforeSend: function() {
                $('#status').show();
            },
            error: function() {
                $("#status").hide();
                ymPrompt.alert({ message: '更新商品数量失败，请联系管理员！', title: '系统提示', btn: [['确定', 'ok']], handler: null });
            },
            success: function() {
                var $status = arguments[0];
                $("#status").hide();
                if ($status.substring(0, 2) == "-1") {
                    //alert("库存不足，当前库存为"+$status.split(",")[2]+",您最多只能购买"+$status.split(",")[2]);
                    ymPrompt.confirmInfo("此商品库存不足，是否添加缺货登记?", null, null, "系统提示", function(tp) { tp == 'ok' ? AddOOS($p_ID) : null })
                    //库存不足后focus到原文本框
                    $("#txt" + $p_ID).val(1);
                    $("#txt" + $p_ID).focus();
                    $("#txt" + $p_ID).select();
                    return false;
                }
                $("#extraShoppingCart").html($status.split("-------")[0]);
                $("#lblCount").html($status.split("-------")[1]);
                //$("#lblCounts").html($status.split("-------")[1]);
                //$("#lblScore").html($status.split("-------")[2]);                    
            }
        });
    }
}


//清空购物车
function delCart() {
    ymPrompt.confirmInfo("您确定要清空购物车吗？", null, null, "系统提示", function(tp) { tp == 'ok' ? ClearCart() : null })
}
function ClearCart() {
    $.ajax({
        url: "/ajax.aspx?q=delcart&time=" + new Date().toString(),
        type: 'GET',
        timeout: 30000,
        beforeSend: function() {
            $('#status').show();
        },
        error: function() {
            $('#status').hide();
            ymPrompt.alert({ message: '清空购物车出现错误，请联系管理员！', title: '系统提示', btn: [['确定', 'ok']], handler: null });
        },
        success: function() {
            $('#status').hide();
            window.location = ("/dir");
        }
    });
}
//去付款
function payCart() {
    if ($("#shoppingCart").html() == "") {
        ymPrompt.alert({ message: '购物车中没有正常购买的商品,不能进行下一步!', title: '系统提示', btn: [['确定', 'ok']], handler: null });
        return;
    }
    window.location = ("/list/paycart.shtml");
}

//免费赠送去付款
function payzsCart() {
    window.location = ("/zengsong/paycart.shtml");
}

//新闻内容分页，跳转到指定新闻的指定页	
function jump(n_ID, currentPage) {
    createXmlHttpRequest();
    var url = "/ajax.aspx?q=newspages&n_ID=" + n_ID + "&currentPage=" + currentPage;

    xmlHttp.open("GET", url, true);

    xmlHttp.onreadystatechange = jumpResult;

    //防止缓存
    xmlHttp.setRequestHeader("If-Modified-Since", "0");

    xmlHttp.send(null);
}

//返回跳转页面成功与否
function jumpResult() {
    //操作成功
    if (xmlHttp.readyState == 4) {
        if (xmlHttp.status == 200) {
            var NewsHtml = xmlHttp.responseText;
            var NewsDiv = document.getElementById("content");
            NewsDiv.innerHTML = NewsHtml;
        }
    }
}

//添加资讯到收藏夹
function addToFavourite(n_ID) {
    //如果没有登录，则弹出登录框

    //待添加

    //转到添加资讯页面
    window.location = ("NewsFavouriteAdd.aspx?n_ID=" + n_ID);
}

//选择收货人信息后
function showAddressInfo() {
    var address = document.getElementById("selectAddress");
    var mai_ID = address.options[address.selectedIndex].value;
    if (mai_ID != 0) {
        createXmlHttpRequest();
        var url = "/ajax.aspx?q=selectAddress&mai_ID=" + mai_ID;

        xmlHttp.open("GET", url, true);

        xmlHttp.onreadystatechange = showAddressResult;

        //防止缓存
        xmlHttp.setRequestHeader("If-Modified-Since", "0");

        xmlHttp.send(null);
    }
    else {
        document.getElementById("txtName").value = "";
        document.getElementById("txtPhone").value = "";
        document.getElementById("txtTel").value = "";
        document.getElementById("txtZip").value = "";
        document.getElementById("txtEmail").value = "";
        document.getElementById("txtAddress").value = "";
    }
}

//选择收货人信息返回的结果
function showAddressResult() {
    //操作成功
    if (xmlHttp.readyState == 4) {
        if (xmlHttp.status == 200) {
            var AddressInfo = xmlHttp.responseText;
            if (AddressInfo == 0) {
                alert("获取收货人信息失败!");
                return false;
            }
            else {
                var infolist = AddressInfo.split(",");
                document.getElementById("txtName").value = infolist[0];
                document.getElementById("txtPhone").value = infolist[1];
                document.getElementById("txtTel").value = infolist[2];
                document.getElementById("txtZip").value = infolist[3];
                document.getElementById("txtEmail").value = infolist[4];
                document.getElementById("txtAddress").value = infolist[5];
            }
        }
    }
}

//添加收货人信息
function addInfo($flag) {
    var $id = $("#txtID").val(); //产品ID
    var $name = $("#txtName").val();
    var $mobile = $("#txtPhone").val();
    var $tel = $("#txtTel").val();
    var $zip = $("#txtZip").val();
    var $email = $("#txtEmail").val();
    var $address = $("#txtAddress").val();
    //验证
    if ($name == "") {
        alert("联系人不能为空！");
        $("#txtName").focus();
        return false;
    }
    if ($email == "") {
        alert("邮箱不能为空！");
        $("#txtEmail").focus();
        return false;
    }
    if (!$email.match(/^(.+)@(.+)$/)) {
        alert("邮箱格式不正确！");
        $("#txtEmail").focus();
        return false;
    }
    if ($mobile == "" && $tel == "") {
        alert("手机与固定电话必须填一项！");
        $("#txtPhone").focus();
        return false;
    }
    if ($mobile != "") {
        if ($mobile.length > 12 || $mobile < 11) {
            alert("手机号码填写不正确，请核实！");
            $("#txtPhone").focus();
            return false;
        }
    }
    if ($tel != "") {
        if ($tel.length > 13 || $tel.length < 7) {
            alert("固话信息填写不正确，请核实！");
            $("#txtTel").focus();
            return false;
        }
    }
    if ($address == "") {
        alert("收货地址不能为空！");
        $("#txtAddress").focus();
        return false;
    }
    //            if($zip=="")
    //            {
    //                alert("邮编不能为空！");
    //                $("#txtZip").focus();
    //                return false;
    //            }
    //            if($zip.length!=6)
    //            {
    //                alert("邮编的位数不正确，请核实！");
    //                $("#txtZip").focus();
    //                return false;
    //            }
    $.ajax({
        url: "/ajax.aspx?q=addAddress&flag=" + $flag + "&id=" + $id + "&name=" + escape($name) + "&mobile=" + $mobile + "&tel=" + $tel +
	            "&zip=" + $zip + "&email=" + $email + "&address=" + escape($address) + "&time=" + new Date().toString(),
        type: 'GET',
        timeout: 30000,
        beforeSend: function() {
            $('#ajaxStatus').show();
        },
        error: function() {
            $('#ajaxStatus').hide();
            ymPrompt.alert({ message: '添加收货地址出现错误，请重新添加或联系管理员！', title: '系统提示', btn: [['确定', 'ok']], handler: null });
        },
        success: function() {
            var $status = arguments[0];
            $('#ajaxStatus').hide();
            if ($status == -1) {
                alert("保存收货人信息失败!");
                parent.ymPrompt.close();
            }
            else if ($status == -2) {
                alert("保存收货人信息失败2");
                return false;
            }
            else {
                //弹出窗口操作后的结果
                if ($status.split("-")[0] == 0) {
                    alert("保存收货人信息成功!");
                    parent.document.getElementById("divList").innerHTML = $status.split("-")[1];
                    parent.ymPrompt.close();
                }
                else {
                    alert("保存收货人信息失败!");
                    return false;
                }
            }
        }
    });
}

//更新收货人信息
function updateAddress(mai_ID, linkman, mobile, tel, zip, email, address) {
    document.getElementById("txtID").value = mai_ID;
    document.getElementById("txtName").value = trimStr(linkman);
    document.getElementById("txtPhone").value = trimStr(mobile);
    document.getElementById("txtTel").value = trimStr(tel);
    document.getElementById("txtZip").value = trimStr(zip);
    document.getElementById("txtEmail").value = trimStr(email);
    document.getElementById("txtAddress").value = trimStr(address);
    document.getElementById("btnSave").focus();
}

function delAddress(mai_ID) {
    if (confirm("您确定要删除此条收货人信息吗?")) {
        createXmlHttpRequest();
        var url = "/ajax.aspx?q=addAddress&flag=delete&id=" + mai_ID;

        xmlHttp.open("GET", url, true);

        xmlHttp.onreadystatechange = delInfoResult;

        //防止缓存
        xmlHttp.setRequestHeader("If-Modified-Since", "0");

        xmlHttp.send(null);
    }
}

function delInfoResult() {
    //操作成功
    if (xmlHttp.readyState == 4) {
        if (xmlHttp.status == 200) {
            var AddressInfo = xmlHttp.responseText;
            if (AddressInfo == -2) {
                alert("删除收货人信息失败!");
                document.getElementById("ajaxStatus").innerHTML = "";
                return false;
            }
            else {
                alert("删除收货人信息成功!");
                //这里用来无刷新返回列表，暂时没写
                document.getElementById("divList").innerHTML = AddressInfo.split("-")[1];
                //window.location=("Me_AddressInfo.aspx");
                document.getElementById("ajaxStatus").innerHTML = "";

            }
        }
    }
    else {
        document.getElementById("ajaxStatus").innerHTML = "正在操作中....";
    }
}


//下一步去提交订单，提交前先判断是否已经购买商品
function Next() {
    var cart = document.getElementById("shoppingCart");
    if (cart.innerHTML == "") {
        alert("购物车中没有正常购买的商品,不能进行下一步");
        return false;
    }
    else
        window.location = ("PayCart.aspx");
}

//关闭未付款的订单
function cancelOrder(o_ID) {
    createXmlHttpRequest();
    var url = "/ajax.aspx?q=cancelOrder&o_ID=" + o_ID;

    xmlHttp.open("GET", url, true);

    xmlHttp.onreadystatechange = cancelOrderResult;

    //防止缓存
    xmlHttp.setRequestHeader("If-Modified-Since", "0");

    xmlHttp.send(null);
}

function cancelOrderResult() {
    //操作成功
    if (xmlHttp.readyState == 4) {
        if (xmlHttp.status == 200) {
            var CancelInfo = xmlHttp.responseText;
            if (CancelInfo == 0) {
                alert("关闭订单成功!");
                window.location = "Me_Orders.aspx?status=4";
            }
            else {
                alert("关闭订单失败!");
                return false;
            }
        }
    }
    else {
        document.getElementById("ajaxStatus").innerHTML = "正在操作中....";
    }
}

//确认收货
function confirmOrder(o_ID) {
    createXmlHttpRequest();
    var url = "/ajax.aspx?q=confirmOrder&o_ID=" + o_ID;

    xmlHttp.open("GET", url, true);

    xmlHttp.onreadystatechange = confirmOrderResult;

    //防止缓存
    xmlHttp.setRequestHeader("If-Modified-Since", "0");

    xmlHttp.send(null);
}

function confirmOrderResult() {
    //操作成功
    if (xmlHttp.readyState == 4) {
        if (xmlHttp.status == 200) {
            var CancelInfo = xmlHttp.responseText;
            if (CancelInfo == 0) {
                alert("确认收货成功!");
                window.location = "/Members/Orders-5.shtml";
            }
            else {
                alert("确认收货失败!请联系管理员");
                return false;
            }
        }
    }
    else {
        document.getElementById("ajaxStatus").innerHTML = "正在操作中....";
    }
}
//确认提交与支付宝合作的面膜订单
function submitaliorders($pid) {
    $.ajax({
        url: "/ajax.aspx?q=checkcookie&time=" + new Date().toString(),
        type: 'GET',
        timeout: 30000,
        beforeSend: function() {

        },
        error: function() {
            //显示登录注册窗口
            ymPrompt.win({ message: '/zengsong/login.aspx', width: 700, height: 260, title: '请先登录或注册', handler: null, maxBtn: false, minBtn: false, iframe: true })
        },
        success: function() {
            var $result = Number(arguments[0].split("-|-")[0]);
            if ($result > 0) {
                //已登录,直接转到cart页面
                window.location=("/zengsong/cart-" + $pid + ".shtml");
            }
            else {
                ymPrompt.win({ message: '/zengsong/login.aspx', width: 700, height: 260, title: '请先登录或注册', handler: null, maxBtn: false, minBtn: false, iframe: true })
            }
        }
    });
}

//簡單的註冊函數
function register($pid) {
    var infoofuser = $("#userinfo").html();
    var infoofpwd = $("#pwdinfo").html();
    var infoofpwdagain = $("#pwdagaininfo").html();
    var infoofemail = $("#emailinfo").html();
   
    //  alert(infoofuser);
    //真实姓名
    if (infoofuser.indexOf("会员名可用") == -1) {
        alert("您的用户名输入错误，请根据提示正确填写用户名！");
        $("#txtusername").focus();
        $("#usernull").show();
        return false;
    }
    //密码
    else if (infoofpwd.indexOf("密码输入正确") == -1) {
        alert("您的密码输入错误，请根据提示正确填写密码！");
        $("#txtpwd").focus();
        return false;
    }
    //确认密码
    else if (infoofpwdagain.indexOf("密码输入正确") == -1) {
        alert("您的二次密码输入错误，请根据提示正确填写！");
        $("#txtpwdagain").focus();
        return false;
    }
    //邮箱
    else if (infoofemail.indexOf("邮箱可用") == -1) {
        alert("您的邮箱输入错误，请根据提示正确填写！");
        $("#txtemail").focus();
        return false;
    }

    $.ajax({
        url: "/ajax.aspx?q=register&username=" + escape($("#txtusername").val()) + "&password=" + $("#txtpwd").val() + "&email=" + $("#txtemail").val() + "&from=19&time=" + new Date().toString(),
        type: 'GET',
        timeout: 30000,
        beforeSend: function() {
            $("#btnregister").val("注册中");
        },
        error: function() {
            $("#btnregister").val("注册");
            alert("注册失败,请重试");
        },
        success: function() {
        alert("注册成功"); //转向购物车页面
        //parent.ymPrompt.close();
        parent.location = ("/zengsong/cart-" + $pid + ".shtml");
        }
    });
}

//登录函数
function alilogin($pid) {
    if ($("#txtmembername").val() == "") {
        alert("请输入您的会员用户名！");
        $("#txtmembername").focus();
        return false;
    }
    else if ($("#txtPassword").val() == "") {
        alert("请输入您的登录密码！");
        $("#txtPassword").focus();
        return false;
    }
    $.ajax({
        url: "/ajaxLogin.aspx?saveType=1&name=" + escape($("#txtmembername").val()) + "&password=" + MD5($("#txtPassword").val()) + "&time=" + new Date().toString(),
        type: "GET",
        timeout: 30000,
        beforeSend: function() {
            $("#loginStatus").show();
        },
        error: function() {
            alert("登录失败!");
            $("#loginStatus").hide();
        },
        success: function() {
            var $status = Number(arguments[0]);
            if ($status > 1) {
                //登录成功后，转到购物车页面
                alert("登录成功");
                parent.location = ("/zengsong/cart-" + $pid + ".shtml");
            }
            else if ($status == 0) {
                $("#loginStatus").html("用户名不正确");
                $("#txtUserName").focus();
            }
            else if ($status == -1) {
                $("#loginStatus").html("密码不正确");
                $("#txtPassWord").focus();
            }
            else {
                $("#loginStatus").html("帐号已经被删除");
            }
        }
    });
    
}

//验证是否为数字
function isNumeric(s) {
    var regu = "^[0-9]+$";
    var re = new RegExp(regu);
    if (s.search(re) != -1) { return true; } else { return false; }
}

//去掉字符串中的空格
function trimStr(str) {
    var re = /\s*(\S[^\0]*\S)\s*/;
    re.exec(str);
    return RegExp.$1;
}
//将Asc字符转化为HTML字符
function AscToHtml(theValue) {
    theValue = theValue.replace(/\$/g, "'");
    theValue = theValue.replace(/&lt;/g, "<");
    theValue = theValue.replace(/&gt;/g, ">");
    theValue = theValue.replace(/&quot/g, "\"");
    return theValue;
}
