/*This plugin binds events to input elements so that they get
  emptied on focus and get their default value back if set empty

  Copyright Unc Inc 2008
*/

$.fn.prevalue = function(options) {

    options = $.extend(
        {allowEmpty: false}, options
    );

    return this.each(function() {
        /* Remove previously bound functions */
        $(this).unbind("focus");
        $(this).unbind("blur");

        var default_value = $(this).val();

        $(this).focus(function() {
            if ($(this).val() == default_value) {
                $(this).val("");
            }
			if ($(this).hasClass("errorDisplay")) {
                $(this).removeClass("errorDisplay");
				$(this).val("");
            }
        });

        $(this).blur(function() {
            if (!options.allowEmpty && $(this).val() == "") {
                $(this).val(default_value);
            }
        });
    });
}