function avanca(){
	
	var tipo     = document.getElementById("tp");	
	var user     = document.getElementById("us");	
	
	if( (tipo.value == 1) && (user.value == 1) ){
		location.href="graacademico.php";
	} else 	if( (tipo.value == 1) && (user.value == 2) ){
		location.href="graprofessor.php";
	} else 	if( (tipo.value == 1) && (user.value == 3) ){
		location.href="gracoordenador.php";
	} else 	if( (tipo.value == 2) && (user.value == 1) ){
		location.href="posacademico.php";
	} else 	if( (tipo.value == 2) && (user.value == 2) ){
		location.href="posprofessor.php";
	} else 	if( (tipo.value == 2) && (user.value == 3) ){
		location.href="poscoordenador.php";
	} else {
		return false;
	}
}






/*
* GRADUAÇÃO
*/
/* 
* ACADEMICO
*/
function verificarAcademicoGra() {
	var cpf       = document.getElementById("edtcpf");
	var matricula = document.getElementById("edtmatricula");
	var ajax      = createRequest();
	var obj       = document.getElementById("status");
	
	if (!validaCPF(cpf.value)) {
		alert("O \"CPF\" informado é inválido!");
		cpf.focus();
	} else if (Trim(matricula.value) == "") {
		alert("Campo \"MATRÍCULA\" não informado!");
		matricula.focus();
	} else {
		ajax.open("POST", "graacademico_action.php", true); // requisição assíncrona
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send("acao=verificar&cpf="+escape(cpf.value)+"&matricula="+escape(matricula.value));
		
		obj.innerHTML = "aguarde...";
		
		ajax.onreadystatechange = function() {
			if (ajax.readyState == 4) {
				if (ajax.status == 200) {
					var retorno  = ajax.responseText.split("*");
					
					if (retorno[0] == "0") {
						document.getElementById("email").setAttribute("disabled", true);
						document.getElementById("email").className = "t0";
					} else {
						document.getElementById("cpf").value       = cpf.value;
						document.getElementById("matricula").value = matricula.value;
						
						document.getElementById("email").removeAttribute("disabled");
						document.getElementById("email").className = "t1 obrig";
						document.getElementById("email").focus();
					}
					
					document.getElementById("codusuario").value = retorno[0];
					obj.innerHTML = retorno[1];
				} else {
					alert("ERRO "+ajax.status);
				}
			}
		}
	}
}


function validarAcademicoGra() {
	var codusuario = document.getElementById("codusuario").value;
	var matricula  = document.getElementById("edtmatricula").value;
	var cpf        = document.getElementById("edtcpf").value;
	var email      = document.getElementById("email");
	
	if (codusuario == "0") {
		alert("As informações de matrícula devem ser validadas!");
		return false;
	} else if (!checkMail(email.value)) {
		alert("O \"EMAIL\" informado é inválido!");
		email.focus();
		return false;
	} else {
		if (confirm("Confirma as informações cedidas para o cadastro?")) {
			return true;
		} else {
			return false;
		}
	}
}


