// DHTML Editing Component Constants for JavaScript
// Copyright 2000 Microsoft Corporation.  All rights reserved.
//

//
// Command IDs
//
DECMD_BOLD =                      5000
DECMD_COPY =                      5002
DECMD_CUT =                       5003
DECMD_DELETE =                    5004
DECMD_DELETECELLS =               5005
DECMD_DELETECOLS =                5006
DECMD_DELETEROWS =                5007
DECMD_FINDTEXT =                  5008
DECMD_FONT =                      5009
DECMD_GETBACKCOLOR =              5010
DECMD_GETBLOCKFMT =               5011
DECMD_GETBLOCKFMTNAMES =          5012
DECMD_GETFONTNAME =               5013
DECMD_GETFONTSIZE =               5014
DECMD_GETFORECOLOR =              5015
DECMD_HYPERLINK =                 5016
DECMD_IMAGE =                     5017
DECMD_INDENT =                    5018
DECMD_INSERTCELL =                5019
DECMD_INSERTCOL =                 5020
DECMD_INSERTROW =                 5021
DECMD_INSERTTABLE =               5022
DECMD_ITALIC =                    5023
DECMD_JUSTIFYCENTER =             5024
DECMD_JUSTIFYLEFT =               5025
DECMD_JUSTIFYRIGHT =              5026
DECMD_LOCK_ELEMENT =              5027
DECMD_MAKE_ABSOLUTE =             5028
DECMD_MERGECELLS =                5029
DECMD_ORDERLIST =                 5030
DECMD_OUTDENT =                   5031
DECMD_PASTE =                     5032
DECMD_REDO =                      5033
DECMD_REMOVEFORMAT =              5034
DECMD_SELECTALL =                 5035
DECMD_SEND_BACKWARD =             5036
DECMD_BRING_FORWARD =             5037
DECMD_SEND_BELOW_TEXT =           5038
DECMD_BRING_ABOVE_TEXT =          5039
DECMD_SEND_TO_BACK =              5040
DECMD_BRING_TO_FRONT =            5041
DECMD_SETBACKCOLOR =              5042
DECMD_SETBLOCKFMT =               5043
DECMD_SETFONTNAME =               5044
DECMD_SETFONTSIZE =               5045
DECMD_SETFORECOLOR =              5046
DECMD_SPLITCELL =                 5047
DECMD_UNDERLINE =                 5048
DECMD_UNDO =                      5049
DECMD_UNLINK =                    5050
DECMD_UNORDERLIST =               5051
DECMD_PROPERTIES =                5052

// OLECMDEXECOPT  
OLECMDEXECOPT_DODEFAULT =         0 
OLECMDEXECOPT_PROMPTUSER =        1
OLECMDEXECOPT_DONTPROMPTUSER =    2

// DHTMLEDITCMDF
DECMDF_NOTSUPPORTED =             0 
DECMDF_DISABLED =                 1 
DECMDF_ENABLED =                  3
DECMDF_LATCHED =                  7
DECMDF_NINCHED =                  11

// DHTMLEDITAPPEARANCE
DEAPPEARANCE_FLAT =               0
DEAPPEARANCE_3D =                 1 

// OLE_TRISTATE
OLE_TRISTATE_UNCHECKED =          0
OLE_TRISTATE_CHECKED =            1
OLE_TRISTATE_GRAY =               2

var aEditors = new Array();

function CreateEditor(sEditorName) {
	aEditors[sEditorName] = new Editor(sEditorName);
}

function Editor(sName) {
	this.m_sName = sName;
	this.cbEditor = null;
	this.currentElement = null;
	this.clickElement = null;
	this.currentPanel = null;
	this.secondPanel = null;
	this.ILevel = 3;
	this.rlevel = 3;
	this.init = 0;
	this.showing = 0;
	this.styleSet = 0;
	this.styles = null;
	
	this.evButtons = null;
	
	this.cheight = 0;
	this.IDx = 0;
	this.sInit = 1;
	this.refocus = null;
	this.fm = null;
}

function InsertTable(sName) {

	var pVar = eval("aEditors[sName].fm." + sName + "ObjTableInfo;");
	var args = new Array();
	var arr = null;
	
	args["NumRows"] = pVar.NumRows;
	args["NumCols"] = pVar.NumCols;
	args["TableAttrs"] = pVar.TableAttrs;
	args["CellAttrs"] = pVar.CellAttrs;
	args["Caption"] = pVar.Caption;

  	arr = null;

  	arr = showModalDialog("/js/instable.html", args, "font-family:Verdana; font-size:12; dialogWidth:36em; dialogHeight:25em");
  	
  	if (arr != null) {
    	// Initialize table object
    	for ( elem in arr ) {    
    		if ("NumRows" == elem && arr["NumRows"] != null) {
    	  		pVar.NumRows = arr["NumRows"];
    		} else if ("NumCols" == elem && arr["NumCols"] != null) {
    	  		pVar.NumCols = arr["NumCols"];
    		} else if ("TableAttrs" == elem) {
    	  		pVar.TableAttrs = arr["TableAttrs"];
    		} else if ("CellAttrs" == elem) {
    	  		pVar.CellAttrs = arr["CellAttrs"];
    		} else if ("Caption" == elem) {
    	  		pVar.Caption = arr["Caption"];
    		}
    	}
		aEditors[sName].cbEditor.ExecCommand(DECMD_INSERTTABLE,OLECMDEXECOPT_DODEFAULT, pVar);
  	}
}

var theWinActive;
function InsertImage(sName) {
  
  var sSrc, sAlt;
  if(aEditors[sName].currentElement != null && aEditors[sName].currentElement.tagName == "IMG") {
  	theWinActive = window.open('../image_manager/insert_image.html?&editorID=' + sName, 'image_manager', 'width=520,height=350,left=80,top=100,resizable=no,scrollbars=no,menubar=no,directories=no,location=no,status=no');
  	theWinActive.focus();
  }
  else {
	theWinActive = window.open('../image_manager/insert_image.html?editorID=' + sName, 'image_manager', 'width=520,height=350,left=80,top=100,resizable=no,scrollbars=no,menubar=no,directories=no,location=no,status=no');
	theWinActive.focus();
  }
  
}

function snapUpImage(sName) {
	var sSrc, sAlt;
	sSrc = theWinActive.document.theForm.txtSourceURL.value;
	sAlt = theWinActive.document.theForm.txtAltText.value;
	
  	if(aEditors[sName].currentElement != null && aEditors[sName].currentElement.tagName == "IMG") {    
  		aEditors[sName].currentElement.src = sSrc;
	  	aEditors[sName].currentElement.alt = sAlt;
	  	panelswitch(sName);
  	}
  	else {
		insertHTMLDirect(sName, "<img alt=\"" + sAlt + "\" src=\"" + sSrc + "\">");
  	}
  	theWinActive.close();
}

function InsertImageOld(sName) {
  var arr = null;
  var args = new Array();
  
  if(aEditors[sName].currentElement != null && aEditors[sName].currentElement.tagName == "IMG") {  
  	args["src"] = aEditors[sName].currentElement.src;
  	args["alt"] = aEditors[sName].currentElement.alt;
  	arr = showModalDialog("../image_manager/insert_image.html", args, "font-family:Verdana; font-size:11; dialogWidth:48em; dialogHeight:35em");
  	if (arr != null) {
  		aEditors[sName].currentElement.src = arr["TagResult"];
  		aEditors[sName].currentElement.alt = arr["AltResult"];
  		panelswitch(sName);
  	}  
  }
  else {
  	args["src"] = "";
  	args["alt"] = "";
  	arr = showModalDialog("../image_manager/insert_image.html", args, "font-family:Verdana; font-size:11; dialogWidth:48em; dialogHeight:35em");
  	if (arr != null) {
		insertHTMLDirect(sName, "<img alt=\"" + arr["AltResult"] + "\" src=\"" + arr["TagResult"] + "\">");
  	}
  }
  
}

function DECMD_INSERTAN_IMAGE_onclick(sName) {
	insertHTMLDirect(sName, "<img src=\"/images/c9/icons/bold.gif\">");
}

function InsertTrackedLink(sName) {
	var arr = null;
	var args = new Array();
	
	var sel = eval(sName + ".DOM.selection");
	if ("None" != sel.type ) {
    	range = sel.createRange();
    	
		arr = showModalDialog("insert_tracked_link.jsp?selection=" + escape(range.htmlText), args, "font-family:Verdana; font-size:12; dialogWidth:36em; dialogHeight:25em");
		if (arr != null) {			
			range.pasteHTML(arr["URLResult"]);
		}
		panelswitch(sName);
	}
	else {
		alert('nothing selected!!');
	}
}

