﻿
function apenasNumericos(caracter) 
{
    if (document.all) // IE
    { 
        var tecla = event.keyCode;
    } else {
        if (document.layers) 
        {
            var tecla = caracter.which; 
        } else {
            var tecla = caracter.which;
        }
    }

    if (tecla > 47 && tecla < 58)  // numeros de 0 a 9
    {
        return true;
    } else {
        if (tecla != 8)  // backspace
        {
            if (tecla==0) 
            {
                return true;
            } else {
                return false;
            }
        } else {
            return true;
        }
    }
}


function separador1000(controlo, c, caracter)
{
	var aux = '';
	var counter = 0;
	var valor = controlo.value;
	
	if (document.all) // IE
    { 
        var tecla = event.keyCode;
    } else {
        if (document.layers) 
        {
            var tecla = caracter.which; 
        } else {
            var tecla = caracter.which;
        }
    }
    
    if ((tecla != 9) && (tecla != 16))  // TAB e Shif TAB
    {	
        // retirar zeros a esquerda
	    for (i = 0; i < valor.length; i++) 
		    if (valor.charAt(i) != '0')
		    break; 
	    valor = valor.substr(i, (valor.length - i))
    	
	    // retirar todos os separadores ja incluidos
	    valor = valor.replace(/\./g, '')

	    for (i = (valor.length - 1); i >= 0; i--)
	    {
		    if (counter == 3)
		    {
			    aux = c + aux;
			    counter = 0;
		    }
		    aux = valor.charAt(i) + aux;
		    counter++;
	    }	
	    
	    controlo.value = aux;   
    }
    
}


function PopupCentro(pagina,nome,w,h,scroll)
{
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
	var win = window.open(pagina,nome,settings);
}

