﻿document.domain = "519.com";

function LoadLinks() {
    var output = "";
    var woutput = "";
    $.getJSON("http://service.519.com/ActiveLinkService.aspx?action=link&callback=?", { count: 7, type: 3 },
             function(linkResult) {
                 var linkList = linkResult.linkList;
                 $(linkList).each(function() {
                     if (output != "") {
                         output += " | ";
                     }
                     output += "<a href='" + this.Link + "' target='_blank'>" + this.Name + "</a>";
                 });
                 $("#links").html(output);
             });
}

function getFriendCount() {
    $.getJSON("http://service.519.com/FriendCount.aspx?action=loadcount&callback=?", function(resault) {
        //alert(resault.SendEmailCount);
        $("#FriendsCount").html(resault.FriendsCount);
        $("#SendEmailCount").html(resault.SendEmailCount);
        $("#InviteFriendsCount").html(resault.InviteFriendsCount);
        $("#FriendCellPhoneIsValidCount").html(resault.FriendCellPhoneIsValidCount);
    });
}

/****************************************************shown_james*******************************************************/
function LoadArts(id, template, num, tagID, count, lng, dispContent, contentCount) {
    var url = "";
    url = "http://service.519.com/ReadArts.aspx";

    var tmp = template;
    template = "";

    $.getJSON(url + "?action=" + escape(id) + "&num=" + num + "&count=" + count + "&lng=" + lng + "&callback=?&dispContent=" + dispContent + "&contentCount=" + contentCount,
            function(Result) {
                var List = Result;
                var i = 0;
                $(List).each(function() {
                    if (this.Title != "");
                    template += tmp.replace("$title", this.Title).replace("$link", this.ArticleUrl).replace("$alt", this.Alt).replace("$content", this.Content);
                    i++;
                });
                for (var j = 0; j < (num - i); j++) {
                    template += tmp.replace("$title", "").replace("$link", "").replace("$alt", this.Alt).replace("$content", this.Content);
                }
                $("#img_" + tagID).remove();
                $("#" + tagID).html(template);
                $("#" + tagID).css("display", "");
            });
}


function chgLng(lng) {
    createCookie("lng", lng, 30);
    if (lng == "2")
        window.location = "http://www.519.com/english/index.html";
    else
        window.location = "http://www.519.com/index.html";
}

function stockIn(pid) {
    $.getJSON(
        "http://service.519.com/Product.aspx?action=queryStockIn&callback=?&productID=" + pid,
        function(json) {
            if (json.StockNum > 0) {
                $("#stockIn").css("display", "none");
                $("#stockBuy").css("display", "inline");
            }
            else {
                $("#stockIn").css("display", "inline");
                $("#stockBuy").css("display", "none");
            }
        });
}

function AddFavorite(sURL, sTitle) {
    try {
        window.external.addFavorite(sURL, sTitle);
    }
    catch (e) {
        try {
            window.sidebar.addPanel(sTitle, sURL, "");
        }
        catch (e) {
            alert("加入收藏失败，请使用Ctrl+D进行添加");
        }
    }
}

function getWine(pos, val) {
    var VALUR_URL = "http://service.519.com/product/";
    var VALUE_DEF = "1000-0-0-0-0-0-0-1-0-0-0-0-0-0-0-0-0-0";
    var VALUE_EXT = ".html";

    var path = window.location.href;
    var strsDef = VALUE_DEF.split("-");
    var strsVal = path.substring(path.lastIndexOf("/") + 1, path.lastIndexOf(".")).split("-");
    strsVal[17] = "0";

    if (strsVal.length == 18)
        if (strsVal[0] == "1000")
        if (pos != 8)
        for (var i = 0; i < strsDef.length - 1; i++)
        if (i != 6)
        strsDef[i + 1] = strsVal[i + 1];
    if (pos == 9 && val != 0) {
        strsDef[8] = 0;
        $("#normal").css("display", "none");
        $("#advance").css("display", "block");
    }


    strsDef[pos] = val;
    var resStr = strsDef.join("-");
    window.location.href = VALUR_URL + resStr.substring(0, resStr.length) + VALUE_EXT;


}

function getSpecialWine(pos, val) {
    var VALUR_URL = "http://service.519.com/product/";
    var VALUE_DEF = "1004-0-0-0-0-0-0-1-0-0-0-0-0-0-0-0-0-0";
    var VALUE_EXT = ".html";

    var path = window.location.href;
    var strsDef = VALUE_DEF.split("-");
    var strsVal = path.substring(path.lastIndexOf("/") + 1, path.lastIndexOf(".")).split("-");


    if (strsVal.length == 18)
        if (strsVal[0] == "1000")
        if (pos != 8)
        for (var i = 0; i < strsDef.length - 1; i++)
        if (i != 6)
        strsDef[i + 1] = strsVal[i + 1];
    if (pos == 9 && val != 0) {
        strsDef[8] = 0;
        $("#normal").css("display", "none");
        $("#advance").css("display", "block");
    }


    strsDef[pos] = val;
    var resStr = strsDef.join("-");
    window.location.href = VALUR_URL + resStr.substring(0, resStr.length) + VALUE_EXT;
}

