function IE() {
  return (navigator.appName == "Microsoft Internet Explorer");
}

function abreJanela(src) {
   window.open(src,"","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=820,height=600,_top");
}

function abreSite(src) {
   window.open(src,"","");
}

function gotoTop() {
   parent.window.scrollTo(0,0);
}

function iframeResize()
{
    var vFrame=document.getElementById('conteudo');
    if (!vFrame) vFrame=parent.document.getElementById('conteudo');
    if (IE()) {
       vFrame.height = vFrame.Document.body.scrollHeight;
    } else {
       vFrame.height = vFrame.contentDocument.body.offsetHeight;
    }
}

function ChangeContent(src) {
   ctt = document.getElementById('conteudo');
   ctt.src = src;
}

function getRadioButtonValue(radio) {
  var valor = "";
  for (var i=0; i < radio.length; i++) {
    if (radio[i].checked) {
       valor = radio[i].value;
    }
  }
  return valor;
}

function selectComboOption(combo, valor) {
  for (var i=0; i < combo.options.length; i++) {
    if (combo.options[i].value == valor) {
      combo.options[i].selected = true;
    }
  }
}

function ShowIfTrueHideOtherwise(idElemento, condicao) {
  var elem = document.getElementById(idElemento);
  if (condicao) {
    elem.style.display = 'block';
  } else {
    elem.style.display = 'none';
  }
}

function setView(expandir, img, nome) {
  ShowIfTrueHideOtherwise('view_' + img.id, expandir);
  if (expandir) {
    img.src = 'paginas/img/bt_expandir.gif';
    if (nome) img.setAttribute('alt', 'Clique aqui para ocultar ' + nome);
  } else {
    img.src = 'paginas/img/bt_contrair.gif';
    if (nome) img.setAttribute('alt', 'Clique aqui para tornar visível ' + nome);
  }
  iframeResize();
}

function toggleView(img, nome) {
  expandir = img.src.indexOf('contrair') > 0;
  setView(expandir, img, nome);
}

function toogleTRView(id) {
  tr = document.getElementById('view_' + id);
  img = document.getElementById(id);
  if ((tr) && (img)) {
    setView((tr.style.display == 'none'), img, null);
  }
}

function toggleAtuacao(img) {
  isOn = img.src.indexOf('laranja') > 0;
  if (isOn) {
    img.src = 'paginas/img/rb_cinza.gif';
    img.setAttribute('alt', 'Clique aqui para marcar como sua área de atuação.');
  } else {
    img.src = 'paginas/img/rb_laranja.gif';
    img.setAttribute('alt', 'Clique aqui para desmarcar como sua área de atuação.');
  }
}

function toggleInteresse(img) {
  isOn = img.src.indexOf('verde') > 0;
  if (isOn) {
    img.src = 'paginas/img/rb_cinza.gif';
    img.setAttribute('alt', 'Clique aqui para marcar como sua área de interesse.');
  } else {
    img.src = 'paginas/img/rb_verde.gif';
    img.setAttribute('alt', 'Clique aqui para desmarcar como sua área de interesse.');
  }
}

function toggleReuniao(idTabela, idReuniao) {
  tb = document.getElementById(idTabela);
  if (tb) {
    for (i=0; i < tb.rows.length; i++) {
      if (tb.rows[i].id.indexOf('view_') == 0) {
        if (tb.rows[i].id.indexOf('view_'+idReuniao) == 0) {
          tb.rows[i].style.display = '';
        } else {
          tb.rows[i].style.display = 'none';
        }
      }
    }
  }
}

function RemoveComConfirmacao(src, target) {
   if(confirm("Tem certeza que deseja remover " + target + "?")) {
      document.location = src;
   }
}

function RemoveImagemComConfirmacao(id, target) {

   if(confirm("Tem certeza que deseja remover " + target + "?")) {
      img = document.getElementById('img' + id);
      if (img) {
        img.src = "./paginas/img/foto_removida.gif";
        img.width = 80;
        img.height = 18;
      }
      campo = document.getElementById('edDeletar' + id);
      if (campo) campo.value = "S";
      tr = document.getElementById('viewBtDel' + id);
      if (tr) tr.style.display = 'none';
   }
}

function ReintegraComConfirmacao(src, target, sexo) {
   if (sexo == 'F') {
     lbAssociado = 'a associada';
   } else {
     lbAssociado = 'o associado';
   }

   if(confirm("Tem certeza que deseja reintegrar " + lbAssociado + " " + target + " à Confraria Empresarial?")) {
      document.location = src;
   }
}

function ReenviaFichaComConfirmacao(src, target) {

   if(confirm("Tem certeza que deseja reenviar a ficha de inscrição para " + target + "?")) {
      document.location = src;
   }
}

function AceitaCandidatoComConfirmacao(src, target) {

   if(confirm("Tem certeza que deseja aceitar o ingresso de " + target + " na Confraria Empresarial?")) {
      document.location = src;
   }
}

function DelLinhaTabela(idTabela, idLinha) {
  tabela = document.getElementById(idTabela);
  achou = false;
  i = 0;
  while ((!achou) && (i<tabela.rows.length)) {
    achou = (tabela.rows[i].id == idLinha);
    if (achou) tabela.deleteRow(i);
    i++;
  }
}

