function Numeric()
{
  if(event.keyCode < 48 || event.keyCode > 57)
    event.returnValue = 0;
}


function mascaracep(campo,cep){

 if (cep.length == 5){
cep = cep + '-';
document.formulario[campo].value = cep;
}
if (cep.length == 9){
endereco(campo,cep);
}
}

function formataCEP(formato, keypress, objeto)
{
campo = eval(objeto);
if (formato=='CEP')
{
caracteres = '01234567890';
separacoes = 1;
separacao1 = '-';
conjuntos = 2;
conjunto1 = 5;
conjunto2 = 3;
if ((caracteres.search(String.fromCharCode (keypress))!=-1) && campo.value.length < 
(conjunto1 + conjunto2 + 1))
{
if (campo.value.length == conjunto1) 
   campo.value = campo.value + separacao1;
}
else 
event.returnValue = false;
}
}


function trim(valorTrim){
var len = valorTrim.length;
for(var x=0; x<len; x++) if(valorTrim.charCodeAt(x)!=32 && valorTrim.charCodeAt(x)!=10 && valorTrim.charCodeAt(x)!=13) break;
valorTrim = valorTrim.substring(x,len);
len = valorTrim.length;
for(x=len-1; x>1; x--) if(valorTrim.charCodeAt(x)!=32 && valorTrim.charCodeAt(x)!=10 && valorTrim.charCodeAt(x)!=13) break;
valorTrim = valorTrim.substring(0,x+1);
return valorTrim;
}

function getFocus(formulario, campo){
eval("document." + formulario + "." + campo + ".focus()")
}

function notNumeric(){
  if(event.keyCode < 64 || event.keyCode > 122)
event.returnValue = 0;
}

function popup(caminho,nome,largura,altura,rolagem) 
{
var esquerda = (screen.width - largura) / 2;
var cima = (screen.height - altura) / 2 -50;
window.open(caminho,nome,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=' + rolagem + ',resizable=yes,copyhistory=no,top=' + cima + ',left=' + esquerda + ',width=' + largura + ',height=' + altura);
}


function FormataValor(campo,tammax,teclapres) 
 {
var tecla = teclapres.keyCode;
vr = campo.value;
vr = vr.replace( "/", "" );
vr = vr.replace( "/", "" );
vr = vr.replace( ",", "" );
vr = vr.replace( ".", "" );
vr = vr.replace( ".", "" );
vr = vr.replace( ".", "" );
vr = vr.replace( ".", "" );
tam = vr.length;
if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }
if (tecla == 8 ){tam = tam - 1 ; }
if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
if ( tam <= 2 ){ 
 campo.value = vr ; }
 if ( (tam > 2) && (tam <= 5) ){
 campo.value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ) ; }
 if ( (tam >= 6) && (tam <= 8) ){
 campo.value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
 if ( (tam >= 9) && (tam <= 11) ){
 campo.value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
 if ( (tam >= 12) && (tam <= 14) ){
 campo.value = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
 if ( (tam >= 15) && (tam <= 17) ){
 campo.value = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ;}
}
}
function validarCep(cep)
{
txCep = trim(cep);
if(txCep.length == 0)
return false;

txCep = txCep.replace("-","");
txCep = txCep.replace(".","");
if(txCep.length != 8 || isNaN(txCep))
return false;
else
return true;
}
