// #####################################################################3
//		COMMAND ID's & GLOBALS REQUIRED
// #####################################################################3

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
//
// Enums
//

// 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

//Button groups for toolbar
var BTN_TYPE_STANDARD = 0
var BTN_TYPE_PRESENTATION = 1
var BTN_TYPE_SRC = 2
var BTN_TYPE_TABLE = 3
var BTN_TYPE_INPUT = 4
var BTN_TYPE_DROPDOWN = 5

//Button Array Indexes
//ImageURL, Name, function, type,status, width, CMDID
var BTN_PROP_IMGURL = 0
var BTN_PROP_TITLE = 1
var BTN_PROP_FUNC = 2
var BTN_PROP_TYPE = 3
var BTN_PROP_DEFSTATUS = 4
var BTN_PROP_WIDTH = 5
var BTN_PROP_CMDID = 6

var intEditorCount = 0;		//Global to track object creation count


// #####################################################################3
//		OBJECT CONSTRUCTOR
// #####################################################################3

// HTMLEditor
//
// DESC		:	Object Constructor
function HTMLEditor(strFormElName, strW, strH, strDefaultCont, strURL, intLimit, blIncSRC, blIncTable, strCSSURL, strWidthOffSet, strHeightOffSet){
	
	intEditorCount += 1;
	
	this.CtrlRef = "HTMLEditor"+intEditorCount;	// reference to HTML ID of AX Control
	this.height = strH;							// control height
	this.width = strW;							// control width
	this.HTMLContent = strDefaultCont;			// default HTML String
	this.UrlDir = strURL;				// CSS URL for editor.
	this.ImgDir = "../Images/edit_toolbar/";
	this.FormElName = strFormElName;
	
	this.IncSRC = blIncSRC;
	this.IncTable = blIncTable;
	this.CharLimit = intLimit;
	
	this.stylesheet = strCSSURL;
	
	//assign last
	this.ToolbarBtns = this.ToolbarButtonArray();
	
	//if (strWidthOffSet != "")
		//this.width = Number(window.screen.width) - Number(strWidthOffSet);
		
	if (strHeightOffSet != "")	
		this.height = Number(window.screen.height) - Number(strHeightOffSet);
	
}

// HTMLEditor.prototype.ReturnCtrlRef
//
// Returns the CtrlRef Object
HTMLEditor.prototype.ReturnCtrlRef = function(){

	return this.CtrlRef;

}

// HTMLEditor.prototype.Draw
//
// DESC		:	Puts ActiveX Control on screen
HTMLEditor.prototype.Draw = function(){
	
	//Event Handlers for the control..
	
	document.write(""+
		"<input type=\"hidden\" name=\"EditorCtrlRef\" value=\""+ this.CtrlRef +"\">"+
		"<script LANGUAGE=\"javascript\" FOR=\""+this.CtrlRef+"\" EVENT=\"DisplayChanged\">"+
		"<!--\n"+
		"return EditorDisplayChanged('"+this.CtrlRef+"')\n"+
		"//-->\n"+
		"</scr"+"ipt>"+
		"<script LANGUAGE=\"javascript\" FOR=\""+this.CtrlRef+"\" EVENT=\"ShowContextMenu\">\n"+
		"<!--\n"+
		"return ShowContextMenu('"+this.CtrlRef+"')\n"+
		"//-->\n"+
		"</scr"+"ipt>"+
		"<script LANGUAGE=\"javascript\" FOR=\""+this.CtrlRef+"\" EVENT=\"ContextMenuAction(itemIndex)\">\n"+
		"<!--\n"+
		"return ContextMenuAction(itemIndex, '"+this.CtrlRef+"')\n"+
		"//-->\n"+
		"</scr"+"ipt>");
		
	//toolbar HTML
	this.ToolBar();
		
	//write Active X control with set properties
	document.write("<br><OBJECT classid=\"clsid:2D360201-FFF5-11d1-8D03-00A0C959BC0A\" defval='"+this.CharLimit+"' ID="+this.CtrlRef+" height="+this.height+" width="+this.width+" VIEWASTEXT>"+
		"	<PARAM name=Scrollbars value=true>"+
		"	<PARAM name=UseDivOnCarriageReturn value=true>"+
		"	<PARAM name=SourceCodePreservation value=true>"+
		"	<PARAM name=ScrollbarAppearance value=1>"+
		"	<PARAM name=Appearance value=1>"+
		"	<PARAM name=ActivateApplets value=false>"+
		"	<PARAM name=ActivateActiveXControls value=false>"+
		"	<PARAM name=ShowBorders value=true>"+
		"</OBJECT>"+
		"<object style=\"display:none\" ID=\""+this.CtrlRef+"ObjTableInfo\" CLASSID=\"clsid:47B0DFC7-B7A3-11D1-ADC5-006008A5848C\" VIEWASTEXT>"+
		"</object>"+
		"<TEXTAREA Name='"+this.FormElName+"' ID=TXT"+this.CtrlRef+" style='display:none;width:"+(this.width)+";height:"+(this.height)+"px;'></TEXTAREA>");
			
	//initialise Screen Editor with defaults and Content
	this.InitEditor();
}

HTMLEditor.prototype.GiveFocus = function(){

	if (eval("document.all."+this.CtrlRef).style.display == "none")
		eval("document.all.TXT"+this.CtrlRef).focus();
	else
		eval(this.CtrlRef).focus();
}

// HTMLEditor.prototype.InitEditor
//
// DESC		:	Creates Header HTML with CSS Reference for the editor
HTMLEditor.prototype.InitEditor = function(){
	// Stylesheet info to control initial presentation for user
	var sHeaderInfo = ""
	+ "<HTML>"
	+ "	<HEAD>"
	+ "		<LINK rel='stylesheet' type='text/css' href='"+this.stylesheet+"'>"
	+ "	</HEAD>"
	+ "	<BODY ID=DHTMLEditBody leftmargin=4 topmargin=4>"
	+ this.HTMLContent
	+ "</BODY>"
	+ "</HTML>";
	var DHTMLCtrl = eval("document.all."+this.CtrlRef);
	
	//loads default HTML string
	DHTMLCtrl.DocumentHTML = sHeaderInfo;
	
	// have to store toolbar button array as property of the control, so window 
	// callbacks can access data
	DHTMLCtrl.toolbarArray = this.ToolbarBtns;
	
	//right click menu arrays also stored as control properties
	DHTMLCtrl.ContextMenu = new Array();
	DHTMLCtrl.GeneralContextMenu = new Array();
	DHTMLCtrl.TableContextMenu = new Array();
	
	DHTMLCtrl.GeneralContextMenu[0] = new ContextMenuItem("Cut", DECMD_CUT);
	DHTMLCtrl.GeneralContextMenu[1] = new ContextMenuItem("Copy", DECMD_COPY);
	DHTMLCtrl.GeneralContextMenu[2] = new ContextMenuItem("Paste", DECMD_PASTE);
	DHTMLCtrl.GeneralContextMenu[3] = new ContextMenuItem("", 0);
	DHTMLCtrl.GeneralContextMenu[4] = new ContextMenuItem("Select All", DECMD_SELECTALL);
	DHTMLCtrl.GeneralContextMenu[5] = new ContextMenuItem("", 0);
	DHTMLCtrl.GeneralContextMenu[6] = new ContextMenuItem("Insert Table", DECMD_INSERTTABLE);
	
	
	DHTMLCtrl.TableContextMenu[0] = new ContextMenuItem("", 0);
	DHTMLCtrl.TableContextMenu[1] = new ContextMenuItem("Insert Row", DECMD_INSERTROW);
	DHTMLCtrl.TableContextMenu[2] = new ContextMenuItem("Delete Rows", DECMD_DELETEROWS);
	DHTMLCtrl.TableContextMenu[3] = new ContextMenuItem("", 0);
	DHTMLCtrl.TableContextMenu[4] = new ContextMenuItem("Insert Column", DECMD_INSERTCOL);
	DHTMLCtrl.TableContextMenu[5] = new ContextMenuItem("Delete Columns", DECMD_DELETECOLS);
	DHTMLCtrl.TableContextMenu[6] = new ContextMenuItem("", 0);
	DHTMLCtrl.TableContextMenu[7] = new ContextMenuItem("Insert Cell", DECMD_INSERTCELL);
	DHTMLCtrl.TableContextMenu[8] = new ContextMenuItem("Delete Cells", DECMD_DELETECELLS);
	DHTMLCtrl.TableContextMenu[9] = new ContextMenuItem("Merge Cells", DECMD_MERGECELLS);
	DHTMLCtrl.TableContextMenu[10] = new ContextMenuItem("Split Cell", DECMD_SPLITCELL);
}