/*
* PROFESSOR
*/
function verificarProfessorGra() {
	var cpf        = document.getElementById("edtcpf");
	var nascimento = document.getElementById("edtnascimento");
	var ajax       = createRequest();
	var obj        = document.getElementById("status");
	var obj2       = document.getElementById("status2");
	
	if (!validaData(nascimento.value)) {
		alert("A \"DATA DE NASCIMENTO\" informada é inválida!");
		nascimento.focus();
	} else if (!validaCPF(cpf.value)) {
		alert("O \"CPF\" informado é inválido!");
		cpf.focus();
	} else {
		ajax.open("POST", "graprofessor_action.php", true); // requisição assíncrona
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send("acao=verificar&cpf="+escape(cpf.value)+"&nascimento="+escape(nascimento.value));
		
		obj.innerHTML  = "aguarde...";
		obj2.innerHTML = "";
		
		ajax.onreadystatechange = function() {
			if (ajax.readyState == 4) {
				if (ajax.status == 200) {
					var retorno = ajax.responseText.split("*");
					
					if (retorno[0] == "0") {
						if (document.getElementById("loginValido").value == 0) {
							document.getElementById("edtnovologin").setAttribute("disabled", true);
							document.getElementById("edtnovologin").className = "t0";
							
							document.getElementById("email").setAttribute("disabled", true);
							document.getElementById("email").className = "t0";
						}
					} else {
						document.getElementById("cpf").value        = cpf.value;
						document.getElementById("nascimento").value = nascimento.value;
						
						document.getElementById("edtnovologin").removeAttribute("disabled");
						document.getElementById("edtnovologin").className = "t1 obrig";
						
						if (document.getElementById("loginValido").value == 0) {
							document.getElementById("email").removeAttribute("disabled");
							document.getElementById("email").className = "t1 obrig";
						}
						
						document.getElementById("edtnovologin").focus();
					}
					
					document.getElementById("codusuario").value = retorno[0];
					obj.innerHTML = retorno[1];
				} else {
					alert("ERRO "+ajax.status);
				}
			}
		}
	}
}


function verificarLoginProfessorGra() {
	var login = document.getElementById("edtnovologin");
	var ajax  = createRequest();
	var obj   = document.getElementById("status2");
	
	if (Trim(login.value) == "") {
		alert("Informe o \"LOGIN\" para validação!");
		login.focus();
	} else {
		ajax.open("POST", "graprofessor_action.php", true); // requisição assíncrona
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send("acao=login&login="+escape(login.value));
		
		obj.innerHTML = "aguarde...";
		
		ajax.onreadystatechange = function() {
			if (ajax.readyState == 4) {
				if (ajax.status == 200) {
					var retorno = ajax.responseText.split("*");
					
					if (retorno[0] == "0") {
						document.getElementById("login").value = "";
						
						document.getElementById("email").setAttribute("disabled", true);
						document.getElementById("email").className = "t0";
						
						document.getElementById("edtnovologin").focus();
					} else {
						document.getElementById("login").value = login.value;
						
						document.getElementById("email").removeAttribute("disabled");
						document.getElementById("email").className = "t1 obrig";
						
						document.getElementById("email").focus();
					}
					
					document.getElementById("loginValido").value = retorno[0];
					obj.innerHTML = retorno[1];
				} else {
					alert("ERRO "+ajax.status);
				}
			}
		}
	}
}


function validarProfessorGra() {
	var codusuario = document.getElementById("codusuario").value;
	var valido     = document.getElementById("loginValido").value;
	var email      = document.getElementById("email");
	
	if (codusuario == 0) {
		alert("Seu cadastro não foi validado. Clique em \"Verificar cadastro\" para validar!");
		document.getElementById("edtcpf").focus();
		return false;
	} else if (valido == 0) {
		alert("O login não foi verificado. Clique em \"Verificar disponibilidade\" para verificar!");
		document.getElementById("edtnovologin").focus();
		return false;
	} else if (!checkMail(email.value)) {
		alert("O \"EMAIL\" informado é inválido!");
		email.focus();
		return false;
	} else {
		if (confirm("Confirma os dados informados para cadastro?")) {
			return true;
		} else {
			return false;
		}
	}
}



