function abreJanela (Doc, Alt, Larg, Nome)
{
 // para abrir uma nova janela em pop-up
 
LeftPosition = (screen.width) ? (screen.width-Larg)/2 : 0;
TopPosition = (screen.height) ? (screen.height-Alt)/2 : 0;

 var Args = "scrollbars=yes,location=no,directories=no,status=no,menubar=no,resizable,top="+TopPosition+",left="+LeftPosition+",toolbar=no,copyhistory=no,width=" + Larg + ",height=" + Alt + "";
 var Janela = window.open(Doc, Nome, Args);
 
 return;
}

function excluir(endereco){
	//pergunta se deseja realmente excluir o registro do banco antes de excluir realmente
	if(window.confirm('Deseja realmente excluir este registro?')){
		location.href = endereco
	}
}

function botaEMail(usuario, servidor, texto, opcoes) {
	var email = usuario+unescape("%40")+servidor;
	if(typeof(texto) == "undefined" || texto == ""){
		texto = email;
	}
	if(typeof(opcoes) == "undefined"){
		opcoes = "";
	} else {
		opcoes = "?" + escape(opcoes).replace(/%3D/g,"=").replace(/%26/g,"&").replace(/%3B/g,";");
	}
	document.write('<a href="mailto:'+email+opcoes+'">'+texto+'</a>');
}


function pulldown_menu()
{ 
var url = document.pulldown.selectname.options[document.pulldown.selectname.selectedIndex].value
window.location.href = url 
}

/*
************************ Validação de CPF *****************************

Nome do formulário: form1
nome do campo: cpf
Exemplo como chamar:  <input type="text" name="cpf" maxlength="11" onBlur="checaCPF()">

***********************************************************************
*/
function checaCPF()  {
cpf = document.form1.cpf.value;
erro = new String;
if (cpf.length < 11){ 
	alert ('São necessários 11 dígitos para verificação do CPF! \n\n');
	document.form1.cpf.value = '';
	document.form1.cpf.focus(); 
}
var nonNumbers = /\D/;
if (nonNumbers.test(cpf)){
	alert ('A verificação de CPF suporta apenas números! \n\n');
	document.form1.cpf.value = '';
	document.form1.cpf.focus(); 
}
if (cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999"){
	alert ('Número de CPF inválido!');
	document.form1.cpf.value = '';
	document.form1.cpf.focus(); 
}
var a = [];
var b = new Number;
var c = 11;
for (i=0; i<11; i++){
	a[i] = cpf.charAt(i);
	if (i < 9) b += (a[i] * --c);
	}
	if ((x = b % 11) < 2) { a[9] = 0 } else { a[9] = 11-x }
	b = 0;
	c = 11;
	for (y=0; y<10; y++) b += (a[y] * c--);
		if ((x = b % 11) < 2) { a[10] = 0; } else { a[10] = 11-x; }
		 if ((cpf.charAt(9) != a[9]) || (cpf.charAt(10) != a[10])){
			alert ('CPF Inválido \n\n Digito verificador com problema!');
			document.form1.cpf.value = '';
			document.form1.cpf.focus(); 
		 }
		if (erro.length > 0){
			alert(erro);
			return false;
		}
		return true;
}

////////////////// Contador de caracteres no formulário
<!--
function getObject(obj) {
  var theObj;
  if(document.all) {
    if(typeof obj=="string") {
      return document.all(obj);
    } else {
      return obj.style;
    }
  }
  if(document.getElementById) {
    if(typeof obj=="string") {
      return document.getElementById(obj);
    } else {
      return obj.style;
    }
  }
  return null;
}

//Contador de caracteres.
function Contar(entrada,salida,texto,caracteres) {
  var entradaObj=getObject(entrada);
  var salidaObj=getObject(salida);
  var longitud=caracteres - entradaObj.value.length;
  if(longitud <= 0) {
    longitud=0;
    texto='<span class="disable"> '+texto+' </span>';
    entradaObj.value=entradaObj.value.substr(0,caracteres);
  }
  salidaObj.innerHTML = texto.replace("{CHAR}",longitud);
}

////////////////// Auto Tab

var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e) {
	var keyCode = (isNN) ? e.which : e.keyCode;
	var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
	if(input.value.length >= len && !containsElement(filter,keyCode)) {
		input.value = input.value.slice(0, len);
		input.form[(getIndex(input)+1) % input.form.length].focus();
	}
	
function containsElement(arr, ele) {
	var found = false, index = 0;
	while(!found && index < arr.length)
	if(arr[index] == ele)
		found = true;
	else
		index++;
		return found;
	}

function getIndex(input) {
	var index = -1, i = 0, found = false;
	while (i < input.form.length && index == -1)
		if (input.form[i] == input)index = i;
	else i++;
	return index;
	}
	return true;
	}
	
//fim auto tab


function esconde(layerNome)
{
  var elemID = document.getElementById(layerNome);
    elemID.style.display = 'none';
}


function mostra(layerNome)
{
  var elemID = document.getElementById(layerNome);
  if (elemID.style.display == 'inline')
  {
    elemID.style.display = 'none';
  }
  else {
    elemID.style.display = 'inline';
  }
}

function seleciona_tp_pessoa(){ 
	var url = document.f1.pessoa.options[document.f1.pessoa.selectedIndex].value
	window.location.href = url 
}
