// JavaScript Document


function valida_cpf(cpf)
{
var numeros, digitos, soma, i, resultado, digitos_iguais;
digitos_iguais = 1;
if (cpf.length < 11)
	return false;
for (i = 0; i < cpf.length - 1; i++)
	if (cpf.charAt(i) != cpf.charAt(i + 1))
		  {
		  digitos_iguais = 0;
		  break;
		  }
if (!digitos_iguais)
	{
	numeros = cpf.substring(0,9);
	digitos = cpf.substring(9);
	soma = 0;
	for (i = 10; i > 1; i--)
		  soma += numeros.charAt(10 - i) * i;
	resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
	if (resultado != digitos.charAt(0))
		  return false;
	numeros = cpf.substring(0,10);
	soma = 0;
	for (i = 11; i > 1; i--)
		  soma += numeros.charAt(11 - i) * i;
	resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
	if (resultado != digitos.charAt(1))
		  return false;
	return true;
	}
else
	return false;
}


/*Função Pai de Mascaras*/
function Mascara(o,f){
	v_obj=o
	v_fun=f
	setTimeout("execmascara()",1)
}

/*Função que Executa os objetos*/
function execmascara(){
	v_obj.value=v_fun(v_obj.value)
}

/*Função que Determina as expressões regulares dos objetos*/
function leech(v){
	v=v.replace(/o/gi,"0")
	v=v.replace(/i/gi,"1")
	v=v.replace(/z/gi,"2")
	v=v.replace(/e/gi,"3")
	v=v.replace(/a/gi,"4")
	v=v.replace(/s/gi,"5")
	v=v.replace(/t/gi,"7")
	return v
}

/*Função que permite apenas numeros*/
function Integer(v){
	return v.replace(/\D/g,"")
}

/*Função que padroniza CPF*/
function Cpf(v){
	v=v.replace(/\D/g,"")                    
	v=v.replace(/(\d{3})(\d)/,"$1.$2")       
	v=v.replace(/(\d{3})(\d)/,"$1.$2")       
											 
	v=v.replace(/(\d{3})(\d{1,2})$/,"$1-$2") 
	return v
} 

/*Função que padroniza CNPJ*/
function Cnpj(v){
	v=v.replace(/\D/g,"")                   
	v=v.replace(/^(\d{2})(\d)/,"$1.$2")     
	v=v.replace(/^(\d{2})\.(\d{3})(\d)/,"$1.$2.$3") 
	v=v.replace(/\.(\d{3})(\d)/,".$1/$2")           
	v=v.replace(/(\d{4})(\d)/,"$1-$2")              
	return v
}

// Função mascara de CEP
function mascaraCEP(objeto)
{
	campo = eval (objeto);
	separacao1 = '-';
	conjunto1 = 5;
	conjunto2 = 9;
	if (desabilitateclas())
	{
			if (campo.value.length < (conjunto2))
			{
			  if (campo.value.length == conjunto1)
					campo.value = campo.value + separacao1;
			}
	}
	else
		event.returnValue = false;
}

/****** Funções em java script para selecionar as checkbox *******/
function selecionar(n)
{
	n = eval(n);
	if (n.checked == false)
		nao_sel_todas();
	else
		sel_todas();
}
function sel_todas()
{
	var tam = document.form.elements.length;
	for (var i = 0; i < tam; i++) {
		document.form.elements[i].checked = true;
		total_aniversariantes++;
	}
}
function nao_sel_todas()
{
	var tam = document.form.elements.length;
	for (var i = 0; i < tam; i++) {
		document.form.elements[i].checked = false;
		total_aniversariantes--;
	}
}


/************ PARA MOSTRAR E ESCONDER LAYER ************/
// Script que verifica o browser a ser usado
if (document.all || document.layers) {
	IE4 = (document.all);
	NS4 = (document.layers);
	NS6 = false;
} else if (document.getElementById) {
	IE4 = false;
	NS4 = false;
	NS6 = (document.getElementById);
}
if ( navigator.userAgent.indexOf("Mozilla") != -1 ) {
	mozilla = true;
}
function getStyle(id){return NS4 ? document[id] : NS6 ? document.getElementById(id).style : document.all[id].style;}
function HideLayer(id){getStyle(id).visibility = NS4 ? "hide" : "hidden"; getStyle(id).display = "none";}
function ShowLayer(id){getStyle(id).visibility = NS4 ? "show" : "visible"; getStyle(id).display = "block";}
/******************************************************/

/************ PARA DESABILITAR TECLAS ****************/
// Desabilita teclas exceto números, ponto e vírgula
function desabilitateclas_parcial()
{
	var tecla = event.keyCode;
	//alert(tecla);
	if ((tecla >= 0 && tecla <= 7)||(tecla >= 9 && tecla <= 12)||(tecla >= 14 && tecla <= 43)||(tecla >= 45 && tecla <= 47)||
	(tecla >= 58 && tecla <= 98)||(tecla >= 100 && tecla <= 127))
	{ return false; }
	return tecla;
}// fim da função desabilitateclas

// Desabilita todas as teclas exceto números
function desabilitateclas(evento)
{
	// Detectando diferenças de browsers
	if( document.all && ! navigator.userAgent.match(/opera/gi) ) { // somente IE 
		var tecla = event.keyCode;
	} 
	else { // atende  no mínimo o Firefox, Netscape 6+,  e Opera 
		var tecla = evento.which;
	}
	/*
	0: TAB
	8: BACKSPACE
	13: ENTER
	48 - 57: Númeris de 0 a 9
	*/
	if ((tecla == 0)||(tecla == 8)||(tecla == 13)||(tecla >=48 && tecla <= 57))
		return tecla;
	return false;
}
/******************************************************/

