function DoLogin() {
    Logon(document.getElementById('login_email').value,
                  document.getElementById('login_password').value);
}

$body = null;
$loading = null;

function Logon($email, $pass) {
    if ($email && $pass) {
        $body = document.getElementById("body");
        $loading = document.getElementById("msg_loading");

        $.ajax({
            type: "POST",
            url: "/test.php",
            data: "email="+$email+"&pass="+$pass,
            dataType: "json",
            error: function (r,t) {
                if ($loading && $body) {
                    $body.style.overflow = "auto";
                    $loading.style.display = "none";
                }
                if (t) alert("AJAX Error: " + t);
            },
            success: function (d) {
                if ($loading && $body) {
                    $body.style.overflow = "auto";
                    $loading.style.display = "none";
                }

                if (d && d.Result && d.Content) {
                    if (d.Result == "OK") {
                       document.location = d.Content;
                    } else if (d.Result == "ERROR") {
                       alert("Error: " + d.Content);
                    } else 
                       alert("ERROR: Invalid data");
                } else alert("ERROR: No data");
            }
        });
        if ($loading && $body) {
            $body.style.overflow = "hidden";
            $loading.style.display = "block";
        }
    }
}
