function resultadoCancerMamaPrec(n){
   n = parseInt(n);
   if (n == 0) n = 1;
   if (n < 10) n = "0"+n;
   document.getElementById("resultado").innerHTML = "<a class='fechar' href='javascript:closeResultado();'></a><div style='height:22px;'><a id='back' class='voltar' href='javascript:menosGraf();'></a><a id='next' class='proxima' href='javascript:maisGraf();'></a></div><img class="+n+" id='imGraf' src='../images/graficos/"+n+".png' />";
   document.getElementById("resultado").style.display = "block";
   n += 1;
}

function closeResultado(){
   document.getElementById("resultado").innerHTML = "";
   document.getElementById("resultado").style.display = "none";

}

function maisGraf(){
   n = document.getElementById('imGraf').className;
   n = parseInt(n) + parseInt(1);
   if(n > 10){
      n = 0;
   }
   resultadoCancerMamaPrec(n);
}

function menosGraf(){
   n = parseInt(n) - parseInt(1);
   if(n < 0){
      n = 10;
   }
   resultadoCancerMamaPrec(n);
}

function controleNumber(nome, num) {
   document.getElementById(nome).value = num;
   
}

function controleResultado(nome, cont, fim) {
   if (fim == null && document.getElementById(nome+'Numero') != null) {
      cont  = parseInt(document.getElementById(nome+'Numero').value);
   }
   if (fim >= 1) {
      for (var i=1; i<=fim; i++) {
         if (i==cont){
            ElementFadeInOut(nome+i, 1);
            if (document.getElementById('idResultadoPaginacao') != null)
               document.getElementById('idResultadoPaginacao').getElementsByTagName('a')[i].className = 'texto_verde texto_negrito texto_13';
         } else {
            ElementShowHiddenSimple(nome+i, 0);
            if (document.getElementById('idResultadoPaginacao') != null)
               document.getElementById('idResultadoPaginacao').getElementsByTagName('a')[i].className = '';
         }
      }      
   }
   
}

function controleElement(nome, acrescimo, cont) {
   if (cont == null) cont = parseInt(acrescimo) + parseInt(document.getElementById(nome+'Controle').value);
   num  = parseInt(document.getElementById(nome+'Numero').value);
   if (num) {
      if (acrescimo > 0) {
         if (cont > num) cont = 1;
      } else {
         if (cont == 0) cont = num;
      }
      document.getElementById(nome+'Controle').value = cont;
      if (document.getElementById(nome+'ButtonAuto') != null) {
         document.getElementById(nome+'ButtonAuto').value = 'Stop';
      }
      for (var i = 1; i<=num; i++) {
         if (i == cont) {
            ElementFadeInOut(nome+i, 1);
            ElementClassChange(nome+'Button'+i, 'botaoLinkSelected');
            if (document.getElementById('idResultadoPaginacao') != null)
               document.getElementById('idResultadoPaginacao').getElementsByTagName('a')[i].className = 'texto_verde texto_negrito texto_13';
         } else {
            ElementShowHiddenSimple(nome+i, 0);
            ElementClassChange(nome+'Button'+i, 'botaoLink');
            if (document.getElementById('idResultadoPaginacao') != null)
               document.getElementById('idResultadoPaginacao').getElementsByTagName('a')[i].className = '';
         }
      }
   }
}

function controleElementAuto(nome, acrescimo) {
   var loopingTime = 3000;
   var checkStopEnd = false;
   var stopEnd = (document.getElementById(nome+'ButtonAuto')!=null&&document.getElementById(nome+'ButtonAuto').value=='Auto'?1:0);
   if (isNaN(parseInt(document.getElementById(nome+'Controle').value)) == true) {
      document.getElementById(nome+'Controle').value = 0;
   }
   if (stopEnd == '1') {
      cont = parseInt(document.getElementById(nome+'Controle').value) + parseInt(acrescimo);
      num  = parseInt(document.getElementById(nome+'Numero').value);
      if (num) {
         if (stopEnd == 1 && cont > num) {
            checkStopEnd = true;
            document.getElementById(nome+'ButtonAuto').value = 'Stop';
         }
         if (acrescimo > 0) if (cont > num) cont = 1;
         else if (cont == 0) cont = num;
         document.getElementById(nome+'Controle').value = cont;
         for (var i = 1; i<=num; i++) {
            if (i == cont) {
               ElementFadeInOut(nome+i, 1);
               ElementClassChange(nome+'Button'+i, 'botaoLinkSelected');
            } else {
               ElementShowHiddenSimple(nome+i, 0);
               ElementClassChange(nome+'Button'+i, 'botaoLink');
            }
         }
      }
      ElementInnerValue(nome+'ButtonAuto', 'Auto');
      setTimeout("controleElementAuto('"+nome+"', '"+acrescimo+"')", loopingTime);
   } else {
      ElementInnerValue(nome+'ButtonAuto', 'Stop');
   }
   
   //parar
   //ElementClassChange(nome+'ButtonAuto', 'botaoLink');
   //ElementClassChange(nome+'ButtonStop', 'botaoLinkSelected');
}

