jQuery.fn.extend({
	validate: function(endPoint, failure, success) {
		jQuery(this).blur(function() {
			if (jQuery(this).val().length == 0) {
				return false;
			}

			jQuery.ajax({
				'type' : 'POST',
				'url' : 'ajax.php?' + endPoint,
				'dataType' : 'json',
				'data' : {
					value : jQuery(this).val()
				}, 
				'success' : function(json) { 
					if (typeof(success) == 'function') {
						if (json.success) success(json);
						else failure(json);
					}
				},
				'error' : function(xml) {
					var json = eval('(' + xml.responseText + ')');
					failure(json)
				}
			});
		});
	}
});

