// ==UserScript==
// @name      	Rich Text Editor for DelphiForums
// @namespace 	none
// @description	v4.1 9-Nov-2009, WhiteMare, http://forums.delphiforums.com/GoFirefox, http://www.gofirefoxnow.com
// @include	http://*delphiforums.com/n/mb/compose.asp*
// @include	http://betawww.prospero.com/n/mb/compose.asp*
// @include	http://*talkcity.com/n/mb/compose.asp*
// @include	http://*delphiforums.com/n/mb/edit.asp*useHtml*
// @include	http://betawww.prospero.com/n/mb/edit.asp*useHtml*
// @include	http://*talkcity.com/n/mb/edit.asp*useHtml*
// @include	http://*.delphiforums.com/n/mb/message.asp?webtag=*msg=*
// @include	http://betawww.prospero.com/n/mb/message.asp?webtag=*msg=*
// @include	http://*talkcity.com/n/mb/message.asp?webtag=*msg=*
// @include	http://*.delphiforums.com/n/control/welcomescreen.asp*
// @include	http://betawww.prospero.com/n/control/welcomescreen.asp*
// @include	http://*talkcity.com/n/control/welcomescreen.asp*
// @include	http://*.delphiforums.com/n/mydelphi/myaccount.asp*
// @include	http://betawww.prospero.com/n/mydelphi/myaccount.asp*
// @include	http://*talkcity.com/n/mydelphi/myaccount.asp*
// @include	http://*.delphiforums.com/dir-app/bbcard/bbAccount.asp*
// @include	http://betawww.prospero.com/dir-app/bbcard/bbAccount.asp*
// @include	http://*talkcity.com/dir-app/bbcard/bbAccount.asp*
// @include	http://forums.about.com/n/pfx/forum.aspx?*nav=post*
// @include	http://*.delphiforums.com/dir-app/spellcheck/sproxy.asp*
// @include	http://betawww.prospero.com/dir-app/spellcheck/sproxy.asp*
// @include	http://*talkcity.com/dir-app/spellcheck/sproxy.asp*
// @include	http://www.spellchecker.net/spellcheck/script/ssrv.cgi
// @include	http://profiles.delphiforums.com/*

// ==/UserScript==

// Quick Quote style - enter valid CSS for rteQuickQuoteStyle if you want a different style for Quick Quotes.
var rteQuickQuoteStyle = ""

// below is an example of a quick quote style
// To use the example, just remove the two slashes at the beginning of the line, and save this script.
// rteQuickQuoteStyle = "border-color: rgb(0, 0, 0); margin: 5px; padding-left: 5px; padding-bottom: 5px; padding-top: 8px; color: blue; font-style: italic;"

// check for updates to the editor
checkForUpdates();

// delete old editor, if present
var oldEditor = document.getElementById('mMsg_body_Toolbar');
if (oldEditor) {
  // walk up the DOM - td, tr, tbody, table.  Delete the whole table
  var tbl = oldEditor.parentNode.parentNode.parentNode;
  // tbl.parentNode.removeChild(tbl);	
}

////////////////////////////
//	Global Variables
////////////////////////////
var rteInitializeEditor = true;
var rteIsMac = false;
if (navigator.userAgent.toLowerCase().indexOf('macintosh') >= 0) rteIsMac = true;

// used to determine what type of page this is
var isNewPlatform = false;	// about.com
var isNewSig = false;		// sigs for about.com
var isNew = false;		// Post New Message page
var isEdit = false;		// Edit Message page
var isStartPage = false;	// Edit Start page
var isSignature = false;	// My Preferences page (either Premium or Basic)
var hasSig = false;		// any page that allows sigs
var basicSig = false;		// Reply or New Message page for Basic members
var basicMyPrefs = false;	// My Preferences page for Basic members
var isReply = false;		// Reply to a message page
//var isSpell = false;
var hasSpellcheck = false;	// new way of checking for Delphi spell check

////////////////////////////
//	General Functions
////////////////////////////
// pile0nades's page code library
// http://markmail.org/message/3ofqvsf2x4xaj3gz
var Code = {
  run: function(code, novoid) {
    location.href = "javascript:" + (novoid ? code : "void(" + code +
");").replace(/%/g, '%'+'25');
    return this;
  },
  set: function(name, value) {
    return this.run("window." + name + " = " + value);
  },
  edit: function(name, regex, replacement) {
    var bubble = (function() {
      eval("window.name = " + window.name.toString().replace(regex,
"replacement"));
    }).toString().replace(/name/g, name)
    .replace("regex", regex instanceof RegExp ? regex.toString() :
"\"" + regex + "\"")
    .replace("replacement", replacement);
    return this.run('(' + bubble + ')()');
  },

} 



// modified from http://www.quirksmode.org/js/findpos.html 
function rteFindPos(obj) {
  var x = 0, y = 0;
  while (obj.offsetParent) {
      x += obj.offsetLeft;
      y += obj.offsetTop;
      obj = obj.offsetParent;
   }
   return [x,y];
}	
function rteAddGlobalStyle(css) {
    var head, style;
    head = document.getElementsByTagName('head')[0];
    if (!head) { return; }
    style = document.createElement('style');
    style.type = 'text/css';
    style.innerHTML = css;
    head.appendChild(style);
}
////////////////////////////
//	Initialize Editor
////////////////////////////
function rteInitEditor(){  

if (rteInitializeEditor) { 
	//Editor.removeEventListener("load", rteInitEditor, false);
 
	var Editor = document.getElementById('rteEditor');
	EditorWin = Editor.contentWindow;
	EditorDoc = Editor.contentDocument;
	window.EditorWin = EditorWin;
	window.EditorDoc = EditorDoc;

	rteInitializeEditor = false;
	EditorWin.document.designMode = 'on';

	// added the following to enable Delete key to work when editor first loaded
	// not needed for Reply page
	// this should be done differently
	if (! document.getElementById('compCheckUsehtml')) { 
	EditorDoc.write('<br>');
	EditorDoc.close();
	}

	var winStyle = 'background-image: ' + editorStyle.backgroundImage +';' ;
	winStyle += 'background-color: '  + editorStyle.backgroundColor + ';' ;
	winStyle += 'color: '  + editorStyle.color + ';' ;

	var objectStyle = 'object {background-color: #cfcfcf; border: 1px solid; display:block; }'; 
	
	// determine font size to use in editor
	var styleAddr = document.styleSheets[0].href;
	var fsize = 0;
	if (styleAddr.indexOf("msgSize=") > 0) {
	var temp = styleAddr.split("msgSize=")[1];
	fsize = temp.split("&")[0];
	}
	if (fsize > 0) {
	winStyle += 'font-size: ' + fsize + 'pt;' ;
	}
	var theBody = EditorWin.document.getElementsByTagName('body')[0]
	theBody.setAttribute('style', winStyle); 

	var theHead = EditorWin.document.getElementsByTagName('head')[0]
	var link = EditorWin.document.createElement("link");
	link.setAttribute("rel", "stylesheet");
	link.setAttribute("type", "text/css");
	link.setAttribute("media", "screen");
	link.setAttribute("href", styleAddr);
	theHead.appendChild(link);

	EditorWin.document.body.innerHTML = rteTextarea.value;
	if (rteTextarea.value == '') { 
		// add style for embedded objects so they show up in WYSIWYG
		//EditorWin.document.body.innerHTML += '<style type="text/css">' + objectStyle + '</style>' ;
		EditorWin.document.body.innerHTML += '<br>';
		rteSetDefaults();
		rteSetDefaultSig();
	}
	CreateColorTable("ColorTable", "selcolor");
	EditorWin.focus();
	EditorDoc.addEventListener("keypress", rteHandler, false);
}
}
////////////////////////////
//	Set Defaults
////////////////////////////
function rteSetDefaults() {
	// setup default styles, if they exist
	var sep = ".|$.";
	var rteCSS = GM_getValue("rteDefaults", "").split(sep);

	if (rteCSS.length >= 5) {
	EditorWin.document.execCommand('removeformat', false, null);	
	if (rteCSS[1] != "") EditorWin.document.execCommand('forecolor', false, rteCSS[1]);
	if (rteCSS[2] != "") EditorWin.document.execCommand('fontname', false, rteCSS[2]);
	if (rteCSS[3] == "1") EditorWin.document.execCommand('bold', false, null);
	if (rteCSS[4] == "1") EditorWin.document.execCommand('italic', false, null);
	}
}

function rteSetDefaultSig() {
	// setup default sig, if they exist
	var sep = ".|$.";
	var rteCSS = GM_getValue("rteDefaults", "").split(sep);

	// setup default sig for new messages only
	if (rteCSS.length >= 6 && isNew) {
	    if (rteCSS[5] != "") {
		var sep = ".|$.";
		var defSig = "";
		if (basicSig) {
			var sig_array= GM_getValue("BasicSignatures", "").split(sep);
			if (sig_array[0] == "") {
			  sig_array= GM_getValue("Signatures", "").split(sep);
			}
			var name_array= GM_getValue("BasicNames", "").split(sep);
			if (name_array[0] == "") {
			  name_array= GM_getValue("FriendlyNames", "").split(sep);
			}
		} else {
			var sig_array= GM_getValue("Signatures", "").split(sep); 
			if (sig_array[0] == "") {
			  sig_array= GM_getValue("BasicSignatures", "").split(sep);
			}
			var name_array= GM_getValue("FriendlyNames", "").split(sep);
 			if (name_array[0] == "") {
			  name_array= GM_getValue("BasicNames", "").split(sep);
			}
		}

		// figure out default sig
		for (i = 0; i <= name_array.length-1; i++) {
			if (name_array[i] == rteCSS[5]) { 
				defSig = sig_array[i];
			}
		}		

		if (defSig != "") {
		if (document.getElementById('compSigTxt')) { 
			document.getElementById('compSigTxt').value = defSig; }
		else { 
			if (document.getElementById('mMsg_signature')) { 
				document.getElementById('mMsg_signature').value = defSig; }

			if (basicSig) {
				if (getComputedStyle(rteTextarea, '').display == 'none') {
					rteHtmlUpdate();
				}
				// insert default sig
				rteTextarea.value += '<div class="sig" id="rteSigArea">' + defSig + '</div>';
  				EditorWin.document.body.innerHTML = rteTextarea.value;
				
			}
		}
		}
	    }	
	}

}
////////////////////////////
//	Keyboard handler
////////////////////////////
function rteHandler(event) {
//	if (event.type == "keypress" && ((!rteIsMac && event.ctrlKey) || (rteIsMac && event.metaKey))) {
	if (event.type == "keypress" && event.ctrlKey) {
		var sel = null;
		var range = null;
		var key = String.fromCharCode(event.charCode).toLowerCase();
		var cmd = null;
		var value = null;
		switch (key) {

			// simple key commands follow

		    case 'b': cmd = "bold"; break;
		    case 'i': cmd = "italic"; break;
		    case 'u': cmd = "underline"; break;
		    case 's': cmd = "strikethrough"; break;
		    case 'z': cmd = "undo"; break;
		    case 'y': cmd = "redo"; break;
		    case 'v': cmd = "paste"; break;
		
		}
		if (cmd) {
			// execute simple command
			this.execCommand(cmd, false, value);
			event.preventDefault();
			event.stopPropagation();
		}
	}
}
////////////////////////////
//	Toolbar Buttons
////////////////////////////
function rteCreateButton(cmd, spacer, src) {
    var img, button;
    img = document.createElement('img');
    if (cmd == "Show Or Hide") {
	img.setAttribute('class', 'more');
    } else {
    img.width = 21;
    img.height = 21;
    }
    if (spacer) { img.setAttribute('class', 'sep'); }
    img.src = src;
    button = document.createElement('a');
    button.title = cmd;
    button.href = '#';
    button.addEventListener("click", rteClickBtn, true);
    button.appendChild(img);
    return button;
}

function rteClickBtn(event) {
	var cmd, link;
    	link = event.currentTarget;
    	cmd = link.title.toLowerCase().replace(/ /g, '');

	switch (cmd) {
 
	case "createlink":
	case "insertimage":
	var myLink = prompt("Enter URL:","http://");
	if (myLink != null) {
		EditorWin.document.execCommand(cmd, false, myLink); 
		}
	break;

	case "inserthtml":
	var myHTML = prompt("Enter HTML:");
	if (myHTML != null) {
		EditorWin.document.execCommand(cmd, false, myHTML); 
		}
	break;

	case "defaultfont":
	rteSetDefaults();
	break;

	case "savesiginlist":
	var newNames, newMax, mySigName;
	var vNames, vSigs
	var oldName = "";
	var currLoc = 0;
	var sep = ".|$.";
	var newList = "";
	// Save the HTML if they are in WYSIWYG mode
	if (getComputedStyle(rteTextarea, '').display == 'none') {
		rteHtmlUpdate();
	}
	// Check for Sig selected
    	var SBox = window.document.getElementById('switchsig');
	if (SBox) {
    		if (SBox.selectedIndex > 0) {
			currLoc = SBox.selectedIndex;
        		oldName = SBox.options[currLoc].text;	
		}
	}



	if (oldName == "") 
		{ mySigName = prompt("Enter a friendly name for this sig:"); }
	else
		{ mySigName = prompt("Update this sig, or type in a different name to create a new sig", oldName); }

	if (mySigName != null) {
		if (mySigName != "") {
			if (basicMyPrefs) {
				vNames = "BasicNames"; 
				vSigs = "BasicSignatures";
			} else {
				vNames = "FriendlyNames"; 
				vSigs = "Signatures";
			}
		if (mySigName != oldName) {

		// Add new sig

			//newMax = GM_getValue("maxSig", 0) + 1;
			newNames = GM_getValue(vNames, "");
			if (newNames != "") 
				newNames += sep;
			newNames += mySigName;
			newList = GM_getValue(vSigs, "");
			if (newList != "")
				newList += sep;	
			newList += rteTextarea.value;

			// add sig to sig box
			if (SBox) {
    				NewLoc=SBox.length;

	        		NewOptValue=NewLoc - 1;
	        
	        		newOptionName = new window.Option(mySigName,NewOptValue);
	        		SBox.options[NewLoc]=newOptionName;
	        		SBox.options[NewLoc].selected=true;
			}

			//GM_setValue("maxSig", newMax);
			GM_setValue(vNames, newNames);
			GM_setValue(vSigs, newList);
			}
		else {
		// update sig

			if (currLoc > 0) {
    				var sig_array= GM_getValue(vSigs, "").split(sep);

        			sig_array[currLoc-1] = rteTextarea.value;

    				var numSigs = sig_array.length - 1;


    				for (i = 0; i <= numSigs; i++) {
					if (newList != "")
						newList += sep;
					newList += sig_array[i];
				}

				GM_setValue(vSigs, newList);
			}

		}
		}
	}
	break;

	case "inserttable":
	var pos = rteFindPos(this);
	rtePopup(pos, cmd);
	break;

	case "insertmedia":
	var pos = rteFindPos(this);
	window.document.getElementById('rteInsertMediaContent').value="";
	rtePopup(pos, cmd);
	window.document.getElementById('rteInsertMediaContent').focus();
	break;

	// case "managesigs":
	// var pos = rteFindPos(this);
	// rtePopup(pos, cmd);
	// break;

	





	case "nosig":
	if (document.getElementById('compSigTxt'))  
		{ document.getElementById('compSigTxt').value = ''; }
	else { 
		if (isSignature) {
			rteTextarea.value = '';
  			EditorWin.document.body.innerHTML = rteTextarea.value;
		}
		if (basicSig) {
			if (EditorWin.document.getElementById('rteSigArea')) {
				EditorWin.document.getElementById('rteSigArea').innerHTML = '';
				if (getComputedStyle(rteTextarea, '').display == 'none') {
					rteHtmlUpdate();
				}
			}
		}
	}
	break;

	case "quickquote":
	quickQuote();
	break;

	case "showorhide":
	if (getComputedStyle(document.getElementById('rteExtraLine'), '').display == 'none') {
		document.getElementById('rteExtraLine').style.display = 'block';
		GM_setValue("displayExtra", 1);
	} else {
		document.getElementById('rteExtraLine').style.display = 'none';
		GM_setValue("displayExtra", 0);
	}
	break;

	case "morecolors":
	var pos = rteFindPos(this);
	rtePopup(pos, cmd);
	break;

	case "spellcheck":
		// copy html from the iframe to the text area, and switch to HTML view
		if (rteTextarea.style.display == 'none') {
			//rteTextarea.value = EditorWin.document.body.innerHTML;
			rteSetMode("Source");
			var radios = document.getElementsByName('rteMode');
			radios[0].checked = 0;
			radios[1].checked = 1;	
		}
		// use location hack to call spell checker
		location.href = "javascript:void(doSpell('en','document.ComposeForm.MessageText',document.location.protocol + '//' + document.location.host + '/dir-app/spellcheck/sproxy.asp',true));";
	break;

	default: 
	EditorWin.document.execCommand(cmd, false, null); 

	}  // end switch
	
	if (cmd != 'insertmedia' && cmd != 'myfirefox') EditorWin.focus();
		
	event.preventDefault();
}

