// Cross-Browser Rich Text Editor
// Version 3.08b
// Written by Kevin Roth (http://www.kevinroth.com/rte/)
// Visit the support forums at http://www.kevinroth.com/forums/index.php?c=2
// License: http://creativecommons.org/licenses/by/2.5/

//init globals
var lang = "en";
var encoding = "UTF-8";
var debugMode = false;
var isRichText = false;
var defaultWidth = 500;
var defaultHeight = 200;
var allRTEs = "";
var currentRTE = "";
var selectionText = "";
var rng;
var lastCommand;
var maxLoops = 20;
var loopCnt = 0;
var baseUrl = window.parent.document.location.protocol + "//" + document.domain + "/";

var imagesPath = "";
var includesPath = "";
var cssFile = "../css/rte.css";
var generateXHTML = true;
var encodeHTML = false;

//browser vars
var ua = navigator.userAgent.toLowerCase();
var isIE = ((ua.indexOf("msie") != -1) && (ua.indexOf("opera") == -1) && (ua.indexOf("webtv") == -1));
var ieVersion = parseFloat(ua.substring(ua.indexOf('msie ') + 5));
var isGecko = (ua.indexOf("gecko") != -1);
var isSafari = (ua.indexOf("safari") != -1);
//var safariVersion = parseFloat(ua.substring(ua.lastIndexOf("safari/") + 7));
var webkitVersion = get_webkit_version();
if (webkitVersion) {
	webkitVersion = webkitVersion["major"];
} else {
	webkitVersion = null;
}
var isKonqueror = (ua.indexOf("konqueror") != -1);
var konquerorVersion = parseFloat(ua.substring(ua.indexOf('konqueror/') + 10));
var isOpera = (ua.indexOf("opera") != -1);
var isNetscape = (ua.indexOf("netscape") != -1);
var netscapeVersion = parseFloat(ua.substring(ua.lastIndexOf('/') + 1));

//command vars
var toolbar1Enabled = true;
var toolbar2Enabled = true;

var cmdFormatBlockEnabled = true;
var cmdFontNameEnabled = true;
var cmdFontSizeEnabled = true;
var cmdIncreaseFontSizeEnabled = false;
var cmdDecreaseFontSizeEnabled = false;

var cmdBoldEnabled = true;
var cmdItalicEnabled = true;
var cmdUnderlineEnabled = true;
var cmdStrikethroughEnabled = true;
var cmdSuperscriptEnabled = true;
var cmdSubscriptEnabled = true;

var cmdJustifyLeftEnabled = true;
var cmdJustifyCenterEnabled = true;
var cmdJustifyRightEnabled = true;
var cmdJustifyFullEnabled = true;

var cmdInsertHorizontalRuleEnabled = true;
var cmdInsertOrderedListEnabled = true;
var cmdInsertUnorderedListEnabled = true;

var cmdOutdentEnabled = true;
var cmdIndentEnabled = true;
var cmdForeColorEnabled = true;
var cmdHiliteColorEnabled = true;
var cmdInsertHTMLEnabled = true;
var cmdSpellCheckEnabled = false;
var cmdCreateLinkEnabled = true;
var cmdInsertEmailEnabled = true;
var cmdInsertFileEnabled = true;
var cmdInsertImageEnabled = true;

var cmdCutEnabled = true;
var cmdCopyEnabled = true;
var cmdPasteEnabled = true;
var cmdUndoEnabled = true;
var cmdRedoEnabled = true;
var cmdRemoveFormatEnabled = true;
var cmdUnlinkEnabled = true;


function initRTE(imgPath, incPath, css, genXHTML, encHTML) {
	//set browser vars
	try {
		//set global vars
		imagesPath = imgPath;
		includesPath = incPath;
		cssFile = css;
		generateXHTML = genXHTML;
		if (encHTML) encodeHTML = true;
		
		//check to see if designMode mode is available and disable unsupported commands
		if (document.designMode) {
			if (document.getElementById && !isIE && !isSafari && !isKonqueror) {
				isRichText = true;
				if (isGecko || isOpera) {
					cmdIncreaseFontSizeEnabled = true;
					cmdDecreaseFontSizeEnabled = true;
					cmdCutEnabled = false;
					cmdCopyEnabled = false;
					cmdPasteEnabled = false;
				}
				if (isNetscape && netscapeVersion < 8) {
					cmdInsertHTMLEnabled = false;
				}
			} else if (isIE && ieVersion >= 5.5) {
				isRichText = true;
				cmdSpellCheckEnabled = true;
			} else if (isSafari) {
				if (webkitVersion >= 420) {
					isRichText = true;
				} else if (webkitVersion >= 312) {
					//Safari 1.3+ is capable of designMode, Safari 1.3 = webkit build 312
					isRichText = true;
					toolbar1Enabled = false;
					cmdStrikethroughEnabled = false;
					cmdJustifyFullEnabled = false;
					cmdInsertHorizontalRuleEnabled = false;
					cmdInsertOrderedListEnabled = false;
					cmdInsertUnorderedListEnabled = false;
					cmdOutdentEnabled = false;
					cmdIndentEnabled = false;
					cmdInsertImageEnabled = false;
					cmdPasteEnabled = false;
					cmdInsertHTMLEnabled = false;
					cmdCreateLinkEnabled = false;
					cmdUnlinkEnabled = false;
					cmdRemoveFormatEnabled = false;
				}
			}
		}
		
		if (isRichText) {
			document.writeln('<style type="text/css">@import "' + includesPath + 'rte.css";</style>');
			document.writeln('<iframe width="150" height="100" id="cp" src="' + includesPath + 'palette.htm" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" style="visibility:hidden; position: absolute;"></iframe>');
			if (isIE) {
				document.onmouseover = raiseButton;
				document.onmouseout  = normalButton;
				document.onmousedown = lowerButton;
				document.onmouseup   = raiseButton;
			}
		}
		
		//for testing standard textarea, uncomment the following line
		//isRichText = false;
	} catch (e) {
		if (debugMode) alert(e);
	}
}

