//选项卡
function LoginSelect(n) {
    var tli = document.getElementById("Login_menu").getElementsByTagName("li");
    var mli = document.getElementById("Login_main").getElementsByTagName("ul");
    //alert(tli.innerHTML)
    for (i = 0; i < tli.length; i++) {
        tli[i].className = i == n ? "hover" : "";
        mli[i].style.display = i == n ? "block" : "none";
    }
}
function LoginClose() {
    document.getElementById("LoginBox").style.display = "none";
}
function LoginShow(ishow) {
    document.getElementById("LoginBox").style.display = "block";
    if (ishow == "1") {
        LoginSelect(1);
    }
}

function getByCart() {
    getAjax("/Mall/Order/GetByCart.ashx", "", function (rs) {
        if (rs != "") {
            $("#ByCartA").html("购物车(" + rs + ")");
        } else {
            $("#ByCartA").html("购物车");
        }
    });
}
getAjax("/Mall/Mall_HeadLoginStatus.ashx", "id=2", function (rs) {
    if (rs != "end") {
        //jQuery(".login_ban").html("<p style=\" font-size:larger;padding:0 10px;margin-top: 20px;\">欢迎您，掌心学院是一个最具有影响力的在线教育平台</p>");
        //jQuery(".head_top .fr").html("<a href='/Mall/Order/Mall_ShoppingCart.aspx' id='ByCartA'>购物车</a>  |  <a href='/Member/MemberCenter.aspx?kaoshi=2'>学习卡</a> |   您好:<a href=\"#\">" + rs + "</a><a href='/Mall/Mall_HeadLoginStatus.ashx?id=1'> 安全退出</a>");
        //getByCart(); //查询购物车
$("#duq").css("display", "none");
	$("#dul").css("display", "block");
$("#gh").css("display", "block");
    }
});
function MinCheckUserDataValid() {
    if (!H_LoginBtn()) {
        return false;
    }
    else {
        var userName = $("#H_txtUserNames").val();
        var userPwd = $("#H_txtUserPwds").val();
      //  var txtCode = $("#H_txtCodes").val();
        var parm = 'action=login&user_Account=' + escape(userName) + '&userPwd=' + escape(userPwd);
        $.get('/Frame/Frame.ashx', parm, function (rs) {
            if (parseInt(rs) == 1) {
               $("#H_txtCodes").focus();
                $("#H_errorMsg1").html("验证码输入不正确");
                ToggleCode("Verify_codeImag", '/Ajax/Verify_code.ashx');
                return false;
            } else if (parseInt(rs) == 2) {
                $("#H_txtUserNames").focus();
                $("#H_errorMsg1").html("账户被锁,联系管理员");
                return false;
            } else if (parseInt(rs) == 4) {
                $("#H_txtUserNames").focus();
                $("#H_errorMsg1").html("账户或密码有错误");
                return false;
            } else if (parseInt(rs) == 6) {
                $("#H_errorMsg1").focus();
                $("#H_errorMsg1").html("该用户已经登录");
                return false;
            } else if (parseInt(rs) == 3) {
                setTimeout(Load, 1000);
            } else {
                CheckingLogin(0);
                alert('服务器连接不上,联系管理员！');
                window.location.href = window.location.href.replace('#', '');
                return false;
            }
        });
    }
}
function H_LoginBtn() {
    var name = $("#H_txtUserNames").val();
    var pwd = $("#H_txtUserPwds").val();
    //var code = $("#H_txtCodes").val();
    $("#H_errorMsg1").html("");
    if (name == "") {
        $("#H_txtUserNames").focus();
        $("#H_errorMsg1").html("账户不能为空");
        return false;
    } else if (pwd == "") {
        $("#H_txtUserPwds").focus();
        $("#H_errorMsg1").html("密码不能为空");
        return false;
    }  else {
        return true;
    }
}
function Load() {
    //var url = document.referrer; //课程的地址
var url = "";
    if (url != "") {
        window.location.href = url;
    }
    else {
        //window.location.href = '/Member/MemberCenter.aspx';
	window.location.reload();//刷新当前页面
	$("#duq").css("display", "none");
	$("#dul").css("display", "block");
    }
    return false;
}
function animatenTop(thisTop, thisLeft) {
    var CopyDiv = '<img src="/Training/Courseware/Office/NullPhoto.gif" id="box" style="top:' + thisTop + 'px;left:' + thisLeft + 'px" />';
    var topLength = 200; //取得到购物车的宽度
    var leftLength = $('#ByCartA').offset().left; //取得到购物车的宽度 

    $("body").append(CopyDiv);
    $("body").children("#box").animate({ width: "30px", height: "30px", "top": topLength, "left": leftLength, "opacity": .1 }, 1200, function () { $(this).remove(); getByCart(); });

}
//添加购物车 
function addByCart(shopname, shopid, property, price, type, buy) {
    var parm = "shopname=" + shopname + "&shopid=" + shopid + "&property=" + property + "&price=" + price + "&type=" + type + "&buy=" + buy;
    getAjax("/Mall/Order/AddShoppingCart.ashx", parm, function (rs) {
        if (rs == "1") {
            layer.confirm('已加入购物车！', { btn: ['确定'] });
            var thisTop = $("#csinfo_buycart").offset().top; //所在位置的高度
            var thisLeft = $("#csinfo_buycart").offset().left; //所在位置的宽度

        }
        else if (rs == "2") {

        }
        else if (rs == "3") {//
            window.location.href = "/Mall/Slogin.aspx";
        }
        else if (rs == "0") {
            layer.confirm('购物车中已存在！', { btn: ['确定'] });
        }
        else {
            window.location.href = "/Mall/Order/Mall_Finance_Order.aspx?" + rs;
        }

    });
}
function LoginBtn() {
    var name = $("#txtUserNames").val();
    var pwd = $("#txtUserPwds").val();
    var code = $("#txtCodes").val();
    $("#errorMsg1").html("");
    if (name == "") {
        $("#txtUserNames").focus();
        $("#errorMsg1").html("账户不能为空");
        return false;
    } else if (pwd == "") {
        $("#txtUserPwds").focus();
        $("#errorMsg1").html("密码不能为空");
        return false;
    } else if (code == "") {
        $("#txtCodes").focus();
        $("#errorMsg1").html("验证码不能为空");
        return false;
    } else {
        return true;
    }
}
function IsLogin(obj) {

    var url = obj.href;
    getAjax("/Mall/GetLogin.ashx", "", function (rs) {
        if (rs == "1") {
            window.location.open(url);
        }
        else {
            LoginShow();
           
            return false;
        }
    });
}
function getAjax(url, parm, callBack) {
    $.ajax({
        type: 'post',
        dataType: "text",
        url: url,
        data: parm,
        cache: false,
        async: false,
        success: function (msg) {
            callBack(msg);
        }
    });
}
