﻿/*
* jQuery emptyonclick plugin
*
* Created by Andreas Creten (andreas@madewithlove.be) on 2008-06-06.
* Copyright (c) 2008 madewithlove. All rights reserved.
*
* Version: 1.2
*
* Changelog :
* Version 1.2 (17 Jun 2008)
*  - Empty the fields onsubmit when they are not changed
*
* Version 1.1 (11 Jun 2008)
*  - Fixed a bug when working with an empty field (no default value)
*
* Version 1.0 (06 Jun 2008):
*  - Original version
*/

jQuery.fn.extend({
    emptyonclick: function(options) {
        return this.each(function() {
            new jQuery.EmptyOnClick(this, options);
        });
    }
});

jQuery.EmptyOnClick = function(element, options) {

    var defaultValue = $(element).val();

    if (options != undefined && options != null) {
        if (options.RemoveClass != undefined && options.RemoveClass != null) {
            if (options.RemoveClass) {
                $(element).removeClass("watermarkOn");
            }
        }
    }

    // Bind event handlers to the element
    $(element)
    // On Focus: Store the default value if it's not set, empty the field
    .bind("focus", function(e) {
        if (defaultValue == $(this).val()) {
            $(this).val('');
            $(this).removeClass("watermarkOn");
        }

    })
    // On Blur: if the field is empty, reset the default value
    .bind("blur", function(e) {
        if (!$(this).val()) {
            $(this).val(defaultValue);
            $(this).addClass("watermarkOn");
        }
    });
};