function richTextEditor(id,buttons) {
	//creates a richTextEditor object
	this.rteID = id;
	this.html = "";
	this.width = defaultWidth;
	this.height = defaultHeight;
	
	switch( buttons ) {
		case 'advanced':
				this.readOnly = false;
				this.toolbar1 = true;
				this.toolbar2 = true;
				
				this.cmdFormatBlock = true;
				this.cmdFontName = false;
				this.cmdFontSize = false;
				this.cmdIncreaseFontSize = false;
				this.cmdDecreaseFontSize = false;
				
				this.cmdBold = true;
				this.cmdItalic = true;
				this.cmdUnderline = true;
				this.cmdStrikethrough = true;
				this.cmdSuperscript = true;
				this.cmdSubscript = true;
				
				this.cmdJustifyLeft = true;
				this.cmdJustifyCenter = true;
				this.cmdJustifyRight = true;
				this.cmdJustifyFull = true;
				this.cmdOutdent = true;
				this.cmdIndent = true;
				
				this.cmdInsertHorizontalRule = true;
				this.cmdInsertOrderedList = true;
				this.cmdInsertUnorderedList = true;
				
				this.cmdForeColor = false;
				this.cmdHiliteColor = false;
				this.cmdInsertLink = false;
				this.cmdInsertEmail = false;
				this.cmdInsertFile = false;
				this.cmdInsertImage = false;
				this.cmdInsertSpecialChars = false;
				this.cmdInsertTable = false;
				this.cmdSpellcheck = false;
				
				this.cmdCut = false;
				this.cmdCopy = false;
				this.cmdPaste = false;
				this.cmdUndo = false;
				this.cmdRedo = false;
				this.cmdRemoveFormat = false;
				this.cmdUnlink = false;
				
				this.toggleSrc = true;
				break;
				
			case 'medium':
				this.readOnly = false;
				this.toolbar1 = true;
				this.toolbar2 = true;
				
				this.cmdFormatBlock = false;
				this.cmdFontName = false;
				this.cmdFontSize = false;
				this.cmdIncreaseFontSize = false;
				this.cmdDecreaseFontSize = false;
				
				this.cmdBold = true;
				this.cmdItalic = true;
				this.cmdUnderline = true;
				this.cmdStrikethrough = false;
				this.cmdSuperscript = false;
				this.cmdSubscript = false;
				
				this.cmdJustifyLeft = true;
				this.cmdJustifyCenter = true;
				this.cmdJustifyRight = true;
				this.cmdJustifyFull = true;
				this.cmdOutdent = true;
				this.cmdIndent = true;
				
				this.cmdInsertHorizontalRule = true;
				this.cmdInsertOrderedList = true;
				this.cmdInsertUnorderedList = true;
				
				this.cmdForeColor = false;
				this.cmdHiliteColor = false;
				this.cmdInsertLink = false;
				this.cmdInsertEmail = false;
				this.cmdInsertFile = false;
				this.cmdInsertImage = false;
				this.cmdInsertSpecialChars = false;
				this.cmdInsertTable = false;
				this.cmdSpellcheck = false;
				
				this.cmdCut = false;
				this.cmdCopy = false;
				this.cmdPaste = false;
				this.cmdUndo = false;
				this.cmdRedo = false;
				this.cmdRemoveFormat = false;
				this.cmdUnlink = false;
				
				this.toggleSrc = true;
				break;

			case 'basic':
				this.readOnly = false;
				this.toolbar1 = true;
				this.toolbar2 = true;
				
				this.cmdFormatBlock = false;
				this.cmdFontName = false;
				this.cmdFontSize = false;
				this.cmdIncreaseFontSize = false;
				this.cmdDecreaseFontSize = false;
				
				this.cmdBold = true;
				this.cmdItalic = true;
				this.cmdUnderline = true;
				this.cmdStrikethrough = false;
				this.cmdSuperscript = false;
				this.cmdSubscript = false;
				
				this.cmdJustifyLeft = true;
				this.cmdJustifyCenter = true;
				this.cmdJustifyRight = true;
				this.cmdJustifyFull = true;
				this.cmdOutdent = false;
				this.cmdIndent = false;
				
				this.cmdInsertHorizontalRule = false;
				this.cmdInsertOrderedList = false;
				this.cmdInsertUnorderedList = false;
				
				this.cmdForeColor = false;
				this.cmdHiliteColor = false;
				this.cmdInsertLink = false;
				this.cmdInsertEmail = false;
				this.cmdInsertFile = false;
				this.cmdInsertImage = false;
				this.cmdInsertSpecialChars = false;
				this.cmdInsertTable = false;
				this.cmdSpellcheck = false;
				
				this.cmdCut = false;
				this.cmdCopy = false;
				this.cmdPaste = false;
				this.cmdUndo = false;
				this.cmdRedo = false;
				this.cmdRemoveFormat = false;
				this.cmdUnlink = false;
				
				this.toggleSrc = true;
				break;
				
			case 'min':
				this.readOnly = false;
				this.toolbar1 = true;
				this.toolbar2 = true;
				
				this.cmdFormatBlock = false;
				this.cmdFontName = false;
				this.cmdFontSize = false;
				this.cmdIncreaseFontSize = false;
				this.cmdDecreaseFontSize = false;
				
				this.cmdBold = true;
				this.cmdItalic = true;
				this.cmdUnderline = true;
				this.cmdStrikethrough = false;
				this.cmdSuperscript = false;
				this.cmdSubscript = false;
				
				this.cmdJustifyLeft = false;
				this.cmdJustifyCenter = false;
				this.cmdJustifyRight = false;
				this.cmdJustifyFull = false;
				this.cmdOutdent = false;
				this.cmdIndent = false;
				
				this.cmdInsertHorizontalRule = false;
				this.cmdInsertOrderedList = false;
				this.cmdInsertUnorderedList = false;
				
				this.cmdForeColor = false;
				this.cmdHiliteColor = false;
				this.cmdInsertLink = false;
				this.cmdInsertEmail = false;
				this.cmdInsertFile = false;
				this.cmdInsertImage = false;
				this.cmdInsertSpecialChars = false;
				this.cmdInsertTable = false;
				this.cmdSpellcheck = false;
				
				this.cmdCut = false;
				this.cmdCopy = false;
				this.cmdPaste = false;
				this.cmdUndo = false;
				this.cmdRedo = false;
				this.cmdRemoveFormat = false;
				this.cmdUnlink = false;
				
				this.toggleSrc = true;
				break;
				
			case 'clean':
				this.readOnly = false;
				this.toolbar1 = true;
				this.toolbar2 = true;
				
				this.cmdFormatBlock = false;
				this.cmdFontName = false;
				this.cmdFontSize = false;
				this.cmdIncreaseFontSize = false;
				this.cmdDecreaseFontSize = false;
				
				this.cmdBold = true;
				this.cmdItalic = true;
				this.cmdUnderline = true;
				this.cmdStrikethrough = false;
				this.cmdSuperscript = false;
				this.cmdSubscript = false;
				
				this.cmdJustifyLeft = false;
				this.cmdJustifyCenter = false;
				this.cmdJustifyRight = false;
				this.cmdJustifyFull = false;
				this.cmdOutdent = false;
				this.cmdIndent = false;
				
				this.cmdInsertHorizontalRule = false;
				this.cmdInsertOrderedList = false;
				this.cmdInsertUnorderedList = false;
				
				this.cmdForeColor = false;
				this.cmdHiliteColor = false;
				this.cmdInsertLink = false;
				this.cmdInsertEmail = false;
				this.cmdInsertFile = false;
				this.cmdInsertImage = false;
				this.cmdInsertSpecialChars = false;
				this.cmdInsertTable = false;
				this.cmdSpellcheck = false;
				
				this.cmdCut = false;
				this.cmdCopy = false;
				this.cmdPaste = false;
				this.cmdUndo = false;
				this.cmdRedo = false;
				this.cmdRemoveFormat = false;
				this.cmdUnlink = false;
				
				this.toggleSrc = true;
				break;
				
			default:
				this.html = "";
				this.width = defaultWidth;
				this.height = defaultHeight;
				this.readOnly = false;
				this.toolbar1 = true;
				this.toolbar2 = true;
				
				this.cmdFormatBlock = true;
				this.cmdFontName = false;
				this.cmdFontSize = false;
				this.cmdIncreaseFontSize = false;
				this.cmdDecreaseFontSize = false;
				
				this.cmdBold = true;
				this.cmdItalic = true;
				this.cmdUnderline = true;
				this.cmdStrikethrough = false;
				this.cmdSuperscript = false;
				this.cmdSubscript = false;
				
				this.cmdJustifyLeft = true;
				this.cmdJustifyCenter = true;
				this.cmdJustifyRight = true;
				this.cmdJustifyFull = true;
				this.cmdOutdent = true;
				this.cmdIndent = true;
				
				this.cmdInsertHorizontalRule = true;
				this.cmdInsertOrderedList = true;
				this.cmdInsertUnorderedList = true;
				
				this.cmdForeColor = false;
				this.cmdHiliteColor = false;
				this.cmdInsertLink = false;
				this.cmdInsertEmail = false;
				this.cmdInsertFile = false;
				this.cmdInsertImage = false;
				this.cmdInsertSpecialChars = false;
				this.cmdInsertTable = false;
				this.cmdSpellcheck = false;
				
				this.cmdCut = false;
				this.cmdCopy = false;
				this.cmdPaste = false;
				this.cmdUndo = false;
				this.cmdRedo = false;
				this.cmdRemoveFormat = false;
				this.cmdUnlink = false;
				
				this.toggleSrc = true;
				break;
	}
	
	//add methods
	this.build = build;
}

function build() {
	with (this) {
		if (isRichText) {
			if (this.readOnly) {
				this.toolbar1 = false;
				this.toolbar2 = false;
			}
			writeRichText(this);
			enableDesignMode(this.rteID, htmlDecode(this.html), this.readOnly);
			
			if (isGecko) {
				//set focus on the RTE
				//Did not want to set the focus to this automatically
				/*
				currentRTE = this.rteID;
				insertHTML("<br>");
				rteCommand(this.rteID, "undo");
				*/
			}
			
			//uncheck toggle source checkbox
			if (this.toggleSrc) document.getElementById("chkSrc" + this.rteID).checked = false;
		} else {
			writePlainText(this);
		}
	}
}

function writePlainText(rte) {
	if (!rte.readOnly) {
		document.writeln('<textarea name="' + rte.rteID + '" id="' + rte.rteID + '" style="width: ' + rte.width + 'px; height: ' + rte.height + 'px;">' + rte.html + '</textarea>');
	} else {
		document.writeln('<textarea name="' + rte.rteID + '" id="' + rte.rteID + '" style="width: ' + rte.width + 'px; height: ' + rte.height + 'px;" readonly>' + rte.html + '</textarea>');
	}
}