function insertSpecialChar(sName) {
	var sel = aEditors[sName].cbEditor.DOM.selection;

   	range = sel.createRange();
   	if(range != null) {
		var arr = showModalDialog( "/js/specialchar.html","","font-family:Verdana; font-size:12; dialogWidth:30em; dialogHeight:34em" );
		if(arr != null && arr != '')
			range.pasteHTML(arr);	
	}
}

function InsertAnObject(sName) {
  var arr = null;
  var args = new Array();
	if(aEditors[sName].currentElement != null && aEditors[sName].currentElement.tagName == "IMG") {
		args["src"] = aEditors[sName].currentElement.src;
		arr = showModalDialog("insert_personalization_field.jsp?classname=" + escape(sPersonalizationClass), args, "font-family:Verdana; font-size:12; dialogWidth:36em; dialogHeight:25em");
		if (arr != null) {
			aEditors[sName].currentElement.src = arr["TagResult"];
			aEditors[sName].currentElement.alt = arr["AltResult"];
		}
		panelswitch(sName);
	}
	else {  
		arr = showModalDialog("email_templ_insert_field.jsp", args, "font-family:Verdana; font-size:12; dialogWidth:36em; dialogHeight:25em");
		if (arr != null) {
			insertHTMLDirect(sName, "<img alt=\"" + arr["AltResult"] + "\" src=\"" + arr["TagResult"] + "\">");
		}
	}
}

function DECMD_INSERTAN_FILE_onclick(sName) {
	alert('pending');
}

function documentComplete(sName, objValue) {

	aEditors[sName].fm = document.theForm;

	aEditors[sName].evButtons = new Array()
	aEditors[sName].evButtons[0] = new evItem(DECMD_BOLD, document.body.all["ID_bold" + sName]);
	aEditors[sName].evButtons[1] = new evItem(DECMD_CUT,document.body.all["ID_cut" + sName]);
	aEditors[sName].evButtons[2] = new evItem(DECMD_COPY,document.body.all["ID_copy" + sName])
	aEditors[sName].evButtons[3] = new evItem(DECMD_PASTE,document.body.all["ID_paste" + sName])
	aEditors[sName].evButtons[4] = new evItem(DECMD_UNDO,document.body.all["ID_undo" + sName])
	aEditors[sName].evButtons[5] = new evItem(DECMD_REDO,document.body.all["ID_redo" + sName])
	aEditors[sName].evButtons[6] = new evItem(DECMD_SETFORECOLOR,document.body.all["ID_fgcolor" + sName])
	aEditors[sName].evButtons[7] = new evItem(DECMD_BOLD,document.body.all["ID_bold" + sName])
	aEditors[sName].evButtons[8] = new evItem(DECMD_ITALIC,document.body.all["ID_italic" + sName])
	aEditors[sName].evButtons[9] = new evItem(DECMD_UNDERLINE,document.body.all["ID_under" + sName])
	aEditors[sName].evButtons[10] = new evItem(DECMD_OUTDENT,document.body.all["ID_deindent" + sName])
	aEditors[sName].evButtons[11] = new evItem(DECMD_INDENT,document.body.all["ID_inindent" + sName])
	aEditors[sName].evButtons[12] = new evItem(DECMD_JUSTIFYLEFT,document.body.all["ID_left" + sName])
	aEditors[sName].evButtons[13] = new evItem(DECMD_JUSTIFYCENTER,document.body.all["ID_center" + sName])
	aEditors[sName].evButtons[14] = new evItem(DECMD_JUSTIFYRIGHT,document.body.all["ID_right" + sName])
	aEditors[sName].evButtons[15] = new evItem(DECMD_UNORDERLIST,document.body.all["ID_bullist" + sName])
	aEditors[sName].evButtons[16] = new evItem(DECMD_IMAGE,document.body.all["ID_image" + sName])
	aEditors[sName].evButtons[17] = new evItem(DECMD_HYPERLINK,document.body.all["ID_link" + sName])

	aEditors[sName].evButtons[18] = new evItem(DECMD_DELETECELLS,document.body.all["ID_delcell" + sName])
	aEditors[sName].evButtons[19] = new evItem(DECMD_DELETECOLS,document.body.all["ID_delcol" + sName])
	aEditors[sName].evButtons[20] = new evItem(DECMD_DELETEROWS,document.body.all["ID_delrow" + sName])
	aEditors[sName].evButtons[21] = new evItem(DECMD_INSERTCELL,document.body.all["ID_inscell" + sName])
	aEditors[sName].evButtons[22] = new evItem(DECMD_INSERTCOL,document.body.all["ID_inscol" + sName])
	aEditors[sName].evButtons[23] = new evItem(DECMD_INSERTROW,document.body.all["ID_insrow" + sName])
	aEditors[sName].evButtons[24] = new evItem(DECMD_MERGECELLS,document.body.all["ID_mrgcell" + sName])
	aEditors[sName].evButtons[25] = new evItem(DECMD_SPLITCELL,document.body.all["ID_spltcell" + sName])

	eval("aEditors[sName].fm." + sName + ".DOM.body.innerHTML = objValue.value;");
	eval("aEditors[sName].fm." + sName + ".DOM.createStyleSheet('http://localhost/css/contentStyle.css');");
	eval("aEditors[sName].fm." + sName + ".BaseURL = sBaseURL;");
	
	aEditors[sName].init = 1;
	aEditors[sName].cbEditor = eval("aEditors[sName].fm." + sName); 
	
	buildStyles(sName);
}

function DECMD_SETFORECOLOR_onclick(sName) {
  var arr = showModalDialog( "/js/selcolor.html","","font-family:Verdana; font-size:12; dialogWidth:30em; dialogHeight:34em" );

  if (arr != null) {
    aEditors[sName].cbEditor.ExecCommand(DECMD_SETFORECOLOR,OLECMDEXECOPT_DODEFAULT, arr);
  }
}

function DECMD_SETBACKCOLOR_onclick(sName) {
  var arr = showModalDialog( "/js/selcolor.html","","font-family:Verdana; font-size:12; dialogWidth:30em; dialogHeight:34em" );

  if (arr != null) {
   aEditors[sName].currentElement.bgColor = arr;
  }
  aEditors[sName].cbEditor.focus();
}

function drawEditingPanel(sName, sElementName) {
	var html = "";
	html += "<tr><td><table><tr>";
	
	html += "<td>";
	html += "<select name=\"ClassName" + sName + "\" onchange=\"setClass('" + sName + "', aEditors['" + sName + "'].fm.ClassName.options[aEditors['" + sName + "'].fm.ClassName.selectedIndex].value)\" style=\"font-size:8pt\"></select>";
	html += "</td>";
	
	html += "<td><select ID=\"ParagraphStyle" + sName + "\" TITLE=\"Paragraph Format\" LANGUAGE=\"javascript\" onchange=\"ComandBox('" + sName + "', 'pstyle')\" style=\"font-size:8pt\">";
	html += "<option value=\"Normal\">Normal";
	html += "<option value=\"Heading 1\">Heading 1";
	html += "<option value=\"Heading 2\">Heading 2";
	html += "<option value=\"Heading 3\">Heading 3";
	html += "<option value=\"Heading 4\">Heading 4";
	html += "<option value=\"Heading 5\">Heading 5";
	html += "<option value=\"Heading 6\">Heading 6";
	html += "<option value=\"Address\">Address";
	html += "<option value=\"Formatted\">Formatted";
	html += "</select>";
	html += "<select ID=\"FontName" + sName + "\"  TITLE=\"Font Name\" LANGUAGE=\"javascript\" onchange=\"ComandBox('" + sName + "', 'fontname')\" style=\"font-size:8pt\">";
	html += "<option value=\"Arial\">Arial";
	html += "<option value=\"Tahoma\">Tahoma";
	html += "<option value=\"Courier New\">Courier New";
	html += "<option value=\"Times New Roman\">Times New Roman";
	html += "<option value=\"Verdana\">Verdana";
	html += "</select>";
	html += "<select ID=\"FontSize" + sName + "\"  TITLE=\"Font Size\" LANGUAGE=\"javascript\" onchange=\"ComandBox('" + sName + "', 'fontsize')\" style=\"font-size:8pt\">";
	html += "<option value=\"1\">1";
	html += "<option value=\"2\">2";
	html += "<option value=\"3\">3";
	html += "<option value=\"4\">4";
	html += "<option value=\"5\">5";
	html += "<option value=\"6\">6";
	html += "<option value=\"7\">7";
	html += "</select></td>";
	
	html += "<td><img class=\"button\" id=\"ID_fgcolor" + sName + "\" src=\"/images/c9/icons/fgcolor.gif\" onMouseDown=\"evButtonEvent('" + sName + "', this);\" onMouseUp=\"evButtonEvent('" + sName + "', this);\" onMouseOver=\"evButtonEvent('" + sName + "', this);\" onMouseOut=\"evButtonEvent('" + sName + "', this);\" onClick=\"evButtonEvent('" + sName + "', this);\" unselectable=\"on\" width=\"23\" height=\"22\" class=\"button\"></td>";
	
	html += "<td><img title=\"Fix MS Word formating\" class=\"button\" src=\"/images/c9/icons/word.gif\" onMouseDown=\"evButtonEvent('" + sName + "', this);\" onMouseUp=\"evButtonEvent('" + sName + "', this);\" onMouseOver=\"evButtonEvent('" + sName + "', this);\" onMouseOut=\"evButtonEvent('" + sName + "', this);\" onClick=\"ComandBox('" + sName + "', 'word');\" unselectable=\"on\" width=\"23\" height=\"22\"></td>";
	html += "<td><img alt=\"Insert Special Character\" class=\"button\" id=\"ID_specialchar" + sName + "\" src=\"/images/c9/icons/icon_emptybox_white.gif\" onMouseDown=\"evButtonEvent('" + sName + "', this);\" onMouseUp=\"evButtonEvent('" + sName + "', this);\" onMouseOver=\"evButtonEvent('" + sName + "', this);\" onMouseOut=\"evButtonEvent('" + sName + "', this);\" onClick=\"ComandBox('" + sName + "', 'specialchar');\" unselectable=\"on\" class=\"button\"></td>";
	
	html += "<td><span class=\"maintext\"><input onclick=\"htmlview('" + sName + "', document.theForm." + sElementName + ", this.checked)\" type=checkbox>View HTML Source</span></td>";
	html += "<input type=hidden name=\"iLevel" + sName + "\" value=\"3\">";
	html += "</tr></td></tr></table>";
	
	document.write(html);
}

