When your contact send you a message, there's X char. And if you replace ':)' to '*smile*', the end of the text can't be write. You can replace with only the same length.
code:
function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MessageKind){
Message = replace(Message, ":)", "xx");
return Message;
}