﻿/* Author: Michael Voong 2009-01-14 */
$.fn.extend({
    //Onlabel is the class the input box will use onced focused
    // defaultval is the label within the input box before focus
    activateFormReplace: function(onLabel, defaultVal) {
        this.data('replaceOldVal', defaultVal);

        if (!this.inputHasChanged())
            this.addClass(onLabel);

        this.blur(function() {
            if (!$(this).inputHasChanged()) { 
                $(this).val($(this).data('replaceOldVal'));
                $(this).addClass(onLabel);
            } else {
                $(this).removeClass(onLabel);
            }
        });

        this.focus(function() {
            if ($(this).val() == $(this).data('replaceOldVal')) {
                $(this).val("");
                $(this).removeClass(onLabel);
            } else {
                $(this).removeClass(onLabel);
            }
        });
    },
    inputHasChanged: function() {
        return ($(this).val() != $(this).data('replaceOldVal') && $(this).val() != "");
    }
});