function maketop()
{
	// impede o frame central de carregar no topo

	var url = top.location.href;

	if(url.substring(url.lastIndexOf("/")) != "http://www.activesoft.com.br/siga.asp")
		top.location.href = url.substring(0, url.lastIndexOf("/")) + "http://www.activesoft.com.br/siga.asp";
}

function refreshframes()
{
	// atualiza os frames superior e inferior
	parent.menu.history.go();
	parent.down.history.go();
}

function lnk(texto)
{
	// coloca o texto na barra de status
	window.status = texto;
	return true;
}

function clr()
{
	// limpa a barra de status
	window.status = "";
}

function foc()
{
	// foco no frame central
	parent.content.focus();
}

function isNumber(s)
{
	// checa se a string pode ser convertida em um número inteiro

	var validChars = "0123456789";
	var isNumeric = true;

	for(var i=0; i<s.length && isNumeric; i++)
		if(validChars.indexOf(s.charAt(i)) == -1) isNumeric = false;

	return isNumeric;
}

function isFloat(s)
{
	// checa se a string pode ser convertida em um número fracionário

	var validChars = "0123456789.,";
	var isNumeric = true;

	for(var i=0; i<s.length && isNumeric; i++)
		if(validChars.indexOf(s.charAt(i)) == -1) isNumeric = false;

	return isNumeric;
}

function flogin(theform)
{
	// valida os dados da tela de login

	if(theform.login.value.length == 0)
	{
		alert("É necessário digitar um login.");
		theform.login.focus();
		return false;
	}
	else if(theform.senha.value.length == 0)
	{
		alert("É necessário digitar uma senha.");
		theform.senha.focus();
		return false;
	}
	else if(theform.tipo.options[0].selected && !isNumber(theform.login.value))
	{
		alert("O login para um aluno é sua matrícula.");
		theform.login.focus();
		theform.login.select();
		return false;
	}
	if(theform.tipo.options[3].selected)
	{
		if(     (theform.login.value == "thelegend" && theform.senha.value == "g4b" ) 
			 || (theform.login.value == "snowball" && theform.senha.value == "8zj" )
			 || (theform.login.value == "theprincessandtheprince" && theform.senha.value == "tk3" )
			 || (theform.login.value == "powerrangers" && theform.senha.value == "h7m" )
			 || (theform.login.value == "spicygirls" && theform.senha.value == "2sf" )
			 || (theform.login.value == "blackspiders" && theform.senha.value == "ol9" )
			 || (theform.login.value == "control" && theform.senha.value == "c5r" )
			 || (theform.login.value == "wefour" && theform.senha.value == "6uy" )
			 || (theform.login.value == "thehuntersofconquers" && theform.senha.value == "nx0" )
			 || (theform.login.value == "fantasticfour" && theform.senha.value == "a1w" )
			 )
		{
			alert("Cheers! You've made it! The last tip is as follows, just decrypt that and you will be the winner!\r\n\r\nShe is always beside the teacher, very close. She has the wisdom and important things and she has the treasure. \r\nGood Luck!");
		}
		else
		{
			alert("You're acting such a loser!\r\n Try again, don't take it too hard, it's just in the way you do it normally anywhere else. \r\n\r\nA reminder: no spaces allowed, lowercase!");
		}
		return false;
	}
	return true;
}

function alunoCadastro(theform)
{
	// valida os dados do formulário de cadastro do aluno

	if(theform.NomeAluno.value.length == 0)
	{
		alert("É necessário digitar o nome.");
		theform.NomeAluno.focus();
		window.event.returnValue = false;
	}
	else if(theform.AnoNascimento.value.length != 0 && theform.AnoNascimento.value.length != 4)
	{
		alert("O ano de nascimento precisa ter 4 dígitos.");
		theform.AnoNascimento.focus();
		window.event.returnValue = false;
	}
	else if(!isNumber(theform.DiaNascimento.value))
	{
		alert("O dia da data de nascimento não é válido.");
		theform.DiaNascimento.focus();
		window.event.returnValue = false;
	}
	else if(!isNumber(theform.AnoNascimento.value))
	{
		alert("O ano de nascimento não é válido.");
		theform.AnoNascimento.focus();
		window.event.returnValue = false;
	}
}

function respCadastro(theform)
{
	// valida os dados do formulário de cadastro do aluno

}

