var ultimo_menu=new Object();
var anoCorrente = new Date().getFullYear();
var NNx = document.getElementById?1:0;
var IEx = document.all?1:0;
var sql;
var xmlHttp;

function Bisexto(ano) {
	if (ano % 4 == 0)
		return true;
	return false;
}

function DiasMes(mes, ano) {
	var ar = new Array(12);
	ar[0] = 31; // Janeiro
	ar[1] = (Bisexto(ano)) ? 29 : 28; // Fevereiro
	ar[2] = 31; // Março
	ar[3] = 30; // Abril
	ar[4] = 31; // Maio
	ar[5] = 30; // Junnho
	ar[6] = 31; // Julho
	ar[7] = 31; // Agosto
	ar[8] = 30; // Setembro
	ar[9] = 31; // Outubro
	ar[10] = 30; // Novembro
	ar[11] = 31; // Dezembro
	return ar[mes];
}

function VerificaDataInteira(campo,tipoData,proximoCampo) {	
	var vCampo = campo.value;
	if (vCampo.length == 10) {
		var eData = /^((0[1-9]|[12]\d)\/(0[1-9]|1[0-2])|30\/(0[13-9]|1[0-2])|31\/(0[13578]|1[02]))\/19\d{2}$/;
		var eDataExp = /^((0[1-9]|[12]\d)\/(0[1-9]|1[0-2])|30\/(0[13-9]|1[0-2])|31\/(0[13578]|1[02]))\/[12][0-9]{3}$/;
		if(tipoData == 'nasc')
			if( !eData.test(vCampo) ) {
				alert("A data informada é inválida, deve estar no formato DD/MM/19AA");
				campo.value="";
				campo.focus();
				return;
			}
		if(tipoData == 'exp')
			if( !eDataExp.test(vCampo) ) {
				alert("A data informada é inválida, deve estar no formato DD/MM/AAAA");
				campo.value="";
				campo.focus();
				return;
			}
		var vAno = parseInt(vCampo.substr(6,4));
		if(tipoData == 'nasc') {
			var idademinima=15;
			var idademaxima=80;
			if(vAno+idademinima > anoCorrente){
				alert("Você não pode ter menos do que " + idademinima + " anos.");
				campo.value="";
				campo.focus();
				return;
			}
			if(vAno+idademaxima < anoCorrente){
				alert("Você não pode ter mais do que " + idademaxima + " anos.");
				campo.value="";
				campo.focus();
				return;
			}
		}
		if(tipoData == 'exp') {
			if(vAno < 1900 || vAno > anoCorrente){
				alert("Verifique a data digitada no campo Data de Expedição.");
				campo.value="";
				campo.focus();
				return;
			}
		}
		//Se chegou até o fim sem dar erro, a data está correta. Pula para o próximo campo
		proximoCampo.focus();
	}
}

function VerificaDataSeparada(objetodia,objetomes,objetoano,idademinima,idademaxima,anoLimite,mesLimite,diaLimite) {
	var data = new Date(anoLimite,mesLimite,diaLimite);
	var dia = objetodia.value;
	var mes = objetomes.value;
	var ano = "19" + objetoano.value;
	var diasnomes = DiasMes(mes-1,ano);
	
	if ( dia != "" && mes != "" && ano != "19" ) {
		if ( (!isNaN(dia)) || (!isNaN(mes)) || (!isNaN(ano)) ) {
			if ( eval(mes) >= 1 && eval(mes) <= 12 ) { // verifica mes valido
				if ( dia >= 1 && dia <= diasnomes ) {  // verifica se mes tem o numero de dias correto.
					if ( eval(ano) > (anoLimite - idademaxima) ) {  // verifica maior que idade máxima
						if ( eval(ano) > (anoLimite - idademinima) ) { // verifica menor que idade mínima ( Com o ano/mes )
							alert('A idade mínima para inscrição é ' + idademinima + ' anos.' );
							objetoano.value="";
							objetoano.focus();
						}
						else {
							if ( eval(ano) == (anoLimite - idademinima) ) { // verifica menor que idade minima ( Com o ano/mes )
								if ( eval(mes) > data.getMonth()+1 ) {
									alert('A idade mínima para inscrição é ' + idademinima + ' anos.');
									objetomes.value="";
									objetomes.focus();
								}
								else {
									if ( eval(mes) == data.getMonth()+1 ) {
										if ( eval(dia) > data.getDate() ) {
											alert('A idade mínima para inscrição é ' + idademinima + ' anos.');
											objetodia.value="";
											objetodia.focus();
										}
									}
								}
							}
						}
					}
					else {
						alertadata=objetodia.value + "/" + objetomes.value + "/19" + objetoano.value;
						alert('Lembre-se que você esta digitando a data de nascimento\ne pelos cálculos você tem mais de ' + idademaxima + ' anos.\nVerifique se esta data esta correta!\t' + alertadata);
						objetoano.value="";
						objetoano.focus();
					}
				}				
				else { //-> o mes nao tem o numero de dias correto.
					alert('O dia relativo ao mes/ano ( ' + mes + '/' + ano + ' ) deve estar entre ( 01 e ' + diasnomes + ' )' );
					objetodia.value="";
					objetodia.focus();
				}
			}
			else { // o mes nao e valido
				alert('O mês deve estar no intervalo 01 a 12');
				objetomes.value="";
				objetomes.focus();
			}
		}
		else {
			alert('Campos da Data devem ser numéricos');
			objetodia.value="";
			objetomes.value="";
			objetoano.value="";
			objetodia.focus();
		}
	}
}

