﻿/**
* jQuery Resettable - A function to make form fields reset to their initial values when left blank
* Copyright (c) 2009 Ben Byrne - ben(at)fireflypartners(dot)com | http://www.fireflypartners.com
* Dual licensed under MIT and GPL.
* Date: 10/16/2009
* @author Ben Byrne
* @version 0.1.0
*
*/


jQuery.fn.resettable = function() {

    fields = new Array();

    this.each(function() {

        //check to make sure the element has a name attribute. If not, do nothing!
        if (!jQuery(this).attr("name")) return true;

        fields[jQuery(this).attr("name")] = jQuery(this).val();

        jQuery(this).focus(function() {
            if (jQuery(this).val() == fields[jQuery(this).attr("name")]) jQuery(this).val("");
        }).blur(function() {
            if (jQuery(this).val() == "") jQuery(this).val(fields[jQuery(this).attr("name")]);
        });

    });
    return this;
}
