﻿$.fn.watermark = function (opts) {
    return this.each(function () {
        var sValue = 'Enter a value';
        if (typeof opts != 'undefined')
            sValue = opts;
        var obj = $(this);

        if ($(this).val() == sValue) {
            $(this).val("");
        }

        if ($(this).val() == "") {
            obj.addClass("watermarkOn").val(sValue);
        }

        obj.focus(function () {
            $(this).filter(function () {

                // We only want this to apply if there’s not
                // something actually entered
                return $(this).val() == "" || $(this).val() == sValue;

            }).removeClass("watermarkOn").val("");
        });

        obj.blur(function () {
            $(this).filter(function () {

                // We only want this to apply if there’s not
                // something actually entered
                return $(this).val() == ""
            }).addClass("watermarkOn").val(sValue);
        });
    });
};
