var port = (window.location.port == 0) ? '' : ':' + window.location.port;
var url = window.location.protocol + '//' + window.location.hostname + port + window.location.pathname + '?';
var image_url = 'images';
var iframe, editor, post, outerdoc;
var privateMessage = 1;
var innerInterval, tbInterval, pressedInterval, initialized;
window.onresize = tb_layout;

function initOuterIFrame () {
	var objEditFrame = document.frames.editor_iframe.document;
    objEditFrame.write('\<html\>\n');
	objEditFrame.write('\<head\>\n');
	objEditFrame.write('\n');
	objEditFrame.write('\n');
	objEditFrame.write('\<style type=\"text\/css\" media=\"screen\"\>\n');
	objEditFrame.write('\<!--\n');
	objEditFrame.write('body { scrollbar-base-color: #404040; scrollbar-arrow-color: #C33d4a; }\n');
	objEditFrame.write('a.menu:link,a.menu:visited { font-size:10; color:#cccccc; text-decoration:none; font-face:\'Arial,  sans-serif\'; font-weight:600; }\n');
	objEditFrame.write('a.menu:hover { font-size:11; color:#000000; text-decoration:underline; font-face:\'Arial,  sans-serif\'; font-weight:600; }\n');
	objEditFrame.write('.submit { background-color:#999999; font-family: Arial,  sans-serif; font-size:10px; color:white; font-weight:bold; }\n');
	objEditFrame.write('.button { background-color:#ffffff; color: black; font-family: Arial,  sans-serif; font-size: 10px; }\n');
	objEditFrame.write('a:link { color:#000000; text-decoration:underline; font-face:\'Arial,  sans-serif\';}\n');
	objEditFrame.write('a:visited { color:#000000; text-decoration:underline; font-face:\'Arial,  sans-serif\';}\n');
	objEditFrame.write('a:hover { color:#3366cc; text-decoration:underline; font-face:\'Arial,  sans-serif\'; }\n');
	objEditFrame.write('--\>\n');
	objEditFrame.write('\<\/style\>\n');
	objEditFrame.write('\n');
	objEditFrame.write('\n');
	objEditFrame.write('\<style type=\"text\/css\" media=\"screen\"\>\n');
	objEditFrame.write('\<!--\n');
	objEditFrame.write('\/* \n');
	objEditFrame.write(' * =================================================================\n');
	objEditFrame.write(' * HTML Editor - A wysiwyg web based editor for IE5.5+\n');
	objEditFrame.write(' *    Website  : http:\/\/gossamer-threads.com\/\n');
	objEditFrame.write(' *    Author   : Scott Beck sbeck@gossamer-threads.com\n');
	objEditFrame.write(' *    Revision : $Id: editor_style.css,v 1.3 2002\/01\/11 23:18:19 jagerman Exp $\n');
	objEditFrame.write(' *\n');
	objEditFrame.write(' * =================================================================\n');
	objEditFrame.write(' *\n');
	objEditFrame.write(' * Description: Style sheet for the main editor window.\n');
	objEditFrame.write(' *\/\n');
	objEditFrame.write('\n');
	objEditFrame.write('body {\n');
	objEditFrame.write('        \n');
	objEditFrame.write('}\n');
	objEditFrame.write('\n');
	objEditFrame.write('.tb_icon {\n');
	objEditFrame.write('	position : absolute;\n');
	objEditFrame.write('	width    : 22px;\n');
	objEditFrame.write('	height   : 22px;\n');
	objEditFrame.write('	left     : -1px;\n');
	objEditFrame.write('	top      : -1px;\n');
	objEditFrame.write('}\n');
	objEditFrame.write('\n');
	objEditFrame.write('.icon_down {\n');
	objEditFrame.write('	position : absolute;\n');
	objEditFrame.write('	left     : 0px;\n');
	objEditFrame.write('	top      : 0px;\n');
	objEditFrame.write('	height   : 23px; \n');
	objEditFrame.write('	width    : 24px;\n');
	objEditFrame.write('}\n');
	objEditFrame.write('\n');
	objEditFrame.write('.icon_downpressed {\n');
	objEditFrame.write('	position : absolute;\n');
	objEditFrame.write('	left     : 1px;\n');
	objEditFrame.write('	top      : 1px;\n');
	objEditFrame.write('}\n');
	objEditFrame.write('\n');
	objEditFrame.write('.tb_menu_item {\n');
	objEditFrame.write('	position      : absolute;\n');
	objEditFrame.write('	border-bottom : #FFFFFF solid 1px; \n');
	objEditFrame.write('	border-left   : #FFFFFF solid 1px; \n');
	objEditFrame.write('	border-right  : #FFFFFF solid 1px; \n');
	objEditFrame.write('	border-top    : #FFFFFF solid 1px; \n');
	objEditFrame.write('	top           : 1px;\n');
	objEditFrame.write('	height        : 22px;\n');
	objEditFrame.write('	width         : 23px;\n');
	objEditFrame.write('}\n');
	objEditFrame.write('\n');
	objEditFrame.write('.menu_item_mouseoverup {\n');
	objEditFrame.write('	position      : absolute;\n');
	objEditFrame.write('	border-bottom : buttonshadow solid 1px; \n');
	objEditFrame.write('	border-left   : buttonhighlight solid 1px; \n');
	objEditFrame.write('	border-right  : buttonshadow solid 1px; \n');
	objEditFrame.write('	border-top    : buttonhighlight solid 1px; \n');
	objEditFrame.write('	top           : 1px;\n');
	objEditFrame.write('	height        : 22px; \n');
	objEditFrame.write('	width         : 23px;\n');
	objEditFrame.write('}\n');
	objEditFrame.write('\n');
	objEditFrame.write('.menu_item_mouseoverdown {\n');
	objEditFrame.write('	position      : absolute;\n');
	objEditFrame.write('	border-bottom : buttonhighlight solid 1px; \n');
	objEditFrame.write('	border-left   : buttonshadow solid 1px; \n');
	objEditFrame.write('	border-right  : buttonhighlight solid 1px; \n');
	objEditFrame.write('	border-top    : buttonshadow solid 1px; \n');
	objEditFrame.write('	top           : 1px;\n');
	objEditFrame.write('	height        : 22px; \n');
	objEditFrame.write('	width         : 23px;\n');
	objEditFrame.write('}\n');
	objEditFrame.write('\n');
	objEditFrame.write('.menu_item_down {\n');
	objEditFrame.write('	position         : absolute;\n');
	objEditFrame.write('	background-color : #FFFFFF; \n');
	objEditFrame.write('	border-bottom    : buttonhighlight solid 1px; \n');
	objEditFrame.write('	border-left      : buttonshadow solid 1px; \n');
	objEditFrame.write('	border-right     : buttonhighlight solid 1px; \n');
	objEditFrame.write('	border-top       : buttonshadow solid 1px; \n');
	objEditFrame.write('	top              : 1px;\n');
	objEditFrame.write('	height           : 22px; \n');
	objEditFrame.write('	width            : 23px;\n');
	objEditFrame.write('}\n');
	objEditFrame.write('\n');
	objEditFrame.write('.tb_sep {\n');
	objEditFrame.write('	position     : absolute; \n');
	objEditFrame.write('	border-left  : buttonshadow solid 1px; \n');
	objEditFrame.write('	border-right : buttonhighlight solid 1px; \n');
	objEditFrame.write('	font-size    : 0px; \n');
	objEditFrame.write('	top          : 1px;\n');
	objEditFrame.write('	height       : 22px; \n');
	objEditFrame.write('	width        : 1px; \n');
	objEditFrame.write('}\n');
	objEditFrame.write('\n');
	objEditFrame.write('.tb_general {\n');
	objEditFrame.write('	position         : absolute;\n');
	objEditFrame.write('	background-color : #C0C0C0;\n');
	objEditFrame.write('	height           : 22px; \n');
	objEditFrame.write('	top              : 2px;\n');
	objEditFrame.write('	font             : 8pt Arial,  sans-serif;\n');
	objEditFrame.write('	border           : none;\n');
	objEditFrame.write('}\n');
	objEditFrame.write('\n');
	objEditFrame.write('.tb_text_mouseover {\n');
	objEditFrame.write('	background-color : #C0C0C0;\n');
	objEditFrame.write('	height           : 20px; \n');
	objEditFrame.write('	top              : 2px;\n');
	objEditFrame.write('	font-family      : \"MS Sans Serif\";\n');
	objEditFrame.write('	font-size        : 6pt;\n');
	objEditFrame.write('	border-bottom    : buttonhighlight solid 1px; \n');
	objEditFrame.write('	border-left      : buttonshadow solid 1px; \n');
	objEditFrame.write('	border-right     : buttonhighlight solid 1px; \n');
	objEditFrame.write('	border-top       : buttonshadow solid 1px; \n');
	objEditFrame.write('	height           : 17px;\n');
	objEditFrame.write('}\n');
	objEditFrame.write('\n');
	objEditFrame.write('.tb_handle {\n');
	objEditFrame.write('	position         : absolute;\n');
	objEditFrame.write('	background-color : #FFFFFF; \n');
	objEditFrame.write('	border-left      : buttonhighlight solid 1px; \n');
	objEditFrame.write('	border-right     : buttonshadow solid 1px;\n');
	objEditFrame.write('	border-top       : buttonhighlight solid 1px; \n');
	objEditFrame.write('	font-size        : 1px;\n');
	objEditFrame.write('	top              : 1px; \n');
	objEditFrame.write('	height           : 22px;\n');
	objEditFrame.write('	width            : 3px;\n');
	objEditFrame.write('}\n');
	objEditFrame.write('\n');
	objEditFrame.write('.toolbar {\n');
	objEditFrame.write('	position         : relative;\n');
	objEditFrame.write('	background-color : #FFFFFF; \n');
	objEditFrame.write('	border-bottom    : buttonshadow solid 1px; \n');
	objEditFrame.write('	border-left      : buttonhighlight solid 1px; \n');
	objEditFrame.write('	border-right     : buttonshadow solid 1px; \n');
	objEditFrame.write('	border-top       : buttonhighlight solid 1px; \n');
	objEditFrame.write('	height           : 25px;\n');
	objEditFrame.write('	top              : 0px;\n');
	objEditFrame.write('	left             : 0px;\n');
	objEditFrame.write('}\n');
	objEditFrame.write('\n');
	objEditFrame.write('\n');
	objEditFrame.write('--\>\n');
	objEditFrame.write('\<\/style\>\n');
	objEditFrame.write('\n');
	objEditFrame.write('\<\/head\>\n');
	objEditFrame.write('\n');
	objEditFrame.write('\<body leftmargin=\"0\" topmargin=\"0\" bgcolor=\"#FFFFFF\"\>\n');
	objEditFrame.write('\n');
	objEditFrame.write('\<div class=\"toolbar\" id=\"File\" title=\"File\" onselectstart=\"return parent.cancel_event();\"\>\n');
	objEditFrame.write('	\<!--====================================--\>\n');
	objEditFrame.write('    \<span id=\"cut\" title=\"Cut Div\" onclick=\"parent.command(\'Cut\')\" class=\"tb_menu_item\"\>\n');
	objEditFrame.write('    \<img title=\"Cut\" class=\"tb_icon\" src=\"images\/cut.gif\" alt=\"Bold\"\>\n');
	objEditFrame.write('  \<\/span\>\n');
	objEditFrame.write('  \<span id=\"copy\" title=\"Copy Div\" onclick=\"parent.command(\'Copy\')\" class=\"tb_menu_item\"\>\n');
	objEditFrame.write('    \<img title=\"Copy\" class=\"tb_icon\" src=\"images\/copy.gif\" alt=\"Copy\"\>\n');
	objEditFrame.write('  \<\/span\>\n');
	objEditFrame.write('  \<span id=\"paste\" title=\"Paste Div\" onclick=\"parent.command(\'Paste\')\" class=\"tb_menu_item\"\>\n');
	objEditFrame.write('    \<img title=\"Paste\" class=\"tb_icon\" src=\"images\/paste.gif\" alt=\"Paste\"\>\n');
	objEditFrame.write('  \<\/span\>\n');
	objEditFrame.write('\<\/div\>\n');
	objEditFrame.write('\n');
	objEditFrame.write('\<div class=\"toolbar\" id=\"Format\" title=\"Format\" onselectstart=\"return parent.cancel_event ();\"\>\n');
	objEditFrame.write('	\<!--=====================================--\>\n');
	objEditFrame.write('	\<span id=\"bold\" title=\"Bold Item\" onclick=\"parent.command(\'Bold\');\" class=\"tb_menu_item\"\>\n');
	objEditFrame.write('		\<img id=\"boldImage\" title=\"Bold\" class=\"tb_icon\" src=\"images\/bold.gif\" alt=\"Bold\"\>\<\/img\>\n');
	objEditFrame.write('	\<\/span\>\n');
	objEditFrame.write('	\<span id=\"italic\" title=\"Italic Item\" onclick=\"parent.command(\'Italic\');\" class=\"tb_menu_item\"\>\n');
	objEditFrame.write('		\<img id=\"italicImage\" title=\"Italic\" class=\"tb_icon\" src=\"images\/italic.gif\" alt=\"Italic\"\>\<\/img\>\n');
	objEditFrame.write('	\<\/span\>\n');
	objEditFrame.write('	\<span id=\"underline\" title=\"Underline Item\" onclick=\"parent.command(\'Underline\');\" class=\"tb_menu_item\"\>\n');
	objEditFrame.write('		\<img id=\"underlineImage\" title=\"Underline\" class=\"tb_icon\" src=\"images\/under.gif\" alt=\"Underline\"\>\<\/img\>\n');
	objEditFrame.write('	\<\/span\>\n');
	objEditFrame.write('	\<!-----------------------------------------\>\n');
	objEditFrame.write('	\<span title=\"Seperator\" class=\"tb_sep\"\>\<\/span\>\n');
	objEditFrame.write('	\<span id=\"jleft\" title=\"Left Div\" TEXT_MODE=\'no\' onclick=\"parent.command(\'JustifyLeft\');\" class=\"tb_menu_item\"\>\n');
	objEditFrame.write('		\<img id=\"jleftImage\" title=\"Justify Left\" class=\"tb_icon\" src=\"images\/left.gif\" alt=\"Justify Left\"\>\<\/img\>\n');
	objEditFrame.write('	\<\/span\>\n');
	objEditFrame.write('	\<span id=\"jcenter\" title=\"Center Div\" TEXT_MODE=\'no\' onclick=\"parent.command(\'JustifyCenter\');\" class=\"tb_menu_item\"\>\n');
	objEditFrame.write('		\<img id=\"jcenterImage\" title=\"Justify Center\" class=\"tb_icon\" src=\"images\/center.gif\" alt=\"Justify Center\"\>\<\/img\>\n');
	objEditFrame.write('	\<\/span\>\n');
	objEditFrame.write('	\<span id=\"jright\" title=\"Right Div\" TEXT_MODE=\'no\' onclick=\"parent.command(\'JustifyRight\');\" class=\"tb_menu_item\"\>\n');
	objEditFrame.write('		\<img id=\"jrightImage\" title=\"Justify Right\" class=\"tb_icon\" src=\"images\/right.gif\" alt=\"Justify Right\"\>\<\/img\>\n');
	objEditFrame.write('	\<\/span\>\n');
	objEditFrame.write('	\<!-----------------------------------------\>\n');
	objEditFrame.write('	\<span title=\"Seperator\" class=\"tb_sep\"\>\<\/span\>\n');
	objEditFrame.write('	\<span id=\"ol\" title=\"OL Div\" TEXT_MODE=\'no\' onclick=\"parent.command(\'InsertOrderedList\');\" class=\"tb_menu_item\"\>\n');
	objEditFrame.write('		\<img id=\"olImage\" title=\"Ordered List\" class=\"tb_icon\" src=\"images\/numlist.gif\" alt=\"Ordered List\"\>\<\/img\>\n');
	objEditFrame.write('	\<\/span\>\n');
	objEditFrame.write('	\<span id=\"ul\" title=\"UL Div\" TEXT_MODE=\'no\' onclick=\"parent.command(\'InsertUnorderedList\');\" class=\"tb_menu_item\"\>\n');
	objEditFrame.write('		\<img id=\"ulImage\" title=\"Unordered List\" class=\"tb_icon\" src=\"images\/bullist.gif\" alt=\"Unordered List\"\>\<\/img\>\n');
	objEditFrame.write('	\<\/span\>\n');
	objEditFrame.write('	\<span title=\"Outdent Div\" onclick=\"parent.command(\'Outdent\')\" TEXT_MODE=\'no\' class=\"tb_menu_item\"\>\n');
	objEditFrame.write('		\<img title=\"Outdent\" class=\"tb_icon\" src=\"images\/outdent.gif\" alt=\"Outdent\"\>\<\/img\>\n');
	objEditFrame.write('	\<\/span\>\n');
	objEditFrame.write('	\<span title=\"Indent Div\" onclick=\"parent.command(\'Indent\')\" TEXT_MODE=\'no\' class=\"tb_menu_item\"\>\n');
	objEditFrame.write('		\<img title=\"Indent\" class=\"tb_icon\" src=\"images\/indent.gif\" alt=\"Indent\"\>\<\/img\>\n');
	objEditFrame.write('	\<\/span\>\n');
	objEditFrame.write('	\n');
	objEditFrame.write('\<\/div\>\n');
	objEditFrame.write('\<div class=\"toolbar\" id=\"Misc\" title=\"Misc\" onselectstart=\"return parent.cancel_event();\"\>\n');
	objEditFrame.write('	\<!--=====================================--\>\n');
	objEditFrame.write('	\<span id=\"link\" title=\"Show Div\" onclick=\"parent.showCode()\" class=\"tb_menu_item\"\>\n');
	objEditFrame.write('		\<img id=\"linkImage\" title=\"Show Code\" class=\"tb_icon\" src=\"images\/code.gif\" alt=\"Create Link\"\>\<\/img\>\n');
	objEditFrame.write('		\ \n');
	objEditFrame.write('	\<\/span\>\n');
	objEditFrame.write('\<\/div\>\n');
	noLinks = document.forms[1].nolinks.value;
if (noLinks!="true") {
	objEditFrame.write('\<div class=\"toolbar\" id=\"Misc\" title=\"Misc\" onselectstart=\"return parent.cancel_event();\"\>\n');
	objEditFrame.write('	\<!--=====================================--\>\n');
	objEditFrame.write('	\<span id=\"link\" title=\"Link Div\" onclick=\"parent.linkDialog()\" class=\"tb_menu_item\"\>\n');
	objEditFrame.write('		\<img id=\"linkImage\" title=\"Link\" class=\"tb_icon\" src=\"images\/link.gif\" alt=\"Create Link\"\>\<\/img\>\n');
	objEditFrame.write('	\<\/span\>\n');
	objEditFrame.write('\<\/div\>\n');
	} else {
	objEditFrame.write('\<div class=\"toolbar\" id=\"Misc\" title=\"Misc\" onselectstart=\"return parent.cancel_event();\"\>\n');
	objEditFrame.write('	\<!--=====================================--\>\n');
	objEditFrame.write('	\<span id=\"link\" title=\"Link Div\" onclick=\"parent.linkDialog()\" class=\"tb_menu_item\"\>\n');
	objEditFrame.write('		\ \n');
	objEditFrame.write('	\<\/span\>\n');
	objEditFrame.write('\<\/div\>\n');
 	}

	noDocLinks = document.forms[1].nodoclinks.value;
if (noDocLinks!="true") {
objEditFrame.write('\<div class=\"toolbar\" id=\"Misc\" title=\"Misc\" onselectstart=\"return parent.cancel_event();\"\>\n');
		objEditFrame.write('	\<!--=====================================--\>\n');
		objEditFrame.write('	\<span title=\"LinkDoc Div\" onclick=\"linkdoc();\" TEXT_MODE=\'no\' class=\"tb_menu_item\"\>\n');
		objEditFrame.write('		\<img id=\"linkdocImage\" title=\"LinkDoc\" class=\"tb_icon\" src=\"images\/doc.gif\" alt=\"Create Linked To Doc\"\>\<\/img\>\n');
		objEditFrame.write('	\<\/span\>\n');
		objEditFrame.write('\<\/div\>\n');
	} else {
objEditFrame.write('\<div class=\"toolbar\" id=\"Misc\" title=\"Misc\" onselectstart=\"return parent.cancel_event();\"\>\n');
		objEditFrame.write('	\<!--=====================================--\>\n');
		objEditFrame.write('	\<span title=\"LinkDoc Div\" onclick=\"linkdoc();\" TEXT_MODE=\'no\' class=\"tb_menu_item\"\>\n');
		objEditFrame.write('		\ \n');
		objEditFrame.write('	\<\/span\>\n');
		objEditFrame.write('\<\/div\>\n');
 	}
	objEditFrame.write('\<iframe width=\"100%\" height=\"200\" name=\"editor_iframe\" id=\"editor_iframe\" style=\"position: absolute\"\>\<\/iframe\>\n');
	objEditFrame.write('\<\/body\>\n');
	objEditFrame.write('\<\/html\>\n');
	objEditFrame.write('');
    innerInterval = setInterval("initInnerIFrame()", 100);
}