////////////////////////////
//	Push Buttons
////////////////////////////
function rteCreatePushButton(name, text) {
    var theButton, theText, box;
    theButton = document.createElement('button');
    theButton.type = 'button';
    theButton.name = name;
    theButton.innerHTML = text;
    // set id so that button is styled.  May need to change this.
    theButton.id = 'ssbtn';	
    theButton.addEventListener("click", rteClickPushButton, true);
    return theButton;
}

// Click a button
function rteClickPushButton(event) {

	var cmd, link;
    	link = event.currentTarget;
    	cmd = link.name.toLowerCase().replace(/ /g, '');

	switch (cmd) {

	case "editoroptions":
	if (basicMyPrefs) {
		var configName= "backup_BasicNames";
	} else {
		var configName= "backup_FriendlyNames";
	}

	if (GM_getValue(configName, "") == "") {
	// hide restore button if no backup exists
 	document.getElementById('ManageOpts_Restores').style.display = 'none';
	}


	ManageOpts_Button(event);
	var pos = rteFindPos(this);
	rtePopup(pos, cmd);
	break;

	case "inserthtml":
	var myHTML = prompt("Enter HTML:");
	if (myHTML != null) {
		EditorWin.document.execCommand(cmd, false, myHTML); 
		}
	break;
 
	case "quickquote":

	var range;
	if (window.getSelection().toString().length > 0) {
		var bqNode = document.createElement("blockquote");
		if (rteQuickQuoteStyle == "") {
		bqNode.innerHTML = '" ';
		bqNode.appendChild(window.getSelection().getRangeAt(0).cloneContents());
		bqNode.innerHTML += ' "';
 		bqNode.setAttribute('style', 'border-left: 3px double; margin: 10px; padding: 5px; border-color: ' + editorStyle.color + ';');
 		} else {
		// user setup a custom quick quote 
		bqNode.appendChild(window.getSelection().getRangeAt(0).cloneContents());
		bqNode.setAttribute('style', rteQuickQuoteStyle );
		}

		var tempNode = document.createElement("div");
		//tempNode.appendChild(document.createElement("br"));
		tempNode.appendChild(bqNode); 
		tempNode.appendChild(document.createElement("br")); 
		EditorWin.document.execCommand('inserthtml', false, tempNode.innerHTML);
		EditorWin.focus();
	}
	break;

	} // end switch
	event.preventDefault();	
}
////////////////////////////
//	Tabs
////////////////////////////
function rteClickTab(event) {
	var cmd, link;
    	link = event.currentTarget;
    	cmd = link.title.toLowerCase().replace(/ /g, '');

	switch (cmd) {

	// clicked My Firefox tab in Delphi profile
	case "myfirefox":
	
	  isSignature = true;
	  hasSig = true;

	  if (rteInitializeEditor) { 
		// turn off current tab
		var dfe;
	    	dfe = document.evaluate(
   			"//li[@class='ptcTab ptcCurrent']",
   			document,
   			null,
   			XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
   			null);

	    	for (var i = 0; i < dfe.snapshotLength; i++) {
			dfe.snapshotItem(i).setAttribute('class', 'ptcTab ptcNC');
	    	}

		// highlight My Firefox tab
		var tab = window.document.getElementById("dfMyFirefox");
		tab.setAttribute('class', 'ptcTab ptcCurrent'); 
		
		// check whether to use Basic or Premium sigs
		// Basic members only have 5 tabs (including My Firefox), Premium have 8
		dfe = document.evaluate(
   			"//li[@class='ptcTab ptcNC']",
   			document,
   			null,
   			XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
   			null);
		
		if (dfe.snapshotLength < 7) {
			basicMyPrefs = true;
		}

		// get old content
		var old;
	    	old = document.evaluate(
   			"//div[@class='ptcContent']",
   			document,
   			null,
   			XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
   			null); 

		// create new content

		var h2 = document.createElement('h2');
		h2.innerHTML = "My Firefox";
		var tmp = document.createElement('div');
		tmp.setAttribute('class', 'ptcLeft');
		tmp.appendChild(h2);

		var newC = document.createElement('div');
		newC.setAttribute('class', 'ptcBar');
		newC.appendChild(tmp);

		tmp = document.createElement('div');
		tmp.setAttribute('class', 'ptcRight');
		newC.appendChild(tmp);
		tmp = document.createElement('div');
		tmp.setAttribute('class', 'ptcClear');
		newC.appendChild(tmp);

		var newD = document.createElement('div');
		newD.setAttribute('class', 'ptcTabSubHead');
		newD.appendChild(newC);

		var newE = document.createElement('div');
		newE.setAttribute('class', 'ptcProfilePage');
		newE.appendChild(newD);

		var txtarea = document.createElement('textarea');
		txtarea.id = 'rteProfileTextarea';
		var newE1 = document.createElement('div');
		newE1.setAttribute('class', 'ptcCommentsBlock');
		newE1.appendChild(txtarea);
		newE.appendChild(newE1);

		var newF = document.createElement('div');
		newF.setAttribute('class', 'ptcContent');
		newF.appendChild(newE);

		// replace content
		cand = old.snapshotItem(0);
		cand.parentNode.replaceChild(newF, cand);

		// create RTE, then enable it
		createRTE();

		rteInitEditor();
		//setTimeout(function() { rteInitEditor(); }, 200);
	}
		
	break;


	}  // end switch
		
	event.preventDefault();
}

function rteHTMLChange(event) {
	//if (rteTextarea.style.display == 'none') {
  		//rteDesignUpdate();
	//}
}

////////////////////////////
//	Quick Quote
////////////////////////////

function quickQuote() {
var range;
EditorWin.document.execCommand('removeformat', false, null);
var sel = EditorWin.getSelection();
if (sel.toString().length > 0) {
  if (typeof sel != "undefined") {
    try {
	range= sel.getRangeAt(0);
    } catch(e) {
	range= EditorWin.document.createRange();
    }
  } else { 
	range= EditorWin.document.createRange();
  }

  var bqNode = document.createElement("blockquote");
  if (rteQuickQuoteStyle == "") {
  bqNode.setAttribute('style', 'border-left: 3px double; margin: 10px; padding: 5px; border-color: ' + editorStyle.color + ';');
  } else {
  bqNode.setAttribute('style', rteQuickQuoteStyle);
  }

  range.surroundContents(bqNode);
  bqNode.innerHTML = '" ' + bqNode.innerHTML + ' "';
  }
} // quick quote

////////////////////////////
//	Popups
////////////////////////////
function rtePopup (pos, cmd) { 
	switch (cmd) {

	case "inserttable":
	tablePopup.style.overflow = 'auto';
	tablePopup.style.position = 'absolute';
	tablePopup.style.top = (pos[1] - 60) + 'px';
	tablePopup.style.left = (pos[0] - 50) + 'px';
	tablePopup.style.display = 'block';
	break;

	case "insertmedia":
	mediaPopup.style.overflow = 'auto';
	mediaPopup.style.position = 'absolute';
	mediaPopup.style.top = (pos[1] - 60) + 'px';
	mediaPopup.style.left = (pos[0] - 350) + 'px';
	mediaPopup.style.display = 'block';
	break;

	case "managesigs":
	// managesigs is no longer used

	// clear list
    	var SBox = window.document.getElementById('optionsList');
	numOfOptions=SBox.length;
	for (var i=numOfOptions; i>0; i--) { 
        SBox.options[i]=null;
	}

	//re-create
	var sep = ".|$.";
	var dropdown;

	if (basicMyPrefs) {
		var name_array= GM_getValue("BasicNames", "").split(sep); 
	} else {
		var name_array= GM_getValue("FriendlyNames", "").split(sep); 
	}

	for (i = 0; i <= name_array.length-1; i++) {
		SBox.options[i+1] = new window.Option(name_array[i],i,false,true);
		}

	optionPopup.style.overflow = 'auto';
	optionPopup.style.position = 'absolute';
	optionPopup.style.top = (pos[1] - 35) + 'px';
	optionPopup.style.left = (pos[0] - 100) + 'px';
	optionPopup.style.display = 'block';
	break;

	case "editoroptions":

	optionPopup.style.overflow = 'auto';
	optionPopup.style.position = 'absolute';
	optionPopup.style.top = (pos[1] - 5) + 'px';
	optionPopup.style.left = (pos[0] - 100) + 'px';
	optionPopup.style.display = 'block';
	break;

	case "addcolor":
	colorPopup.style.overflow = 'auto';
	colorPopup.style.position = 'absolute';
	colorPopup.style.top = (pos[1] - 160) + 'px';
	colorPopup.style.left = (pos[0] - 250) + 'px';
	colorPopup.style.display = 'block';
	break;

	case "morecolors":
	colorPopup.style.overflow = 'auto';
	colorPopup.style.position = 'absolute';
	colorPopup.style.top = (pos[1] - 40) + 'px';
	colorPopup.style.left = (pos[0] - 450) + 'px';
	colorPopup.style.display = 'block';
	break;
	}
}

////////////////////////////
//	Tables
////////////////////////////
function rteTableCancel() {
	tablePopup.style.display = 'none';
}

function rteTableSubmit() {

	tablePopup.style.display = 'none';

	var dfForm = window.document.getElementById('rteInsertTableForm');
	var theHTML = '<table '; 
	theHTML += ' cellpadding=' + window.document.getElementById('rteInsertTable_cellpadding').value;
	theHTML += ' cellspacing=' + window.document.getElementById('rteInsertTable_cellspacing').value;
	theHTML += ' width=' + window.document.getElementById('rteInsertTable_tablewidth').value + window.document.getElementById('rteInsertTable_widthunit').options[window.document.getElementById('rteInsertTable_widthunit').selectedIndex].value;

	if (window.document.getElementById('rteInsertTable_tablealign').value != '')
	  theHTML += ' align=' + window.document.getElementById('rteInsertTable_tablealign').options[window.document.getElementById('rteInsertTable_tablealign').selectedIndex].value;
	if (window.document.getElementById('rteInsertTable_tablecolor').value != '')
	  theHTML += ' bgcolor=' + window.document.getElementById('rteInsertTable_tablecolor').value;
	theHTML += ' border=' + window.document.getElementById('rteInsertTable_borderwidth').value;
	theHTML += '>';

	for (var r = 1; r <= window.document.getElementById('rteInsertTable_rows').value; r++) {
		theHTML += '<tr>';
		for (var c = 1; c <= window.document.getElementById('rteInsertTable_columns').value; c++) {
			theHTML += '<td';
			if (window.document.getElementById('rteInsertTable_cellcolor').value != '')
				theHTML += ' bgcolor=' + window.document.getElementById('rteInsertTable_cellcolor').value;
			theHTML += '>&nbsp;</td>';
		}
		theHTML += '</tr>';
	}
	theHTML += '</table>';

	EditorWin.document.execCommand('inserthtml', false, theHTML); 
}


function rteInsertTable (apopup) {  
	
apopup.innerHTML = '<table width="100%" border=0 cellpadding=2 cellspacing=0><tr><td class=head><b>Insert a Table</b></td></tr></table>' 

apopup.innerHTML += '<FORM NAME="form1" id="rteInsertTableForm"><TABLE border=0><TR><td ALIGN="RIGHT">Rows:</TD><TD><INPUT TYPE="text" NAME="rows" id="rteInsertTable_rows" VALUE="2" MAXLENGTH="3" SIZE="3"></TD><td ALIGN="RIGHT" nowrap>Cell Padding:</TD><TD><INPUT TYPE="text" NAME="cellpadding" id="rteInsertTable_cellpadding" VALUE="0" MAXLENGTH="3" SIZE="3"></TD></TR><TR><td ALIGN="RIGHT">Columns:</TD><TD><INPUT TYPE="text" NAME="columns" id="rteInsertTable_columns" VALUE="2" MAXLENGTH="3" SIZE="3"></TD><td ALIGN="RIGHT" nowrap>Cell Spacing:</TD><TD><INPUT TYPE="text" NAME="cellspacing" id="rteInsertTable_cellspacing" VALUE="0" MAXLENGTH="3" SIZE="3"></TD></TR><tr><td align="right">Align:</td><td><select name="tablealign" id="rteInsertTable_tablealign" ><option value="">Not Set</option><option value="center">Center</option><option value="left">Left</option><option value="right">Right</option></select></td><td COLSPAN="4">&nbsp;</td></tr>' 
	+ '<tr> <td align="right" nowrap>Table Color:</td><td><input type="text" name="tablecolor" id="rteInsertTable_tablecolor" value="" maxlength="20" size="7"></td><td align="right" nowrap>&nbsp;&nbsp;Cell Color:</td><td><input type="text" name="cellcolor" id="rteInsertTable_cellcolor"  value="" maxlength="20" size="7"></td>   </tr><tr> <td align="right" nowrap>Table Width:</td><td><input type"text" name="tablewidth" id="rteInsertTable_tablewidth"  value="100" maxlength="10" size="3">&nbsp;<select name="widthunit" id="rteInsertTable_widthunit" ><option value="%" selected>Percent</option><option value="px">Pixels</option></select></td><td align="right" nowrap>Border Width:</td> <td><input type="text" name="borderwidth" id="rteInsertTable_borderwidth"  value="1" maxlength="3" size="3"></td>  </tr></table>'
	+ '<br><center><input type="button" name="InsertTable_Submit" id="InsertTable_Submit" value="Insert Table" class=button><input class=button type="button" name="InsertTable_Cancel" id="InsertTable_Cancel" value="Cancel"></center></form>';

    apopup.className = 'msgback';                                                                                      
    apopup.style.zIndex = 2147483647;
    apopup.style.position = 'absolute';
    apopup.style.MozBorderRadius = '6px';
    apopup.style.display = 'none';
    apopup.style.textAlign = 'left';
    apopup.style.padding = '10px';
    apopup.style.width = '500px';
	return apopup;
}

////////////////////////////
//	Media button
////////////////////////////
function rteMediaCancel() {
	mediaPopup.style.display = 'none';
}

function rteMediaSubmit() {
	mediaPopup.style.display = 'none';
	var theHTML = window.document.getElementById('rteInsertMediaContent').value + "<br>" ;	
	EditorWin.document.execCommand('inserthtml', false, theHTML); 
	EditorWin.focus();
}


