// JavaScript Document

var size = 12;

// Troca tamanho das fontes da matéria
function changeFontSize(type){
	if (type=="up") {
		if(size<15) size+=1;
	} else {
		if(size>9) size-=1;
	}

ps = document.getElementById('brtpTexto').getElementsByTagName("p");
uls = document.getElementById('brtpTexto').getElementsByTagName("ul");
	if(ps.length > 0)	{
		for(ip=0; ip<ps.length;ip++) {
			ps[ip].style.fontSize = size+'px';
		}
	}
	if(uls.length > 0)	{
		for(iul=0; iul<uls.length;iul++) {
			uls[iul].style.fontSize = size+'px';
		}
	}
}

// funcao de redirecionamento
function redirect(URLStr) { 

	var location = URLStr; 
	
	document.location.href=location;

}

//funcao qde redirecionamento interno
function navegaBoxGeral(url){
        window.location.assign(url);
}


//funcao para abrir popup
function OpenWindow(FileNameToOpen, janela, largura, altura, scrollbar)
{
newWindow = window.open(FileNameToOpen, janela, 'width='+largura+', height='+altura+', toolbar=no, scrollbars='+scrollbar+', location=no, left=100, top=100')
if (newWindow.open)
{
newWindow.focus()
}
}

// funcao que formata o campo telefone
function Formatar_Telefone(objeto,tammax,teclapres){

        var tecla = teclapres.keyCode;
        vr = objeto.value;
        vr = vr.replace( "(", "" );
        vr = vr.replace( ")", "" );
        vr = vr.replace( " ", "" );
        vr = vr.replace( "-", "" );
        tam = vr.length;

        if (tam < tammax && tecla != 8) {
                tam = vr.length + 1 ;
        }

        if (tecla == 8 ) {
                tam = tam - 1 ;
        }

        if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ) {
                if ( tam <= 4 ) {
                         objeto.value = vr ;
                }
                 if ( (tam > 4) && (tam <= 8) ) {
                         objeto.value = vr.substr(0,tam-4) + '-' + vr.substr( tam - 4, tam ) ;
                }
                 if ( (tam >= 9) && (tam <= 10) ) {
                        objeto.value = '(' + vr.substr(0,2) + ') ' + vr.substr(2,tam-6) + '-' + vr.substr(tam-4,tam) ;
                }
        }
}

// funcao que valida o cpf
function ValidaCPF(cpfvalid) {

                cpf = cpfvalid;
                valor = true;
                erro = new String;
                if (cpf.length < 11) erro += "Sao necessarios 11 digitos para verificacao do CPF! \n\n";
                var nonNumbers = /\D/;
                if (nonNumbers.test(cpf)) erro += "A verificacao de CPF suporta apenas numeros! \n\n";
                if (cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999"){
                          erro += "Numero de CPF invalido!"
                }
                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])){
                        erro +="Digito verificador com problema!";
                }
                if (erro.length > 0){
                        alert(erro);
                        return false;
                }
                return true;
}

function Validar_Cadastro(){
 
        if (document.formCadPromo01.cpfInternauta.value!="") {
                if (!ValidaCPF(document.formCadPromo01.cpfInternauta.value)) {
                        document.formCadPromo01.cpfInternauta.focus();
                        //alert("Digite um e-mail válido!");
                        return false;
                }
        }

}

// funcao que exibe erros
function erroPagina(erro) {
	
	alert(erro); history.back();
	
}