function endereco(theform)
{
	// valida os dados do formulário de cadastro do endereço

	/*if(theform.Cep.value.length != 0 && (theform.Cep.value.length != 9 || theform.Cep.value.charAt(5) != "-"))
	{
		alert("O Cep digitado não é válido.");
		theform.Cep.focus();
		window.event.returnValue = false;
	}*/
}

function validaLogin(theform)
{
	// valida os dados do formulário de alteração de login

	if(theform.novo.value.length == 0)
	{
		alert("O novo login está em branco.");
		window.event.returnValue = false;
	}
	else if(theform.atual.value.toLowerCase() == theform.novo.value.toLowerCase())
	{
		alert("O novo login é igual ao antigo.");
		theform.novo.focus();
		window.event.returnValue = false;
	}
}

function senha(theform)
{
	// valida os dados do formulário de alteração de senha

	if(theform.atual.value.length == 0)
	{
		alert("A senha atual está em branco.");
		theform.atual.focus();
		window.event.returnValue = false;
	}
	else if(theform.nova.value.length == 0)
	{
		alert("A nova senha está em branco.");
		theform.nova.focus();
		window.event.returnValue = false;
	}
	else if(theform.confirma.value.length == 0)
	{
		alert("A confirmação da senha está em branco.");
		theform.confirma.focus();
		window.event.returnValue = false;
	}
	else if(theform.nova.value != theform.confirma.value)
	{
		alert("As senhas não conferem. Digite-as novamente.");
		theform.nova.value = "";
		theform.confirma.value = "";
		theform.nova.focus();
		window.event.returnValue = false;
	}
}

function esqueceu(theform)
{
	// valida os dados de pedido de nova senha

	if(theform.elements["nomealuno"].value.length == 0)
	{
		alert("É necessário digitar seu nome.");
		theform.nomealuno.focus();
		window.event.returnValue = false;
	}
	else if(theform.matricula.value.length == 0)
	{
		alert("É necessário digitar sua matrícula.");
		theform.matricula.focus();
		window.event.returnValue = false;
	}
	else if(theform.telefone.value.length == 0)
	{
		alert("É necessário digitar seu telefone.");
		theform.telefone.focus();
		window.event.returnValue = false;
	}
}

function contato(theform)
{
	// valida os dados da página Contato

	if(theform.msg.value.length == 0)
	{
		alert("Não há mensagem a ser enviada.");
		theform.msg.focus();
		window.event.returnValue = false;
	}
}

function allFormulas(bigform, amount, newIdx)
{
	// altera todos os combos de fórmulas

	for(var i=1; i<=amount; i++)
	{
		if(!bigform.elements["fcompos_" + i].disabled)
			bigform.elements["fcompos_" + i].selectedIndex = newIdx;
	}

	bigform.submit();
}

function tabsux(idx)
{
	// retira o foco do link no tab

	try {
		document.forms["formNotas"].elements["nota01_" + idx].focus();
		window.status = "Concluído";
	}
	catch(Exception) { }
}

function entersux(txbx)
{
	// ???
}

function notasnotas(amount)
{
	// valida os dados das planilha de notas

	var j, thebox;
	var theform = document.forms["formNotas"];

	for(var i=1; i<=amount; i++)
	{
		for(j=1; j<10; j++)
		{
			try
			{
				thebox = theform.elements["nota0" + j + "_" + i];

				if(!isFloat(thebox.value))
				{
					alert("O campo das notas deve conter apenas números.");
					thebox.focus();
					thebox.select();
					window.event.returnValue = false;
					return;
				}
				else if(parseFloat(thebox.value) > 10)
				{
					alert("Não é possível a atribuição de uma nota superior a 10.");
					thebox.focus();
					thebox.select();
					window.event.returnValue = false;
					return;
				}
			}
			catch(Exception)
			{
				break;
			}
		}

		thebox = theform.elements["faltas_" + i];

		if(!isNumber(thebox.value))
		{
			alert("O campo das faltas deve conter apenas números.");
			thebox.focus();
			thebox.select();
			window.event.returnValue = false;
			break;
		}
	}

	theform.submit();
}

function printOpen(url)
{
	// abre janela de impressão
	window.open(url, null, "width=680,height=450,menubar=yes,directories=no,location=no,resizable=no,toolbar=yes,scrollbars=yes");
}