function linkdoc () {
	filename = document.forms[1].FILELINK.value;
 	filename = filename.replace(" ", "%20");
	surroundTag(("<a href='data/"+filename+"'>"), "</a>");
/*	surroundTag(("<a href='data/"+filename+"' target=_blank>"), "</a>"); */
}

function initInnerIFrame () {
    if (document.frames.editor_iframe.document.editor_iframe) {
        clearInterval(innerInterval);
    } else {
        return;
    }
    outerdoc = document.frames.editor_iframe.document;
    iframe = outerdoc.frames.editor_iframe;
    editor = iframe.document;
    var initValue = (privateMessage) ? document.message.msg_body_html.value : document.post.post_message_html.value;
    editor.write('\n');
	editor.write('\<html\>\n');
	editor.write('\<head\>\n');
	editor.write('\<style\>\n');
	editor.write('body {\n');
	editor.write('    background-color      : #white;\n');
	editor.write('    font-family           : \"Arial,  sans-serif\";\n');
	editor.write('    font-size             : \"12\"; \n');
	editor.write('}\n');
	editor.write('\<\/style\>\n');
	editor.write('\n');
	editor.write('\<style type=\"text\/css\">\n');
	editor.write('\<!--\n');
	editor.write('body { scrollbar-base-color: #DDDDD; scrollbar-arrow-color: #C33d4a; }\n');
	editor.write('a.menu:link,a.menu:visited { font-size:12; color:#cccccc; text-decoration:none; font-face:\'Arial,  sans-serif\'; font-weight:600; }\n');
	editor.write('a.menu:hover { font-size:12; color:#000000; text-decoration:underline; font-face:\'Arial,  sans-serif\'; font-weight:600; }\n');
	editor.write('.submit { background-color:#999999; font-family: Arial,  sans-serif; font-size:12; color:white; font-weight:bold; }\n');
	editor.write('.button { background-color:#ffffff; color: black; font-family: Arial,  sans-serif; font-size: 12; }\n');
	editor.write('a:link { color:#000000; text-decoration:underline; font-face:\'Arial,  sans-serif\';}\n');
	editor.write('a:visited { color:#000000; text-decoration:underline; font-face:\'Arial,  sans-serif\';}\n');
	editor.write('a:hover { color:#3366cc; text-decoration:underline; font-face:\'Arial,  sans-serif\'; }\n');
	editor.write('p { spacing: 0px; margin: 0px; border: 0px; }\n');
	editor.write('--\>\n');
	editor.write('\<\/style\>\n');
	editor.write('\n');
	editor.write('\<\/head\>\n');
	editor.write('\<body contenteditable=\"true\" id=\"post\"\>\n');
	editor.write('' + initValue + '</body></html>');
    post = editor.all.post;
    tbInterval = setInterval("toolbarInit()", 100);
    (privateMessage) ? document.message.onsubmit = retrieveHTML : document.post.onsubmit = retrieveHTML;
    pressedInterval = setInterval("calcPressed()", 300);
}

