// JavaScript Document
//登入帳號、密碼、驗證碼檢查
/*
輸入:
	obj_admin_username:帳號輸入物件
	obj_admin_password:密碼輸入物件
	obj_verifying_code:驗證碼輸入物件
輸出:
	XML文件
	成功:
		<result>1<result>
		重新整理頁面
	失敗:
		<result>0</result>
		<message>資料錯誤</message>
		顯示message內容	
*/
function Login( str_member_username_id , str_member_password_id /* , str_verifying_code_id */ )
{
	var username = document.getElementById( str_member_username_id ).value;
	var password = document.getElementById( str_member_password_id ).value;
	//var verifying_code = document.getElementById( str_verifying_code_id ).value;

	//alert( username );
	//alert( password )
	
	request = createRequest();
	var url = str_path + "js/ajax/login.php";
	
	request.open( "POST" , url , true );
	request.onreadystatechange = function()
	{
		if( Response() )
		{
			var obj_xmldoc = request.responseXML;
			
			var str_result = obj_xmldoc.getElementsByTagName( "result" ).item(0).childNodes[0].nodeValue;
			
			if( str_result == "1" )
			{
				//導向頁面
				//location.href = str_path;
				location.reload();
			}
			else
			{
				//顯示錯誤訊息
				var str_message = obj_xmldoc.getElementsByTagName( "message" ).item(0).childNodes[0].nodeValue;
				
				alert( str_message );
				/*
				if( str_result == "2" )
				{
					RebuildVerifyingCode( document.getElementById( "img_verifying_code" ) );					
					
					document.getElementById( "verifying_code" ).value = "";
					document.getElementById( "verifying_code" ).focus();
				}
				*/
	
			}
		}
	};
	request.setRequestHeader( "Content-Type","application/x-www-form-urlencoded" );
	request.send(	"username=" + username + 
					"&password=" + password  );	
}

//登出
function Logout()
{
	//document.getElementById( 'layer' ).style.display = '';
	
	request = createRequest();
	var url = str_path + "js/ajax/logout.php";
	request.open( "POST" , url , true );
	request.onreadystatechange = function()
	{
		if( Response() )
		{
			//導向頁面
			
			alert( request.responseText );
			location.reload();
			
			//ShowLogout( '1' );
		}
	};
	request.setRequestHeader( "Content-Type","application/x-www-form-urlencoded" );
	request.send( null );
}



//顯示登入表單
function ShowLogin( bool_show )
{
	if( bool_show == "0" )
	{
		document.getElementById( 'layer' ).style.display = 'none';
		document.getElementById( 'login_layer' ).style.display = 'none';
		
		//document.body.scroll = "yes";
	}
	else if( bool_show == "1" )
	{
		document.getElementById( 'layer' ).style.display = '';		
		document.getElementById( 'login_layer' ).style.display = '';
		
		document.getElementById( 'layer' ).style.width = document.body.scrollWidth;
		if( document.body.scrollHeight > document.body.clientHeight )
		{
			document.getElementById( 'layer' ).style.height = document.body.scrollHeight;
			document.getElementById( 'login_layer' ).style.height = document.body.scrollHeight;
		}
		else
		{
			document.getElementById( 'layer' ).style.height = document.body.clientHeight;
			document.getElementById( 'login_layer' ).style.height = document.body.clientHeight;
		}
		
		document.getElementById( 'member_username' ).focus();
	}
}

//顯示登入表單
function ShowLogout( bool_show )
{
	if( bool_show == "0" )
	{
		document.getElementById( 'layer' ).style.display = 'none';
		document.getElementById( 'logout_layer' ).style.display = 'none';
		
		location.reload();
	}
	else if( bool_show == "1" )
	{
		document.getElementById( 'layer' ).style.display = '';		
		document.getElementById( 'logout_layer' ).style.display = '';
		
		document.getElementById( 'layer' ).style.width = document.body.clientWidth;
		if( document.body.scrollHeight > document.body.clientHeight )
		{
			document.getElementById( 'layer' ).style.height = document.body.scrollHeight;
			document.getElementById( 'logout_layer' ).style.height = document.body.scrollHeight;
		}
		else
		{
			document.getElementById( 'layer' ).style.height = document.body.clientHeight;
			document.getElementById( 'logout_layer' ).style.height = document.body.clientHeight;
		}
	}
}
