﻿/*
'=====================================================================
' Author: WebSky
' Create on 2008-07-03
'=====================================================================
*/
/*function killErrors() {
return true;
}
window.onerror = killErrors;*/
//var loginstate = false;


//获取Cookies
//var UserNames=null; //Cookies姓名

var username        //接收登陆strUser
var password        //接收strPWD

 function GetCookies(sName)   
  {   
      var  aCookie = document.cookie.split(";");   
      for  (var   i=0;i< aCookie.length;i++)   
      {   
          var aCrumb =  aCookie[i].split("=");   
          if  (sName == aCrumb[0])     
         return unescape(aCrumb[3]);  
          username=aCrumb[3];
         
      }   
      return  null;   
  } 
//alert(username);




function checkNavigator()
{
   if(navigator["cookieEnabled"]==false)
   {
      alert("温馨提示：\n\n对不起，登陆操作需要先开启您浏览器的Cookies才能正常登陆！");
   }
}

/************************************************** 
参数说明： 
sMainName UserName Cookie名 
sSubName  FlySky   Cookie子键名，留空表示单值Cookie 
**************************************************/ 
/*
function  GetCookie(UserName, FlySky) 
{ 
var   sCookieName   =   FlySky   +   "= "; 
var   sSubCookieName   =   (FlySky)   ?   FlySky   +   "= "   :   null; 
var   sCookie; 
var   sWholeCookie   =   document.cookie; 
//alert(sWholeCookie);
var   nValueBegin   =   sWholeCookie.indexOf(sCookieName); 

if(nValueBegin   !=   -1) 
{ 
var   nValueEnd   =   sWholeCookie.indexOf( "; ",   nValueBegin); 
if   (nValueEnd   ==   -1) 
nValueEnd   =   sWholeCookie.length; 
var   sValue   =   sWholeCookie.substring(nValueBegin   +   sCookieName.length, nValueEnd); //获得Cookie值 

if(sSubCookieName) //多值Cookie 
{ 
var   nSubValueBegin   =   sValue.indexOf(sSubCookieName); 
if(nSubValueBegin   !=   -1) 
{ 
var   nSubValueEnd   =   sValue.indexOf( "& ",  nSubValueBegin); 
if(nSubValueEnd   ==   -1) 
nSubValueEnd   =   sValue.length; 
var   sSubValue   =   sValue.substring(nSubValueBegin  +  sSubCookieName.length, nSubValueEnd); //获得指定的子键值 
return   unescape(sSubValue); 

} 
} 
if(!sSubCookieName) 
return   unescape(sValue); 

} 
return   null; 
} 
*/


var urls = {
      login:"/Public/AjaxLogin.aspx" //登陆处理中心
    ,shoplogin:"/Public/login_yes_inc.aspx" //返回Xml值页面
    
    //,chk : "/public/inc/chk.aspx"
}