//controlar botao
function controleElementButton(nome, d) {
   
   if (d != null && nome != null) {
      if (d.value == 'Auto') {
         d.value = 'Stop'; 
      } else {
         d.value = 'Auto'; 
         controleElementAuto(nome, '1');
      }
   }
}

//checar checkboxs
function checkboxChildCheck(id, option) {
   var validationTema = false;
   var cont = 1;
   while (validationTema != true) {
      if (document.getElementById(id+cont)) {
         if (option == true) {
            document.getElementById(id+cont).checked = true;
         } else {
            document.getElementById(id+cont).checked = false;
         }
      } else {
         validationTema = true;
      }
      cont++;
   }
}

function checkboxChildCheck2(id, option) {
   if (document.getElementById(id) != null) {
      for (var i=0; i<document.getElementById(id).getElementsByTagName('input').length; i++) {
         if (document.getElementById(id).getElementsByTagName('input')[i] != null) {
            if (option == true) {
               document.getElementById(id).getElementsByTagName('input')[i].checked = true;
            } else {
               document.getElementById(id).getElementsByTagName('input')[i].checked = false;
            }
         }
      }
   }
}

//carregar definicao
function loadDefinition(orig, idDest, link) {
   //altera posicao de destino para origem
   changePosition(orig, idDest);  
   ElementInner(idDest, '');
   //carrega link
   refreshPage(link, idDest);
}

//busca por localizacao
function findAddress() {
   var checkCep = false;
   var urlDestiny = "http://comercio.locaweb.com.br/correios/calcula_sedex.asp";
   if (document.getElementById('idCepOrigem') != null && document.getElementById('idPais') != null) {
      if (document.getElementById('idPais').value == "1") {
         var cep = document.getElementById('idCepOrigem').value;
         if (cep.length == 9) {
            var doc = document.formCorreio;
            document.getElementById('idCep').value = cep.replace('-', '');
            doc.action = urlDestiny;
            window.open('../geral/validacao_cep.php', 'CORREIO', 'toolbar=0,menubar=0,resizable=0,status=0,scrollbars=0,width=1,height=1');
            self.focus();
            checkCep = true;
         }
      } else {
         alert("Somente dentro do Brasil");
         return false;
      }
   }
   if (checkCep == true) {
      doc.submit();
   } else {
      var cep = document.getElementById('idCepOrigem').value;
      if (cep.length < 9) {
         alert('Campo CEP inválido. Este campo precisa conter 8 números.');
      }
      
   }
}

//zerar checkValidacao
function validationCepChange() {
   finishAddress('','','','','');
}

//para outro pais
function validationCountryChange(op, clear) {
   if (clear == null) clear = true;
   if (op == "1") {
      //brasil
      if (clear == true) finishAddress('','','','','');
      
      ElementShowHidden('idSpanEndereco', 0);
      ElementShowHidden('idSpanNumero', 1);
      ElementShowHidden('idSpanComplemento', 1);
      ElementShowHidden('idSpanBairro', 0);
      ElementShowHidden('idSpanCidade', 0);
      ElementShowHidden('idSpanEstadoNome', 0);
      ElementShowHidden('idSpanNomeEstado', 1);
      ElementShowHidden('idSpanNomeBairro', 1);
      ElementShowHidden('idEnderecoEncontrado', 1);
      ElementShowHidden('idBairroEncontrado', 1);
      ElementShowHidden('idCidadeEncontrado', 1);
      ElementShowHidden('idEstadoEncontrado', 1);
      ElementInner('idEnderecoEncontrado', '---');
      ElementInner('idSpanNomeEndereco', 'Endereço');
      ElementInner('idSpanNomeCep', 'CEP');
      ElementInner('idSpanNomeCidade', 'Cidade');
      ElementInner('idSpanNomeNumero', 'Número');
      ElementInner('idSpanNomeComplemento', 'Complemento');
      ElementInner('idSpanNomeEstado', 'Estado');
      //endereco nao adicionado manualmente
      ElementInnerValue('idEnderecoManual', '0');
      ElementDisable('idButtonCep', 0, 'slow', 'botao');
   } else {
      //demais paises
      ElementShowHidden('idSpanEndereco', 1);
      ElementShowHidden('idSpanNumero', 0);
      ElementShowHidden('idSpanComplemento', 0);
      ElementShowHidden('idSpanBairro', 0);
      ElementShowHidden('idSpanNomeBairro', 0);
      ElementShowHidden('idSpanCidade', 1);
      ElementShowHidden('idSpanEstadoNome', 0);
      ElementShowHidden('idEnderecoEncontrado', 0);
      ElementShowHidden('idBairroEncontrado', 0);
      ElementShowHidden('idSpanNomeBairro', 0);
      ElementShowHidden('idCidadeEncontrado', 0);
      ElementShowHidden('idSpanNomeBairro', 0);
      ElementShowHidden('idEstadoEncontrado', 0);
      ElementShowHidden('idSpanNomeEstado', 0);
      
      ElementInner('idSpanNomeEndereco', 'Address');
      ElementInner('idSpanNomeCep', 'Zip Code');
      ElementInner('idSpanNomeCidade', 'City');
      ElementInner('idSpanNomeNumero', '');
      ElementInner('idSpanNomeComplemento', '');
      ElementInner('idSpanNomeEstado', '');
      ElementInner('idEnderecoEncontrado', '');
      //endereco adicionado manualmente
      ElementInnerValue('idEnderecoManual', '1');
      //esconder opcao - alterar manualmente
      ElementInner('idSpanEnderecoManual', '');
      ElementDisable('idButtonCep', 1, 'slow', 'botaoDisabled');
   }
   document.getElementById('idCheckValidacao').value = '0';
}