function rteInsertMedia (apopup) {  
	
apopup.innerHTML = '<table width="100%" border=0 cellpadding=2 cellspacing=0><tr><td class=head><b>Insert Media</b></td></tr></table>' 

apopup.innerHTML += '<p>Place your cursor in the box, then Paste or type in the HTML code for your content from YouTube or other approved sites.</p>'
apopup.innerHTML += '<FORM NAME="form4" id="rteInsertMediaForm"><TABLE border=0><tr><td colspan="4"><textarea columns="80" rows="10" style="width:525px;" id="rteInsertMediaContent" ></textarea></td></tr></table>'
	+ '<br><center><input type="button" name="InsertMedia_Submit" id="InsertMedia_Submit" value="Insert Media" class=button>&nbsp;<input class=button type="button" name="InsertMedia_Cancel" id="InsertMedia_Cancel" value="Cancel"></center></form>';

    apopup.className = 'msgback';                                                                                      
    apopup.style.zIndex = 2147483647;
    apopup.style.position = 'absolute';
    apopup.style.MozBorderRadius = '6px';
    apopup.style.display = 'none';
    apopup.style.textAlign = 'left';
    apopup.style.padding = '10px';
    apopup.style.width = '550px';
	return apopup;
}

////////////////////////////
//	Old
////////////////////////////
// no longer used
//function rteSpellStart () {
//	if (rteTextarea.style.display == 'none') {
//		rteTextarea.value = EditorWin.document.body.innerHTML;
//	}
//}

// no longer used
//function rteSpellFinish () {
//if (window.parent.frames[1].document.forms[0].elements[6].name == "text") {
	// copy from spellcheck window into rich text editor
	// note: have to use elements[6] instead of .name because having "text" as a name field messes up the javascript call	
//	var sEditor = window.parent.opener;
//	var theText = window.parent.frames[1].document.forms[0].elements[6].value;
//	sEditor.postMessage(theText, "*");
//	}
//}

// used by spellchecker
// no longer used
//function receiveMessage(event)
//{
//  if (event.origin !== "http://www.spellchecker.net")
//    return;

//document.getElementById('rteEditor').contentWindow.document.body.innerHTML = event.data;

//  alert('message received ' + event.data);
//}


// Called when the user clicks on "InsertImage" button
// not used
function rteInsertImage() {
	this._popupDialog("insert_image.html", function(param) {
		if (!param) {	// user must have pressed Cancel
			return false;
		}
		var sel = EditorWin._getSelection();
		var range = EditorWin._createRange(sel);
		EditorWin.document.execCommand("insertimage", false, param["f_url"]);
		var img = null;
		img = range.startContainer.previousSibling;
		for (field in param) {
			var value = param[field];
			if (!value) {
				continue;
			}
			switch (field) {
			    case "f_alt"    : img.alt	 = value; break;
			    case "f_border" : img.border = parseInt(value); break;
			    case "f_align"  : img.align	 = value; break;
			    case "f_vert"   : img.vspace = parseInt(value); break;
			    case "f_horiz"  : img.hspace = parseInt(value); break;
			}
		}
	}, null);
}

////////////////////////////
//	Dropdowns
////////////////////////////
function rteCreateDropdown(cmd) {
    var dropdown;
	switch (cmd) {
	case 'formatblock': 
		dropdown = '<select id="formatblock" class="wsel"><option value="p">Normal</option><option value="p">Paragraph</option><option value="h1">Heading 1</option><option value="h2">Heading 2</option><option value="h3">Heading 3</option><option value="h4">Heading 4</option><option value="h5">Heading 5</option><option value="h6">Heading 6</option><option value="address">Address</option><option value="pre">Formatted</option></select>';
	break;

	case 'fontname':
		var sep = ".|$.";
		var name_array= GM_getValue("FontNames", "").split(sep); 

		dropdown = '<select id="fontname" class="wsel"><option value="">Font</option>';
		for (i = 0; i <= name_array.length-1; i++) {
			dropdown += '<option value="' + i + '">' + name_array[i] + '</option>';
		}
		dropdown += '</select>';
	break;


	case 'fontsize':
		dropdown = '<select id="fontsize" class="wsel"><option value="Size">Size</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option></select>';
	break;
	case 'forecolor':
		var arColor = ['black','darkslategrey','grey','maroon','red','deeppink','lightpink','purple','violet','darkblue','blue','aqua','skyblue','teal','green','lime','springgreen','olive','orange','darkgoldenrod'];
		var liteColor = ['yellow','bisque','white'];
		
		dropdown = '<select id="forecolor" class=wsel><option selected>- Color -</option>'
		for (var i = 0; i < arColor.length; i++) {
		dropdown += '<option style="color:' + arColor[i] + ';">' + arColor[i] + '</option>';
		}
		for (var i = 0; i < liteColor.length; i++) {
		dropdown += '<option style="color:' + liteColor[i] + ';background:black;">' + liteColor[i] + '</option>';
		}
		dropdown += '</select>';
	break;	
	case 'switchsig':
		var sep = ".|$.";
		if (basicSig || basicMyPrefs ) {
			var name_array= GM_getValue("BasicNames", "").split(sep);
			if (name_array[0] == "") {
			  name_array= GM_getValue("FriendlyNames", "").split(sep);
			}
		} else {
			var name_array= GM_getValue("FriendlyNames", "").split(sep);
 			if (name_array[0] == "") {
			  name_array= GM_getValue("BasicNames", "").split(sep);
			}
		}

		//var sig_array= GM_getValue("FriendlyNames", "").split(sep);

		dropdown = '<select id="switchsig" class="wsel"><option value="">Switch Sig</option>';
		for (i = 0; i <= name_array.length-1; i++) {
			dropdown += '<option value="' + i + '">' + name_array[i] + '</option>';
		}
		dropdown += '</select>';
	break;

	case 'insertsmiley':
		var sep = ".|$.";
		var name_array= GM_getValue("SmileyNames", "").split(sep); 

		dropdown = '<select id="insertsmiley" class="wsel"><option value="">Smileys</option>';
		for (i = 0; i <= name_array.length-1; i++) {
			dropdown += '<option value="' + i + '">' + name_array[i] + '</option>';
		}
		dropdown += '</select>';
	break;
	}

	dropdown += '<span class="sep"></span>\n';
    return dropdown;
}
function rteChangeDropdown(event) {

	var dropdown, sVal;
    	dropdown = event.currentTarget;
	if (dropdown.selectedIndex > 0) {
	sVal = dropdown.options[dropdown.selectedIndex].value;

	switch (dropdown.id) {
	case 'switchsig': 
	
		var sep = ".|$.";
		if (basicSig || basicMyPrefs) {
			var sig_array= GM_getValue("BasicSignatures", "").split(sep);
			if (sig_array[0] == "") {
			  sig_array= GM_getValue("Signatures", "").split(sep);
			}
		} else {
			var sig_array= GM_getValue("Signatures", "").split(sep); 
			if (sig_array[0] == "") {
			  sig_array= GM_getValue("BasicSignatures", "").split(sep);
			}
		}

		if (document.getElementById('compSigTxt')) { 
			document.getElementById('compSigTxt').value = sig_array[sVal]; }
		else { 
			if (document.getElementById('mMsg_signature')) { 
				document.getElementById('mMsg_signature').value = sig_array[sVal]; }

			if (isSignature) {
				rteTextarea.value = sig_array[sVal];
  				EditorWin.document.body.innerHTML = rteTextarea.value;
			}

			if (basicSig) {
				if (getComputedStyle(rteTextarea, '').display == 'none') {
					rteHtmlUpdate();
				}
				// replace sig if possible
				if (EditorWin.document.getElementById('rteSigArea')) {
					EditorWin.document.getElementById('rteSigArea').innerHTML = sig_array[sVal];
				} else {
					rteTextarea.value += '<div class="sig" id="rteSigArea">' + sig_array[sVal] + '</div>';
  					EditorWin.document.body.innerHTML = rteTextarea.value;
				}
			}
		}	
	break;

	case 'fontname':
		var sep = ".|$.";
		var sig_array= GM_getValue("myFonts", "").split(sep); 
		var myFont = sig_array[sVal];
		if (myFont != null) {
		EditorWin.document.execCommand("fontname", false, myFont); 
		}

	break;	

	case 'insertsmiley':
		var sep = ".|$.";
		var sig_array= GM_getValue("Smileys", "").split(sep); 
		var myLink = sig_array[sVal];
		if (myLink != null) {
		EditorWin.document.execCommand("insertimage", false, myLink); 
		}

	break;		
	default: 	
		if (dropdown.id == 'formatblock') sVal = '<'+ sVal +'>';
		EditorWin.document.execCommand(dropdown.id, false, sVal);
		dropdown.selectedIndex = 0;
	
}	// end switch
	}	
	//EditorWin.focus();
}

////////////////////////////
//	Manage Options
////////////////////////////
function rteManageOptions (apopup) {  
	var dropdown;
	var sep = ".|$.";
	var currDefaults = GM_getValue("rteDefaults", "");

	if (basicMyPrefs) {
		var configName= "BasicNames";
		var configList= "BasicSignatures"; 
	} else {
		var configName= "FriendlyNames";
		var configList= "Signatures"; 
	}

	var name_array= GM_getValue(configName, "").split(sep);
		 
	dropdown = '<select id="optionsList" size="16" class="wsel"><option value="">Select a Signature</option>';

	for (i = 0; i <= name_array.length-1; i++) {
		dropdown += '<option value="' + i + '"';
		if ( i == 0) {
			dropdown += ' selected '; } 
		dropdown +=  '>' + name_array[i] + '</option>';
	}
	dropdown += '</select>';

apopup.innerHTML = '<div><button id="ManageOpts_Sigs" name="ManageOpts_Sigs" type="button">Sigs</button>'
 		+ '<button id="ManageOpts_Smileys" name="ManageOpts_Smileys" type="button">Smileys</button>'
		+ '<button id="ManageOpts_Colors" name="ManageOpts_Colors" type="button">Colors</button>'
		+ '<button id="ManageOpts_Fonts" name="ManageOpts_Fonts" type="button">Fonts</button>'
		+ '<button id="ManageOpts_Defaults" name="ManageOpts_Defaults" type="button">Defaults</button>'
		+ '<button id="ManageOpts_Backups" name="ManageOpts_Backups" type="button">Backup</button>'
		+ '<button id="ManageOpts_Restores" name="ManageOpts_Restores" type="button">Restore</button>'
 		+ '</div>';
	
apopup.innerHTML += '<table width="100%" border=0 cellpadding=2 cellspacing=3 id="popupHeader"><tr><td class=head><b>Manage <span id="ManageOpts_Title">Signature</span>s</b></td></tr></table>' 

apopup.innerHTML += '<form name="form2" id="rteManageOptionsForm"><table border=0 align="center" id="rteManageOptionsTable">' 
	+ '<tr><td>' + dropdown + '</td>'
	+ '<td align="left" valign="middle"><input type="button" name="ManageOpts_Up" id="ManageOpts_Up" value="&#8593;" class="button">&nbsp;&nbsp;Move Up<br>'
	+ '<input type="button" name="ManageOpts_Down" id="ManageOpts_Down" value="&#8595;" class="button">&nbsp;&nbsp;Move Down<br><br>'
//	+ '<input type="button" name="ManageOpts_Copy" id="ManageOpts_Copy" value="Copy" class="button"><br>'
	+ '<input type="button" name="ManageOpts_Rename" id="ManageOpts_Rename" value="Rename" class="button"><br>'
	+ '<input type="button" name="ManageOpts_Delete" id="ManageOpts_Delete" value="Delete" class="button"><br><br>'
	+ '<input type="button" name="ManageOpts_Add" id="ManageOpts_Add" value="Add" class="button" style="display:none;">'
	+ '</td></tr></table>'

	+ '<table border=0 align="center" id="rteManageOptionsDefaultsTable" style="display:none;">'
	+ '<tr><td>Default Sig :</td><td><select id="defaultSig" class="wsel"><option value="">None</option></select></td></tr>'
	+ '<tr><td>Font Color :</td><td><select id="defaultColor" class="wsel"><option value="">None</option></select></td></tr>'
	+ '<tr><td>Font Face:</td><td><select id="defaultFont" class="wsel"><option value="">None</option></select></td></tr>'
	+ '<tr><td>Bold :</td><td><input type="checkbox" id="defaultWeight" value="1"></td></tr>'
	+ '<tr><td>Italic :</td><td><input type="checkbox" id="defaultItalic" value="1"></td></tr>'
	+ '<tr><td>Use Forum Background :</td><td><input type="checkbox" id="defaultBck" value="1"></td></tr>'
	+ '</table>'

	+ '<table border=0 align="center" id="rteManageOptionsBackupTable" style="display:none;">'
	+ '<tr><td colspan="2">'
	+ 'To save a backup of your sigs, select the box called "Backup My Sigs", <br>then click the Save List button.<br><br>Only backup your sigs when you know they are working correctly.<br><br>'
	+ '<b>Once you have backed up your sigs, you cannot go back to a previous copy of your sigs.</b><br><br>'
	+ '<center><input type="checkbox" name="ManageOpts_Backup" id="ManageOpts_Backup" value="Backup">Backup My Sigs</center>'   
	+ '</td></tr></table>'

	+ '<table border=0 align="center" id="rteManageOptionsRestoreTable" style="display:none;">'
	+ '<tr><td colspan="2">'
	+ 'You last backed up your sigs : <span id="ManageOptsRestore_Time"></span><br><br>'
	+ 'To restore of your sigs, select the box called "Restore My Sigs", <br>then click the Save List button.<br><br>'
	+ '<b>Once you have restored your sigs, you cannot go back to the current copy of your sigs.</b><br><br>'
	+ '<center><input type="checkbox" name="ManageOpts_Restore" id="ManageOpts_Restore" value="Restore">Restore My Sigs</center>'   
	+ '</td></tr></table>'

	+ '<input type="hidden" name="ManageOpts_CurrName" id="ManageOpts_CurrName" value="' + configName + '">'
	+ '<input type="hidden" name="ManageOpts_CurrList" id="ManageOpts_CurrList" value="' + configList + '">'	
	+ '<br><center><input type="button" name="ManageOpts_Submit" id="ManageOpts_Submit" value="Save List" class=button><input class=button type="button" name="ManageOpts_Cancel" id="ManageOpts_Cancel" value="Cancel"></center></form>';

    apopup.className = 'msgback';                                                                                      
    apopup.style.zIndex = 2147483647;
    apopup.style.position = 'absolute';
    apopup.style.MozBorderRadius = '6px';
    apopup.style.display = 'none';
    apopup.style.textAlign = 'left';
    apopup.style.padding = '10px';
    apopup.style.width = '500px';
	return apopup;
}

