﻿//----------------------------------------------------------------- GERAL
function Trim(str) {
	return str.replace(/^\s+|\s+$/g, "");
}

function AbreInfo(valor) {
	document.getElementById("sobreObra").style.display = 'none';
	document.getElementById("sobreAutor").style.display = 'none';
	document.getElementById("matComplementar").style.display = 'none';
	document.getElementById("dataComemorativa").style.display = 'none';
	//document.getElementById("materialApoio").style.display = 'none';
	//document.getElementById("datas").style.display = 'none';
	document.getElementById(valor).style.display = '';
}

//---------------------- QUEM SOMOS
function mostraTexto(obj, qualTexto) {
	for (var i = 1; i <= 5; i++) {
		document.getElementById('Texto' + i.toString()).style.display = (qualTexto == i) ? '' : 'none';
	}
	document.getElementById('Texto0').innerHTML = obj.innerHTML;
}

//---------------------- FALE CONOSCO / TRABALHE CONOSCO
function mostraTel(num) {
	for (var i = 1; i <= 3; i++) {
		if (i == num) {
			document.getElementById('Fones' + i.toString()).style.display =
				(document.getElementById('Fones' + i.toString()).style.display == "none") ? "" : "none";
		} else {
			document.getElementById('Fones' + i.toString()).style.display = 'none';
		}
	}
}

function mostraFormulario(objPalestra, objAutor, objAssunto) {
	var palestra = document.getElementById(objPalestra);
	var autor = document.getElementById(objAutor);
	var assunto = document.getElementById(objAssunto);

	switch (assunto.selectedIndex) {
		case 6:
			palestra.style.display = '';
			autor.style.display = 'none';
			break;
		case 9:
			palestra.style.display = 'none';
			autor.style.display = '';
			break;
		default:
			palestra.style.display = 'none';
			autor.style.display = 'none';
	}

}

function validaCampoVazio(objId, nome) {
	var obj = document.getElementById(objId);
	if (obj.value == "") {
		alert("O campo " + nome + " é obrigatório.");
		if (!obj.disabled) {
			obj.focus();
		}
		return false;
	} else {
		return true;
	}
}

function validaNomeCompleto(objId, nome) {
	obj = document.getElementById(objId);
	if (Trim(obj.value).length == 0 || Trim(obj.value).indexOf(' ') == -1) {
		alert('Favor preencher o nome e sobrenome');
		obj.focus();
		return false;
	} else {
		return true;
	}
}

function valida_email(objId) {
	obj = document.getElementById(objId);
	if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(obj.value))) {
		alert("E-mail inválido!");
		obj.value = "";
		obj.focus();
		return false;
	} else {
		return true;
	}
}

function valida_dtNascimento(objId) {
	f = document.getElementById(objId);
	erro = 0;
	hoje = new Date();
	anoAtual = hoje.getFullYear();
	barras = f.value.split("/");
	if (barras.length == 3) {
		dia = barras[0];
		mes = barras[1];
		ano = barras[2];
		resultado = (!isNaN(dia) && (dia > 0) && (dia < 32)) && (!isNaN(mes) && (mes > 0) && (mes < 13)) && (!isNaN(ano) && (ano.length == 4) && (ano <= anoAtual && ano >= 1900));
		if (!resultado) {
			alert("Formato de data invalido!");
			f.value = "";
			f.focus();
			return false;
		}
	} else {
		alert("Formato de data invalido!");
		f.value = "";
		f.focus();
		return false;
	}
	return true;
}

function validaCPF(objID) {
	var cpf = document.getElementById(objID).value;
	var erro = new String;
	//var filtro = /^\d{3}.\d{3}.\d{3}-\d{2}$/i;

	if (cpf.length > 0) {
		cpf = remove(cpf, ".");
		cpf = remove(cpf, "-");

		if (cpf.length < 11) erro += "São necessários 11 dígitos para verificação do CPF! ";
		var nonNumbers = /\D/;
		//if (nonNumbers.test(cpf)) erro += "A verificação de CPF suporta apenas numeros! ";
		if (nonNumbers.test(cpf)) erro += "O CPF deve ter apenas números! ";
		if (cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "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] = 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 += "Dígito verificador inválido!";
		}

		if (erro.length > 0) {
			alert(erro);
			document.getElementById(objID).value = "";
			document.getElementById(objID).focus();
			return false;
		}
	}
	return true;
}

function remove(str, sub) {
	i = str.indexOf(sub);
	r = "";
	if (i == -1) return str;
	r += str.substring(0, i) + remove(str.substring(i + sub.length), sub);
	return r;
}

//------------------------------------- MASCARA DE CAMPOS
function mask(format, obj, e) {
	var keynum, keychar, numcheck;
	var iChar = obj.value.length;
	var out = format.substring(iChar, iChar + 1);
	keynum = (window.event) ? e.keyCode : e.which;
	keychar = String.fromCharCode(keynum);
	if (keynum == 8 || keynum == 0) { return true; }
	if (iChar >= format.length) { return false; }
	switch (out) {
		case "0": numcheck = /\d/; return numcheck.test(keychar); break;
		case "A": numcheck = /[A-Za-zÀ-ÿ]/; return numcheck.test(keychar); break;
		case "#": return keychar; break;
		default: obj.value += out; return mask(format, obj, e);
	}
	return false;
}

//------------------------------------- ABRIR POPUP
function winopen(page, wdt, hgt) {
	var _x = wdt / 2;
	var _y = hgt / 2;
	var pos_tela_width = (screen.width / 2) - _x;
	var pos_tela_height = (screen.height / 2) - _y;
	window.open(page, "pre", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,noresize,copyhistory=no,width=" + wdt + ",height=" + hgt + ",top=" + pos_tela_height + ",left=" + pos_tela_width);
}
//------------------------------------- SCRIPT FLASH
function flash(flash, largura, altura) {
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="' + largura + '" height="' + altura + '" id="ShockwaveFlash5">');
	document.write('	<param name="movie" value="' + flash + '" />');
	document.write('	<param name="quality" value="high" />');
	document.write('	<param name="wmode" value="transparent" />');
	document.write('	<param name="allowScriptAccess" value="sameDomain" />');
	document.write('	<param name="allowFullScreen" value="false" />');
	//document.write('	<param name="bgcolor" value="#ffffff" />');
	document.write('	<embed src="' + flash + '" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="' + largura + '" height="' + altura + '" />');
	document.write('</object>');
}

/*
function FechaPopUp() {
document.all.animaFlash.style.display = 'none';
}

function mostraInst(obj) {
obj.style.display = (obj.style.display == "none") ? "" : "none";
}


function mostraInst(cbxInstituicao, tbdInstituicao) {
tbdInstituicao.style.display = (cbxInstituicao.checked) ? '' : 'none';

InstValidators(cbxInstituicao.checked);
}

function faleConoscoOnLoad(objId,objIdHide) {
if (document.getElementById(objId).checked) {
document.getElementById(objId).style.display == "";
} else {
document.getElementById(objId).style.display == "none";
}
}
*/
