function showInline (elName) {
	var theElemenet = document.getElementById(elName);
	if (theElemenet) {
		theElemenet.style.display = "inline";
	}
}
function hideInline (elName) {
	var theElemenet = document.getElementById(elName);
	if (theElemenet) {
		theElemenet.style.display = "none";
	}
}

function soLetras(theFormObj) {
	var naoLetras = /[^a-zA-Z\s+\?\.\,\0-9\@]/gi; /* tudo que NAO (^) for letra (a-zA-Z) ou espaco (\s)*/
	theFormObj.value = theFormObj.value.replace(naoLetras, ' ');
}

function isCaracterEspecial(caractere) {
	var strValidos = "\\`!^*()-_=+|{}[]:/~'\";%$#&<>"
	if( strValidos.indexOf(caractere) == -1 )
		return true;
	return false;
}

function isNum( caractere ) {
	var strValidos = "0123456789"
	if( strValidos.indexOf(caractere) == -1 )
		return false;
	return true;
}

function isNum2( caractere ) {
	var strValidos = "0123456789"
	if( strValidos.indexOf(caractere) == -1 )
		return caractere;
	return '';
}

function SohNumeros( caractere ) {
	if(isNum(caractere) == true)
		return caractere;
	else
		return '';
}

function validaCaracterEspecial(campo, event) {

	var BACKSPACE= 8;
	var ENTER= 13;

	/* outros */
	var key;
	var tecla;
	CheckTAB=true;
	/* se netscape bla senao blabla */
	if(navigator.appName.indexOf("Netscape")!= -1)
		tecla= event.which;
	else
		tecla= event.keyCode;
	key = String.fromCharCode(tecla);

	if (tecla == BACKSPACE)
		return true;
	if (tecla == ENTER)
		return false;

	return (isCaracterEspecial(key));
}

function validaTecla(campo, event) {
	var BACKSPACE= 8;
	var key;
	var tecla;
	CheckTAB=true;
	if(navigator.appName.indexOf("Netscape")!= -1)
		tecla= event.which;
	else
		tecla= event.keyCode;
	key = String.fromCharCode(tecla);
	if (tecla == 13)
		return false;
	if (tecla == BACKSPACE)
		return true;
	return (isNum(key));
}

function FormataData(campo,teclapres) {
	var tecla = teclapres.keyCode;
	vr = campo.value;
	vr = vr.replace( ".", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	tam = vr.length + 1;

	if ( tecla != 9 && tecla != 8 ){
		if ( tam > 2 && tam < 5 )
			campo.value = vr.substr( 0, tam - 2  ) + '/' + vr.substr( tam - 2, tam );
		if ( tam >= 5 && tam <= 10 )
			campo.value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 );
	}
}

function FormataHora(campo,teclapres) {
	var tecla = teclapres.keyCode;
	vr = campo.value;
	vr = vr.replace( ".", "" );
	vr = vr.replace( ":", "" );
	vr = vr.replace( ":", "" );
	tam = vr.length + 1;

	if ( tecla != 9 && tecla != 8 ){
		if ( tam > 2 && tam < 5 )
			campo.value = vr.substr( 0, tam - 2  ) + ':' + vr.substr( tam - 2, tam );
		if ( tam >= 5 && tam <= 7 )
			campo.value = vr.substr( 0, 2 ) + ':' + vr.substr( 2, 2 ) + ':' + vr.substr( 4, 2 );
	}
}

function textCounter(campo, countcampo, maxlimit) {
	var caracteres;
	if (campo.value.length > maxlimit) {
		campo.value = campo.value.substring(0, maxlimit);
	} else {
		caracteres = maxlimit - campo.value.length;
		if(caracteres > 1) {
			countcampo.value = caracteres + " caracteres restantes";
		} else if(caracteres == 1) {
			countcampo.value = caracteres + " caractere restante";
		} else {
			countcampo.value = "Número máximo de caracteres já utilizado";
		}
	}
}

function FormataMaiusculo(campo) {
	campo.value = campo.value.toUpperCase();
}

/* modificações feitas pelo Jorge */

function isTecla(caractere) {
	var strValidos = "`!^*()=+|{}[]~'\";%#&<>"
	if ( strValidos.indexOf( caractere ) == -1 ) {
		return true;
	}
return false;
}

function capturaTecla(campo, event) {
	var ENTER = 13;
	var SPACE = 8;

	var key;
	var tecla;
	CheckTAB = true;
	if (navigator.appName.indexOf("Netscape") != -1) { tecla = event.which; } else { tecla = event.keyCode; }
	key = String.fromCharCode(tecla);

	if (tecla == ENTER) { return false; }
	if (tecla == SPACE) { return true; }

return (isTecla(key));
}

/* ------------- HINT ------------- */

//verifica o navegador
sAgent = navigator.userAgent;
bIsIE = sAgent.indexOf("MSIE") > -1;
bIsNav = sAgent.indexOf("Mozilla") > -1 && !bIsIE;

//setando as variaveis de controle de eventos do mouse
var xmouse = 0;
var ymouse = 0;
document.onmousemove = MouseMove;

//funcoes de controle de eventos do mouse:
function MouseMove(e){
	if (e) {
		MousePos(e);
	} else {
		MousePos();
	}
}

function MousePos(e) {
	if (bIsNav){
		xmouse = e.pageX;
		ymouse = e.pageY;
	}
	if (bIsIE) {
		xmouse = document.body.scrollLeft + event.x;
		ymouse = document.body.scrollTop + event.y;
	}
}

//funcao que mostra e esconde o hint
function Hint(objNome, action){ //action = 1 -> Esconder action = 2 -> Mover
	if (bIsIE) {
		objHint = document.all[objNome];
	}
	if (bIsNav) {
		objHint = document.getElementById(objNome);
		event = objHint;
	}
	switch (action){
		case 1: //Esconder
			objHint.style.visibility = "hidden";
			break;
		case 2: //Mover
			objHint.style.visibility = "visible";
			objHint.style.left = xmouse + 15;
			objHint.style.top = ymouse + 15;
			break;
	}
}

function ajax(url, campo) {

	//alert(nick);
	//alert(dest);
	//alert(msg);

	req = null;

	// Procura por um objeto nativo (Mozilla/Safari)
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
		req.onreadystatechange = function() {
			if (req.readyState == 4) {
				if (req.status == 200) {
					document.getElementById(campo).value = req.responseText;
				} else {
					alert("Houve um problema ao obter os dados:n" + req.statusText);
				}
			}
		};
		req.open("GET",url,true);
		req.send(null);
	// Procura por uma versão ActiveX (IE)
	} else if (window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
		if (req) {
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					if (req.status == 200) {
						document.getElementById(campo).value = req.responseText;
					} else {
						alert("Houve um problema ao obter os dados:n" + req.statusText);
					}
				}
			};
			req.open("GET",url,true);
			req.setRequestHeader("Content-Type","application/x-www-form-urlencoded; ");
			req.send();
		}
	}
}

function busca_nome(num_matricula, campo) {

	if(num_matricula.length > 3) {
		/*alert(campo);
		alert(document.getElementById(campo).value);*/

		url="busca_nome.php?num_matricula="+num_matricula;
		ajax(url, campo);
	}
}

function mudapagina(combo)
{
var endereco = combo.value;
if (endereco != "#")
{novapagina = window.open(endereco,"NewPage");
}
}
