﻿function getCookie(name)//取cookies函数       
{

    var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));

    if (arr != null) return unescape(arr[2]); return null;

}

function Login(BackUrl) {
    if (BackUrl != "") {
        document.cookie = "SessionUrl" + "=" + BackUrl;
    }
    else {
        var exp = new Date();

        exp.setTime(exp.getTime() - 1);

        var cval = getCookie("SessionUrl");

        if (cval != null) document.cookie = "SessionUrl" + "=" + cval + ";expires=" + exp.toGMTString();
      }
    
    MsgBoxClass({
        LayerId: "#Layer",
        title: "用户登录",
        content: "<div style='height:200px;text-align:center;'><img style='margin-top:40px' src='/images/loading/loader2.gif' /></div>",
        okButtonText: "登 录",
        noButtonText: "取 消",

        okbutton_clcik: function() {
        
            //$("#Layer_clone").find('.tabcontent').children().eq(0).html("正在登陆");
            var UserName = $.trim($("#LoginUserName").val());
            var Pwd = $.trim($("#Pwd").val());
            var vcode = $.trim($("#text_vcode").val());
            var InviteID = $.trim($("#hi_InviteID").val());
            var IsSaveLogin = $("#SaveLogin").val();
            
            if (UserName == "" || Pwd == "" || vcode == "") {

                $("#Layer_clone").find(".WrongInfoDiv").html('用户名、密码、验证码不能为空');
                return;
            }
            if (!CheckStr(UserName)) {
                $("#Layer_clone").find(".WrongInfoDiv").html('用户名包含非法字符');
                return;
            }
            if (!CheckStr(Pwd)) {
                $("#Layer_clone").find(".WrongInfoDiv").html('密码包含非法字符');
                return;
            }
            $("#Layer_clone").find(".WrongInfoDiv").html('正在登陆，请稍等...');
            $.post("/Exc/Exe.aspx?ac=Login", { IsSaveLogin: "" + IsSaveLogin + "", UserName: "" + UserName + "", Pwd: "" + Pwd + "", Vcode: "" + vcode + "", InviteID: "" + InviteID + "" }, function(data) {
                if (data != "ok") {
                    $("#Layer_clone").find(".WrongInfoDiv").html(data);
                    GetVcodeLogin('Loginvcode', '/validatecode.aspx');
                }
                else {
                    if (BackUrl != "") {
                        window.location.href = BackUrl;
                    }
                    else {
                        window.location.href = window.location.href;
                    }

                }
            });
        },
        nobutton_clcik: function() {

            CloseLayer2("#Layer", true);
        }
    });
   
   var url="/user/LoginForm.htm?c="+Math.random();
   $("#Layer_clone").css("top", parseInt( $("#Layer_clone").css("top"))-100);
   $.get(url,function(data){
    
       $("#Layer_clone").find('.tabcontent').html(data);
       GetVcodeLogin('Loginvcode','/validatecode.aspx');
   });
}

//切换验证码
function GetVcodeLogin(obj,url)
{
  $("#text_vcode").val("");
  var VcodeObjs=document.getElementById(obj); 
  VcodeObjs.src=url +"?"+Math.random();
  
}