var LoginPopUp=Class.create();
LoginPopUp.prototype={
    initialize:function()
    {
        this.x = 410; //登陆框所在X轴
        this.y = 20; //登陆框所在Y轴
       
        //this.command = null;
        //this.appxml = null;
        //this.users = "";
        //this.MessageId = null;
        //this.LoginId = null;
        /* this.sendXML = null;   //发送XML
        this.responseXML = null;
        this.msg = null;
        this.code = null;
        this.fun = null;//外挂函数
        */
        /*
        if($("loginlink")==null)
        {
            var _css=document.createElement("link");
            _css.id="loginlink";
            _css.href="LogOn.css";
            _css.rel = "stylesheet";
            _css.type ="text/css";
            document.getElementsByTagName("head").item(0).appendChild(_css);
        }*/
    }
	
	
	
    ,set : function(f,mess)
    {//用户登陆操作
        //checkNavigator();
        
        //this.MessageId = mess?$(mess):$("Message");
       // this.LoginId = $("loginmsg");
        /*this.loadings();
		this.command = "userlogin";
        this.users=f.strUser.value.toLowerCase();
      
 	    this.appxml = "<username>"+this.users+"</username>"
	       +"<userpsw>"+f.strPWD.value+"</userpsw>"
           +"<note>"+f.note.checked+"</note>"
	       +"<url>"+f.url.value+"</url>"; */
		this.load();
		//alert(this.appxml);
		return false;
    }
	
    ,get:function()
    {//查询用户登陆状态
        //this.MessageId = $("loginmsg");
       //alert(this.MessageId);
        //this.LoginId = $("loginmsg");
        //alert(this.LoginId);
        //this.loadings();
        var cacheLogins = getCookie("Login");  // 获取UserLogin状态
	    username=getCookie("UserName")   
	    //alert(cacheLogins+username)
        //alert(cacheLogins);
         // alert(username);
        if(cacheLogins == "yes")
        {//已登陆，验证登陆的合法性 
	      // this.command = "checkUsersLoginState";
	       //this.appxml = "<loginstate>"+getDataTime()+"</loginstate>";
	       //alert(this.appxml);
		   //this.load();
		   if(username!="undefined" && username!="null")
		   {
		    GetLogin(); 
		   }
		   else
		   {
		    this.lose();
		    return false;
		   }
        }
        else
        {
        //  Getlose(); //浮动登陆
          this.lose();//固定登陆
          return false;
          }
		
    }
	
    ,load:function()//加载函数 
    {
       // this.sendXML = toSCPXML(this.command,this.appxml);
       //_sendx(urls.login,this.databind.bind(this),this.LoginId,"POST",this.sendXML);
       //_sendx("/AjaxLogin/AjaxLogin.aspx?username="+username+"&password="+password+"");
         // alert(urls.login);
          //alert(this.databind.bind(this));
          //alert(this.LoginId);
    }
    
   // ,databind:function(p,v)
  //  {
	    //this.responseXML=v;
        //this.parameter();
        //if(this.command == "userlogin") this.loginInfo();
        //else this.checkInfo();
   // }
    
  
   // ,loginInfo:function()
   // {
     //   if (this.code == 2000){
    //        this.hide();
           // this.setInfo();
             /* //window.open('http://Manage.Bzw.cn');
            /********************设置用户登陆后的功能项*******************
            this.startup();
	    } 
        else if (this.code == 5000){
	          if(this.MessageId) this.MessageId.innerHTML ="<font color=red>"+this.msg+"</font>";
	          else alert(msg);
	    }  //else {
	          //alert("There was a problem retrieving the XML data:\n" + req.statusText);
	          //alert("系统提示：\n\n您当前的操作服务器无法响应，请联系管理员解决这一问题！");
	          */
      //  }
  //  }
	
	 
 //   ,checkInfo:function()
  //  {
       // var o = this.LoginId;
     //   if (this.code == 2000){
          //var userinfo=this.msg.split("|");
         // if(userinfo!=null && userinfo[0]=="yes")
	     // {
	         // this.users = userinfo[1];
             // this.msg = userinfo[3];
        //      this.setInfo();
	         // this.startup();
	    //      return ;
	      //}
     //   }
        //if(!loginstate) 
      //  this.lose();
   // } 
    
    
   /* ,setInfo : function()
    {//登陆成功后的信息设定 
        var o = this.LoginId;
        if(!o) return;
        o.className = "top_dlh";
        
        var str = "<h1></h1><ul><li><span class=\"tsA\">欢迎回家，<b>" + this.users + "</b> <a href=\"/public/logout.aspx\">[退出]</a></span><span class=\"tsB\"><a href=\"http://manage.Bzw.com/?url=/guestbook/\"  target=_blank >消息<b>(";
        if(parseInt(this.msg)>0)
            str += this.msg;
        else
            str += this.msg;
        str += ")</b></a></span></li></ul>";
        o.innerHTML = str;
        //alert(str);
       
        //如果是首页
        if($("usershoploginMsg"))
        {
            //$("usershoploginMsg").className = "login_content";
               // _sendx(urls.shoplogin+"?tmp"+getDataTime(),this.pageshopbind.bind(this),"usershoploginMsg");
                alert(urls.shoplogin);
               
        }
        
    }
     */
     
     
    ,Enter :function(e)
    {
    	var keyCode = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;
    	if (keyCode == 13)
    	{
    		this.set(document.all.userlogintopform);
    		return false;
    	}
    	else
    	{
    		return true;
    	}
    }
    
  /*
    ,startup :function()
    {//设置用户登陆后的功能项
        UserName = this.users;
	    loginstate = true;
		setUserConfig(this.users);
		if(this.fun!=null) this.fun();//外挂函数
    }
    
    
    ,parameter :function()
    {//参数处理 
        this.msg  = getMessage(this.responseXML,"msg");
		this.code = getCode(this.responseXML);
    }
    */
  //  ,loadings :function()
   // {
        //this.MessageId.innerHTML = "请梢等，正在验证信息...";
   // }
	
	
	
    ,show:function()
    {
        var _d = $('LoginDIV');
        _d.show();
        _d.style.left = this.x;
        _d.style.top = this.y;
    }
    ,hide:function()
    {
       if($('LoginDIV')) $('LoginDIV').hide();
    }
   
   ,lose :function()
    {//未登陆信息 
//       //this.LoginId.innerHTML = "尊敬的开心吧棋牌游戏中心用户，请先<a href=#login onClick=login.show();>登陆</a>";
  //      Getlose();
//           // document.getElementById("loginmsg").innerHTML="尊敬的开心吧棋牌游戏中心用户，请先<a href=#login onClick=login.show();>登陆</a>";

        //左边登陆
        if($("usershoploginMsg")) 
        {
            $("usershoploginMsg").innerHTML = this.myNotLogin();
        }
   }
	
    ,myNotLogin : function()
    {        
             var _html="<table width=\"200\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">"
                    +"<tr>"
                    +"<td width=\"21\" rowspan=\"3\">&nbsp; </td>"
                    +"<td height=\"25\"><img src=\"/Image/index_22.jpg\" width=\"47\" height=\"16\" alt=\"\"></td>"
                    +"<td height=\"25\"><input name=\"strUsers\" type=\"text\" size=\"16\" onMouseOver=\"this.style.background='#024387';\" onMouseOut=\"this.style.background='#024387'\" onFocus=\"this.select();\" style=\"width: 110px; border-right: #242B02 0px solid;border-top: #242B02 0px solid; font-size: 9pt; border-left: #242B02 0px solid;border-bottom: #FFFFFF 1px solid; height: 16px; background-color: #024387;color:#fff\"></td>"
                    +"<td width=\"21\" rowspan=\"3\">&nbsp; </td>"
                    +"</tr>"
                    +"<tr>"
                    +"<td height=\"25\"><img src=\"/Image/index_32.jpg\" width=\"47\" height=\"16\" alt=\"\"></td>"
                    +"<td height=\"25\"><input name=\"strPWDs\" type=\"password\" size=\"16\" onMouseOver=\"this.style.background='#024387';\" onMouseOut=\"this.style.background='#024387'\" onFocus=\"this.select();\" style=\"width: 110px; border-right: #242B02 0px solid;border-top: #242B02 0px solid; font-size: 9pt; border-left: #242B02 0px solid;border-bottom: #FFFFFF 1px solid; height: 16px; background-color: #024387;color:#fff\"></td>"
                    +"</tr>"
                    +"<tr>"
                    +"<td height=\"35\" colspan=\"2\" valign=\"top\">"
                    
                    +"<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr>"
                    +"<td align=\"right\"><div><input name=\"logsend\" type=\"submit\" value=\"\" class=\"inp2\" onclick=\"checklogins()\" /></div></td>"
                    +"<td align=\"center\"><div><a href=\"/Manage/Retake.html\"><img src=\"/Image/index_40.jpg\" width=\"61\" height=\"24\" border=\"0\" alt=\"\"></a></div></td>"
                    +"</tr>"
                    +"<tr>"
                    +"<td colspan=\"2\">"
                    +"<div style=\"color:#FFFFFF;padding-left:1px; display:none\" id=\"Messages\"></div>"
                    +"</td>"
                    +"</tr>"
                    +"</table>"
                    +"</td>"
                    +"</tr>"
                    

                    +"</table>"

       return _html;
    }
	
	
    ,pageshopbind : function(p,v)
    {
        $(p).innerHTML = v;
    }
    ,logMar : function(x,y)
    {
        this.x = x;
        this.y = y;
    }
    ,state : function(fun)
    {
        fun = fun?fun:this.fun?this.fun:function(){return true};
        if(loginstate) { if(fun()) return true;}
        else { DisplayDIV(this.x,this.y,'LoginDIV'); return false;}
    }
}