function VerificaDataExpedicao(objetodia,objetomes,objetoano) {
	var dia=objetodia.value;
	var mes=objetomes.value;
	var ano=objetoano.value;
	var diasnomes=DiasMes(mes-1,ano);

	if ( dia != "" && mes != "" && ano != "" ) {
		if ( (!isNaN(dia)) || (!isNaN(mes)) || (!isNaN(ano)) ) {
			if ( eval(mes) >= 1 && eval(mes) <= 12 ) { // verifica mes valido
	  			if ( dia >= 1 && dia <= diasnomes ) { // verifica se mes tem o numero de dias correto.
		   			if ( eval(ano) <= 1900 ) {  // ano precisa ser com 4 dígitos
						alertadata=objetodia.value + "/" + objetomes.value + "/" + objetoano.value;
						alert('Use 4 dígitos no ano da data de expedição do documento de identidade. Você digitou ' + alertadata);
						objetoano.value="";
						objetoano.focus();
					}
				}				
				else {//-> o mes nao tem o numero de dias correto.
					alert('O dia relativo ao mês/ano ( ' + mes + '/' + ano + ' ) deve estar entre ( 01 e ' + diasnomes + ' )' );
					objetodia.value="";
					objetodia.focus();
				}
			}
			else { // o mes nao e valido
				alert('O mês deve estar no intervalo 01 a 12');
				objetomes.value="";
				objetomes.focus();
			}
		}
		else {
			alert('Campos da Data devem ser numéricos');
			objetodia.value="";
			objetomes.value="";
			objetoano.value="";
			objetodia.focus();
		}
	}
}


function AcertaEmail() {
	var objeto=eval("document.FormInscricao.Email");
	var valor=objeto.value.toLowerCase();
	objeto.value=valor;
	var erro="";
				  
	if ( valor.indexOf("@") == -1 )	{
		erro="Verifique seu E-mail, esta faltando o caracter @";
	}
	else {
		var novovalor=valor.substr(valor.indexOf("@")+1);
		if ( novovalor.indexOf("@") > -1 ) {
			erro="Verifique seu E-mail, tem mais de um caracter @";
		}
		else {
			if ( valor.indexOf(" ") > -1 ) {
				erro="Verifique seu E-mail, não pode haver caracter espaço";
			}
			else {
				if ( valor.indexOf(".") == -1 ) {
					erro="Verifique seu E-mail, não contém caracter ponto";
				}
				else {
					if ( valor.substr(valor.length-1) == "." ) {
						erro="Verifique seu E-mail, o último caracter não pode ser ponto";
					}
					else {
						if ( valor.substr(0,4) == "www." ) {
							erro="Verifique seu E-mail, os primeiros caracteres não podem ser 'www.' ";
						}
					}
				}
			}
		}
	}
	if ( erro != 0 ) { 
		objeto.focus();
		alert(erro);
	}
}