function drawFontPanel(sName) {
	var html = "";
	html += "<tr><td><table><tr>";
	html += "<td><img id=\"ID_link" + sName + "\" title=\"Insert a link\" class=\"button\" src=\"/images/c9/icons/link.gif\" onMouseDown=\"evButtonEvent('" + sName + "', this);\" onMouseUp=\"evButtonEvent('" + sName + "', this);\" onMouseOver=\"evButtonEvent('" + sName + "', this);\" onMouseOut=\"evButtonEvent('" + sName + "', this);\" onClick=\"evButtonEvent('" + sName + "', this);\" unselectable=\"on\" width=\"23\" height=\"22\"></td>";
	html += "<td><img id=\"ID_cut" + sName + "\" title=\"Cut\" class=\"button\" src=\"/images/c9/icons/cut.gif\" onMouseDown=\"evButtonEvent('" + sName + "', this);\" onMouseUp=\"evButtonEvent('" + sName + "', this);\" onMouseOver=\"evButtonEvent('" + sName + "', this);\" onMouseOut=\"evButtonEvent('" + sName + "', this);\" onClick=\"evButtonEvent('" + sName + "', this);\" unselectable=\"on\" width=\"23\" height=\"22\"></td>";	
	html += "<td><img id=\"ID_copy" + sName + "\" title=\"Copy\" class=\"button\" src=\"/images/c9/icons/copy.gif\" onMouseDown=\"evButtonEvent('" + sName + "', this);\" onMouseUp=\"evButtonEvent('" + sName + "', this);\" onMouseOver=\"evButtonEvent('" + sName + "', this);\" onMouseOut=\"evButtonEvent('" + sName + "', this);\" onClick=\"evButtonEvent('" + sName + "', this);\" unselectable=\"on\" width=\"23\" height=\"22\"></td>";
	html += "<td><img id=\"ID_paste" + sName + "\" title=\"Paste\" class=\"button\" src=\"/images/c9/icons/paste.gif\" onMouseDown=\"evButtonEvent('" + sName + "', this);\" onMouseUp=\"evButtonEvent('" + sName + "', this);\" onMouseOver=\"evButtonEvent('" + sName + "', this);\" onMouseOut=\"evButtonEvent('" + sName + "', this);\" onClick=\"evButtonEvent('" + sName + "', this);\" unselectable=\"on\" width=\"23\" height=\"22\"></td>";
	html += "<td><img id=\"ID_undo" + sName + "\" title=\"Undo\" class=\"button\" src=\"/images/c9/icons/undo.gif\" onMouseDown=\"evButtonEvent('" + sName + "', this);\" onMouseUp=\"evButtonEvent('" + sName + "', this);\" onMouseOver=\"evButtonEvent('" + sName + "', this);\" onMouseOut=\"evButtonEvent('" + sName + "', this);\" onClick=\"evButtonEvent('" + sName + "', this);\" unselectable=\"on\" width=\"23\" height=\"22\"></td>";
	html += "<td><img id=\"ID_redo" + sName + "\" title=\"Redo\" class=\"button\" src=\"/images/c9/icons/redo.gif\" onMouseDown=\"evButtonEvent('" + sName + "', this);\" onMouseUp=\"evButtonEvent('" + sName + "', this);\" onMouseOver=\"evButtonEvent('" + sName + "', this);\" onMouseOut=\"evButtonEvent('" + sName + "', this);\" onClick=\"evButtonEvent('" + sName + "', this);\" unselectable=\"on\" width=\"23\" height=\"22\"></td>";

	html += "<td><img class=\"button\" id=\"ID_bold" + sName + "\" src=\"/images/c9/icons/bold.gif\" onMouseDown=\"evButtonEvent('" + sName + "', this);\" onMouseUp=\"evButtonEvent('" + sName + "', this);\" onMouseOver=\"evButtonEvent('" + sName + "', this);\" onMouseOut=\"evButtonEvent('" + sName + "', this);\" onClick=\"evButtonEvent('" + sName + "', this);\" unselectable=\"on\" width=\"23\" height=\"22\" class=\"button\"></td>";
	html += "<td><img class=\"button\" id=\"ID_italic" + sName + "\" src=\"/images/c9/icons/italic.gif\" onMouseDown=\"evButtonEvent('" + sName + "', this);\" onMouseUp=\"evButtonEvent('" + sName + "', this);\" onMouseOver=\"evButtonEvent('" + sName + "', this);\" onMouseOut=\"evButtonEvent('" + sName + "', this);\" onClick=\"evButtonEvent('" + sName + "', this);\" unselectable=\"on\" width=\"23\" height=\"22\" class=\"button\"></td>";
	html += "<td><img class=\"button\" id=\"ID_under" + sName + "\" src=\"/images/c9/icons/under.gif\" onMouseDown=\"evButtonEvent('" + sName + "', this);\" onMouseUp=\"evButtonEvent('" + sName + "', this);\" onMouseOver=\"evButtonEvent('" + sName + "', this);\" onMouseOut=\"evButtonEvent('" + sName + "', this);\" onClick=\"evButtonEvent('" + sName + "', this);\" unselectable=\"on\" width=\"23\" height=\"22\" class=\"button\"></td>";
	
	html += "<td><img id=\"ID_bgcolor2" + sName + "\" class=\"button\" title=\"bgcolor\" src=\"/images/c9/icons/bgcolor.gif\" onMouseDown=\"evButtonEvent('" + sName + "', this);\" onMouseUp=\"evButtonEvent('" + sName + "', this);\" onMouseOver=\"evButtonEvent('" + sName + "', this);\" onMouseOut=\"evButtonEvent('" + sName + "', this);\" onClick=\"evButtonEvent('" + sName + "', this);\" unselectable=\"on\" width=\"23\" height=\"22\"></td>";
	
	html += "<td><img id=\"ID_left" + sName + "\" title=\"Align left\" class=\"button\" src=\"/images/c9/icons/left.gif\" onMouseDown=\"evButtonEvent('" + sName + "', this);\" onMouseUp=\"evButtonEvent('" + sName + "', this);\" onMouseOver=\"evButtonEvent('" + sName + "', this);\" onMouseOut=\"evButtonEvent('" + sName + "', this);\" onClick=\"evButtonEvent('" + sName + "', this);\" unselectable=\"on\" width=\"23\" height=\"22\"></td>";
	html += "<td><img id=\"ID_center" + sName + "\" title=\"Align center\" class=\"button\" src=\"/images/c9/icons/center.gif\" onMouseDown=\"evButtonEvent('" + sName + "', this);\" onMouseUp=\"evButtonEvent('" + sName + "', this);\" onMouseOver=\"evButtonEvent('" + sName + "', this);\" onMouseOut=\"evButtonEvent('" + sName + "', this);\" onClick=\"evButtonEvent('" + sName + "', this);\" unselectable=\"on\" width=\"23\" height=\"22\"></td>";
	html += "<td><img id=\"ID_right" + sName + "\" title=\"Align right\" class=\"button\" src=\"/images/c9/icons/right.gif\" onMouseDown=\"evButtonEvent('" + sName + "', this);\" onMouseUp=\"evButtonEvent('" + sName + "', this);\" onMouseOver=\"evButtonEvent('" + sName + "', this);\" onMouseOut=\"evButtonEvent('" + sName + "', this);\" onClick=\"evButtonEvent('" + sName + "', this);\" unselectable=\"on\" width=\"23\" height=\"22\"></td>";
	
	html += "<td><img class=\"button\" id=\"ID_deindent" + sName + "\" src=\"/images/c9/icons/deindent.gif\" onMouseDown=\"evButtonEvent('" + sName + "', this);\" onMouseUp=\"evButtonEvent('" + sName + "', this);\" onMouseOver=\"evButtonEvent('" + sName + "', this);\" onMouseOut=\"evButtonEvent('" + sName + "', this);\" onClick=\"evButtonEvent('" + sName + "', this);\" unselectable=\"on\" width=\"23\" height=\"22\" class=\"button\"></td>";
	html += "<td><img class=\"button\" id=\"ID_inindent" + sName + "\" src=\"/images/c9/icons/inindent.gif\" onMouseDown=\"evButtonEvent('" + sName + "', this);\" onMouseUp=\"evButtonEvent('" + sName + "', this);\" onMouseOver=\"evButtonEvent('" + sName + "', this);\" onMouseOut=\"evButtonEvent('" + sName + "', this);\" onClick=\"evButtonEvent('" + sName + "', this);\" unselectable=\"on\" width=\"23\" height=\"22\" class=\"button\"></td>";
	html += "<td><img class=\"button\" id=\"ID_bullist" + sName + "\" src=\"/images/c9/icons/bullist.gif\" onMouseDown=\"evButtonEvent('" + sName + "', this);\" onMouseUp=\"evButtonEvent('" + sName + "', this);\" onMouseOver=\"evButtonEvent('" + sName + "', this);\" onMouseOut=\"evButtonEvent('" + sName + "', this);\" onClick=\"evButtonEvent('" + sName + "', this);\" unselectable=\"on\" width=\"23\" height=\"22\" class=\"button\"></td>";
	html += "<td><img class=\"button\" id=\"ID_numlist" + sName + "\" src=\"/images/c9/icons/numlist.gif\" onMouseDown=\"evButtonEvent('" + sName + "', this);\" onMouseUp=\"evButtonEvent('" + sName + "', this);\" onMouseOver=\"evButtonEvent('" + sName + "', this);\" onMouseOut=\"evButtonEvent('" + sName + "', this);\" onClick=\"evButtonEvent('" + sName + "', this);\" unselectable=\"on\" width=\"23\" height=\"22\" class=\"button\"></td>"; 
	html += "</tr></table></td></tr>";
	document.write(html);
}