/*
* COORDENADOR
*/
function verificarCoordenadorGra() {
	var cpf        = document.getElementById("edtcpf");
	var nascimento = document.getElementById("edtnascimento");
	var ajax       = createRequest();
	var obj        = document.getElementById("status");
	var obj2       = document.getElementById("status2");
	
	if (!validaData(nascimento.value)) {
		alert("A \"DATA DE NASCIMENTO\" informada é inválida!");
		nascimento.focus();
	} else if (!validaCPF(cpf.value)) {
		alert("O \"CPF\" informado é inválido!");
		cpf.focus();
	} else {
		ajax.open("POST", "gracoordenador_action.php", true); // requisição assíncrona
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send("acao=verificar&cpf="+escape(cpf.value)+"&nascimento="+escape(nascimento.value));
		
		obj.innerHTML  = "aguarde...";
		obj2.innerHTML = "";
		
		ajax.onreadystatechange = function() {
			if (ajax.readyState == 4) {
				if (ajax.status == 200) {
					var retorno  = ajax.responseText.split("*");
					
					if (retorno[0] == "0") {
						if (document.getElementById("loginValido").value == 0) {
							document.getElementById("edtnovologin").setAttribute("disabled", true);
							document.getElementById("edtnovologin").className = "t0";
							
							document.getElementById("email").setAttribute("disabled", true);
							document.getElementById("email").className = "t0";
						}
					} else {
						document.getElementById("cpf").value        = cpf.value;
						document.getElementById("nascimento").value = nascimento.value;
						
						document.getElementById("edtnovologin").removeAttribute("disabled");
						document.getElementById("edtnovologin").className = "t1 obrig";
						
						if (document.getElementById("loginValido").value == 0) {
							document.getElementById("email").removeAttribute("disabled");
							document.getElementById("email").className = "t1 obrig";
						}
						
						document.getElementById("edtnovologin").focus();
					}
					
					document.getElementById("codusuario").value = retorno[0];
					obj.innerHTML = retorno[1];
				} else {
					alert("ERRO "+ajax.status);
				}
			}
		}
	}
}


function verificarLoginCoordenadorGra() {
	var login = document.getElementById("edtnovologin");
	var ajax  = createRequest();
	var obj   = document.getElementById("status2");
	
	if (Trim(login.value) == "") {
		alert("Informe o \"LOGIN\" para validação!");
		login.focus();
	} else {
		ajax.open("POST", "gracoordenador_action.php", true); // requisição assíncrona
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send("acao=login&login="+escape(login.value));
		
		obj.innerHTML = "aguarde...";
		
		ajax.onreadystatechange = function() {
			if (ajax.readyState == 4) {
				if (ajax.status == 200) {
					var retorno = ajax.responseText.split("*");
					
					if (retorno[0] == "0") {
						document.getElementById("email").setAttribute("disabled", true);
						document.getElementById("email").className = "t0";
						
						document.getElementById("edtnovologin").focus();
					} else {
						document.getElementById("login").value = login.value;
						
						document.getElementById("email").removeAttribute("disabled");
						document.getElementById("email").className = "t1 obrig";
						
						document.getElementById("email").focus();
					}
					
					document.getElementById("loginValido").value = retorno[0];
					obj.innerHTML = retorno[1];
				} else {
					alert("ERRO "+ajax.status);
				}
			}
		}
	}
}


function validarCoordenadorGra() {
	var codusuario = document.getElementById("codusuario").value;
	var valido     = document.getElementById("loginValido").value;
	var email      = document.getElementById("email");
	
	if (codusuario == 0) {
		alert("Seu cadastro não foi validado. Clique em \"Verificar cadastro\" para validar!");
		document.getElementById("edtcpf").focus();
		return false;
	} else if (valido == 0) {
		alert("O login não foi verificado. Clique em \"Verificar disponibilidade\" para verificar!");
		document.getElementById("edtnovologin").focus();
		return false;
	} else if (!checkMail(email.value)) {
		alert("O \"EMAIL\" informado é inválido!");
		email.focus();
		return false;
	} else {
		if (confirm("Confirma os dados informados para cadastro?")) {
			return true;
		} else {
			return false;
		}
	}
}












