function Mascarar_Telefone(objeto,tammax,teclapres)

{

	var tecla = teclapres.keyCode;

	vr = objeto.value;

	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 <= 4 ) { 

	 		objeto.value = vr ;

		}

	 	if ( (tam > 4) && (tam <= 8) ) {

	 		objeto.value = vr.substr(0,tam-4) + '-' + vr.substr( tam - 4, tam ) ;

		}

	 	if ( (tam >= 9) && (tam <= 10) ) {

			objeto.value = '(' + vr.substr(0,2) + ') ' + vr.substr(2,tam-6) + '-' + vr.substr(tam-4,tam) ;			

		}

	}		

}