function drawImagePanel(sName) {
	var html = "";
	html += "<tr><td width=50><i><b>Image</b></i></td><td><table><tr><td>";
	html += "Width:	<input type=\"text\" name=\"IPwidth\" onChange=\"setStyle('width',this)\" onKeyPress=\"setStyle('width',this)\" style=\"font-size:8pt;width:40\">";
	html += "Height:<input type=\"text\" name=\"IPheight\" onChange=\"setStyle('height',this)\" onKeyPress=\"setStyle('height',this)\" style=\"font-size:8pt;width:40\">";
	html += "Border:<input type=\"text\" name=\"IPborder\" onChange=\"setImage('border',this)\" onKeyPress=\"setImage('border',this)\" style=\"font-size:8pt;width:20\">";
	html += "hSpace:<input type=\"text\" name=\"IPhspace\" onChange=\"setImage('hspace',this)\" onKeyPress=\"setImage('hspace',this)\" style=\"font-size:8pt;width:20\">";
	html += "vSpace:<input type=\"text\" name=\"IPvspace\" onChange=\"setImage('vspace',this)\" onKeyPress=\"setImage('vspace',this)\" style=\"font-size:8pt;width:20\">";
	html += "Align:";
	html += "<select name=\"IPalign\" onChange=\"setImage('align',this)\" style=\"font-size:8pt\">";
	html += "<option value=\"\">None</option>";
	html += "<option value=\"top\">top</option>";
	html += "<option value=\"middle\">middle</option>";
	html += "<option value=\"bottom\">bottom</option>";
	html += "<option value=\"left\">left</option>";
	html += "<option value=\"center\">center</option>";
	html += "<option value=\"right\">right</option>";
	html += "</select>";
	html += "</td></tr></table></td></tr>";
	document.write(html);
}

function drawTablePanel(sName) {
	var html = "";
	html += "<tr><td unselectable=\"on\" width=50><table><tr>";
	html += "<td><img id=\"ID_instable" + sName + "\" title=\"Insert a table\" class=\"button\" src=\"/images/c9/icons/instable.gif\" onMouseDown=\"evButtonEvent('" + sName + "', this);\" onMouseUp=\"evButtonEvent('" + sName + "', this);\" onMouseOver=\"evButtonEvent('" + sName + "', this);\" onMouseOut=\"evButtonEvent('" + sName + "', this);\" onClick=\"evButtonEvent('" + sName + "', this);\" unselectable=\"on\" width=\"23\" height=\"22\"></td>";
	html += "<td><span class=maintext>W:</span><input type=\"text\" name=\"TBwidth" + sName + "\" onChange=\"setStyle('" + sName + "', 'width',this)\" onKeyPress=\"setStyle('" + sName + "', 'width',this)\" style=\"font-size:8pt;width:25\">";
	html += "<span class=maintext>H:</span><input type=\"text\" name=\"TBheight" + sName + "\" onChange=\"setStyle('" + sName + "', 'height',this)\" onKeyPress=\"setStyle('" + sName + "', 'height',this)\" style=\"font-size:8pt;width:25\">";
	html += "<span class=maintext>Bd:</span><input type=\"text\" name=\"TBborder" + sName + "\" onChange=\"setImage('" + sName + "', 'border',this)\" onKeyPress=\"setImage('" + sName + "', 'border',this)\" style=\"font-size:8pt;width:15\">";
	html += "<span class=maintext>Pd:</span><input type=\"text\" name=\"TBcellPadding" + sName + "\" onChange=\"setImage('" + sName + "', 'cellPadding',this)\" onKeyPress=\"setImage('" + sName + "', 'cellPadding',this)\" style=\"font-size:8pt;width:15\">";
	html += "<span class=maintext>Sp:</span><input type=\"text\" name=\"TBcellSpacing" + sName + "\" onChange=\"setImage('" + sName + "', 'cellSpacing',this)\" onKeyPress=\"setImage('" + sName + "', 'cellSpacing',this)\" style=\"font-size:8pt;width:15\">";
 	html += "<span class=maintext>vA</span><select name=\"TDvalign" + sName + "\" onChange=\"setImage('vAlign',this)\" style=\"font-size:8pt;width:34\">";
	html += "<option value=\"\"> </option>";
	html += "<option value=\"top\">T</option>";
	html += "<option value=\"middle\">M</option>";
	html += "<option value=\"bottom\">B</option>";
	html += "</select></td>";
	html += "<td><img id=\"ID_insrow" + sName + "\" class=\"button\" title=\"insrow\" src=\"/images/c9/icons/insrow.gif\" onMouseDown=\"evButtonEvent('" + sName + "', this);\" onMouseUp=\"evButtonEvent('" + sName + "', this);\" onMouseOver=\"evButtonEvent('" + sName + "', this);\" onMouseOut=\"evButtonEvent('" + sName + "', this);\" onClick=\"evButtonEvent('" + sName + "', this);\" unselectable=\"on\" width=\"23\" height=\"22\"></td>";
	html += "<td><img id=\"ID_delrow" + sName + "\" class=\"button\" title=\"delrow\" src=\"/images/c9/icons/delrow.gif\" onMouseDown=\"evButtonEvent('" + sName + "', this);\" onMouseUp=\"evButtonEvent('" + sName + "', this);\" onMouseOver=\"evButtonEvent('" + sName + "', this);\" onMouseOut=\"evButtonEvent('" + sName + "', this);\" onClick=\"evButtonEvent('" + sName + "', this);\" unselectable=\"on\" width=\"23\" height=\"22\"></td>";
	html += "<td><img id=\"ID_inscol" + sName + "\" class=\"button\" title=\"inscol\" src=\"/images/c9/icons/inscol.gif\" onMouseDown=\"evButtonEvent('" + sName + "', this);\" onMouseUp=\"evButtonEvent('" + sName + "', this);\" onMouseOver=\"evButtonEvent('" + sName + "', this);\" onMouseOut=\"evButtonEvent('" + sName + "', this);\" onClick=\"evButtonEvent('" + sName + "', this);\" unselectable=\"on\" width=\"23\" height=\"22\"></td>";
	html += "<td><img id=\"ID_delcol" + sName + "\" class=\"button\" title=\"delcol\" src=\"/images/c9/icons/delcol.gif\" onMouseDown=\"evButtonEvent('" + sName + "', this);\" onMouseUp=\"evButtonEvent('" + sName + "', this);\" onMouseOver=\"evButtonEvent('" + sName + "', this);\" onMouseOut=\"evButtonEvent('" + sName + "', this);\" onClick=\"evButtonEvent('" + sName + "', this);\" unselectable=\"on\" width=\"23\" height=\"22\"></td>";
	html += "<td><img id=\"ID_inscell" + sName + "\" class=\"button\" title=\"inscell\" src=\"/images/c9/icons/inscell.gif\" onMouseDown=\"evButtonEvent('" + sName + "', this);\" onMouseUp=\"evButtonEvent('" + sName + "', this);\" onMouseOver=\"evButtonEvent('" + sName + "', this);\" onMouseOut=\"evButtonEvent('" + sName + "', this);\" onClick=\"evButtonEvent('" + sName + "', this);\" unselectable=\"on\" width=\"23\" height=\"22\"></td>";
	html += "<td><img id=\"ID_delcell" + sName + "\" class=\"button\" title=\"delcell\" src=\"/images/c9/icons/delcell.gif\" onMouseDown=\"evButtonEvent('" + sName + "', this);\" onMouseUp=\"evButtonEvent('" + sName + "', this);\" onMouseOver=\"evButtonEvent('" + sName + "', this);\" onMouseOut=\"evButtonEvent('" + sName + "', this);\" onClick=\"evButtonEvent('" + sName + "', this);\" unselectable=\"on\" width=\"23\" height=\"22\"></td>";
	html += "<td><img id=\"ID_mrgcell" + sName + "\" class=\"button\" title=\"mrgcell\" src=\"/images/c9/icons/mrgcell.gif\" onMouseDown=\"evButtonEvent('" + sName + "', this);\" onMouseUp=\"evButtonEvent('" + sName + "', this);\" onMouseOver=\"evButtonEvent('" + sName + "', this);\" onMouseOut=\"evButtonEvent('" + sName + "', this);\" onClick=\"evButtonEvent('" + sName + "', this);\" unselectable=\"on\" width=\"23\" height=\"22\"></td>";
	html += "<td><img id=\"ID_spltcell" + sName + "\" class=\"button\" title=\"spltcell\" src=\"/images/c9/icons/spltcell.gif\" onMouseDown=\"evButtonEvent('" + sName + "', this);\" onMouseUp=\"evButtonEvent('" + sName + "', this);\" onMouseOver=\"evButtonEvent('" + sName + "', this);\" onMouseOut=\"evButtonEvent('" + sName + "', this);\" onClick=\"evButtonEvent('" + sName + "', this);\" unselectable=\"on\" width=\"23\" height=\"22\"></td>";	
	html += "<td>";
	
	html += "</td></tr></table></td></tr>";
	document.write(html);
}


