function fn_FormataCPFCNPJ(tpoEdit)
{
//usar no onkeypress
// tpoEdit => tipo de edição
//		      0 - CPF	1 - CNPJ

	//bloqueia caracteres não-numéricos
	goodChars = "0123456789X"
	caracDigit = String.fromCharCode(window.event.keyCode)
	if (goodChars.indexOf(caracDigit) == -1)	
		{window.event.returnValue = false}

	with(window.event.srcElement)
	{
		// máscara do CPF
		if (tpoEdit == 0 && window.event.keyCode != 8)
		{
			if (value.length == 3 || value.length == 7)
				{value += "."}
			if (value.length == 11)
				{value += "-"}
			//tamanho máximo do CPF
			if (value.length >= 14)
				{event.returnValue = false}
		}
		// máscara do CGC
		if (tpoEdit == 1 && window.event.keyCode != 8)
		{
			if (value.length == 2 || value.length == 6)
				{value += "."}
			if (value.length == 10)
				{value += "/"}
			if (value.length == 15)
				{value += "-"}
			//tamanho máximo do CNPJ
			if (value.length >= 18)
				{event.returnValue = false}			
		}
	}
}