$(document).ready(function()
{
  function doOpen(what)
  {
    var div = '#' + what.replace('list_open_', 'notes_forms_module_');
    $('#notes #notes_form .notes_forms_module').not(div).hide();
    $(div).fadeIn('slow');
    $('#notes #notes_form ul li').removeClass('selected');
    $('#' + what).addClass('selected');
  }

  $('#notes .notes_box_delete a').click(function()
  {
    $(this).parent().parent().fadeOut('slow');
    id = $(this).parent().parent().attr('id').replace('notes_note_', '');
    myUrl = '/traddel/web/main/deleteNote/id/' + id;
    $.post(myUrl, function(data)
    {
      alert(data);
      $.get('/traddel/web/main/getNumAppunti', function(data)
      {
        num = parseInt(data);
        if (num == 0)
        {
          window.location.reload();
        }
      });
    });
  });

  $('#notes #notes_send a').click(function()
  {
    $(this).fadeOut('slow');
    $('#notes #notes_form').fadeIn('slow');
  });

  $('#notes #notes_form .notes_forms_module').hide();
  $('#notes #notes_form ul#menu li').click(function()
  {
    doOpen($(this).attr('id'));
  });
  doOpen('list_open_dati_personali');
  
  $('.navigation span').click(function()
  {
    doOpen($(this).attr('class').replace('navigation_goto_', '').replace(' right', '').replace(' left', ''));
  });
  
  $('.input_azienda').hide();

  $('#notes_ragione_sociale_privato').click(function()
  {
    $('.input_azienda').hide();
  });
  $('#notes_ragione_sociale_azienda').click(function()
  {
    if ($.browser.msie)
    {
      $('.input_azienda').show();
    }
    else
    {
      $('.input_azienda').css('display', 'table-row');
    }
    
  });

  $('#notes_provincia').change(function()
  {
    if ($(this).val() != '')
    {
      $('#my_italia').attr('selected', 'selected');
    }
  });

  $('#notes_stato').change(function()
  {
    if ($(this).attr('id') != 'my_italia')
    {
      $('#my_nothing').attr('selected', 'selected');
    }
  });

});