function press (button, image) {
    button.isPressed = true;
    button.className = "menu_item_mouseoverdown";
    image.className  = "icon_down";
} 

function unpress (button, image) {
    button.isPressed = false;
    button.className = "tb_menu_item";
    image.className  = "tb_icon";
}

function disable (button) {
	button.className  = "tb_menu_item";
    button.disabled = true;
    button.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=0, opacity=25)";
}

function enable (button) {
    button.disabled = false;
    button.style.filter = null;
}

var pressLoopInit = false;
var pressButtons = {};
var pressLoop = [];
function calcPressed () {
    var sel = editor.selection.createRange();
    if (!pressLoopInit) {
        pressLoop[pressLoop.length] = 'Bold';
        pressButtons['Bold'] = [outerdoc.all.bold, outerdoc.all.boldImage];
        pressLoop[pressLoop.length] = 'Italic';
        pressButtons['Italic'] = [outerdoc.all.italic, outerdoc.all.italicImage];
        pressLoop[pressLoop.length] = 'Underline';
        pressButtons['Underline'] = [outerdoc.all.underline, outerdoc.all.underlineImage];
        pressLoop[pressLoop.length] = 'JustifyLeft';
        pressButtons['JustifyLeft'] = [outerdoc.all.jleft, outerdoc.all.jleftImage];
        pressLoop[pressLoop.length] = 'JustifyCenter';
        pressButtons['JustifyCenter'] = [outerdoc.all.jcenter, outerdoc.all.jcenterImage];
        pressLoop[pressLoop.length] = 'JustifyRight';
        pressButtons['JustifyRight'] = [outerdoc.all.jright, outerdoc.all.jrightImage];
        pressLoop[pressLoop.length] = 'InsertOrderedList';
        pressButtons['InsertOrderedList'] = [outerdoc.all.ol, outerdoc.all.olImage];
        pressLoop[pressLoop.length] = 'InsertUnorderedList';
        pressButtons['InsertUnorderedList'] = [outerdoc.all.ul, outerdoc.all.ulImage];
        pressLoopInit = true;
    }

    for (var i = 0; i < pressLoop.length; i++) {
        var pressed = sel.queryCommandValue(pressLoop[i]);
        var span  = pressButtons[pressLoop[i]][0];
        var image = pressButtons[pressLoop[i]][1];
        if (pressed && !span.isPressed) press(span, image);
        else if (!pressed && span.isPressed) unpress(span, image);
        else if (span.isPressed == null) span.isPressed = false;
    }

    var cutable  = false;
    var copyable = false;
    var pastable = false;
    try {
        cutable  = sel.queryCommandEnabled('Cut');
        copyable = sel.queryCommandEnabled('Copy');
        pastable = sel.queryCommandEnabled('Paste');
    } catch (e) { }
    var linkable = (sel.htmlText != '' && sel.htmlText != '\n<P>&nbsp;</P>');

    if      ( cutable  &&  outerdoc.all.cut.disabled  ) enable (outerdoc.all.cut  );
    else if (!cutable  && !outerdoc.all.cut.disabled  ) disable(outerdoc.all.cut  );
    if      ( copyable &&  outerdoc.all.copy.disabled ) enable (outerdoc.all.copy );
    else if (!copyable && !outerdoc.all.copy.disabled ) disable(outerdoc.all.copy );
    if      ( pastable &&  outerdoc.all.paste.disabled) enable (outerdoc.all.paste);
    else if (!pastable && !outerdoc.all.paste.disabled) disable(outerdoc.all.paste);
    if      ( linkable &&  outerdoc.all.link.disabled ) enable (outerdoc.all.link );
    else if (!linkable && !outerdoc.all.link.disabled ) disable(outerdoc.all.link );
}