/*
* POS - GRADUAÇÃO
*/
/* 
* ACADEMICO
*/
function verificarAcademicoPos() {
	var cpf       = document.getElementById("edtcpf");
	var matricula = document.getElementById("edtmatricula");
	var ajax      = createRequest();
	var obj       = document.getElementById("status");
	
	if (!validaCPF(cpf.value)) {
		alert("O \"CPF\" informado é inválido!");
		cpf.focus();
	} else if (Trim(matricula.value) == "") {
		alert("Campo \"MATRÍCULA\" não informado!");
		matricula.focus();
	} else {
		ajax.open("POST", "posacademico_action.php", true); // requisição assíncrona
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send("acao=verificar&cpf="+escape(cpf.value)+"&matricula="+escape(matricula.value));
		
		obj.innerHTML = "aguarde...";
		
		ajax.onreadystatechange = function() {
			if (ajax.readyState == 4) {
				if (ajax.status == 200) {
					var retorno  = ajax.responseText.split("*");
					
					if (retorno[0] == "0") {
						document.getElementById("email").setAttribute("disabled", true);
						document.getElementById("email").className = "t0";
					} else {
						document.getElementById("cpf").value       = cpf.value;
						document.getElementById("matricula").value = matricula.value;
						
						document.getElementById("email").removeAttribute("disabled");
						document.getElementById("email").className = "t1 obrig";
						document.getElementById("email").focus();
					}
					
					document.getElementById("codusuario").value = retorno[0];
					obj.innerHTML = retorno[1];
				} else {
					alert("ERRO "+ajax.status);
				}
			}
		}
	}
}


function validarAcademicoPos() {
	var codusuario = document.getElementById("codusuario").value;
	var matricula  = document.getElementById("edtmatricula").value;
	var cpf        = document.getElementById("edtcpf").value;
	var email      = document.getElementById("email");
	
	if (codusuario == "0") {
		alert("As informações de matrícula devem ser validadas!");
		return false;
	} else if (!checkMail(email.value)) {
		alert("O \"EMAIL\" informado é inválido!");
		email.focus();
		return false;
	} else {
		if (confirm("Confirma as informações cedidas para o cadastro?")) {
			return true;
		} else {
			return false;
		}
	}
}


/*
* PROFESSOR
*/
function verificarProfessorPos() {
	var cpf        = document.getElementById("edtcpf");
	var nascimento = document.getElementById("edtnascimento");
	var ajax       = createRequest();
	var obj        = document.getElementById("status");
	var obj2       = document.getElementById("status2");
	
	if (!validaData(nascimento.value)) {
		alert("A \"DATA DE NASCIMENTO\" informada é inválida!");
		nascimento.focus();
	} else if (!validaCPF(cpf.value)) {
		alert("O \"CPF\" informado é inválido!");
		cpf.focus();
	} else {
		ajax.open("POST", "posprofessor_action.php", true); // requisição assíncrona
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send("acao=verificar&cpf="+escape(cpf.value)+"&nascimento="+escape(nascimento.value));
		
		obj.innerHTML  = "aguarde...";
		obj2.innerHTML = "";
		
		ajax.onreadystatechange = function() {
			if (ajax.readyState == 4) {
				if (ajax.status == 200) {
					var retorno = ajax.responseText.split("*");
					
					if (retorno[0] == "0") {
						if (document.getElementById("loginValido").value == 0) {
							document.getElementById("edtnovologin").setAttribute("disabled", true);
							document.getElementById("edtnovologin").className = "t0";
							
							document.getElementById("email").setAttribute("disabled", true);
							document.getElementById("email").className = "t0";
						}
					} else {
						document.getElementById("cpf").value        = cpf.value;
						document.getElementById("nascimento").value = nascimento.value;
						
						document.getElementById("edtnovologin").removeAttribute("disabled");
						document.getElementById("edtnovologin").className = "t1 obrig";
						
						if (document.getElementById("loginValido").value == 0) {
							document.getElementById("email").removeAttribute("disabled");
							document.getElementById("email").className = "t1 obrig";
						}
						
						document.getElementById("edtnovologin").focus();
					}
					
					document.getElementById("codusuario").value = retorno[0];
					obj.innerHTML = retorno[1];
				} else {
					alert("ERRO "+ajax.status);
				}
			}
		}
	}
}