var xmlHttp; //创造xmlHttpRequest对象
 function createXMLHttpRequest()
   {
      if(window.ActiveXObject)
          {
             xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
             
          }
          else if(window.XMLHttpRequest)
             {
               xmlHttp=new XMLHttpRequest();
             }
     }


 //时间函数
function getDataTime()
{
	var strDate,strTime;
	strDate = new Date();
	strTime = strDate.getTime();
	return strTime;
}


/************************************************** 
参数说明：                  浮动登陆 
strUser 用户名 
strPWD  密 码
Message 返回状态
**************************************************/ 
function checklogin()   //浮动登陆检测
  {
     var tmpdate=getDataTime();
     username=document.getElementById("strUser").value;
     password=document.getElementById("strPWD").value;

     
    if(username.length==0)
       {  
        document.getElementById("Message").innerText="温馨提示:请输入用户名！";
        window.event.returnValue=false;
        document.getElementById("strUser").focus();
        return false;
        }
        else
          {
              if(password.length==0)
                {
                     document.getElementById("Message").innerText="温馨提示:请输入密码！";
                     window.event.returnValue=false;
                     document.getElementById("strPWD").focus();
                     return false;
                }
          }
         createXMLHttpRequest();//创建对象
        var url=""+urls.login+"?username="+username+"&password="+password+"&tmp="+tmpdate;
        //alert(url);
        xmlHttp.open("GET",url,true);//传递到服务器进行处理
        xmlHttp.onreadystatechange=callback;
        xmlHttp.send(null);
  }
  
  //回调函数的代码
  function callback()
    {
      document.getElementById("Message").innerText="请梢等，正在验证信息...";
        var tmpdate=getDataTime();
            if(xmlHttp.readyState==4)
             {
                  if(xmlHttp.status==200)
                      {
                            var strText=xmlHttp.responseText;
                            //alert(strText);
                             if(strText=="True")
                              {
                                 setTimeout("GetLogin();",1200);
                              }
                             else if(strText=="False")
                              { 
                                   setTimeout("document.getElementById(\"Message\").innerText=\"温馨提示:你输入的密码或用户名错误！\"",1200);
                                    document.getElementById("strPWD").focus();
                                    return false;
                               }
                             else if(strText=="NoPass")
                              {
                                    setTimeout("document.getElementById(\"Message\").innerText=\"温馨提示:您的号已经被管理员限制，不能登陆！\"",1200);
                                    document.getElementById("strUser").focus();
                                    return false;
                              }
                              else if(strText=="NoReg")
                              {
                                    setTimeout("document.getElementById(\"Message\").innerText=\"温馨提示:你输入的密码或用户名错误！\"",1200);
                                    document.getElementById("strUser").focus();
                                    //ChkReg();
                                    return false;
                                   
                              }
                              else
                               {
                                    setTimeout("document.getElementById(\"Message\").innerText=\"温馨提示:系统异常，请稍后再尝试登录！\"",1200);
                                     document.getElementById("strUser").focus();
                                     return false;
                               }
                         }
                 }
}
  
  
  
  


