﻿function AddToCart(id) {
            $.post("/checkout/CartAddItem/" + id + "?d=" + Math.random(), {}, function (data, textStatus) {
                if (data.Status == 1) {
                    //  location.href = '/Checkout/Cart';
                    $("#buy" + id).html("<a href='/Checkout/Cart'><img src='/Themes/5icuc/images/added.gif' title='已添加到购物车' /></a>");
                    $("#cartNum").html(parseInt($("#cartNum").html())+1);
                }
                else {
                    alert("系统忙，请稍后再试。");
                }
            }, "json");
        }

        function AddToSaveForLater(id) {
            $.post("/MyAccount/ScriptCheckLogin/?d=" + Math.random(), {}, function (data, textStatus) {
                if (data.Status == 1) {
                    AddToSave(id);
                }
                else {
                    dialog("用户登陆", "id:flogin", "450px", "auto");
                    $("#floatBox .floatBoxcontent .fusername").pressEnter(function () {
                        $("#floatBox .floatBoxcontent .floginbutton").click();
                    });
                    $("#floatBox .floatBoxcontent .fpassword").pressEnter(function () {
                        $("#floatBox .floatBoxcontent .floginbutton").click();
                    });
                }
            }, "json");


        }

        function AddToSave(id) {
            $.post("/Product/AddSaveLater/" + id + "?d=" + Math.random(), {}, function (data, textStatus) {
                if (data.Status == 1) {
                    $("#savelater" + id).html("<a href='/MyAccount/Save'><img src='/Themes/5icuc/images/but_put_have.gif' title='已添加到暂存架' /></a>");
                    alert("收藏成功。");
                }
                else {
                    alert("系统忙，请稍后再试。");
                }
            }, "json");
        }
        
        function SetBuy(id)
        {
           $("#buy" + id).html("<a href='/Checkout/Cart'><img src='/Themes/5icuc/images/added.gif' title='已添加到购物车' /></a>");
       }


       function UserLogin() {
           if ($("#floatBox .floatBoxcontent .fusername").val() == "") {
               alert("请填写登陆Email。");
               $("#floatBox .floatBoxcontent .fusername").focus();
               return;
           }
           if ($("#floatBox .floatBoxcontent .fpassword").val() == "") {
               alert("请填写登陆密码。");
               $("#floatBox .floatBoxcontent .fpassword").focus();
               return;
           }
           $("#floginload").show();
           $.post("/MyAccount/ScriptLogin/?d=" + Math.random(), { Action: "post",
               szaccount: $("#floatBox .floatBoxcontent .fusername").val(),
               password: $("#floatBox .floatBoxcontent .fpassword").val()
           }, function (data, textStatus) {
               if (data.Status == 1) {
                   $("#floginload").hide();
                   ClosefLogin();
                   $("#loginInfo").html("欢迎光临中国传媒大学纪念品中心，<a href='/MyAccount/Logout'>退出</a>");
               }
               else {
                   alert("登陆失败，请检查您的用户名和密码。");
                   $("#floginload").hide();
               }
           }, "json");
       }

       function ClosefLogin() {
           var height = "auto";
           $("#floatBox #floginbutton").attr('disabled', false);
           $("#floatBoxBg").animate({ opacity: "0" }, "normal", function () { $(this).hide(); });
           $("#floatBox").animate({ top: ($(document).scrollTop() - (height == "auto" ? 300 : parseInt(height))) + "px" }, "normal", function () { $(this).hide(); });
       }
