/**
 * @author Sdking
 * @classDescription The methods for user ultilities
 */
window.IsLogin=false;
window.UserId="";
function ValidateUser(type)
{

		type=false;
		if(window.IsLogoin==undefined)
		{
				window.IsLogin=false;
				window.UserId="";
		}
	if(window.IsLogoin==true)
		{
			alert("ÄúÒÑ¾­µÇÂ¼.");
			return;
		}

	$.ajax({
				url: "Service/CommonService.asmx/IsUserLogin",
				type: "POST",
				async:type,
				dataType: "xml",
				success: function(xml)
				{
					
					var bL=$(xml).find("item").attr("isLogin");
					var uid=$(xml).find("item").attr("uid");
	
				
					if(bL=='1')
					{
						window.IsLogin=true;
						window.UserId=uid;
					}
					else
					{
						window.IsLogin=false;
						window.UserId="";
					}
	
				},
				error:function(XMLHttpRequest,textStatus,errorThrown)
				{
					//alert(textStatus);
				}
	});

}
function UserPost()
{

	var uid=document.getElementById("txtUid").value;
	var psw=document.getElementById("txtPsw").value;
	var vCode=document.getElementById("txtVCode").value;
 
	uid=uid.trim();
	psw = psw.trim();
	vCode=vCode.trim();
	if(uid.length==0)
	{
		return "";
	}
	if(psw.length==0)
	{
		return "";
	}
	if(vCode.length==0)
	{
		return "";
	}
	$.ajax({
				url: "Service/CommonService.asmx/UserAuthentication",
				type: "POST",
				dataType: "xml",

				data:{uid:uid,psw:psw,vCode:vCode},
				success: function(xml)
				{
					flag =$(xml).find("return").attr("flag");
					msg=$(xml).find("return").attr("msg");
					
					if(flag=="o")
					{
						window.IsLogin=true;
						window.UserId=uid;
						//alert("userLogined");
					}
					else
					{
						window.IsLogin=false;
						window.UserId="";
						document.getElementById("txtVCode").value="";
						var imgCode=document.getElementById('imgCheckCode'); 
						imgCode.src=imgCode.src
						alert(msg);
					}
					SetUserStatus();
				},
				error:function(XMLHttpRequest,textStatus,errorThrown)
				{
					alert(textStatus);
				}
	});
}
function SetUserStatus()
{
	if(window.IsLogin!= undefined && window.UserId!=undefined)
	{
		if(window.IsLogin && window.UserId!="")
		{
			document.getElementById("divLoginLoading").style.display="none";	
			document.getElementById("divUserLogin").style.display="none";
			
			document.getElementById("divUserInfo").style.display="block";
			document.getElementById("spanUserId").innerText=window.UserId;
		}	
		else
		{
			document.getElementById("spanUserId").innerText="";
			document.getElementById("divLoginLoading").style.display="none";
			document.getElementById("divUserInfo").style.display="none";
			
			document.getElementById("divUserLogin").style.display="block";
			
		}
	}
}