//adicionar localizacao para opener
function finishAddress(address, neighborhood, city, state, idState) {
   if (document.getElementById('idCheckValidacao')) {
      var doc = document;
   } else {
      var doc = window.opener.document;
   }
   if (address && neighborhood && city && state) {
      //inserir textos
      if (doc.getElementById('idCheckValidacao') != null) {
         //endereco
         doc.getElementById('idEnderecoEncontrado').innerHTML = address;
         //bairro
         doc.getElementById('idBairroEncontrado').innerHTML = neighborhood;
         //cidade uf
         doc.getElementById('idCidadeEncontrado').innerHTML = city;
         doc.getElementById('idEstadoEncontrado').innerHTML = state;
         //adicionar valores
         doc.getElementById('idEndereco').value = address;
         doc.getElementById('idBairro').value = neighborhood;
         doc.getElementById('idCidade').value = city;
         doc.getElementById('idEstado').value = idState;
         doc.getElementById('idEstadoNome').value = state;
         doc.getElementById('idCheckValidacao').value = '1';
         //endereco nao adicionado manualmente
         doc.getElementById('idEnderecoManual').value = '0';
         //exibir opcao - alterar manualmente
         doc.getElementById('idSpanEnderecoManual').innerHTML = "Este não é o seu endereço? Clique <a href='javascript:void(0);' onClick='javascript:insertAddressManual()'>aqui</a> para alterar manualmente.";
         //doc.getElementById('idSpanEnderecoManual').style.display = 'block';
         return true;
      } 
   } else {
      //limpar textos
      if (doc.getElementById('idEnderecoEncontrado') != null) {
         //endereco
         doc.getElementById('idEnderecoEncontrado').innerHTML = '';
         //bairro
         doc.getElementById('idBairroEncontrado').innerHTML = '';
         //cidade
         doc.getElementById('idCidadeEncontrado').innerHTML = '';
         //estado
         doc.getElementById('idEstadoEncontrado').innerHTML = '';
         //valores
         doc.getElementById('idEndereco').value = '';
         doc.getElementById('idBairro').value = '';
         doc.getElementById('idCidade').value = '';
         doc.getElementById('idEstado').value = '';
         doc.getElementById('idCheckValidacao').value = '';
         return true;
      }
   }
}

function insertAddressManual() {
   ElementShowHidden('idSpanEndereco', 1);
   ElementShowHidden('idSpanNumero', 1);
   ElementShowHidden('idSpanComplemento', 1);
   ElementShowHidden('idSpanBairro', 1);
   ElementShowHidden('idSpanCidade', 1);
   ElementShowHidden('idSpanEstadoNome', 1);
   ElementShowHidden('idEnderecoEncontrado', 0);
   ElementShowHidden('idBairroEncontrado', 0);
   ElementShowHidden('idCidadeEncontrado', 0);
   ElementShowHidden('idEstadoEncontrado', 0);
   ElementInnerValue('idEnderecoManual', 0);
}

function showDescription(url) {
   ElementFullScreen('idFullScreen'); 
   $("#idDivDescription").animate({width:"540px",height:"50%"});
   refreshPage(url, 'idDivDescription');
}

function hideDescription() {
   $("#idDivDescription").animate({height:"5px"});
   ElementShowHidden('idDivDescription', '0'); 
   ElementShowHiddenNormal('idFullScreen', '0');
}