function retrieveHTML () {
    (privateMessage) ? document.message.msg_body.value = post.innerHTML : document.post.post_message.value = post.innerHTML;
}

function command (cmd) {
    iframe.focus();
    try {
        editor.execCommand(cmd);
    } catch (e) { }
    iframe.focus();
}

function updateTab (selected_val) {
	var col = document.getElementsByName("post_icon");
	for (i = 0; i < col.length; i++) {
		col[i].tabIndex = (selected_val == col[i].value) ? 5 : 0;
	}
}

// This is called for things like [quote]...[/quote] - they should surround the selected text.
function surroundTag (start, end) {
    iframe.focus();
    var selection = editor.selection.createRange();
    selection.pasteHTML(start + selection.htmlText + end);
    iframe.focus();
}

// This is called for tags like [smile] - it replaces any selected text
function insertTag (tag) {
    iframe.focus();
    var selection = editor.selection.createRange();
    selection.pasteHTML(tag);
    iframe.focus();
}

function showCode () {
    var sel = editor.selection.createRange();
    if (sel.htmlText == '' || sel.htmlText == '\n<P>&nbsp;</P>') return;

    iframe.focus();
    setTimeout("editor.execCommand('CreateLink', false); iframe.focus();", 100);
}

function linkDialog () {
    var sel = editor.selection.createRange();
    if (sel.htmlText == '' || sel.htmlText == '\n<P>&nbsp;</P>') return;

    iframe.focus();
    setTimeout("editor.execCommand('CreateLink', false); iframe.focus();", 100);
}

