﻿	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("");
	 if(document.getElementById("loginDiv")!=null)  //有购物车登录。	
	      window.location=window.location;	 
	}
	function UserLoginState()
	{
	
	if(document.getElementById("UserLogin")!=null)
	{
		if(xmlHttp.readyState == 4) 
		{
		     if(xmlHttp.status==200)
		     {			          
			    document.getElementById("UserLogin").innerHTML = xmlHttp.responseText ;
			 }
			 else
			 {
			    alert("服务器连接失败。错误代码为：[" + xmlHttp.status + "]," + xmlHttp.statusText);
			 }
		}
		else //if (xmlHttp.readyState == 2)
		{
		   document.getElementById("UserLogin").innerHTML="正在等待服务器响应……";
		}
		
	}
	}
	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;	
		//alert(document.getElementById("UserName"));		
		//var k=document.getElementById("KeepLong");
		//var getvalue=k.options[k.selectedIndex].value;//被选中项的值
		xmlHttp = GetXmlHttp();
		xmlHttp.onreadystatechange=LoginCallBack;		
		xmlHttp.open("GET","UserLogin.aspx?UserName="+ u +"&UserPSW="+ w,true);		
		xmlHttp.send("");
		
		
	}
	


   function PostLogin2()
	{
	  
		var u=document.getElementById("UserName2").value;
		var w=document.getElementById("UserPSW2").value;	
		//alert(document.getElementById("UserName"));		
		//var k=document.getElementById("KeepLong");
		//var getvalue=k.options[k.selectedIndex].value;//被选中项的值
		xmlHttp = GetXmlHttp();
		xmlHttp.onreadystatechange=LoginCallBack;		
		xmlHttp.open("GET","UserLogin.aspx?UserName="+ u +"&UserPSW="+ w,true);		
		xmlHttp.send("");
		
		
	}
	function LoginCallBack()
	{
		if(xmlHttp.readyState == 4   ) 
		{
             if(xmlHttp.status==200)
	         {
			    var s=xmlHttp.responseText;
			    if (s=="1")
			    {
			      
				    GetUserLogined();
			    }			   
			    else if (s=="-1")
			    {
				    alert("密码或者用户名错误。\n也可能你的账号不是激活的状态。");GetUserLogin();
			    }
            }
            else
            {
                alert("服务器连接失败。错误代码为：[" + xmlHttp.status + "]," + xmlHttp.statusText);
            }
		}
		else 
		{
		    document.getElementById("UserLogin").innerHTML="正在登陆，请稍侯。。。。。。";
		}
}

	function PostRegist()
	{	
		var u=document.getElementById("Account_Name").value;
		var w=document.getElementById("Account_Password").value;	
	    if(u==''||w=='')
         {
           alert('用户名和密码不得为空！');
           return;
         }
		//var k=document.getElementById("KeepLong");
		//var getvalue=k.options[k.selectedIndex].value;//被选中项的值
		xmlHttp = GetXmlHttp();
		xmlHttp.onreadystatechange=RegistCallBack;
		xmlHttp.open("GET","UserRegist.aspx?Account_Name="+ u +"&Account_Password="+ w,true);
		xmlHttp.send("");
		
	}
	
	function RegistCallBack()
	{
		if(xmlHttp.readyState == 4   ) 
		{
             if(xmlHttp.status==200)
	         {
			    var s=xmlHttp.responseText;			   
			    if (s=="1")
			    {
				    alert("用户注册成功！");
				   //document.getElementById("Loading").innerHTML="<br>注册成功！<br>你可<a href=index.aspx>返回首页</a>进行登陆！";
				   //document.getElementById("Loading").visibility="visible";
			    }			   
			    else if (s=="-1")
			    {
				  alert("用户名称重复！");
				    document.getElementById("Loading").style.visibility="hidden";
			    }
            }
            else
            {
                alert("服务器连接失败。错误代码为：[" + xmlHttp.status + "]," + xmlHttp.statusText);
            }
		}
		else 
		{
		    document.getElementById("Loading").style.visibility="visible";
		}
}
	function Clear()
	{
	   		
	   var obj=document.getElementById("setnull").getElementsByTagName("input");
//	   alert(document.getElementById("setnull"));
	   if(obj.length)
        {
              for(var i=0;i<obj.length;i++)
               {
                 if(obj[i].type=="text" || obj[i].type=="password")
                    {
                      obj[i].value="";
                      }
                  }
         }
	   
	}
