Encodes (escapes) HTML Special Chars
function htmlSpecialCharsEntityEncode(str) {
return str.replace(/[<>&\r\n"']/gm, function (match) {
return '&' + {
'<': 'lt;',
'>': 'gt;',
'&': 'amp;',
'\r': "#13;",
'\n': "#10;",
'"': 'quot;',
"'": 'apos;' /*single quotes just to be safe*/
}[match];
});
}