function writeRichText(rte) {
	try {
		if (allRTEs.length > 0) allRTEs += ";";
		allRTEs += rte.rteID;
		
		//option definitions
		var btnAlignCenter = '<td><img class="rteImage" src="' + imagesPath + 'align_center.png" width="16" height="16" alt="Center" title="Center" onclick="rteCommand(\'' + rte.rteID + '\', \'justifycenter\', \'\')"></td>';
		var btnAlignJustify = '<td><img class="rteImage" src="' + imagesPath + 'align_justify.png" width="16" height="16" alt="Justify Full" title="Justify Full" onclick="rteCommand(\'' + rte.rteID + '\', \'justifyfull\', \'\')"></td>';
		var btnAlignLeft = '<td><img class="rteImage" src="' + imagesPath + 'align_left.png" width="16" height="16" alt="Align Left" title="Align Left" onclick="rteCommand(\'' + rte.rteID + '\', \'justifyleft\', \'\')"></td>';
		var btnAlignRight = '<td><img class="rteImage" src="' + imagesPath + 'align_right.png" width="16" height="16" alt="Align Right" title="Align Right" onclick="rteCommand(\'' + rte.rteID + '\', \'justifyright\', \'\')"></td>';
		var btnBold = '<td><img id="bold" class="rteImage" src="' + imagesPath + 'bold.png" width="16" height="16" alt="Bold" title="Bold" onclick="rteCommand(\'' + rte.rteID + '\', \'bold\', \'\')"></td>';
		var btnClean = '<td><img class="rteImage" src="' + imagesPath + 'clean.png" width="16" height="16" alt="Clean HTML" title="Clean HTML" onclick="cleanupHTML(\'' + rte.rteID + '\', false);"></td>';
		var btnCopy = '<td><img class="rteImage" src="' + imagesPath + 'copy.png" width="16" height="16" alt="Copy" title="Copy" onclick="rteCommand(\'' + rte.rteID + '\', \'copy\')"></td>';
		var btnCut = '<td><img class="rteImage" src="' + imagesPath + 'cut.png" width="16" height="16" alt="Cut" title="Cut" onclick="rteCommand(\'' + rte.rteID + '\', \'cut\')"></td>';
		var btnEmail = '<td><img class="rteImage" src="' + imagesPath + 'email.png" width="16" height="16" alt="Insert E-mail Link" title="Insert E-mail Link" onclick="dlgInsertEmail(\'' + rte.rteID + '\')"></td>';
		var btnForeColor = '<td><div id="forecolor_' + rte.rteID + '"><img class="rteImage" src="' + imagesPath + 'forecolor.png" width="16" height="16" alt="Text Color" title="Text Color" onmousedown="dlgColorPalette(\'' + rte.rteID + '\', \'forecolor\', \'\'); return false;"></div></td>';
		var btnHiliteColor = '<td><div id="hilitecolor_' + rte.rteID + '"><img class="rteImage" src="' + imagesPath + 'bgcolor.png" width="16" height="16" alt="Background Color" title="Background Color" onmousedown="dlgColorPalette(\'' + rte.rteID + '\', \'hilitecolor\', \'\'); return false;"></div></td>';
		var btnHr = '<td><img class="rteImage" src="' + imagesPath + 'hr.png" width="16" height="16" alt="Horizontal Rule" title="Horizontal Rule" onclick="rteCommand(\'' + rte.rteID + '\', \'inserthorizontalrule\', \'\')"></td>'
		//OLD COMMAND PROMPT IMAGE INSERTION var btnImage = '<td><img class="rteImage" src="' + imagesPath + 'image.png" width="16" height="16" alt="Add Image" title="Add Image" onclick="addImage(\'' + rte.rteID + '\')"></td>';
		var btnImage = '<td><div id="image_' + rte.rteID + '"><img class="rteImage" src="' + imagesPath + 'image.png" width="16" height="16" alt="Add Image" title="Add Image" onmousedown="dlgInsertImage(\'' + rte.rteID + '\')"></div></td>';
		var btnIndent = '<td><img class="rteImage" src="' + imagesPath + 'indent.png" width="16" height="16" alt="Indent" title="Indent" onclick="rteCommand(\'' + rte.rteID + '\', \'indent\', \'\')"></td>';
		var btnItalic = '<td><img class="rteImage" src="' + imagesPath + 'italic.png" width="16" height="16" alt="Italic" title="Italic" onclick="rteCommand(\'' + rte.rteID + '\', \'italic\', \'\')"></td>';
		var btnLink = '<td><img class="rteImage" src="' + imagesPath + 'link.png" width="16" height="16" alt="Insert Link" title="Insert Link" onclick="dlgInsertLink(\'' + rte.rteID + '\')";></td>';
		var btnOl = '<td><img class="rteImage" src="' + imagesPath + 'ol.png" width="16" height="16" alt="Ordered List" title="Ordered List" onclick="rteCommand(\'' + rte.rteID + '\', \'insertorderedlist\', \'\')"></td>';
		var btnOutdent = '<td><img class="rteImage" src="' + imagesPath + 'outdent.png" width="16" height="16" alt="Outdent" title="Outdent" onclick="rteCommand(\'' + rte.rteID + '\', \'outdent\', \'\')"></td>';
		var btnPaste = '<td><img class="rteImage" src="' + imagesPath + 'paste.png" width="16" height="16" alt="Paste" title="Paste" onclick="rteCommand(\'' + rte.rteID + '\', \'paste\')"></td>';
		var btnRedo = '<td><img class="rteImage" src="' + imagesPath + 'redo.png" width="16" height="16" alt="Redo" title="Redo" onclick="rteCommand(\'' + rte.rteID + '\', \'redo\')"></td>';
		var btnRemoveFormat = '<td><img class="rteImage" src="' + imagesPath + 'remove_format.png" width="16" height="16" alt="Remove Formatting" title="Remove Formatting" onclick="rteCommand(\'' + rte.rteID + '\', \'removeformat\')"></td>';
		var btnSpell = '<td><img class="rteImage" src="' + imagesPath + 'spellcheck.png" width="16" height="16" alt="Spell Check" title="Spell Check" onclick="checkspell()"></td>';
		var btnStrikethrough = '<td><img class="rteImage" src="' + imagesPath + 'strikethrough.png" width="16" height="16" alt="Strikethrough" title="Strikethrough" onmousedown="rteCommand(\'' + rte.rteID + '\', \'strikethrough\', \'\')"></td>';
		var btnSubscript = '<td><img class="rteImage" src="' + imagesPath + 'subscript.png" width="16" height="16" alt="Subscript" title="Sibscript" onmousedown="rteCommand(\'' + rte.rteID + '\', \'subscript\')"></td>';
		var btnSuperscript = '<td><img class="rteImage" src="' + imagesPath + 'superscript.png" width="16" height="16" alt="Superscript" title="Superscript" onmousedown="rteCommand(\'' + rte.rteID + '\', \'superscript\')"></td>';
		var btnSymbol = '<td><img class="rteImage" src="' + imagesPath + 'symbol.png" width="16" height="16" alt="Insert Special Character" title="Insert Special Character" onclick="dlgInsertSpecialChar(\'' + rte.rteID + '\')"></td>';
		var btnTable = '<td><div id="table_' + rte.rteID + '"><img class="rteImage" src="' + imagesPath + 'table.png" width="16" height="16" alt="Insert Table" title="Insert Table" onmousedown="dlgInsertTable(\'' + rte.rteID + '\')"></div></td>';				
		var btnUl = '<td><img class="rteImage" src="' + imagesPath + 'ul.png" width="16" height="16" alt="Unordered List" title="Unordered List" onclick="rteCommand(\'' + rte.rteID + '\', \'insertunorderedlist\', \'\')"></td>';
		var btnUnderline = '<td><img class="rteImage" src="' + imagesPath + 'underline.png" width="16" height="16" alt="Underline" title="Underline" onclick="rteCommand(\'' + rte.rteID + '\', \'underline\', \'\')"></td>';
		var btnUndo = '<td><img class="rteImage" src="' + imagesPath + 'undo.png" width="16" height="16" alt="Undo" title="Undo" onclick="rteCommand(\'' + rte.rteID + '\', \'undo\')"></td>';
		var btnUnlink = '<td><img class="rteImage" src="' + imagesPath + 'unlink.png" width="16" height="16" alt="Remove Link" title="Remove Link" onmousedown="rteCommand(\'' + rte.rteID + '\', \'unlink\')"></td>';
		var btnFile = '<td><img class="rteImage" src="' + imagesPath + 'file.png" width="16" height="16" alt="Insert Document" title="Insert Document" onclick="window.open(\'pop_file.php?element_id=' + rte.rteID + '\',\'admin_pop\',\'width=400,height=400,scrollbars=yes\');"></td>';
		var spacer = '<td><img class="rteVertSep" src="' + imagesPath + 'divider.gif" width="2" height="16" border="0" alt=""></td>';
		
		var optFont = '<td><select id="fontname_' + rte.rteID + '" onchange="selectFont(\'' + rte.rteID + '\', this.id)">';
			optFont += '<option value="">[Font]</option>';
			optFont += '<option value="Arial, Helvetica, sans-serif">Arial</option>';
			optFont += '<option value="Courier New, Courier, mono">Courier New</option>';
			optFont += '<option value="Times New Roman, Times, serif">Times New Roman</option>';
			optFont += '<option value="Verdana, Arial, Helvetica, sans-serif">Verdana</option>';
			optFont += '</select></td>';
		var optSize = '<td><select unselectable="on" id="fontsize_' + rte.rteID + '" onchange="selectFont(\'' + rte.rteID + '\', this.id);">';
			optSize += '<option value="Size">[Size]</option>';
			optSize += '<option value="1">1</option>';
			optSize += '<option value="2">2</option>';
			optSize += '<option value="3">3</option>';
			optSize += '<option value="4">4</option>';
			optSize += '<option value="5">5</option>';
			optSize += '<option value="6">6</option>';
			optSize += '<option value="7">7</option>';
			optSize += '</select></td>';
		var optStyle = '<td><select id="formatblock_' + rte.rteID + '" onchange="selectFont(\'' + rte.rteID + '\', this.id);">';
			optStyle += '<option value="">[Style]</option>';
			optStyle += '<option value="<p>" class="select-p">Normal</option>';
			optStyle += '<option value="<pre>" class="select-code"><pre>Code</pre></option>';
			optStyle += '<option value="<h1>" class="select-h1">Heading 1</option>';
			optStyle += '<option value="<h2>" class="select-h2">Heading 2</option>';
			optStyle += '<option value="<h3>" class="select-h3">Heading 3</option>';
			optStyle += '<option value="<h4>" class="select-h4">Heading 4</option>';
			optStyle += '<option value="<h5>" class="select-h5">Heading 5</option>';
			optStyle += '<option value="<h6>" class="select-h6">Heading 6</option>';
			optStyle += '</select></td>';
		//end button definitions
		
		var s=0;
		document.writeln('<div class="rteDiv" style="width: ' + rte.width + 'px;">');
		document.writeln('<div class="rteTitle">editBox</div>');
		if (toolbar1Enabled && rte.toolbar1) {
			document.writeln('<table class="rteBack" cellpadding="2" cellspacing="0" id="toolbar1_' + rte.rteID + '">');
			document.writeln('<tr>');
			if (cmdFormatBlockEnabled && rte.cmdFormatBlock) { document.writeln(optStyle); s++; }
			if (cmdFontNameEnabled && rte.cmdFontName) { document.writeln(optFont); s++; }
			if (cmdFontSizeEnabled && rte.cmdFontSize) { document.writeln(optSize); s++; }
			if (s>0) { document.writeln(spacer); s=0; }
			if (cmdInsertEmailEnabled && rte.cmdInsertEmail) { document.writeln(btnEmail); s++; }
			if ((cmdInsertHTMLEnabled || cmdCreateLinkEnabled) && rte.cmdInsertLink) { document.writeln(btnLink); s++; }
			if ((cmdInsertHTMLEnabled || cmdCreateLinkEnabled) && rte.cmdInsertLink) { document.writeln(btnUnlink); s++; }
			if (cmdInsertFileEnabled && rte.cmdInsertFile) { document.writeln(btnFile); }
			if (cmdInsertImageEnabled && rte.cmdInsertImage) { document.writeln(btnImage); }
			if (s>0) { document.writeln(spacer); s=0; }
			document.writeln(btnUndo);
			document.writeln(btnRedo);
			document.writeln(btnClean);
			
			document.writeln(spacer);
			
			if (cmdBoldEnabled && rte.cmdBold) { document.writeln(btnBold); s++; }
			if (cmdItalicEnabled && rte.cmdItalic) { document.writeln(btnItalic); s++; }
			if (cmdUnderlineEnabled && rte.cmdUnderline) { document.writeln(btnUnderline); s++; }
			if (cmdStrikethroughEnabled && rte.cmdStrikethrough) { document.writeln(btnStrikethrough); s++; }
			if (cmdSuperscriptEnabled && rte.cmdSuperscript) { document.writeln(btnSuperscript); s++; }
			if (cmdSubscriptEnabled && rte.cmdSubscript) { document.writeln(btnSubscript); s++; }
			if (s>0) { document.writeln(spacer); s=0; }
			if (cmdJustifyLeftEnabled && rte.cmdJustifyLeft) { document.writeln(btnAlignLeft); s++; }
			if (cmdJustifyCenterEnabled && rte.cmdJustifyCenter) { document.writeln(btnAlignCenter); s++; }
			if (cmdJustifyRightEnabled && rte.cmdJustifyRight) { document.writeln(btnAlignRight); s++; }
			if (cmdJustifyFullEnabled && rte.cmdJustifyFull) { document.writeln(btnAlignJustify); s++; }
			if (s>0) { document.writeln(spacer); s=0; }
			if (cmdInsertHorizontalRuleEnabled && rte.cmdInsertHorizontalRule) { document.writeln(btnHr); s++; }
			if (s>0) { document.writeln(spacer); s=0; }
			if (cmdInsertOrderedListEnabled && rte.cmdInsertOrderedList) { document.writeln(btnOl); s++; }
			if (cmdInsertUnorderedListEnabled && rte.cmdInsertUnorderedList) { document.writeln(btnUl); s++; }
			if (s>0) { document.writeln(spacer); s=0; }
			if (cmdOutdentEnabled && rte.cmdOutdent) { document.writeln(btnOutdent); s++; }
			if (cmdIndentEnabled && rte.cmdIndent) { document.writeln(btnIndent); s++; }
			if (cmdForeColorEnabled && rte.cmdForeColor) { document.writeln(btnForeColor); s++; }
			if (cmdHiliteColorEnabled && rte.cmdHiliteColor) { document.writeln(btnHiliteColor); s++; }
			if (cmdUnlinkEnabled && rte.cmdUnlink) { document.writeln(btnUnlink); s++; }
			if (cmdInsertHTMLEnabled && rte.cmdInsertSpecialChars) { document.writeln(btnSymbol); s++; }
			if (s>0) { document.writeln(spacer); s=0; }
			if (cmdInsertHTMLEnabled && rte.cmdInsertTable && !isOpera) { document.writeln(btnTable); s++; }
			if (cmdSpellCheckEnabled && rte.cmdSpellcheck) { document.write(btnSpell); s++; }
			if (cmdCutEnabled && rte.cmdCut) { document.writeln(btnCut); s++; }
			if (cmdCopyEnabled && rte.cmdCopy) { document.writeln(btnCopy); s++; }
			if (cmdPasteEnabled && rte.cmdPaste) { document.writeln(btnPaste); s++; }
			if (cmdRemoveFormatEnabled && rte.cmdRemoveFormat) { document.writeln(btnRemoveFormat); s++; }
			s=0;
			document.writeln('</tr>');
			document.writeln('</table>');
		}
		document.writeln('<iframe id="' + rte.rteID + '" name="' + rte.rteID + '" src="' + includesPath + 'blank.htm" frameborder="0" style="width: ' + (rte.width - 10) + 'px; height: ' + (rte.height - 4) + 'px; margin: 0 2px; padding: 2px;"></iframe>');
		if (!rte.readOnly && rte.toggleSrc)
			document.writeln('<input type="checkbox" class="checkbox" id="chkSrc' + rte.rteID + '" onclick="toggleHTMLSrc(\'' + rte.rteID + '\',' + rte.toolbar1 + ',' + rte.toolbar2 + ');" />&nbsp;<label for="chkSrc' + rte.rteID + '">View Source</label>');
		document.writeln('<input type="hidden" id="hdn' + rte.rteID + '" name="' + rte.rteID + '" value="">');
		document.writeln('</div>');
	} catch (e) {
		if (debugMode) alert(e);
	}
}

