// JavaScript Document
function exibe_camada(nome){
	if(document.getElementById(nome).style.display == "none")
	   document.getElementById(nome).style.display = ""
	else
	   document.getElementById(nome).style.display = "none"
}

function go_pagina(pagina){
  document.location.href=pagina;
}

function abre_pagina(largura, altura, endereco, descricao, scrollb, menub){
  var posicaoX = screen.width;
  var posicaoY = screen.height;
  posicaoX = posicaoX - largura;
  posicaoY = posicaoY - altura;
  posicaoX = posicaoX / 2;
  posicaoY = posicaoY / 2;
  var j = window.open(endereco,descricao,'scrollbars=' + scrollb + ', menubar=' + menub + ', width=' + largura + ', height=' + altura + ',top=' + posicaoY + ',left=' + posicaoX);
  if(j == false || !j || j == null) alert('Por favor, desabilite o bloqueador de POP-UP e tente novamente.');
}
	
function valida_data_nascimento(campo)
{

      var tmp = campo.value;
      var dia = parseInt(tmp.substring(0,2));
      var mes = parseInt(tmp.substring(3,5));
      var ano = parseInt(tmp.substring(6,10));
      var d   = new Date;
      d = parseInt(d.getYear());

      if(ano > 1900 && ano <= d)
      {
          if(mes == 1 || mes == 3 || mes == 5 || mes == 7 || mes == 8 || mes == 10 || mes == 12)
          {
              if(dia < 1 || dia > 31)
              {
                  alert('Você informou o DIA incorretamente.');
                  campo.value='';
                  campo.focus();
                  return false;
              }
          }else if (mes == 4 || mes == 6 || mes == 9 || mes == 11)
          {
              if(dia < 1 || dia > 30)
              {
                  alert('Você informou o DIA incorretamente.');
                  campo.value='';
                  campo.focus();
                  return false;
              }

          }else if (mes == 2)
          {
              if(dia < 1 || dia > 29)
              {
                  alert('Você informou o DIA incorretamente.');
                  campo.value='';
                  campo.focus();
                  return false;
              }
          }else
          {
              alert('Você informou o MÊS incorretamente.');
              campo.value='';
              campo.focus();
              return false;
          }
      }else
      {
          alert('Você informou o ANO incorretamente.');
          campo.value='';
          campo.focus();
          return false;
      }
}

function trim(texto){
   // Atribui valores às variáveis que servirão de contador		
	 cont = texto.length;
	 j = (cont-1);
   k = 0;   
	 i = 0; 
 
	 // Vai retirar os espaços do INÍCIO da string
	 while(i < cont){
	   // Verifica se a posição informado pelo index "i" ainda é espaço
	   if(texto.charAt(i) != " " || i > cont) break; 

		 i++;
		}
	 
	 // Vai retirar os espaços do FIM da string
	 while(j > 0){
	 // Verifica se a posição informado pelo index "j" ainda é espaço
	   if(texto.charAt(j) != " " || j < 0) break; 
		 j--; k++;
		}

   // Subtrai os espaços da string atual e a retorna ja formatada
	 return texto.substr(i,cont-(k+i));
}

function mensagem(texto, destino){
		 var val = prompt(texto,"");
		 destino.value = trim(val);
}

function mensagem_return(texto){
		 var val = prompt(texto,"");
		 return trim(val);
}

function valida_voto(t,n){
   var resp;
   for(var i = 0; i < document.frm.length; i++)
   if(document.frm.elements[i].checked == true)
      resp = document.frm.elements[i].value;
      
   if(!resp)
      alert('Para votar, selecione uma resposta acima.');
   else	  
      abre_pagina('430', '380', 'view_enquete.php?r='+resp, 'RESULTADO', 'no', 'yes');
}