// 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 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('To vote, select the answer above.');
   else	  
      abre_pagina('430', '380', 'view_enquete.php?r='+resp, 'RESULTADO', 'no', 'yes');
}