// #####################################################################3
//		TOOL BAR ARRAY
// #####################################################################3

// HTMLEditor.prototype.ToolbarButtonArray
//
// DESC		:	Creates Array of toolbar controls with relevant parameters
HTMLEditor.prototype.ToolbarButtonArray = function(){

	TbarBtns = new Array();
	
	//ImageURL, Name, function, type, status, width, CMDID
	pushItem(TbarBtns, new Array("p.gif", "Paragraph", "if (!this.disabled){"+ this.CtrlRef+".ExecCommand(DECMD_SETBLOCKFMT,OLECMDEXECOPT_DODEFAULT,'Normal');}",BTN_TYPE_STANDARD,true,"25","DECMD_SETBLOCKFMT"));
	pushItem(TbarBtns, new Array("h1.gif", "Heading 1", "if (!this.disabled){"+ this.CtrlRef+".ExecCommand(DECMD_SETBLOCKFMT,OLECMDEXECOPT_DODEFAULT,'Heading 1');}",BTN_TYPE_STANDARD,true,"25","DECMD_SETBLOCKFMT"));
	pushItem(TbarBtns, new Array("h2.gif", "Heading 2", "if (!this.disabled){"+ this.CtrlRef+".ExecCommand(DECMD_SETBLOCKFMT,OLECMDEXECOPT_DODEFAULT,'Heading 2');}",BTN_TYPE_STANDARD,true,"25","DECMD_SETBLOCKFMT"));
	pushItem(TbarBtns, new Array("h3.gif", "Heading 3", "if (!this.disabled){"+ this.CtrlRef+".ExecCommand(DECMD_SETBLOCKFMT,OLECMDEXECOPT_DODEFAULT,'Heading 3');}",BTN_TYPE_STANDARD,true,"25","DECMD_SETBLOCKFMT"));
	
	pushItem(TbarBtns, new Array("link.gif", "Insert HyperLink", "if (!this.disabled){createLink('"+ this.UrlDir +"','"+ this.FormElName +"','"+ this.CtrlRef +"');}", BTN_TYPE_STANDARD,true,"25","DECMD_HYPERLINK"));
	pushItem(TbarBtns, new Array("undo.gif", "Undo", "if (!this.disabled){"+ this.CtrlRef+".ExecCommand(DECMD_UNDO,OLECMDEXECOPT_DODEFAULT);}",BTN_TYPE_STANDARD,true,"25","DECMD_UNDO"));
	pushItem(TbarBtns, new Array("redo.gif", "Redo", "if (!this.disabled){"+ this.CtrlRef+".ExecCommand(DECMD_REDO,OLECMDEXECOPT_DODEFAULT);}",BTN_TYPE_STANDARD,true,"25","DECMD_REDO"));
	pushItem(TbarBtns, new Array("cut.gif", "Cut", "if (!this.disabled){"+ this.CtrlRef+".ExecCommand(DECMD_CUT,OLECMDEXECOPT_DODEFAULT);}", BTN_TYPE_STANDARD,true,"25","DECMD_CUT"));
	pushItem(TbarBtns, new Array("copy.gif", "Copy", "if (!this.disabled){"+ this.CtrlRef+".ExecCommand(DECMD_COPY,OLECMDEXECOPT_DODEFAULT);}", BTN_TYPE_STANDARD,true,"25","DECMD_COPY"));
	pushItem(TbarBtns, new Array("paste.gif", "Paste", "if (!this.disabled){"+ this.CtrlRef+".ExecCommand(DECMD_PASTE,OLECMDEXECOPT_DODEFAULT);"+this.CtrlRef+".Refresh();"+this.CtrlRef+".focus();}", BTN_TYPE_STANDARD,true,"25","DECMD_PASTE"));

	//Presentation
	pushItem(TbarBtns, new Array("bold.gif","Bold","if (!this.disabled){"+ this.CtrlRef+".ExecCommand(DECMD_BOLD,OLECMDEXECOPT_DODEFAULT);}",BTN_TYPE_PRESENTATION,true,"25","DECMD_BOLD"));
	pushItem(TbarBtns, new Array("italic.gif","Italic","if (!this.disabled){"+ this.CtrlRef+".ExecCommand(DECMD_ITALIC,OLECMDEXECOPT_DODEFAULT);}",BTN_TYPE_PRESENTATION,true,"25","DECMD_ITALIC"));
	pushItem(TbarBtns, new Array("under.gif","Underline","if (!this.disabled){"+ this.CtrlRef+".ExecCommand(DECMD_UNDERLINE,OLECMDEXECOPT_DODEFAULT);}",BTN_TYPE_PRESENTATION,true,"25","DECMD_UNDERLINE"));
	pushItem(TbarBtns, new Array("inindent.gif","Indent","if (!this.disabled){"+ this.CtrlRef+".ExecCommand(DECMD_INDENT,OLECMDEXECOPT_DODEFAULT);}",BTN_TYPE_PRESENTATION,true,"25","DECMD_INDENT"));
	pushItem(TbarBtns, new Array("deindent.gif","De-Indent","if (!this.disabled){"+ this.CtrlRef+".ExecCommand(DECMD_OUTDENT,OLECMDEXECOPT_DODEFAULT);}",BTN_TYPE_PRESENTATION,true,"25","DECMD_OUTDENT"));
	pushItem(TbarBtns, new Array("left.gif","Align Left","if (!this.disabled){LeftText(this,'"+ this.CtrlRef+"');}",BTN_TYPE_PRESENTATION,true,"25","DECMD_JUSTIFYLEFT"));
	pushItem(TbarBtns, new Array("center.gif","Align Center","if (!this.disabled){CenterText(this,'"+ this.CtrlRef+"');}",BTN_TYPE_PRESENTATION,true,"25","DECMD_JUSTIFYCENTER"));
	pushItem(TbarBtns, new Array("right.gif","Align Right","if (!this.disabled){RightText(this,'"+ this.CtrlRef+"');}",BTN_TYPE_PRESENTATION,true,"25","DECMD_JUSTIFYRIGHT"));
	pushItem(TbarBtns, new Array("numlist.gif","Numbered List","if (!this.disabled){"+ this.CtrlRef+".ExecCommand(DECMD_ORDERLIST,OLECMDEXECOPT_DODEFAULT);}",BTN_TYPE_PRESENTATION,true,"25","DECMD_ORDERLIST"));
	pushItem(TbarBtns, new Array("bullist.gif","Bulletted List","if (!this.disabled){"+ this.CtrlRef+".ExecCommand(DECMD_UNORDERLIST,OLECMDEXECOPT_DODEFAULT);}",BTN_TYPE_PRESENTATION,true,"25","DECMD_UNORDERLIST"));
	pushItem(TbarBtns, new Array("fgcolor.gif","Foreground Color","if (!this.disabled){DisplayColorWindow('FG','"+this.CtrlRef+"');}",BTN_TYPE_STANDARD,true,"25","DECMD_SETFORECOLOR"));
	
	//Table
	pushItem(TbarBtns, new Array("instable.gif","Insert Table","if (!this.disabled){DisplayTableWindow('"+this.CtrlRef+"');}",BTN_TYPE_TABLE,true,"25","DECMD_INSERTTABLE"));
// Change back to this if errors are thrown	
//	pushItem(TbarBtns, new Array("insrow.gif","Insert Row","if (!this.disabled){InsertRow('"+ this.CtrlRef+"');}",BTN_TYPE_TABLE,true,"25","DECMD_INSERTROW"));
//	pushItem(TbarBtns, new Array("inscol.gif","Insert Column","if (!this.disabled){InsertColumn('"+ this.CtrlRef +"');}",BTN_TYPE_TABLE,true,"25","DECMD_INSERTCOL"));
//	pushItem(TbarBtns, new Array("inscell.gif","Insert Cell","if (!this.disabled){InsertCell('"+ this.CtrlRef+"');}",BTN_TYPE_TABLE,true,"25","DECMD_INSERTCELL"));
	pushItem(TbarBtns, new Array("insrow.gif","Insert Row","if (!this.disabled){"+ this.CtrlRef+".ExecCommand(DECMD_INSERTROW,OLECMDEXECOPT_DODEFAULT);}",BTN_TYPE_TABLE,true,"25","DECMD_INSERTROW"));
	pushItem(TbarBtns, new Array("inscol.gif","Insert Column","if (!this.disabled){"+ this.CtrlRef+".ExecCommand(DECMD_INSERTCOL,OLECMDEXECOPT_DODEFAULT);}",BTN_TYPE_TABLE,true,"25","DECMD_INSERTCOL"));
	pushItem(TbarBtns, new Array("inscell.gif","Insert Cell","if (!this.disabled){"+ this.CtrlRef+".ExecCommand(DECMD_INSERTCELL,OLECMDEXECOPT_DODEFAULT);}",BTN_TYPE_TABLE,true,"25","DECMD_INSERTCELL"));
	pushItem(TbarBtns, new Array("delcell.gif","Delete Cell","if (!this.disabled){DeleteCell('"+ this.CtrlRef+"');}",BTN_TYPE_TABLE,true,"25","DECMD_DELETECELLS"));
	pushItem(TbarBtns, new Array("delcol.gif","Delete Column","if (!this.disabled){DeleteColumn('"+ this.CtrlRef+"');}",BTN_TYPE_TABLE,true,"25","DECMD_DELETECOLS"));
	pushItem(TbarBtns, new Array("delrow.gif","Delete Row","if (!this.disabled){DeleteRow('"+ this.CtrlRef+"');}",BTN_TYPE_TABLE,true,"25","DECMD_DELETEROWS"));
	pushItem(TbarBtns, new Array("spltcell.gif","Split Cell","if (!this.disabled){"+ this.CtrlRef+".ExecCommand(DECMD_SPLITCELL,OLECMDEXECOPT_DODEFAULT);}",BTN_TYPE_TABLE,true,"25","DECMD_SPLITCELL"));
	pushItem(TbarBtns, new Array("mrgcell.gif","Merge Cells","if (!this.disabled){"+ this.CtrlRef+".ExecCommand(DECMD_MERGECELLS,OLECMDEXECOPT_DODEFAULT);}",BTN_TYPE_TABLE,true,"25","DECMD_MERGECELLS"));

	//special
	pushItem(TbarBtns, new Array("image.gif", "Insert Image", "if (!this.disabled){window.open('../CMS/GetImage.asp','_Images','width=550,height=500,toolbar=no,location=no,menubar=no,status=no,scrollbars=yes,resizable=yes');}", BTN_TYPE_STANDARD,true,"25","DECMD_IMAGE"));
	pushItem(TbarBtns, new Array("source.gif","HTML Source","if (!this.disabled){toggleView('"+this.CtrlRef+"');}",BTN_TYPE_SRC,true,"25",""));
	pushItem(TbarBtns, new Array("find.gif","Find Text in document","if (!this.disabled){"+ this.CtrlRef+".ExecCommand(DECMD_FINDTEXT,OLECMDEXECOPT_PROMPTUSER);}",BTN_TYPE_STANDARD,true,"25","DECMD_FINDTEXT"));
	pushItem(TbarBtns, new Array("borders.gif","Borders","if (!this.disabled){"+ this.CtrlRef+".ShowBorders = !"+this.CtrlRef+".ShowBorders;}",BTN_TYPE_STANDARD,true,"25",""));
	pushItem(TbarBtns, new Array("details.gif","Show Details","if (!this.disabled){"+this.CtrlRef+".ShowDetails = !"+this.CtrlRef+".ShowDetails;}",BTN_TYPE_STANDARD,true,"25",""));
	pushItem(TbarBtns, new Array("remove_formatting.gif","Format","HTMLFormat('"+this.CtrlRef+"');",BTN_TYPE_STANDARD,true,"25",""));

//	pushItem(TbarBtns, new Array("anchor.gif","Bookmark","if (!this.disabled){CreateAnchor('"+ this.UrlDir +"','"+this.CtrlRef+"');}",BTN_TYPE_STANDARD,true,"25",""));

	pushItem(TbarBtns, new Array("props.gif","Properties","if (!this.disabled){GetProperties('"+this.CtrlRef+"');}",BTN_TYPE_STANDARD,true,"25",""));

	strLimit = "Limit: <SPAN ID=LIMIT"+this.CtrlRef+" class=inputtext defval='"+this.CharLimit+"' style='width:30px'>"+this.CharLimit+"</SPAN>"
	//pushItem(TbarBtns, new Array(strLimit,"","",BTN_TYPE_INPUT,true,"60",""));
	
	return TbarBtns;
}