function getPointsProduct(pos, val) {
    var VALUR_URL = "http://service.519.com/product/";
    var VALUE_DEF = "1008-0-0-0-0-0-0-1-0-0-0-0-0-0-0-0-0-0";
    var VALUE_EXT = ".html";

    var path = window.location.href;
    var strsDef = VALUE_DEF.split("-");
    var strsVal = path.substring(path.lastIndexOf("/") + 1, path.lastIndexOf(".")).split("-");


    if (strsVal.length == 18)
        if (strsVal[0] == "1000")
        if (pos != 8)
        for (var i = 0; i < strsDef.length - 1; i++)
        if (i != 6)
        strsDef[i + 1] = strsVal[i + 1];
    if (pos == 9 && val != 0) {
        strsDef[8] = 0;
        $("#normal").css("display", "none");
        $("#advance").css("display", "block");
    }


    strsDef[pos] = val;
    var resStr = strsDef.join("-");
    window.location.href = VALUR_URL + resStr.substring(0, resStr.length) + VALUE_EXT;
}

function getGiftWine(pos, val) {
    var VALUR_URL = "http://service.519.com/product/";
    var VALUE_DEF = "1003-0-0-0-0-0-0-1-0-0-0-0-0-0-0-0-0-0";
    var VALUE_EXT = ".html";

    var path = window.location.href;
    var strsDef = VALUE_DEF.split("-");
    var strsVal = path.substring(path.lastIndexOf("/") + 1, path.lastIndexOf(".")).split("-");


    if (strsVal.length == 18)
        if (strsVal[0] == "1000")
        if (pos != 8)
        for (var i = 0; i < strsDef.length - 1; i++)
        if (i != 6)
        strsDef[i + 1] = strsVal[i + 1];
    if (pos == 9 && val != 0) {
        strsDef[8] = 0;
        $("#normal").css("display", "none");
        $("#advance").css("display", "block");
    }


    strsDef[pos] = val;
    var resStr = strsDef.join("-");
    window.location.href = VALUR_URL + resStr.substring(0, resStr.length) + VALUE_EXT;
}
function getfirstWine(pos, val) {
    var VALUR_URL = "http://service.519.com/product/";
    var VALUE_DEF = "1005-0-0-0-0-0-0-1-0-0-0-0-0-0-0-0-0-0";
    var VALUE_EXT = ".html";

    var path = window.location.href;
    var strsDef = VALUE_DEF.split("-");
    var strsVal = path.substring(path.lastIndexOf("/") + 1, path.lastIndexOf(".")).split("-");


    if (strsVal.length == 18)
        if (strsVal[0] == "1000")
        if (pos != 8)
        for (var i = 0; i < strsDef.length - 1; i++)
        if (i != 6)
        strsDef[i + 1] = strsVal[i + 1];
    if (pos == 9 && val != 0) {
        strsDef[8] = 0;
        $("#normal").css("display", "none");
        $("#advance").css("display", "block");
    }


    strsDef[pos] = val;
    var resStr = strsDef.join("-");
    window.location.href = VALUR_URL + resStr.substring(0, resStr.length) + VALUE_EXT;
}

function getHealthWine(pos, val) {
    var VALUR_URL = "http://service.519.com/product/";
    var VALUE_DEF = "1006-0-0-0-0-0-0-1-0-0-0-0-0-0-0-0-0-0";
    var VALUE_EXT = ".html";

    var path = window.location.href;
    var strsDef = VALUE_DEF.split("-");
    var strsVal = path.substring(path.lastIndexOf("/") + 1, path.lastIndexOf(".")).split("-");


    if (strsVal.length == 18)
        if (strsVal[0] == "1000")
        if (pos != 8)
        for (var i = 0; i < strsDef.length - 1; i++)
        if (i != 6)
        strsDef[i + 1] = strsVal[i + 1];
    if (pos == 9 && val != 0) {
        strsDef[8] = 0;
        $("#normal").css("display", "none");
        $("#advance").css("display", "block");
    }


    strsDef[pos] = val;
    var resStr = strsDef.join("-");
    window.location.href = VALUR_URL + resStr.substring(0, resStr.length) + VALUE_EXT;
}