function enableDesignMode(rte, html, readOnly) {
	try {
		if (cssFile.length > 0) {
			var frameStyle = "<style type=\"text/css\">@import url(" + cssFile + ");</style>\n";
		} else {
			var frameStyle = "<style type=\"text/css\">\n";
			frameStyle += "body {\n";
			frameStyle += "	background: #FFF;\n";
			frameStyle += "}\n";
			frameStyle += "</style>\n";
		}
		
		var frameHtml = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
		frameHtml += "<html id=\"" + rte + "\" xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\">\n";
		frameHtml += "<head>\n";
		frameHtml += "<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\" />\n";
		frameHtml += "<base href=\"" + baseUrl + "\" />\n";
		frameHtml += frameStyle;
		frameHtml += "</head>\n";
		frameHtml += "<body id=\"rte_body\" style=\"margin: 0; padding: 0;\">\n";
		frameHtml += html + "\n";
		//if (isGecko) frameHtml += frameStyle;
		frameHtml += "</body>\n";
		frameHtml += "</html>";
		
		var oRTE = document.getElementById(rte);
		try {
			if (isGecko) {
				if (!readOnly) oRTE.contentDocument.designMode = "on";
				try {
					var oRTEDoc = oRTE.contentWindow.document;
					oRTEDoc.open("text/html","replace");
					oRTEDoc.write(frameHtml);
					oRTEDoc.close();
					if (!readOnly) oRTEDoc.addEventListener("keypress", geckoKeyPress, true);

					// enable Fx spellchecking (added 2008-06-04 by kfreitas)
					var frameBodyArr = oRTEDoc.getElementsByTagName("body");
					frameBodyArr[0].setAttribute("spellcheck", "true");
				} catch (e) {
					alert("Error preloading content.");
				}
				loopCnt = 0;
			} else if (oRTE.contentWindow) {
				//IE 5.5+
				try {
					var oRTEDoc = oRTE.contentWindow.document;
					oRTEDoc.open("text/html","replace");
					oRTEDoc.write(frameHtml);
					oRTEDoc.close();
					if (!readOnly && isIE) oRTEDoc.attachEvent("onkeypress", evt_ie_keypress);
				} catch (e) {
					alert("Error preloading content.");
				}
				if (!readOnly) oRTEDoc.designMode = "on";
				loopCnt = 0;
			} else {
				//IE5 and Opera
				var oRTEDoc = oRTE.document;
				oRTEDoc.open("text/html","replace");
				oRTEDoc.write(frameHtml);
				oRTEDoc.close();
				if (!readOnly && isIE) oRTEDoc.attachEvent("onkeypress", evt_ie_keypress);
				if (!readOnly) oRTEDoc.designMode = "on";
				loopCnt = 0;
			}
		} catch (e) {
			//some browsers may take some time to enable design mode.
			//Keep looping until able to set.
			if (loopCnt < maxLoops) {
				setTimeout("enableDesignMode('" + rte + "', '" + html + "', " + readOnly + ");", 100);
				loopCnt += 1;
			} else {
				alert("Error enabling designMode.");
			}
		}
	} catch (e) {
		if (debugMode) alert(e);
	}
}

function updateRTE(rte) {
	try {
		if (isRichText) {
			//if viewing source, switch back to design view
			if (document.getElementById("chkSrc" + rte) && document.getElementById("chkSrc" + rte).checked) document.getElementById("chkSrc" + rte).click();
			setHiddenVal(rte);
		} else {
			return;
		}
	} catch (e) {
		if (debugMode) alert(e);
	}
}

function updateRTEs() {
	try {
		if (allRTEs != "") {
			var vRTEs = allRTEs.split(";");
			for (var i = 0; i < vRTEs.length; i++) {
				updateRTE(vRTEs[i]);
			}
		}
	} catch (e) {
		if (debugMode) alert(e);
	}
}

function rteCommand(rte, command, option) {
	//function to perform command
	try {
		var oRTE = document.getElementById(rte);
		if (oRTE.contentWindow) {
			oRTE.contentWindow.focus();
			oRTE.contentWindow.document.execCommand(command, false, option);
		} else {
			oRTE.document.focus();
		  	oRTE.document.execCommand(command, false, option);
		}
		loopCnt = 0;
		
		return false;
	} catch (e) {
		if (debugMode) alert(e);
		//Keep looping until able to set.
		if (loopCnt < maxLoops) {
			setTimeout("rteCommand('" + rte + "', '" + command + "', '" + option + "');", 100);
			loopCnt += 1;
		} else {
			alert("Error executing command.");
		}
	}
}

