function doLogin( module , frm )
{
	var login_user = frm.login_user;
	var login_password = frm.login_password;

	if ( login_user.value == '' )
	{
		alert( 'กรุณากรอกชื่อ' );
		login_user.focus();
	}
	else if ( login_password.value == '' )
	{
		alert( 'กรุณากรอกรหัสผ่าน' );
		login_password.focus();
	}
	else
	{
		var req = Inint_AJAX();
		req.onreadystatechange = function()
		{
			if ( req.readyState == 4 )
			{
				if ( req.status == 200 )
				{
					var ret = req.responseText;
					var ds = ret.split( '|' );
					if ( ds.length > 1 )
					{
						alert( ds[0] );
						document.getElementById( ds[1] ).focus();
					}
					else
					{
						var logindiv = document.getElementById( 'login-div' );
						logindiv.innerHTML = ds[0];
						convertLinks( logindiv );
					};
				};
			};
		};
		req.open( "post" , module + "/chklogin.php" , true );
		req.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded" );
		req.send( 'action=login&login_user=' + encodeURIComponent( login_user.value ) + 
			'&login_password=' + encodeURIComponent( login_password.value )
			);
	};
	return false;
};

function doLogout( module )
{
	var req = Inint_AJAX();
	req.onreadystatechange = function()
	{
		if ( req.readyState == 4 )
		{
			if ( req.status == 200 )
			{
				var logindiv = document.getElementById( 'login-div' );
				logindiv.innerHTML = req.responseText;
				convertLinks( logindiv );
			};
		};
	};
	req.open( "post" , module + "/chklogin.php" , true );
	req.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded" );
	req.send( 'action=logout' );
	return false;
};

function memberEdit( module , action , id , status , no )
{
	var query = '';
	if ( action == 'delete' && confirm( 'คุณต้องการที่จะลบสมาชิกหมายเลข ' + no ) )
	{
		query = 'action=delete&id=' + id;
	}
	else if ( action == 'status' && confirm( 'คุณต้องการที่จะเปลี่ยนสถานะสมาชิกหมายเลข ' + no ) )
	{
		query = 'action=status&id=' + id + '&status=' + status;
	};

	if ( query != '' )
	{
		showloading(); // แสดง loading
		var req = Inint_AJAX();
		req.open( "post" , module + "/action.php" , true );
		req.onreadystatechange = function()
		{
			if ( req.readyState == 4 )
			{
				hideloading(); // ยกเลิก loading
				if ( req.status == 200 )
				{
					var rets = eval( '(' + req.responseText  + ')' );
					if ( rets[0].error != '' )
					{
						alert( rets[0].error );
					}
					else if ( action == 'delete' )
					{
						document.getElementById( 'M_' + id ).style.display = 'none';
					};
					if ( action == 'status' )
					{
						document.getElementById( 'S_' + id ).selectedIndex = rets[0].ret;
					};
				};
			};
		};
		req.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded" );
		req.send( query );
		return false;
	};
};
