﻿function LgState(){//判断是否登陆
    this.divid=$("#UserState");
    this.isLogin=function(){//判断是否登陆
        if(this.divid.length>0){
            var result=this.GetLogin();
            if(result.length==0){
                this.divid.html(this.ShowDiv(""));
            }else{
                this.divid.html(this.ShowDiv(result));
            }
        }
    }
    this.ShowDiv=function(username){//显示登陆后信息
        if(username.length==0){
            return"<span class=\"balck12\">您好，欢迎光临动力商城！请</span><a href=\"/user/register.aspx\" class=\"menu-12red\" rel='nofollow'>【登录】</a><span class=\"balck12\">未注册用户请</span><a href=\"/user/register.aspx\" class=\"menu-12red\" rel='nofollow'>【免费注册】</a><span class=\"balck12\"> 如需帮助请联系</span><a href=\"#\" onClick=\"openDoyooCustomChat('13284');return false\" target=\"_blank\" class=\"menu-12red\" rel='nofollow'>【在线客服】</a>";
        }else{
            return"<div style='float:left;'><span class=\"balck12\">您好,</span><a href=\"#\" ><span style=\"color:#7007D5;text-decoration: none;font-size:12px;font-weight:bold\">"+username+"</span></a>,欢迎光临动力商城! <a href=\"javascript:Ls.ExitLg()\" class=\"lan12\" rel='nofollow'>【安全退出】</a></div><div style='float:right;margin-right:8px;'><span class=\"balck12\"> 如需帮助请联系</span><a href=\"#\" onClick=\"openDoyooCustomChat('13284');return false\" target=\"_blank\" class=\"menu-12red\" rel='nofollow'>【在线客服】</a></div>";
        }
    }
    this.ExitLg=function(){//推出登陆
        if(!window.confirm('您确定要退出登录吗?'))return;
        if(this.divid.length>0){
            var result=this.GetExitLogin();
            if(result==1){
                if($("#pgurl").length>0&&$("#pgurl").val()==1){//如果用户在会员中心点击退出
                    location.href="/";
                }
                this.divid.html(this.ShowDiv(""));
            }else{
                this.divid.html(this.ShowDiv(""));
            }
        }
    }
    this.GetLogin=null;
    this.GetExitLogin=null;
}
function LoginIn(){//登陆
    this.uname=null;this.upwd=null;this.uyz=null;this.divid=$("#UserState");
    this.showlogin=function(){
        sm.showConten=this.htmllogin();
        sm.openNewDiv();
    }
    this.login=function()
    {
        if(this.Uname()&&this.Upwd()&&this.Uyz())
        {
            var result=this.GetValue(this.uname,this.upwd,this.uyz);//登陆动作
            switch(result){
            case"-1": if(this.divid.length>0)this.divid.html(this.ShowDiv(""));$("#ShowContent").html(this.rusulehtml("验证码输入有误,请重试!",""));break;
            case"0": if(this.divid.length>0)this.divid.html(this.ShowDiv(""));$("#ShowContent").html(this.rusulehtml("用户名错误,请重试!",""));break;
            case"-4": if(this.divid.length>0)this.divid.html(this.ShowDiv(""));$("#ShowContent").html(this.rusulehtml("密码错误,请重试!",""));break;
            case"-2": if(this.divid.length>0)this.divid.html(this.ShowDiv(""));$("#ShowContent").html(this.rusulehtml("验证码已过期,请重试!",""));break;
            default: 
                if(result!=null&&typeof(result)!="undefined"){
                    if(this.divid.length>0)this.divid.html(this.ShowDiv(result));
                    sm.closeDivs();
                    if(this.ResultFun!=null){this.ResultFun();}
                    }else{
                        $("#ShowContent").html(this.rusulehtml("系统繁忙,请重试或与管理员联系!!",""));
                    }
                    break;
            }
        }
    }
    this.GetValue=null;
    this.GetYzValue=null;
    this.ResultFun=null;
    this.ShowDiv=function(username){//登陆之后的状态
        if(username!=null){
            if(username.length==0){
                return"<span class=\"balck12\">您好，欢迎光临动力商城！请</span><a href=\"/user/register.aspx\" class=\"menu-12red\" rel='nofollow'>【登录】</a><span class=\"balck12\">未注册用户请</span><a href=\"/user/register.aspx\" class=\"menu-12red\" rel='nofollow'>【免费注册】</a><span class=\"balck12\"> 如需帮助请联系</span><a href=\"#\" onClick=\"openDoyooCustomChat('13284');return false\" target=\"_blank\" class=\"menu-12red\" rel='nofollow'>【在线客服】</a>";
            }else{
                return"<div style='float:left;'><span class=\"balck12\">您好,</span><a href=\"#\" ><span style=\"color:#7007D5;text-decoration: none;font-size:12px;font-weight:bold\">"+username+"</span></a>,欢迎光临动力商城! <a href=\"javascript:Ls.ExitLg()\" class=\"lan12\" rel='nofollow'>【安全退出】</a></div><div style='float:right;margin-right:8px;'><span class=\"balck12\"> 如需帮助请联系</span><a href=\"#\" onClick=\"openDoyooCustomChat('13284');return false\" target=\"_blank\" class=\"menu-12red\" rel='nofollow'>【在线客服】</a></div>";
            }
        }
    }
    this.Uname=function(){//验证用户名
        this.uname=$.trim($("#uname").val());
        if(this.uname.length==0){
            $("#txtname").html("<span style=\"color:#FF0000\">请填写用户名!</span>");return false;
        }else{
            $("#txtname").html("");return true;
        }
    }
    this.Upwd=function(){//验证密码
        this.upwd=$("#upwd").val();
        if(this.upwd.length==0){
            $("#txtpwd").html("<span style=\"color:#FF0000\">请填写密码!</span>");return false;
        }else{
            $("#txtpwd").html("");return true;
        }
    }
    this.Uyz=function(){//验证验证码
        this.uyz=$.trim($("#uyz").val());
        if(this.uyz.length==0){
            $("#txtyz").html("<span style=\"color:#FF0000\">请输入验证码</span>");return false;
        }else if(this.uyz.length!=4){
            $("#txtyz").html("<span style=\"color:#FF0000\">验证码有误</span>");return false;
        }else{
            $("#txtyz").html("&nbsp;");return true;
        }
    }
    this.Times=function(){//生成随机数
        var d=new Date();
        return d.getMilliseconds()+d.getTime()+d.getSeconds();
    }
    this.htmllogin=function(){//弹窗登录框代码
    return  "<table width=\"355\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"margin-top:18px;\">"+
            "  <tr>"+
            "    <td width=\"90\" height=\"30\" align=\"right\"><span class=\"balck12\">用户名：</span></td>"+
            "    <td colspan=\"2\" align=\"left\"><input id=\"uname\" onblur=\"lg.Uname()\" name=\"Input\" type=\"text\"  class=\"zhuce-input\"> &nbsp;<span id=\"txtname\" class=\"price12hui\">请输入用户名</span></td>"+
            "  </tr>"+
            "  <tr>"+
            "    <td height=\"30\" align=\"right\"><span class=\"balck12\">密码：</span></td>"+
            "    <td colspan=\"2\" align=\"left\"><input id=\"upwd\" onblur=\"lg.Upwd()\" style=\"width:146px;height:16px\" name=\"Input\" type=\"password\" class=\"zhuce-input\" > &nbsp;<span class=\"price12hui\" id=\"txtpwd\">请输入密码</span></td>"+
            "  </tr>"+
            "  <tr>"+
            "    <td height=\"30\" align=\"right\"><span class=\"balck12\">验证码：</span></td>"+
            "    <td colspan=\"2\" align=\"left\"><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td width=\"95\"><input onblur=\"lg.Uyz()\" id=\"uyz\" name=\"Input3\" type=\"text\"  class=\"zhuce-input2\" style=\"width:85px;\"></td><td width=\"66\"><img width=\"58\" height=\"24\" src=\"/another/ValidateCode.aspx?"+this.Times()+"\"></td><td> <span class=\"price12hui\" id=\"txtyz\">请输入验证码</span></td></tr></table></td>"+
            "  </tr>"+
            "  <!--tr>"+
            "    <td height=\"35\" align=\"right\">"+
            "      </td>"+
            "    <td colspan=\"2\" align=\"left\" valign=\"middle\"><input type=\"checkbox\" name=\"checkbox\" value=\"checkbox\" >&nbsp;<span class=\"balck12\">记住用户名</span></td>"+
            "  </tr-->"+
            "  <tr>"+
            "    <td height=\"55\" align=\"right\">&nbsp;</td>"+
            "    <td valign=\"middle\"><a href=\"javascript:lg.login()\"><img src=\"/images/webicon/tc-denglu.gif\" width=\"57\" height=\"25\" align=\"absmiddle\"  style=\"padding:0px 20px 0px 20px\" ></a> <a href=\"javascript:rg.showReg()\" class=\"menu-12red\">注册新用户</a> <a href=\"/user/getkey.aspx\" target=\"_blank\" class=\"menu-12red\">忘记密码？</a></td>"+
            "  </tr>"+
            "</table>";
    }
    this.rusulehtml=function(zt,hape){//状态框代码
        return  "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"margin-top:2px;\" align=\"center\">"+
                "  <tr>"+
                "    <td width=\"120\" height=\"30\">&nbsp;</td>"+
                "    <td>&nbsp;</td>"+
                "  </tr>"+
                "  <tr>"+
                "    <td rowspan=\"2\" align=\"center\"><img src=\"/admin/images/error_11.gif\"/></td>"+
                "     <td height=\"30\" style=\"font-size:14px; color:#FF0000\">"+zt+"</td>"+
                "  </tr>"+
                "  <tr>"+
                "       <td height=\"60\">"+hape+"</a></td>"+
                "  </tr>"+
                "  <tr>"+
                "    <td height=\"40\">&nbsp;</td>"+
                "    <td><a href=\"javascript:lg.Chongshi()\" title=\"返回重试\"><img src=\"/images/webicon/jf_06_fan.gif\" style=\"margin-right:20px\"/></a><a href=\"javascript:sm.closeDivs()\" title=\"关闭\"><img src=\"/images/webicon/cloes_06.gif\"/></a></td>"+
                "  </tr>"+
                "</table>";
    }
    this.Chongshi=function(){
        $("#ShowContent").html(this.htmllogin());
    }
    OnKeyDown();
}
function Register(){//注册
    this.uname=null;this.upwd=null;this.uqrpwd=null;this.uemall=null;this.uyz=null;this.checks=null;this.divid=$("#UserState");
    this.showReg=function(){
        ss.showConten=this.showHtml();
        ss.openNewDiv();
    }
    this.Uname=function(){//验证用户名
        this.uname=$.trim($("#u_name").val());
        $("#txtname").html("验证中...");
        if(this.uname.length==0){
            $("#txtname").html("用户名必填!");return false;
        }else{
            if(this.uname.length<4){
                $("#txtname").html("用户名应大于4位!");return false;
            }else{
                var reg=/^[0-9a-zA-Z_]*$/;
                if(reg.test(this.uname)){
                    if(this.Yzname()==0){
                        $("#txtname").html("&nbsp;");return true;
                    }else{
                        $("#txtname").html("用户名 \" "+this.uname+"\" 已经存在!");return false;
                    }
                }else{
                    $("#txtname").html("用户名必须以英文、数字及“_”、“-”组成");return false;
                }
            }
        }
    }
    this.Upwd=function(){//验证密码
        this.upwd=$("#u_pwd").val();
        $("#txtpwd").html("验证中...");
        if(this.upwd.length==0){
            $("#txtpwd").html("请填写密码!");return false;
        }else{
            if(this.upwd.length<6){
                $("#txtpwd").html("密码应大于6位!");return false;
            }else{
                $("#txtpwd").html("&nbsp;");return true;
            }
        }
    }
    this.Uqrpwd=function(){//验证确认密码
        this.uqrpwd=$("#uqrpwd").val();
        $("#txtqrpwd").html("验证中...");
        if(this.uqrpwd.length>0){
            if(this.upwd==this.uqrpwd){
                $("#txtqrpwd").html("&nbsp;");return true;
            }else{
                $("#txtqrpwd").html("两次输入密码不一致!");return false;
            }
        }else{
            $("#txtqrpwd").html("请输入确认密码!");return false;
        }
    }
    this.Uemall=function(){//用户email
        this.uemall=$.trim($("#uemall").val());
        $("#txtemall").html("验证中...");
        if(this.uemall.length>0){
            var filter=/^\s*([A-Za-z0-9_-]+(\.\w+)*@(\w+\.)+\w{2,3})\s*$/;
            if(!filter.test(this.uemall)){
                $("#txtemall").html("emall输入有误!");return false;
            }else{
                $("#txtemall").html("&nbsp;");return true;
            }
        }else{
            $("#txtemall").html("请输入您的emall!");return false;
        }
    }
    this.Uyz=function(){//验证码验证
        this.uyz=$.trim($("#u_yzr").val());
        $("#txtyanz").html("验证中...");
        if(this.uyz.length==0){
            $("#txtyanz").html("请输入验证码");return false;
        }else if(this.uyz.length!=4){
            $("#txtyanz").html("验证码有误");return false;
        }else{
            var filter=/^\d{4}$/;
            if(!filter.test(this.uyz)){
                $("#txtyanz").html("验证码有误");return false;
            }else{
                $("#txtyanz").html("&nbsp;");return true;
            }
        }
    }
    this.Uche=function(){//验证协议框
        this.checks=$("#u_che");
        $("#cxy").html("验证中...");
        if(this.checks.attr("checked")){
            $("#cxy").html("");return true;
        }else{
            $("#cxy").html("如果您已同意协议,请打钩!");return false;
        }
    }
    this.Times=function(){//生成随机数
        var d=new Date();
        return d.getMilliseconds()+d.getTime()+d.getSeconds();
    }
    this.addUser=function(){//注册会员
        if(this.Uname()&&this.Upwd()&&this.Uqrpwd()&&this.Uemall()&&this.Uyz()&&this.Uche()){
        var result=this.GetAddUser(this.uname,this.upwd,this.uemall,this.uyz);
        switch(result){
            case-1: if(this.divid.length>0)this.divid.html(this.ShowDiv(""));$("#ShowContent").html(this.rusulehtml("验证码输入有误,请重试!",""));break;
            case 0: if(this.divid.length>0)this.divid.html(this.ShowDiv(""));$("#ShowContent").html(this.rusulehtml("注册失败,请重试!",""));break;
            case-3: if(this.divid.length>0)this.divid.html(this.ShowDiv(""));$("#ShowContent").html(this.rusulehtml("注册成功 登陆失败,请重新登录!",""));break;
            case-2: if(this.divid.length>0)this.divid.html(this.ShowDiv(""));$("#ShowContent").html(this.rusulehtml("验证码已过期,请重试!",""));break;
            default:
                if(result!=null&&typeof(result)!="undefined"){
                    if(this.divid.length>0)this.divid.html(this.ShowDiv(result));
                    ss.closeDivs();
                    if(this.ResultFun!=null){this.ResultFun();}
                }else{
                    $("#ShowContent").html(this.rusulehtml("系统繁忙,请重试或与管理员联系!",""));
                }
                break;
            }   
        }
    }
    this.ShowDiv=function(username){//改变登录状态
        if(username.length==0){
            return"<span class=\"balck12\">您好，欢迎光临动力商城！请</span><a href=\"/user/register.aspx\" class=\"menu-12red\" rel='nofollow'>【登录】</a><span class=\"balck12\">未注册用户请</span><a href=\"/user/register.aspx\" class=\"menu-12red\" rel='nofollow'>【免费注册】</a><span class=\"balck12\"> 如需帮助请联系</span><a href=\"#\" onClick=\"openDoyooCustomChat('13284');return false\" target=\"_blank\" class=\"menu-12red\" rel='nofollow'>【在线客服】</a>";
        }else{
            return"<div style='float:left;'><span class=\"balck12\">您好,</span><a href=\"#\" ><span style=\"color:#7007D5;text-decoration: none;font-size:12px;font-weight:bold\">"+username+"</span></a>,欢迎光临动力商城! <a href=\"javascript:Ls.ExitLg()\" class=\"lan12\" rel='nofollow'>【安全退出】</a></div><div style='float:right;margin-right:8px;'><span class=\"balck12\"> 如需帮助请联系</span><a href=\"#\" onClick=\"openDoyooCustomChat('13284');return false\" target=\"_blank\" class=\"menu-12red\" rel='nofollow'>【在线客服】</a></div>";
        }
    }
    this.Yzname=function(){
        var result=this.GetNameValue(this.uname);return result;
    }
    this.GetNameValue=null;
    this.GetAddUser=null;
    this.ResultFun=null;
    this.showHtml=function(){
        return "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\" style=\"margin-top:12px\">"+
        "  <tr>"+
        "    <td height=\"25\" width=\"24%\" align=\"right\"><span class=\"balck12\">用户名：</span></td>"+
        "    <td colspan=\"2\" align=\"left\"><input type=\"text\" id=\"u_name\" onblur=\"rg.Uname()\" class=\"zhuce-input1\" /> &nbsp;<span id=\"txtname\" style=\"color:#FF0000;font-size:12px\"></span></td>"+
        "  </tr>"+
        "  <tr>"+
        "    <td height=\"22\" colspan=\"3\"><span style=\"margin-left:100px\" class=\"price12hui\">4-20位字符，可由中英文、数字及“_”、“-”组成</span></td>"+
        "  </tr>"+
        "  <tr>"+
        "    <td  height=\"25\" align=\"right\"><span class=\"balck12\">密码：</span></td>"+
        "    <td colspan=\"2\" align=\"left\"><input type=\"password\" id=\"u_pwd\" style=\"width:150px;\" onblur=\"rg.Upwd()\"  class=\"zhuce-input1\" /> &nbsp;<span id=\"txtpwd\" style=\"color:#FF0000;font-size:12px\"></span></td>"+
        "  </tr>"+
        "  <tr>"+
        "    <td height=\"22\" colspan=\"3\"><span style=\"margin-left:100px\" class=\"price12hui\">6-16位字符，可由英文、数字及“_”、“-”组成</span></td>"+
        "  </tr>"+
        "  <tr>"+
        "    <td  height=\"25\"align=\"right\"><span class=\"balck12\">再次输入密码：</span></td>"+
        "    <td colspan=\"2\" align=\"left\"><input type=\"password\" id=\"uqrpwd\" style=\"width:150px;\" onblur=\"rg.Uqrpwd()\" class=\"zhuce-input1\" /> &nbsp;<span id=\"txtqrpwd\" style=\"color:#FF0000;font-size:12px\"></span></td>"+
        "  </tr>"+
        "  <tr>"+
        "    <td height=\"22\" colspan=\"3\"><span class=\"price12hui\" style=\"margin-left:100px\">6-16位字符，可由英文、数字及“_”、“-”组成</span></td>"+
        "  </tr>"+
        "  <tr>"+
        "    <td  height=\"25\" align=\"right\"><span class=\"balck12\">电子邮箱：</span></td>"+
        "    <td colspan=\"2\" align=\"left\"><input type=\"text\" id=\"uemall\" onblur=\"rg.Uemall()\"  class=\"zhuce-input1\" /> &nbsp;<span id=\"txtemall\" style=\"color:#FF0000;font-size:12px\"></span></td>"+
        "  </tr>"+
        "  <tr>"+
        "    <td height=\"22\" colspan=\"3\"><span style=\"margin-left:100px\" class=\"price12hui\">接收订单通知、促销活动、找回密码，填写后不能修改</span></td>"+
        " </tr>"+
        " <tr>"+
        "    <td  height=\"25\"  align=\"right\"><span class=\"balck12\">验证码：</span></td>"+
        "    <td colspan=\"2\" align=\"left\"><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td width=\"95\"><input onblur=\"rg.Uyz()\" id=\"u_yzr\" name=\"Input3\" type=\"text\"  class=\"zhuce-input2\" style=\"width:85px;\"></td><td width=\"66\"><img width=\"58\" height=\"24\" src=\"/another/ValidateCode.aspx?"+this.Times()+"\"></td><td> <span id=\"txtyanz\" style=\"color:#FF0000;font-size:12px\">&nbsp;</span></td></tr></table></td>"+
        "  </tr>"+
        "  <tr>"+
        "    <td  height=\"30\" align=\"right\"><input type=\"checkbox\" id=\"u_che\" value=\"checkbox\" checked=\"checked\"/></td>"+
        "    <td colspan=\"2\" align=\"left\" valign=\"middle\"><span class=\"balck12\">我已阅读并同意</span><a href=\"/agreement.htm\" target=\"_blank\" class=\"lan12\">《动力商城用户协议》</a><span id=\"cxy\" style=\"color:#FF0000;font-size:12px\"></span></td>"+
        "  </tr>"+
        "  <tr>"+
        "    <td  height=\"35\" align=\"right\">&nbsp;</td>"+
        "    <td valign=\"middle\"><a href=\"javascript:rg.addUser()\"><img src=\"/images/webicon/tc-zhuce.gif\" width=\"57\" height=\"25\" align=\"absmiddle\" style=\"padding:0px 200px 0px 20px\" /></a> <a href=\"javascript:lg.showlogin()\" class=\"menu-12red\">用户登录</a></td>"+
        "  </tr>"+
        "</table>";
    }
    this.rusulehtml=function(zt,hape){
        return  "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"margin-top:2px;\" align=\"center\">"+
                "  <tr>"+
                "    <td width=\"120\" height=\"30\">&nbsp;</td>"+
                "    <td>&nbsp;</td>"+
                "  </tr>"+
                "  <tr>"+
                "    <td rowspan=\"2\" align=\"center\"><img src=\"/admin/images/error_11.gif\"/></td>"+
                "     <td height=\"30\" style=\"font-size:14px; color:#FF0000\">"+zt+"</td>"+
                "  </tr>"+
                "  <tr>"+
                "       <td height=\"60\">"+hape+"</a></td>"+
                "  </tr>"+
                "  <tr>"+
                "    <td height=\"40\">&nbsp;</td>"+
                "    <td><a href=\"javascript:lg.Chongshi()\" title=\"返回重试\"><img src=\"/images/webicon/jf_06_fan.gif\" style=\"margin-right:20px\"/></a><a href=\"javascript:sm.closeDivs()\" title=\"关闭\"><img src=\"/images/webicon/cloes_06.gif\"/></a></td>"+
                "  </tr>"+
                "</table>";
    }
    OnKeyDown();
}
    function OnKeyDown(){//键盘回车事件
        window.document.onkeydown=function(){
            if(event.keyCode==13){
            var e=event.srcElement;
            if(e!=null&&(e.id=="uname"||e.id=="upwd"||e.id=="uyz")){
                lg.login();
            }else if(e!=null&&(e.id=="u_name"||e.id=="u_pwd"||e.id=="uqrpwd"||e.id=="uemall"||e.id=="u_yzr"||e.id=="u_che")){
                rg.addUser();
            }
            return false;
        }
    }
}