I have a very limited jQuery experience and I was wondering if you can help me with a function that has to check, with an AJAX request, if an email address exists or not. 

Until now I have this piece of code for email checking:

```
$('input#email').bind('blur', function () {
    $.ajax({
        url: 'ajax/email.php',
        type: 'GET',
        data: 'email=' + $('input#email').val(),
        cache: false,
        success: function (html) {
            if (html == 1) alert('Email exists!');
        }
    });
});

```

How can I make a function out of this and use it like this:

```
if (!email_exists($('input#email').val())) {
    $('#error_email').text('Email exists').show();
    return false;
}

```

My PHP code looks like this:

```
$email = ($_GET['email']) ? $_GET['email'] : $_POST['email'];

$query = "SELECT `id` FROM `users` \n"."WHERE `users`.`email` = '".mysql_real_escape_string($email)."'";
$result = mysql_query($query);

if (mysql_num_rows($result) > 0) {
    echo '1';
} else {
    echo '0';
}

```

Thank you.