var initInterval, toolbars, tb;

// Keep track of number of images loaded.
//var imagesLoaded = 0;

function toolbarInit () {
/* ---------------------------------------------------------
 * Should be called after the outerdoc has loaded. 
 * Initializes the Toolbar for display.
 */
    // 'toolbars' contains all the div tags
	var tbs = outerdoc.body.all.tags("DIV");

    // There are 3 <div>'s. If another is ever added, this number should be incremented.
    if (tbs.length < 3)
        return;
    else
        clearInterval(tbInterval);

    initialized = true;

    tb = {};
    toolbars = [];
    document.all.editor_iframe.style.visibility = 'visible';
// Go through the outerdoc and get the toolbar classes
	for (var i = 0; i < tbs.length; i++) {
		var toolbar = tbs[i];

		tb[toolbar.title] = toolbar;
		toolbars[toolbars.length] = toolbar;

		toolbar.TB_INDEX  = toolbars.length;

// Initialize the toolbar
        tb_init(toolbar);
	}

	tb_layout();

// If the window is resized we need to re-layout the 
// toolbar.
	toolbar_init = true;
}

function tb_init (toolbar) {
/* ---------------------------------------------------------
 * Called for each toolbar DIV. Populates the toolbar and 
 * sets the width.
 */
	toolbar.TBWidth = 0;
    tb_populate(toolbar)
	toolbar.style.posWidth = toolbar.TBWidth;
	return true;
}

