$(function()  
{  
    $('#TxtMensagem').keyup(function(e)  
    {  
        var maxLength = 3000;  
        var textlength = this.value.length;  
        if (textlength >= maxLength)  
        {  
            $('#charStatus').html('<p class="erroFormTxt">O limite de ' + maxLength + ' caracteres foi ultrapassado para a mensagem.</p>');
            this.value = this.value.substring(0, maxLength);  
            e.preventDefault();  
        }  
        else  
        {  
            $('#charStatus').html('Voc&ecirc; ainda pode preencher mais ' + (maxLength - textlength) + ' caractere(s) na mensagem.');  
        }  
    });  


	$('#TxtTelefone').bind('keyup paste focus blur',function(){
		var fone = $(this).val();
		fone = fone.replace(/[\D]/g,'');
		fone = fone.substr(0,10);
		fone = fone.replace(/(\d{0,2})(\d{0,4})(\d{0,4})/,function(str,ddd,f1,f2){
			    retorno = '';
			    if(ddd.length == 2)
			    {
			        retorno = '(' + ddd + ')';
        		        retorno += ' ' + f1;
        	
			        if(f2.length > 0)
			            retorno += '-' + f2;
			    }
				else
				{
					retorno = ddd;
				}
			    return retorno;
			});

		$(this).val(fone);
	});

});  


