// Muda-se aqui para alterar as dimensões das janelas popup, ao menos as que não tiverem as mesmas definidas na chamada da função

function popup(ende, wi, he) {
	window.open(ende, 'popups', 'toolbar=yes,location=yes,menubar=yes,status=yes,scrollbars=yes,resizable=yes,width=' + wi + ',height=' + he + '');
}

function popupB(ende, wi, he) {
	window.open(ende, 'popups', 'toolbar=no,location=no,menubar=no,status=no,scrollbars=no,resizable=no,width=' + wi + ',height=' + he + '');
}

function popupC(ende, wi, he) {
	window.open(ende, 'popups', 'toolbar=no,location=no,menubar=no,status=no,scrollbars=yes,resizable=yes,width=' + wi + ',height=' + he + '');
}

function prt(ende) {
	window.open(ende, 'print', 'toolbar=no,location=no,menubar=yes,status=yes,scrollbars=yes,resizable=yes,width=460,height=426');
}

function gcampo(ende) {
	window.open(ende, 'CampoResultado', 'toolbar=no,location=no,menubar=no,status=no,scrollbars=yes,resizable=yes,width=680,height=300');
}

function lista(ende) {
	window.open(ende, 'Lista', 'toolbar=no,location=no,menubar=no,status=no,scrollbars=yes,resizable=yes,width=360,height=350');
}
function listaMd(wi, he, ende) {
	window.open(ende, 'Lista', 'toolbar=no,location=no,menubar=no,status=no,scrollbars=yes,resizable=yes,width=' + wi + ',height=' + he + '');
}

function calendario(ende) {
	window.open(ende, 'Calendario', 'toolbar=no,location=no,menubar=no,status=no,scrollbars=yes,resizable=yes,width=290,height=310');
}

function obs(ende) {
	window.open(ende, 'Observacao', 'toolbar=no,location=no,menubar=yes,status=yes,scrollbars=yes,resizable=yes,width=500,height=400');
}

function imagem(ende) {
	window.open(ende, 'Imagem', 'toolbar=no,location=no,menubar=no,status=no,scrollbars=no,resizable=yes,width=660,height=590');
}

// -----------------------------------------------------------------

// Experimento:

function pageDown() {
	if (window.scrollBy)
		window.scrollBy(0, window.innerHeight ? window.innerHeight : document.body.clientHeight);
}

function pageUp() {
	if (window.scrollBy)
		window.scrollBy(0, window.innerHeight ? -window.innerHeight : -document.body.clientHeight);
}

// fim experimento

function focusPrimeiroCampo() {
	var form = document.forms[0];
	if (form != null) {
		for ( var i = 0; i < form.elements.length; i++) {
			if ((form.elements[i].tagName == "TEXTAREA") || (form.elements[i].tagName == "INPUT" && (form.elements[i].type == "text" || form.elements[i].type == "password"))) {
				form.elements[i].focus();
				return;
			}
		}
	}
}

function teste() {
	for ( var i = 0; i < document.forms[0].elements.length; i++) {
		if (document.forms[0].elements[i].tagName == "TEXTAREA") {
			document.forms[0].elements[i].value = '0';
		} else if (document.forms[0].elements[i].type == "text") {
			document.forms[0].elements[i].value = '0';
		} else if (document.forms[0].elements[i].type == "radio") {
			document.forms[0].elements[i].checked = true;
		}
	}
}
// TODO: Fazer essa função ser mais "amigável" com o usuário, não comer caracteres
// nota: parece que é melhor não usar a mesma
function passaProx(atual, prox) {
	/*
	 * if (atual.value.length>=atual.maxLength) prox.focus();
	 */
}

// -----------------------------------------------------------------

function isNum(key) {
	if ((key < 48) || (key > 57) || (key == 32))
		if (key != 13)
			return false
}

// -----------------------------------------------------------------
// javascript das relações
function sbtRelacao(iframeDe) {
	if (window.frames[iframeDe])
		if (gerenciadorCheckbox(window.frames[iframeDe].document.forms[0].codigos, true, false))
			window.frames[iframeDe].document.forms[0].submit();
}

function rfRelacao(iframe) {
	if (window.top.frames[iframe]) {
		gerenciadorCheckbox(window.top.frames[iframe].document.forms[0].codigos, false, false)
		window.top.frames[iframe].document.forms[0].submit();
	}
}

function marcar(iframe, tipo) {
	if (window.frames[iframe])
		gerenciadorCheckbox(window.frames[iframe].document.forms[0].codigos, false, tipo);
}

function gerenciadorCheckbox(c, verificador, marcador) {
	if (c != null)
		if (!verificador) {
			if (c.length != null) {
				for ( var i = 0; i < c.length; i++)
					c[i].checked = marcador;
			} else
				c.checked = marcador;
		} else {
			var tem = false;
			if (c.length != null) {
				for ( var i = 0; i < c.length; i++) {
					if (c[i].checked) {
						tem = true;
						break;
					}
				}
			} else if (c.checked)
				tem = true;
			return tem;
		}
	return false;
}

// -----------------------------------------------------------------

function mostrar(LayerID) {
	// if (document.all)
	// {
	if (document.getElementById(LayerID).style.display == '') {
		document.getElementById(LayerID).style.display = 'none';
	} else {
		document.getElementById(LayerID).style.display = '';
	}
	// }
}

function mostraArea(LayerID, select, textar) {
	if (select.selectedIndex == 2 || select.selectedIndex == 4) {
		document.getElementById(LayerID).style.display = '';
	} else {
		document.getElementById(LayerID).style.display = 'none';
		textar.value = '';
	}
}

function IsData(dia, mes, ano) { // usar Janeiro=1
	hoje = new Date();
	entrada = new Date(ano, mes - 1, dia);
	if (entrada > hoje)
		return false;
	timeA = new Date(ano, mes, 1);
	timeB = new Date(timeA - 86400000);
	if (dia > timeB.getDate())
		return false;
	return true;
}

function round(x, n) {
	if (n == null)
		n = 0;
	return Math.round(x * Math.pow(10, n)) / Math.pow(10, n);
}

// -----------------------------------------------------------------

function maismenos(btn, frm, tipo, qtde) {
	btn.disabled = true;
	frm.qtde.value = qtde + tipo;
	frm.action += '?anula=' + tipo;
	frm.submit();
}

function mostraBtn() {
	document.getElementById('aguarde').style.display = 'none';
	document.getElementById('btns').style.display = '';
}

// -----------------------------------------------------------------

function mOco(id, qstr) {
	mostrar('o' + id);
	var o = document.getElementById('ft' + id);
	if (o != null)
		if (o.src != (qstr))
			o.src = qstr;
}

// Função para forçar page break no Firefox:
// function setPageBreak() {
// document.getElementById("xpage").style.pageBreakBefore="always";
// }