function drawTDPanel(sName) {
	var html = "";
	html += "<tr><td width=50><i><b>Cell</b></i></td><td><table><tr><td>";
	html += "W<input type=\"text\" name=\"TDwidth" + sName + "\" onChange=\"setStyle('width',this)\" onKeyPress=\"setStyle('width',this)\" style=\"font-size:8pt;width:40\">";
	html += "H<input type=\"text\" name=\"TDheight" + sName + "\" onChange=\"setStyle('height',this)\" onKeyPress=\"setStyle('height',this)\" style=\"font-size:8pt;width:40\">";
 	html += "bg<input type=\"text\" name=\"TDbgColor" + sName + "\" 	onChange=\"setImage('bgColor',this)\" onKeyPress=\"setImage('bgColor',this)\" style=\"font-size:8pt;width:50\">";
 	html += "A<select name=\"TDalign" + sName + "\" onChange=\"setImage('align',this)\" style=\"font-size:8pt;width:50\">";
	html += "<option value=\"\">None</option>";
	html += "<option value=\"left\">left</option>";
	html += "<option value=\"center\">center</option>";
	html += "<option value=\"right\">right</option>";
	html += "</select>";
 	html += "vA<select name=\"TDvalign" + sName + "\" onChange=\"setImage('vAlign',this)\" style=\"font-size:8pt;width:50\">";
	html += "<option value=\"\">None</option>";
	html += "<option value=\"top\">top</option>";
	html += "<option value=\"middle\">middle</option>";
	html += "<option value=\"bottom\">bottom</option>";
	html += "</select></td>";
	html += "<td><img id=\"ID_insrow" + sName + "\" class=\"button\" title=\"insrow\" src=\"/images/c9/icons/insrow.gif\" onMouseDown=\"evButtonEvent('" + sName + "', this);\" onMouseUp=\"evButtonEvent('" + sName + "', this);\" onMouseOver=\"evButtonEvent('" + sName + "', this);\" onMouseOut=\"evButtonEvent('" + sName + "', this);\" onClick=\"evButtonEvent('" + sName + "', this);\" unselectable=\"on\" width=\"23\" height=\"22\"></td>";
	html += "<td><img id=\"ID_delrow" + sName + "\" class=\"button\" title=\"delrow\" src=\"/images/c9/icons/delrow.gif\" onMouseDown=\"evButtonEvent('" + sName + "', this);\" onMouseUp=\"evButtonEvent('" + sName + "', this);\" onMouseOver=\"evButtonEvent('" + sName + "', this);\" onMouseOut=\"evButtonEvent('" + sName + "', this);\" onClick=\"evButtonEvent('" + sName + "', this);\" unselectable=\"on\" width=\"23\" height=\"22\"></td>";
	html += "<td><img id=\"ID_inscol" + sName + "\" class=\"button\" title=\"inscol\" src=\"/images/c9/icons/inscol.gif\" onMouseDown=\"evButtonEvent('" + sName + "', this);\" onMouseUp=\"evButtonEvent('" + sName + "', this);\" onMouseOver=\"evButtonEvent('" + sName + "', this);\" onMouseOut=\"evButtonEvent('" + sName + "', this);\" onClick=\"evButtonEvent('" + sName + "', this);\" unselectable=\"on\" width=\"23\" height=\"22\"></td>";
	html += "<td><img id=\"ID_delcol" + sName + "\" class=\"button\" title=\"delcol\" src=\"/images/c9/icons/delcol.gif\" onMouseDown=\"evButtonEvent('" + sName + "', this);\" onMouseUp=\"evButtonEvent('" + sName + "', this);\" onMouseOver=\"evButtonEvent('" + sName + "', this);\" onMouseOut=\"evButtonEvent('" + sName + "', this);\" onClick=\"evButtonEvent('" + sName + "', this);\" unselectable=\"on\" width=\"23\" height=\"22\"></td>";
	html += "<td><img id=\"ID_inscell" + sName + "\" class=\"button\" title=\"inscell\" src=\"/images/c9/icons/inscell.gif\" onMouseDown=\"evButtonEvent('" + sName + "', this);\" onMouseUp=\"evButtonEvent('" + sName + "', this);\" onMouseOver=\"evButtonEvent('" + sName + "', this);\" onMouseOut=\"evButtonEvent('" + sName + "', this);\" onClick=\"evButtonEvent('" + sName + "', this);\" unselectable=\"on\" width=\"23\" height=\"22\"></td>";
	html += "<td><img id=\"ID_delcell" + sName + "\" class=\"button\" title=\"delcell\" src=\"/images/c9/icons/delcell.gif\" onMouseDown=\"evButtonEvent('" + sName + "', this);\" onMouseUp=\"evButtonEvent('" + sName + "', this);\" onMouseOver=\"evButtonEvent('" + sName + "', this);\" onMouseOut=\"evButtonEvent('" + sName + "', this);\" onClick=\"evButtonEvent('" + sName + "', this);\" unselectable=\"on\" width=\"23\" height=\"22\"></td>";
	html += "<td><img id=\"ID_mrgcell" + sName + "\" class=\"button\" title=\"mrgcell\" src=\"/images/c9/icons/mrgcell.gif\" onMouseDown=\"evButtonEvent('" + sName + "', this);\" onMouseUp=\"evButtonEvent('" + sName + "', this);\" onMouseOver=\"evButtonEvent('" + sName + "', this);\" onMouseOut=\"evButtonEvent('" + sName + "', this);\" onClick=\"evButtonEvent('" + sName + "', this);\" unselectable=\"on\" width=\"23\" height=\"22\"></td>";
	html += "<td><img id=\"ID_spltcell" + sName + "\" class=\"button\" title=\"spltcell\" src=\"/images/c9/icons/spltcell.gif\" onMouseDown=\"evButtonEvent('" + sName + "', this);\" onMouseUp=\"evButtonEvent('" + sName + "', this);\" onMouseOver=\"evButtonEvent('" + sName + "', this);\" onMouseOut=\"evButtonEvent('" + sName + "', this);\" onClick=\"evButtonEvent('" + sName + "', this);\" unselectable=\"on\" width=\"23\" height=\"22\"></td>";
	html += "<td><img id=\"ID_bgcolor" + sName + "\" class=\"button\" title=\"bgcolor\" src=\"/images/c9/icons/bgcolor.gif\" onMouseDown=\"evButtonEvent('" + sName + "', this);\" onMouseUp=\"evButtonEvent('" + sName + "', this);\" onMouseOver=\"evButtonEvent('" + sName + "', this);\" onMouseOut=\"evButtonEvent('" + sName + "', this);\" onClick=\"evButtonEvent('" + sName + "', this);\" unselectable=\"on\" width=\"23\" height=\"22\"></td>";
	html += "</td></tr></table></td></tr>";
	document.write(html);
}

