﻿// JavaScript Document
// JavaScript Document
var $loadingIcon = '<img src="images/loading.gif" width="16" height="16" border=0>';

function AJAX($URL,$method,$param,$success_function,$fail_function ){
	
if (typeof $method == 'undefined' ) $method = 'post';
if (typeof $fail_function == 'undefined' ) $fail_function = defaultFail;

new Ajax.Request($URL,
	{  method:$method,
		parameters: $param,
	    onSuccess: $success_function,     
		onFailure: $fail_function  
		}); 
}//end AJAX

function login($username, $password){
	$('loginResult').innerHTML = '';
	//if($username.length >5){
		$('loginResult').innerHTML = $loadingIcon;
		AJAX('services.php','POST',"act=login&username="+$username+"&password="+$password,loginResult);
	//}
}

function loginResult(transport){
	var response = transport.responseText || "no response text";       
	//alert("Success! \n\n" + response); 
	if(response == 'false'){
		alert('錯誤！請檢查你的帳戶名稱與密碼是否正確！');
		$('loginResult').innerHTML ='';
		//$('loginResult').innerHTML = '<font color="red">錯誤！請</font>';
	}else if(response == 'true'){
		$('loginResult').innerHTML = '';
	    document.location = 'editprofile.php';
	}else{
		alert('請在15分鐘後再嘗試登入!');
		$('loginResult').innerHTML ='';
	}
}

function getKeyCode(e)
{
	//alert(e);
 if (window.event)
    return window.event.keyCode;
 else if (e)
    return e.which;
 else
    return null;
}



function defaultFail(){
	alert('Something went wrong...');  	
}//end defaultFail
