$(document).ready(function(){
  $('#mostra').hide();
  $('#carregando').hide();

  var ContactName = $('#campo-nome');
  var ContactEmail = $('#campo-email');
  
  var ContactNameDefault = 'nome';
  var ContactEmailDefault = 'e-mail';
  
  ContactName.focus(function(){
    if($(this).attr('value') == ContactNameDefault) $(this).attr('value', '');
  });

  ContactEmail.focus(function(){
    if($(this).attr('value') == ContactEmailDefault) $(this).attr('value', '');
  });

  ContactName.blur(function(){
    if($(this).attr('value') == '') $(this).attr('value', ContactNameDefault);
  });

  ContactEmail.blur(function(){
    if($(this).attr('value') == '') $(this).attr('value', ContactEmailDefault);
  });

  $('#btn-enviar').bind('click', function(){
    $('#mostra').html('');
    $('#mostra').hide();
    $('#carregando').fadeIn();
    $.post('newsletter',{ name: $('#campo-nome').val(), email: $('#campo-email').val(), subject: 'Cadastro', message: '' },function(response){
      setTimeout('finishAjax("'+escape(response)+'")', 400);
    });
  });
});

function finishAjax(response) {
  var html = unescape(response);

  if (html.substring(0, 2) == 'OK') {
    /*
    $('#ContactName').val() = '';
    $('#ContactEmail').val() = '';
    $('#ContactMessage').val() = '';
    */
  }

  $('#carregando').hide();
  $('#mostra').html(html);
  $('#mostra').fadeIn();
}