function TextoMaiusculo(campo)
{
	var objeto=eval("window.document.FormInscricao." + campo);
	var valor=objeto.value.toUpperCase();
	objeto.value=valor;
}

function AcertaTexto(campo,espacos,tipo,esp)
{
	var objeto=eval("window.document.FormInscricao." + campo);
	var valor=objeto.value.toLowerCase();
	var aux="",letra="";
	
	if ( tipo == "AN" )
	{
		for (var i=0;i<=valor.length-1;i++)
		{
			if ( ( valor.charCodeAt(i) == 32 ) || ( valor.charCodeAt(i) == 39 ) || ( valor.charCodeAt(i) >96 && valor.charCodeAt(i) <123 ) || ( valor.charCodeAt(i) >64 && valor.charCodeAt(i) <91 ) || ( valor.charCodeAt(i) >191 && valor.charCodeAt(i) < 256 ) || ( valor.charCodeAt(i) > 47 && valor.charCodeAt(i) < 58 ))
			{
			  aux=aux+valor.charAt(i);
			}
		}
	valor=aux;
	aux="";
	}
	
	if ( tipo == "A" ){
		for (var i=0;i<=valor.length-1;i++){
			if((valor.charCodeAt(i) == 45) && (valor.substr(0,7) == "ben-hur")){
				aux=aux+valor.charAt(i);
			}
			else{
				if ( ( valor.charCodeAt(i) == 32 ) || ( valor.charCodeAt(i) == 39 ) || ( valor.charCodeAt(i) >96 && valor.charCodeAt(i) <123 ) || ( valor.charCodeAt(i) >64 && valor.charCodeAt(i) <91 ) || ( valor.charCodeAt(i) >191 && valor.charCodeAt(i) < 256 ) ){
				aux=aux+valor.charAt(i);
			}
		}
	}
	valor=aux;
	aux="";
	}
	
	for (var i=0;i<=valor.length-1;i++)
	{
		if (valor.charAt(i) != " ")
		{
			if ( (i==0) || (valor.charAt(i-1) == " ") || ( valor.charAt(i-1) == "'" ) || (valor.charAt(i-1) == "-") )
			{
				if ( ( valor.substr(i-1,3) != " e " && valor.substr(i-1,4) != " da " && valor.substr(i-1,4) != " de " &&  valor.substr(i-1,7) != " xxiii " && valor.substr(i-1,4) != " di " && valor.substr(i-1,4) != " do "  &&  valor.substr(i-1,5) != " dos " && valor.substr(i-1,5) != " das " ) || ( valor.charAt(i-1) == "'" ) )
				{
					aux=aux+valor.charAt(i).toUpperCase();
				}
				else
				{
					aux=aux+valor.charAt(i);
				}             
			}
			else
			{
				aux=aux+valor.charAt(i);
			}
		}
		else
		{
			if (valor.charAt(i+1) != " ")
			{
				aux=aux+valor.charAt(i);
			}
		}
	}
	
	valor=aux;
	aux="";
		
	if ( valor.charAt(0) == " " )
	{
		aux=valor.substr(1,valor.length);
		valor=aux;
	}
	if ( valor.charAt(valor.length-1) == " " )
	{
		aux=valor.substr(0,valor.length-1);
		valor=aux;
	}	 
	if(valor.length == 0) {
		if(campo == 'NomedoCandidato') {
			alert("Informe o Nome do Candidato");			
			objeto.focus();
			objeto.select();
		}
	}
	else {
		if ( valor.indexOf(" ") < espacos)
		{
			alert("O "+ campo + " deve ter no mínimo 2 palavras.");
			if (esp == 1)
			{
				objeto.focus();
				objeto.select();
			}
		}
		else
		{
			objeto.value=valor;
		}
	}
} 

function validacaoNome(nome){
	var nomeAux = nome.toUpperCase();
	var tam = nomeAux.length;
	var aux = 0;
	var contTrue = 0;
	var contFalse = 0;
	var car;
	while(aux < tam){
		car = nomeAux.charCodeAt(aux);
		if((car == 32) || (car == 39) || ((car >= 65) && (car <= 90)) || (car == 45) || ((car >= 192) && (car <= 195)) || ((car >= 199) && (car <= 207)) || ((car >= 209) && (car <= 214)) || ((car >= 217) && (car <= 220))){
			contTrue++;
		}
		else{
			contFalse++;
		}
		aux++;
	}
	if(contFalse != 0){
		return false;
	}
	else{
		return true;
	}
}

