$(document).ready(function() {
    $("form label.dyn-mandatory").each(function() { 
        
        $(this).click(function() { 
            if ($(this).next().val().length == 0) {
                $(this).show().css({"opacity":"1"});
            } else {
                $(this).hide();
            }
            $(this).next().focus();
        });
        
        var width = $(this).next().outerWidth();
        $(this).next().css({"margin-left":0, "margin-right":"0", "background-color":"transparent","z-index":"2"});
        $(this).css({"z-index":"1"});
        $(this).parent().css({"width":width+"px","margin-right":"3px"});
        
        $(this).next().focusin(function() { 
            if ($(this).val().length == 0) {
                $(this).prev().show().css({"opacity":"0.4"});
            } else {
                $(this).prev().hide();
            }
        });
        
        $(this).next().focusout(function() { 
            if ($(this).val().length == 0) {
                $(this).prev().show().css({"opacity":"1"});
            } else {
                $(this).prev().hide();
            }
        });
        
        $(this).next().keyup(function() { 
            if ($(this).val().length == 0) {
                $(this).prev().show().css({"opacity":"0.4"});
            } else {
                $(this).prev().hide();
            }
        });
    });
    
    $("form label.dyn-mandatory").each(function() { 
        $(this).click(); 
    });
    
    $("form label.dyn-mandatory").first().next().focus();
});