function dlgColorPalette(rte, command) {
	//function to display or hide color palettes
	try {
		setRange(rte);
		
		//get dialog position
		var buttonElement = document.getElementById(command + '_' + rte);
		var iLeftPos = findPosX(buttonElement);
		var iTopPos = findPosY(buttonElement) + buttonElement.offsetHeight;
		var oDialog = document.getElementById('cp');
		
		oDialog.style.left = iLeftPos + "px";
		oDialog.style.top = iTopPos + "px";
		
		if ((command == lastCommand) && (rte == currentRTE)) {
			//if current command dialog is currently open, close it
			if (oDialog.style.visibility == "hidden") {
				showHideElement('cp', 'show');
			} else {
				showHideElement('cp', 'hide');
			}
		} else {
			showHideElement('cp', 'show');
		}
		
		//save current values
		lastCommand = command;
		currentRTE = rte;
	} catch (e) {
		if (debugMode) alert(e);
	}
}

function dlgInsertTable(rte) {
	//function to open insert table dialog
	try {
		//save current values
		setRange(rte);
		currentRTE = rte;
		InsertTable = popUpWin(includesPath + 'pop_rte_table.php', 'InsertTable', 350, 450, '');
		if (InsertTable) {
			setTimeout("InsertTable.focus()",100);
		} else {
			alert("Error: While Launching New Window...\nYour browser maybe blocking up Popup windows.\n\nPlease check your Popup Blocker Settings");
		}
	} catch (e) {
		if (debugMode) alert(e);
	}
}

function dlgInsertImage(rte) {
	//function to open insert table dialog
	try {
		//save current values
		setRange(rte);
		currentRTE = rte;
		InsertImage = popUpWin(includesPath + 'pop_rte_image.php', 'InsertImage', 650, 600, '');
		if (InsertImage) {
			setTimeout("InsertImage.focus()",100);
		} else {
			alert("Error: While Launching New Window...\nYour browser maybe blocking up Popup windows.\n\nPlease check your Popup Blocker Settings");
		}
	} catch (e) {
		if (debugMode) alert(e);
	}
}

function dlgInsertLink(rte) {
	//function to open insert link dialog
	try {
		if (cmdInsertHTMLEnabled) {
			//save current values
			setRange(rte);
			currentRTE = rte;
			InsertLink = popUpWin(includesPath + 'insert_link.htm?selectionText=' + selectionText, 'InsertLink', 360, 180, '');
			if (InsertLink) {
				setTimeout("InsertLink.focus()",100);
			} else {
				alert("Error: While Launching New Window...\nYour browser maybe blocking up Popup windows.\n\nPlease check your Popup Blocker Settings");
			}
		} else {
			var url = prompt("Enter URL", "http://");
			rteCommand(rte, "createlink", url);
		}
	} catch (e) {
		if (debugMode) alert(e);
	}
}

function dlgInsertEmail(rte) {
	try {
		var szURL = prompt("Enter e-mail:", "");
		szURL = "mailto:" + szURL;
		rteCommand(rte, "createlink", szURL);
	} catch (e) {
		if (debugMode) alert(e);
	}
}

function dlgInsertSpecialChar(rte) {
	//function to open insert special character dialog
	try {
		//save current values
		setRange(rte);
		currentRTE = rte;
		InsertSpecialChar = popUpWin(includesPath + 'insert_special_char.htm', 'InsertSpecialChar', 360, 250, '');
		if (InsertSpecialChar) {
			setTimeout("InsertSpecialChar.focus()",100);
		} else {
			alert("Error: While Launching New Window...\nYour browser maybe blocking up Popup windows.\n\nPlease check your Popup Blocker Settings");
		}
	} catch (e) {
		if (debugMode) alert(e);
	}
}

function popUpWin (url, win, width, height, options) {
	try {
		var leftPos = (screen.availWidth - width) / 2;
		var topPos = (screen.availHeight - height) / 2;
		options += 'width=' + width + ',height=' + height + ',top=' + topPos + ',left=' + leftPos + ',scrollbars=1,resizable=1';
		return window.open(url, win, options);
	} catch (e) {
		if (debugMode) alert(e);
	}
}

function setColor(color) {
	//function to set color
	try {
		var rte = currentRTE;
		if (isSafari || isIE) {
			if (lastCommand == "hilitecolor") lastCommand = "backcolor";
			
			//retrieve selected range
			if (!isSafari) rng.select();
		}
		
		rteCommand(rte, lastCommand, color);
		showHideElement('cp', "hide");
	} catch (e) {
		if (debugMode) alert(e);
	}
}

function addImage(rte) {
	//function to add image
	try {
		imagePath = prompt('Enter Image URL:', 'http://');
		if ((imagePath != null) && (imagePath != "")) {
			rteCommand(rte, 'InsertImage', imagePath);
		}
	} catch (e) {
		if (debugMode) alert(e);
	}
}

//positioning functions courtesy of Peter-Paul Koch - http://www.quirksmode.org/
function findPosX(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft;
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft;
		}
	}
	return curleft;
}

function findPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		curtop = obj.offsetTop;
		while (obj = obj.offsetParent) {
			curtop += obj.offsetTop;
		}
	}
	return curtop;
}

function selectFont(rte, selectname) {
	//function to handle font changes
	try {
		var idx = document.getElementById(selectname).selectedIndex;
		// First one is always a label
		if (idx != 0) {
			var selected = document.getElementById(selectname).options[idx].value;
			var cmd = selectname.replace('_' + rte, '');
			rteCommand(rte, cmd, selected);
			document.getElementById(selectname).selectedIndex = 0;
		}
	} catch (e) {
		if (debugMode) alert(e);
	}
}

function insertHTML(html,rte_update) {
	//function to add HTML -- thanks dannyuk1982
	try {
		if (document.all && !isOpera) {
			rng.pasteHTML(html);
			rng.collapse(false);
			rng.select();
		} else {
			rteCommand(currentRTE, 'inserthtml', html);
			if( rte_update == 'update' ) {
				rteUpdateLinks();
			}
		}
		
	} catch (e) {
		if (debugMode) alert(e);
	}
}

function rteUpdateLinks() {
	var iframe_content = frames[currentRTE].document.getElementById('rte_body').innerHTML;
	iframe_content = iframe_content.replace('../',absPath);
	frames[currentRTE].document.getElementById('rte_body').innerHTML = iframe_content;
}

function showHideElement(element, showHide) {
	//function to show or hide elements
	try {
		//element variable can be string or object
		if (document.getElementById(element)) {
			element = document.getElementById(element);
			if (showHide == "show") {
				if (element.id.substring(0,7) == "toolbar") element.style.display = "block";
				element.style.visibility = "visible";
			} else if (showHide == "hide") {
				if (element.id.substring(0,7) == "toolbar") element.style.display = "none";
				element.style.visibility = "hidden";
			}
		}
	} catch (e) {
		if (debugMode) alert(e);
	}
}

function setRange(rte) {
	//function to store range of current selection
	try {
		var oRTE = document.getElementById(rte);
		if (oRTE.contentWindow) {
			var oRTEDoc = oRTE.contentWindow.document;
			oRTE.contentWindow.focus();
		} else {
			var oRTEDoc = oRTE.document;
			oRTEDoc.focus();
		}
		
		if (document.all) {
			sel = oRTEDoc.selection;
			rng = sel.createRange();
			if (encodeHTML) {
				selectionText = htmlEncode(rng.text.toString());
			} else {
				selectionText = rng.text.toString();
			}
		} else if (document.getSelection) {
			rng = oRTEDoc.createRange();
			if (encodeHTML) {
				selectionText = htmlEncode(oRTEDoc.getSelection());
			} else {
				selectionText = oRTEDoc.getSelection();
			}
		}
	} catch (e) {
		if (debugMode) alert(e);
	}
}

function stripHTML(oldString) {
	//function to strip all html
	try {
		var newString = oldString.replace(/(<([^>]+)>)/ig,"");
		
		//replace carriage returns and line feeds
	   newString = newString.replace(/\r\n/g," ");
	   newString = newString.replace(/\n/g," ");
	   newString = newString.replace(/\r/g," ");
		
		//trim string
		newString = trim(newString);
		
		return newString;
	} catch (e) {
		if (debugMode) alert(e);
	}
}

function trim(sInString) {
	//removes leading and trailing spaces from the passed string
	try {
		sInString = sInString.replace(/^\s+/g, "");
		return sInString.replace(/\s+$/g, "");
	} catch (e) {
		if (debugMode) alert(e);
	}
}

function cleanWordContent(wordContent) {
	//found at http://blogs.speerio.net/peerio/
//	wordDiv = document.createElement("DIV");
//	wordDiv.innerHTML = wordContent;
//	for (var i = 0; i < wordDiv.all.length; i++) {
//		wordDiv.all[i].removeAttribute("className","",0);
//		wordDiv.all[i].removeAttribute("style","",0);
//	}
//	wordContent = wordDiv.innerHTML;
	
	wordContent = String(wordContent).replace(/<\\?\?xml[^>]*>/g,"");
	wordContent = String(wordContent).replace(/<\/?o:p[^>]*>/g,"");
	wordContent = String(wordContent).replace(/<\/?v:[^>]*>/g,"");
	wordContent = String(wordContent).replace(/<\/?o:[^>]*>/g,"");
//	wordContent = String(wordContent).replace(/&nbsp;/g,"");//<p>&nbsp;</p>
//	wordContent = String(wordContent).replace(/<\/?SPAN[^>]*>/g,"");
//	wordContent = String(wordContent).replace(/<\/?FONT[^>]*>/g,"");
//	wordContent = String(wordContent).replace(/<\/?STRONG[^>]*>/g,"");
//	wordContent = String(wordContent).replace(/<\/?P[^>]*><\/P>/g,"");
//	wordContent = String(wordContent).replace(/<\/?H1[^>]*>/g,"");
//	wordContent = String(wordContent).replace(/<\/?H2[^>]*>/g,"");
//	wordContent = String(wordContent).replace(/<\/?H3[^>]*>/g,"");
//	wordContent = String(wordContent).replace(/<\/?H4[^>]*>/g,"");
//	wordContent = String(wordContent).replace(/<\/?H5[^>]*>/g,"");
//	wordContent = String(wordContent).replace(/<\/?H6[^>]*>/g,"");
	
	return wordContent;
}

