$(
	function()
	{
		if ($("#toploign").length > 0 )
		{
			initLoginPanel();
		}
		
		if ($("#username").length > 0 )
		{
			initLogoutPanel();
		}
	}
);

function initLoginPanel()
{
	$("#toploign").keypress(
		function(e)
		{
			if (e.keyCode == 13)
				jsLogin();
		}
	);
	
	$("#toppasswd").keypress(
		function(e)
		{
			if (e.keyCode == 13)
				jsLogin();
		}
	);
}

function jsLogin()
{
	strLogin = $("#toploign").val();
	strPass = $("#toppasswd").val();
	
	if (strLogin.split(" ").join("").length > 0 && strPass.split(" ").join("").length > 0 )
	{
		var objPost = new Object();
		objPost.login = strLogin;
		objPost.logout = strPass;
		
		$.post(
			"http://www.hlctv.net/library/flow1/main.php?action=member&saction=login" , objPost ,
			function(e)
			{
				var obj = new Object();
				eval("obj = "+e+";");
				
				if (obj.code == 1)
				{
					alert(obj.msg);
					window.location.reload();
				}
				else
					alert(obj.msg);
			}
		);
	}
}

function initLogoutPanel()
{
	var objPost = new Object();
	
	
	$.post(
		"http://www.hlctv.net/library/flow1/main.php?action=member&saction=getName" , objPost ,
		function(e)
		{
			var obj = new Object();
			eval("obj = "+e+";");
			
			if (obj.code == 1)
			{
				$("#username").html(obj.msg);
			}
			else
				window.location.href = "index.php";
		}
	);
}

function jsLogOut()
{
	var objPost = new Object();
	$.post(
		"http://www.hlctv.net/library/flow1/main.php?action=member&saction=logout" , objPost ,
			function(e)
			{
				var obj = new Object();
				eval("obj = "+e+";");
				
				window.location.href = "index.php";
			}
	);
}	

function jsResetPasswd()
{
	intEmpty = 0;
	var objPost = new Object();
	
	$(".cssForm").find(".cssTextBox").each(
		function()
		{
			var strV = $(this).val();
			eval("objPost."+$(this).attr('name')+" = strV;");
			
			if (strV == "" )
				intEmpty = 1;
		}
	);
	
	if (intEmpty == 0 )
	{
		var objSendOut = new Object();
		objSendOut.log = objPost.login;
		
		$.post(
			"http://www.hlctv.net/library/flow1/main.php?action=member&saction=forgetpwd" , objSendOut ,
				function(e)
				{
					var obj = new Object();
					eval("obj = "+e+";");
					
					$(".cssTextBox").val("");
					alert(obj.msg);
				}
		);
	}
}

function jsRegNow()
{
	objData = new Object();
	intEmpty = 0;
	//
	$(".cssRegInput").each(
		function()
		{
			strV = $(this).val();
			eval("objData."+$(this).attr('name')+" = strV;");
			
			if (strV == "" )
			{
				intEmpty = 1;
			}
		}
	);
	
	if (intEmpty == 0 )
	{
		objData.news = (($("#news:checked").length > 0 )? 1 : 0 );
		objData.agree = (($("#agree:checked").length > 0 )? 1 : 0 );
		
		if (objData.agree == 1)
		{
			if (objData.passwd == objData.repasswd )
			{
				if (objData.email == objData.confirmEmail )
				{
					var objSendOut = new Object();
					objSendOut.captcha = objData.captcha;
					objSendOut.email = objData.email;
					objSendOut.passwd = objData.passwd;
					objSendOut.newsflag = objData.news;
					
					$.post(
						"http://www.hlctv.net/library/flow1/main.php?action=member&saction=reg" , objSendOut ,
							function(e)
							{
								var obj = new Object();
								eval("obj = "+e+";");
								
								if (obj.code == 1)
								{
									alert(obj.msg);
									window.location.href = "index.php";
								}
								else
								{
									alert(obj.msg);
									jsCapRe();
									$("#ca").val("");
								}
							}
					);
				}
				else
					alert(objErr.email);
			}
			else
				alert(objErr.passwd);
		}
		else
			alert(objErr.req);
	}
	else
		alert(objErr.req);
	
}

function jsCapRe()
{
	$("#capimg").attr('src' , 'http://www.hlctv.net/cap/captcha.php?r='+Math.random());
}