// Muda o focus do telefone
function muda_focus(a,b)
{
	if(a.length==2)
		b.focus();
}

function muda_focus2(a,b)
{
	if(a.length==9)
		b.focus();
}
// Função mascara de FONE
function mascaraFONE(objeto)
{
	campo = eval (objeto);
	separacao1 = '-';
	conjunto1 = 4;
	conjunto2 = 9;
	if (desabilitateclas(event))
	{
		if (campo.value.length < (conjunto2))
		{
		  if (campo.value.length == conjunto1)
				campo.value = campo.value + separacao1;
		}
	}
	else
		event.returnValue = false;
}

// Abre pop-up
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

//FUNCAO COLOCA VIRGULA NO NUMERO INTEIRO
function amf2005_BecameCurrency(cur,len)
{
   n='__0123456789';
   d=cur.value;
   l=d.length;
   r='';
   if (l > 0)
   {
    z=d.substr(0,l-1);
    s='';
    a=2;
    for (i=0; i < l; i++)
    {
        c=d.charAt(i);
        if (n.indexOf(c) > a)
        {
            a=1;
            s+=c;
        };
    };
    l=s.length;
    t=len-1;
    if (l > t)
    {
        l=t;
        s=s.substr(0,t);
    };
    if (l > 2)
    {
        r=s.substr(0,l-2)+','+s.substr(l-2,2);
    }
    else
    {
        if (l == 2)
        {
            r='0.'+s;
        }
        else
        {
            if (l == 1)
            {
                r='0.0'+s;
            };
        };
    };
    if (r == '')
    {
        r='0.00';
    }
    else
    {
        l=r.length;
        if (l > 6)
        {
            j=l%3;
            w=r.substr(0,j);
            wa=r.substr(j,l-j-6);
            wb=r.substr(l-6,6);
            if (j > 0)
            {
               // w+='.';
            };
            k=(l-j)/3-2;
            for (i=0; i < k; i++)
            {
                w+=wa.substr(i*3,3)+'.';
            };
            r=w+wb;
        };
    };
   };
   if (r.length <= len)
   {
    cur.value=r;
   }
   else
   {
    cur.value=z;
   };
   return 'ok';
};

// Verifica inconsistência do e-mail sem o foco no campo
function checa_email(obj)
{
	//email_de
	re=/^[A-Za-z0-9_.-]+@([A-Za-z0-9_.-]+\.)+[A-Za-z]{2,4}$/i;
	if(!re.test(obj.value)){
		alert('O e-mail informado parece não estar correto.');
		//obj.focus();
		return false;
	}
}

// Verifica inconsistência do e-mail com o foco no campo
function checa_email_foco(obj)
{
	//email_de
	re=/^[A-Za-z0-9_.-]+@([A-Za-z0-9_.-]+\.)+[A-Za-z]{2,4}$/i;
	if(!re.test(obj.value)){
		alert('O e-mail informado parece não estar correto.');
		obj.focus();
		return false;
	}
}

//minusculo qdo digita
function minuscula(campo)
{
	variavel=document.getElementById(campo).value;
	variavel=variavel.toLowerCase();
	document.getElementById(campo).value=variavel;
}

function limpar(id)
{
	document.getElementById(id).innerHTML = "";
}

function full(link,nome_janela) 
{
	largura = screen.width - 10;
	altura = screen.height - 220;
	
	if (link != '')
		window.open(link,''+nome_janela+'','width='+largura+',height='+altura+',top=0,left=0,screenX=0,screenY=0,status=yes,scrollbars=yes,toolbar=yes,resizable=yes,maximized=yes,menubar=yes,location=yes');
}

function full2(link,nome_janela) 
{
	largura = screen.width - 25;
	altura = screen.height - 70;
	
	if (link != '')
		window.open(link,''+nome_janela+'','width='+largura+',height='+altura+',top=5,left=4,screenX=0,screenY=0,status=no,scrollbars=yes,toolbar=no,resizable=no,maximized=no,menubar=no,location=no');
}

function copiar(texto)
{
	texto=document.getElementById(texto);
	texto.select();
	var cop = texto.createTextRange();
	cop.execCommand("Copy");
}


//VERIFICA SE SELECIONOU ALGUM PARA ENVIAR
var total_aniversariantes=0;
function somando(id)
{
	chk=document.getElementById(id);
	if(chk.checked==true)
	{
		total_aniversariantes++;
	}
	else
	{
		total_aniversariantes--;
	}
	//alert(total_aniversariantes);
}

function piscar(x) {
   x = (x == null) ? 0 : x;
   var objLinks = document.getElementsByTagName("a");

   for (var i = 0; i < objLinks.length; i++) {
       if (objLinks[i].className == "piscar") {
           var objStyle = objLinks[i].style;
           objStyle.color = (x % 2 == 1)  ?  ""  :  "#cc0000";
           //objStyle.color = (objStyle.color == "#cc0000")  ?  ""  :  "#cc0000";
       }
   }

   setTimeout("piscar("+ (x+1) +")", 500);
}
piscar();  


function esconde(id)
{
	
	if(document.getElementById(id).style.display == 'none')
	{
		document.getElementById(id).style.display='block';
	}
	else
	{
		document.getElementById(id).style.display='none';
	}
}

function esconde_video(id,id_img)
{
	
	if(document.getElementById(id).style.display == 'none')
	{
		document.getElementById(id).style.display='block';
		document.getElementById(id_img).src='imagens/seta_cima.gif';
	}
	else
	{
		document.getElementById(id).style.display='none';
		document.getElementById(id_img).src='imagens/seta_baixo.gif';
	}
}