function setCurr() {
    var path = window.location.href.split("-");
    var map="";
   
    for (var i = 1; i <= 17; i++) {
        $("#li_" + i + "_" + path[i]).removeClass();
        $("#ac_" + i + "_" + path[i]).remove();
        if ($("#li_" + i + "_" + path[i]).attr("title") != undefined) {
            if (map != "")
                map += " + ";
            map += $("#li_" + i + "_" + path[i]).attr("title");
        }

        $("#li_" + i + "_" + path[i]).addClass("sortBox_dd");
        $("#dd_" + i + "_" + path[i]).append("<a id='ac_" + i + "_" + path[i] + "' class=\"cancel\" href=\"javascript:getWine(" + i + ",0)\"><img src=\"http://www.519.com/519images/icon_close.gif\" /></a>");
        $("#li_" + i + "_" + path[i] + " a").css("color", "#C60202");

    }
    if (path.length > 1) {
        if (path[9] != 0) {
            $("#imgusage").attr("src", "http://www.519.com/519images/" + getUImage(path[9]));
            $("#wineusage").css("display", "block");
            $("#u_" + path[9] + " a").addClass("current");
        }
        $("#o_" + path[6]).attr("src", getOrderImg(path[6]));
    }
    if (path[8] == "4") {
        $("#imgusage").attr("src", "http://www.519.com/519images/banner-recommended.jpg");
        $("#wineusage").css("display", "block");
        $("#u_" + path[8] + " a").addClass("current");
    }
    if(map!="")
        $("#show_map").html("&nbsp&nbsp&nbsp&nbsp您的搜索条件：" + map);
}

function getOrderImg(code) {
    switch (code) {
        case "4":
        case "2":
            return "http://www.519.com/519images/up_01.jpg";
            break;
        case "1":
        case "3":
        case "7":
            return "http://www.519.com/519images/down_02.jpg";
            break;
    }
}

function getUImage(code) {
    switch (code) {
        case "436":
            return "banner-gift.jpg";
            break;
        case "437":
            return "img_342.gif";
            break;
        case "438":
            return "banner-lady.jpg";
            break;
        case "439":
            return "banner-business.jpg";
            break;
        case "440":
            return "banner-wedding.jpg";
            break;
        case "441":
            return "img_340.gif";
            break;
        case "442":
            return "img_338.gif";
            break;
        default:
            return "img_341.gif";
            break;
    }
}

function selectLayer(Num) {
    var path = window.location.href;
    var paths = path.split("-");
    path = paths[0] + "-" + paths[1] + "-" + Num + "-1.html";
    window.location.href = path;
}

function getCurrentLayer(Oneli, One, pos) {
    var Num = window.location.href.split("-")[pos];
    for (i = 1; i < 5; i++)
        if (i == Num)
        document.getElementById(Oneli + i).className = "intabcurrent";
    else
        document.getElementById(Oneli + i).className = "";
}

function doSearch(str, type) {
    if (type == "1") {
        var strSearch = escape(Trim(str));
        //alert(uniencode(str) + "    " + strSearch.replace(new RegExp("%", "gm"), "\\"));
        window.location = "http://service.519.com/product/1000-0-0-0-0-0-0-1-0-0-0-0-0-0-0-0-0-" + strSearch.replace(new RegExp("%", "gm"), "_") + ".html";
    }
    else
        window.open("http://www.google.com/search?sitesearch=www.519.com&hl=zh-cn&ie=utf8&query=" + str);
    //window.location = "http://www.google.com/search?sitesearch=www.519.com&hl=zh-cn&ie=utf8&query=" + str;

}
/*-------------------------------------------图片预加载------------------------------------------------------------*/
function MM_preloadImages() { //v3.0
    var d = document; if (d.images) {
        if (!d.MM_p) d.MM_p = new Array();
        var i, j = d.MM_p.length, a = MM_preloadImages.arguments; for (i = 0; i < a.length; i++)
            if (a[i].indexOf("#") != 0) { d.MM_p[j] = new Image; d.MM_p[j++].src = a[i]; }
    }
}
//-->
/*-------------------------------------------图片预加载------------------------------------------------------------*/
    function uniencode(text)
   {
        text = escape(text.toString()).replace(/\+/g, "%2B");
       var matches = text.match(/(%([0-9A-F]{2}))/gi);
        if (matches)
        {
            for (var matchid = 0; matchid < matches.length; matchid++)
            {
               var code = matches[matchid].substring(1,3);
               if (parseInt(code, 16) >= 128)
               {
                   text = text.replace(matches[matchid], '%u00' + code);
              }
           }
       }
       text = text.replace('%25', '%u0025');
    
      return text;
   }
