function carregaPagina(container_id,page_url,silenciosamente) {
  if (silenciosamente == undefined) silenciosamente = false;
  var container = document.getElementById(container_id);
  if (!silenciosamente) container.innerHTML = '<div id="aviso">Aguarde...</div>';
  $.ajax({
    url: page_url,
    type: 'GET',
    dataType: 'text',
    timeout: 15000,
    error: function() {
      if (!silenciosamente) container.innerHTML = '<div id="aviso">Falha na comunicação com o servidor. Tente novamente.</div>';
    },
    success: function(resposta) {
      if (resposta != undefined)
        container.innerHTML = resposta;
    }
  });
}

function envia_contato(f,idmodal) {
  var modal = document.getElementById(idmodal);
  modal.style.zIndex = 0;
  modal.style.visibility = 'visible';
  if (f.nome.value=='') {
    alert('Por favor, forneça seu nome!');
    f.nome.focus();
  } else if (f.FROM.value=='') {
    alert('Por favor, forneça seu e-mail!');
    f.email.focus();
  } else if (f.TO.value=='') {
    alert('Por favor, selecione a área desejada!');
    f.SUBJECT.focus();
  } else if (f.mensagem.value=='') {
    alert('Por favor, digite sua mensagem!');
    f.mensagem.focus();
  } else {
    var str = $(f).serialize();
    $.ajax({
      url: '/scripts_ok/formmail.php',
      type: 'POST',
      data: str,
      dataType: 'text',
      timeout: 15000,
      error: function() {
        alert('Erro ao enviar seu contato. Por favor, tente novamente.');
      },
      success: function(resposta) {
        if (resposta != undefined) {
          alert('Obrigado por enviar seu contato!');
          carregaPagina('corpo','home.php');
        }
      }
    });
  }
  modal.style.zIndex = -1;
  modal.style.visibility = 'hidden';
}

function toggleDisplay(idobj,display,idleg) {
  var obj = document.getElementById(idobj);
  if (obj.style.display != display) {
    obj.style.display = display;
    if (idleg != undefined)
      document.getElementById(idleg).style.backgroundColor = '#79d';
  } else {
    obj.style.display = 'none';
    if (idleg != undefined)
      document.getElementById(idleg).style.backgroundColor = '#9bf';
  }
}