function mudoucampo(campo)
{
var campocompara;
if ( document.layers )
   {
   campocompara=eval("window.document.FormInscricao.h" + campo );
   }
   
if ( document.all )
   {
   campocompara=eval("window.document.FormInscricao.h" + campo + ".value");
   }
var campoalterado=eval("window.document.FormInscricao." + campo)
var cepok=eval("window.document.FormInscricao.CEP.value")

if ( cepok.length == 8 && campoalterado.value == campocompara )
   { 
   alert('Este campo foi incluído pelo CEP e não deveria ser alterado.\nVerifique o CEP e se necessário, faça a alteração.');
   campoalterado.focus();
   }
}   

function Esconde() {
	ultimo_menu.visibility="hidden";
}
// depreciado
function ColdTip(campo) {
	this.css.visibility='hidden';		
}

function HotTip(divTip) {
	this.css=document.getElementById(divTip).style;
	this.css.visibility='visible';		
	ultimo_menu=this.css;		
}

function press(t1,t2,tam) {    
	if (t1.value.length==tam)
		t2.focus();
}

function Numerico(event) {
    Tecla = event.which;
    if(Tecla == null)
    Tecla = event.keyCode;

    if(Tecla >57 || (Tecla > 32 && Tecla < 48))
        return false;
    return true;
}

function Duvidas() {
	window.open("CV_DUVIDAS.HTM","","dependent=true,width=700,height=450,scrollbars=1,toolbar=1,location=0,status=0,menubar=0,resizable=1");
}

function VerificaDigMatri() {
 	var objeto=eval("document.FormInscricao.NrMatricula");
	var objeto1=eval("document.FormInscricao.BarraMatricula");
	var objeto2=eval("document.FormInscricao.DigMatricula");
	
	var objeto=objeto.value;
	var objeto1=objeto1.value;
	var objeto2=objeto2.value;
	
	var N1 = parseInt(objeto1.substr(0,1));	
	var N2 = parseInt(objeto1.substr(1,1));
	var N3 = parseInt(objeto.substr(0,1));
	var N4 = parseInt(objeto.substr(1,1));
	var N5 = parseInt(objeto.substr(2,1));
	var N6 = parseInt(objeto.substr(3,1));
	var N7 = parseInt(objeto2.substr(0,1));
	
	var SomaMat = (N1 * 7) + (N2 * 6) + (N3 * 5) + (N4 * 4) + (N5 * 3) + (N6 * 2);
	var Temp = 11 - (SomaMat - (parseInt(SomaMat/11) * 11));
	var Digito = Temp - (parseInt(Temp/11) * 11);
	if (Digito == 10) {
	 	Digito = 0;
	}	
	else { 
		Digito = Digito - (parseInt(Digito/10) * 10);
	}
	if (Digito == N7) 
	{
		document.forms[0].Opcao1.focus();
	}
	else
	{
		alert('         A matrícula está incorreta! \n \n  Obs: Se você é ou foi aluno de graduação da UFRGS \n           e não lembra da sua matrícula, assinale  \n           o campo 7 e deixe o campo 8 em branco.');
		document.forms[0].NrMatricula.value = '';
		document.forms[0].BarraMatricula.value = '';
		document.forms[0].DigMatricula.value = '';
		document.forms[0].NrMatricula.focus();
	}

}

function VerificaNome(campo){
	var objeto=eval("document.FormInscricao."+campo);
	var resto=objeto.value;	
	if (resto != " "){	
		for (var i=1;i<=resto.length-1;i++){
			if (i == 1){ 
				if (resto.charCodeAt(i) == 32){
					alert('A primeira palavra não pode conter apenas uma letra! \n\n Obs: Lembre-se de não usar abreviaturas no nome.');objeto.focus();objeto.select(); return;
				}
			}
			else{
				if (i == resto.length-1){
					if (resto.charCodeAt(i-1) == 32){
						alert('A última palavra não pode conter apenas uma letra! \n\n Obs: Lembre-se de não usar abreviaturas no nome.');objeto.focus();objeto.select(); return;
					}
				}
				else{
					if ((resto.charCodeAt(i-1) == 32) && (resto.charCodeAt(i+1) == 32) && (resto.charCodeAt(i) != 101)){
						alert('Não use abreviaturas no nome.');objeto.focus();objeto.select(); return;
					}
	  			}
			}
		}
	}
}