//去空格的方法
function LTrim(str) {
    var i;
    for (i = 0; i < str.length; i++) {
        if (str.charAt(i) != " " && str.charAt(i) != " ") break;
    }
    str = str.substring(i, str.length);
    return str;
}
function RTrim(str) {
    var i;
    for (i = str.length - 1; i >= 0; i--) {
        if (str.charAt(i) != " " && str.charAt(i) != " ") break;
    }
    str = str.substring(0, i + 1);
    return str;
}
function Trim(str) {
    return LTrim(RTrim(str));
}

//去空格的方法END



/**********************************************************************************************************************/
/*弹出式菜单*/
//没剑 2008-07-02
//http://regedit.cnblogs.com
/*参数说明*/
//showobj:要显示的菜单ID
//timeout：延时时间,鼠标停留/离开后延时多久开始显示/隐藏菜单
//speed：菜单显示速度，数字越大，显示越慢,默认为100
//调用示例:$("#button").DMenu("#content");
jQuery.fn.DMenu = function(showobj, timeout, speed) {
    timeout = timeout ? timeout : 300;
    speed = speed ? speed : 100;
    //按钮对象
    var button = $(this);
    //延时计数器
    var timer = null;
    //隐藏的浮动层
    var hideDiv = $("<div style=\"margin:11px 0px 0px 30px;display:none;\"></div>"); /**/
    //容器对象
    var Container = $("<div id=\"shoppingCartConten\"></div>");
    Container.hide();
    hideDiv.append(Container);
    //菜单对象
    var jqShowObj = $(showobj);
    //隐藏菜单
    jqShowObj.hide();
    //菜单显示的状态
    var display = false;
    //按钮的offset
    var offset = button.offset();
    //菜单区高
    var height = jqShowObj.height();
    //菜单区宽
    var width = jqShowObj.width();
    //按钮的高
    var btnHeight = button.height();
    //按钮的宽
    var btnWidth = button.width();
    //定位层放到最前面
    $(document.body).prepend(hideDiv);
    //放到容器中
    //Container.append(jqShowObj);

    //****显示菜单方法开始****//
    var showMenu = function() {
        //如果菜单为显示则退出操作
        if (display) {
            return false;
        }
        //设置容器属性
        Container.css({
            /*margin:0px;*/
            width: btnWidth + "px",
            height: btnHeight + "px"
        });
        //定位隐藏层
        hideDiv.css({
            position: "absolute",
            top: offset.top + "px",
            left: offset.left + (btnWidth / 2) - (width / 2) + "px",
            height: height + "px",
            width: width + "px"
        }).show();
        //给容器加个黑边框
        Container.css({
            border: "1px solid #666666"
        });
        //显示定位层
        //高宽慢慢增大
        Container.animate({
            marginTop: btnHeight,
            height: height + 10,
            width: width + 4,
            opacity: '100'
        }, speed, function() {
            //动画结束时 start//
            //显示菜单
            jqShowObj.show();
            //添加菜单入容器
            Container.append(jqShowObj);
            //去除边框
            Container.css({
                border: "0px"
            });
            //显示状态置为true
            display = true;
            //鼠标移入
            jqShowObj.mouseover(function() {
                clearTimeout(timer);
            });
            //鼠标移开
            jqShowObj.mouseout(function() {
                hideMenu();
            });
            //动画结束时 end//
        });
    };
    //****显示菜单方法结束****//

    //****隐藏菜单方法开始****//
    var hideMenu = function() {
        clearTimeout(timer);
        //延时隐藏菜单
        timer = setTimeout(function() {
            //显示边框
            Container.css({
                border: "1px solid #666666"
            });
            //清空容器
            Container.empty();
            //收缩容器
            Container.animate({
                width: btnWidth, height: btnHeight, marginTop: '0', opacity: '0'
            }, speed, function() {
                //动画结束时 start//
                //隐藏容器
                Container.hide();
                //定位层隐藏
                hideDiv.hide();
                //显示状态置为false
                display = false;
                //动画结束时 end//
            });
        }, timeout);
    };
    //****隐藏菜单方法结束****//

    //绑定按钮鼠标经过事件
    button.hover(function(e) {
        //延时显示菜单
        clearTimeout(timer);
        timer = setTimeout(function() {
            showMenu();
        }, timeout);
    }, function() {
        clearTimeout(timer);
        //鼠标离开按钮时，如果菜单还是显示状态则隐藏
        if (display) {
            timer = setTimeout(function() {
                hideMenu();
            }, timeout);
        }
    });
};
/************************************************************************************************************/

function GetQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    if (r != null)
        return unescape(r[2]);
    return null;
}

function reg() {
    top.window.location.href = "http://passport.519.com/login.html?RefferURL=" + escape(top.window.location.href);
}

