/**
 * @author arturo
 */
var email_free = true;

function check_email(login) {
	var url   = 'http://www.twittermovil.com/services/users.php?nocache=' + Math.random();
	var peticion = new Ajax.Request(url, {
		method:       'post',
		asynchronous: false,
		postBody:     'email='+login,
		onSuccess:    process_response
  });
}

function process_response(response) {
	if (response.responseText == '1')
		email_free =  true;
	else
		email_free = false;
}

function get_email_free() {
	return email_free;
}

Validate.Unique_Email = function(value, paramsObj) {
	// the following sets up default options and overides them with those passed in
	var params = Object.extend( { failureMessage: "El email ya ha sido usado"}, paramsObj || {});

	//Call to server
	check_email(value);

	// here you would check the value you wish to validate (the one passed in), against some expected value
	// if it fails then use the Validate.fail method will throw an exception containing the failure message
	if(!get_email_free())
		Validate.fail(params.failureMessage);

	// if the script reaches this far then no exception has been thrown, so the validation passed
	return true;
}