


$(document).ready(function() {
  
  $(".field.f_sex").each(function(){
    fieldType_Sex({showField: !$(this).hasClass("field_disabled"), containerId: "container_"+$(this).attr("id"),fieldName: $(this).attr("id"), fieldValue: $(this).find(".ff input").attr("value")});
  });
});

function fieldType_Sex(settings)
  {
    settings = jQuery.extend({
      
      fieldName: '',
      containerId: '',
      showField: true,
      fieldValue: '',
      
      labelMale: 'Muž',
      labelFemale: 'Žena'
      
    },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.container = $('#' + settings.containerId);
        //alert(settings.fieldValue);
      }
    
    function show()
      {
        //alert(settings.fieldValue);
        settings.container.html('');
        settings.container.append(
          '<label for="'+settings.fieldName+'_radio">'+settings.labelFemale+'<input class="input_radio" type="radio" name="'+settings.fieldName + '_radio" id="f_'+settings.fieldName+'_0" value="0" '+(settings.fieldValue == 0 ? 'checked="checked"' : '')+' /></label>' + 
          '<label for="'+settings.fieldName+'_radio">'+settings.labelMale+'<input class="input_radio" type="radio" name="'+settings.fieldName + '_radio" id="f_'+settings.fieldName+'_1" value="1" '+(settings.fieldValue == 1 ? 'checked="checked"' : '')+' /></label>' +
          '<input class="input_hidden" type="hidden" name="'+settings.fieldName+'" id="f_'+settings.fieldName+'" value="' + settings.fieldValue + '" />'
        );
        $(settings.container).find("input[type='radio']").click(function(){$("#f_"+settings.fieldName).attr("value", $(this).attr("value"));});
      }
      
    function remove()
      {
        $('#' + settings.fieldName + ' .ff').html('');
      }
  
  }