function ManageOpts_Button(event)
{
    
    var btn;
    btn = event.currentTarget.id;
    //var SBox = window.document.getElementById('optionsList');
    var SBox = document.getElementById('optionsList');
    var numOfOptions=SBox.length;

    if (SBox.selectedIndex > 0) {
        var currLoc=SBox.selectedIndex;

	switch (btn) {

	case "ManageOpts_Add":
	var msg = "Enter a value";
	var sep = ".|$.";
	var isColorOpt = false;
	
		switch (window.document.getElementById('ManageOpts_Title').innerHTML) {

		case "Smiley":
		msg = "Enter the URL for this smiley (including http://) :"; 
		break;

		case "Font":
		msg = "Enter one or more font families, separated by commas :"; 
		break;

		case "Color":
		msg = "Enter a hex code for this color :";
		isColorOpt = true; 
		break;
		}

	var myAddName = prompt("Enter a friendly name:");

	if (myAddName != null) {
		if (myAddName != "") {
		  if (isColorOpt) {
		    window.document.getElementById('CustomColor_Name').value = myAddName;
		    
		    var pos = rteFindPos(this);
		    rtePopup(pos, "addcolor");
		    //optionPopup.style.display = 'none';
		  } else {
		  var myAddValue = prompt(msg);
		    if (myAddValue != null) {
		      if (myAddValue != "") {
    			var NewLoc=SBox.length;
			myAddValue = sep + myAddValue;
	        	newOptionName = new window.Option(myAddName,myAddValue);
	        	SBox.options[NewLoc]=newOptionName;
	        	SBox.options[NewLoc].selected=true;
		      }
		    }
		  }
		}
	}
	break;

	case "ManageOpts_Copy":

	var myCopyName = prompt("Enter a friendly name for the new copy of this sig:");

	if (myCopyName != null) {
		if (myCopyName != "") {
    		NewLoc=SBox.length;

	        NewOptValue=SBox.options[currLoc].value;
	        
	        newOptionName = new window.Option(myCopyName,NewOptValue);
	        SBox.options[NewLoc]=newOptionName;
	        SBox.options[NewLoc].selected=true;
		}
	}
	break;

	case "ManageOpts_Delete":
 	SBox.options[currLoc]=null;
	if (numOfOptions > 1)
		{  if ((numOfOptions-1) == currLoc)
			   { // we are deleting the last entry, set the previous option to selected
	             SBox.options[currLoc-1].selected=true; }
	       else
			   { // else set the next option to selected
	             SBox.options[currLoc].selected=true; }
	    }
	break;

	case "ManageOpts_Rename":

	var myReName = prompt("Enter a new name :", SBox.options[currLoc].text);

	if (myReName != null) {
		if (myReName != "") {
		SBox.options[currLoc].text = myReName;
		}
	}
	break;

	case "ManageOpts_Down":
 	if (currLoc < numOfOptions-1) {
     	SwapOption(SBox,currLoc,currLoc+1);}
	break;

	case "ManageOpts_Up":
	if (currLoc > 1) {
	SwapOption(SBox,currLoc,currLoc-1); }
	break;

	case "ManageOpts_Sigs":
	case "ssbtn":

	if (basicMyPrefs) { 
		rteManageOptionsSwitch("Signature", "BasicNames", "BasicSignatures"); 
	} else { 
		rteManageOptionsSwitch("Signature", "FriendlyNames", "Signatures"); 
	}
	break;

	case "ManageOpts_Smileys":
	rteManageOptionsSwitch("Smiley", "SmileyNames", "Smileys");
	break;

	case "ManageOpts_Colors":
	rteManageOptionsSwitch("Color", "ColorNames", "myColors");
	break;

	case "ManageOpts_Fonts":
	rteManageOptionsSwitch("Font", "FontNames", "myFonts");
	break;

	case "ManageOpts_Defaults":
	rteManageOptionsSwitchDefaults(); 
	break;

	case "ManageOpts_Backups":
	if (basicMyPrefs) {
		rteManageOptionsSwitchAlt("Backup", "BasicNames", "BasicSignatures"); 
	} else {
		rteManageOptionsSwitchAlt("Backup", "FriendlyNames", "Signatures"); 
	}
	break;

	case "ManageOpts_Restores":
	if (basicMyPrefs) {
		rteManageOptionsSwitchAlt("Restore", "BasicNames", "BasicSignatures"); 
	} else {
		rteManageOptionsSwitchAlt("Restore", "FriendlyNames", "Signatures"); 
	}
	break;
		
	} // end switch

    }
}

function SwapOption(SBox, oldIndex, newIndex)
{
    var temp1=SBox.options[oldIndex].text;
    var temp2=SBox.options[oldIndex].value;
    
    SBox.options[oldIndex].text = SBox.options[newIndex].text;
    SBox.options[oldIndex].value = SBox.options[newIndex].value;
    SBox.options[newIndex].text = temp1; 
    SBox.options[newIndex].value = temp2; 

    SBox.options[oldIndex].selected=false;
    SBox.options[newIndex].selected=true;
}

function rteManageOptionsSwitch(aName, configName, configList) {

	//if (window.document.getElementById('ManageOpts_Title').innerHTML != aName) {
	window.document.getElementById('ManageOpts_Title').innerHTML=aName;
	window.document.getElementById('ManageOpts_CurrName').value=configName;
	window.document.getElementById('ManageOpts_CurrList').value=configList;


	window.document.getElementById('rteManageOptionsDefaultsTable').style.display = "none";
	window.document.getElementById('rteManageOptionsBackupTable').style.display = "none";
	window.document.getElementById('rteManageOptionsRestoreTable').style.display = "none";
	window.document.getElementById('rteManageOptionsTable').style.display = "table";


	if (aName == "Signature") {
		window.document.getElementById('ManageOpts_Add').style.display = "none";
	} else {
		window.document.getElementById('ManageOpts_Add').style.display = "inline";	
	}

	// clear list
    	var SBox = window.document.getElementById('optionsList');
	numOfOptions=SBox.length;
	for (var i=numOfOptions; i>0; i--) { 
        SBox.options[i]=null;
	}
	SBox.options[0].text='Select a ' + aName;

	//re-create list
	var sep = ".|$.";
	var dropdown;

	var name_array= GM_getValue(configName, "").split(sep); 

	for (i = 0; i <= name_array.length-1; i++) {
		SBox.options[i+1] = new window.Option(name_array[i],i,false,true);
	}
	if (SBox.length > 1) SBox.options[1].selected=true;
// } // any changes?
}

function rteManageOptionsSwitchAlt(aName, configName, configList) {
if (window.document.getElementById('ManageOpts_Title').innerHTML != aName) {
	window.document.getElementById('ManageOpts_Title').innerHTML=aName;
	window.document.getElementById('ManageOpts_CurrName').value=configName;
	window.document.getElementById('ManageOpts_CurrList').value=configList;

	if (aName == "Backup") {
	window.document.getElementById('rteManageOptionsTable').style.display = "none";
	window.document.getElementById('rteManageOptionsRestoreTable').style.display = "none";
	window.document.getElementById('rteManageOptionsDefaultsTable').style.display = "none";
	window.document.getElementById('rteManageOptionsBackupTable').style.display = "table";
	return;
	} 

	if (aName == "Restore") {
    	var configName = window.document.getElementById('ManageOpts_CurrName').value;
	var backupTime = GM_getValue("backupTime_" + configName, "");
	window.document.getElementById('ManageOptsRestore_Time').innerHTML = backupTime;
	window.document.getElementById('ManageOptsRestore_Time').style.display = "inline";
	window.document.getElementById('rteManageOptionsTable').style.display = "none";
	window.document.getElementById('rteManageOptionsBackupTable').style.display = "none";
	window.document.getElementById('rteManageOptionsDefaultsTable').style.display = "none";
	window.document.getElementById('rteManageOptionsRestoreTable').style.display = "table";
	return;
	} 
} // any changes?
}

function rteManageOptionsSwitchDefaults() {
if (window.document.getElementById('ManageOpts_Title').innerHTML != "Default") {
	var sep = ".|$.";
	var currDefaults = GM_getValue("rteDefaults", "").split(sep);

	window.document.getElementById('ManageOpts_Title').innerHTML="Default";
	window.document.getElementById('ManageOpts_CurrName').value="Default";
	window.document.getElementById('ManageOpts_CurrList').value="Default";

	window.document.getElementById('defaultBck').checked = (currDefaults[0] == 1) ? true:false;

	
	// get sigs
	// clear list
    	var dsBox = window.document.getElementById('defaultSig');
	var nbr=dsBox.length;
	for (var i=nbr; i>0; i--) { 
        dsBox.options[i]=null;
	}

	if (basicMyPrefs) { 
		var theNames = GM_getValue("BasicNames", "").split(sep);
	} else { 
		var theNames = GM_getValue("FriendlyNames", "").split(sep);
	}

	for (i = 0; i <= theNames.length-1; i++) {
		if (theNames[i] == currDefaults[5]) { 
		dsBox.options[i+1] = new window.Option(theNames[i],theNames[i],false,true);
		} else {  
		dsBox.options[i+1] = new window.Option(theNames[i],theNames[i],false,false);
		}
	}
	
	// get font colors
	// clear list
    	var cBox = window.document.getElementById('defaultColor');
	nbr=cBox.length;
	for (var i=nbr; i>0; i--) { 
        cBox.options[i]=null;
	}

	theNames = GM_getValue("ColorNames", "").split(sep);
	theColors = GM_getValue("myColors", "").split(sep);

	for (i = 0; i <= theColors.length-1; i++) {
		if (theColors[i] == currDefaults[1]) {
		cBox.options[i+1] = new window.Option(theNames[i],theColors[i],false,true);
		} else {
		cBox.options[i+1] = new window.Option(theNames[i],theColors[i],false,false);
		}
	}

	// get fonts
	// clear list
    	var fBox = window.document.getElementById('defaultFont');
	nbr=fBox.length;
	for (var i=nbr; i>0; i--) { 
        fBox.options[i]=null;
	}

	theNames = GM_getValue("FontNames", "").split(sep);
	theFonts = GM_getValue("myFonts", "").split(sep);

	for (i = 0; i <= theFonts.length-1; i++) {
		if (theFonts[i] == currDefaults[2]) {
		fBox.options[i+1] = new window.Option(theNames[i],theFonts[i],false,true);
		} else {
		fBox.options[i+1] = new window.Option(theNames[i],theFonts[i],false,false);
		}
	}

	window.document.getElementById('defaultWeight').checked = (currDefaults[3] == 1) ? true:false;
	window.document.getElementById('defaultItalic').checked = (currDefaults[4] == 1) ? true:false;


	// display Defaults
	window.document.getElementById('rteManageOptionsTable').style.display = "none";
	window.document.getElementById('rteManageOptionsRestoreTable').style.display = "none";
	window.document.getElementById('rteManageOptionsBackupTable').style.display = "none";
	window.document.getElementById('rteManageOptionsDefaultsTable').style.display = "table";	
}
}


function rteManageOptionsCancel() {
	optionPopup.style.display = 'none';
}

function rteManageOptionsSubmit() { 
    var sep = ".|$.";
    var newList = "";
    var newNames = "";
    var id, theName, i;
    var configName = window.document.getElementById('ManageOpts_CurrName').value;
    var configList = window.document.getElementById('ManageOpts_CurrList').value;
    var configOpt = window.document.getElementById('ManageOpts_Title').innerHTML;

    if (configOpt == "Default") {
	var newList = (window.document.getElementById('defaultBck').checked)? "1" : "0";
	newList += sep + window.document.getElementById('defaultColor').value;
	newList += sep + window.document.getElementById('defaultFont').value;
	newList += (window.document.getElementById('defaultWeight').checked)? sep+"1" : sep + "0";
	newList += (window.document.getElementById('defaultItalic').checked)? sep+"1" : sep + "0";
	newList += sep + window.document.getElementById('defaultSig').value;
    	GM_setValue("rteDefaults", newList);
     	optionPopup.style.display = 'none'; 
    return;
    }

    if (configOpt == "Backup") {
    	if (window.document.getElementById('ManageOpts_Backup').checked) {
		optionPopup.style.display = 'none'; 
		window.document.getElementById('ManageOpts_Backup').checked = false;
    		newNames = GM_getValue(configName, "");
    		newList = GM_getValue(configList, "");
    		GM_setValue("backup_" + configName, newNames);
    		GM_setValue("backup_" + configList, newList);
		var now=new Date();
		var nowTime = now.toLocaleString();
    		GM_setValue("backupTime_" + configName, nowTime);		
    	} else {
    		alert ('You need to mark the checkbox labeled "Backup My Sigs" in order for your Sigs to be saved.');
    	}
    return;
    }

    if (configOpt == "Restore") {
    	if (window.document.getElementById('ManageOpts_Restore').checked) {


		optionPopup.style.display = 'none'; 
		window.document.getElementById('ManageOpts_Restore').checked = false;
    		newNames = GM_getValue("backup_" + configName, "");
    		newList = GM_getValue("backup_" + configList, "");
    		GM_setValue(configName, newNames);
    		GM_setValue(configList, newList);

	// clear sig list in Main window
    	var SBox = window.document.getElementById('switchsig');
	numOfOptions=SBox.length;
	for (var i=numOfOptions; i>0; i--) { 
        SBox.options[i]=null;
	}

	//re-create
	var sep = ".|$.";
	var dropdown;
	var name_array= newNames.split(sep); 

	for (i = 0; i <= name_array.length-1; i++) {
		SBox.options[i+1] = new window.Option(name_array[i],i,false,true);
		}

    	} else {
    		alert ('You need to mark the checkbox labeled "Restore My Sigs" in order for your Sigs to be restored.');
    	}
    return;
    }

     optionPopup.style.display = 'none'; 

    var name_array= GM_getValue(configName, "").split(sep); 
    var opt_array= GM_getValue(configList, "").split(sep);


    var SBox = window.document.getElementById('optionsList');
    var numOpts = SBox.length - 1;

    for (i = 1; i <= numOpts; i++) {
	id = SBox.options[i].value;
	theName = SBox.options[i].text;
	if (newList != "")
		newList += sep;
	if (isNaN(id)) {
		if (id.indexOf(sep) == 0) {
			id = id.substr(4);
		}
		newList += id;	// added records
	} else {
		newList += opt_array[id];
	}
	if (newNames != "")
		newNames += sep;
	newNames += theName;
    }
    GM_setValue(configName, newNames);
    GM_setValue(configList, newList);
}

////////////////////////////
//	Color Chart (on toolbar)
////////////////////////////
function rteCreateColorChart() {
	var sep = ".|$.";
	var colorChart = document.createElement('div');
	var arColor = ['black','grey','maroon','red','deeppink','lightpink','purple','violet','darkblue','blue','aqua','skyblue','teal','green','springgreen','orange','darkgoldenrod','yellow','bisque','white'];
	
	colorChart.setAttribute('id', 'colorChart');
	var theNames = GM_getValue("ColorNames", "").split(sep);
	var theColors = GM_getValue("myColors", "").split(sep);
	for (var i = 0; i < theNames.length; i++) {
		colorChart.appendChild(rteCreateColor(theNames[i],theColors[i]));
	}
	return colorChart;
}
function rteCreateColor(aName, aColor) {
	var btn
	btn = document.createElement('p');
    	btn.title = aName;
	btn.id = aColor;
	// sometimes colors have pound sign
	if (aColor.charAt(0) == "#") {
		btn.setAttribute('style', 'background-color:' + aColor + ';');
	} else {
		btn.setAttribute('style', 'background-color:#' + aColor + ';');
	}
	
	btn.addEventListener("click", rteClickColorChart, true);
    	return btn;
}
function rteClickColorChart(event) { 
    	var aColor = event.currentTarget.style.backgroundColor.toLowerCase();
	EditorWin.document.execCommand('forecolor', false, aColor); 		
	EditorWin.focus();
}






////////////////////////////
//	Color Table
////////////////////////////
// These functions for the custom color popup are adapted from the FCKEditor

function CreateColorTable(targetTable, targetBox) {

	// Get the target table.
	var oTable = document.getElementById(targetTable) ;

	// Create the base colors array.
	var aColors = ['00','33','66','99','cc','ff'] ;

	AppendColorRow( oTable, 0, 0 ) ;
	AppendColorRow( oTable, 3, 0 ) ;
	AppendColorRow( oTable, 0, 3 ) ;
	AppendColorRow( oTable, 3, 3 ) ;

	// Create the last row.
	var oRow = oTable.insertRow(-1) ;
	
	// Create the gray scale colors cells.
	for ( var n = 0 ; n < 6 ; n++ )
	{
		AppendColorCell( oRow, '#' + aColors[n] + aColors[n] + aColors[n] ) ; 
	}
	
	// Fill the row with black cells.
	for ( var i = 0 ; i < 12 ; i++ )
	{
		AppendColorCell( oRow, '#000000' ) ; 
	}
	// Add event listeners
	oTable.addEventListener("mouseout", rteClearActual, false);
	document.getElementById(targetBox).addEventListener("keyup", rteUpdateColor, false);
}

