// Create client object and call, in order to check the username and password
// if the username and password are correct, OR if there is some kind of operational
// error, return true to submit the form, otherwise return false to cancel the submit

function doLogin() {

    // Create the client object, passing the async
    // handler. Note lower case! 
    var auth = new detailschecker(LoginHandler);

    // error? don't support XMLHttpRequest?
    // just post the form and it all the standard way
    auth.clientErrorFunc = function(e) {
        document.loginform.submit();
        return true;
    }

    // Call the remote method (method lower case!)
    auth.checkdetails(document.getElementById('username').value, document.getElementById('password').value);
    return false;
}

// A handler is required to accept the response
// of asychronous calls... 
var LoginHandler = {

    // Function must have same name as remote method
    checkdetails: function(result) {
        if (result == -1) {
            document.getElementById('loginmessage').innerHTML = 'No such user';
        } else if (result == -2) {
            document.getElementById('loginmessage').innerHTML = 'Wrong password';
        } else if (result == -3) {
            document.getElementById('loginmessage').innerHTML = 'Nothing entered';
        } else {
            document.forms.loginform.submit();
        }
    }
}
