﻿jQuery.fn.DefaultValue = function (text) {
    return this.each(function () {

        this.isTextValue = false;
        this.newText = text;

        var defaultValue = this.value;

        if (this.newText == "" || this.newText == null || typeof (this.newText) == "undefined") {
            this.isTextValue = false;
        }
        else {
            this.isTextValue = true;
            this.value = this.newText;
        }
        //Make sure we're dealing with text-based form fields
        if (this.type != 'text' && this.type != 'password' && this.type != 'textarea')
            return;

        //Store field reference
        var fld_current = this;

        //Set value initially if none are specified
        if (this.value == '') {
            this.value = this.newText;
        }

        //Remove values on focus
        jQuery(this).focus(function () {
            if (this.isTextValue) {
                //this.value= defaultValue;
            }
            else {
                if (this.value == defaultValue)
                    this.value = "";
            }

        });

        //Place values back on blur
        jQuery(this).blur(function () {
            if (this.value == '') {
                if (this.isTextValue == true)
                    this.value = this.newText;
                else
                    this.value = defaultValue;
            }

        });

    });

};