function AcertaIdentidade(campo){
	var contLetras=0;
	var contHifens=0;
	var objeto=eval("window.document.FormInscricao." + campo);
	var valor=objeto.value.toLowerCase();
	var aux="",letra="";
	for (var i=0;i<=valor.length-1;i++){
		if ((valor.charCodeAt(i) >96 && valor.charCodeAt(i) <123) || (valor.charCodeAt(i) >64 && valor.charCodeAt(i) <91) || (valor.charCodeAt(i) > 44 && valor.charCodeAt(i) < 58)){
			  aux=aux+valor.charAt(i);
		}
		if((valor.charCodeAt(i) > 96) && (valor.charCodeAt(i) < 123)){//se for letra, até 3 serão toleradas.
			contLetras++;
		}
		if(valor.charCodeAt(i) == 45){//se for hifen, somente 1 será tolerado.
			contHifens++;
		}
	}
	
	if(contLetras > 3){
		alert('Máximo permitido: 3 letras no documento de identidade.');
		document.FormInscricao.DocumentoIdentidade.value="";
		document.FormInscricao.DocumentoIdentidade.focus();
		return;
	}

	if(contHifens > 1){
		alert('Máximo permitido: 1 hífen no documento de identidade.');
		document.FormInscricao.DocumentoIdentidade.value="";
		document.FormInscricao.DocumentoIdentidade.focus();
		return;
	}
	
	valor=aux;
	aux="";
	var ID=valor.toUpperCase();
	document.FormInscricao.DocumentoIdentidade.value=ID;
}

function AcertaOrgao(campo){
	var objeto=eval("window.document.FormInscricao." + campo);
	var valor=objeto.value.toUpperCase();
	var ID=valor.toUpperCase();
	document.FormInscricao.OrgaoExp.value=ID;
}

function AcertaUF(){
	var UF = document.FormInscricao.UF.value.toUpperCase();
	document.FormInscricao.UF.value=UF;
}


function ConfereTelefone(){
	var ddd = document.FormInscricao.DDD.value;
	var tel = document.FormInscricao.Telefone.value;
	if((tel == "") && (ddd != "")){
		alert("Preencha o campo de telefone.");
		document.FormInscricao.Telefone.focus();
	}
	if((tel != "") && (ddd == "")){
		alert("Será assumido DDD = 0xx51. \nCaso queira, você pode alterá-lo.");
	}
}

