jQuery.fn.extend({
    emptyonclick: function(options) {
        return this.each(function() {
            new jQuery.EmptyOnClick(this, options);
        });
    }
});

jQuery.EmptyOnClick = function(element, options) {
    var defaultValue = $j(element).val();
    
    // Bind event handlers to the element
    $j(element)
    // On Focus: Store the default value if it's not set, empty the field
    .bind("focus", function(e) {
        if(defaultValue == $j(this).val())
            $j(this).val('');

    })
    // On Blur: if the field is empty, reset the default value
    .bind("blur", function(e) {
        if(!$j(this).val()) {
            $j(this).val(defaultValue);
        }
    });

    // Search for the form which has the element
    $j("form:has(#s)")
    // If the form gets resetted, set the default value back
    .bind('reset', function(e) {
        $j(element).val(defaultValue);
        $j(element).removeClass(options.changeClass);
    }) 
    // If the form gets submitted empty, remove the default values
    .bind('submit', function(e) {
        if($j(element).val() == defaultValue)
            $j(element).val('');
    });
};
