/*
 * ToggleFormText
 *
 * Author:   Grzegorz Frydrychowicz
 * E-mail:   grzegorz.frydrychowicz@gmail.com
 * Date:     16-11-2007
 * requires agahsystems/common.js/[$.fn.bindUp]
*/
function toggleFormText() {

    // jquery focus selector
    var hasFocus = function(elem) {
        elem = $(elem).get(0);
        return elem === document.activeElement && (elem.type || elem.href);
    };

    var checkAll = function($this) {
        $this = $($this);
        if (hasFocus($this)) {
            if ($this.val() == $this.attr('title')) {
                $this.val('');
            }
            $this.removeClass("hidenBoxTitle");
        } else {
            if ($this.val() == '' || $this.val() == $this.attr('title')) {
                $this.val($this.attr('title'));
                $this.addClass("hidenBoxTitle");
            } else {
                $this.removeClass("hidenBoxTitle");
            }
        };
    };

    $("input:text, textarea, input:password").each(function() {
        checkAll(this);
    }).bind('focus blur agahSystems_inputChange', function() {
        checkAll(this);
    });
}

function toggleFormText_remove() {
//    $("input:image, input:button, input:submit, button").bindUp('click', function() {
//        $(this.form.elements).each(function() {
//            if (this.type == 'text' || this.type == 'textarea' || this.type == 'password') {
//                if (this.value == this.title && this.title != '') {
//                    this.value = '';
//                }
//            }
//        });
//    });

    $('input,textarea').each(function() {
        if (this.value == this.title && this.title != '') {
            this.value = '';
        }
    });
}
