


$(document).ready(function() {
  
  $(".field.f_password").each(function(){
    fieldType_Password({showField: !$(this).hasClass("field_disabled"), containerId: "container_"+$(this).attr("id"),fieldName: $(this).attr("id"), fieldValue: $(this).find(".ff input").attr("value")});
  });
});

function fieldType_Password(settings)
  {
    settings = jQuery.extend({
      
      fieldName: '',
      containerId: '',
      showField: true,
      fieldValue: '',
      
      labelRetypePassword: 'Heslo znovu'
      
    },settings);
    
    initialize();
    
    if(settings.showField){show();}
    else{remove();}
    
    function initialize()
      {
        $('#' + settings.fieldName + ' label input').unbind("click").click(function(){
          if($(this).attr("checked")){show();}
          else{remove();}
          //$('#' + settings.fieldName).toggleClass("field_disabled");
        });
        
        settings.container = $('#' + settings.containerId);
      }
    
    function show()
      {
        settings.container.html('');
        settings.container.append(
          '<input class="input_password" type="password" name="new_'+settings.fieldName + '" id="f_new_'+settings.fieldName+'" value="" />' + 
          '<span>'+settings.labelRetypePassword+':</span><input class="input_password" type="password" name="new_'+settings.fieldName + '_check" id=\"f_new_'+settings.fieldName + '_check" value="" />'
        );
      }
      
    function remove()
      {
        $('#' + settings.fieldName + ' .ff').html('<input type="hidden" name="'+settings.fieldName+'" value="'+settings.fieldValue+'" />');
      }
  
  }