//Busca o endereço a partir do CEP
function BuscaEndereco(sqlin,param,servidor) {
	var url;
	if ( param=='' ) { 
		alert('CEP inválido ou faltante. Digite novamente o CEP.');
		return false;
	}
	else {
		param=parseInt(param);
	}
	sql=sqlin;
	try {
		ajax = new ActiveXObject("Microsoft.XMLHTTP");
	}
	catch(e) {
		try {
			ajax = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(ex) {
			try {
				ajax = new XMLHttpRequest();
			}
			catch(exc) {
				alert("Esse browser nao tem recursos para uso do Ajax");
				ajax  = null;
			}
		}
	}
	if( ajax ) {
		//
		// O (client.php) deve ter a mesma origem do form default.php
		// ex.:  esta chamada abaixo somente é executada se for originada por 'http://www1.ufrgs.br/'
		//
		if (servidor == 'ANUBIS')
			url = "http://anubis/webservices/client.php";
		else
			url = "http://www1.ufrgs.br/webservices/client.php";
		ajax.open("POST", url, true);
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.onreadystatechange = function() {
			if(ajax.readyState == 4 ) { 
				if(ajax.responseXML) { 
					processXMLusuario(ajax.responseXML);
				}
				else {
					alert("Documento nao é tipo XML");
					return false;
				}
			}
		}
		var params = "sql="+sql+"&param="+param;
		ajax.send(params);
	}
}

function processXMLusuario(obj){
	var nomecampo = document.FormInscricao;
	nomecampo.UF.value    ="";
	nomecampo.Cidade.value="";
	nomecampo.Logradouro.value="";
	nomecampo.Bairro.value="";
	
	var dataXML = obj.getElementsByTagName(sql);
	var Campos  = new Array();
	if(dataXML.length > 0) {
		var x=dataXML[0].childNodes;
		var c=0;
		for (i=0;i<x.length;i++) {
			if (x.item(i).nodeType==1) { 
				c++;
				Campos[c]=x.item(i).nodeName;
			}
		}
		for(var i=0; i<dataXML.length; i++) {
			var item = dataXML[i];
			for(var u=1; u<Campos.length; u++) {
				eval('var '+Campos[u]+'=item.getElementsByTagName("'+Campos[u]+'")[0].firstChild.nodeValue;');
				valor=(eval(Campos[u])=='*')? '' : eval(Campos[u]);
				eval("document.FormInscricao."+Campos[u]+".value='"+valor+"';");
			}
		}
	}
	else { 
		nomecampo.UF.value    ="";
		nomecampo.Cidade.value="";
		nomecampo.Logradouro.value="";
		nomecampo.Bairro.value="";
		alert("CEP inválido, por favor digite novamente."); 
		setTimeout("document.FormInscricao.CEP.focus()",1);
   }
}

function CursoOrigem(){
   var opcao=window.document.FormInscricao.Opcao1.value;
   parent.CurOrigem.location='../../includes/Curso_origem.php?opcao=' + opcao
   window.focus();
   return false;
}

function VerificaCodPessoa(){
   var CodPessoa=window.document.FormInscricao.CodPessoa.value;
   parent.VerifPessoa.location='../../includes/CodPessoa.php?CodPessoa=' + CodPessoa
   window.focus();
   return false;
}

function VerificaCartaoVest(){
   var CodPessoa=window.document.FormInscricao.CodPessoa.value;
   if((CodPessoa > 99999999) && (CodPessoa < 00000001)){ // ????
		alert ("Valor inválido para o Número do Cartão UFRGS.");
		window.document.FormInscricao.CodPessoa.focus();
		return false;
   }
}

//Usada??
function VerificaIdioma()
{

	var valor1 = window.document.FormInscricao.Opcao1.options[document.FormInscricao.Opcao1.selectedIndex].value;
	var valor2 = window.document.FormInscricao.Opcao1A.options[document.FormInscricao.Opcao1A.selectedIndex].value;
/*    var valor3 = window.document.FormInscricao.Opcao2.options[document.FormInscricao.Opcao2.selectedIndex].value;
    var valor4 = window.document.FormInscricao.Opcao2A.options[document.FormInscricao.Opcao2A.selectedIndex].value;*/
		
    if (valor1 == 94 || valor1 == 280 || valor1 == 302 || valor1 == 345 || valor1 == 353 || valor1 == 507 || valor1 == 515 || valor1 == 540 || 
			  valor2 == 94 || valor2 == 280 || valor2 == 302 || valor2 == 345 || valor2 == 353 || valor2 == 507 || valor2 == 515 || valor2 == 540 ||
        valor3 == 94 || valor2 == 280 || valor2 == 302 || valor2 == 345 || valor2 == 353 || valor2 == 507 || valor2 == 515 || valor2 == 540 ||
        valor4 == 94 || valor2 == 280 || valor2 == 302 || valor2 == 345 || valor2 == 353 || valor2 == 507 || valor2 == 515 || valor2 == 540)
		{				
				document.FormInscricao.CodIdioma[0].disabled = true;
				document.FormInscricao.CodIdioma[1].disabled = true;
				document.FormInscricao.CodIdioma[2].disabled = true;
				document.FormInscricao.CodIdioma[3].disabled = false;
				document.FormInscricao.CodIdioma[4].disabled = true;
				document.FormInscricao.CodIdioma[3].checked = true;
		}
		else
		{
				document.FormInscricao.CodIdioma[0].disabled = false;
				document.FormInscricao.CodIdioma[1].disabled = false;
				document.FormInscricao.CodIdioma[2].disabled = false;
				document.FormInscricao.CodIdioma[3].disabled = false;
				document.FormInscricao.CodIdioma[4].disabled = false;
				document.FormInscricao.CodIdioma[3].checked = false;		 		
		}

		
}

function VerificaOpcaoAlter()
{
 var valor1 = window.document.FormInscricao.Opcao1A.options[document.FormInscricao.Opcao1A.selectedIndex].value.substr(0,window.document.FormInscricao.Opcao1A.options[document.FormInscricao.Opcao1A.selectedIndex].value.length-4);
// var valor2 = window.document.FormInscricao.Opcao2.options[document.FormInscricao.Opcao2.selectedIndex].value.substr(0,window.document.FormInscricao.Opcao2.options[document.FormInscricao.Opcao2.selectedIndex].value.length-4);
 var valor3 = window.document.FormInscricao.Opcao1.options[document.FormInscricao.Opcao1.selectedIndex].value.substr(0,window.document.FormInscricao.Opcao1.options[document.FormInscricao.Opcao1.selectedIndex].value.length-4);
 var espec1 = window.document.FormInscricao.Opcao1A.options[document.FormInscricao.Opcao1A.selectedIndex].value.substr(window.document.FormInscricao.Opcao1A.options[document.FormInscricao.Opcao1A.selectedIndex].value.length-3,1);
// var espec2 = window.document.FormInscricao.Opcao2.options[document.FormInscricao.Opcao2.selectedIndex].value.substr(window.document.FormInscricao.Opcao2.options[document.FormInscricao.Opcao2.selectedIndex].value.length-3,1);
 var espec3 =  window.document.FormInscricao.Opcao1.options[document.FormInscricao.Opcao1.selectedIndex].value.substr(window.document.FormInscricao.Opcao1.options[document.FormInscricao.Opcao1.selectedIndex].value.length-3,1);
 
 if(valor1 == valor3)
           {
           alert('1ª Opção de curso e Alternativa para 1ª Opção de Curso, não podem ser iguais!! ')
           window.document.FormInscricao.Opcao1A.focus();
           }
 
 else if (espec1 =="S")
        {
/*			if(valor2 == ''){
		        alert("Lembre-se de que sua 2ª Opção de curso deverá ser igual \na sua Alternativa de 1ª opção!" );
    		    window.document.FormInscricao.Opcao2.focus();
			}
			else if(valor2 != valor1){
		        alert("Esta alternativa não é válida. O curso selecionado exige \nprova específica e não é igual a sua 2ª Opção de curso" );
    		    window.document.FormInscricao.Opcao1A.focus();
			}*/
        }
    
 }
 

function apenasDigitos(event){
	if (window.event) {
		key = event.keyCode;
	}
	else if ( event.which ) {
		key = event.which;
	}
	if ( key != 8 || key < 48 || key > 57 )
		return ( ( ( key > 47 ) && ( key < 58 ) ) || ( key == 8 ) );
	return true;
}

function MascaraData(campo, teclaPress) {
	if (window.event) {
		var tecla = teclaPress.keyCode;
	}
	else {
		tecla = teclaPress.which;
	}

	var s = new String(campo.value);
	// Remove todos os caracteres a seguir: ( ) / - . e espaço, para tratar a string de novo.
	s = s.replace(/(\.|\(|\)|\/|\-| )+/g,'');

	tam = s.length + 1;

	if ( tecla != 9 && tecla != 8 ) {
		if (tam > 2 && tam < 5)
			campo.value = s.substr(0,2) + '/' + s.substr(2, tam);
		if (tam >= 5 && tam < 10)
			campo.value = s.substr(0,2) + '/' + s.substr(2,2) + '/' + s.substr(4,tam-4);
	}
}

function MascaraCPF(campo, teclaPress) {
	if (window.event) {
		var tecla = teclaPress.keyCode;
	}
	else {
		tecla = teclaPress.which;
	}
	var s = new String(campo.value);
	// Remove todos os caracteres a seguir: ( ) / - . e espaço, para tratar a string de novo.
	s = s.replace(/(\.|\(|\)|\/|\-| )+/g,'');
	tam = s.length + 1;
	if ( tecla != 9 && tecla != 8 ) {
		if (tam > 3 && tam < 7)
			campo.value = s.substr(0,3) + '.' + s.substr(3, tam);
		if (tam >= 7 && tam < 10)
			campo.value = s.substr(0,3) + '.' + s.substr(3,3) + '.' + s.substr(6,tam-6);
		if (tam >= 10 && tam < 12)
			campo.value = s.substr(0,3) + '.' + s.substr(3,3) + '.' + s.substr(6,3) + '-' + s.substr(9,tam-9);
	}
}

function MascaraInscricao(campo, teclaPress,tamanho,qtdDV) {
	if (window.event)
		var tecla = teclaPress.keyCode;
	else
		tecla = teclaPress.which;
	var s = new String(campo.value);
	s = s.replace(/(\.|\(|\)|\/|\-| )+/g,'');
	tam = s.length;
	if ( tecla != 8 && tecla != 9 ) {
		if( tam > 0)
			campo.value = s.substr(0,tam - qtdDV) + "-" + s.substr(tam - qtdDV ,qtdDV);
	}
}

// Verifica se já tem alguém inscrito com esse CPF.
// Precisa de um arquivo php para fazer a verificação, que é recebido no parâmetro paginaVerificacao
function CPFUnico(cpf,paginaVerificacao){
	if(cpf.value != "") {
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null) {
			alert ("Não foi possível completar a operação. Atualize seu navegador.");
			return;
		}
	
		var strParam = "cpf=" + cpf.value;
		
		var url = paginaVerificacao;
		var campos = strParam;
	
		xmlHttp.onreadystatechange=stateChangedCPF;
		xmlHttp.open("POST",url,true);
		xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=iso-8859-1");
		xmlHttp.setRequestHeader("Content-length",campos.length);         
		xmlHttp.send(campos);
	}
}