function tb_populate (toolbar) {
/* ---------------------------------------------------------
 * Moves all of toolbar 'toolbar's icons to the proper location on
 * the screen and sets the correct size for the toolbars.
 */

	var elements = toolbar.children;
	if (!elements) return;

// Loop through all the toolbars children.
	for (var i = 0; i < elements.length; i++) {
		var element = elements[i];
		if (element.tagName == "SCRIPT" || element.tagName == "!") continue;

// Switch to see what element we are workin with.
		switch (element.className) {
			case "tb_menu_item": // A button
				if (element.INITIALIZED == null)
                    tb_init_button(element)
				element.style.posLeft = toolbar.TBWidth;
				toolbar.TBWidth += element.offsetWidth + 1;
				break;

			case "tb_general": // Not a button - most likely a form field

			case "tb_menu_text":
				element.style.posLeft = toolbar.TBWidth;
				toolbar.TBWidth += element.offsetWidth + 5;
				break;

			case "tb_sep": // Seperator
				element.style.posLeft = toolbar.TBWidth + 2;
				toolbar.TBWidth += 5;
				break;

			case "tb_handle": // Toolbar handle
				element.style.posLeft = 2;
				toolbar.TBWidth += element.offsetWidth + 7;
				break;

			default: // Should never get here unless the html is messed
		}
	}

	toolbar.TBWidth++; // Add 1 in case the width is zero
	return true;
}