/************************************************** 
参数说明：                  左边登陆 
strUsers 用户名 
strPWDs  密 码
Messages 返回状态
**************************************************/ 
function checklogins()   
  {
     var tmpdate=getDataTime();
     username=document.getElementById("strUsers").value;
     password=document.getElementById("strPWDs").value;
    if(username.length==0)
       {  
        document.getElementById("Messages").style.display="block"
        //document.all.style.display='block|none'
        document.getElementById("Messages").innerText="温馨提示:请输入用户名！";
        window.event.returnValue=false;
        document.getElementById("strUsers").focus();
        return false;
        }
        else
          {
              if(password.length==0)
                {
                      document.getElementById("Messages").style.display="block"
                     document.getElementById("Messages").innerText="温馨提示:请输入密码！";
                     window.event.returnValue=false;
                     document.getElementById("strPWDs").focus();
                     return false;
                }
          }
         createXMLHttpRequest();//创建对象
        var url=""+urls.login+"?username="+username+"&password="+password+"&tmp="+tmpdate;
        //alert(url);
        xmlHttp.open("GET",url,true);//传递到服务器进行处理
        xmlHttp.onreadystatechange=callbacks;
        xmlHttp.send(null);
  }

 //回调函数的代码
  function callbacks()
    {
      document.getElementById("Messages").style.display="block"
      document.getElementById("Messages").innerText="请梢等，正在验证信息...";
        var tmpdate=getDataTime();
            if(xmlHttp.readyState==4)
             {
                  if(xmlHttp.status==200)
                      {
                            var strText=xmlHttp.responseText;
                            //alert(strText);
                             if(strText=="True")
                              {
                                 setTimeout("GetLogin();",1200);
                              }
                             else if(strText=="False")
                              { 
                                    setTimeout("document.getElementById(\"Messages\").innerText=\"温馨提示:你输入的密码错误！\"",800);
                                    document.getElementById("strPWDs").focus();
                                    return false;
                               }
                             else if(strText=="NoPass")
                              {
                                    setTimeout("document.getElementById(\"Messages\").innerText=\"温馨提示:您的号已经被管理员限制，不能登陆！\"",800);
                                    document.getElementById("strUsers").focus();
                                    return false;
                              }
                              else if(strText=="NoReg")
                              {
                                    setTimeout("document.getElementById(\"Messages\").innerText=\"温馨提示:你输入的用户名不存在！\"",800);
                                    document.getElementById("strUsers").focus();
                                    //ChkReg();
                                    return false;
                                   
                              }
                              else
                               {
                                    setTimeout("document.getElementById(\"Messages\").innerText=\"温馨提示:系统异常，请稍后再尝试登录！\"",2500);
                                     document.getElementById("strUsers").focus();
                                     return false;
                               }
                         }
                 }
}




