function pega_extensao(arq){
	var s, extensao, posicao;
	extensao = "";
	s = arq;
	for (i = s.length; i > 0; i--){
		if (s.charAt(i) == "."){
			posicao = i;
			i = 0;
		}
	}
	for (i = posicao; i < s.length; i++)
		extensao = extensao + s.charAt(i);
	return(extensao.toLowerCase());
}

/*********************************************************/
/* VALIDA CPF */

function validaCpf(cpf){
	var numeros, digitos, soma, i, resultado, digitos_iguais;
	digitos_iguais = 1;
	if (cpf.length < 11)
	      return false;
	for (i = 0; i < cpf.length - 1; i++)
	      if (cpf.charAt(i) != cpf.charAt(i + 1)){
	            digitos_iguais = 0;
	            break;
				}
	if (!digitos_iguais){
	      numeros = cpf.substring(0,9);
	      digitos = cpf.substring(9);
	      soma = 0;
	      for (i = 10; i > 1; i--)
	            soma += numeros.charAt(10 - i) * i;
	      resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
	      if (resultado != digitos.charAt(0))
	            return false;
	      numeros = cpf.substring(0,10);
	      soma = 0;
	      for (i = 11; i > 1; i--)
	            soma += numeros.charAt(11 - i) * i;
	      resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
	      if (resultado != digitos.charAt(1))
	            return false;
	      return true;
	      }
	else
	      return false;
}

/*********************************************************/
/* TAB AUTOMÁICO */

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;
}

/*********************************************************/
/* VALIDA E-MAIL */

function checa_mail(mail){
	var str, arroba, ponto
	str=mail
	for (i=0; i < (mail.length-1); i++){
		if ((i > 0) && (str.charAt(i)=="@")) {
			arroba=true
		} else
			if ((str.charAt(i)==".") && (arroba)) {
				ponto=true
			}
	}
	if ((! arroba) || (! ponto))
		return false
	else
		return true
}

/*********************************************************/
/* VALIDA RADIO */

function checaRadio(campo) {
	var str, myOption
	myOption = -1;
	str=campo
	for (i=str.length-1; i > -1; i--) {
		if (str[i].checked) {
			myOption = i; i = -1;
		}
	}
	
	if (myOption == -1)
		return false;
	else
		return true;
}

/*********************************************************/
/* MASCARA PARA TELEFONE */

function TelMask (keypress, objeto){
//	campo = eval (objeto);
	separador = '-';
	conjunto = 4;
		if (objeto.value.length == conjunto){
			objeto.value = objeto.value + separador;
		}
}


/**  ROLL OVER DE IMAGENS **/
function roll(img_name, img_src){
   document[img_name].src = img_src;
}


/** MOSTRA E ESCONDE DIVS **/

function getStyle(id){	
	return document.getElementById(id).style;
}

function HideLayer(id){	
	getStyle(id).visibility = "hidden";
	getStyle(id).display = "none";
}
function ShowLayer(id){	
	getStyle(id).visibility = "visible";
	getStyle(id).display = "block";
}