function drawImageSrcPanel(sName) {
	var html = "";
	html += "<tr><td><table><tr><td><img id=\"ID_image" + sName + "\" title=\"Insert an image\" class=\"button\" src=\"/images/c9/icons/image.gif\" onMouseDown=\"evButtonEvent('" + sName + "', this);\" onMouseUp=\"evButtonEvent('" + sName + "', this);\" onMouseOver=\"evButtonEvent('" + sName + "', this);\" onMouseOut=\"evButtonEvent('" + sName + "', this);\" onClick=\"evButtonEvent('" + sName + "', this);\" unselectable=\"on\" width=\"23\" height=\"22\"></td>";
	
	if(bShowLinkTracking)
		html += "<td><img title=\"Insert Tracked Link\" class=\"button\" src=\"/images/c9/icons/objectlink.gif\" onMouseDown=\"evButtonEvent('" + sName + "', this);\" onMouseUp=\"evButtonEvent('" + sName + "', this);\" onMouseOver=\"evButtonEvent('" + sName + "', this);\" onMouseOut=\"evButtonEvent('" + sName + "', this);\" onClick=\"ComandBox('" + sName + "', 'trackedlink');\" unselectable=\"on\" width=\"23\" height=\"22\"></td>";
	
	if(bShowPersonalization)
		html += "<td><img title=\"Insert Personalization Field\" class=\"button\" src=\"/images/c9/icons/objectlink.gif\" onMouseDown=\"evButtonEvent('" + sName + "', this);\" onMouseUp=\"evButtonEvent('" + sName + "', this);\" onMouseOver=\"evButtonEvent('" + sName + "', this);\" onMouseOut=\"evButtonEvent('" + sName + "', this);\" onClick=\"ComandBox('" + sName + "', 'objectlink');\" unselectable=\"on\" width=\"23\" height=\"22\"></td>";

	html += "<td><input type=\"text\" name=\"IPalt" + sName + "\" onChange=\"setImage('" + sName + "', 'alt',this)\" onKeyPress=\"setImage('" + sName + "', 'alt',this)\" style=\"font-size:8pt;width=200\"></td>";
	html += "<td><span class=maintext>Src:</span><input type=\"text\" name=\"IPsrc" + sName + "\" onChange=\"setImage('" + sName + "', 'src',this)\" onKeyPress=\"setImage('" + sName + "', 'src',this)\" style=\"font-size:8pt;width:200;\"></td>";

	html += "</tr></table></td></tr>";
	document.write(html);
}

function drawImagePanel2(sName) {
	var html = "";
	html += "<tr><td>Src:<input type=\"text\" name=\"IPsrc" + sName + "\" onChange=\"setImage('" + sName + "', 'src',this)\" onKeyPress=\"setImage('" + sName + "', 'src',this)\" style=\"font-size:8pt\">";
	html += "Alt:<input type=\"text\" name=\"IPalt" + sName + "\" onChange=\"setImage('" + sName + "', 'alt',this)\" onKeyPress=\"setImage('" + sName + "', 'alt',this)\" style=\"font-size:8pt\">";
	html += "</td></tr>";
	document.write(html);
}

function evButtonEvent(sName, ele){	
	if (ele.className == 'buttonDisabled')
		return false;
	switch(window.event.type)
	{
	case "mouseover":
	if (ele.className != 'buttonChecked')
		high(ele);
	break;
	case "mouseout":
	if (ele.className != 'buttonChecked')
		low(ele);
	break;
	case "mousedown":
		down(ele);
	break;
	case "click":
		ComandBox(sName, ele.id.slice(3,(ele.id.length - sName.length)))
	break;
	case "mouseup":
	if (ele.className != 'buttonChecked')
		high(ele);
	break;
	}
}


function high(ele){
	ele.className = 'buttonOver'
}

function low(ele){
	ele.className = 'button'
}

function down(ele){
	ele.className = 'buttonDown'
}

function ComandBox(sName, command){
	var tbContentElement = aEditors[sName].cbEditor;
  switch (command) {
    	case "link"		:tbContentElement.ExecCommand(DECMD_HYPERLINK,OLECMDEXECOPT_PROMPTUSER);break;
		case "save"		:htmlview(sName);aEditors[sName].fm.submit();break;
		case "cut"		:tbContentElement.ExecCommand(DECMD_CUT,OLECMDEXECOPT_DODEFAULT);break;
		case "copy"		:tbContentElement.ExecCommand(DECMD_COPY,OLECMDEXECOPT_DODEFAULT);break;
		case "paste"	:tbContentElement.ExecCommand(DECMD_PASTE,OLECMDEXECOPT_DODEFAULT);break;
		case "undo"		:tbContentElement.ExecCommand(DECMD_UNDO,OLECMDEXECOPT_DODEFAULT);break;
		case "redo"		:tbContentElement.ExecCommand(DECMD_REDO,OLECMDEXECOPT_DODEFAULT);break;
		case "fgcolor"	:DECMD_SETFORECOLOR_onclick(sName);break;
		case "bgcolor"	:DECMD_SETBACKCOLOR_onclick(sName);break;
		case "bgcolor2"	:DECMD_SETBACKCOLOR_onclick(sName);break;
		case "bold"		:tbContentElement.ExecCommand(DECMD_BOLD,OLECMDEXECOPT_DODEFAULT);break;
		case "italic"	:tbContentElement.ExecCommand(DECMD_ITALIC,OLECMDEXECOPT_DODEFAULT);break;
		case "under"	:tbContentElement.ExecCommand(DECMD_UNDERLINE,OLECMDEXECOPT_DODEFAULT);break;
		case "deindent"	:tbContentElement.ExecCommand(DECMD_OUTDENT,OLECMDEXECOPT_DODEFAULT);break;
		case "inindent"	:tbContentElement.ExecCommand(DECMD_INDENT,OLECMDEXECOPT_DODEFAULT);break;
		case "left"		:tbContentElement.ExecCommand(DECMD_JUSTIFYLEFT,OLECMDEXECOPT_DODEFAULT);break;
		case "center"	:tbContentElement.ExecCommand(DECMD_JUSTIFYCENTER,OLECMDEXECOPT_DODEFAULT);break;
		case "right"	:tbContentElement.ExecCommand(DECMD_JUSTIFYRIGHT,OLECMDEXECOPT_DODEFAULT);break;
		case "bullist"	:tbContentElement.ExecCommand(DECMD_UNORDERLIST,OLECMDEXECOPT_DODEFAULT);break;
    	case "numlist"	:tbContentElement.ExecCommand(DECMD_ORDERLIST,OLECMDEXECOPT_DODEFAULT);break;
    	case "specialchar" :insertSpecialChar(sName);break;
		case "instable"	:InsertTable(sName);break;
		case "filelink"	:DECMD_INSERTAN_FILE_onclick(sName);break;
		case "objectlink" :InsertAnObject(sName);break;
		case "trackedlink" :InsertTrackedLink(sName);break;
		case "image"	:InsertImage(sName);break;//DECMD_INSERTAN_IMAGE_onclick();break;
		case "fontsize"	:eval("tbContentElement.ExecCommand(DECMD_SETFONTSIZE, OLECMDEXECOPT_DODEFAULT, parseInt(aEditors[sName].fm.FontSize" + sName + ".value));");break;
		case "fontname"	:eval("tbContentElement.ExecCommand(DECMD_SETFONTNAME, OLECMDEXECOPT_DODEFAULT, aEditors[sName].fm.FontName" + sName + ".value);");break;
		case "pstyle"	:eval("tbContentElement.ExecCommand(DECMD_SETBLOCKFMT, OLECMDEXECOPT_DODEFAULT, aEditors[sName].fm.ParagraphStyle" + sName + ".value);");break;
		case "borders"	:tbContentElement.ShowBorders = !tbContentElement.ShowBorders;break;
		case "htmlview"	:htmlview(sName);break;
		case "delcell"	:tbContentElement.ExecCommand(DECMD_DELETECELLS,OLECMDEXECOPT_DODEFAULT);break;
		case "delcol" 	:tbContentElement.ExecCommand(DECMD_DELETECOLS,OLECMDEXECOPT_DODEFAULT);break;
		case "delrow"	:tbContentElement.ExecCommand(DECMD_DELETEROWS,OLECMDEXECOPT_DODEFAULT);break;
		case "inscell"	:tbContentElement.ExecCommand(DECMD_INSERTCELL,OLECMDEXECOPT_DODEFAULT);break;
		case "inscol"	:tbContentElement.ExecCommand(DECMD_INSERTCOL,OLECMDEXECOPT_DODEFAULT);break;
		case "insrow"	:tbContentElement.ExecCommand(DECMD_INSERTROW,OLECMDEXECOPT_DODEFAULT);break;
		case "mrgcell"	:tbContentElement.ExecCommand(DECMD_MERGECELLS,OLECMDEXECOPT_DODEFAULT);break;
		case "spltcell"	:tbContentElement.ExecCommand(DECMD_SPLITCELL,OLECMDEXECOPT_DODEFAULT);break;
		case "word"	    :worddecide(sName);break;
	}      

}