function tb_init_button (element) {
/* ---------------------------------------------------------
 * Sets op all the defaults for a button DIV. Saves any 
 * onclick and detaches the event. OnClick events are called
 * onMouseDown.
 */
	if (element.className == "tb_general") return true;

// Set events
	element.onmouseover   = tb_mouseover;
	element.onmouseout    = tb_mouseout;
	element.onmousedown   = tb_mousedown;
	element.onmouseup     = tb_mouseup;

// Disable events
	element.ondragstart   = cancel_event;
	element.onselectstart = cancel_event;
	element.onselect      = cancel_event;

// Save onClick event for onMouseDown
	element.YUSERONCLICK  = element.onclick;
	element.onclick       = cancel_event;

// So we don't re-initialize
	element.INITIALIZED  = true;

	return true;
}

function tb_layout () {
/* ---------------------------------------------------------
 * Layouts the toolbar on the screen based on the screen
 * width and the widths built in tb_populate().
 */

    if (!initialized)
        toolbarInit();

	var num_tb = toolbars.length;

// No toolbars
	if (num_tb == 0) return;
	var i;

// Get the screen width minus the width of the scrollbar
	var sbar = outerdoc.body.offsetWidth - outerdoc.body.clientWidth;
	var ScrWid = (outerdoc.body.offsetWidth  - sbar);
	var ScrHit = (outerdoc.body.offsetHeight - sbar);

// Go through the toolbars and find the width of the widest
// one.
	var TotalLen = ScrWid;
	var tb = [];
	var e = 0;
	for (i = 0; i < num_tb; i++) {
		tb[e] = toolbars[i];
		if (tb[e].TBWidth > TotalLen) TotalLen = tb[e].TBWidth;
		e++;
	}
	e--;
	if (!tb.length) { return; }
	var PrevTB;
	var LastStart = 0;
	var RelTop = 0;
	var LastWid, CurrWid;

// Position the top toolbar to the top of the screen
	var TB           = tb[0];
	TB.style.posTop  = 0;
	TB.style.posLeft = 0;
	var rows         = 1;

// Go through the toolbars and update there width
// and position.
	var Start = TB.TBWidth;
	for (i = 1; i < tb.length; i++) {
		PrevTB = TB;
		TB = tb[i];
		CurrWid = TB.TBWidth;

// Reached the end of the screen, reset to the start
		if ((Start + CurrWid) > ScrWid) { 
			Start = 0;
			rows++;
			LastWid = TotalLen - LastStart;
		}
		else {
			LastWid = PrevTB.TBWidth;
			RelTop -= TB.offsetHeight;
		}
	  
		TB.style.posTop = RelTop;
		TB.style.posLeft = Start;
		PrevTB.style.width = LastWid;

		LastStart = Start;
		Start    += CurrWid;

	}
	outerdoc.all.editor_iframe.style.posTop     = rows * 25;
	outerdoc.all.editor_iframe.style.posHeight  = ScrHit - (rows * 25);
	outerdoc.all.editor_iframe.style.posWidth   = ScrWid;
	outerdoc.all.editor_iframe.style.visibility = 'visible';

// Set the total width
	TB.style.width = TotalLen - LastStart;

// Move the rest of the toolbars down
	TB = tb[--i];
	var TBInd = TB.sourceIndex;
	var A = TB.document.all;
	for (var i in A) {
		var item = A.item(i);
		if (item && item.style && item.sourceIndex > TBInd && tb[item.title])
		    item.style.posTop = RelTop;
	}
}