function AppendColorRow( targetTable, rangeA, rangeB ) {
	// This function combines two ranges of three values from the color array into a row
	// Create the base colors array.
	var aColors = ['00','33','66','99','cc','ff'] ;
	for ( var i = rangeA ; i < rangeA + 3 ; i++ ) 
	{ 
		var oRow = targetTable.insertRow(-1) ; 

		for ( var j = rangeB ; j < rangeB + 3 ; j++ ) 
		{ 
			for ( var n = 0 ; n < 6 ; n++ ) 
			{ 
				AppendColorCell( oRow, '#' + aColors[j] + aColors[n] + aColors[i] ) ; 
			} 
		} 
	}
}

	
// This function create a single color cell in the color table.
function AppendColorCell( targetRow, color ) {
	var oCell = targetRow.insertCell(-1) ;
	oCell.className = 'ColorCell' ;
	oCell.bgColor = color ;
		
	// Add event listeners
	oCell.addEventListener("mouseover", function(){ document.getElementById('hicolor').style.backgroundColor = this.bgColor ; document.getElementById('hicolortext').innerHTML = this.bgColor ; }, false);
	oCell.addEventListener("click", function(){ document.getElementById('selhicolor').style.backgroundColor = this.bgColor ; document.getElementById('selcolor').value = this.bgColor ; }, false);
	oCell.addEventListener("dblclick", function(){ document.getElementById('selhicolor').style.backgroundColor = this.bgColor ; document.getElementById('selcolor').value = this.bgColor ; rteColorSubmit(); }, false);
	//oCell.addEventListener("click", rtetest, false);

}
function rtetest(event)
{
	//alert (event.currentTarget.parentNode.parentNode.parentNode.id);
	//document.getElementById('selhicolor').style.backgroundColor = '' ;
	//document.getElementById('selcolor').value = '' ;
}

function rteClearColors()
{
	document.getElementById('selhicolor').style.backgroundColor = '' ;
	document.getElementById('selcolor').value = '' ;
}

function rteClearActual()
{
	document.getElementById('hicolor').style.backgroundColor = '' ;
	document.getElementById('hicolortext').innerHTML = '&nbsp;' ;
}

function rteUpdateColor(event)
{ 
	try { 
	if (document.getElementById('selcolor').value.length == 6 || document.getElementById('selcolor').value.length == 7) 
		document.getElementById('selhicolor').style.backgroundColor = document.getElementById('selcolor').value ; 
	else
		document.getElementById('selhicolor').style.backgroundColor = '' ;	

	}

	catch (e) { rteClearColors() ; e.preventDefault();	 }
}

function rteCustomColor (apopup) {  
	
	apopup.innerHTML = '<table width="100%" border=0 cellpadding=2 cellspacing=0><tr><td class=head><b>Select a Color</b></td></tr></table>' 

	apopup.innerHTML += '<form name="form3" id="rteCustomColorForm">'
	+ '<table border="0" cellspacing="5" cellpadding="0" width="100%">'
	+ '<tr><td valign="top" align="center" nowrap width="100%">'
	+  '<table id="ColorTable" border="0" cellspacing="0" cellpadding="0" width="270">'
	+  '</table>'
	+  '</td>'
	+  '<td valign="top" align="left" nowrap>'
	+  '<b>Highlight</b><input type="hidden" id="CustomColor_Name">'
	+  '<div id="hicolor"></div>'
	+  '<div id="hicolortext">&nbsp;</div>'
	+  '<b>Selected</b>'
	+  '<div id="selhicolor"></div>'
	+  '<input id="selcolor" type="text" maxlength="20"><br>'
	+  '</td></tr>'
	+  '</table>'
	+  '<br><center><input type="button" name="CustomColor_Submit" id="CustomColor_Submit" value="Select" class=button><input class=button type="button" name="CustomColor_Cancel" id="CustomColor_Cancel" value="Cancel"></center></form>';

    	apopup.className = 'msgback';                                                                                      
    	apopup.style.zIndex = 2147483647;
    	apopup.style.position = 'absolute';
    	apopup.style.MozBorderRadius = '6px';
    	apopup.style.display = 'none';
    	apopup.style.textAlign = 'left';
    	apopup.style.padding = '10px';
    	apopup.style.width = '400px';

	return apopup;
}

function rteColorCancel() {
	colorPopup.style.display = 'none';
	rteClearColors();
}

function rteColorSubmit() {
	colorPopup.style.display = 'none';
	var aColor = window.document.getElementById('selcolor').value;
	if (typeof(optionPopup) == 'undefined') {
		EditorWin.document.execCommand('forecolor', false, aColor); 		
		EditorWin.focus();
	} else {
		if (optionPopup.style.display == 'none') {
		EditorWin.document.execCommand('forecolor', false, aColor); 		
		EditorWin.focus();
		} else {
		var SBox = window.document.getElementById('optionsList');
		var myAddName = window.document.getElementById('CustomColor_Name').value;
		var sep = ".|$.";

    		var NewLoc=SBox.length;
		myAddValue = sep + aColor;
		newOptionName = new window.Option(myAddName,myAddValue);
		SBox.options[NewLoc]=newOptionName;
		SBox.options[NewLoc].selected=true;
		}
	}
	rteClearColors();
return false;
}

////////////////////////////
//	Switch (WYSIWYG or Source)
////////////////////////////
function rteCreateSwitch(id, value, checked, title) {
    	var theSwitch, theText, box;
    	theSwitch = document.createElement('input');
    	theSwitch.type = 'radio';
	theSwitch.id = id;
	theSwitch.name = id;
	theSwitch.value = value;
	theSwitch.checked = checked;
	theSwitch.title = title;
	theSwitch.setAttribute('style', 'vertical-align: middle;');
	
	box = document.createElement('b');
	theText = document.createTextNode(value);
	box.setAttribute('style', 'vertical-align: top; margin: 10px;');
	box.appendChild(theSwitch);
	box.appendChild(theText);

	theSwitch.addEventListener("click", rteClickSwitch, true);
    return box;
}

function rteClickSwitch(event) {
var theSwitch;
    theSwitch = event.currentTarget;
    rteSetMode(theSwitch.value);
}

// Update textarea
function rteHtmlUpdate() {
	dflinkify();
	rteTextarea.value = EditorWin.document.body.innerHTML;
}	
// Update iframe
function rteDesignUpdate() {
  	EditorWin.document.body.innerHTML = rteTextarea.value;
}
// switch between Design and HTML modes
function rteSetMode(Mode) { 
	// if editor was not initialized on load, do it now
	if (rteInitializeEditor) { rteInitEditor(); }

	if (Mode == 'WYSIWYG') { 
		// Go to Design mode
  		rteDesignUpdate();		
		rteTextarea.setAttribute('style', 'display: none;');
		iframe.setAttribute('style', 'height: 250px;');

		EditorWin.focus();
	}
	else {
		// Go to HTML mode
		rteHtmlUpdate();
		iframe.setAttribute('style', 'height: 1px;');
		if (isEdit) {
rteTextarea.setAttribute('style', 'display: inline; width: '+(document.width-245)*0.96+'px; height: 250px;');
		} else {
		rteTextarea.setAttribute('style', 'display: inline; width: 95%; height: 250px;');
		}
	}
}