function verificarLoginProfessorPos() {
	var login = document.getElementById("edtnovologin");
	var ajax  = createRequest();
	var obj   = document.getElementById("status2");
	
	if (Trim(login.value) == "") {
		alert("Informe o \"LOGIN\" para validação!");
		login.focus();
	} else {
		ajax.open("POST", "posprofessor_action.php", true); // requisição assíncrona
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send("acao=login&login="+escape(login.value));
		
		obj.innerHTML = "aguarde...";
		
		ajax.onreadystatechange = function() {
			if (ajax.readyState == 4) {
				if (ajax.status == 200) {
					var retorno = ajax.responseText.split("*");
					
					if (retorno[0] == "0") {
						document.getElementById("login").value = "";
						
						document.getElementById("email").setAttribute("disabled", true);
						document.getElementById("email").className = "t0";
						
						document.getElementById("edtnovologin").focus();
					} else {
						document.getElementById("login").value = login.value;
						
						document.getElementById("email").removeAttribute("disabled");
						document.getElementById("email").className = "t1 obrig";
						
						document.getElementById("email").focus();
					}
					
					document.getElementById("loginValido").value = retorno[0];
					obj.innerHTML = retorno[1];
				} else {
					alert("ERRO "+ajax.status);
				}
			}
		}
	}
}


function validarProfessorPos() {
	var codusuario = document.getElementById("codusuario").value;
	var valido     = document.getElementById("loginValido").value;
	var email      = document.getElementById("email");
	
	if (codusuario == 0) {
		alert("Seu cadastro não foi validado. Clique em \"Verificar cadastro\" para validar!");
		document.getElementById("edtcpf").focus();
		return false;
	} else if (valido == 0) {
		alert("O login não foi verificado. Clique em \"Verificar disponibilidade\" para verificar!");
		document.getElementById("edtnovologin").focus();
		return false;
	} else if (!checkMail(email.value)) {
		alert("O \"EMAIL\" informado é inválido!");
		email.focus();
		return false;
	} else {
		if (confirm("Confirma os dados informados para cadastro?")) {
			return true;
		} else {
			return false;
		}
	}
}



/*
* COORDENADOR
*/
function verificarCoordenadorPos() {
	var cpf        = document.getElementById("edtcpf");
	var nascimento = document.getElementById("edtnascimento");
	var ajax       = createRequest();
	var obj        = document.getElementById("status");
	var obj2       = document.getElementById("status2");
	
	if (!validaData(nascimento.value)) {
		alert("A \"DATA DE NASCIMENTO\" informada é inválida!");
		nascimento.focus();
	} else if (!validaCPF(cpf.value)) {
		alert("O \"CPF\" informado é inválido!");
		cpf.focus();
	} else {
		ajax.open("POST", "poscoordenador_action.php", true); // requisição assíncrona
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send("acao=verificar&cpf="+escape(cpf.value)+"&nascimento="+escape(nascimento.value));
		
		obj.innerHTML  = "aguarde...";
		obj2.innerHTML = "";
		
		ajax.onreadystatechange = function() {
			if (ajax.readyState == 4) {
				if (ajax.status == 200) {
					var retorno  = ajax.responseText.split("*");
					
					if (retorno[0] == "0") {
						if (document.getElementById("loginValido").value == 0) {
							document.getElementById("edtnovologin").setAttribute("disabled", true);
							document.getElementById("edtnovologin").className = "t0";
							
							document.getElementById("email").setAttribute("disabled", true);
							document.getElementById("email").className = "t0";
						}
					} else {
						document.getElementById("cpf").value        = cpf.value;
						document.getElementById("nascimento").value = nascimento.value;
						
						document.getElementById("edtnovologin").removeAttribute("disabled");
						document.getElementById("edtnovologin").className = "t1 obrig";
						
						if (document.getElementById("loginValido").value == 0) {
							document.getElementById("email").removeAttribute("disabled");
							document.getElementById("email").className = "t1 obrig";
						}
						
						document.getElementById("edtnovologin").focus();
					}
					
					document.getElementById("codusuario").value = retorno[0];
					obj.innerHTML = retorno[1];
				} else {
					alert("ERRO "+ajax.status);
				}
			}
		}
	}
}