function tb_mouseover () {
/* ---------------------------------------------------------
 * OnMouseOver event handler function for toolbar buttons.
 */
 // Source must be an image
    var event = document.frames.editor_iframe.event;
	if (event.srcElement.tagName != "IMG") return cancel_event(event);
	var image   = event.srcElement;
	var element = image.parentElement;

// If we are in text mode and the button is disables for 
// text mode. cancel the mouseover.
	if (element.disabled) return cancel_event(event);

// If the image in normal state put it in mouseover state
	if (image.className == "tb_icon") {
		element.className = "menu_item_mouseoverup";
	}
// else if it is in down state put it in mouseover
// for down states.
	else if (image.className == "icon_down") {
		element.className = "menu_item_mouseoverdown";
	}

	return cancel_event(event);
}

function tb_mouseout () {
/* ---------------------------------------------------------
 * MouseOut event handler function for toolbar buttons
 */
 // The source tag must be an image.
    var event = document.frames.editor_iframe.event;
	if (event.srcElement.tagName != "IMG") return cancel_event(event);
	var image   = event.srcElement;
	var element = image.parentElement;

	if (element.disabled) return cancel_event(event);

// If the button is a toggle update it's state.
    if (element.isPressed) {
		element.className = "menu_item_mouseoverdown"
		image.className   = 'icon_down';
	}
// else put the image back to it's normal state.
	else {
	    element.className  = "tb_menu_item";
	    image.className    = "tb_icon";
	}

    return cancel_event(event);
}

function tb_mousedown () {
/* ---------------------------------------------------------
 * MouseDown event handler for toolbar buttons.
 */

 // The source tag must be an image.
    var evnt = document.frames.editor_iframe.event;
	if (evnt.srcElement.tagName != "IMG") return cancel_event(evnt);
	var image   = evnt.srcElement;
	var element = image.parentElement;

// If we are in "text mode" and the button is not supported in
// "text mode" cancel the event and return false.
	if (element.disabled) return cancel_event(evnt);

    if (element.isPressed != null && !element.isPressed)
        press(element, image);
	element.className = "menu_item_mouseoverdown";
	image.className   = "icon_down";

// We disabled the click function and saved it in this.
// Eval it here and run it.

	if (element.YUSERONCLICK) eval(element.YUSERONCLICK + "anonymous()");
	return cancel_event(evnt);
}

function tb_mouseup () {
/* ---------------------------------------------------------
 * MouseUp event handler function for toolbar buttons.
 */
 // The source element must be an image type.
    var event = document.frames.editor_iframe.event;
	if (event.srcElement.tagName != "IMG") return cancel_event(event);
	var image   = event.srcElement;
	var element = image.parentElement;

// If we are in "text mode" and the field is disabled in that
// mode return and cancel the event.
	if (element.disabled) return cancel_event(event);

// It the icons to the mouseUp state.
	element.className = "menu_item_mouseoverup";
	image.className   = "tb_icon";

// Refocus the compose window here.
	iframe.focus();

	return cancel_event(event);

}

function cancel_event (evnt) {
/* ---------------------------------------------------------
 * General function to cancel an event.
 */
    if (!evnt) evnt = event;
    if (!evnt) return false;
    evnt.returnValue  = false;
    evnt.cancelBubble = true;
    if (event) {
        event.returnValue  = false;
        event.cancelBubble = true;
    }
    return false;
}