function displayChanged(sName) {	
	if (aEditors[sName].rlevel > 0) {
		displayChanged_standard(sName);
	}
}

function displayChanged_standard(sName) {
  if(!aEditors[sName].cbEditor)
    return false;
  
  for (i=0; i<aEditors[sName].evButtons.length; i++) {
    s = aEditors[sName].cbEditor.QueryStatus(aEditors[sName].evButtons[i].command);
	ele = aEditors[sName].evButtons[i].element
    if (s == DECMDF_DISABLED || s == DECMDF_NOTSUPPORTED) {
		if (ele.className != 'buttonDisabled')
			ele.className = 'buttonDisabled'
    } else if (s == DECMDF_ENABLED  || s == DECMDF_NINCHED) {
		if(ele.className != 'button')
			ele.className = 'button'
    } else { 
		if(ele.className != 'buttonChecked')
			ele.className = 'buttonChecked'
    }
  }

  s = aEditors[sName].cbEditor.QueryStatus(DECMD_GETBLOCKFMT);
  if (s == DECMDF_DISABLED || s == DECMDF_NOTSUPPORTED) {
    eval("aEditors[sName].fm.ParagraphStyle" + sName + ".disabled = true;");
  } else {
    eval("aEditors[sName].fm.ParagraphStyle" + sName + ".disabled = false;");
    eval("aEditors[sName].fm.ParagraphStyle" + sName + ".value = aEditors[sName].cbEditor.ExecCommand(DECMD_GETBLOCKFMT, OLECMDEXECOPT_DODEFAULT);");
  }
  s = aEditors[sName].cbEditor.QueryStatus(DECMD_GETFONTNAME);
  if (s == DECMDF_DISABLED || s == DECMDF_NOTSUPPORTED) {
    eval("aEditors[sName].fm.FontName" + sName + ".disabled = true;");
  } else {
    eval("aEditors[sName].fm.FontName" + sName + ".disabled = false;");
    eval("aEditors[sName].fm.FontName" + sName + ".value = aEditors[sName].cbEditor.ExecCommand(DECMD_GETFONTNAME, OLECMDEXECOPT_DODEFAULT);");
  }
  
  if (s == DECMDF_DISABLED || s == DECMDF_NOTSUPPORTED) {
    eval("aEditors[sName].fm.FontSize" + sName + ".disabled = true;");
  } else {
    eval("aEditors[sName].fm.FontSize" + sName + ".disabled = false;");
    eval("aEditors[sName].fm.FontSize" + sName + ".value = aEditors[sName].cbEditor.ExecCommand(DECMD_GETFONTSIZE, OLECMDEXECOPT_DODEFAULT);");
  }
  
  buildStyles(sName);
}	

function setselection(sName){
	checkElement = aEditors[sName].currentElement;
	sel = aEditors[sName].cbEditor.DOM.selection;	
	if (( "Text" == sel.type ) || ( "None" == sel.type )) {	
    	range = sel.createRange();
		range.collapse();
		aEditors[sName].currentElement = aEditors[sName].cbEditor.DOM.elementFromPoint(range.offsetLeft,range.offsetTop);		
		aEditors[sName].flag = 0;
	}
	else {
		aEditors[sName].flag = 1
	}
	
	aEditors[sName].selectElement = null;
	a = sel.createRange()
	if (a.text == aEditors[sName].currentElement.innerText)
		aEditors[sName].selectElement = aEditors[sName].currentElement
	
	if (a.htmlText == aEditors[sName].currentElement.outerHTML)
		aEditors[sName].selectElement = aEditors[sName].currentElement
	
  	for(k=0;k<eval("aEditors[sName].fm.ClassName" + sName + ".options.length");k++) {
  		if(eval("aEditors[sName].fm.ClassName" + sName + ".options[k].value") == aEditors[sName].currentElement.className) {
  			eval("aEditors[sName].fm.ClassName" + sName + ".options.selectedIndex = k;");
  			break;
  		}
  	}
  
	return aEditors[sName].currentElement;
}

function panelswitch(sName){	
	eval("aEditors[sName].fm.IPalt" + sName + ".value = '';");
	eval("aEditors[sName].fm.IPsrc" + sName + ".value = '';");
	eval("aEditors[sName].fm.TBwidth" + sName + ".value = '';");
	eval("aEditors[sName].fm.TBheight" + sName + ".value = '';");
	eval("aEditors[sName].fm.TBcellSpacing" + sName + ".value = '';");
	eval("aEditors[sName].fm.TBcellPadding" + sName + ".value = '';");
	eval("aEditors[sName].fm.TBborder" + sName + ".value = '';");
	eval("aEditors[sName].fm.TDvalign" + sName + ".selectedIndex = 0;");
	
	if(aEditors[sName].currentElement != null) {
		if (aEditors[sName].currentElement.tagName == 'IMG') {
			imagePanelSrcInit(sName)
		}
		else {
			if ((aEditors[sName].currentElement.tagName == 'TABLE')||(aEditors[sName].currentElement.tagName == 'TR')) {
				imageTableInit(sName)
			}
			else if (aEditors[sName].currentElement.tagName == 'TD') {
				imageTDInit(sName)
			}
		}
	}
}

function buildStyles(sName){

	if(aEditors[sName].styleSet == 1)
		return;

	aEditors[sName].styles = aEditors[sName].cbEditor.DOM.styleSheets[0].rules
	var jCounter = 0;
	
	if(aEditors[sName].styles.length > 0) {
		aEditors[sName].styleSet = 1;
	}
	
	for (i=0;i<aEditors[sName].styles.length;i++){
		text = aEditors[sName].styles[i].selectorText
		if((text.charAt(0) == '.') && (text.indexOf(':') == -1)){
			jCounter++
			text= text.slice(1,100)
			eval("aEditors[sName].fm.ClassName" + sName + ".options[jCounter] = new Option(text,text,null,null);");
		}
	 }
	 aEditors[sName].sInit = 0
}

function setInsertos(sName, ele){
	range = aEditors[sName].cbEditor.DOM.body.createTextRange()
	range.collapse()
	el = elem[ele]
	range.moveToElementText(el)
  	range.select()

	displayChanged_standard(sName);
	setselection(sName);
	panelswitch(sName);
}
 
function htmlview(sName, objElement, bChecked) {	
	if(aEditors[sName].init == 1){
		if (aEditors[sName].showing == 0){
			objElement.value = aEditors[sName].cbEditor.DOM.body.innerHTML;			
			eval(sName + "htmlSrc.style.visibility='visible';");
			aEditors[sName].cbEditor.style.visibility='hidden';
			aEditors[sName].showing = 1;
		} 
		else {				
			aEditors[sName].cbEditor.DOM.body.innerHTML =  objElement.value;
			eval(sName + "htmlSrc.style.visibility='hidden';");
			aEditors[sName].cbEditor.style.visibility='visible';
			aEditors[sName].showing = 0;
		}
	}
}