function headerlogin() {
    var userName = $("#userName").attr("value");
    var password = $("#password").attr("value");
    $.getJSON("http://passport.519.com/loginService.aspx?action=headerlogin&callback=?", { userName: userName, password: password }, function(islogin) {
        if (islogin == "True")
            window.location.reload();
        else
            alert("帐号或密码错误，请重试！");
    });

}

function login() {
    top.window.location.href = "http://passport.519.com/login.html?RefferURL=" + escape(top.window.location.href);
}

function logout() {
//    window.location = "http://blogs.519.com/sslogout.html" + ((window.location.href.indexOf("returnUrl") > 0) ? window.location.href.substring(window.location.href.indexOf("returnUrl") + 10) : "?returnUrl=" + window.location.href);
    $.getJSON(
    "http://passport.519.com/loginservice.aspx?action=logout&callback=?",
    function() {
    createCookie("sppid", "");
    $("#hidSPID").attr("value", "");
        window.location.reload();

    });
}

function authoritate() {
    $.getJSON(
        "http://passport.519.com/loginservice.aspx?action=authoritate&callback=?",
        function(json) {
            if (json.RESULT == 1)
                top.window.location.href = "http://passport.519.com/login.html?RefferURL=" + escape(top.window.location.href);
        }
   );
}

function authoritate2() {
    $.getJSON(
        "http://passport.519.com/loginservice.aspx?action=authoritate&callback=?",
        function(json) {
            if (json.RESULT == 1)
                top.window.location.href = "http://passport.519.com/998push/index.html";
        }
   );
}

function submitForm(eve, formid) {
    if (eve.keyCode == 13) {
        $("#" + formid).submit();
    }
}
function FormatNum(input) {
    var maxLength = 8;
    input = String(input);
    if (input.length >= maxLength) {
        return num;
    }
    else {
        var output = "";
        for (var i = 0; i < maxLength - input.length; i++) {
            output += "0";
        }
        return output + input;
    }
}

/*---------------------------------------cookie------------------------------------------*/
function createCookie(name, value, days, Tdom, domain) {
    var Tdom = (Tdom) ? Tdom : "/";
    var domain = (domain) ? domain : "519.com";
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    } else {
        var expires = "";
    }
    document.cookie = name + "=" + value + expires + "; path=" + Tdom + "; domain=." + domain;
}
function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') { c = c.substring(1, c.length); }
        if (c.indexOf(nameEQ) == 0) { return c.substring(nameEQ.length, c.length); }
    }
    return null;
}
/*---------------------------------------cookie------------------------------------------*/

/*---------------------------------------shoppingCart------------------------------------------*/
function buy(pid, num) {  //公共AddShoppingCart @TS
    if (pid < 1)
        return;
    $.getJSON(
        "http://service.519.com/shoppingcart.aspx?action=add&callback=?&id=" + pid + "&num=" + num,
        function(json) {
        
            if (json.ProductID == -4)
                alert("只有注册用户才能参加本次活动！");
            else if (json.ProductID == -3)
                alert("您已购买超过指定数量的商品，不能再购买！");
            else if (json.ProductID == -2)
                alert("您已参加过本活动，不能重复参加！");
            else if (json.ProductID == -1)
                alert("您尚未达到本次活动所需条件，只有新注册用户才能参加本次活动！");
            else if (json.ProductID == -5)
                alert("您没有足够的积分换取该物品");
            else if (json.ProductID == 0) //购买失败 @TS
                window.location.href = "http://passport.519.com/login.html?refferUrl=" + window.location.href;
            else    //购买成功，结账时请选择购物车 @TS
                window.location.href = "http://www.519.com/shoppingcart.html";
        }
   );
}

