function hint_value(el, hint, color) {
    if (!hint)
        hint = el.val();

    var hint_on = function() {
        if (el.val() == "" || el.val() == hint) {
            if (color) {
                el.attr("old_color", el.css("color"));
                el.css("color", color);
            }
            el.val(hint);
        }
    };

    var hint_off = function() {
        if (el.val() == hint) {
            el.val("");
            if (el.attr("old_color"))
                el.css("color", el.attr("old_color"));
        }
    };

    el.focus(hint_off).click(hint_off);
    el.blur(hint_on);
    $(el.form).submit(hint_off);

    hint_on();
}

// jQuery function to append to val()
// simple .append has bugs with Firefox, Safari and Opera
$.fn.appendVal = function(txt) {
    return this.each(function(){ this.value += txt; });
};

$.fn.limitText = function(limit, indicator) {
    return this.keyup(function(){
        var text = $(this);

        indicator.toggleClass("error", text.val().length > limit - 20);
            
        if (text.val().length > limit)
            text.val(text.val().substring(0, limit));
        else
            if (indicator)
                indicator.html(limit - text.val().length);
    });
};

$.fn.focusEnd = function() {
    return this.each(function() {
        var A = this;
        if (A.style.display != "none") {
            if ($.browser.msie) {
                A.focus();
                var B = A.createTextRange();
                B.collapse(false);
                B.select()
            }
            else {
                A.setSelectionRange(A.value.length, A.value.length);
                A.focus()
            }
        }
    })
};
