﻿

/*----------------------------------------------------------------------------
Muda CSS
-----------------------------------------------------------------------------*/
function setActiveStyleSheet(title) {
    var i, a, main;
    for (i = 0; (a = document.getElementsByTagName("link")[i]); i++) {
        if (a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
            a.disabled = true;
            if (a.getAttribute("title") == title) a.disabled = false;
        }
    }
}


/*----------------------------------------------------------------------------
Exibe Palestrantes
-----------------------------------------------------------------------------*/
function exibe(id) {
    var id2 = "X" + id;
    if (document.getElementById(id).style.display == "none") {
        document.getElementById(id).style.display = "block";
    }
    else {
        document.getElementById(id).style.display = "none";
    }
}
/*----------------------------------------------------------------------------
Aumentar e diminuir a fonte
-----------------------------------------------------------------------------*/
var tagAlvo = new Array('p');

var tamanhos = new Array('9px', '12px', '15px', '18px', '21px', '24px', '27px');
var tamanhoInicial = 2;

function mudaTamanho(idAlvo, acao) {
    if (!document.getElementById) return
    var selecionados = null, tamanho = tamanhoInicial, i, j, tagsAlvo;
    tamanho += acao;
    if (tamanho < 0) tamanho = 0;
    if (tamanho > 6) tamanho = 6;
    tamanhoInicial = tamanho;
    if (!(selecionados = document.getElementById(idAlvo))) selecionados = document.getElementsByTagName(idAlvo)[0];

    selecionados.style.fontSize = tamanhos[tamanho];

    for (i = 0; i < tagAlvo.length; i++) {
        tagsAlvo = selecionados.getElementsByTagName(tagAlvo[i]);
        for (j = 0; j < tagsAlvo.length; j++) tagsAlvo[j].style.fontSize = tamanhos[tamanho];
    }
}


/*----------------------------------------------------------------------------
Formatação para qualquer mascara
-----------------------------------------------------------------------------*/
function formatar(src, mask) {
    if (src.value.length != 0) {
        var i = src.value.length;
        var saida = mask.substring(0, 1);
        var texto = mask.substring(i)
        if (texto.substring(0, 1) != saida) {
            src.value += texto.substring(0, 1);
        }
    }
}

//colocar no objeto isso: onKeyPress="return Numero(event);"
function Numero(e)//Só aceita numero
{
	if (document.all) // Internet Explorer
		var tecla = event.keyCode;
	else if(document.layers) // Nestcape
		var tecla = e.which;
		if (tecla > 47 && tecla < 58) // numeros de 0 a 9
			return true;
		else
			{
				if (tecla != 8 && tecla != 13) // backspace e Enter
					event.keyCode = 0;
					//return false;
				else
					return true;
			}
}

function CheckData(obj) {	
	if(obj.value.length == 10){
		dia = obj.value.substr(0,2);
		mes = obj.value.substr(3,2);
		ano = obj.value.substr(6,4);
	
		if(ano < 1800) {
			obj.value = dia+"/"+mes+"/";
		} else if(mes == "02" && dia > "28") {
			if(ano%4) //verifica se o ano é bissexto
				dia = "28";
			else
				dia = "29";
			
			obj.value = dia+"/"+mes+"/"+ano;
			alert("A data foi alterada, por favor confira.");
	
		} else if((mes == "04" || mes == "06" || mes == "9" || mes == "11") &&
		(dia == "31")) {
			dia = "30";
			obj.value = dia+"/"+mes+"/"+ano;
			alert("A data foi alterada, por favor confira.");
		}
	}	

	if (obj.value.length == 2) {
		if ((obj.value.substr(obj.value.length-2,obj.value.length) > "31") ||
		(obj.value.substr(obj.value.length-2,obj.value.length) == "00"))
			obj.value = obj.value.substr(0,obj.value.length-2);
	}

	if (obj.value.length == 5) {
		if ((obj.value.substr(obj.value.length-2,obj.value.length) > "12") ||
		(obj.value.substr(obj.value.length-2,obj.value.length) == "00"))	
			obj.value = obj.value.substr(0,obj.value.length-2);
	}
	
	formatar(obj, '##/##/####');
}