function htmlsave(sName, fmElement) {
	if(aEditors[sName] != undefined) {
		if(aEditors[sName].init != 0) {
			if (aEditors[sName].showing == 0) {
				fmElement.value = aEditors[sName].cbEditor.DOM.body.innerHTML;
			}
			else {
				aEditors[sName].cbEditor.DOM.body.innerHTML = fmElement.value;
			}
		}
	}
}

function worddecide(sName){
  text = "<html><title>Cloudnine - MS Word Format Removal</title><style>"
  +"A {text-decoration:none; color:black; FONT: normal 8px MS Sans Serif; height:1;width:100%;padding:2px;cursor:default;padding-left:20;}"
  +"A:hover { background-color:#55689a;color:white;cursor:default; text-decoration:none;}"
  +"</style>"
  +"<body style='margin:0;border:solid 1; border-color:buttonhighlight buttonshadow buttonshadow buttonhighlight;background-color:buttonface'>"
  +"<a href='javascript:void' onclick='opener.wordclean_lite(\"" + sName + "\");window.close()' title='This removes font styles'>Lite</a>"
  +"<a href='javascript:void' onclick='opener.wordclean(\"" + sName + "\");window.close()' title='This removes all html and leaves only carriage returns'>Industrial strength</a>"
  +"</body>"
  
  a = window.open('', 'wordclean', 'width=200,height=10,resizable=yes,top=150,left=150');
  a.document.write(text);
}

function wordclean(sName){
      regx  = /(<|<\/)([^>])*>/gi;
      regx2 = /\n/gi;

      text = aEditors[sName].cbEditor.DOM.body.innerHTML
      text =  text.replace(regx,'')
      text =  text.replace(regx2,'<br>')
            
      aEditors[sName].cbEditor.DOM.body.innerHTML = text;
      text = aEditors[sName].cbEditor.DOM.body.innerHTML;
      aEditors[sName].cbEditor.DOM.body.innerHTML = text;  
}

function wordclean_lite(sName){
      regx  = /(<|<\/)(span|\?xml|o:|font|div)([^>])*>/gi;
      regx2 = /<p([^>])*>/gi;
      regx3 = /<p>&nbsp;<\/p>/gi;
      text = aEditors[sName].cbEditor.DOM.body.innerHTML
      text =  text.replace(regx,'')
      text =  text.replace(regx2,'<p>')
      text =  text.replace(regx3,'')
      
      aEditors[sName].cbEditor.DOM.body.innerHTML = text;
      text = aEditors[sName].cbEditor.DOM.body.innerHTML;
      aEditors[sName].cbEditor.DOM.body.innerHTML = text;
}

function setClass(sName, value){
	a = aEditors[sName].cbEditor.DOM.selection.createRange();
  	if (value == 'RemoveHtml'){
    	if(confirm("Are you sure? This option is useful for cleaning up word docs")){
      		wordclean(sName)
    	}
  	}
  	else if (value == 'RemoveStyle'){
 		if(aEditors[sName].currentElement.parentNode && aEditors[sName].currentElement.outerHTML == aEditors[sName].currentElement.parentNode.innerHTML && aEditors[sName].currentElement.parentNode.className)
 			aEditors[sName].currentElement.parentNode.removeAttribute('className')
 		else
    		aEditors[sName].currentElement.removeAttribute('className')
	}
	else if ((a.text == aEditors[sName].currentElement.innerText) && (aEditors[sName].currentElement.tagName != 'BODY')) {
		aEditors[sName].currentElement.className = value;
  	}
  	else {
  		var selection;
		selection = aEditors[sName].cbEditor.DOM.selection.createRange();
		
		if(value == '') {
			selection.pasteHTML(selection.text);
		}
		else {
			if(selection.htmlText.length > 0) {
				var sNewText = '<span class="'+value+'">' + selection.htmlText + '</span>';
				selection.pasteHTML(sNewText);
			}
		}
    }

   setselection(sName);
}

function insertHTMLDirect(sName, stHTML) {
	selection = aEditors[sName].cbEditor.DOM.selection.createRange();
	selection.pasteHTML(stHTML);
}

function real_image(sName, arr) {
  selection = aEditors[sName].cbEditor.DOM.selection.createRange();
  selection.pasteHTML(arr);

  aEditors[sName].cbEditor.focus();
}

function real_file(sName, arr) {
  aEditors[sName].cbEditor.ExecCommand(DECMD_HYPERLINK,OLECMDEXECOPT_DONTPROMPTUSER,arr);
  aEditors[sName].cbEditor.focus();
}

function real_object(sName, arr) {
  aEditors[sName].cbEditor.ExecCommand(DECMD_HYPERLINK,OLECMDEXECOPT_DONTPROMPTUSER,arr);
  aEditors[sName].cbEditor.focus();
}

function pasteIT(sName, left,right){
	var selection;
	selection = aEditors[sName].cbEditor.DOM.selection.createRange();
	selection.pasteHTML(left+selection.text+right);
}

function evSetState(sName, ele,state){
	
	if (state == 'gray'){
		ele.style.filter = "alpha(opacity=25)";
		ele.style.cursor = "default";
	} else
		ele.style.filter = "";
	
	if (state == 'unchecked')
		ele.className = 'button'
	if (state == 'checked')
		ele.className = 'buttonChecked'
}

function evItem(command, element) {
  this.command = command;
  this.element = element;
}

function imagePanelSrcInit(sName) {
	eval("aEditors[sName].fm.IPalt" + sName + ".value = aEditors[sName].currentElement.alt;");
	eval("aEditors[sName].fm.IPsrc" + sName + ".value = aEditors[sName].currentElement.src;");
}

function imageTableInit(sName){
	if(aEditors[sName].currentElement.style.width) {
		eval("aEditors[sName].fm.TBwidth" + sName + ".value = aEditors[sName].currentElement.style.width;");
	}
	else {
		eval("aEditors[sName].fm.TBwidth" + sName + ".value = aEditors[sName].currentElement.width;");
	}
	if(aEditors[sName].currentElement.style.height)
		eval("aEditors[sName].fm.TBheight" + sName + ".value = aEditors[sName].currentElement.style.height;");
	else
		eval("aEditors[sName].fm.TBheight" + sName + ".value = aEditors[sName].currentElement.height;");
	
	eval("aEditors[sName].fm.TBborder" + sName + ".value = aEditors[sName].currentElement.border;");
	eval("aEditors[sName].fm.TBcellSpacing" + sName + ".value = aEditors[sName].currentElement.cellSpacing;");
	eval("aEditors[sName].fm.TBcellPadding" + sName + ".value = aEditors[sName].currentElement.cellPadding;");
}

function imageTDInit(sName){
	eval("aEditors[sName].fm.TDvalign" + sName + ".value =aEditors[sName].currentElement.vAlign;");
}

function setImage(sName, attr,fmele){
	if (event.keyCode == 13){
		aEditors[sName].currentElement[attr] = fmele.value
	} if (window.event.type == 'change'){
		aEditors[sName].currentElement[attr] = fmele.value
	}
	fmele.focus()
}
function setStyle(sName, attr,fmele){
	if (event.keyCode == 13){
	if(fmele.value){
		aEditors[sName].currentElement.style[attr] = fmele.value
		aEditors[sName].currentElement[attr] = fmele.value
	} else{
		aEditors[sName].currentElement.style[attr] = null
		aEditors[sName].currentElement[attr] = ''
	}
	} if (window.event.type == 'change'){
		aEditors[sName].currentElement.style[attr] = fmele.value
	}
	fmele.focus()
}

function ContentHide(sName, theLayer){
	if(init){
		if((theLayer == 'Content')||(theLayer == 'content')){
			if(!aEditors[sName].showing)
				aEditors[sName].cbEditor.style.visibility='visible'
			if(aEditors[sName].currentPanel)
				aEditors[sName].currentPanel.style.visibility='visible'
			if(aEditors[sName].secondPanel)
				aEditors[sName].secondPanel.style.visibility='visible'
		} else {
			if(!aEditors[sName].showing)
				aEditors[sName].cbEditor.style.visibility='hidden'
			if(aEditors[sName].currentPanel)
				aEditors[sName].currentPanel.style.visibility='hidden'
			if(aEditors[sName].secondPanel)
				aEditors[sName].secondPanel.style.visibility='hidden'
		}
	}
}