////////////////////////////
//	Submit Event Handler
////////////////////////////
function newsubmit(event) { 
    var target = event ? event.target : this;
	// for some reason, a carriage return causes the color popup to submit
	// added this code to eliminate problem
	if (target.id == "selcolor" || target.id == "rteCustomColorForm") {
	event.preventDefault();		// prevent the submit
	}
	// copy html from the iframe to the text area
	if (rteTextarea.style.display == 'none') {
	EditorWin.document.body.innerHTML  = EditorWin.document.body.innerHTML.replace(/<p class="MsoNormal">/g, '<p>').replace(/<[-a-z0-9]+:[-a-z0-9]+( [-a-z0-9]+:[-a-z0-9]+="[-a-z0-9]+)*">/gi, '').replace(/<\/[-a-z0-9]+:[-a-z0-9]+>/g, '').replace(/<[/]?st1:[a-zA-Z]+>/g,'');
	// strip out Microsoft city and place tags
	// EditorWin.document.body.innerHTML  = EditorWin.document.body.innerHTML.replace(/<[/]?st1:[a-zA-Z]+>/g,'');
	rteHtmlUpdate();
	}
} 

////////////////////////////
//	Linkify
//////////////////////////// 
// make urls linkable	
function dflinkify () { 
	// code from http://downloads.mozdev.org/greasemonkey/linkify.user.js
	const urlRegex = /\b(https?:\/\/[^\s+\"\<\>]+)/ig;

	// tags we will scan looking for un-hyperlinked urls
	var allowedParents = ["abbr", "acronym", "address", "applet", "b", "bdo", "big", "blockquote", "body", "caption", "center", "cite", "code", "dd", "del", "div", "dfn", "dt", "em", "fieldset", "font", "form", "h1", "h2", "h3", "h4", "h5", "h6", "i", "iframe", "ins", "kdb", "li", "object", "pre", "p", "q", "samp", "small", "span", "strike", "s", "strong", "sub", "sup", "td", "th", "tt", "u", "var"];
    
	var xpath = "//text()[(parent::" + allowedParents.join(" or parent::") + ") and " + "contains(translate(., 'HTTP', 'http'), 'http')]";

    var candidates = EditorWin.document.evaluate(xpath, EditorWin.document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);

	for (var cand = null, i = 0; (cand = candidates.snapshotItem(i)); i++) {
        if (urlRegex.test(cand.nodeValue)) {
            var span = EditorWin.document.createElement("span");
            var source = cand.nodeValue;
            
            cand.parentNode.replaceChild(span, cand);

            urlRegex.lastIndex = 0;
            for (var match = null, lastLastIndex = 0; (match = urlRegex.exec(source)); ) {
                span.appendChild(EditorWin.document.createTextNode(source.substring(lastLastIndex, match.index)));
                
                var a = EditorWin.document.createElement("a");
                a.setAttribute("href", match[0]);
                a.appendChild(EditorWin.document.createTextNode(match[0]));
                span.appendChild(a);

                lastLastIndex = urlRegex.lastIndex;
            }

            span.appendChild(EditorWin.document.createTextNode(source.substring(lastLastIndex)));
            span.normalize();
        }
	}
}
////////////////////////////
//	Check For Updates to RTE
////////////////////////////

function checkForUpdates() {

	var RTEVersion = 4.1;
	var oldVersion = GM_getValue("RTEVersion", "0")	

	if (oldVersion < RTEVersion) { 

	// setup defaults
    	var sep = ".|$.";
	var newNames, newList ;
	var baseURL = "http://ffextensionguru.com/gofirefox/th_";

	newNames = GM_getValue("SmileyNames", "");
	if (newNames == "") {

	// this is the list for brand new users of the editor 
	newNames = "2Funny"
	newList  = baseURL + "2funny.gif";
	newNames += sep + "Angel"
	newList  += sep + baseURL + "angel.gif";
	newNames += sep + "Angry"
	newList  += sep + baseURL + "angry.gif";
	newNames += sep + "Bow"
	newList  += sep + baseURL + "bow.gif";
	newNames += sep + "Bravo"
	newList  += sep + baseURL + "bravo.gif";
	newNames += sep + "Censored"
	newList  += sep + baseURL + "censored.gif";
	newNames += sep + "Cheesy"
	newList  += sep + baseURL + "cheesy.gif";
	newNames += sep + "Cool"
	newList  += sep + baseURL + "coolsmiley.gif";
	newNames += sep + "Crying"
	newList  += sep + baseURL + "crying.gif";
	newNames += sep + "Doh"
	newList  += sep + baseURL + "doh.gif";
	newNames += sep + "Dont Know"
	newList  += sep + baseURL + "dontknow.gif";
	newNames += sep + "Dunce"
	newList  += sep + baseURL + "dunce.gif";
	newNames += sep + "Grumble"
	newList  += sep + baseURL + "grumbel.gif";
	newNames += sep + "Handshake"
	newList  += sep + baseURL + "handshake.gif";
    	newNames += sep + "Happy";
    	newList  += sep + baseURL + "happy.gif";
	newNames += sep + "Hug"
	newList  += sep + baseURL + "hug.gif";
	newNames += sep + "Kiss"
	newList  += sep + baseURL + "kiss.gif";
	newNames += sep + "Love"
	newList  += sep + baseURL + "love.gif";
	newNames += sep + "Shocked"
	newList  += sep + baseURL + "shocked.gif";
	newNames += sep + "Shy"
	newList  += sep + baseURL + "ashamed.gif";
	newNames += sep + "Silly"
	newList  += sep + baseURL + "silly.gif";
	newNames += sep + "Sleepy"
	newList  += sep + baseURL + "sleepy.gif";
	newNames += sep + "Stupid"
	newList  += sep + baseURL + "stupid.gif";
	newNames += sep + "Talkative"
	newList  += sep + baseURL + "talkative.gif";
	newNames += sep + "Tantrum"
	newList  += sep + baseURL + "tickedoff.gif";
	newNames += sep + "Thumb Up"
	newList  += sep + baseURL + "thumbup.gif";
	newNames += sep + "Tongue"
	newList  += sep + baseURL + "tongue.gif";
	newNames += sep + "Trouble"
	newList  += sep + baseURL + "trouble.gif";
	newNames += sep + "Undecided"
	newList  += sep + baseURL + "undecided.gif";
	newNames += sep + "Whistle"
	newList  += sep + baseURL + "whistle.gif";
	newNames += sep + "Wonder"
	newList  += sep + baseURL + "wonder.gif";

	GM_setValue("SmileyNames", newNames);
	GM_setValue("Smileys", newList);
	
	} else {
	// this corrects URLs for old smileys

	newList = GM_getValue("Smileys", "");
	newList = newList.replace("http://tinyurl.com/yfg6o6/", baseURL, "g");
	newList = newList.replace("http://tinyurl.com/2hqm6h/", baseURL, "g");
	newList = newList.replace("http://tinyurl.com/yfg6o6/smile_gold.gif", baseURL + "happy.gif");
	newList = newList.replace("http://users.pandora.be/eforum/emoticons4u/happy/1055.gif", baseURL + "handshake.gif");
 	newList = newList.replace("http://users.pandora.be/eforum/emoticons4u/happy/799.gif", baseURL + "happy.gif");
	newList = newList.replace("http://users.telenet.be/eforum/emoticons4u/love/216.gif", baseURL + "hug.gif");
	newList = newList.replace("http://users.pandora.be/eforum/emoticons4u/sleep/schla01.gif", baseURL + "sleepy.gif");
	newList = newList.replace("http://imagehost.biz/ims/pictes/209228.gif", baseURL + "whistle.gif");
	newList = newList.replace("http://pro.imagehost.biz/ims/pictes/209192.gif", baseURL + "wonder.gif");
	newList = newList.replace("http://www.teccentral.de/forum/images/eigene_smilies/a0222220.gif", baseURL + "angel.gif");
	newList = newList.replace("http://www.todojuegos.com/modules/Forums/images/smiles/badmood.gif", baseURL + "angry.gif");
	newList = newList.replace("http://i2.photobucket.com/albums/y43/christianchr/Emoticons_2/worthy.gif", baseURL + "bow.gif");
	newList = newList.replace("http://img.photobucket.com/albums/v209/Sasafrass/Smilies/clapping.gif", baseURL + "bravo.gif");
	newList = newList.replace("http://img90.exs.cx/img90/2365/k1ocray.gif", baseURL + "crying.gif");
	newList = newList.replace("http://tinyurl.com/yfg6o6/doh.gif", baseURL + "doh.gif");
	newList = newList.replace("http://img116.exs.cx/img116/934/z0tdntknw.gif", baseURL + "dontknow.gif");
	newList = newList.replace("http://ganjataz.com/01smileys/images/smileys/saddunce.gif", baseURL + "dunce.gif");
	newList = newList.replace("http://www2.flirtlife.de/images/smiles/grummel.gif", baseURL + "grumbel.gif");
	newList = newList.replace("http://smily.hit.bg/hug.gif", baseURL + "hug.gif");
	newList = newList.replace("http://tinyurl.com/yfg6o6/smooch0bv.gif", baseURL + "kiss.gif");
	newList = newList.replace("http://www.crackmanworld.com/inc/libs/editor_files/images/smileys/smiley9.gif", baseURL + "ashamed.gif");
	newList = newList.replace("http://www.asturcon3.com/emicons/KOLOBOK/aiwan_smiles/tease.gif", baseURL + "silly.gif");
	newList = newList.replace("http://tinyurl.com/yfg6o6/h9yboredom.gif", baseURL + "sleepy.gif");
	newList = newList.replace("http://img62.exs.cx/img62/2879/silly30gn.gif", baseURL + "talkative.gif");
	newList = newList.replace("http://img26.exs.cx/img26/2245/thumbsup8de.gif", baseURL + "thumbup.gif");


	if (oldVersion <= 3.5) {
	if (newList.indexOf("coolsmiley.gif") == -1) {
	// add new smileys for people already using the editor
	newNames += sep + "Censored";
	newList += sep + baseURL + "censored.gif";
	newNames += sep + "Cool";
	newList += sep + baseURL + "coolsmiley.gif";
	newNames += sep + "Doh";
	newList += sep + baseURL + "doh.gif";
	newNames += sep + "Tantrum";
	newList += sep + baseURL + "tickedoff.gif";
	newNames += sep + "Tongue";
	newList += sep + baseURL + "tongue.gif";
	newNames += sep + "Trouble";
	newList += sep + baseURL + "trouble.gif";
	}
	}
	if (oldVersion <= 3.6) {
	if (newList.indexOf("2Funny.gif") == -1) {
	// add new smileys for people already using the editor
	newNames += sep + "2Funny";
	newList += sep + baseURL + "2funny.gif";
	newNames += sep + "Cheesy"
	newList  += sep + baseURL + "cheesy.gif";
	newNames += sep + "Love"
	newList  += sep + baseURL + "love.gif";
	newNames += sep + "Shocked"
	newList  += sep + baseURL + "shocked.gif";
	newNames += sep + "Stupid"
	newList  += sep + baseURL + "stupid.gif";
	newNames += sep + "Undecided"
	newList  += sep + baseURL + "undecided.gif";
	}
	}
	GM_setValue("SmileyNames", newNames);
	GM_setValue("Smileys", newList);
	}

	newNames = GM_getValue("FontNames", "");
	if (newNames == "") { 
    	newNames  = "Geneva";
    	newList   = "geneva,verdana,arial,helvetica,sans-serif";
	newNames += sep + "Arial";
	newList  += sep + "arial,geneva,verdana,sans-serif";
	newNames += sep + "Arial Black";
	newList  += sep + "'Arial Black',Gadget,sans-serif";
	newNames += sep + "Chiller";
	newList  += sep + "Chiller,fantasy";
	newNames += sep + "Comic";
	newList  += sep + "'Comic Sans MS',cursive";
	newNames += sep + "Console";
	newList  += sep + "'Lucida Console',Monaco,monospace";
	newNames += sep + "Courier";
	newList  += sep + "'Courier New', Courier, monospace";
	newNames += sep + "Cursive";
	newList  += sep + "'Lucida Handwriting',cursive";
	newNames += sep + "Fantasy";
	newList  += sep + "fantasy";
	newNames += sep + "Georgia";
	newList  += sep + "georgia,verdana,arial,geneva,arial,helvetica,serif";
	newNames += sep + "Impact";
	newList  += sep + "Impact,Charcoal,sans-serif";
	newNames += sep + "Palatino";
	newList  += sep + "Palatino Linotype,'Book Antiqua',Palatino,serif";
	newNames += sep + "Times";
	newList  += sep + "'Times New Roman',Times,serif";
	newNames += sep + "Verdana";
	newList  += sep + "verdana,geneva,arial,helvetica,sans-serif";

	GM_setValue("FontNames", newNames);
	GM_setValue("myFonts", newList);
	}

	newNames = GM_getValue("ColorNames", "");
	if (newNames == "") {
	var colorList = ['000000','808080','800000','ff0000','ff1493','ffb6c1','800080','ee82ee','00008b','0000ff','00ffff','87ceeb','008080','008000','00ff7f','ffa500','b8860b','ffff00','ffe4c4','ffffff'];
	var nameList = ['Black','Grey','Maroon','Red','Deep Pink','Light Pink','Purple','Violet','Dark Blue','Blue','Aqua','Sky Blue','Teal','Green','Spring Green','Orange','Dark Golden Rod','Yellow','Bisque','White'];

	newList = "";
	for (var i = 0; i < nameList.length; i++) {
		if (i > 0) {
		newNames += sep;
		newList += sep;
		}
		newNames += nameList[i];
		newList += colorList[i];
	}
	GM_setValue("ColorNames", newNames);
	GM_setValue("myColors", newList);
	}
	
	// patch to correct Delphi URLs in Sig List	03/25/2006
	var i, newSigList, temp_array 
	var root = "http://people.delphiforums.com/"; 
	temp_array= GM_getValue("Signatures", "").split(root); 
	newSigList = temp_array[0];
	for (i = 1; i <= temp_array.length-1; i++) {
		//change membername to lowercase
		indx = temp_array[i].indexOf('/');
		if (indx > 0) {
		temp_array[i] = temp_array[i].substring(0,indx).toLowerCase() + temp_array[i].substring(indx,temp_array[i].length); 
		}
		newSigList += root + temp_array[i]
	}
	if (newSigList.length > 0)
		GM_setValue("Signatures", newSigList);

	temp_array= GM_getValue("BasicSignatures", "").split(root); 
	newSigList = temp_array[0];
	for (i = 1; i <= temp_array.length-1; i++) {
		//change membername to lowercase
		indx = temp_array[i].indexOf('/');
		if (indx > 0) {
		temp_array[i] = temp_array[i].substring(0,indx).toLowerCase() + temp_array[i].substring(indx,temp_array[i].length); 
		}
		newSigList += root + temp_array[i]
	}
	if (newSigList.length > 0)
    		GM_setValue("BasicSignatures", newSigList);
	
	GM_setValue("RTEVersion", "4.1");
}
}

////////////////////////////
//	Configure Styles
////////////////////////////	
function configureStyles() {

// Configure styles - iframe will use some styles from the text area
// Note that some variables are global

//var styleAddr = document.styleSheets[0].href;
editorStyle = getComputedStyle(rteTextarea, '');

if (isEdit) {
var editorWidth = ((document.width-245)*0.96)+'px';
} else {
var editorWidth = '95%';
}
if (isSignature)
	editorWidth = '700px';
if (isNewPlatform)
	editorWidth = '600px';

var rteCSS = GM_getValue("rteDefaults", "");
if (rteCSS.charAt(0) == "1") rteUseDefaultBck = false; 
else rteUseDefaultBck = true;

if (rteUseDefaultBck) var editorBck = 'background-image: url(data:image/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAABeCAAAAADUcWGDAAAABGdBTUEAANbY1E9YMgAAAAlwSFlzAAAASAAAAEgARslrPgAAAiJJREFUeNptkut%2BojAQxc%2F7v4dyFVTkflOhVgURWqCt1n2WPWPr%2Fvyw%2FyST4ZJkZnJwIV8CruTrcvcu16u8v%2BB2u%2F25CfhDnrxv8eTrt3Bfe5GB8eMXvD%2FAuWmaE1uD42F%2F2O8PhwOKoiw5igJZvs6zPMsyxHEURnEUhXA9z%2FM913fhOM5yuVwsHVhzYtv2HKZlmuZsNjOhm4ah6%2BxQNVXTNU1ToaqaoqrKVMFUnSqcVQXKRKGnKiomk8mU7%2BWroqiygCv4i6xXIQtVXdd0yGays0aPGKZp8DQ6hslzxTACawaLYVg0FizLsm1GZWNuW%2FbcZrCYLxb2gizBJJyl4ywccFrdG9zVynFWrufCdV3PZ8IBfM8PfC8IQoRR4IcsSMK6kCRKEqRpnGZJmqbIszRj3bI11uvNerPdbAqU5bYotmWxxW73Ir3c4XUn8Al7chCD6njncERFjlVVV6iruq5OVX1Ccz43vLFzA3FamhZt23Zte247dG3XdW8ccr9v7z0bhl6mvu8xDEM%2F0gwYhYED1MJ47%2Fj84eMTXw%2BevMuDJ%2B%2F64L%2Fe03%2F%2FvJ%2FNPrnfOPKkuxLH32AG9MLAWPHevd3pJLdWcmtxkqxFqjjVLMuxqo9ULKHZY89SSn%2FFS0ntstZbbKX0%2BSbPIQrOU7mZJI2TJE7iCEEYhGEY%2BLxVETT17IE3TmipjfliKUY0ZFEyFpVtmr%2B60g0q0KDaoFOnFKqu%2FQV0lIUEDyBfbgAAACJ6VFh0U29mdHdhcmUAAHjac0zJT0pV8MxNTE8NSk1MqQQAL5wF1K4MqU0AAAAASUVORK5CYII%3D);';
else editorBck = '';
	
rteAddGlobalStyle(
'.mytable{ margin-top: 2px; margin-bottom: 0px;  border-collapse: collapse; text-align: left; width: ' + editorWidth + ';' + editorBck + 'background-color: #cfcfcf;}' +
'.editbuttons td { padding: 2px 2px 0px 2px; }' +
'.editbuttons select { margin: 2px; float: left; }' +
'.editbuttons img { margin: 1px; border:0; background: transparent; float: left; }' +
'.editbuttons .sep { margin-left: 5px; float: left; }' +
'.editbuttons img.more { margin-left: 5px; float: right; }' +
'.editbuttons img:hover { background-color: e2e2e2; }' +
'object {background-color: blue; border: 1px solid; display:block; }' +
'#rteEditor { width: ' + editorWidth + '; height: 250px; border: 1px solid #a5acb2;}'  + 
'#colorChart p  {width: 28px; height: 15px; float: left; margin: 0px; cursor:pointer; }' +
'#ColorTable { cursor: pointer ; cursor: hand ; }' +
'#hicolor { height: 74px ; width: 74px ; border-width: 1px ; border-style: solid ; }' +
'#hicolortext { width: 75px ; text-align: right ; margin-bottom: 7px ; }' +
'#selhicolor { height: 20px ; width: 74px ; border-width: 1px ; border-style: solid ; }' +
'#selcolor { width: 75px ; height: 20px ; margin-top: 0px ; margin-bottom: 7px ; }' +
'#btnClear { width: 75px ; height: 22px ; margin-bottom: 6px ; }' +
'.ColorCell { height: 15px ; width: 15px ; }'
);

}

////////////////////////////
//	Create Toolbar
////////////////////////////
	
// Add toolbar - match structure/styles of DelphiForums

function createToolbar() {
if (rteUseDefaultBck) rteEditorID = "rteToolbar";
else rteEditorID = "tb2";

	var mytable = document.createElement('table');
		with (mytable) {
		className = "mytable";
		id = rteEditorID;
		}

	mytablebody = document.createElement("tbody");
	mycurrent_row = document.createElement("tr");
	with (mycurrent_row){
		className = 'editbuttons';
		}
	mycurrent_cell=document.createElement("td");
	
	mycurrent_cell.innerHTML = rteCreateDropdown('formatblock');
	mycurrent_cell.innerHTML += rteCreateDropdown('fontname');
	mycurrent_cell.innerHTML += rteCreateDropdown('fontsize');
	//mycurrent_cell.innerHTML += rteCreateDropdown('forecolor');
	mycurrent_cell.innerHTML += rteCreateDropdown('insertsmiley');

	if (basicSig || basicMyPrefs ) {	
		var vNames = "BasicNames";
		var vNamesAlt = "FriendlyNames"; 
	} else {
    		var vNames = "FriendlyNames";
		var vNamesAlt = "BasicNames"; 
	}

	if (hasSig && GM_getValue(vNames, "") != "") {
	mycurrent_cell.innerHTML += rteCreateDropdown('switchsig');
	} else {
	// check the other sig list
	if (hasSig && GM_getValue(vNamesAlt, "") != "") {
	mycurrent_cell.innerHTML += rteCreateDropdown('switchsig');
	}
	}

	if (isSignature) {
	mycurrent_cell.appendChild(rteCreateButton(
 		'Save Sig In List',
		false,
		'data:data:image/gif;base64,R0lGODlhFQAUAPcEAAAAAMDAwJSetYCAAP%2F%2F%2FwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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%2F48KCowMDIwHB4gJCowMDAwPDw8GBoYMB4QLCYcEAwIKCQcKOssWBocICQkKCosF5nZP%2F4%2F4STq6C40NCAMEBQYLCwsMDI0EBIUG1vcrbH49DY0LXH46aus6CwsKCwwGBIMJWgrZCYkPCwUHBoUNDY8ICIkP%2FIYFBYULDQ8I2eseDg4KW2yWBQMOCgQMDY8GBYUIiOoY6asOCYQGBwcHBQMLCQYJBwQJCYoLfH4zBIYJCgsP%2F%2F%2F%2F%2F%2F%2FwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAEkALAAAAAAVABQAAAeogEmCg4SFhoeIiYqLAI2NBAkCRYtJAEiXmA1GJosEmJgQI0Yoigmfl0dGqoofnwwOChoGIYoCmAwHEQEBKkCKK5gOEZcFCEctiQ2YCgFIBQsDACWJEJhEAc8DMQIciUeYIgcIAzs1Dz0piN%2BXNwYbBAIPNEIVGIfrHRInLhkTPEM6ZlzAYejbkYMIj8gIAuLHCxgFVUmcSCIHBRY2KBXyYcGDxo8gCQUCADs%3D'));
	}

	if (hasSig) {
	mycurrent_cell.appendChild(rteCreateButton(
 		'No Sig',
		false,
		'data:image/gif;base64,R0lGODlhFQAUAIABAAAAAAAAACH5BAEAAAEALAAAAAAVABQAAAIpjI%2Bpy%2B3vAFxAzootxIbvGmRXpn3idJBlI6lX2IJmJz%2FqyuIvyvc%2BWgAAOw%3D%3D'));
	}

	mycurrent_cell.appendChild(rteCreateButton(
		'Show Or Hide',
		false,
		'data:image/gif;base64,R0lGODlhFQAUAKIEACFShAAAAE11nRpCav%2F%2F%2FwAAAAAAAAAAACH5BAEAAAQALAAAAAAVABQAAAM0SLrc%2FkvAqQQA9NmLc7wE5xHbIlIlc45sywQELMf0PLs4uyrXkK29kSio4%2FhcRNwxxxwlAAA7')) ;
	
	mybr = document.createElement("br");
	mybr.setAttribute('style', 'clear: both;');
	mycurrent_cell.appendChild(mybr);

	mycurrent_cell.appendChild(rteCreateButton(
 		'Bold',
		false,
		'data:image/gif;base64,R0lGODlhFQAUAIABAAAAAP///yH5BAEAAAEALAAAAAAVABQAAAIkjI+py+0Po1Sg2iqt0ZDz52HdJY7AVjrhaaKsSqbTTNf2jR8FADs='));
	mycurrent_cell.appendChild(rteCreateButton(
		'Italic',
		false,
		'data:image/gif;base64,R0lGODlhFQAUAJECAICAgAAAAP///wAAACH5BAEAAAIALAAAAAAVABQAAAIglI+py+0Po3Sh1mkqwAJcrnFewAkhNpanZFnlC8fyDBUAOw=='));
	mycurrent_cell.appendChild(rteCreateButton(
		'Underline',
		false,
		'data:image/gif;base64,R0lGODlhFQAUAJECAICAgAAAAP///wAAACH5BAEAAAIALAAAAAAVABQAAAIplI+py+0Po1ShBmEvrIdHj2mbCD5g6ZyiSa5pAAgA+lrTjWQ6zvf+XQAAOw=='));
	mycurrent_cell.appendChild(rteCreateButton(
 		'More Colors',
		false,
		'data:image/gif;base64,R0lGODlhFQAVALMAAACZAABmAP8A%2FwD%2F%2F%2F8AAP%2F%2FAAAA%2FwAAAGZmZv%2F%2F%2FwAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAkALAAAAAAVABUAAARRMMlJq704a326%2F9sxdWM4ihK6pepKkW5FInRdZzOhI0OP4CKEjsDzARO25AXxQRSeiAAg8Ns4oVNAVZO0rRCGMEJA3mbAYrLAjOneYvC4fBIBADs%3D'));
	mycurrent_cell.appendChild(rteCreateButton(
 		'Default Font',
		false,
		'data:image/gif;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAIAAAAC64paAAAABGdBTUEAAAAAiyVgTQAAAAZ0Uk5TAP8A%2FwD%2FN1gbfQAAAXtJREFUOI2llLFqwlAUhv9bHGyXgJKhT%2BAgTqUgdMlSelN8AXHMpJNbssQpQ7K4CoKDYMnQIYJiSlskpV1KXZqtbj6BQ4dWoT0dUjXGWkX%2F6Z577sc55%2BdwGRFhVx3sTAKIRWLXdX3fB6Cq6maaQioWi9lsNjjn83lRFOlfLeBerwdA07T5TSqV2hY2TRNAuJpt29vCFLKdcx5512i8mabvOK9rYdu2w3YEI7Raw1zuvlzuEFG1%2BpROO5zf%2FgEH4pyH7QRugIHjeEFWUbqK0o3CkQlFUZzB18BAktzVMoslGY1GpVJpHjabzdlRAKaeJzL2rOvd8FxLG1ar1VzXXVmEc%2BALmAIxwzhmzGu3H4MUm5tsWVZQXxAEAJ7nVSoVWZaDrK6%2FGMYncAQA%2BCY6jW7YRknSA9AHBkEYrRyRqqqa1spkEoXC5W%2BrrA8IRCdLba8TY1dAgkiehXfAEdHZVrBldcZjNpkcxuOJ4fA9mfyo1y%2Bihu2gvT6DveAfzbnScqfxawAAAAAASUVORK5CYII%3D'));
	
	if (hasSpellcheck) {
	mycurrent_cell.appendChild(rteCreateButton(
		'Spell Check',
		false,
		'data:image/gif;base64,R0lGODlhFQAUANU%2FAHaW0Yys7K27y2aJyW6V4ipNlXZ8hDtis36i6lmD1oaTok5SVn2FkBASFlZeZ0ZIS1F91Fl6u4Om6VRXW7PL6zddqjxCSW53giMmKiwwNRseIczh%2B52687DB1VZ7xGBiZlBzt1d7voqQmUFrwktywUt51V1vjp%2BsvKvD5qO94azI8kNnsoyZqXSRxkVMVKaxv7K%2Fz5CYoq290FxiabG%2F0bHL93F0eIyYpm9ydj9qvzQ4PLzL3Za351J1uoim2f%2F%2F%2FyH5BAEAAD8ALAAAAAAVABQAAAaOwJ9wSCwaj8ikcik0%2FGCLD%2BP3mjweO6TAJqAtfjHR7Pa7TI%2BTH0bQ0OFODtmwRigqGhjMxfVjOCwKZSYJLUUZgSwaeBYdChmKKyBMRBsBEBEUk0MSl5maPxIJPShLHAGbBAcpSwEICAQqrgc%2BTAcHCa8EOSGaHgUkJSMVnz8%2BBQcVAMQ%2FAwUDy0I80NPEQQA7'));
	}
	mycurrent_cell.appendChild(rteCreateButton(
		'Quick Quote',
		false,
		'data:image/gif;base64,R0lGODlhFQAVAKIHAA4ODra2tmFhYQAAYmJiYgAAAP%2F%2F%2F%2F%2F%2F%2FyH5BAEAAAcALAAAAAAVABUAAANEeLrc%2FjDKSeW4OOPyiPlg%2BHGOJ55kYwpsQLxgyphnKC%2B0wQqueSu5muF3yAGOx1hHaFvqdignc%2FgoWK9YbGXL7Xq%2F3AQAOw%3D%3D'));
	mycurrent_cell.appendChild(rteCreateButton(
		'Justify Left',
		true,
		'data:image/gif;base64,R0lGODlhFQAUAIABAAAAAP///yH5BAEAAAEALAAAAAAVABQAAAIfjI+py+0PGZi01oiDtbnrDXoPSIkYuZkNCqjuC8dIAQA7'));
	mycurrent_cell.appendChild(rteCreateButton(
		'Justify Center',
		false,
		'data:image/gif;base64,R0lGODlhFQAUAIABAAAAAP///yH5BAEAAAEALAAAAAAVABQAAAIejI+py+0PGZi01oiPtTnvD3QYOIkRyZkPqrbuCy8FADs='));
	mycurrent_cell.appendChild(rteCreateButton(
		'Justify Right',
		false,
		'data:image/gif;base64,R0lGODlhFQAUAIABAAAAAP///yH5BAEAAAEALAAAAAAVABQAAAIejI+py+0PGZi01oiTtTnuD3QdOIkPyZkeqbbuCycFADs='));
	mycurrent_cell.appendChild(rteCreateButton(
		'Justify Full',
		false,
		'data:data:image/gif;base64,R0lGODlhFQAVAPcAAMDAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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qFTZuZGGp7YI235n1nzh6Oa6WwAAOw=='));
	mycurrent_cell.appendChild(rteCreateButton(
		'Insert Unordered List',
		false,
		'data:image/gif;base64,R0lGODlhFQAUAJECAAAAgAAAAP///wAAACH5BAEAAAIALAAAAAAVABQAAAIklI+py+0O4lsRmIBzpnL6DyZVaIyChnIWybZiF5qoprr2jX8FADs='));
	mycurrent_cell.appendChild(rteCreateButton(
		'Outdent',
		true,
		'data:image/gif;base64,R0lGODlhFQAUAJECAAAAgAAAAP///wAAACH5BAEAAAIALAAAAAAVABQAAAIrlI+py63hojyhQovr3AKgjCmAR4EaMqacMX6ZQxrgyoXmSTc2lPeyDwxGCgA7'));
	mycurrent_cell.appendChild(rteCreateButton(
		'Indent',
		false,
		'data:image/gif;base64,R0lGODlhFQAUAJECAAAAgAAAAP///wAAACH5BAEAAAIALAAAAAAVABQAAAIrlI+py63hojyhQovr3AKgjC2AZ4BWMqbcMVKZQ5bvuoWmRjs2lPelDwxGCgA7'));

	mycurrent_cell.appendChild(rteCreateButton(
		'Insert Horizontal Rule',
		true,
		'data:image/gif;base64,R0lGODlhFQAUAPcDAIiNnYCAgAAAAP%2F%2F%2FwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAMALAAAAAAVABQAAAhIAAcIHEiwoMGDCBMqXMhQYYCGBh8%2BHBCgosWKCC1CJChR4EWNG0OKFPivpMmTJw%2BiXGly5MKJIjtS%2FIjxIMiQMmnCdMmzp8GAADs%3D'));
	mycurrent_cell.appendChild(rteCreateButton(
		'Undo',
		false,
		'data:image/gif;base64,R0lGODlhFgAWAJECAAAAmQAAAP%2F%2F%2FwAAACH5BAEAAAIALAAAAAAWABYAAAIllI%2Bpy%2B0Po5yUgXsfOJnvln2JuGAk55hlqiJd9VbyTNf2jedPAQA7'));
	mycurrent_cell.appendChild(rteCreateButton(
		'Redo',
		false,
		'data:image/gif;base64,R0lGODlhFgAWAJECAAAAmQAAAP%2F%2F%2FwAAACH5BAEAAAIALAAAAAAWABYAAAImlI%2Bpy%2B0Po5z0gHtptsC6rnQbAyZYuaDcmKqnGsLVTNf2jec6VQAAOw%3D%3D'));

//	mycurrent_cell.appendChild(rteCreateButton(
//		'Insert HTML',
//		false,
//		'data:image/gif;base64,R0lGODlhFQAUAOZNAJKanWd4kNfh9pGbnZGbnDM9S5GbmsfV8s%2Fb9JKcnv3RaJGntIiYsO%2Fz%2B%2Fjksd%2Fn%2BJCcmvX4%2FHeGnISUq7%2FP8JCcnJOcm%2B%2Fz%2FI2dtPnmrsLIwo2ctI6enufu%2BpGgt5OktJGZm%2Bjt%2BfvksNbZ1v3TZ4CQp%2Bfu%2BZGamZCamZGntb%2FP8fv8%2F%2Fb4%2Ffr8%2F5SnuJmovvv8%2FpSlu%2Frlruft%2BvvTZJOkupyrwY6cnJOaoJKanO7y%2B3uMo3%2BPpvjkr%2FzTZ77BtZ%2BuxeDo%2BJKboIaXrZqpv%2FX3%2FY2cmbjK7%2FzRaXeDlzVJY9XRvv%2F%2F%2F%2F%2F%2F%2FwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAE0ALAAAAAAVABQAAAe0gE2Cg4SFhoeIiSMEHCA4RhCJhTkKND5IJAoEKS4fCxqIBCIOPRkOMgBLqksLiBBLAatLAyg3BkIJP4cGsr2rFocJsEzExcVLJ4cDvr4Du8PGxrOHBKtANi8xHhsMDBMlOxKFFbBLRMUwRQ0NHQ8CSoWpqjVMBQURSfn5CPCEAP8AMDBpEUFHiCACBCA40O%2FQkBX2TOjLp6KhIR4sLsxwt%2FAAhSMWC0lQQrKkyZCSUqpcyTIQADs%3D'));
	mycurrent_cell.appendChild(rteCreateButton(
		'Remove Format',
		false,
		'data:image/gif;base64,R0lGODlhFQAUAPcFAJSetcDA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AAAAAACH5BAEAAAUALAAAAAAVABQAAAhdAAsIHEiwoMGDCBMqXMiw4cAB%2FyL%2BGzCg4b8ABDAGCPCP4cWMICEu%2FKiRwMSOCUmCnEgxZUmMLFEeVAmTokyDEDfqjKnwos6NJ0f%2BBHoTIUSJESs6XMq0qdOnSwMCADs%3D'));

	
	mycurrent_cell.appendChild(rteCreateButton(
		'Create Link',
		true,
		'data:image/gif;base64,R0lGODlhFgAWALMBAP%2F%2F%2F%2F%2F%2F%2F39%2FfwAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAEALAAAAAAWABYAAAQ%2BMMhJq7046827%2F2AoZsJjmtJpClcJAJP5xmz1wGr%2BpNa93zBJKfDrpXQnXmU4KT1qKSjFmSSqpKOsdsvteiMAOw%3D%3D'));
		//'data:image/gif;base64,R0lGODlhGQAYALMIAE1NTQCAAMDAwAAA/4CAgP///wAAgACAgP///wAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAgALAAAAAAZABgAAARxEMlJq7046827n0QofiBxCGgAkEQhuEGseuHgDvgQEx0xoAJDTDfj+ASygOEgXBlxyCTOufHlkocBVUMwXGUDA68DyAHOAAN6m0kDXi+Ay8XGvNd4Qd0ivwPvBXsVd3hoemRwgXOHHmsIjiSRkpOUHxEAOw=='));
	mycurrent_cell.appendChild(rteCreateButton(
		'UnLink',
		true,
		'data:image/gif;base64,R0lGODlhFQAUAPcEAAAAAJCdsszMzP%2F%2F%2F%2F%2F%2F%2FwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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XAigocOHEA1CnPhQYsMAGDNmdGhRo0eMDTt%2B1Biy4MWRGwGIRBmgJMGTLF0OhIlSpkCHMW3%2Bo8jTIgCQD4GqNHkSolCfPCsSTap0odOnUKEGBAA7'));
	mycurrent_cell.appendChild(rteCreateButton(
		'Insert Image',
		true,
		'data:data:image/gif;base64,R0lGODlhEgASAKIAAP%2F%2FAAD%2F%2F4CAgICAAACAAIAAAAAAAP%2F%2F%2FyH5BAUUAAcALAAAAAASABIAAANZeLrc%2FlAZQaulhokyuO9gtgiDYZ5oISpbFhwvIB%2BlVr74ASiq1r8CmLA2uh2ClECwN%2BoFWUgiq%2FQ8HilMVqF6Ia2OA8JBTB63fIS0ei0Ff96dL2o%2Bj9jvkAQAOw%3D%3D'));
	
//	mybr = document.createElement("br");
//	mybr.setAttribute('style', 'clear: both;');
//	mycurrent_cell.appendChild(mybr);

	myextraline = document.createElement("div");
	myextraline.id = "rteExtraLine";

	myextraline.appendChild(rteCreateButton(
		'Strikethrough',
		false,
		'data:image/gif;base64,R0lGODlhFQAUAJECAAAAMwAAAAAAAAAAACH5BAEAAAIALAAAAAAVABQAAAIllI%2Bpy%2B0Po2Sh2hAr0pAf3HmTcEnXWZpiA36tI64UOtb2jedCAQA7'));
	myextraline.appendChild(rteCreateButton(
		'Superscript',
		false,
		'data:image/gif;base64,R0lGODlhFQAVAJEAAIAAAAAAAP%2F%2F%2FwAAACH5BAEAAAIALAAAAAAVABUAAAIhlI%2Bpy%2B0Po4wATGWvyZr3%2BgSBIV5iqaHmuZKjBsfyTGsFADs%3D'));
	myextraline.appendChild(rteCreateButton(
		'Subscript',
		false,
		'data:image/gif;base64,R0lGODlhFQAVAJEAAAAAgAAAAP%2F%2F%2FwAAACH5BAEAAAIALAAAAAAVABUAAAIglI%2Bpy%2B0Po5y0hmAuvdpi30mdBgAVYp5ptbLlCcfy7BQAOw%3D%3D'));

	myextraline.appendChild(rteCreateButton(
		'Insert HTML',
		false,
		'data:image/gif;base64,R0lGODlhFQAUA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WZ7tCqtlYN84%2Fsp8vMdAWiZHvP1YSFdmxuTVisTSZTqJWK%2FYbAIAOw%3D%3D'));

	myextraline.setAttribute('style', 'clear: both;');
	if (GM_getValue("displayExtra", 1) == 0) {
		//myextraline.setAttribute('style', 'display: block;');
	//} else {
		myextraline.setAttribute('style', 'clear: both; display: none;');
	}

	mycurrent_cell.appendChild(myextraline);	

	mybr = document.createElement("br");
	mybr.setAttribute('style', 'clear: left;');
	mycurrent_cell.appendChild(mybr);	
	mycurrent_cell.appendChild(rteCreateColorChart());
			
	mycurrent_row.appendChild(mycurrent_cell);
	mytablebody.appendChild(mycurrent_row);
	mytable.appendChild(mytablebody);

return mytable;
}

////////////////////////////
//	WYSIWYG / Source Switch
////////////////////////////	
//add the switch between WYSIWYG and Source
function addWysiwygSwitch() {
	var myswitch = document.createElement("span");
	myswitch.appendChild(rteCreateSwitch(
		'rteMode',
		'WYSIWYG',
		true,
		'What You See Is What You Get'));
	myswitch.appendChild(rteCreateSwitch(
		'rteMode',
		'Source',
		false,
		'Edit HTML Source'));

	var dfPostTopBtn = document.getElementById('compPostTopBtn');
	if (dfPostTopBtn) {  
		dfPostTopBtn.parentNode.insertBefore(myswitch, dfPostTopBtn.nextSibling); 
	} else { 
		mytable.parentNode.insertBefore(document.createElement("br"), mytable);
		mytable.parentNode.insertBefore(myswitch, mytable);  
	}
}

////////////////////////////
//	Add Misc Editor Buttons
////////////////////////////
function addMiscEditorButtons() {
	// hide the Delphi Spell Check button 

	if (isNew || isEdit) {
	var dfSpellBtn;
	dfSpellBtn = document.evaluate(
   		"//input[@name='Spell Check'] | //input[@name='spellcheck']",
   		document,
   		null,
   		XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
   		null);
	for (var i = 0; i < dfSpellBtn.snapshotLength; i++) {
		dfSpellBtn.snapshotItem(i).style.display = 'none';
	}
	}

// add Editor Options button if My Preferences page
	if (isSignature) {
	mytable.parentNode.insertBefore(rteCreatePushButton('EditorOptions', 'Editor Options'), mytable);
	}
// add Quick Quote button if Replying
	if (isReply) {
	var dfYouReply = document.getElementById('compReplyMsgPre');
	dfYouReply.appendChild(document.createElement("br"));
	dfYouReply.appendChild(document.createElement("br"));
	dfYouReply.appendChild(rteCreatePushButton('QuickQuote', 'Quick Quote'));
	}
}

////////////////////////////
//	Photobucket - this is for old Preferences page.  
//      Disabled call to this function because it breaks on the new My Preferences page
////////////////////////////
// setup Photobucket
function setupPBforEditor() {
	if (isSignature) {

	    var oldFunction = unsafeWindow.photobucket_complete;
	    // if PB exists, create function to insert image in WYSIWYG or HTML view of RTE
	    if (typeof(oldFunction) == "function") {
		var newCall = "var rteTextarea = document.getElementsByTagName('textarea')[0]; "
		newCall += "if (getComputedStyle(rteTextarea, '').display == 'none') { ";
		newCall += "document.getElementById('rteEditor').contentWindow.document.execCommand('inserthtml', false, imgTag);";
		newCall += "} else {";
		newCall += "rteTextarea.value += imgTag;";
		newCall += "}";

		var newHTML = oldFunction.toString().replace("document.myaccountinfo.signature.value += imgTag;", newCall);
		Code.set("photobucket_complete", newHTML);
	    
	    	// Move PB under the RTE
	    
	    	// locate the tr for the timezone
	    	var dfTimezone;
	    	var dfe;
	    	dfe = document.evaluate(
   			"//tr[@class='timezone']",
   			document,
   			null,
   			XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
   			null);
	    	for (var i = 0; i < dfe.snapshotLength; i++) {
			dfTimezone = dfe.snapshotItem(i);
	    	}

	    
	    	// locate the tr for PB
	    	var dfPBBox;
	    	dfe = document.evaluate(
   			"//iframe[@id='plugin']",
   			document,
   			null,
   			XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
   			null);
	  
		// dfe only exists on old My Prefs page

		if (typeof(dfe) != 'undefined' ) {
	    		dfPBBox = dfe.snapshotItem(0).parentNode.parentNode;
	    	
	    		// the following line used to break the PB widget.  Seems to be working now
	    		dfTimezone.parentNode.insertBefore(dfPBBox, dfTimezone);
		
	    		document.getElementById('plugin').setAttribute('style', 'border: 1px solid #A5ACB2; display: block;');
		}
	    }
	}
}

////////////////////////////
//	Add Editor Popups
////////////////////////////
// add popups (note that popup variables are global)

function addEditorPopups() {

tablePopup = document.createElement('div');
tablePopup.setAttribute('id', 'rteInsertTablePopup');
tablePopup.setAttribute('style', 'border: 2px solid #a5acb2; background-color: #f2f2f2;');
document.body.appendChild(rteInsertTable(tablePopup));

mediaPopup = document.createElement('div');
mediaPopup.setAttribute('id', 'rteInsertMediaPopup');
mediaPopup.setAttribute('style', 'border: 2px solid #a5acb2; background-color: #f2f2f2;');
document.body.appendChild(rteInsertMedia(mediaPopup));

if (isSignature) {
optionPopup = document.createElement('div');
optionPopup.setAttribute('id', 'rteoptionPopup');
optionPopup.setAttribute('style', 'border: 2px solid #a5acb2; background-color: #f2f2f2;');
document.body.appendChild(rteManageOptions(optionPopup));
}

colorPopup = document.createElement('div');
colorPopup.setAttribute('id', 'rteCustomColor');
colorPopup.setAttribute('style', 'border: 2px solid #a5acb2; background-color: #f2f2f2;');
document.body.appendChild(rteCustomColor(colorPopup));

}

////////////////////////////
//	Create RTE
////////////////////////////
function createRTE() {
// Get plain textarea (global)
	rteTextarea = document.getElementsByTagName('textarea')[0];

// Configure Styles
	configureStyles();

// Add Editor Popups
	addEditorPopups();

// Add editor frame
iframe = document.createElement('iframe');

iframe.setAttribute('id', 'rteEditor');
iframe.setAttribute('name', 'rteEditor');
rteTextarea.parentNode.insertBefore(iframe, rteTextarea);
	
rteTextarea.setAttribute('style', 'display: none;');
iframe.setAttribute('style', 'display: inline;');

var Editor = document.getElementById('rteEditor');
EditorWin = Editor.contentWindow;
EditorDoc = Editor.contentDocument;
window.EditorWin = EditorWin;
window.EditorDoc = EditorDoc;

// create Toolbar
	mytable = createToolbar();

	iframe.parentNode.insertBefore(mytable, iframe);

//add the switch between WYSIWYG and Source
	addWysiwygSwitch();

// Add Misc Editor Buttons (e.g. Editor Options, Quick Quote)
	addMiscEditorButtons();

// setup Photobucket
// disable for now because it causes problems with the new My Prefs page
	setupPBforEditor();

// add event listeners
	addListeners();
}


////////////////////////////
//	Add Event Listeners
////////////////////////////	
// add event listeners
function addListeners() {

	document.getElementById('formatblock').addEventListener("change",rteChangeDropdown,false);
	document.getElementById('fontname').addEventListener("change",rteChangeDropdown,false);
	document.getElementById('fontsize').addEventListener("change",rteChangeDropdown,false);
	//document.getElementById('forecolor').addEventListener("change",rteChangeDropdown,false);
	document.getElementById('insertsmiley').addEventListener("change",rteChangeDropdown,false);
	if (document.getElementById('switchsig')) { 
	document.getElementById('switchsig').addEventListener("change",rteChangeDropdown,false);
	}
	if (isSignature) {
	document.getElementById('ManageOpts_Sigs').addEventListener("click", ManageOpts_Button, false);
	document.getElementById('ManageOpts_Smileys').addEventListener("click", ManageOpts_Button, false);
	document.getElementById('ManageOpts_Fonts').addEventListener("click", ManageOpts_Button, false);
	document.getElementById('ManageOpts_Colors').addEventListener("click", ManageOpts_Button, false);
	document.getElementById('ManageOpts_Defaults').addEventListener("click", ManageOpts_Button, false);
	document.getElementById('ManageOpts_Backups').addEventListener("click", ManageOpts_Button, false);
	document.getElementById('ManageOpts_Restores').addEventListener("click", ManageOpts_Button, false);
	document.getElementById('ManageOpts_Down').addEventListener("click",ManageOpts_Button,false);
	document.getElementById('ManageOpts_Up').addEventListener("click",ManageOpts_Button,false);
	document.getElementById('ManageOpts_Delete').addEventListener("click",ManageOpts_Button,false);
//	document.getElementById('ManageOpts_Copy').addEventListener("click",ManageOpts_Button,false);
	document.getElementById('ManageOpts_Add').addEventListener("click",ManageOpts_Button,false);
	document.getElementById('ManageOpts_Rename').addEventListener("click",ManageOpts_Button,false);
	document.getElementById('ManageOpts_Cancel').addEventListener("click", rteManageOptionsCancel, true);
	document.getElementById('ManageOpts_Submit').addEventListener("click", rteManageOptionsSubmit, false);
	}
	document.getElementById('InsertTable_Cancel').addEventListener("click", rteTableCancel, true);
	document.getElementById('InsertTable_Submit').addEventListener("click", rteTableSubmit, false);
	document.getElementById('InsertMedia_Cancel').addEventListener("click", rteMediaCancel, true);
	document.getElementById('InsertMedia_Submit').addEventListener("click", rteMediaSubmit, false);
	document.getElementById('CustomColor_Cancel').addEventListener("click", rteColorCancel, true);
	document.getElementById('CustomColor_Submit').addEventListener("click", rteColorSubmit, false);

	// no longer used
	//if (hasSpellcheck) {
	//	window.addEventListener("message", receiveMessage, false);
	//}

rteTextarea.addEventListener("focus", rteHTMLChange, false);

	// capture the onsubmit event on all forms
	window.addEventListener('submit', newsubmit, true);

	// Copy HTML to design window when leaving the plain text area
	if (isNewPlatform) {
	document.getElementById('mMsg_body').addEventListener("blur", newsubmit, false);
	}
// If a script calls someForm.submit(), the onsubmit event does not fire,
// so we need to redefine the submit method of the HTMLFormElement class.
//HTMLFormElement.prototype._submit = HTMLFormElement.prototype.submit;
//HTMLFormElement.prototype.submit = newsubmit;

}
// end of addListeners

// ////////////////////////////////////////////////////////
//  Main Code
// ////////////////////////////////////////////////////////


////////////////////////////
//	Determine What page we're on
////////////////////////////
// Check for new platform page
if (document.getElementById('mMsg_body')) {
	// e.g. about.com - not finished yet
	//isNewPlatform = true;
}






// add tab to Delphi's new Profile page for Managing Firefox editor
// locate the div for the tabs

	    	var dfLastTab;
	    	var dfe;
	    	dfe = document.evaluate(
   			"//li[@class='ptcTab ptcNC'] | //li[@class='ptcTab ptcCurrent']",
   			document,
   			null,
   			XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
   			null);

		// don't display My Firefox tab when viewing someone else's profile (only 1 tab)
		if (dfe.snapshotLength > 1) {
	    		for (var i = 0; i < dfe.snapshotLength; i++) {
				dfLastTab = dfe.snapshotItem(i);
	    		}
			//Append a tab
			var li, tab;
    			tab = document.createElement('a');
    			tab.title = "My Firefox";
    			tab.href = '#';
    			tab.innerHTML = 'My Firefox';
    			tab.addEventListener("click", rteClickTab, true);

    			li = document.createElement('li');
    			li.setAttribute('class', 'ptcTab ptcNC');
			li.id = "dfMyFirefox";
    			li.appendChild(tab);
    			dfLastTab.parentNode.appendChild(li);		
		}





// Check for Spell Check button
var spellBtn;

spellBtn = document.evaluate(
   	"//input[@name='Spell Check'] | //input[@name='spellcheck']",
   	document,
   	null,
   	XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
   	null);
for (var i = 0; i < spellBtn.snapshotLength; i++) {
//	if (window.postMessage) {
	hasSpellcheck = true;
//	}	
}

if (document.getElementById('mMsg_signature')) {
	// add switch sigs to about.com
	var mycurrent_cell=document.createElement("td");
	mycurrent_cell.id = "rteSigBtns";

	var vNames = '';
	if (GM_getValue("FriendlyNames", "") != "")  {	
		isNewSig = true; 
	} else { 
		if (GM_getValue("BasicNames", "") != "") {
    			isNewSig = true;
			basicSig = true;
		}
	}

	if (isNewSig) {
	mycurrent_cell.innerHTML += rteCreateDropdown('switchsig');

	var mycurrent_row = document.getElementById('mMsg_body_DropDownList_Color').parentNode.parentNode;
	mycurrent_row.appendChild(mycurrent_cell);
	document.getElementById('switchsig').addEventListener("change",rteChangeDropdown,false);
	}
}

// Check for Reply or New Message page
if (document.getElementById('compCheckUsehtml')) {
	
	isNew = true;
	hasSig = true;
	// always enable the HTML checkbox
	if (!document.getElementById('compCheckUsehtml').checked) {
	document.getElementById('compCheckUsehtml').click(); 
	}
	if (! document.getElementById('compSigTxt')) 
		{ basicSig = true; }
	if (document.getElementById('compReplyMsg'))
		{ isReply = true; }
}
else { 

	// check for Edit Start Page
	var startPage;

	startPage = document.evaluate(
   		"//a[contains(@href,'welcomescreen.asp')]",
   		document,
   		null,
   		XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
   		null);

	for (var i = 0; i < startPage.snapshotLength; i++) {
		//enableHTML = true;
		//thisA = startPage.snapshotItem(i);
		if (startPage.snapshotItem(i).href.indexOf('noHtml') > 0) {
			isStartPage = true;	
		}
	}

	if (!isStartPage) {
	// check for Edit Message page
	var submitBtns;
	submitBtns = document.evaluate(
   		"//input[@name='edit']",
   		document,
   		null,
   		XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
   		null);
	for (var i = 0; i < submitBtns.snapshotLength; i++) {
		//enableHTML = true;
		isEdit = true;
	}
	}


	// check for Edit Signature
	var signature;
	signature = document.evaluate(
   		"//textarea[@name='signature']",
   		document,
   		null,
   		XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
   		null);
	for (var i = 0; i < signature.snapshotLength; i++) {
		//enableHTML = true;
		isSignature = true;
		hasSig = true;
	}

	// check if this is the Delphi Spell Checker popup window
	// no longer used
//	var finishLink;

//	finishLink = document.evaluate(
//   		"//a[contains(@href,'javascript:finish()')]",
//   		document,
//   		null,
//   		XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
//   		null);
//	for (var i = 0; i < finishLink.snapshotLength; i++) {
//		isSpell = true;
		// add an onclick event to the Finish button
//		finishLink.snapshotItem(i).addEventListener("click", rteSpellFinish, true);
//	}
//	if (isSpell) window.focus();



	// check if this is the Delphi message frame
	var editLink;
	editLink = document.evaluate(
   		"//a[contains(@href,'/n/mb/edit.asp?webtag')]",
   		document,
   		null,
   		XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
   		null);
	for (var i = 0; i < editLink.snapshotLength; i++) {
		// modify the link to go directly to Edit HTML
		editLink.snapshotItem(i).href = editLink.snapshotItem(i).href + "&useHtml=1";
	}	

	// check for My Preferences for Basic members
	if (! isSignature) {
		if (document.getElementById('p_prefsOptional')) {
			// insert a textarea to use
			var prefs = document.getElementById('p_prefsOptional');
			var tarea = document.createElement('textarea');
			tarea.setAttribute('style', 'width: 600px; height: 250px;');

			if (prefs) { 
				prefs_row = document.createElement("tr");
				prefs_cell=document.createElement("td");
				prefs_cell.appendChild(tarea);
				prefs_row.appendChild(prefs_cell);
				prefs.parentNode.insertBefore(prefs_row, prefs.nextSibling);
			}
			isSignature = true;
			hasSig = true;
			basicMyPrefs = true;
		}

	}
}

////////////////////////////
//	Create the Editor
////////////////////////////	
if (isNewPlatform | isNew || isEdit || isStartPage || isSignature) {

	// Create RTE
	createRTE();


	
	// initialize the editor - use Time Out to avoid timing problems with events 

	if (rteInitializeEditor) { 
	setTimeout(function() { rteInitEditor(); }, 200);
	//rteInitEditor(); 
	}

}  // if html enabled


	