//push function - not reliant on script engine v5.5 push()
function pushItem(array, item){
	array[array.length] = item;
}

// HTMLEditor.prototype.ToolBar
//
// DESC		:	Creates Toolbar to manipulate editor
HTMLEditor.prototype.ToolBar = function(){
	//buttonwidth
	var intButtonWidth = this.width;
	
	//..build toolbar
	strTBar = "<DIV >"
	strTBar += "<TABLE ondragstart=\"return false;\" class=tbar WIDTH='"+this.width+"' onmouseup=\"tbarhilite('u');\" onmousedown=\"tbarhilite('d');\" onmouseout=\"tbarhilite('o');\" onmouseover=\"tbarhilite('v');\" onselectstart=\"return false\" CELLPADDING=0 CELLSPACING=0 BORDER=0>";
	strTBar += "<TR><TD>";
	
	//reset btn count
	var intBtnCount = 0;

	//loop through all buttons
	for (i=0;i<this.ToolbarBtns.length;i++){
		//include all buttons by default
		var blIncludeBtn = true;
		
		//examine button types...
		switch (this.ToolbarBtns[i][BTN_PROP_TYPE]){
			case BTN_TYPE_SRC:	//HTML Source buttons...
				if(!this.IncSRC){	//Omit if set
					blIncludeBtn = false;
				}
				break;
			case BTN_TYPE_TABLE:
				if(!this.IncTable){	//Table creation/editing
					blIncludeBtn = false;	//Omit if set
				}
				break;
			default:
				//include all others by default
				break;
		}
		
		if(this.ToolbarBtns[i][BTN_PROP_TYPE] == BTN_TYPE_INPUT && this.CharLimit == ""){
			blIncludeBtn = false;	//Omit if set
		}
				
		//if button has not been excluded...
		if (blIncludeBtn){
			intBtnCount += parseInt(this.ToolbarBtns[i][BTN_PROP_WIDTH]);	//increase button row count
			strTBar += "" //+ intBtnCount

			if (intBtnCount > intButtonWidth){	//if we have filled row...
				strTBar += "</TD></TR><TR><TD>";	//..start another
				intBtnCount = parseInt(this.ToolbarBtns[i][BTN_PROP_WIDTH]);	//reset button count
			}
						
			strTBar += "<IMG align=absmiddle "
			strTBar += "ID='"+this.CtrlRef+ "_" + String(i) +"'";
			strTBar += " width=23 height=22 onclick=\""+this.ToolbarBtns[i][BTN_PROP_FUNC]+"\" TITLE='"+this.ToolbarBtns[i][BTN_PROP_TITLE]+"' SRC='"+this.ImgDir+this.ToolbarBtns[i][BTN_PROP_IMGURL]+"' class=tbarBtn>";
		}
	}
	
	//finish toolbar
	strTBar += "</TD></TR>";
	strTBar += "</TABLE></DIV>";
	
	//write to screen
	document.write(strTBar);
}

// #####################################################################3
//		EVENT HANDLERS
// #####################################################################3

//Updated Textarea when HTML Edit control changes
function EditorDisplayChanged(ctrlRef){

	ctrlHTML = eval("document.all."+ctrlRef);
	ctrlText = eval("document.all.TXT"+ctrlRef);
	ctrlLIMIT = eval("document.all.LIMIT"+ctrlRef);
	
	//as long as source view is off...
	if(ctrlText.style.display == "none"){
		if (ctrlHTML.Busy == false){
			//update TEXTAREA with HTML to keep form alive
			ctrlText.value = ctrlHTML.DOM.body.innerHTML;
			if (ctrlHTML.defval !== ""){
				ctrlLIMIT.innerHTML = ctrlLIMIT.defval - ctrlHTML.DOM.body.innerHTML.length;
		
				if(parseInt(ctrlLIMIT.innerHTML) < 0){
					ctrlHTML.ExecCommand(DECMD_UNDO,OLECMDEXECOPT_DODEFAULT);
				}
			}		
			ButtonStates(ctrlHTML);
		}
	}
}

