// JScript source code

function login(type){
     var username = $("#txtUserName").val();
     var pwd = $("#txtPwd").val();

      if (username == "" || pwd == "")
      {
            jAlert("请输入用户名或者密码","提示");
            return;
       }
       
       parent.bljs.location.href="http://passport.yeshj.com/api/hj_login.aspx?uc_user="+username+"&uc_pwd="+pwd;
       
               $.ajax({
                type:"POST",
                url:"/vip/getuser.aspx",
                data:"username="+username+"&pwd="+pwd,
                success:function(Msg){
                    if (Msg != null || Msg != "")
                    {
                        var objs = eval("user="+Msg);
                        var uid = user.UserID;
                        if (uid > 0)
                        {
                            var vipFlag = user.IsVip;
                            //正确登录，读取信息。。
                            var html = "<div class=\"mode\">";
                                html += "<div id=\"vipuser\">";
                                    html += "<div id=\"viph_portrait\"><img src=\""+ user.UserIcon +"\"/></div>";
                                    html += "<div id=\"viph_name\">";
                                    if (vipFlag == 1)
                                    {
                                        html += "您好，尊贵的VIP![<a href=\"/logout.aspx?Url=/vip\"><span class=\"qiut\">退出</span></a>]<span class=\"name\">"+ user.UserName +"</span>";
                                    }
                                    else
                                    {
                                         html += "您好![<a href=\"/logout.aspx?Url=/vip\"><span class=\"qiut\">退出</span></a>]<span class=\"name\">"+ user.UserName +"</span>";
                                    }
                                    html += "</div>";
                                html += "</div>";
                                if (vipFlag == 1)
                                {
                                    html += "<div class=\"vipinfo\">";
                                        html += "<div class=\"vipinfoday\"><span class=\"more_vipinfo\"><a href=\"/vip/myvip.aspx\">详情</a></span>您的VIP级别是：<span style=\"vertical-align:middle; \"><img src=\"/vip/images/level_"+ user.VipLevel+"_bulo.gif\" style=\"margin-top:2px;\" /></span></div>";
                                        html += "<div class=\"vipinfoday\"><a href=\"javascript:void(0);\" class=\"xufei\" onclick=\"alert('很抱歉，VIP服务已暂停销售。如有疑问，请咨询在线客服。');\">续费</a>";
                                        html += "会员到期：<span class=\"oran\">"+ user.ExpiredDate +"</span></div>";
                                    html += "</div>";
                                }
                                html += "<div class=\"vipinfo\">";
                                    html += "<div class=\"vipinfoday\"><span class=\"more_vipinfo\"><a href=\"http://bulo.hjenglish.com/account/log\" target=\"_blank\">详情</a></span>沪元余额：<span>"+ user.Wealth +"</span></div>";
                                    html += "<div class=\"vipinfoday\"><span class=\"more_vipinfo\"><a href=\"javascript:void(0);\" class=\"xufei\" onclick=\"openContent('/xb/pay');\">充值</a></span><div class=\"change_xbye\">"+ user.Xb +"</div></div>";
                                html += "</div>";
                                html += "<div class=\"vipinfo\">";
                                    html += "<div class=\"vipinfoday\">您的购买记录：";
                                        html += " <span><a href=\"/vip/myvip.aspx\" target=\"_blank\">查看详情</a></span>";
                                        html += "<div style=\"padding-top:3px;\"><a href=\"/xb\" target=\"_blank\" class=\"bt_xb_center\">学币中心</a></div>";
                                    html += "</div>";
                                html += "</div>";
                            html += "</div>";
                            
                            $('#viplogin').jqmHide();
                            document.getElementById("logincnt").innerHTML = html;
                            //DOM转换
                              $("#showrecord").html("<li><a href=\"/vip/myviporder.aspx\" id=\"menu_record\" title=\"付费记录\"></a></li>");
                                $("#showclass").html("<a href=\"http://class.yeshj.com\" id=\"menuclass\" title=\"沪江网校\" target=\"_blank\"></a>");
                            if(vipFlag == 1){
                                $("#upgradevip").html("<a href=\"http://www.hjenglish.com/down/\" id=\"goxf\" ></a>");
                            }
                           
                            switch(type)
                            {
                                case "my":
                                location.href = "/vip/myvip";
                                break;
                                case "order":
                                location.href = "/vip/myorders";
                                break;
                            }
                        }
                        else
                        {
                                 switch(uid){
                                        case 0:
                                         jAlert("用户名不存在","提示");
                                         
                                        break;
                                        case -11:
                                         jAlert("是社区帐号但是密码不正确","提示");
                                         
                                        break;
                                        case -1:
                                            openContent('checkout_vip2.aspx?action=upgrade&up_username='+username);
                                            $('#viplogin').jqmHide();
                                            
                                        break;
                                        case -2:
                                            jAlert("密码不正确，请重新输入","提示");
                                            $("#txtPwd").val("");
                                            $("#txtPwd").focus();
                                            
                                        break;
                                        case -4:
                                            jAlert("异常错误","提示");
                                            
                                        break;
                                        case -3:
                                            jAlert("账户已被锁定，请联系客服","提示");
                                            
                                        break;
                                  }
                                  
                        }
                    }
                    else
                    {
                        jAlert("数据读取错误，请重试:(","提示");
                    }
                }
            });
}


        function openContent(openUrl)
        {
            var width  = Math.floor( screen.width  * .65 );
	        var height = Math.floor( screen.height * .5 );
	        var leftm  = Math.floor( screen.width  * .1)+30;
	        var topm   = Math.floor( screen.height * .02)+30;
	        var argu = "toolbar=0,location=no,maximize=1,directories=0,status=1,menubar=0,scrollbars=1, resizable=1,left=" + leftm+ ",top=" + topm + ", width=800, height=600";
	        var url=openUrl;
	        window.open(url,"",argu);
        }
