﻿	var xmlHttp;

	function GetUserLogin()
	{
		var url = "/AjaxPostBack.aspx?Action=UserLogin";
		xmlHttp = GetXmlHttp();
		xmlHttp.onreadystatechange = UserLoginState;
		xmlHttp.open("GET", url, true);
		xmlHttp.send("");
	}
	function GetUserReLogin(u)
	{
	    
		var url = "/AjaxPostBack.aspx?Action=UserReLogin&UserName="+u;
		xmlHttp = GetXmlHttp();
		xmlHttp.onreadystatechange = UserLoginState;
		xmlHttp.open("GET", url, true);
		xmlHttp.send("");
	}
	function GetUserLoginRed()
	{
		var url = "/AjaxPostBack.aspx?Action=UserLoginRed";
		xmlHttp = GetXmlHttp();
		xmlHttp.onreadystatechange = UserLoginStateRed;
		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 UserLogout(u)
	{
		var url = "/AjaxPostBack.aspx?Action=UserLogout&UserName="+u;
		xmlHttp = GetXmlHttp();
		xmlHttp.onreadystatechange = UserLogoutState;
		xmlHttp.open("GET", url, true);
		xmlHttp.send("");
		window.location.reload();//注销成功以后刷新网页。
	}
	
	function doLogout(u)
	{
		var url = "/AjaxPostBack.aspx?Action=doLogout&UserName="+u;
		xmlHttp = GetXmlHttp();
		xmlHttp.onreadystatechange = UserLogoutState;
		xmlHttp.open("GET", url, true);
		xmlHttp.send("");
		window.location.reload();//注销成功以后刷新网页。
	}
	function UserLoginState()
	{
		if(xmlHttp.readyState == 4) 
		{
		     if(xmlHttp.status==200)
		     {
			    document.getElementById("UserLogin").innerHTML = xmlHttp.responseText ;
			 }
			 else
			 {
			    alert("服务器连接失败。错误代码为：[" + xmlHttp.status + "]," + xmlHttp.statusText);
			 }
		}
	}
	function UserLoginStateRed()
	{
		if(xmlHttp.readyState == 4) 
		{
		     if(xmlHttp.status==200)
		     {
		        if(xmlHttp.responseText == "-1")
		        {
//		             var sen = getCookie("DeriectURL");
//			        if (sen == "")
//			        {
//			         window.location="/Index.aspx";
//                    }       
//                     else
//                     {           
//                        window.location =sen;
//                     }
                    window.location = "/Soft/SoftClass.aspx?PageNo=1";
		        }
		        else
		        {
			        document.getElementById("UserLogin").innerHTML = xmlHttp.responseText ;
			    }
			 }
			 else
			 {
			    alert("服务器连接失败。错误代码为：[" + xmlHttp.status + "]," + xmlHttp.statusText);
			 }
		}
	}
	function UserLogout()
	{
		var url = "/AjaxPostBack.aspx?Action=UserLogout";
		xmlHttp = GetXmlHttp();
		xmlHttp.onreadystatechange = UserLogoutState;
		xmlHttp.open("GET", url, true);
		xmlHttp.send("");
		window.location.reload();//注销成功以后刷新网页。
	}
	function UserLogoutState()
	{
		if(xmlHttp.readyState == 4)
		{
		   window.location=window.location;//注销成功以后刷新网页。
		}
	}
	function PostLogin()
	{
		var u= encodeURI(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;
		}
		if(p=="")
		{
		    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();
                    window.location = "/Soft/SoftClass.aspx?PageNo=1";
			    }
			    else if (s == "-2")
			    {		   
				    alert("验证码错误或者验证码已经过期！");
				    GetUserLogin();
			    }
			    else if (s == "-1")
			    {
				    alert("密码或者用户名错误。\n也可能你的账号不是激活的状态。");
				    GetUserLogin();
			    }
			    else
			    {
			        //alert("返回未处理值。");
			        //alert(s);
			        $.prompt(s,{
      buttons:{}, 
      prefix:'cleanblue'
});
			        
			    }
            }
            else
            {
                alert("服务器连接失败。错误代码为：[" + xmlHttp.status + "]," + xmlHttp.statusText);
            }
		}
		else 
		{
		    document.getElementById("UserLogin").innerHTML="<img src=/Images/Ajax_Loading.gif width=32 height=32 />";
		}
    }
    
    function PostLoginNew()
	{
		var u=encodeURI(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;
		}
		if(p=="")
		{
		    alert("请输入验证码");
		    return;
		}
		var getvalue=k.options[k.selectedIndex].value;//被选中项的值
		xmlHttp = GetXmlHttp();
		xmlHttp.onreadystatechange = LoginCallBackNew;
		var url = "/Member/UserLogin.aspx?UserName="+ u +"&UserPSW="+ w +"&PassCode="+ p +"&KeepLong="+ getvalue;
		xmlHttp.open("GET", url, true);
		xmlHttp.send("");
		
	}
	
	function LoginCallBackNew()
	{
		if(xmlHttp.readyState == 4) 
		{
             if(xmlHttp.status==200)
	         {
			    var s = xmlHttp.responseText;
			    if (s == "1")
			    {
			        //var sen = getCookie("DeriectURL");
			        //if (sen == "")
			        //{
			        // window.location="/Index.aspx";
                    //}       
                     //else
                     //{           
                        //window.location =sen;
                     //}
//			        window.location="/Index.aspx";
			        
		                //history.go(-2);
				   // GetUserLoginedNew();
				   window.location = "/Soft/SoftClass.aspx?PageNo=1";
			    }
			    else if (s == "-2")
			    {
			     
				    alert("验证码错误或者验证码已经过期！");
				     GetUserLoginRed();
			    }
			    else if (s == "-1")
			    {
				    alert("密码或者用户名错误。\n也可能你的账号不是激活的状态。"); GetUserLoginRed();
			    }
			    else
			    {
			        //alert("返回未处理值。");
			        $.prompt(s,{
      buttons:{}, 
      prefix:'cleanblue'
});
			    }
            }
            else
            {
                alert("服务器连接失败。错误代码为：[" + xmlHttp.status + "]," + xmlHttp.statusText);
            }
		}
		else 
		{
		    document.getElementById("UserLogin").innerHTML="<img src=/Images/Ajax_Loading.gif width=32 height=32 />";
		}
    }
   
    //utility function called by getCookie()
    function getCookieVal(offset)
    {
        var endstr = document.cookie.indexOf(";", offset);
        if(endstr == -1)
        {
            endstr = document.cookie.length;
        }
        return unescape(document.cookie.substring(offset, endstr));
    }

    // primary function to retrieve cookie by name
    function getCookie(name)
    {
        var arg = name + "=";
        var alen = arg.length;
        var clen = document.cookie.length;
        var i = 0;
        while(i < clen)
        {
            var j = i + alen;
            if (document.cookie.substring(i, j) == arg)
            {
                return getCookieVal(j);
            }
            i = document.cookie.indexOf(" ", i) + 1;
            if(i == 0) break;
        }
        return;
    }
