﻿	var xmlHttp;

	function GetUserLogin()
	{
		var url = "/AjaxPostBack.aspx?Action=UserLogin";
		xmlHttp = GetXmlHttp();
		xmlHttp.onreadystatechange = UserLoginState;
		xmlHttp.open("GET", url, true);
		xmlHttp.send("");
	}
	function GetUserLoginMini()
	{
		var url = "/AjaxPostBack.aspx?Action=UserLoginMini";
		xmlHttp = GetXmlHttp();
		xmlHttp.onreadystatechange = UserLoginState;
		xmlHttp.open("GET", url, true);
		xmlHttp.send("");
	}	
	function GetUserLogined()
	{
		var url = "/AjaxPostBack.aspx?Action=UserLogined";
		xmlHttp = GetXmlHttp();
		xmlHttp.onreadystatechange = UserLoginState;
		xmlHttp.open("GET", url, true);
		xmlHttp.send("");
	}
	function UserLoginState()
	{
		if(xmlHttp.readyState == 4) 
		{
		     if(xmlHttp.status==200)
		     {
				 var hts=xmlHttp.responseText ;

				if(hts.indexOf("欢迎您")!=-1){
					 var reg=new RegExp("(可用金币)(.*?)(用户控制面板)");
					 hts=hts.replace(reg,"<b>用户控制面板")
			        document.getElementById("UserLogin").innerHTML = hts;
					}else{
			    document.getElementById("UserLogin").innerHTML = hts;
				//document.getElementById("PassCode").onclick=
				show_code("hidden");
					}

}
			 else
			 {
			    alert("服务器连接失败。错误代码为：[" + xmlHttp.status + "]," + xmlHttp.statusText);
			 }
		}
	}
	/***小毅解决验证码隐藏问题,请注意修改***/
	function show_code(str)
	{
		var pcd=document.getElementById("PassCode").parentNode.parentNode;
		var pcs=document.getElementById("KeepLong").parentNode.parentNode;
		var pcw=document.getElementById("UserPSW");
		if(str=="hidden"){
			pcd.style.display='none';
			pcs.style.display='none';
			pcw.onfocus=new Function("show_code('show')");
		//	pcw.onblur=new Function("show_code('hidden')");
		}else{
			pcd.style.display='';
			pcs.style.display='';
		}
	}
	/***以上代码若有问题,请注意ajax改动**/
	function UserLogout()
	{
		var url = "/AjaxPostBack.aspx?Action=UserLogout";
		xmlHttp = GetXmlHttp();
		xmlHttp.onreadystatechange = UserLogoutState;
		xmlHttp.open("GET", url, true);
		xmlHttp.send("");
		window.location=window.location;//注销成功以后刷新网页。
	}
	function UserLogoutState()
	{
		if(xmlHttp.readyState == 4)
		{
		   window.location=window.location;//注销成功以后刷新网页。
		}
	}
	function PostLogin()
	{
		var u=document.getElementById("UserName").value;
		var w=document.getElementById("UserPSW").value;
		var p=document.getElementById("PassCode").value;
		var k=document.getElementById("KeepLong");
 
		if(u=="")
		{
		    alert("请输入用户名");
		    return;
		}
		if(w=="")
		{
		    alert("请输入密码");
		    return;
		}
		
		var getvalue=k.options[k.selectedIndex].value;//被选中项的值
		xmlHttp = GetXmlHttp();
		xmlHttp.onreadystatechange = LoginCallBack;
		var url = "/Member/UserLogin.aspx?UserName="+ u +"&UserPSW="+ w +"&PassCode="+ p +"&KeepLong="+ getvalue;
		xmlHttp.open("GET", url, true);
		xmlHttp.send("");
		
	}
	function LoginCallBack()
	{
		if(xmlHttp.readyState == 4) 
		{
             if(xmlHttp.status==200)
	         {
			    var s = xmlHttp.responseText;
			    if (s == "1")
			    {
				    GetUserLogined();
			    }
			    else if (s == "-2")
			    {
			        //document.getElementById("PassCode").src='/PassCode.aspx';
				    alert("验证码错误或者验证码已经过期！");GetUserLogin();
			    }
			    else if (s == "-1")
			    {
				    alert("密码或者用户名错误。\n也可能你的账号不是激活的状态。");GetUserLogin();
			    }
			    else
			    {
			        alert("返回未处理值。");GetUserLogin();
			    }
            }
            else
            {
                alert("服务器连接失败。错误代码为：[" + xmlHttp.status + "]," + xmlHttp.statusText);
            }
		}
		else 
		{
		    document.getElementById("UserLogin").innerHTML="<img src=/Images/Ajax_Loading.gif width=32 height=32 />";
		}
}