// loops through toolbar controls and updates based on editor state
// this is a very time critical function - it executes every time a change
// is made in the editor
function ButtonStates(ctrlHTML) {
	var i, s, ImgRef, objSelected, objRange, intCheck;
	
	objSelected = ctrlHTML.DOM.selection;

	//loop for most of the buttons that have COMMAND ID's
	for (i=0; i < ctrlHTML.toolbarArray.length; i++) {
		if(ctrlHTML.toolbarArray[i][BTN_PROP_CMDID] !== ""){
			strCmd = ctrlHTML.toolbarArray[i][BTN_PROP_CMDID];
			intCmd = eval(strCmd);
			s = ctrlHTML.QueryStatus(intCmd);
			
			var ImgRef = eval("document.all."+ctrlHTML.id + "_" + String(i));

			if (typeof(ImgRef.style) == "object")
			{	
				if (s == DECMDF_DISABLED || s == DECMDF_NOTSUPPORTED) {
					ImgRef.className = "tbarBtn";
					ImgRef.style.filter = "alpha(opacity=25)";
					ImgRef.disabled = true;
				} else if (s == DECMDF_ENABLED  || s == DECMDF_NINCHED) {
					ImgRef.className = "tbarBtn";
					ImgRef.style.filter = "";
					ImgRef.disabled = false;
				} else { // DECMDF_LATCHED
					ImgRef.className = "tbarBtnSelected";
					ImgRef.style.filter = "";
					ImgRef.disabled = false;
				}
			}	
		}
		else
		{
			ImgRef = eval("document.all."+ctrlHTML.id + "_" + String(i));
			
			if (typeof(ImgRef.style) == "object")
			{
				intCheck = 0;
				
				if (ctrlHTML.toolbarArray[i][1] == "Bookmark")
				{
					if (objSelected.type.toLowerCase() == "control")
					{
						objRange = objSelected.createRange();
						
						if (objRange.length == 1)
						{
							if (objRange(0).tagName.toLowerCase() == "img")
							{
								if (objRange(0).src.toLowerCase().indexOf("secure/images/edit_toolbar/sml_anchor.gif") > 1)
								{
									intCheck = 2;
								}
								else
								{
									intCheck = 1;
								}
							}
							else
							{
								intCheck = 1;
							}
						}
						else
						{
							intCheck = 1;
						}	
					}
				}
				else if (ctrlHTML.toolbarArray[i][1] == "Properties")
				{
					if (objSelected.type.toLowerCase() != "control")
					{
						intCheck = 1;
					}
				}
				else if (objSelected.type.toLowerCase() == "control")
				{
					intCheck = 1;
				}
				
				
				if (intCheck == 1)					
				{
					ImgRef.className = "tbarBtn";
					ImgRef.style.filter = "alpha(opacity=25)";
					ImgRef.disabled = true;
				}
				else if (intCheck == 2)
				{
					ImgRef.className = "tbarBtnSelected";
					ImgRef.style.filter = "";
					ImgRef.disabled = false;
				}
				else
				{
					ImgRef.className = "tbarBtn";
					ImgRef.style.filter = "";
					ImgRef.disabled = false;
				}
				
			}
		}
	}
}

//toolbar presentation function
function tbarhilite(ev){
	var el=window.event.srcElement;
	if(el.tagName=="IMG"){
		if (el.disabled !== true){
			if (el.className !== "tbarBtnSelected"){
				switch(ev){
					case "o":el.className="tbarBtn";break;
					case "u":el.className="tbarBtnOutset";break;
					case "v":el.className="tbarBtnOutset";break;
					case "d":el.className="tbarBtnInset";break;
				}
			}
		}
	}
}


// called by the toolbar to create a table for insertion in the editor.
// the entire window content is generated from this function, there is no extra HTML file.
function DisplayTableWindow(ctrlref){
	strOP = "<HTML><HEAD><TITLE>Create Table</TITLE>"+
	"<STYLE>.txt{width:50px;}.txt2{width:70px;}TD{font-size:8pt;letter-spacing:-0.5pt}INPUT{border:solid 1px;font-family:verdana;font-size:8pt;letter-spacing:-0.5pt}</STYLE>"+
	"</HEAD><BODY bgcolor=buttonface topmargin=2 leftmargin=2 style='border:none;font-family:verdana;font-size:8pt;letter-spacing:-0.5pt' onBlur='window.document.focus();'>"+
	"<SCRIPT LANGUAGE=javascript>\n"+
	"<!--\n"+
	"function ValidateTable(){\n"+
	"	if (isNaN(parseInt(PAD.value))){alert(\"Cell Padding value not valid\");return false;}\n"+
	"	if (isNaN(parseInt(SPC.value))){alert(\"Cell Spacing value not valid\");return false;}\n"+
	"	if (isNaN(parseInt(BRD.value))){alert(\"Border value not valid\");return false;}\n"+
	"	if (isNaN(parseInt(ROW.value))){alert(\"Rows value not valid\");return false;}\n"+
	"	if (isNaN(parseInt(COL.value))){alert(\"Columns value not valid\");return false;}\n"+
	"	if (isNaN(parseInt(WID.value.replace(/%/,'%')))){alert(\"Width value not valid\");return false;}\n"+
	"	window.opener.InsertTable(PAD.value,SPC.value,BRD.value,ROW.value,COL.value,WID.value,TableAlign[TableAlign.selectedIndex].value,'"+ctrlref+"',window);\n"+
	"}\n"+

	"//-->\n"+
	"</SC"+"RIPT><TABLE>"+
	"<TR><TD>Cell Padding : </TD><TD><INPUT class=txt VALUE=1 TYPE=TEXT ID=PAD></TD></TR>"+
	"<TR><TD>Cell Spacing : </TD><TD><INPUT class=txt VALUE=0 TYPE=TEXT ID=SPC></TD></TR>"+
	"<TR><TD>Border : </TD><TD><INPUT class=txt VALUE=0 TYPE=TEXT ID=BRD></TD></TR>"+
	"<TR><TD>Rows : </TD><TD><INPUT class=txt VALUE=2 TYPE=TEXT ID=ROW></TD></TR>"+
	"<TR><TD>Columns : </TD><TD><INPUT class=txt VALUE=3 TYPE=TEXT ID=COL></TD></TR>"+
	"<TR><TD>Width : </TD><TD><INPUT class=txt VALUE='100%' TYPE=TEXT ID=WID></TD></TR>"+
	"<TR><TD>Align : </TD><TD><select name=TableAlign class=txt2>"+
	"  <option value='' selected>Default</option>"+
	"  <option value='left'>Left</option>"+
	"  <option value='center'>Center</option>"+
	"  <option value='right'>Right</option>"+
	"</select></TD></TR>"+
	"<TR><TD></TD><TD><br><br>"+
	"<INPUT onclick=\"ValidateTable();\" TYPE=BUTTON VALUE=\"Insert Table\" id=BUTTON1 name=BUTTON1></TD></TR>"+
	"</TABLE></BODY></HTML>"

	var mywin = window.open("about:blank", "wincolor", "width=250,height=205,toolbar=no,location=no,menubar=no,status=no,scrollbars=no,resizable=no");
	var myDoc = mywin.document;
	myDoc.open("text/html");
	myDoc.write(strOP);
	myDoc.close();
	myDoc.title = "Create Table";

}

// Uses ObjTableInfo ActiveX control to create a table object - doesn't seem
// to do anything except build the table HTML string from the values provided,
// which is obvioucly easy to do. The one thing it does do of use is to insert
// the table in the right place - I could find no documentation on this AX control
function InsertTable(strPad,strSpace,strBord,strRows,strCols,strWid,strAlign,ctrlRef,winRef) {
	
	winRef.close();
	
	var objTable, objTableRow, objTableCell, objCtrlRef, objSelected, objRange;
	
	objTable = document.createElement("TABLE");
	
	objTable.cellPadding = strPad;
	objTable.cellSpacing = strSpace;
	objTable.border = strBord;
	objTable.width = strWid;
	
	for (i=0; i<Number(strRows); ++i)
	{
		objTableRow = objTable.insertRow();
	
		for (x=0; x<Number(strCols); ++x)
		{
			objTableCell = objTableRow.insertCell();
			
			objTableCell.innerHTML = "<p>&nbsp;</p>";
		}
	}
	
	objCtrlRef = eval("document.all."+ctrlRef);
	objSelected = objCtrlRef.DOM.selection;
	objRange = objSelected.createRange();
	
	objRange.pasteHTML(objTable.outerHTML);
	
	return;
	
	//The next section is left over from the
	//original CMS
	var objTable = eval("document.all."+ctrlRef+"ObjTableInfo");
	var objCtrlRef = eval("document.all."+ctrlRef);
	var tblAlign = "";
	
	if (strAlign != "")
		tblAlign = " align="+ strAlign;
	
	objTable.NumRows = strRows;
	objTable.NumCols = strCols;
	objTable.TableAttrs = " border="+strBord+" cellspacing="+strSpace+" cellpadding="+strPad+" width="+ strWid + tblAlign +" ";
	objTable.CellAttrs = " valign=top ";
	
	objCtrlRef.ExecCommand(DECMD_INSERTTABLE,OLECMDEXECOPT_DODEFAULT, objTable); 
	
	var objSelected = objCtrlRef.DOM.selection;
	
	alert(objSelected.type);
	
	if (objSelected.type.toLowerCase() == "control")
	{
		var objRange = objSelected.createRange();
		
        if (objRange.length == 1)
		{
			var objCTL = objRange.item(0);
			
			alert(objCTL.tagName);
		
			if (objCTL.tagName.toLowerCase() == "table")
			{

			}
			
		}
		
	}					
}