function toggleHTMLSrc(rte, toolbar1, toolbar2) {
	//contributed by Bob Hutzel (thanks Bob!)
	try {
		var oHdnField = document.getElementById('hdn' + rte);
		var oRTE = document.getElementById(rte);
		if (oRTE.contentWindow) {
			var oRTEDoc = oRTE.contentWindow.document;
		} else {
			var oRTEDoc = oRTE.document;
		}
		
		if (document.getElementById("chkSrc" + rte).checked) {
			//we are checking the box, show source
			if (toolbar1) showHideElement("toolbar1_" + rte, "hide");
			if (toolbar2) showHideElement("toolbar2_" + rte, "hide");
			setHiddenVal(rte);
			if (encodeHTML) {
				var htmlSrc = oRTEDoc.createTextNode(htmlDecode(oHdnField.value));
			} else {
				var htmlSrc = oRTEDoc.createTextNode(oHdnField.value);
			}
			oRTEDoc.body.innerHTML = "";
			oRTEDoc.body.appendChild(htmlSrc);
		} else {
			//we are unchecking the box, show rich text
			if (toolbar1) showHideElement("toolbar1_" + rte, "show");
			if (toolbar2) showHideElement("toolbar2_" + rte, "show");
			
			if (isIE) {
				var htmlSrc = oRTEDoc.body.innerText;
			} else {
				var htmlSrc = oRTEDoc.body.ownerDocument.createRange();
				htmlSrc.selectNodeContents(oRTEDoc.body);
				htmlSrc = htmlSrc.toString();
			}
			setHtmlSrc(rte, htmlSrc);
		}
	} catch (e) {
		if (debugMode) alert(e);
	}
}

function setHiddenVal(rte) {
	//set hidden form field value for current rte
	try {
		var oHdnField = document.getElementById('hdn' + rte);
		//console.log(oHdnField);
		if (oHdnField.value == null) oHdnField.value = "";
		
		var html = getHtmlSrc(rte);
		html = cleanWordContent(html);
		
		if (generateXHTML) {
			//convert html output to xhtml (thanks Jacob Lee!)
			html = getXHTML(html);	
		}
		
		//if there is no content (other than formatting) set value to nothing
		if (stripHTML(html.replace("&nbsp;", " ")) == "" &&
			html.toLowerCase().search("<hr") == -1 &&
			html.toLowerCase().search("<img") == -1) html = "";
		
		if (encodeHTML) {
			oHdnField.value = htmlEncode(html);
		} else {
			oHdnField.value = html;
		}
	} catch (e) {
		if (debugMode) alert(e);
	}
}

function getHtmlSrc(rte) {
	try {
		var oRTE = document.getElementById(rte);
		if (oRTE.contentWindow) {
			var oRTEDoc = oRTE.contentWindow.document;
		} else {
			var oRTEDoc = oRTE.document;
		}
		return oRTEDoc.body.innerHTML;
	} catch (e) {
		if (debugMode) alert(e);
	}
}

function setHtmlSrc(rte, html) {
	try {
		var oRTE = document.getElementById(rte);
		if (oRTE.contentWindow) {
			var oRTEDoc = oRTE.contentWindow.document;
		} else {
			var oRTEDoc = oRTE.document;
		}
		if (isIE) { //fix for IE
			var output = htmlEncode(html);
			output = output.replace("%3CP%3E%0D%0A%3CHR%3E", "%3CHR%3E");
			output = output.replace("%3CHR%3E%0D%0A%3C/P%3E", "%3CHR%3E");
			oRTEDoc.body.innerHTML = htmlDecode(output);
		} else {
			oRTEDoc.body.innerHTML = html;
		}
	} catch (e) {
		if (debugMode) alert(e);
	}
}

function htmlEncode(text) {
	return text.replace(/\&/ig,  '&amp;').replace(/\</ig,  '&lt;').replace(/\>/ig,  '&gt;').replace(/\"/ig,  '&quot;');
}

function htmlDecode(text) {
	return text.replace(/\&amp\;/ig,  '&').replace(/\&lt\;/ig,  '<').replace(/\&gt\;/ig,  '>').replace(/\&quot\;/ig,  '"');
}

// webkit.org webkit detection scripts
function parse_webkit_version(version) {
	try {
		var bits = version.split(".");
		var is_nightly = (version[version.length - 1] == "+");
		if (is_nightly) {
			var minor = "+";
		} else {
			var minor = parseInt(bits[1]);
			// If minor is Not a Number (NaN) return an empty string
			if (isNaN(minor)) {
				minor = "";
			}
		}
		return {major: parseInt(bits[0]), minor: minor, is_nightly: is_nightly};
	} catch (e) {
		if (debugMode) alert(e);
	}
}

function get_webkit_version() {
	try {
		var regex = new RegExp("\\(.*\\) AppleWebKit/(.*) \\((.*)");
		var matches = regex.exec(navigator.userAgent);
		if (matches) {
			var webkit_version = parse_webkit_version(matches[1]);    
		} 
		return {major: webkit_version['major'], minor: webkit_version['minor'], is_nightly: webkit_version['is_nightly']};
	} catch (e) {
		//if (debugMode) alert(e);
	}
}

//********************
//Gecko-Only Functions
//********************
function geckoKeyPress(evt) {
	//function to add bold, italic, and underline shortcut commands to gecko RTEs
	//contributed by Anti Veeranna (thanks Anti!)
	try {
		var rte = evt.target.id;
		
		if (evt.ctrlKey) {
			var key = String.fromCharCode(evt.charCode).toLowerCase();
			var cmd = '';
			switch (key) {
				case 'b': cmd = "bold"; break;
				case 'i': cmd = "italic"; break;
				case 'u': cmd = "underline"; break;
			};
	
			if (cmd) {
				rteCommand(rte, cmd);
				
				// stop the event bubble
				evt.preventDefault();
				evt.stopPropagation();
			}
	 	}
	} catch (e) {
		if (debugMode) alert(e);
	}
}

//*****************
//IE-Only Functions
//*****************
function evt_ie_keypress(event) {
	try {
		ieKeyPress(event, rte);
	} catch (e) {
		if (debugMode) alert(e);
	}
} 

function ieKeyPress(evt, rte) {
	try {
		var key = (evt.which || evt.charCode || evt.keyCode);
		var stringKey = String.fromCharCode(key).toLowerCase();
		
		//the following breaks list and indentation functionality in IE (don't use)
		//	switch (key) {
		//		case 13:
		//			//insert <br> tag instead of <p>
		//			//change the key pressed to null
		//			evt.keyCode = 0;
		//			
		//			//insert <br> tag
		//			currentRTE = rte;
		//			insertHTML('<br>');
		//			break;
		//	};
	} catch (e) {
		if (debugMode) alert(e);
	}
}

function checkspell() {
	//function to perform spell check
	try {
		var tmpis = new ActiveXObject("ieSpell.ieSpellExtension");
		tmpis.CheckAllLinkedDocuments(document);
	} catch(e) {
		if(e.number==-2146827859) {
			if (confirm("ieSpell not detected.  Click Ok to go to download page."))
				window.open("http://www.iespell.com/download.php","DownLoad");
		} else {
			alert("Error Loading ieSpell: Exception " + e.number);
		}
	}
}

function raiseButton(e) {
	try {
		var el = window.event.srcElement;
		
		className = el.className;
		if (className == 'rteImage' || className == 'rteImageLowered') {
			el.className = 'rteImageRaised';
		}
	} catch (e) {
		if (debugMode) alert(e);
	}
}

function normalButton(e) {
	try {
		var el = window.event.srcElement;
		
		className = el.className;
		if (className == 'rteImageRaised' || className == 'rteImageLowered') {
			el.className = 'rteImage';
		}
	} catch (e) {
		if (debugMode) alert(e);
	}
}

function lowerButton(e) {
	try {
		var el = window.event.srcElement;
		
		className = el.className;
		if (className == 'rteImage' || className == 'rteImageRaised') {
			el.className = 'rteImageLowered';
		}
	} catch (e) {
		if (debugMode) alert(e);
	}
}




/***********************************************************
* SITECRAFTING FUNCTIONS
***********************************************************/
//Function Insert Link
function insert_rte_link(rte, szURL, blnTargetNew, parent_window, is_internal)
{
	var oRTE;
	
	var tmp;
	
	//if external link does not start with http:// then add it
	if( szURL.substring(0,5) != "http" && is_internal == false )
	{
		szURL = "http://" + szURL;
		
	}	//end if
	
	if (document.all) 
	{
		oRTE = parent_window.frames[rte];
		
		oRTE.focus();
		
		//get current selected range
		var selection = oRTE.document.selection; 
		
		if (selection != null) 
		{
			rng = selection.createRange();
			
		}	//end if
		
		//var rng = oRTE.document.selection.createRange();
		
	}	//end if 
	
	else 
	{
		oRTE = parent_window.document.getElementById(rte).contentWindow;
		
		oRTE.focus();
		
		//get currently selected range
		var selection = oRTE.getSelection();
		
		//rng = selection.getRangeAt(selection.rangeCount - 1).cloneRange();
		
		rng = selection.getRangeAt(selection.rangeCount - 1).cloneRange();
		
	}	//end else
	
	//start the link
	tmp = "<a href='" + szURL + "'";
	
	//if target new, then add
	if( blnTargetNew )
	{
		tmp = tmp + " target='_blank'";
		
	}	//end if
	
	isIE = document.all;
	
	strDisplayName = rng.text;
	
	//add the new link to the selected text
	if (isIE)
	{
		//close the 
		tmp = tmp + ">" + rng.text + "</a>";
		
		strDisplayName = rng.text;
		
		//alert( 'document.all: ' + tmp );
	
		try 
		{
   			rng.pasteHTML(tmp);
		
			rng.collapse(false);
			
			rng.select();
   			
		}	//end try
		
		catch (e)
		{
			alert(e);
			
		}	//end catch
   		
   	}	//end else
   	
   	else
   	{
   		//alert( 'else: ' + tmp );
	
		tmp = tmp + ">" + rng + "</a>";
   		
   		try 
		{
   			oRTE.document.execCommand('insertHTML', false, tmp);
   			
		}	//end try
		
		catch (e)
		{
			//do nothing
			alert(e);
			
		}	//end catch
		
   	}	//end else
   	
}	//end Function

function stripHTML(oldString) {
	var newString = oldString.replace(/(<([^>]+)>)/ig,"");
	
	//replace carriage returns and line feeds
   newString = newString.replace(/\r\n/g," ");
   newString = newString.replace(/\n/g," ");
   newString = newString.replace(/\r/g," ");
	
	//trim string
	newString = trim(newString);
	
	return newString;
}

function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") return inputString;
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
	
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length - 1, retValue.length);
	
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length - 1);
      ch = retValue.substring(retValue.length - 1, retValue.length);
   }
	
	// Note that there are two spaces in the string - look for multiple spaces within the string
   while (retValue.indexOf("  ") != -1) {
		// Again, there are two spaces in each of the strings
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ") + 1, retValue.length);
   }
   return retValue; // Return the trimmed string back to the user
}

