﻿function chaseAbas(chase){
	var nodes = document.getElementById(chase).childNodes.length;
	var i=0,l=0,j=20;
	for(l=0; l < nodes; l++){
		if(document.getElementById(chase).childNodes[l] == "[object HTMLLIElement]"){
			for(i=0; i < nodes; i++,j--){
				if(document.getElementById(chase).childNodes[i] == "[object HTMLLIElement]"){ 
					document.getElementById(chase).childNodes[i].style.zIndex = j;
					document.getElementById(chase).childNodes[i].className = null;
				}
			}
			document.getElementById(chase).childNodes[l].style.zIndex = 21;
			document.getElementById(chase).childNodes[l].className = 'abaSelected';
			break;
		}
	}
}

// Valida o e-mail
function validaEmail(email) {
    var suportado = 0;

    if (window.RegExp) {
        var tempReg = /a/;
        if (tempReg.test("a")) {
            suportado = 1;
        }
    }

    if (!suportado) {
        if (((email.indexOf(".") <= 0) || (email.indexOf("@") <= 0)) || ((email.lastIndexOf(".") == (email.length - 1)) || (email.lastIndexOf("@") == (email.length - 1)))) {
            return false;
        }
    } else {
        var tmp1 = /(@.*@)|(\.\.)|(@\.)|(^\.)/;
        var tmp2 = /^.+@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
        if (tmp1.test(email) || !tmp2.test(email)) {
            return false;
        }
    }
    return true;
}

function ctrlAbas(elem, chase){
	var nodes = document.getElementById(chase).childNodes.length;
	var i = 0, j=20;
	for(i=0; i < nodes; i++, j--){
		//alert(document.getElementById(chase).childNodes[i]);
		if(document.getElementById(chase).childNodes[i] == "[object HTMLLIElement]" || document.getElementById(chase).childNodes[i] == "[object]"){ 
			//alert(document.getElementById(chase).childNodes[i]);
			document.getElementById(chase).childNodes[i].style.zIndex = j;
			document.getElementById(chase).childNodes[i].className = null;
		}
	}
	elem.parentNode.parentNode.parentNode.className = 'abaSelected';
	elem.parentNode.parentNode.parentNode.style.zIndex = 21;
}

function ctrlFAQ(chase) {
    var x = chase.parentNode.parentNode.getElementsByTagName("p");
    for(i=0; i < x.length; i++) {
        if (x[i].style.display == 'block') {
            x[i].style.display = "none";
            x[i].style.verticalAlign = "top";
        }
        else {
            x[i].style.display = "block";
            x[i].style.verticalAlign = "top";
        }
	}
}
	
function validaData(data) {
	if(data.length < 6 || data.length > 10)
	    return false;
	
	pos0 = data.indexOf("/");
	if(pos0 == -1) 
	    return false;
	
	pos1 = data.indexOf("/", pos0 + 1);
	if(pos1 == -1) 
	    return false;
	
	if(data.indexOf("/", pos1 + 1) != -1)
	    return false;
	
	dia = data.substring(0,pos0);
	dia = (dia.charAt(0) == "0")?dia.charAt(dia.length - 1):dia
	
	mes = data.substring(pos0 + 1, pos1);
	mes = (mes.charAt(0) == "0")?mes.charAt(mes.length - 1):mes
	
	ano = data.substring(pos1 + 1, data.length);
	
	if(ano.length < 4)
		return false;
	
	ano = (ano.charAt(0) == "0")?ano.charAt(ano.length - 1):ano
	d = new Date()

	if(isNaN(parseInt(dia)) || isNaN(parseInt(mes)) || isNaN(parseInt(ano))) 
	    return false;

	if(parseInt(ano) > 2100 || parseInt(ano) < 0 || parseInt(mes) > 12 || parseInt(mes) < 1) 
	    return false;
	
	numero = ((parseInt(ano) - 1884) / 4)
	if(numero == Math.floor(numero)) { 
	    dias = "312931303130313130313031"; 
	} else { 
	    dias = "312831303130313130313031";
	}
	diamax = parseInt(dias.substring((mes-1)*2,((mes-1)*2)+2));
	
	if(parseInt(dia) < 1 || parseInt(dia) > diamax)
	    return false;
	
	return true;
}

function valida_num(obj) {
    numeros = new RegExp("[0-9]");

    while (!obj.value.charAt(obj.value.length - 1).match(numeros)) {
        if (obj.value.length == 1 && obj.value == "-") {
            return true;
        }
        if (obj.value.length >= 1) {
            obj.value = obj.value.substring(0, obj.value.length - 1)
        }
        else {
            return false;
        }
    }
}

function formatar(src, mask) {
    var i = src.value.length;
    var saida = mask.substring(i, i + 1);
    var ascii = event.keyCode;

    if (saida == "A") {
        if ((ascii >= 97) && (ascii <= 122)) { event.keyCode -= 32; }
        else { event.keyCode = 0; }
    } else if (saida == "0") {
        if ((ascii >= 48) && (ascii <= 57)) { return }
        else { event.keyCode = 0 }
    } else if (saida == "#") {
        return;
    } else {
        src.value += saida;

        if ((saida != "A") && (saida != "0") && (saida != "#")) {
            if ((ascii >= 48) && (ascii <= 57)) { return }
            else { event.keyCode = 0 }
            if ((ascii >= 97) && (ascii <= 122)) { event.keyCode -= 32; }
            else { event.keyCode = 0; }
        }

        if (saida == "A") {
            if ((ascii >= 97) && (ascii <= 122)) { event.keyCode -= 32; }

        } else { return; }
    }
}
	