// DisplayColorWindow
// 
// called by the toolbar to change the colour of text or background colors.
// the entire window content is generated from this function, there is no extra HTML file.
function DisplayColorWindow(mode,ctrlref){
    
	//mode : BG, FG
	var mywin = window.open("about:blank", "wincolor", "width=500,height=100,toolbar=no,location=no,menubar=no,status=no,scrollbars=no,resizable=no");
	var myDoc = mywin.document;

	//color table
	colors = new Array('0','3','6','9','C','F');

	strColorTable = "<TABLE onclick='assign();' onmouseover='toggleClass();' onmouseout='toggleClass();' WIDTH=100% CELLPADDING=0 CELLSPACING=0 BORDER=0>"
	for(i=0;i<colors.length;i++){
		strColorTable += "<TR>"
		for(j=0;j<colors.length;j++){
			for(k=0;k<colors.length;k++){
				strColorTable += "<TD class=col bgcolor=#"+colors[k]+colors[k]+colors[i]+colors[i]+colors[j]+colors[j]+">&nbsp;</TD>"		
			}			
		}
		strColorTable += "</TR>"
	}
	strColorTable += "</TABLE>"
	
	
	myDoc.open("text/html");
	myDoc.write("<HTML><HEAD></HEAD>"+
	"<STYLE>TD{font-size:8pt;}.col{border:solid 1px buttonface;cursor:hand;}.colO{cursor:hand;border:solid 1px black;}</STYLE>"+
	"<SCRIPT>\n<!--\n"+
	"function toggleClass(){\n"+
	"	var el = window.event.srcElement;if(el.className=='col'){el.className='colO'}else if(el.className=='colO'){el.className='col'}\n"+
	"}\n"+
	"function assign(){\n"+
	"	var el = window.event.srcElement;if(el.className=='col'||el.className=='colO'){window.opener.SetColor('"+mode+"', el.bgColor, '"+ctrlref+"',window);}\n"+
	"}\n--></SCR"+"IPT></TABLE>"+
	"<BODY bgcolor=buttonface topmargin=2 leftmargin=2 style='border:none;font-family:verdana;font-size:8pt;letter-spacing:-0.5pt' onselectstart='return false'>"+
	strColorTable+
	"</BODY></HTML>");
	myDoc.close();

	if(mode == "FG"){
		myDoc.title = "Foreground Color - Click To Assign";
	} else if(mode == "BG"){
		myDoc.title = "Background Color - Click To Assign";
	} else {
		//do nothing
	}
	
}

// callback from color window, sets background/foreground color of
// selection
function SetColor(mode,color,ctrl,winRef){

	winRef.close();	//close popup
	
	var ctrlRef = eval("document.all."+ctrl);
		
	if (mode == "BG"){
		strCMD = DECMD_SETBACKCOLOR;
	} else if (mode == "FG"){
		strCMD = DECMD_SETFORECOLOR;
	} else{
		//not valid
	}
    ctrlRef.ExecCommand(strCMD,OLECMDEXECOPT_DODEFAULT, color);
}

//switched between HTML and Design View
function toggleView(ctrlRef){
	ctrlHTML = eval("document.all."+ctrlRef);
	ctrlText = eval("document.all.TXT"+ctrlRef);
	
	//display TEXTAREA
	if(ctrlText.style.display == "none"){
		
		ctrlText.style.display = "block";
		ctrlHTML.style.display = "none";
		
		//knock out all toolbar controls except source view
		for(var i=0;i < ctrlHTML.toolbarArray.length; i++) {
		
			var ImgRef = eval("document.all."+ctrlHTML.id+ "_"+ String(i));

			if (typeof(ImgRef.style) == "object")
			{
				if(ImgRef.title !== "HTML Source" && ImgRef.title !== "Format"){
					ImgRef.className = "tbarBtn"
					ImgRef.style.filter = "alpha(opacity=25)"
					ImgRef.disabled = true
				}
			}
		}
	
	// display OBJECT - this will call the displayChanged() event which will inturn 
	// reinstate the appropriate toolbar buttons
	} else {
		
		EditorDisplayChanged(ctrlRef);
		ctrlText.style.display = "none";
		ctrlHTML.DOM.body.innerHTML = ctrlText.value;
		ctrlHTML.style.display = "block";
		ctrlHTML.Appearance = 0;
	}
}

// #####################################################################3
//		CONTEXT MENUS
// #####################################################################3

// Constructor for custom object that represents an item on the context menu
function ContextMenuItem(string, cmdId) {
  this.string = string;
  this.cmdId = cmdId;
}

//item selected from right click menu
function ContextMenuAction(itemIndex, ctrlRef){
	
	var objCtrlRef = eval("document.all."+ctrlRef);
	
	if (objCtrlRef.ContextMenu[itemIndex].cmdId == DECMD_INSERTTABLE) {
		DisplayTableWindow(ctrlRef);
	} 
	else 
	{
		objCtrlRef.ExecCommand(objCtrlRef.ContextMenu[itemIndex].cmdId, OLECMDEXECOPT_DODEFAULT);
	}
}

// shows right click menu with various options 
// depending on what's clicked on and what state it is in
function ShowContextMenu(ctrlRef){
	var menuStrings = new Array();
	var menuStates = new Array();
	var state;
	var i;
	var idx = 0;

	var objCtrlRef = eval("document.all."+ctrlRef);

	// Rebuild the context menu. 
	objCtrlRef.ContextMenu.length = 0;

	// Always show general menu
	for (i=0; i<objCtrlRef.GeneralContextMenu.length; i++) {
		objCtrlRef.ContextMenu[idx++] = objCtrlRef.GeneralContextMenu[i];
	}

	// Is the selection inside a table? Add table menu if so
	if (objCtrlRef.QueryStatus(DECMD_INSERTROW) != DECMDF_DISABLED) {
		for (i=0; i<objCtrlRef.TableContextMenu.length; i++) {
			objCtrlRef.ContextMenu[idx++] = objCtrlRef.TableContextMenu[i];
		}
	}

	// Set up the actual arrays that get passed to SetContextMenu
	for (i=0; i<objCtrlRef.ContextMenu.length; i++) {
		menuStrings[i] = objCtrlRef.ContextMenu[i].string;
		if (menuStrings[i] != "") {
			if(objCtrlRef.ContextMenu[i].cmdId == "3FS") {
				state = DECMDF_ENABLED;
			} else {
				state = objCtrlRef.QueryStatus(objCtrlRef.ContextMenu[i].cmdId);
			}
		} else {
			state = DECMDF_ENABLED;
		}
		if (state == DECMDF_DISABLED || state == DECMDF_NOTSUPPORTED) {
			menuStates[i] = OLE_TRISTATE_GRAY;
		} else if (state == DECMDF_ENABLED || state == DECMDF_NINCHED) {
			menuStates[i] = OLE_TRISTATE_UNCHECKED;
		} else { // DECMDF_LATCHED
			menuStates[i] = OLE_TRISTATE_CHECKED;
		}
	}
  
	// Set the context menu
	objCtrlRef.SetContextMenu(menuStrings, menuStates);
}

function InsertRow(CtrlRef)
{
	var objCtrlRef = eval("document.all."+ CtrlRef);

	var objRange = objCtrlRef.DOM.selection.createRange();
	var tdTag = objRange.parentElement();
	var intLoopCounter = 0;
	
	while (tdTag.tagName.toLowerCase() != "td" && intLoopCounter < 50)
	{
		tdTag = tdTag.parentElement;
		
		intLoopCounter++;
	}
	
	if (intLoopCounter < 50)
	{
		var tblTag = tdTag.parentElement;
	
		while (tblTag.tagName.toLowerCase() != "table")
		{
			tblTag = tblTag.parentElement
		}

		var objTR = tblTag.insertRow(0);
		var objTD;
		
		for (i=0; i<tblTag.rows(1).cells.length; ++i)
		{
			objTD = objTR.insertCell();
			
			objTD.innerHTML = "<p>&nbsp;</p>";
		}
	}
}