function cleanupHTML(rte, displayMessage) 
{
	var oRTE;
   
	if (document.all) 
   	{
    	oRTE = frames[rte].document;
   
   	}	//end else
   
   	else 
   	{
    	oRTE = document.getElementById(rte).contentWindow.document;
   
   	}	//end else
   
   	//if viewing source, switch back to design view
   	if (document.getElementById("chkSrc" + rte).checked) 
   	{
    	document.getElementById("chkSrc" + rte).checked = false;
   
		toggleHTMLSrc(rte);
   
	}	//end if
   
	// get text and strip out nbsps which is not done by trim()
   	var oldString = oRTE.body.innerHTML;
   
   	var newString = oldString.replace(/&nbsp;/ig, " ");
   
   	// change allowed tags
   	var r1 = "@open@";
   
	var r2 = "@close@";
   
	// a href
   	newString = newString.replace(/<a\b[^>]+href=['"]([^>]+)['"][^>]*>/ig, r1 + 'a href="$1"' + r2);
   
   	// simple tags
   	var allowedTags = new Array("a", "b", "strong", "i", "em", "h2", "h3", "p", "br", "ol", "ul", "li", "table", "tr", "td", "th", "img", "src", "title", "alt");
   
   	for (var i=0; i<allowedTags.length; i++) 
   	{
    	var reg = new RegExp("<(\\/?)" + allowedTags[i] + "\\b([^>]*)>", "ig");
   
   		newString = newString.replace(reg, r1 + '$1' + allowedTags[i] + r2);
   
	}	//end for loop
   
   	// font, span
   	newString = replaceSpans(newString, "span", "bold", "strong", r1, r2);
   
	newString = replaceSpans(newString, "span", "italic", "em", r1, r2);
   
	newString = replaceSpans(newString, "font", "bold", "strong", r1, r2);
   
	newString = replaceSpans(newString, "font", "italic", "em", r1, r2);
   
	// strip HTML out and fix allowed tags
   	newString = stripHTML(newString);
   	
	newString = newString.replace(/@open@/g, "<");

	newString = newString.replace(/@close@/g, ">");
	
	// write text back
	oRTE.body.innerHTML = newString;
   
	// display message
	if (displayMessage == true) alert("Cleanup done");
   
}	//end function

function replaceSpans(plain, oldTag, property, newTag, r1, r2) 
{
	var start, end, s, before, here, after, neu;
   
	start = '<' + oldTag; // kann auch global sein
   
	end = '</' + oldTag + '>'; // kann auch global sein
   
	s = plain.search(start);
   
	if (s==-1) return plain;
   
	before = plain.substring(0, s);
   
	here = plain.substr(s);
   
	s = here.search(end);
   
	if (s==-1) s = here.length-1;
   
	after = here.substr(s + end.length);
   
	here = here.substring(0, s + end.length);
   
	var reg = new RegExp("(^<" + oldTag + "\\b[^>]+[\'\"][^>]*" + property + "[^>]*[\'\"][^>]*>)", "i");
   
	if (matsch = here.match(reg))
    	neu = r1 + newTag + r2
        	  + here.substring(matsch[0].length, here.length-end.length)
         	  + r1 + '/' + newTag + r2;
   
	else neu = here;
   
	after = replaceSpans(after, oldTag, property, newTag, r1, r2);
   
	return before + neu + after;
   
}	//end function

function insert_rte_code(rte)
{
	var oRTE;
	
	var tmp;
	
	if (document.all) 
	{
		oRTE = frames[rte];
		
		oRTE.focus();
		
		//get current selected range
		var selection = oRTE.document.selection; 
		
		if (selection != null) 
		{
			rng = selection.createRange();
			
		}	//end if
		
		//var rng = oRTE.document.selection.createRange();
		
	}	//end if 
	
	else 
	{
		oRTE = document.getElementById(rte).contentWindow;
		
		oRTE.focus();
		
		//get currently selected range
		var selection = oRTE.getSelection();
		
		//rng = selection.getRangeAt(selection.rangeCount - 1).cloneRange();
		rng = selection.getRangeAt(selection.rangeCount - 1).cloneRange();
		alert(rng.parentNode);
		
	}	//end else
	
	isIE = document.all;
	
	strDisplayName = rng.text;
	
	//add the new link to the selected text
	if (isIE)
	{
		//start the link
		if( toString(rng.text).substring(0,6) == '<code>') {
			tmp = rng.text;
		}
		else {
			tmp = "<code>" + rng.text + "</code>";
		}
		
		strDisplayName = rng.text;
		
		//alert( 'document.all: ' + tmp );
	
		try 
		{
   			rng.pasteHTML(tmp);
		
			rng.collapse(false);
			
			rng.select();
   			
		}	//end try
		
		catch (e)
		{
			alert(e);
			
		}	//end catch
   		
   	}	//end else
   	
   	else
   	{
		if( toString(rng).substring(0,6) == '<code>') {
			tmp = "</code>" + rng + "</code>";
		}
		else {
			tmp = "<code>" + rng + "</code>";
		}
	
   		try 
		{
   			oRTE.document.execCommand('insertHTML', false, tmp);
   			
		}	//end try
		
		catch (e)
		{
			//do nothing
			alert(e);
			
		}	//end catch
		
   	}	//end else
   	
}	//end Function

/*
Html2Xhtml : Javascript Mini HTML to XHTML Parser 
--------------------------------------------------

Copyright ¨Ï 2006 All rights reserved. Jacob Lee <letsgolee@lycos.co.kr>

Free for noncommercial && commercial use.
*/
function getXHTML(data){return new Html2Xhtml(data).parse()};function Html2Xhtml(data){this.data=data||''};Html2Xhtml.prototype.setHTML=function(data){this.data=data||this.data};Html2Xhtml.prototype.parse=function(){var state=0;var xhtml='';var p=0;var unget=false;var tagname='';var attrname='';var attrval='';var quot='';var data=this.data;var len=data.length;var phpval='';var tagtype=0;var insidepre=false;while(1){if(p>=len&&!unget){return xhtml}if(unget){unget=false}else{var c=data.substr(p++,1)}switch(state){case 0:if(c=='<'){state=1;break}var cc=c.charCodeAt();if(Html2Xhtml.charEntities[cc]){xhtml+='&'+Html2Xhtml.charEntities[cc]+';'}else{xhtml+=c}break;case 1:if(/[a-zA-Z]/.test(c)){state=2;tagtype=1;tagname=c.toLowerCase();break}if(c=='/'){state=2;tagtype=-1;break}if(c=='!'){if(data.substr(p,2)=='--'){xhtml+='<!--';p+=2;state=9;break}xhtml+='<!';state=10;break}if(c=='?'){state=11;xhtml+='<'+'?';break}xhtml+='&lt;';unget=true;state=0;break;case 2:if(Html2Xhtml.isSpaceChar[c]){xhtml+=(!insidepre&&tagtype>0&&Html2Xhtml.hasNLBefore[tagname]&&xhtml.length&&xhtml.substr(xhtml.length-1,1)!='\n'?'\n':'')+(tagtype>0?'<':'</')+tagname;state=3;break}if(c=='/'){xhtml+=(!insidepre&&tagtype>0&&Html2Xhtml.hasNLBefore[tagname]&&xhtml.length&&xhtml.substr(xhtml.length-1,1)!='\n'?'\n':'')+(tagtype>0?'<':'</')+tagname;if(data.substr(p,1)!='>'){state=3;break}state=4;break}if(c=='>'){xhtml+=(!insidepre&&tagtype>0&&Html2Xhtml.hasNLBefore[tagname]&&xhtml.length&&xhtml.substr(xhtml.length-1,1)!='\n'?'\n':'')+(tagtype>0?'<':'</')+tagname;unget=true;state=4;break}tagname+=c.toLowerCase();break;case 3:if(Html2Xhtml.isSpaceChar[c]){break}if(c=='/'){if(data.substr(p,1)!='>'){break}state=4;break}if(c=='>'){unget=true;state=4;break}attrname=c.toLowerCase();attrval='';state=5;break;case 4:xhtml+=(Html2Xhtml.isEmptyTag[tagname]?' />':'>')+(!insidepre&&tagtype<0&&Html2Xhtml.hasNLAfter[tagname]&&p<len&&data.substr(p,1)!='\n'?'\n':'');if(tagtype>0&&Html2Xhtml.dontAnalyzeContent[tagname]){state=13;attrname=attrval=quot='';tagtype=0;break}if(tagname=='pre'){insidepre=!insidepre}state=0;tagname=attrname=attrval=quot='';tagtype=0;break;case 5:if(Html2Xhtml.isSpaceChar[c]){xhtml+=' '+attrname;if(Html2Xhtml.isEmptyAttr[attrname]){xhtml+='="'+attrname+'"'}state=3;break}if(c=='/'){xhtml+=' '+attrname;if(Html2Xhtml.isEmptyAttr[attrname]){xhtml+='="'+attrname+'"'}if(data.substr(p,1)!='>'){state=3;break}state=4;break}if(c=='>'){xhtml+=' '+attrname;if(Html2Xhtml.isEmptyAttr[attrname]){xhtml+='="'+attrname+'"'}unget=true;state=4;break}if(c=='='){xhtml+=' '+attrname+'=';state=6;break}if(c=='"'||c=="'"){attrname+='?'}else{attrname+=c.toLowerCase()}break;case 6:if(Html2Xhtml.isSpaceChar[c]){xhtml+=(Html2Xhtml.isEmptyAttr[attrname]?'"'+attrname+'"':'""');state=3;break}if(c=='>'){xhtml+=(Html2Xhtml.isEmptyAttr[attrname]?'"'+attrname+'"':'""');unget=true;state=4;break}if(c=='/'&&data.substr(p,1)=='>'){xhtml+=(Html2Xhtml.isEmptyAttr[attrname]?'"'+attrname+'"':'""');state=4;break}if(c=='"'||c=="'"){quot=c;state=8;break}attrval=c;state=7;break;case 7:if(Html2Xhtml.isSpaceChar[c]){xhtml+='"'+Html2Xhtml.escapeQuot(attrval,'"')+'"';state=3;break}if(c=='/'&&data.substr(p,1)=='>'){xhtml+='"'+Html2Xhtml.escapeQuot(attrval,'"')+'"';state=4;break}if(c=='>'){unget=true;xhtml+='"'+Html2Xhtml.escapeQuot(attrval,'"')+'"';state=4;break}attrval+=c;break;case 8:if(c==quot){xhtml+='"'+Html2Xhtml.escapeQuot(attrval,'"')+'"';state=3;break}attrval+=c;break;case 9:if(c=='-'&&data.substr(p,2)=='->'){p+=2;xhtml+='-->';state=0;break}xhtml+=c;break;case 10:if(c=='>'){state=0}xhtml+=c;break;case 11:if(c=="'"||c=='"'){quot=c;state=12;break}if(c=='?'&&data.substr(p,1)=='>'){state=0;xhtml+='?'+'>';p++;break}xhtml+=c;break;case 12:if(c==quot){state=11;xhtml+=quot+Html2Xhtml.escapeQuot(phpval,quot)+quot;phpval=quot='';break}phpval+=c;break;case 13:if(c=='<'&&data.substr(p,tagname.length+1).toLowerCase()=='/'+tagname){unget=true;state=0;tagname='';break}if(tagname=='textarea'){xhtml+=Html2Xhtml.escapeHTMLChar(c)}else{xhtml+=c}break}}return xhtml};Html2Xhtml.escapeQuot=function(str,quot){if(!quot){quot='"'}if(quot=='"'){return str.replace(/"/ig,'\\"')}return str.replace(/'/ig,"\\'")};Html2Xhtml.escapeHTMLChar=function(c){if(c=='&'){return'&amp;'}if(c=='<'){return'&lt;'}if(c=='>'){return'&gt;'}var cc=c.charCodeAt();if(Html2Xhtml.charEntities[cc]){return'&'+Html2Xhtml.charEntities[cc]+';'}else{return c}};Html2Xhtml.isSpaceChar={' ':1,'\r':1,'\n':1,'\t':1};Html2Xhtml.isEmptyTag={'area':1,'base':1,'basefont':1,'br':1,'hr':1,'img':1,'input':1,'link':1,'meta':1,'param':1};Html2Xhtml.isEmptyAttr={'checked':1,'compact':1,'declare':1,'defer':1,'disabled':1,'ismap':1,'multiple':1,'noresize':1,'nosave':1,'noshade':1,'nowrap':1,'readonly':1,'selected':1};Html2Xhtml.hasNLBefore={'div':1,'p':1,'table':1,'tbody':1,'tr':1,'td':1,'th':1,'title':1,'head':1,'body':1,'script':1,'comment':1,'li':1,'meta':1,'h1':1,'h2':1,'h3':1,'h4':1,'h5':1,'h6':1,'hr':1,'ul':1,'ol':1,'option':1,'link':1};Html2Xhtml.hasNLAfter={'html':1,'head':1,'body':1,'p':1,'th':1,'style':1};Html2Xhtml.dontAnalyzeContent={'textarea':1,'script':1,'style':1};Html2Xhtml.charEntities={160:'nbsp',161:'iexcl',162:'cent',163:'pound',164:'curren',165:'yen',166:'brvbar',167:'sect',168:'uml',169:'copy',170:'ordf',171:'laquo',172:'not',173:'shy',174:'reg',175:'macr',176:'deg',177:'plusmn',178:'sup2',179:'sup3',180:'acute',181:'micro',182:'para',183:'middot',184:'cedil',185:'sup1',186:'ordm',187:'raquo',188:'frac14',189:'frac12',190:'frac34',191:'iquest',192:'agrave',193:'aacute',194:'acirc',195:'atilde',196:'auml',197:'aring',198:'aelig',199:'ccedil',200:'egrave',201:'eacute',202:'ecirc',203:'euml',204:'igrave',205:'iacute',206:'icirc',207:'iuml',208:'eth',209:'ntilde',210:'ograve',211:'oacute',212:'ocirc',213:'otilde',214:'ouml',215:'times',216:'oslash',217:'ugrave',218:'uacute',219:'ucirc',220:'uuml',221:'yacute',222:'thorn',223:'szlig',224:'agrave',225:'aacute',226:'acirc',227:'atilde',228:'auml',229:'aring',230:'aelig',231:'ccedil',232:'egrave',233:'eacute',234:'ecirc',235:'euml',236:'igrave',237:'iacute',238:'icirc',239:'iuml',240:'eth',241:'ntilde',242:'ograve',243:'oacute',244:'ocirc',245:'otilde',246:'ouml',247:'divide',248:'oslash',249:'ugrave',250:'uacute',251:'ucirc',252:'uuml',253:'yacute',254:'thorn',255:'yuml',338:'oelig',339:'oelig',352:'scaron',353:'scaron',376:'yuml',710:'circ',732:'tilde',8194:'ensp',8195:'emsp',8201:'thinsp',8204:'zwnj',8205:'zwj',8206:'lrm',8207:'rlm',8211:'ndash',8212:'mdash',8216:'lsquo',8217:'rsquo',8218:'sbquo',8220:'ldquo',8221:'rdquo',8222:'bdquo',8224:'dagger',8225:'dagger',8240:'permil',8249:'lsaquo',8250:'rsaquo',8364:'euro',402:'fnof',913:'alpha',914:'beta',915:'gamma',916:'delta',917:'epsilon',918:'zeta',919:'eta',920:'theta',921:'iota',922:'kappa',923:'lambda',924:'mu',925:'nu',926:'xi',927:'omicron',928:'pi',929:'rho',931:'sigma',932:'tau',933:'upsilon',934:'phi',935:'chi',936:'psi',937:'omega',945:'alpha',946:'beta',947:'gamma',948:'delta',949:'epsilon',950:'zeta',951:'eta',952:'theta',953:'iota',954:'kappa',955:'lambda',956:'mu',957:'nu',958:'xi',959:'omicron',960:'pi',961:'rho',962:'sigmaf',963:'sigma',964:'tau',965:'upsilon',966:'phi',967:'chi',968:'psi',969:'omega',977:'thetasym',978:'upsih',982:'piv',8226:'bull',8230:'hellip',8242:'prime',8243:'prime',8254:'oline',8260:'frasl',8472:'weierp',8465:'image',8476:'real',8482:'trade',8501:'alefsym',8592:'larr',8593:'uarr',8594:'rarr',8595:'darr',8596:'harr',8629:'crarr',8656:'larr',8657:'uarr',8658:'rarr',8659:'darr',8660:'harr',8704:'forall',8706:'part',8707:'exist',8709:'empty',8711:'nabla',8712:'isin',8713:'notin',8715:'ni',8719:'prod',8721:'sum',8722:'minus',8727:'lowast',8730:'radic',8733:'prop',8734:'infin',8736:'ang',8743:'and',8744:'or',8745:'cap',8746:'cup',8747:'int',8756:'there4',8764:'sim',8773:'cong',8776:'asymp',8800:'ne',8801:'equiv',8804:'le',8805:'ge',8834:'sub',8835:'sup',8836:'nsub',8838:'sube',8839:'supe',8853:'oplus',8855:'otimes',8869:'perp',8901:'sdot',8968:'lceil',8969:'rceil',8970:'lfloor',8971:'rfloor',9001:'lang',9002:'rang',9426:'copy',9674:'loz',9824:'spades',9827:'clubs',9829:'hearts',9830:'diams'};