function Getlose()
{
    document.getElementById("loginmsg").innerHTML = "尊敬的开心吧棋牌游戏中心用户，请先<a href=#login onClick=login.show();>登陆</a>";
}

function GetLogin()
{

    //onclick=login.hide();
    //document.getElementById("loginmsg").innerHTML = "<h1></h1><ul><li><span class=\"tsA\">欢迎回家，<b>" + username + "</b> <a href=\"/public/logout.aspx\">[退出]</a></span><span class=\"tsB\"><a href=\"http://manage.Bzw.com/?url=/guestbook/\"  target=_blank >消息<b>(！";
    
    //返回用户登陆Xml值
    //document.getElementById("usershoploginMsg").innerHTML = "欢迎回家"+username+"";
    var tmpdate=getDataTime();
     var UserShopLoginXml;
     var   xmlDoc=new   ActiveXObject("Microsoft.XMLDOM")  
     xmlDoc.async="false"  
     xmlDoc.load(""+urls.shoplogin+"?Usernamess= "+ username + "&tmp="+tmpdate+"");  
    //var url=""+urls.login+"?username="+username+"&password="+password+"&tmp="+tmpdate;
     //alert(urls.login+"?username="+username+"&tmp="+tmpdate);
     nodes=xmlDoc.documentElement.childNodes  
     UserShopLoginXml=nodes.item(0).text  
    //alert(a1);
     document.getElementById("usershoploginMsg").innerHTML=UserShopLoginXml;
}

//用户名不存在
function ChkReg()
{
		if(confirm("系统提示：\n\n用户名不存在，您现在要注册吗，点击确定注册？"))
  	    {
		     window.top.location="/Manage/Reg.aspx";
        }
}