function LoadShoppingCart() {
    $.getJSON(
        "http://service.519.com/shoppingcart.aspx?action=load&callback=?",
        function(json) {
            var output = "";
            for (var i = 0; i < json.PRODUCTS.length; i++) {
                //output += "<tr><td>" + json.PRODUCTS[i].ProductCode + "</td><td><img src='http://www.519.com/519ErpImages/" + json.PRODUCTS[i].PicUrl +"'/></td><td>" + json.PRODUCTS[i].Name + "</td><td><input type='text' size='2' maxlength='2' value='" + json.PRODUCTS[i].Quantity + "' onchange=javascript:UpdateShoppingCart('" + json.PRODUCTS[i].ProductID + "',this);></td><td>￥" + json.PRODUCTS[i].Price + "</td><td><a href='#' onclick=javascript:DeleteShoppingCart('" + json.PRODUCTS[i].ProductID + "',this); >删除</a></td></tr>";
                if (json.PRODUCTS[i].spid == 0 && json.PRODUCTS[i].ProductType != 11)
                    output += "<tr><td><img src='http://www.519.com/519ErpImages/" + json.PRODUCTS[i].PicUrl + "'/></td><td>" + json.PRODUCTS[i].Name + "</td><td><span id='Q_" + json.PRODUCTS[i].ProductID + "' style='display:none;'>" + json.PRODUCTS[i].Quantity + "</span><input id='V_" + json.PRODUCTS[i].ProductID + "' type='text' size='2' maxlength='2' value='" + json.PRODUCTS[i].Quantity + "'>&nbsp;&nbsp;<a href='javascript:UpdateShoppingCart(" + json.PRODUCTS[i].ProductID + ");'>更新</a></td><td>￥" + json.PRODUCTS[i].Price + "</td><td>￥" + json.PRODUCTS[i].Price * json.PRODUCTS[i].Quantity + "</td><td><a href='#' onclick=javascript:DeleteShoppingCart('" + json.PRODUCTS[i].ProductID + "',this); >删除</a></td></tr>";
                else if (json.PRODUCTS[i].spid != 0 && json.PRODUCTS[i].ProductType != 11) {
                    output += "<tr><td><img src='http://www.519.com/519ErpImages/" + json.PRODUCTS[i].PicUrl + "'/></td><td>" + json.PRODUCTS[i].Name + "</td><td><span id='Q_" + json.PRODUCTS[i].ProductID + "' style='display:none;'>" + json.PRODUCTS[i].Quantity + "</span><input id='V_" + json.PRODUCTS[i].ProductID + "' type='text'readonly='readonly'  size='2' maxlength='2' value='" + json.PRODUCTS[i].Quantity + "'>&nbsp;&nbsp;<a style='clear;text-decoration:line-through' href=''>更新</a></td><td>￥" + json.PRODUCTS[i].Price + "</td><td>￥" + json.PRODUCTS[i].Price * json.PRODUCTS[i].Quantity + "</td><td><a href='#' onclick=javascript:DeleteShoppingCart('" + json.PRODUCTS[i].ProductID + "',this); >删除</a></td></tr>";
                    document.getElementById(json.PRODUCTS[i].spid).readOnly = true;
                }
                else if (json.PRODUCTS[i].ProductType == 11) {
                output += "<tr><td><img src='http://www.519.com/519ErpImages/" + json.PRODUCTS[i].PicUrl + "'/></td><td>" + json.PRODUCTS[i].Name + "</td><td><span id='Q_" + json.PRODUCTS[i].ProductID + "' style='display:none;'>" + json.PRODUCTS[i].Quantity + "</span><input id='V_" + json.PRODUCTS[i].ProductID + "' type='text' size='2' maxlength='2' value='" + json.PRODUCTS[i].Quantity + "'>&nbsp;&nbsp;<a href='javascript:UpdateShoppingCart(" + json.PRODUCTS[i].ProductID + ");'>更新</a></td><td>" + json.PRODUCTS[i].Price + "积分</td><td>" + json.PRODUCTS[i].Price * json.PRODUCTS[i].Quantity + "积分</td><td><a href='#' onclick=javascript:DeleteShoppingCart('" + json.PRODUCTS[i].ProductID + "',this); >删除</a></td></tr>";
            }
            }
            $("#shoppingcartbody").html(output);
            $("#totalprice").html("小计：" + json.TOTAL + "元，比市场价" + json.MarketTotal + "元 节省了" + (json.MarketTotal - json.TOTAL) + "元，共可获" + (json.ScoreTotal) + "积分，部分活动产品不参与积分。");
            LoadShoppingCartCount();
        }
    );
}

function UpdateShoppingCart(productsID) {
    var s = $("#V_" + productsID).val();
    if (s.replace(/\d/g, "").length != 0) {
        $("#V_" + productsID).val($("#Q_" + productsID).html());
        return;
    }
    if (productsID == 873)
        $("#V_" + productsID).val(1);
    if (productsID == 12367 && s>2)
        $("#V_" + productsID).val($("#Q_" + productsID).html());
    $.getJSON("http://service.519.com/shoppingcart.aspx?action=edit&callback=?&id=" + productsID + "&q=" + s, function(json) {
    if (json.ProductID == -5) {
        alert("您没有足够的积分换取该物品");
    }
        else {
            LoadShoppingCart();
            LoadShoppingCartCount();
            LoadMiniShoppingCart();
            createCookie("sppid", "");
            isornotLogin();
            location.reload();
        }
    });     //修改cookies的单个产品数量值@TS
}

