
function Login( str_admin_username_id , str_admin_password_id , str_verifying_code_id )
{
	var username = document.getElementById( str_admin_username_id ).value;
	var password = document.getElementById( str_admin_password_id ).value;
	var verifying_code = document.getElementById( str_verifying_code_id ).value;

	request = createRequest();
	var url = "js/ajax/login.php";
	request.open( "POST" , url , true );
	request.onreadystatechange = function()
	{
		if( Response() )
		{			
			//alert(request.responseText);
			var obj_xmldoc = request.responseXML;
			
			var str_result = obj_xmldoc.getElementsByTagName( "result" ).item(0).childNodes[0].nodeValue;
			
			if( str_result == "1" )
			{
				//導向頁面
			//	location.reload();				
				location.href='index.php';
			}
			else
			{
				//顯示錯誤訊息
				var str_message = obj_xmldoc.getElementsByTagName( "message" ).item(0).childNodes[0].nodeValue;
				
				//document.getElementById( "div_error" ).style.display='';
				document.getElementById( "vip_login_warn" ).innerHTML=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 + 
					"&verifying_code=" + verifying_code );
}

function Logout()
{
	request = createRequest();
	var url = "js/ajax/logout.php";
	request.open( "POST" , url , true );
	request.onreadystatechange = function()
	{
		if( Response() )
		{
			//導向頁面
			//alert( request.responseText );
			location.href='index.php';
		}
	};
	request.setRequestHeader( "Content-Type","application/x-www-form-urlencoded" );
	request.send( null );
}

//重新產生驗證碼
function RebuildVerifyingCode( obj_verifying_code_img )
{
	var verifying_code_url = obj_verifying_code_img.src.split( "?" );
	verifying_code_url = verifying_code_url[0];
	
	obj_verifying_code_img.src = verifying_code_url + "?" + Math.random();
}

