(function($) {
    // max length for textarea
    $(function() {
        $('textarea[data-maxlength]').live('keypress', function() {
            var maxlength = Number($(this).attr('data-maxlength'));
            if ($(this).val().length < maxlength) {
                return true;
            }

            return false;
        });
    });

    // text hint for text field and password field
    $('input[data-hint], textarea[data-hint]').live('blur', function() {
        if ($(this).val() == '') {
            var original = $(this);
            if (this.clone == null) {
                var clone = $(this).is('textarea') ? $('<textarea></textarea>')
                    : $('<input type="text"/>');
                clone.attr('class', original.attr('class'))
                    .addClass('hint').val(original.attr('data-hint'));
                clone.focus(function() {
                    clone.hide();
                    original.show().focus();
                });
                this.clone = clone;
            }
            this.clone.show();
            $(this).hide().after(clone);
        }
    });
    // FIXME: figure out why is blur called intermediately causes bug
    setTimeout("$('input[data-hint], textarea[data-hint]').blur()", 100);
})(jQuery);

