/**
 * Insère le texte d'un libellé dans le champ associé.
 * Lorsque le texte est inséré, la classe CSS "label-in" est attachée au champ de saisie.
 */
function labelInField()
{
    $("label.labelInField").each(
        function () {
            var labelText	=	$(this).html().replace("&nbsp;:", "");
            var field		=	$("#" + $(this).attr("for"));
            $(this).hide();


            if (field[0].tagName == "SELECT") {
                field.prepend('<option selected="selected" value="">' + labelText + '</option>');
                field.val("");
            }

            if (field[0].tagName == "INPUT") {

                try {
                    var inputType   =   field.attr("type");
                }
                catch(e)
                {
                     var inputType  =    "text";
                }

                field.focus(
                    function ()
                    {
                        if (this.value == labelText)
                        {
                            if (inputType)
                            {
                                try {
                                    $(this).attr("type", inputType);
                                }
                                catch(e) { }
                            }
                            this.value	=	"";
                            $(this).removeClass("label-in");
                        }
                    }
                );

                field.blur(
                    function ()
                    {
                        if (this.value == "")
                        {
                            if (inputType == "password")
                            {
                                try {
                                    $(this).attr("type", "text");
                                }
                                catch(e) { }
                            }

                            this.value	=	labelText;
                            $(this).addClass("label-in");
                        }
                    }
                );


                $(field).focus();
                $(field).blur();
            }
        }
    );
}

$(document).ready(labelInField);
