function login() {
    //get username/email and pass to send to backend
    var email = $("#mi_email").val();
    var password = $("#mi_password").val();
    
    $("#loadingspinner").slideDown('slow');
    
    //process
    $.ajax({
        type: "GET",
        dataType: "json",
        url: "membersajax/membersajax.html",
        data: {
            "action" : "login",
            "pathId" : $("#pathId").val(),
            "email" : email,
            "password" : password
        },
        success: function(json) {
            $("#loadingspinner").slideUp('slow');
            if(json.login == "fail") {
                alert(json.reason);
            } else if (json.login == "success") {
                member = json.member;
                $("#curLeadId").val(member.id);
            
                var thehref = location.href;
                thehref = thehref.replace(/&message=\d*/g, "");
                if(thehref.indexOf('html?') == -1) {
                    location.href = thehref + "?message=3";
                } else {
                    location.href = thehref + "&message=3";
                }
            }
        },
        error: function(json) {
        	$("#loadingspinner").slideUp('slow');
        	//alert("Login failed");
        }
    });
}

$().ready(function(){
    $('#accountarea_loggedout, #accountarea_loggedout_in').submit(function(evt){
        evt.preventDefault();
        login();
    });

    if($.browser.msie && $.browser.version < 8){
        $('#login').click(function(){
            $(this).parents('form').submit();
        });
    }
});