function DescStar(valor,id) {
 if(valor == 0) document.getElementById('desc_star'+id).innerHTML = "&nbsp;";
 if(valor == 1) document.getElementById('desc_star'+id).innerHTML = "ruim";
 if(valor == 2) document.getElementById('desc_star'+id).innerHTML = "regular";
 if(valor == 3) document.getElementById('desc_star'+id).innerHTML = "bom";
 if(valor == 4) document.getElementById('desc_star'+id).innerHTML = "excelente";
}

function StarVote(valor,id,ip) {
 jphp("POST","js/starvote.php","valor="+valor+"&id="+id+"&ip="+ip,"StarVoteResult");	
}

function StarVoteResult(html) {
 if(html == 0) alert("Obrigado por votar");
 if(html == 1) alert("Você já votou nesta história");	
}

function Votar(valor) {

 var cpf 		  = document.votacao.cpf.value;
 //var div          = document.getElementById('votar'+valor);

 for(i = 1; i < 6; i++) {
  if(document.getElementById('criatividade'+i).checked == true) ncriatividade = i;
  if(document.getElementById('redacao'+i).checked == true) nredacao = i;
  if(document.getElementById('conteudo'+i).checked == true) nconteudo = i;

 }
 
 if(validarCPF(cpf)) {



  //cpf.value = "";
  //criatividade.v = "";
  //redacao.value = "";
  //conteudo.value = "";
 // div.style.display='none';
  jphp("POST","js/voto.php","id="+valor+"&criatividade="+ncriatividade+"&redacao="+nredacao+"&conteudo="+nconteudo+"&cpf="+cpf,"VotoResult");



 } else {
 alert('O CPF é inválido. Verifique!');	 
 }
}

function VotoResult(html) {
 alert(html);	
}

function SomenteNumero(e){
    var tecla=(window.event)?event.keyCode:e.which;
    if((tecla > 47 && tecla < 58)) return true;
    else{
    if (tecla != 8) return false;
    else return true;
    }
}



function FormataCPF(x,tecla){
        // Por Tiago Araujo Silva (tiago@tiagoaraujo.com)

        separador="-";
        tecla=tecla.keyCode;
        valor=x.value.split('');
        formatado="";
        i=0;

        while(i<valor.length){
            caractere=valor[i];
            numeros=/^\d+$/;
            if(numeros.test(caractere) || caractere==separador){ formatado+=String(caractere);}
            if((formatado.length==3) && tecla!=8){formatado+="."; i++;}
            if((formatado.length==7) && tecla!=8){formatado+="."; i++;}
            if((formatado.length==11) && tecla!=8){formatado+="-"; i++;}
            i++;
        }
        x.value=formatado;
}

function validarCPF(cpf)
{
	cpf = cpf.replace("-", "")
	cpf = cpf.replace(".", "")
	cpf = cpf.replace(".", "")

	if(cpf.length < 11)
		return false

	var cpfCount = ""

	for(i=0;i<10;i++)
	{
		cpfCount = ""

		for(j=0;j<11;j++)
			cpfCount += i

		if(cpfCount == cpf)
		{
			return false
			break
		}
	}

	var a = []
	var b = new Number
	var c = 11

	for(i=0; i<11; i++)
	{
		a[i] = cpf.charAt(i)
		if(i < 9) b += (a[i] * --c)
	}

	if((x = b % 11) < 2)
		a[9] = 0
	else
		a[9] = 11-x

	b = 0
	c = 11
	for(y=0; y<10; y++) b += (a[y] * c--)

	if((x = b % 11) < 2)
		a[10] = 0
	else
		a[10] = 11-x

	if ((cpf.charAt(9) != a[9]) || (cpf.charAt(10) != a[10]))
		return false

	return true
}

function ValidaVotante() {
 if(validarCPF(document.getElementById('cpf').value) == false) {
  alert('CPF Inválido. Verifique.');
  return false;
 }
}

function Existe(email) {
 jphp("POST","js/email.php","email="+email,"EmailResult");	
}

function EmailResult(html) {
 if(html > 0) { document.getElementById('infoemail').innerHTML="Este e-mail já está em uso."; document.getElementById('email').focus(); } else { document.getElementById('infoemail').innerHTML=""; }
}