function DeleteShoppingCart(productsID, obj) {
    if (!confirm("确认删除此商品？"))
        return;
    hid_s = 0; isornotLogin();
    createCookie("sppid", "");
    $("#hidSPID").attr("value", "");
    $("#shoppingcartbody2").html("");
    $.getJSON("http://service.519.com/shoppingcart.aspx?action=del&callback=?&id=" + productsID, function() {
        LoadShoppingCart();
        LoadShoppingCartCount();
        DeleteMiniShoppingCart(productsID);
       
    });

}
function LoadShoppingCartCount() {
    $.getJSON(
        "http://service.519.com/shoppingcart.aspx?action=loadnum&callback=?",
        function(json) {
            if (json.COUNT > 0) {
                $("#totalnum").html(json.COUNT);
            }
            else {
                $("#totalnum").html(0);
            }
        }
    );
}

function LoadMiniShoppingCart() {
    $.getJSON(
        "http://service.519.com/shoppingcart.aspx?action=load&callback=?",
        function(json) {
            var output = "";
            var countNum = 0;
            var countAmount = 0;
            var pointAmount = 0;
            for (var i = 0; i < json.PRODUCTS.length; i++) {
                if (json.PRODUCTS[i].ProductType != 11) {
                    output += "<li id='miniShoppingCart_" + json.PRODUCTS[i].ProductID + "'>&nbsp;&nbsp;&nbsp;&nbsp;<div class='shoppingframe_left'><a href='" + json.PRODUCTS[i].UrlFrom + "' target='_blank'><img src='http://www.519.com/519ErpImages/" + json.PRODUCTS[i].PicUrl + "'/></a></div><div class='shoppingframe_right'> <p class='p01'>" + json.PRODUCTS[i].Name + "</p> <p class='p02'><b id='pprice" + json.PRODUCTS[i].ProductID + "'>￥" + json.PRODUCTS[i].Price + "×" + json.PRODUCTS[i].Quantity + "</b> <a href='javascript:DeleteMiniShoppingCart(" + json.PRODUCTS[i].ProductID + ")'>删除</a></p></div><div class='clear'></div></li>";
                    countAmount += Number(json.PRODUCTS[i].Price) * Number(json.PRODUCTS[i].Quantity);
                }
                else {
                    output += "<li id='miniShoppingCart_" + json.PRODUCTS[i].ProductID + "'>&nbsp;&nbsp;&nbsp;&nbsp;<div class='shoppingframe_left'><a href='" + json.PRODUCTS[i].UrlFrom + "' target='_blank'><img src='http://www.519.com/519ErpImages/" + json.PRODUCTS[i].PicUrl + "'/></a></div><div class='shoppingframe_right'> <p class='p01'>" + json.PRODUCTS[i].Name + "</p> <p class='p02'><b id='pprice" + json.PRODUCTS[i].ProductID + "'>" + json.PRODUCTS[i].Price + "×" + json.PRODUCTS[i].Quantity + "</b> <a href='javascript:DeleteMiniShoppingCart(" + json.PRODUCTS[i].ProductID + ")'>删除</a></p></div><div class='clear'></div></li>";
                    pointAmount += Number(json.PRODUCTS[i].Price) * Number(json.PRODUCTS[i].Quantity);
                }
                countNum += Number(json.PRODUCTS[i].Quantity);
            }

            $("#shoppingCartA").html(output);
            $("#shoppingCart").DMenu("#shoppingCartConten", 100, 100);
            $("#shoppingCartConten").removeClass();
            $("#shoppingCartConten").addClass("shoppingCartConten");
            $("#miniCount").html(countNum);

            $("#minipriceTotal").html("￥" + countAmount+" / " + pointAmount);
        }
   );
}

function DeleteMiniShoppingCart(productID) {
    var Total = 0;
    $.getJSON(
        "http://service.519.com/shoppingcart.aspx?action=del&callback=?&id=" + productID,
        function(json) {
            $("#miniShoppingCart_" + productID).remove();
            $("#miniCount").html(json.itmCount);
            Total = json.TOTAL;
            //$("#minipriceTotal").html("￥"+json.TOTAL);
            $("#minipriceTotal").html("￥" + json.TOTAL);
            LoadShoppingCartCount();
        }
    );

}

/*---------------------------------------shoppingCart------------------------------------------*/


function SubmitMsnDump() {
    document.formMSN.submit();
    //    //$("#loadimg").ajaxStart(
    //    //function() {
    //    //    $("#loadimg").css("display","block");
    //    //});
    //                                               
    //    $.ajax({
    //        type: "post",
    //        url: "FriendDump.aspx",
    //        datatype:"text",
    //        data:{
    //            MSNAccount: $("#MSNAccount").value,
    //            MSNPassword: $("#MSNPassword").value
    //        },
    //        beforeSend: function(XMLHttpRequest){
    //			$("#loadimg").css("display","block");
    //		},
    //        complete:function(){
    //            $("#loadimg").css("display","none");
    //        },
    //        success: function(msg){ 
    //            //$("#a").html(msg); 
    //            location.href="http://www.519.com/519Pages/succee_02.html";
    //        } 
    //    });
}