function InsertColumn(CtrlRef)
{
	var objCtrlRef = eval("document.all."+ CtrlRef);

	var objRange = objCtrlRef.DOM.selection.createRange();
	var tdTag = objRange.parentElement();
	var intLoopCounter = 0;
	
	while (tdTag.tagName.toLowerCase() != "td" && intLoopCounter < 50)
	{
		tdTag = tdTag.parentElement;
		
		intLoopCounter++;
	}
	
	if (intLoopCounter < 50)
	{
		var tblTag = tdTag.parentElement;
		
		while (tblTag.tagName.toLowerCase() != "table")
		{
			tblTag = tblTag.parentElement
		}
		
		var objTD;
		
		for (i=0; i<tblTag.rows.length; ++i)
		{
			objTD = tblTag.rows(i).insertCell(tdTag.cellIndex);
			
			objTD.innerHTML = "<p>&nbsp;</p>";
		}	
	}
}

function InsertCell(CtrlRef)
{
	var objCtrlRef = eval("document.all."+ CtrlRef);

	var objRange = objCtrlRef.DOM.selection.createRange();
	var tdTag = objRange.parentElement();
	var intLoopCounter = 0;
	
	while (tdTag.tagName.toLowerCase() != "td" && intLoopCounter < 50)
	{
		tdTag = tdTag.parentElement;
		
		intLoopCounter++;
	}
	
	if (intLoopCounter < 50)
	{
		var trTag = tdTag.parentElement;
		
		while (trTag.tagName.toLowerCase() != "tr")
		{
			trTag = trTag.parentElement
		}
		
		
		var objTD = trTag.insertCell(tdTag.cellIndex + 1);
		
		objTD.innerHTML = "<p>&nbsp;</p>";		
	}
}

function DeleteCell(CtrlRef)
{
	var objCtrlRef = eval("document.all."+ CtrlRef);

	var objRange = objCtrlRef.DOM.selection.createRange();
	var tdTag = objRange.parentElement();
	var intLoopCounter = 0;
	
	while (tdTag.tagName.toLowerCase() != "td" && intLoopCounter < 50)
	{
		tdTag = tdTag.parentElement;
		
		intLoopCounter++;
	}
	
	if (intLoopCounter < 50)
	{
		var trTag = tdTag.parentElement;
		var tblTag = tdTag.parentElement;
		
		while (trTag.tagName.toLowerCase() != "tr")
		{
			trTag = trTag.parentElement
		}

		while (tblTag.tagName.toLowerCase() != "table")
		{
			tblTag = tblTag.parentElement
		}
		
		if (trTag.cells.length > 1 || tblTag.rows.length > 1)
		{
			objCtrlRef.ExecCommand(DECMD_DELETECELLS,OLECMDEXECOPT_DODEFAULT);
		}			
		else			
		{
			tblTag.removeNode(true);
		}
	}
}

function DeleteColumn(CtrlRef)
{
	var objCtrlRef = eval("document.all."+ CtrlRef);

	var objRange = objCtrlRef.DOM.selection.createRange();
	var tdTag = objRange.parentElement();
	var intLoopCounter = 0;
	
	while (tdTag.tagName.toLowerCase() != "td" && intLoopCounter < 50)
	{
		tdTag = tdTag.parentElement;
		
		intLoopCounter++;
	}
	
	if (intLoopCounter < 50)
	{
		var trTag = tdTag.parentElement;
	
		while (trTag.tagName.toLowerCase() != "tr")
		{
			trTag = trTag.parentElement
		}
		
		if (trTag.cells.length > 1)
		{
			objCtrlRef.ExecCommand(DECMD_DELETECOLS,OLECMDEXECOPT_DODEFAULT);
		}			
		else			
		{
			var tblTag = trTag.parentElement;
			
			while (tblTag.tagName.toLowerCase() != "table")
			{
				tblTag = tblTag.parentElement
			}

			tblTag.removeNode(true);
		}
	}
}

function DeleteRow(CtrlRef)
{
	var objCtrlRef = eval("document.all."+ CtrlRef);

	var objRange = objCtrlRef.DOM.selection.createRange();
	var tdTag = objRange.parentElement();
	var intLoopCounter = 0;
	
	while (tdTag.tagName.toLowerCase() != "td" && intLoopCounter < 50)
	{
		tdTag = tdTag.parentElement;
		
		intLoopCounter++;
	}
	
	if (intLoopCounter < 50)
	{
		var tblTag = tdTag.parentElement;
	
		while (tblTag.tagName.toLowerCase() != "table")
		{
			tblTag = tblTag.parentElement
		}
	
		if (tblTag.rows.length > 1)
		{
			objCtrlRef.ExecCommand(DECMD_DELETEROWS,OLECMDEXECOPT_DODEFAULT);
		}			
		else			
		{
			tblTag.removeNode(true);
		}
	}		
}