function validarCPF(obj) {
    if (obj.value.length != 0) {

        var cpf = obj.value;

        cpf = cpf.replace(".", "").replace(".", "").replace("-", "");

        if (cpf.length != 11 || cpf == "00000000000" || cpf == "11111111111" ||
	  cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" ||
	  cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" ||
	  cpf == "88888888888" || cpf == "99999999999") {
            window.alert("CPF inválido. Tente novamente.");
            obj.focus();
            obj.select();
            return false;
        }

        soma = 0;
        for (i = 0; i < 9; i++)
            soma += parseInt(cpf.charAt(i)) * (10 - i);
        resto = 11 - (soma % 11);
        if (resto == 10 || resto == 11)
            resto = 0;
        if (resto != parseInt(cpf.charAt(9))) {
            window.alert("CPF inválido. Tente novamente.");
            obj.focus();
            obj.select();
            return false;
        }
        soma = 0;
        for (i = 0; i < 10; i++)
            soma += parseInt(cpf.charAt(i)) * (11 - i);
        resto = 11 - (soma % 11);
        if (resto == 10 || resto == 11)
            resto = 0;
        if (resto != parseInt(cpf.charAt(10))) {
            window.alert("CPF inválido. Tente novamente.");
            obj.focus();
            obj.select();
            return false;
        }
    }
   return true;
 }

function validarEmail(obj) {
	if (obj.value == "") {
		alert("Informe seu e-mail.");
		obj.focus();
		obj.select();
		return false;
	} else {
		prim = obj.value.indexOf("@")
		if(prim < 2) {
			alert("O e-mail informado parece não estar correto.");
			obj.focus();
			obj.select();
			return false;
		}
		if(obj.value.indexOf("@",prim + 1) != -1) {
			alert("O e-mail informado parece não estar correto.");
			obj.focus();
			obj.select();
			return false;
		}
		if(obj.value.indexOf(".") < 1) {
			alert("O e-mail informado parece não estar correto.");
			obj.focus();
			obj.select();
			return false;
		}
		if(obj.value.indexOf(" ") != -1) {
			alert("O e-mail informado parece não estar correto.");
			obj.focus();
			obj.select();
			return false;
		}
		if(obj.value.indexOf("zipmeil.com") > 0) {
			alert("O e-mail informado parece não estar correto.");
			obj.focus();
			obj.select();
			return false;
		}
		if(obj.value.indexOf("hotmeil.com") > 0) {
			alert("O e-mail informado parece não estar correto.");
			obj.focus();
			obj.select();
			return false;
		}
		if(obj.value.indexOf(".@") > 0) {
			alert("O e-mail informado parece não estar correto.");
			obj.focus();
			obj.select();
			return false;
		}
		if(obj.value.indexOf("@.") > 0) {
			alert("O e-mail informado parece não estar correto.");
			obj.focus();
			obj.select();
			return false;
		}
		if(obj.value.indexOf(".com.br.") > 0) {
			alert("O e-mail informado parece não estar correto.");
			obj.focus();
			obj.select();
			return false;
		}
		if(obj.value.indexOf("/") > 0) {
			alert("O e-mail informado parece não estar correto.");
			obj.focus();
			obj.select();
			return false;
		}
		if(obj.value.indexOf("[") > 0) {
			alert("O e-mail informado parece não estar correto.");
			obj.focus();
			obj.select();
			return false;
		}
		if(obj.value.indexOf("]") > 0) {
			alert("O e-mail informado parece não estar correto.");
			obj.focus();
			obj.select();
			return false;
		}
		if(obj.value.indexOf("(") > 0) {
			alert("O e-mail informado parece não estar correto.");
			obj.focus();
			obj.select();
			return false;
		}
		if(obj.value.indexOf(")") > 0) {
			alert("O e-mail informado parece não estar correto.");
			obj.focus();
			obj.select();
			return false;
		}
		if(obj.value.indexOf("..") > 0) {
			alert("O e-mail informado parece não estar correto.");
			obj.focus();
			obj.select();
			return false;
		}
	}
		return true;
}

var win = null;
function PopUp(pagina){
    w = 350;
    h = 350;
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings = 'toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition;
	window.open(pagina,'Frequência_Aluno',settings);
}

var win = null;
function PopUpWebCam(pagina){
    w = 580;
    h = 430;
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings = 'toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition;
	window.open(pagina,'WebCam',settings);
}

var win = null;
function PopUpRelatorio(pagina){
    w = 600;
    h = 600;
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings = 'toolbar=yes,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition;
	window.open(pagina,'Relatório',settings);
}
