function somente_numero(campo){
	var digits="0123456789"
	var campo_temp
	for (var i=0;i<campo.value.length;i++){
		campo_temp=campo.value.substring(i,i+1)
		if (digits.indexOf(campo_temp)==-1){
			campo.value = campo.value.substring(0,i);
			break;
		}
	}
}

//Função para criação de máscaras
function FormataCampo(Campo,teclapres,mascara){
	//pegando o tamanho do texto da caixa de texto com delay de -1 no event
	//ou seja o caractere que foi digitado não será contado.
	strtext = Campo.value
	tamtext = strtext.length
	//pegando o tamanho da mascara
	tammask = mascara.length
	//criando um array para guardar cada caractere da máscara
	arrmask = new Array(tammask)
	//jogando os caracteres para o vetor
	for (var i = 0 ; i < tammask; i++){
		arrmask[i] = mascara.slice(i,i+1)
	}
	//alert (teclapres.keyCode)
	//começando o trabalho sujo
	if (((((arrmask[tamtext] == "#") || (arrmask[tamtext] == "9"))) || (((arrmask[tamtext+1] != "#") || (arrmask[tamtext+1] != "9"))))){
		if ((teclapres.keyCode >= 37 && teclapres.keyCode <= 40)||(teclapres.keyCode >= 48 && teclapres.keyCode <= 57)||(teclapres.keyCode >= 96 && teclapres.keyCode <= 105)||(teclapres.keyCode == 8)||(teclapres.keyCode == 9) ||(teclapres.keyCode == 46) ||(teclapres.keyCode == 13)){
			Organiza_Casa(Campo,arrmask[tamtext],teclapres.keyCode,strtext)
		}
		else{
			Detona_Event(Campo,strtext)
		}
	}
	else{//Aqui funcionaria a mascara para números mas eu ainda não implementei
		if ((arrmask[tamtext] == "A")) {
			charupper = event.valueOf()
			//charupper = charupper.toUpperCase()
			Detona_Event(Campo,strtext)
			masktext = strtext + charupper
			Campo.value = masktext
		}
	}
}

function Organiza_Casa(Campo,arrpos,teclapres_key,strtext){
	if (((arrpos == "/") || (arrpos == ".") || (arrpos == ",") || (arrpos == ":") || (arrpos == " ") || (arrpos == "(") || (arrpos == ")") || (arrpos == "-")) && !(teclapres_key == 8)){
		separador = arrpos
		masktext = strtext + separador
		Campo.value = masktext
	}
}

function Detona_Event(Campo,strtext){
	event.returnValue = false
	if (strtext != "") {
		Campo.value = strtext
	}
}
//Término da Função

function mascara_Valor(objeto,event)
{
    var i,exceptions=[8,46,37,38,39,40,13,9,190]; // backspace, delete, arrowleft, arrowtop, arrowright, arrowdown, enter, tab, ponto
    var isException=false;
    
    for(i=0;i<exceptions.length;i++)
        if(exceptions[i]==event.keyCode)
            isException=true;
    
    if (!isException)  
    {
        campo = eval (objeto);
        vr =  campo.value;
        vr = vr.replace( "/", "" );
        vr = vr.replace( ",", "" );
        vr = vr.replace( ",", "" );
        vr = vr.replace( ",", "" );
        vr = vr.replace( ",", "" );
        vr = vr.replace( ".", "" );
        vr = vr.replace( ".", "" );
        vr = vr.replace( ".", "" );
        vr = vr.replace( ".", "" );
        tam = vr.length + 1;
        tamax = 28;

        if (tam < tamax)
        {

            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 ) ;}
        }
    }
}
