/* ---------------------------------
labelsclean.js
***
Made by: Nikolai Khilkovsky
E-mail: khilkovn@gmail[dot]com
URL: http://nightraven.name
--------------------------------- */


var Form_block='';		//Класс блока, в котором расположена форма. Если надо искать по всей странице - оставить пустое значение.

$(document).ready(function () {
    if (Form_block == '') {
        Form_block = '*'
    };
    $(Form_block).find(':text').each(function (i) {
        var inputLabel = $(this).val();
        $(this).focus(function () {
            if ($(this).val() == inputLabel) {
                $(this).val('')
            }
        });
        $(this).blur(function () {
            if ($(this).val() == '') {
                $(this).val(inputLabel)
            }
        })
    });
    $(Form_block).find(':password').each(function (i) {
        var inputLabel = $(this).val(),
            inputClass = $(this).attr('class'),
            inputId = $(this).attr('id'),
            inputTitle = $(this).attr('title'),
            inputStyle = $(this).attr('style');
        $(this).after('<input type="text" />').hide(0);
        $(this).next().val(inputLabel);
        if (inputClass) {
            $(this).next().addClass(inputClass)
        };
        if (inputId) {
            $(this).removeAttr('id');
            $(this).next().attr('id', inputId)
        };
        if (inputTitle) {
            $(this).next().attr('title', inputTitle)
        };
        if (inputStyle) {
            $(this).next().attr('style', inputStyle)
        };
        $(this).next().focus(function () {
            if ($(this).val() == inputLabel) {
                $(this).hide(0);
                if (inputId) {
                    $(this).removeAttr('id');
                    $(this).prev().attr('id', inputId)
                };
                $(this).prev().val('').attr('id', inputId).show(0).focus();
            }
        });
        $(this).blur(function () {
            if ($(this).val() == '') {
                if (inputId) {
                    $(this).removeAttr('id');
                    $(this).next().attr('id', inputId)
                };
                $(this).val(inputLabel).hide(0);
                $(this).next().show(0)
            }
        })
    });
    $(Form_block).find('textarea').each(function (i) {
        var textareaLabel = $(this).val();
        $(this).focus(function () {
            if ($(this).val() == textareaLabel) {
                $(this).val('')
            }
        });
        $(this).blur(function () {
            if ($(this).val() == '') {
                $(this).val(textareaLabel)
            }
        })
    })
});
