
function $get(id){
    return document.getElementById(id)
}

function Trim(str){
while (str.charAt(0) == " ")
str = str.substr(1,str.length -1);

while (str.charAt(str.length-1) == " ")
str = str.substr(0,str.length-1);

return str;
}

function limpa_string(s){
    var Digitos = "0123456789";
    var temp = "";
    var digito = "";
    for (var i=0; i<s.length; i++)  {
        digito = s.charAt(i);
        if (Digitos.indexOf(digito)>=0) {
        temp=temp+digito;   }
    }
    return temp;
}


function valida_CPF(s)
{

    var i;
    s = limpa_string(s);
    var c = s.substr(0,9);
    var dv = s.substr(9,2);
    var d1 = 0;
    for (i = 0; i < 9; i++)
    {
        d1 += c.charAt(i)*(10-i);
    }
        if (d1 == 0) return(false);
    d1 = 11 - (d1 % 11);
    if (d1 > 9) d1 = 0;
    if (dv.charAt(0) != d1)
    {
        return(false);
    }

    d1 *= 2;
    for (i = 0; i < 9; i++)
    {
        d1 += c.charAt(i)*(11-i);
    }
    d1 = 11 - (d1 % 11);
    if (d1 > 9) d1 = 0;
    if (dv.charAt(1) != d1)
    {
        return(false);
    }

    if(s=='11111111111' ||  s=='22222222222' || s=='33333333333' || s=='44444444444' || s=='55555555555' || s=='66666666666' || s=='77777777777' || s=='88888888888' || s=='99999999999' || s=='00000000000')
        return(false);
    else
        return(true);
}

function valida_CNPJ(s)
{
    var i;
    s = limpa_string(s);
    var c = s.substr(0,12);
    var dv = s.substr(12,2);
    var d1 = 0;
    for (i = 0; i < 12; i++)
    {
        d1 += c.charAt(11-i)*(2+(i % 8));
    }
        if (d1 == 0) return false;
        d1 = 11 - (d1 % 11);
    if (d1 > 9) d1 = 0;
    if (dv.charAt(0) != d1)
    {
        return false;
    }

    d1 *= 2;
    for (i = 0; i < 12; i++)
    {
        d1 += c.charAt(11-i)*(2+((i+1) % 8));
    }
    d1 = 11 - (d1 % 11);
    if (d1 > 9) d1 = 0;
    if (dv.charAt(1) != d1)
    {
        return false;
    }
    return true;
}

function validaEmail(valor){

    if( (Trim(valor) == '') || (/^([\w\.\-])+\@(([\w\-])+\.)+([\w ]{2,4})$/.test(valor) == false))
    {
     return false;
    }
    return true;

}

function toPopup(obj, h, w, url){
    LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
    TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
    settings = "height="+h+",width="+w+",top="+TopPosition+",left="+LeftPosition+",scrollbars=no,noresizable";

    janela = window.open(url,"Voto",settings);

    if(janela == null)
        alert("Desative seu sistema de Anti-Popup !!!");
    else{
	
    obj.method = "post";
    obj.target = "_blank";
    obj.action = url;
    obj.submit();
    obj.reset();
    }
}

function exibe(id) {
    if (document.all)
	    elemento = document.all[id];
      else
        elemento = $get(id);
     elemento.style.display='block';
}

function sai(id) {
    if (document.all)
	    elemento = document.all[id];
    else
        elemento = $get(id);
    //setTimeout("elemento.style.display='none'", 400);
   elemento.style.display='none';
}

function dropDown(id)
{
	/*totId = $get(tot).value;
	for(i=0; i<totId; i++)
	{
		nodes = $get('com'+i);
		if(nodes)
			nodes.style.display = 'none';
	}*/
	
	elemento = $get(id);
	
	if(elemento)
	{
		if(elemento.style.display == 'none')
			$get(id).style.display = 'block';
		else
			$get(id).style.display = 'none';
	}
}

function validatorBusca(){
    
    if($get('palavra').value == ''){
        alert('Por favor, informe alguma palavra para iniciar a busca.');
        $get('palavra').focus();
        return false;
    }
    
    if($get('palavra').value.length < 3){
        alert('A palavra da consulta deve no mínimo 3 letras');
        $get('palavra').focus();
        return false;
    }
    
    return true;

}

function sair(){
    if(confirm('Deseja sair?'))
        document.location.href = "index.php?acao=logout";
}

function recuperar(){
    $get('recuperar-senha').style.display = 'block';
    $get('frestrito').style.display = 'none';
}

function recuperar_back(){
    $get('recuperar-senha').style.display = 'none';
    $get('frestrito').style.display = 'block';
}
