
////////////////////////////////////////////////////////////////
// * FlashWinSP2 - Gera o flash
///////////////////////////////////////////////////////////////
function FlashWinSP2(arquivo,largura,altura) {
  document.write("<object width=\"" + largura + "\" height=\"" + altura + "\" classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\">");
  document.write("  <param name=\"movie\" value=\"" + arquivo + "\" />");
  document.write("  <param name=\"quality\" value=\"high\" />");
  document.write("  <param name=\"wmode\" value=\"transparent\" />");
  document.write("  <embed src=\"" + arquivo + "\" width=\"" + largura + "\" height=\"" + altura + "\" quality=\"high\" wmode=\"transparent\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\"></embed>");
  document.write("</object>");
}


////////////////////////////////////////////////////////////////
// * abreJanelaCentro - Abre uma nova janela popup
///////////////////////////////////////////////////////////////
function abreJanelaCentro(Url,NomeJanela,width,height,extras){
	var largura = width;
	var altura = height;
	var adicionais= extras;
	var extras2= extras;
	var topo = (screen.height-altura)/2;
	var esquerda = (screen.width-largura)/2;
	novaJanela=window.open(''+ Url + '',''+ NomeJanela + '','width=' + largura + ',height=' + altura + ',top=' + topo + ',left=' + esquerda + ',scrollbars=yes,resizable=no,features=' + adicionais + '');
	novaJanela.focus();	
}