function ValidadeCPF(cpf,proximoCampo){
	var retornoCPF = 1, cpfDigitos;
	if (cpf.value.length == 14){	
		cpfDigitos = new String(cpf.value);
		cpfDigitos = cpfDigitos.replace(/(\.|\-| )+/g,'');
		retornoCPF = VerificaCPF(cpfDigitos,0);
		if (retornoCPF == 1){
			alert("CPF inválido.");			
			cpf.value = "";						
			cpf.focus();			
		}
		else {
			if(proximoCampo != null)
				proximoCampo.focus();						
		}
	}
}

// retorna 1 para CPF errado e 0 para CPF correto
function VerificaCPF(cpf){
	var i;
	var dig;
	var pridig;
	var secdig;
	var aux;
	var soma = 0;	
	for(i=0;i<9;i++){
		dig = cpf.substr(i,1);
		aux = 10-i;
		soma = soma+(aux*dig);
	}
	pridig = 11 - (soma - ((parseInt(soma/11)) * 11));
	if(pridig > 9){
		pridig = 0;
	}
	soma = 0;
	for(i=0;i<9;i++){
		dig = cpf.substr(i,1);
		aux = 11-i;
		soma = soma+(aux*dig);
	}
	soma = soma + (2*pridig);
	secdig = 11 - (soma - ((parseInt(soma/11)) * 11));
	if(secdig > 9){
		secdig = 0;
	}
	if((pridig != cpf.substr(9,1)) || (secdig != cpf.substr(10,1)) || (cpf == "00000000000") || (cpf == "99999999999")){
		return 1;
	}
	return 0;
}

function VerificaIsencao(cpf, tam){
	if (cpf.value.length == tam){
		cpfDigitos = new String(cpf.value);
		cpfDigitos = cpfDigitos.replace(/(\.|\-| )+/g,'');
		parent.TestesCPF.location='verificacoes.php?cpf=' + cpfDigitos
		window.focus();
		return false;		
	}
}

function GetXmlHttpObject() {
	var xmlHttp=null;
	try {
		// Firefox, Opera 8.0+, Safari
			xmlHttp=new XMLHttpRequest();
		} catch (e) {
		//Internet Explorer
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

function stateChangedCPF() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
		if(xmlHttp.responseText == "ERRO_ISENTO"){
			alert("verifique o CPF informado, pois já existe uma solicitação com o mesmo");
			window.document.getElementById('CPF').value = "";
			window.document.getElementById('CPF').focus();
			return;
		}
		if(xmlHttp.responseText == "OK_ISENTO"){
			window.document.FormInscricao.Sexo.focus();
			return;
		}
	}
}