function flash(largura, altura, arquivo, parametro) {
    document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0" width="' + largura + '" height="' + altura + '" id="teste" align="middle">');
    document.write('<param name="allowScriptAccess" value="sameDomain" /><param name="wmode" value="transparent" />');
    document.write('<PARAM NAME=FlashVars VALUE="' + parametro + '" />');
    document.write('<param name="movie" value="' + arquivo + '" /><param name="quality" value="best" /><param name="bgcolor" value="#ffffff" /><embed src="' + arquivo + '" flashvars="' + parametro + '" wmode="transparent" quality="best" width="' + largura + '" height="' + altura + '" name="teste" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
    document.write('</object>');
}

/* Galeria */
var esq, dir = null;

function slideDir(obj) {
    alert(obj);
    quant = 5;
    var novo = obj.scrollLeft + quant;
    if (novo >= 0 && novo < obj.scrollWidth) {
        obj.scrollLeft = novo;
        dir = setTimeout("slideDir(document.getElementById('thumbs'),5)", 5);
    }
    else {
        parar(1);
    }
}

function slideEsq(obj) {
    quant = 5;
    var novo = obj.scrollLeft - quant;
    if (novo >= -20 && novo < obj.scrollWidth) {
        obj.scrollLeft = novo;
        esq = setTimeout("slideEsq(document.getElementById('thumbs'),5)", 5); 
    }
    else {
        parar(2);
    }
}

function parar(q) {
    if (q == 1)
        clearTimeout(dir);
    else if (q == 2)
        clearTimeout(esq);
}

function fone(obj,prox) {
    switch (obj.value.length) {
        case 1:
        obj.value = "(" + obj.value;
        break;
        case 3:
        obj.value = obj.value + ")";
        break; 
        case 8:
        obj.value = obj.value + "-";
        break; 
        case 13:
        prox.focus();
        break;
    }
}
function formata_data(obj,prox) {
    switch (obj.value.length) {
        case 2:
        obj.value = obj.value + "/";
        break;
        case 5:
        obj.value = obj.value + "/";
        break;
        case 9:
        prox.focus();
        break;
    }
}
function Apenas_Numeros(caracter)
{
var nTecla = 0;
if (document.all) {
nTecla = caracter.keyCode;
} else {
nTecla = caracter.which;
}
if ((nTecla> 47 && nTecla <58)
|| nTecla == 8 || nTecla == 127
|| nTecla == 0 || nTecla == 9 // 0 == Tab
|| nTecla == 13) { // 13 == Enter
return true;
} else {
return false;
}
}

function validaCPF(cpf) 
{

erro = new String;
valorCpf = new String;
valorCpf = cpf.value;

if (valorCpf.length == 11)
{
    cpf.value = valorCpf = cpf.value.substr(0, 3) + '.' + cpf.value.substr(3, 3) + '.' + cpf.value.substr(6, 3) + '-' + cpf.value.substr(9, 2);
}
if (valorCpf.length == 14)
{ 
valorCpf = valorCpf.replace('.', '');
valorCpf = valorCpf.replace('.', '');
valorCpf = valorCpf.replace('-', '');

var nonNumbers = /\D/;

if (nonNumbers.test(valorCpf)) 
{
    erro = "A verificacao de CPF suporta apenas números!"; 
}
else
{
    if (valorCpf == "00000000000" || 
    valorCpf == "11111111111" || 
    valorCpf == "22222222222" || 
    valorCpf == "33333333333" || 
    valorCpf == "44444444444" || 
    valorCpf == "55555555555" || 
    valorCpf == "66666666666" || 
    valorCpf == "77777777777" || 
    valorCpf == "88888888888" || 
    valorCpf == "99999999999") {
        erro = "Número de CPF inválido!"
}

var a = [];
var b = new Number;
var c = 11;

for (i=0; i<11; i++){
a[i] = valorCpf.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 ((valorCpf.charAt(9) != a[9]) || (valorCpf.charAt(10) != a[10])) {
erro = "Número de CPF inválido.";

}
}
}
else
{
if(valorCpf.length == 0)
return false
else
erro = "Número de CPF inválido.";
}
if (erro.length > 0) {
alert(erro);
cpf.focus();
return false;
} 
return true; 
}

//envento onkeyup
function maskCPF(CPF) {
var evt = window.event;
kcode=evt.keyCode;
if (kcode == 8) return;
if (CPF.value.length == 3) { CPF.value = CPF.value + '.'; }
if (CPF.value.length == 7) { CPF.value = CPF.value + '.'; }
if (CPF.value.length == 11) { CPF.value = CPF.value + '-'; }
}

// evento onblur
function formataCPF(CPF)
{
with (CPF)
{
value = value.substr(0, 3) + '.' + 
value.substr(3, 3) + '.' + 
value.substr(6, 3) + '-' +
value.substr(9, 2);
}
}
function retiraFormatacao(CPF)
{
with (CPF)
{
value = value.replace (".","");
value = value.replace (".","");
value = value.replace ("-","");
value = value.replace ("/","");
}
}

//Mostra header se acessado pelo subdominio do mundocaixa
/*
window.onload = function()
{
	if (window.parent.location.href.toLowerCase().indexOf('mc.mundocaixa.com.br', 0) != -1)
	{
		window.document.getElementById("body_top").style.display = "none";
	}
}

*/