//===========================index.html====================
function getStar(num) {
    var stars = "";

    if (num == 0)
        stars = "<img src='http://www.519.com/519images/redStar.gif' width='18' height='17' /><img src='http://www.519.com/519images/redStar.gif' width='18' height='17' /><img src='http://www.519.com/519images/redStar.gif' width='18' height='17' /><img src='http://www.519.com/519images/redStar.gif' width='18' height='17' /><img src='http://www.519.com/519images/grayStar.gif' width='18' height='17' /></p>";
    if (num == 1)
        stars = "<img src='http://www.519.com/519images/redStar.gif' width='18' height='17' /><img src='http://www.519.com/519images/grayStar.gif' width='18' height='17' /><img src='http://www.519.com/519images/grayStar.gif' width='18' height='17' /><img src='http://www.519.com/519images/grayStar.gif' width='18' height='17' /><img src='http://www.519.com/519images/grayStar.gif' width='18' height='17' /></p>";
    if (num == 2)
        stars = "<img src='http://www.519.com/519images/redStar.gif' width='18' height='17' /><img src='http://www.519.com/519images/redStar.gif' width='18' height='17' /><img src='http://www.519.com/519images/grayStar.gif' width='18' height='17' /><img src='http://www.519.com/519images/grayStar.gif' width='18' height='17' /><img src='http://www.519.com/519images/grayStar.gif' width='18' height='17' /></p>";
    if (num == 3)
        stars = "<img src='http://www.519.com/519images/redStar.gif' width='18' height='17' /><img src='http://www.519.com/519images/redStar.gif' width='18' height='17' /><img src='http://www.519.com/519images/redStar.gif' width='18' height='17' /><img src='http://www.519.com/519images/grayStar.gif' width='18' height='17' /><img src='http://www.519.com/519images/grayStar.gif' width='18' height='17' /></p>";
    if (num == 4)
        stars = "<img src='http://www.519.com/519images/redStar.gif' width='18' height='17' /><img src='http://www.519.com/519images/redStar.gif' width='18' height='17' /><img src='http://www.519.com/519images/redStar.gif' width='18' height='17' /><img src='http://www.519.com/519images/redStar.gif' width='18' height='17' /><img src='http://www.519.com/519images/grayStar.gif' width='18' height='17' /></p>";
    if (num == 5)
        stars = "<img src='http://www.519.com/519images/redStar.gif' width='18' height='17' /><img src='http://www.519.com/519images/redStar.gif' width='18' height='17' /><img src='http://www.519.com/519images/redStar.gif' width='18' height='17' /><img src='http://www.519.com/519images/redStar.gif' width='18' height='17' /><img src='http://www.519.com/519images/redStar.gif' width='18' height='17' /></p>";

    return stars;

}

/*zero有待修正为生成页面时的数据写入后隐藏+判断登录更优惠方式*/
function loadLevelPrice(pid, mtype) {
    $.getJSON("http://passport.519.com/loginService.aspx?action=isLogin&callback=?", function(islogin) {
        if (islogin) {
            getProductUnite(pid);
            $.getJSON("http://service.519.com/product/productUnite.aspx?action=loadLevelPrice&callback=?&productID=" + pid + "&type=" + mtype,
          function(res) {
              $("#MemberPrice").html('￥' + res);
          });

        }
        else {
            $("#MemberPrice").html("<a href='http://passport.519.com/login.html?RefferURL=" + window.location + "'>登录更优惠</a>");
            getProductUnite2(pid);
        }
    });
}
/*zero*/

//*************************cookie*****************************
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};
//********************************cookie end*************************

function SubmitOrder() {
    if ($.formValidator.pageIsValid('1')) {
        var email = $("#email").attr("value");
        var mobile = $("#mobile").attr("value");
        var amount = $("#amount").attr("value");
        $.getJSON("http://www.519.com/gaffey_describe.aspx?action=add&callback=?", { email: email, mobile: mobile, amount: amount },
                        function(res) {
                            if (res.RESULT == true) {
                                alert('感谢您的预定');
                                tb_remove();
                            }
                            else
                                alert("对不起，由于正在处理大量预定订单，请稍后再试");
                        });
    }
}

/*页面左侧葡萄酒分类导航点中后的背景样式*/
$(function() {
        $(".sortBox_dd").parent().css("background", "#e6e6e6");
    });