var valid = "123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ._'\":;,\/<>-()*&%$#@! \n"; // define valid characters
function addCharacterListener()
{
    var textareas = document.getElementsByTagName("textarea");
    for(i=0; i < textareas.length; i++)
    {
        textareas[i].attachEvent("onkeyup", escapeMSWordChars);
    }
}

function escapeMSWordChars(e)
{
    var KeyID = (window.event) ? event.keyCode : e.keyCode;
    if(KeyID == 86) // captures a paste event
    {
        //alert("a paste event has been captured");
        var theTextArea = e.srcElement;
        var allowed = valid;
        var string = theTextArea.innerText;
        for (var i=0; i< string.length; i++)
        {
            switch(string.charCodeAt(i))
            {
                case 8211:
                    string = doReplace(string, i, "-");
                    //alert("replace with normal dash!");
                    break;
                case 8220:
                case 8221:
                    string = doReplace(string, i, "\"");
                    //alert("replace with a quote!");
                    break;
                case 8216:
                case 8217:
                    string = doReplace(string, i, "'")
                    //alert("replace with a single quote!");
                    break;

            }//end switch
            /*if (allowed.indexOf(string.charAt(i)) == -1)
            {
                alert("'" + string.charAt(i) + "': " + string.charCodeAt(i));
            }*/
        }//end for
        theTextArea.innerText = string;
    }//end if
}

function doReplace(string, i, replacer)
{
    var newString = string;
    newString = string.substring(0,i) + replacer;
    if(string.length > i+1)
        newString = newString + string.substring(i+1, string.length);
    return newString;
}