////////////////////////////////////////////////////////////////
// * Funções de swap image
///////////////////////////////////////////////////////////////
function trocaImgVoltar() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function PreCarregarImagens() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=PreCarregarImagens.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function ProcurarObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=ProcurarObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function trocarImagem() { //v3.0
  var i,j=0,x,a=trocarImagem.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=ProcurarObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


////////////////////////////////////////////////////////////////
// * LimitaCampo - Limita a quantidade de caracteres em um textarea
// Uso: OnKeyUp="LimitaCampo(this, 100, 'campo_contador');"
// 		o campo_contador será o ID de um input que armazenará a 
//		quantidade de caracteres do textarea
///////////////////////////////////////////////////////////////
function LimitaCampo(campo,tam,campo_contador){
	var tamanho = campo.value.length;
	var tex=campo.value;
	if (tamanho>=tam) {
		campo.value=tex.substring(0,tam); 
	}
	
	if (campo_contador != '' && document.getElementById(campo_contador)) {
		document.getElementById(campo_contador).innerHTML = tamanho;
	}
	
	return true;
}


///////////////////////////////////////////////////////////////
// * ValidaEmail - Validação de E-Mail
///////////////////////////////////////////////////////////////
function ValidaEmail(pVal)
{
	var reTipo = /^[\w-]+(\.[\w-]+)*@(([A-Za-z\d][A-Za-z\d-]{0,61}[A-Za-z\d]\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
	return reTipo.test(pVal);
}


////////////////////////////////////////////////////////////////
// * criaMascara - Cria uma máscara em input text
// Uso: OnKeyUp="criaMascara(this, '##.###.###-#');"
///////////////////////////////////////////////////////////////
  function criaMascara(_RefObjeto, _Modelo){
    var valorAtual = _RefObjeto.value;        
    var valorNumerico = '';
    var nIndexModelo = 0;
    var nIndexString = 0;
    var valorFinal = '';
    var adicionarValor = true;
     
    // limpa a string valor atual para verificar 
    // se todos os caracteres são números
    for (i=0;i<_Modelo.length;i++){
        if (_Modelo.substr(i,1) != '#') {
          valorAtual = valorAtual.replace(_Modelo.substr(i,1),'');
      	}
	}
      
	// verifica se todos os caracteres são números
	for (i=0;i<valorAtual.length;i++){
		if (!isNaN(parseFloat(valorAtual.substr(i,1)))) {
			valorNumerico = valorNumerico + valorAtual.substr(i,1);
		}
	}

	// aplica a máscara ao campo informado usando
	// o modelo de máscara informado no script
	for (i=0;i<_Modelo.length;i++) {

		if (_Modelo.substr(i,1) == '#'){
			if (valorNumerico.substr(nIndexModelo,1) != ''){
				valorFinal = valorFinal + valorNumerico.substr(nIndexModelo,1);
				nIndexModelo++;nIndexString++;
          	} else {
				adicionarValor = false;
			}
		} else {
			if (adicionarValor && valorNumerico.substr(nIndexModelo,1) != '') {
				valorFinal = valorFinal + _Modelo.substr(nIndexString,1)
				nIndexString++;
			}
		}
	}
	//alert(valorFinal)
	_RefObjeto.value = valorFinal 

  }




function modulo(str) {

   	soma=0;
   	ind=2;
   	for(pos=str.length-1;pos>-1;pos=pos-1) {
   		soma = soma + (parseInt(str.charAt(pos)) * ind);
   		ind++;
   		if(str.length>11) {
   			if(ind>9) ind=2;
   		}
	}
   	resto = soma - (Math.floor(soma / 11) * 11);
   	if(resto < 2) {
    	return 0
   	}
   	else {
   		return 11 - resto
   	}
}

////////////////////////////////////////////////////////////////
// * ValidaCPF - Validação de CPF (somente numeros)
///////////////////////////////////////////////////////////////
function ValidaCPF(valor) {

	primeiro=valor.substr(1,1);
	falso=true;
	size=valor.length;
	if (size!=11){
		return false;
	}
	size--;
	for (i=2; i<size-1; ++i){
		proximo=(valor.substr(i,1));
		if (primeiro!=proximo) {
			falso=false
		}
	}
	if (falso){
		return false;
	}
   	if(modulo(valor.substring(0,valor.length - 2)) + "" + modulo(valor.substring(0,valor.length - 1)) != valor.substring(valor.length - 2,valor.length)) {
   		return false;
   	}
   	return true
}


////////////////////////////////////////////////////////////////
// * ValidaCPF - Validação de CNPJ (somente numeros)
///////////////////////////////////////////////////////////////
function ValidaCNPJ(valor) {

	primeiro=valor.substr(1,1);
	falso=true;
	size=valor.length;
	if (size!=14){
		return false;
	}
	size--;
	for (i=2; i<size-1; ++i){
		proximo=(valor.substr(i,1));
		if (primeiro!=proximo) {
			falso=false
		}
	}
	
	if (falso){
		return;
	}
	
   	if(modulo(valor.substring(0,valor.length - 2)) + "" + modulo(valor.substring(0,valor.length - 1)) !=valor.substring(valor.length - 2,valor.length)) {
   		return false;
   	}
   	return true
}







////////////////////////////////////////////////////////////////
// * ValidaData - Validação de Datas no formato dd/mm/aaaa
///////////////////////////////////////////////////////////////
function ValidaData(pData){
	if(pData.length<10 || pData.length>10) return false;

	var ano = '' + pData.substring(6,10);
	var mes = '' + pData.substring(3,5);
	var dia = '' + pData.substring(0,2);
	
	if (!ValidaNumero(ano) || !ValidaNumero(mes) || !ValidaNumero(dia)) return false;
	if(dia>'31') return false;
	if(mes>'12') return false;
	if(ano<='1900') return false;
	if(mes=='02'){
		if(ano%4!=0 && dia>'28'){
			return false;
		}
		else{
			if(dia>'29'){
				return false;
			}
		}
	}
	
	if(mes<='07'){
		if(mes%2==0 && dia>'30') return false;
	}
	else{
		if(mes>'09'){
			if(mes%2!=0 && dia>'30'){
				return false;
			}
		}
	}
					
	return true
}

///////////////////////////////////////////////////////////////
// * ValidaHora - Validação de Horas no formato HH:MM:SS
///////////////////////////////////////////////////////////////
function IsHour(pHora){

	if (pHora != ''){
	
		if(pHora.length < 4 || pHora.length > 5){
			return false
		}

		var aux = pHora.indexOf(":")
		var hora = pHora.substring(0,aux)
		var min = pHora.substring(aux+1,pHora.length)
	
		if(hora > 23 || hora < 0){
			return false
		}
					
		if(min > 59 || min < 0){
			return false
		}
	}
	
	return true
}


///////////////////////////////////////////////////////////////
// * ValidaNumero - Vê se uma string é numérica
///////////////////////////////////////////////////////////////
function ValidaNumero(pNum){

	if (pNum==''){
		return false;
	}
	for (var i = 0; i < pNum.length; i++){
		var ch = pNum.substring(i, i + 1);
		if (ch < '0' || '9' < ch){
			return false;
		}
	}
	return true;
}





////////////////////////////////////////////////////////////////
// * getCheckedValue - Retorna o RADIO selecionado
// * setCheckedValue - Seleciona um valor do RADIO especificado
///////////////////////////////////////////////////////////////
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}
function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}







////////////////////////////////////////////////////////////////
// Alternar LOGIN entre ALUNO/PROFESSOR
///////////////////////////////////////////////////////////////

function painelLogin(numero) {

	if (numero==1){
		document.getElementById('login-professor').style.display='none';
		document.getElementById('login-aluno').style.display='block';
	} else {
		document.getElementById('login-professor').style.display='block';
		document.getElementById('login-aluno').style.display='none';
	}
	
	
}




///////////////////////////////////////////////////////////////
// Submenu
///////////////////////////////////////////////////////////////
var submenu_sobre = 0;
function submenu(id) {
	submenu_sobre=id;
	document.getElementById('sub'+id).style.display='block';
	document.getElementById('sub'+id).onmouseover = function () {
		submenu_sobre=id;
	}
	document.getElementById('sub'+id).onmouseout = function () {
		submenu_sobre=0;
	}
}

function submenu_out(id) {
	submenu_sobre=0;
	setTimeout('desativaSubmenu('+id+');',500);
}

function desativaSubmenu(id) {

	if (submenu_sobre==id) setTimeout('desativaSubmenu('+id+');',500);
	else document.getElementById('sub'+id).style.display='none';

}






