function createLink(strImgDir, strFormField, CtrlRef)
{
	var strHTML, arrAnchors1, strAnchors, arrAnchors2, strBuster

	strHTML = eval("document.all." + strFormField + ".value");
	
	arrAnchors1 = strHTML.split(" src=\"" + strImgDir + "secure/Images/edit_toolbar/sml_anchor.gif\"");
	
	strAnchors = "";
	
	for (i=0; i<(arrAnchors1.length - 1); ++i)
	{
		arrAnchors2 = arrAnchors1[i].split("<");
		
		strAnchors += arrAnchors2[arrAnchors2.length - 1].toLowerCase().replace(/img /, "").replace(/alt=/, "").replace(/\"/gi, "") + "-||-"; 	
	}
	
	strBuster = new Date();
	
	var processWin = window.showModelessDialog("../CMS/LinkCreator.asp?buster=" + escape(strBuster.toString()) + "&Anchors=" + escape(strAnchors), window, "dialogWidth: 500px; dialogHeight:450px; center:yes; status:no; scroll:yes");
	processWin.focus();
}

function Close_Window(obj, varCtrlRef)
{
	obj.close();
	
	eval(varCtrlRef+ ".Refresh();");
}

function HTMLFormat(ctrlRef)
{
	var boolToggle = false;
	var ctrlText = eval("document.all.TXT"+ctrlRef);

	if(ctrlText.style.display == "none")
	{
		toggleView(ctrlRef);
		boolToggle = true;
	}
	
	var obj = ctrlText;
	var strHTML = obj.value;
	var arrTags = strHTML.split("<");
	var Rules = new Array()
	var tmpArray, tmpArray2;
	var strTemp1, strTemp2, strTemp3, strTemp4, varTag;
	
	//Create an array for each rule, based on:
	//attribute Yes=1 / No=0
	//ExactName Yes=1 / No=0
	//Name String

	// Remove all span tags
	tmpArray = new Array(0, 1, "span");
	Rules.push(tmpArray);
	
	// Remove all div tags
	tmpArray = new Array(0, 1, "div");
	Rules.push(tmpArray);
	
	// Remove all font tags
	tmpArray = new Array(0, 1, "font");
	Rules.push(tmpArray);
	
	// Remove COLGROUP tags
	tmpArray = new Array(0, 1, "colgroup");
	Rules.push(tmpArray);
	
	// Remove COL tags
	tmpArray = new Array(0, 1, "col");
	Rules.push(tmpArray);
	
	// Remove all tags with colons following tag opening
	tmpArray = new Array(0, 0, ":");
	Rules.push(tmpArray);
	
	// Remove all class attributes
	tmpArray = new Array(1, 1, "class=");
	Rules.push(tmpArray);

	// Remove all style attributes
	tmpArray = new Array(1, 1, "style=");
	Rules.push(tmpArray);
	
	// Remove type attributes
	tmpArray = new Array(1, 1, "type=");
	Rules.push(tmpArray);
	
	// Remove height attributes
	tmpArray = new Array(1, 1, "height=");
	Rules.push(tmpArray);
	
	// Remove width attributes
	tmpArray = new Array(1, 1, "width=");
	Rules.push(tmpArray);
	
	// Remove attributes with colons
	tmpArray = new Array(1, 0, ":");
	Rules.push(tmpArray);
	
	strHTML = "";
	
	for (i=0; i<arrTags.length; ++i)
	{
		if (arrTags[i].indexOf(">") > -1)
		{
			tmpArray = arrTags[i].split(">");
			
			strTemp1 = tmpArray[0];
			strTemp2 = tmpArray[1];
			
			tmpArray = strTemp1.split(" ");
			
			strTemp3 = tmpArray[0];
			strTemp4 = "";
			
			for (y=1; y<tmpArray.length; ++y)
			{
				strTemp4 += " " + tmpArray[y];
			}	

			for (x=0; x<Rules.length; ++x)
			{
				if (Rules[x][0] == 0 && Rules[x][1] == 0 && strTemp3.toLowerCase().indexOf(Rules[x][2].toLowerCase()) > -1)
				{
					strHTML += strTemp2;
					
					break;
				}
				else if (Rules[x][0] == 0 && Rules[x][1] == 1 && (strTemp3.toLowerCase() == Rules[x][2].toLowerCase() || strTemp3.toLowerCase() == "/"+ Rules[x][2].toLowerCase()))
				{
					strHTML += strTemp2;
					
					break;
				}
				else if (Rules[x][0] == 1 && Rules[x][1] == 1 && strTemp4.toLowerCase().indexOf(" "+ Rules[x][2].toLowerCase()) > -1)
				{
					tmpArray = strTemp4.split(" "+ Rules[x][2].toLowerCase());
					
					strTemp4 = tmpArray[0];

					if (tmpArray[1].substr(0, 1) == "\"")
					{
						tmpArray2 = tmpArray[1].split("\"");

						for (y=2; y<tmpArray2.length; ++y)
						{
							if (y > 2)
								strTemp4 += 	"\"";
							
							strTemp4 += tmpArray2[y];												
						}
					}
					else
					{
						tmpArray2 = tmpArray[1].split(" ");

						for (y=1; y<tmpArray2.length; ++y)
						{
							strTemp4 += " " + tmpArray2[y];												
						}
					}
				}
				else if (Rules[x][0] == 1 && Rules[x][1] == 0 && strTemp4.toLowerCase().indexOf(Rules[x][2].toLowerCase()) > -1)
				{
				//<TD align=right x:num>
				//<TD align=right x>
				
					tmpArray = strTemp4.split(Rules[x][2].toLowerCase());
					
					if (tmpArray[1].indexOf("\"") > tmpArray[1].indexOf(" "))
					{
					//This attribute is specified inside quotes ("), i.e. style="width: 150px;"
						if (tmpArray[0].indexOf(" ") > -1)
						{
						//This attribute is not the first 1 starting from the left
							tmpArray2 = tmpArray[0].split(" ");
							
							strTemp4 = "";
							
							for (y=0; y<(tmpArray2.length-1); ++y)
							{
								if (y>0)
									strTemp4 += " ";
										
								strTemp4 += tmpArray2[y];
							}
							
							tmpArray2 = tmpArray[1].split("\"");	
							
							for (y=2; y<tmpArray2.length; ++y)
							{
								if (y>2)
									strTemp4 += "\"";
								
								strTemp4 += tmpArray2[y];
							}
						}	
						else
						{
						//This attribute is the first 1 starting from the left
							tmpArray2 = tmpArray[1].split("\"");	
							
							strTemp4 = "";

							for (y=2; y<tmpArray2.length; ++y)
							{
								if (y>2)
									strTemp4 += "\"";
								
								strTemp4 += tmpArray2[y];
							}
						}
					}
					else
					{
					//This attribute is not specified inside quotes ("), i.e. width=100

						if (tmpArray[1].indexOf(" ") > -1)
						{
						//This attribute is not the last attribute
							tmpArray2 = tmpArray[0].split(" ");
							
							strTemp4 = "";
							
							for (y=0; y<(tmpArray2.length-1); ++y)
							{
								if (y>0)
									strTemp4 += " ";
										
								strTemp4 += tmpArray2[y];
							}
							
							tmpArray2 = tmpArray[1].split(" ");	
							
							for (y=1; y<tmpArray2.length; ++y)
							{
								if (y>1)
									strTemp4 += " ";
								
								strTemp4 += tmpArray2[y];
							}
						}
						else
						{
						//This attribute is the last attribute
							tmpArray2 = tmpArray[0].split(" ");
							
							strTemp4 = "";
							
							for (y=0; y<(tmpArray2.length-1); ++y)
							{
								if (y>0)
									strTemp4 += " ";
										
								strTemp4 += tmpArray2[y];
							}
						}
					}
				}
			}
			
			if (x >= Rules.length && (strTemp1 != "" || strTemp2 != ""))
				strHTML += "<"+ strTemp3 + strTemp4 + ">"+ strTemp2;
				
		}		
	}	
	
	obj.value = strHTML;
	
	if(boolToggle)
		toggleView(ctrlRef);
}

function LeftText(obj, ctrlRef)
{
	var objMain = eval("document.all." + ctrlRef);
	
	if (obj.className == "tbarBtnSelected")
	{
		var objRange = objMain.DOM.selection.createRange();
		var pTag = objRange.parentElement()
		RemoveAlign(pTag);
	}
	else
	{
		objMain.ExecCommand(DECMD_JUSTIFYLEFT,OLECMDEXECOPT_DODEFAULT);
	}
}

function CenterText(obj, ctrlRef)
{
	var objMain = eval("document.all." + ctrlRef);
	
	if (obj.className == "tbarBtnSelected")
	{
		var objRange = objMain.DOM.selection.createRange();
		var pTag = objRange.parentElement()
		RemoveAlign(pTag);
	}
	else
	{
		objMain.ExecCommand(DECMD_JUSTIFYCENTER,OLECMDEXECOPT_DODEFAULT);
	}
}

function RightText(obj, ctrlRef)
{
	var objMain = eval("document.all." + ctrlRef);
	
	if (obj.className == "tbarBtnSelected")
	{
		var objRange = objMain.DOM.selection.createRange();
		var pTag = objRange.parentElement()
		RemoveAlign(pTag);
	}
	else
	{
		objMain.ExecCommand(DECMD_JUSTIFYRIGHT,OLECMDEXECOPT_DODEFAULT);
	}
}


function RemoveAlign(objTag)
{
	objTag.align = "";
}

function InsertStyle1(ctrlRef)
{
	var objMain = eval("document.all." + ctrlRef);
	var objSelected = objMain.DOM.selection;
	
	if (objSelected.type.toLowerCase() == "text")
	{
		var objRange = objSelected.createRange();

		objRange.pasteHTML("<font class=\"S1\">" + objRange.text + "</font>");
	}
}

function InsertStyle2(ctrlRef)
{
	var objMain = eval("document.all." + ctrlRef);
	var objSelected = objMain.DOM.selection;
	
	if (objSelected.type.toLowerCase() == "text")
	{
		var objRange = objSelected.createRange();

		objRange.pasteHTML("<font class=\"S2\">" + objRange.text + "</font>");
	}
}

function InsertStyle3(ctrlRef)
{
	var objMain = eval("document.all." + ctrlRef);
	var objSelected = objMain.DOM.selection;
	
	if (objSelected.type.toLowerCase() == "text")
	{
		var objRange = objSelected.createRange();

		objRange.pasteHTML("<font class=\"S3\">" + objRange.text + "</font>");
	}
}

function CreateAnchor(strImgDir, ctrlRef)
{
	var objMain = eval("document.all." + ctrlRef);
	var objSelected = objMain.DOM.selection;
	var objRange = objSelected.createRange();
	
	if (objSelected.type.toLowerCase() == "none" || objSelected.type.toLowerCase() == "text")
	{
		var strAnchorName = window.prompt("Please enter the Bookmark name:", "");

		if (strAnchorName != null)
		{
			if (strAnchorName.replace(/ /gi, "") == "")
				window.alert("No name has been entered!");
			else
				objRange.pasteHTML("<img alt=\"" + strAnchorName + "\" src=\"" + strImgDir + "secure/Images/edit_toolbar/sml_anchor.gif\">" + objRange.text);
		}			
	}
	else
	{
		objMain.ExecCommand(DECMD_DELETE);
	}
}

function GetProperties(ctrlRef)
{
	var objMain = eval("document.all." + ctrlRef);
	var objSelected = objMain.DOM.selection;
	
	if (objSelected.type.toLowerCase() == "control")
	{
		var objRange = objSelected.createRange();
		
        if (objRange.length == 1)
		{
			var objCTL = objRange.item(0);
		
			if (objCTL.tagName == "TABLE")
			{
				var strAlignL = "";
				var strAlignC = "";
				var strAlignR = "";
				
				if (objCTL.align == "left")
					strAlignL = " selected";
				else if (objCTL.align == "center")
					strAlignC = " selected";
				else if (objCTL.align == "right")
					strAlignR = " selected";
			
				strOP = "<HTML><HEAD><TITLE>Table Properties</TITLE>"+
				"<STYLE>.txt{width:50px;}.txt2{width:70px;}TD{font-size:8pt;letter-spacing:-0.5pt}INPUT{border:solid 1px;font-family:verdana;font-size:8pt;letter-spacing:-0.5pt}</STYLE>"+
				"</HEAD><BODY bgcolor=buttonface topmargin=2 leftmargin=2 style='border:none;font-family:verdana;font-size:8pt;letter-spacing:-0.5pt' onBlur='window.document.focus();'>"+
				"<SCRIPT LANGUAGE=javascript>\n"+
				"<!--\n"+
				"function ValidateTable(){\n"+
				"	if (isNaN(parseInt(PAD.value))){alert(\"Cell Padding value not valid\");return false;}\n"+
				"	if (isNaN(parseInt(SPC.value))){alert(\"Cell Spacing value not valid\");return false;}\n"+
				"	if (isNaN(parseInt(BRD.value))){alert(\"Border value not valid\");return false;}\n"+
				"	if (isNaN(parseInt(WID.value.replace(/%/,'%')))){alert(\"Width value not valid\");return false;}\n"+
				"	window.opener.UpdateTable(PAD.value,SPC.value,BRD.value,WID.value,TableAlign[TableAlign.selectedIndex].value,'"+ ctrlRef +"',window);\n"+
				"}\n"+
			
				"//-->\n"+
				"</SC"+"RIPT><TABLE>"+
				"<TR><TD>Cell Padding : </TD><TD><INPUT class=txt VALUE='"+ objCTL.cellPadding +"' TYPE=TEXT ID=PAD></TD></TR>"+
				"<TR><TD>Cell Spacing : </TD><TD><INPUT class=txt VALUE='"+ objCTL.cellSpacing +"' TYPE=TEXT ID=SPC></TD></TR>"+
				"<TR><TD>Border : </TD><TD><INPUT class=txt VALUE='"+ objCTL.border +"' TYPE=TEXT ID=BRD></TD></TR>"+
				"<TR><TD>Width : </TD><TD><INPUT class=txt VALUE='"+ objCTL.width +"' TYPE=TEXT ID=WID></TD></TR>"+
				"<TR><TD>Align : </TD><TD><select name=TableAlign class=txt2>"+
				"  <option value=''>Default</option>"+
				"  <option value='left'"+ strAlignL +">Left</option>"+
				"  <option value='center'"+ strAlignC +">Center</option>"+
				"  <option value='right'"+ strAlignR +">Right</option>"+
				"</select></TD></TR>"+
				"<TR><TD></TD><TD><br><br>"+
				"<INPUT onclick=\"ValidateTable();\" TYPE=BUTTON VALUE=\"Update Table\" id=BUTTON1 name=BUTTON1></TD></TR>"+
				"</TABLE></BODY></HTML>";

				var mywin = window.open("about:blank", "wincolor", "width=250,height=160,toolbar=no,location=no,menubar=no,status=no,scrollbars=no,resizable=no");
				var myDoc = mywin.document;
				myDoc.open("text/html");
				myDoc.write(strOP);
				myDoc.close();
				myDoc.title = "Table Properties";
			}
			else if (objCTL.tagName == "IMG")
			{
				if (objCTL.src.substr(objCTL.src.lastIndexOf("/") + 1).toLowerCase() == "sml_anchor.gif")
				{
					var strAnchorName = window.prompt("Please enter the Bookmark name:", objCTL.alt);
					
					if (strAnchorName != null)
						objCTL.alt = strAnchorName;
				}
				else
				{
					strOP = "<HTML><HEAD><TITLE>Image Properties</TITLE>"+
					"<STYLE>.txt{width:50px;}.txt2{width:70px;}TD{font-size:8pt;letter-spacing:-0.5pt}INPUT{border:solid 1px;font-family:verdana;font-size:8pt;letter-spacing:-0.5pt}</STYLE>"+
					"</HEAD><BODY bgcolor=buttonface topmargin=2 leftmargin=2 style='border:none;font-family:verdana;font-size:8pt;letter-spacing:-0.5pt' onBlur='window.document.focus();'>"+
					"<SCRIPT LANGUAGE=javascript>\n"+
					"<!--\n"+
					"function ValidateTable(){\n"+
					"	if (WID.value != ''){if (isNaN(parseInt(WID.value))){alert(\"Width value not valid\");return false;}}\n"+
					"	if (HEI.value != ''){if (isNaN(parseInt(HEI.value))){alert(\"Height value not valid\");return false;}}\n"+
					"	if (BOR.value != ''){if (isNaN(parseInt(BOR.value))){alert(\"Border value not valid\");return false;}}\n"+
					"	window.opener.ImageUpdate(WID.value,HEI.value,BOR.value,'"+ ctrlRef +"',window);\n"+
					"}\n"+
				
					"//-->\n"+
					"</SC"+"RIPT><TABLE>"+
					"<TR><TD>Width : </TD><TD><INPUT class=txt VALUE='"+ objCTL.width +"' TYPE=TEXT ID=WID></TD></TR>"+
					"<TR><TD>Height : </TD><TD><INPUT class=txt VALUE='"+ objCTL.height +"' TYPE=TEXT ID=HEI></TD></TR>"+
					"<TR><TD>Border : </TD><TD><INPUT class=txt VALUE='"+ objCTL.border +"' TYPE=TEXT ID=BOR></TD></TR>"+
					"<TR><TD></TD><TD><br><br>"+
					"<INPUT onclick=\"ValidateTable();\" TYPE=BUTTON VALUE=\"Update\" id=BUTTON1 name=BUTTON1></TD></TR>"+
					"</TABLE></BODY></HTML>";
	
					var mywin = window.open("about:blank", "wincolor", "width=250,height=140,toolbar=no,location=no,menubar=no,status=no,scrollbars=no,resizable=no");
					var myDoc = mywin.document;
					myDoc.open("text/html");
					myDoc.write(strOP);
					myDoc.close();
					myDoc.title = "Image Properties";
				}
			}
		}
	}
}

function UpdateTable(strPad,strSpace,strBord,strWid,strAlign,ctrlRef,winRef) 
{
	var objMain = eval("document.all." + ctrlRef);
	var objSelected = objMain.DOM.selection;
	
	if (objSelected.type.toLowerCase() == "control")
	{
		var objRange = objSelected.createRange();
		
        if (objRange.length == 1)
		{
			var objCTL = objRange.item(0);
		
			if (objCTL.tagName == "TABLE")
			{
				objCTL.border = strBord;	
				objCTL.cellPadding = strPad;
				objCTL.cellSpacing = strSpace;
				objCTL.width = strWid;
				objCTL.align = strAlign;
			}
		}
	}					

	winRef.close();
}

function ImageUpdate(strWid,strHei,strBorder,ctrlRef,winRef) 
{
	var objMain = eval("document.all." + ctrlRef);
	var objSelected = objMain.DOM.selection;
	
	if (objSelected.type.toLowerCase() == "control")
	{
		var objRange = objSelected.createRange();
		
        if (objRange.length == 1)
		{
			var objCTL = objRange.item(0);
		
			if (objCTL.tagName == "IMG")
			{
				var strCurrentWid = Number(objCTL.width);
				var strCurrentHei = Number(objCTL.height);

				if (strWid != "" && strHei != "")
				{	
					objCTL.width = strWid;
					objCTL.height = strHei;
				}
				else if (strWid != "")
				{
					var intWidthRatio = Number(strWid) / strCurrentWid;
					
					objCTL.width = strWid;
					objCTL.height = Math.round(strCurrentHei * intWidthRatio);
				}
				else if (strHei != "")
				{
					var intHeightRatio = Number(strHei) / strCurrentHei;
					
					objCTL.height = strHei;
					objCTL.width = Math.round(strCurrentWid * intHeightRatio);
				}
				
				if (strBorder == "")
					objCTL.border = "0";
				else
					objCTL.border = strBorder;	
					
				//if (strWid != "" && strWid.indexOf("%") < 1)
				//	strWid += "px";
					
				//if (strHei != "" && strHei.indexOf("%") < 1)
				//	strHei += "px";
				
				//objCTL.style.width = strWid;
				//objCTL.style.height = strHei;
			}
		}
	}					

	winRef.close();
}

-->