// JavaScript Document
function empresa() {
	window.location = "incluir_empresa.htm";
}
function instituicao() {
	window.location = "incluir_instituicao.htm";
}

function abrir() {

	janela = window.open("pesquisar_inst.htm", "Pesquisar",
			"menubar=no,scrollbars=yes,status=no,toolbar=no");
	// interceptacao de erro na abertura da janela
	text = "Se a janela nao estava abrindo talvez seja porque voce tenha um programa bloqueador de pop-up! Observacao ? O windows XP service pack 2 bloqueia pop-ups!";

	if (janela == null) {
		alert(text);
		return;
	}
	// fim
	janela.resizeTo(700, 400);
	janela.moveTo(100, 100);

}
function MM_swapImgRestore() { // 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 MM_preloadImages() { // 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 = MM_preloadImages.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 MM_findObj(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 = MM_findObj(n, d.layers[i].document);
	if (!x && d.getElementById)
		x = d.getElementById(n);
	return x;
}

function MM_swapImage() { // v3.0
	var i, j = 0, x, a = MM_swapImage.arguments;
	document.MM_sr = new Array;
	for (i = 0; i < (a.length - 2); i += 3)
		if ((x = MM_findObj(a[i])) != null) {
			document.MM_sr[j++] = x;
			if (!x.oSrc)
				x.oSrc = x.src;
			x.src = a[i + 2];
		}
}
function cadastro() {
	var answer = confirm("Confirma Inclus?o?")
	if (answer) {
		window.location = "incluir_ie.htm";
	} else {
		alert("Opera??o cancelada!")
	}
}

// Evento utilizado na tag onkeypress="javascript:somenteCaracteresNumericos()";
function somenteCaracteresNumericos(event) {
	var key;
	if (window.event)
		key = event.keyCode
	else
		key = event.which
		// Was key that was pressed a numeric character (0-9) or backspace (8) or tab(0 in firefox)?
	if (key > 47 && key < 58 || key == 8 || key == 0)
		return; // if so, do nothing
	else // otherwise, discard character

	if (window.event) // IE
		window.event.returnValue = null;
	else
		// Firefox
		event.preventDefault();

}

function somenteCaracteresLetras(event) {
	var key;
	if (window.event)
		key = event.keyCode
	else
		key = event.which
		// Was key that was pressed a numeric character (0-9) or backspace (8) or tab(0 in firefox)?
	if (!(key > 48 && key < 57) || key == 8 || key == 0) 
		return; // if so, do nothing
	else // otherwise, discard character

	if (window.event) // IE
		window.event.returnValue = null;
	else
		// Firefox
		event.preventDefault();
}

function formata(x) {
	var e = event.keyCode;
	if (e < 48 || (e > 57 && e < 96) || e > 105) {
		return;
	}
	var str = x.value.replace('.', '');
	var tam = str.length;
	if (tam > 1) {
		x.value = str.substring(0, tam - 1) + '.' + str.substring(tam - 1, tam);
	}
}

function isValorNumerico(campo) {
	if (isNaN(campo.value)) {
		alert('Voc? n?o digitou um n?mero')
	}
}

function isTeclaPressionadaNumerica(campo) {
	var valor = campo.value;
	var chr = valor.charAt(valor.length - 1);

	if (isNaN(chr)) {
		campo.value = valor.substr(campo.value.length - 1);
		if (isNaN(campo.value)) {
			campo.value = '';
		}
	}
}

/*
 * Fun??o para verificar se algum checkbox est? marcado.
 */
function verificaChecked(frm, nome) {
	var i;
	var ok = 0;
	for (i = 0; i < frm.length; i++) {
		if (frm.elements[i].type == "checkbox") {
			if ((frm.elements[i].name == nome) && frm.elements[i].checked) {
				ok++;
			}
		}
	}
	return ok;
}

function trim(s) {

	while (s.substring(0, 1) == ' ') {
		s = s.substring(1, s.length);
	}
	while (s.substring(s.length - 1, s.length) == ' ') {
		s = s.substring(0, s.length - 1);
	}
	return s;
}

function ehVazio(campo) {
	if (campo.value == null || trim(campo.value) == '') {
		return true;
	}
	return false;
}