function verificarLoginCoordenadorPos() {
	var login = document.getElementById("edtnovologin");
	var ajax  = createRequest();
	var obj   = document.getElementById("status2");
	
	if (Trim(login.value) == "") {
		alert("Informe o \"LOGIN\" para validação!");
		login.focus();
	} else {
		ajax.open("POST", "poscoordenador_action.php", true); // requisição assíncrona
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send("acao=login&login="+escape(login.value));
		
		obj.innerHTML = "aguarde...";
		
		ajax.onreadystatechange = function() {
			if (ajax.readyState == 4) {
				if (ajax.status == 200) {
					var retorno = ajax.responseText.split("*");
					
					if (retorno[0] == "0") {
						document.getElementById("email").setAttribute("disabled", true);
						document.getElementById("email").className = "t0";
						
						document.getElementById("edtnovologin").focus();
					} else {
						document.getElementById("login").value = login.value;
						
						document.getElementById("email").removeAttribute("disabled");
						document.getElementById("email").className = "t1 obrig";
						
						document.getElementById("email").focus();
					}
					
					document.getElementById("loginValido").value = retorno[0];
					obj.innerHTML = retorno[1];
				} else {
					alert("ERRO "+ajax.status);
				}
			}
		}
	}
}


function validarCoordenadorPos() {
	var codusuario = document.getElementById("codusuario").value;
	var valido     = document.getElementById("loginValido").value;
	var email      = document.getElementById("email");
	
	if (codusuario == 0) {
		alert("Seu cadastro não foi validado. Clique em \"Verificar cadastro\" para validar!");
		document.getElementById("edtcpf").focus();
		return false;
	} else if (valido == 0) {
		alert("O login não foi verificado. Clique em \"Verificar disponibilidade\" para verificar!");
		document.getElementById("edtnovologin").focus();
		return false;
	} else if (!checkMail(email.value)) {
		alert("O \"EMAIL\" informado é inválido!");
		email.focus();
		return false;
	} else {
		if (confirm("Confirma os dados informados para cadastro?")) {
			return true;
		} else {
			return false;
		}
	}
}






















/*
*	ADMINISTRATIVO
*/ 
function validarAdm() {
	var retorno;
	var login = document.getElementById("login").value;
	var email = document.getElementById("email");
	
	var valores = new Array(new Array("nome", "vazio", "Campo \"NOME\" não preenchido!"),
							new Array("cpf", "cpf", "O \"CPF\" informado é inválido!"),
							new Array("endereco", "vazio", "Campo \"ENDEREÇO\" não preenchido!"),
							new Array("cidade", "vazio", "Campo \"CIDADE\" não preenchido!"),
							new Array("uf", "select0", "Selecione uma \"UF\" na caixa de seleção!"),
							new Array("cep", "cep", "Campo \"CEP\" inválido!"));
	
	retorno = validarCampos(valores);
	
	if ((retorno) && (Trim(login) == "")) {
		alert("Informe um \"LOGIN\" válido!\nApós preencher o login clique no botão \"Verificar disponibilidade\"!");
		document.getElementById("edtnovologin").focus();
		retorno = false;
	} else if ((retorno) && (!checkMail(email.value))) {
		alert("O \"EMAIL\" informado é inválido!");
		email.focus();
		retorno = false;
	}
	
	if (retorno) {
		if (confirm("Confirma as informações cedidas?")) {
			return true;
		} else {
			return false;
		}
	} else {
		return false;
	}
}


