// FUNÇÃO AJAX
function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {
        xmlhttp = false;p4o
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}
var http = getHTTPObject();



function SoNumero(nro)
{
 var valid    = "0123456789";
 var numerook = "";
 var temp;

  for (var i=0; i< nro.length; i++) {
    temp = nro.substr(i, 1);
    if (valid.indexOf(temp) != -1) 
      numerook = numerook + temp;
   } 
 return(numerook);
}

function MascaraCPF(campo,w)
{
   var CPF = SoNumero(campo.value);
   var CPFAux = ''; 
   var campo1 = campo.value;

   if (w.keyCode == 8) {      
     if (campo1.length == 3 || campo1.length == 7 || campo1.length == 11) {
        CPF = CPF.substr(0,CPF.length-1);
       } 
    }
     
   if (CPF.length < 12) {
     
     for (var i=0; i<CPF.length; i++) {
       CPFAux = CPFAux + CPF.substr(i,1);     
       if (i == 2 || i == 5) {
         CPFAux = CPFAux + ".";
        }
       if (i == 8) {
         CPFAux = CPFAux + "-";
        }
      }  
     campo.value = CPFAux;
    }
   else {
      campo.value = campo.value.substr(0,14);
     }    
}


// INSERIR
function confirmarVoto() 
{

    if(document.getElementById("secTitulo").value != '' && document.getElementById("grupoID").value != '')
    {

        http.open("GET", "/RevistaPerfil/Enquete?ope=insSec&"+camposForm(document.formSecao,1), true);
        
        http.onreadystatechange=function()
        {
            
            if(http.readyState==4)
            { 

                if(http.status==200)
                {                                        
                       if(http.responseText == "null")
                       {
                             alert("Uma Seção com este mesmo nome já foi inserida.");
                            
                            }else
                            {
                             listarSec();
                             cancel('secao');
                       }
                }
            }
       }
        http.send(null);
    }else{
    alert('O Campo Título ou Grupo não podem ficar vazio.');
    }  
    
}


 function votar(form,enqID){
  
  var Radio=null;
  var opID = null;

    // Pegar valor do Radio
    Radio= form.opcao;
    for(var i=0;i<Radio.length;i++) {
        
            if(Radio[i].checked) {
                opID = Radio[i].value;
            }
    }
            if(opID != null) {
                // Abrir Janela e enviar os valores
                abrirWin("/RevistaPerfil/Enquete/EnqueteControlador.jsp?opID="+opID+"&enqID="+enqID,300,420);
            
                }else{
                alert("Selecione uma opção por favor.");
                }



  }
  
  function enqResultado(enqID){
      
      abrirWin("/RevistaPerfil/Enquete/EnqueteResultado.jsp?enqID="+enqID,300,420);
      
      }

function abrirWin(win,w,h){

var esquerda = (screen.width - w)/2;
var topo = (screen.height - h)/2;
window.open(win,'WIN','height=' + h + ', width=' + w + ', top=' + topo + ', left=' + esquerda+',scrollbars=yes');

}