  /*---------------------------------------------
     Autor: Adriano da Silva Araújo
     Descrição: 
       Biblioteca de funções javascript úteis.
    ---------------------------------------------*/
  
  //Abre uma janela popup centralizada na tela e solicita as características da janela.
  function abrirJanela(sUrl, sNomeJanela, sCaracteristicas, iWidth, iHeight) {
    open( sUrl, sNomeJanela, sCaracteristicas + ",width=" + iWidth + ",height=" + iHeight 
      + ",top=" + ((screen.height/2) - (iHeight/2) - 50) + ",left=" + ((screen.width/2) - (iWidth/2)) );
  }
  
  //Pega o indice de um item no array elements de seu formulário.
  function getElementIndex(element) {
    for (var i=0; i < element.form.length; i++) {
      //retorna o valor de i se encontrou o item.
      if (element.name == element.form.elements[i].name)
         return i;
    }
    //retorna -1 se naum encontrou o item.
    return -1;
  }
  
  //Joga o foco para o próximo item do formulário.
  //Essa função deve ser usada no evento onKeyUp
  //de um campo com tamanho fixo.
  function focusNext(edt) {
    //if (event.keyCode >= 96 && event.keyCode <= 105) {
       var nextIndex = getElementIndex(edt) + 1;
       if (edt.value.length == edt.maxLength && typeof(edt.form.elements[nextIndex]) != "undefined")
           edt.form.elements[nextIndex].focus();
    //}
  }
  
  //Muda o action de um formulário e dá um submit nele.
  function enviaForm(frm, acao) {
    frm.action = acao; frm.submit();
  }
  
  //Coloca o foco no campo especificado.
  function darFoco(campo, darSelect) {
    campo.focus();
    if (darSelect && typeof(campo.select) != "undefined") campo.select(); else campo.value += "";
  }  
  
  //Esconde ou exibe um campo qualquer.
  function setVisible(campo, visible) {
    campo.style.display = (visible) ? "" : "none";
  }
  
  //***Funções que pegam o X e Y de um objeto na página.
  function pegaX(obj)
  {
		var curleft = 0;
		if (obj.offsetParent)
		{
			while (obj.offsetParent)
			{
				curleft += obj.offsetLeft
				obj = obj.offsetParent;
			}
		}
		else if (obj.x)
			curleft += obj.x;
		return curleft;
  }
  function pegaY(obj)
  {
		var curtop = 0;
		//var printstring = '';
		if (obj.offsetParent)
		{
			while (obj.offsetParent)
			{
				//printstring += ' element ' + obj.tagName + ' has ' + obj.offsetTop;
				curtop += obj.offsetTop
				obj = obj.offsetParent;
			}
		}
		else if (obj.y)
			curtop += obj.y;
//		window.status = printstring;
		return curtop;
  }
  //**--Fim funções para pega X e Y--------------------


//**--Funções usadas nas páginas de listagem------------
function incluir(paginaCadastro) {
	document.getElementById("trCadastro").style.display = "";
	document.getElementById("ifrmCadastro").src = paginaCadastro;
}

function cancelar() {
	document.getElementById("trCadastro").style.display = "none";
	document.form.busca.focus();
}

function editar(id, paginaCadastro) {
	document.getElementById("trCadastro").style.display = "";
	document.getElementById("ifrmCadastro").src = paginaCadastro + "?acao=alt&id="+id;
}


function excluir(id) {
	if (confirm("Deseja excluir?")) enviaForm(document.form, "?acao=del&id="+id);
}
//**----------------------------


//**---Funções usadas para manipulação de telas de cadastro em popups---
function selectChange(objSel, paginaCadastro, w, h) {
	if (objSel.value=="-1") {
	    objSel.selectedIndex = 0;
		abrirJanela(paginaCadastro + "?popup=1", "", "scrollbars=yes", w, h);
	}
}

function adicionarOption(objSel, valor, texto) {
	objSel.options[objSel.options.length++] = new Option(texto, valor);
	objSel.selectedIndex = objSel.options.length-1;
}
//**----------------------------