function defaultsFromLabels(form_sel) {
    $(form_sel).find('label').parent().hide();

    $(form_sel).find('input[type="text"], textarea').blur(function(){
        if($(this).val() == ''){
            var id = $(this).attr('id');
            var text = $(form_sel).find('label[for="'+id+'"]').text();
            $(this).val(text);
        }
    });
    
    $(form_sel).find('input[type="text"], textarea').focus(function(){
        var id = $(this).attr('id');
        var text = $(form_sel).find('label[for="'+id+'"]').text();        
        if($(this).val() == text){
            $(this).val('');
        }
    });

    $(form_sel).find('input[type="text"], textarea').trigger('blur');
}

/*Obsługa dodawnia dynamicznie formularzy w embededForms*/
function addMoreForm(obj, url){  
    var forms_box = $(obj);
    //console.log(forms_box);
        
    //pobierz formularz i wstaw
    $.getJSON(url, function(data) { //+'?num='+id[1]
        forms_box.append(data.form);
        forms_box.children().last().fadeIn('slow');
            
        forms_box.children().each(function(i) {
            $(this).find('input, textarea, label').each(function(j){
                //zamiana id
                var id = $(this).attr('id');
                var name = $(this).attr('name');
                var lfor = $(this).attr('for');
                    
                //zamiana atrybutów 'id' elementu
                if(id!= null){
                    $(this).attr('id', id.replace(/(_\d\_)+/g, '_'+i+'_'));
                }
                    
                //zamiana atrybutów 'for' elementu
                if( lfor != null){
                    $(this).attr('for', lfor.replace(/(_\d\_)+/g, '_'+i+'_'));
                }
                    
                //zamiana atrybutu 'name' elementu
                if(name != null){
                    $(this).attr('name', name.replace(/\[\d\]+/, '['+i+']'));
                }
            });
        });
    });
}
    
function removeMoreForm(obj){
    console.log($(obj).parent());
    $(obj).parent().fadeOut('slow', function(){
        $(this).remove();
    });
}



