// Generates the FreeTextBox

// id: string, the unique ID of the textbox
// width: string, "XXXpx" or "XX%"
// height: string, "XXXpx"
// alignment: string, "horizontal" or "vertical"
// arrayToolbars: array of strings, contains the necessary toolbars
// displayTabs: boolean, if false, the tabs on the bottom will not be rendered
//
// readonly: boolean
// enabletoolbars: boolean
// enableSizingGrip: boolean
// receivefocus: boolean
// displaymode: can be FTB_MODE_DESIGN or FTB_MODE_HTML
// widthVerticalToolArea: string, "XXXpx" used only in vertical mode.
// 		Sets the vertical tool area width to this size. (should be n*26)
function GenerateTextBox(id, width, height, alignment, arrayToolbars, displayTabs,
	readonly, enabletoolbars, enableSizingGrip, receivefocus, displaymode,
	imagePath, widthVerticalToolArea, defaulValue)
{
	// checking parameters
	if (!id) { alert("The ID is obligatory!!!"); return; }
	if (!width) width = "600px";
	if (!height) height = "350px";
	if (!alignment) alignment = "horizontal";
	if (!arrayToolbars) { arrayToolbars = new Array(); enabletoolbars = false; }
	if (!displayTabs) displayTabs = false;
	if (!readonly) readonly = false;
	if (!receivefocus) receivefocus = false;
	if (!displaymode) displaymode = FTB_MODE_DESIGN;
	if (!enableSizingGrip) enableSizingGrip = false;
	if (!imagePath) imagePath = "js/img/";
	if (imagePath.charAt(imagePath.length - 1) != "/") { imagePath = imagePath + "/"; }
	if (!widthVerticalToolArea || (alignment == "horizontal"))
		widthVerticalToolArea = "100%";
	if (!defaulValue) defaulValue = "";
	
	var textboxHTML = '<table id="'+id+'_OuterTable" cellpadding="0" cellspacing="0" class="OuterTable" style="width: '+width+';">';

	if (arrayToolbars.length > 0)
	{
		textboxHTML += '<tr>'
			+ (alignment == "horizontal" ? '<td class="ToolbarCell">' : '<td rowspan="3" valign="top" class="ToolbarCell">')
			+ '<div id="' + id + '_toolbarArea" style="width: ' + widthVerticalToolArea + ';">'
			+ GenerateToolBars(id, arrayToolbars, alignment, imagePath)
			+ "</div></td></tr>";
	}
		
		// Designer, HTML and PopupDisplay areas
	textboxHTML += "<tr>"
		+ '<td style="padding: 0 4px 0 2px; margin: 0; font-size: 0; width: 100%;">'
		
		+ '<div id="'+id+'_popupDisplayBase" class="popupDisplayBase">'
		+ '<div class="popupDisplayAreaBG" style="height: ' + height + ';"></div>'
		+ '<div id="'+id+'_popupDisplayArea" class="popupDisplayArea" style="height: ' + height + ';" align="center"></div>'
		+ '</div>' 
				
		+ '<div id="' + id + '_designEditorArea" style="width: 100%;">'
		+ '<iframe id="'+id+'_designEditor" style="margin: 1px 0 2px 0; width: 100%; height: ' + height + ';" src="about:blank" class="DesignBox"></iframe>'
		+ '</div>'
		+ '<div id="' + id + '_htmlEditorArea" style="display: none; width: 100%;">'
		+ '<textarea id="' + id + '" name="' + id + '" disabled="disabled" style="width: 100%; height: ' + height + ';" class="HtmlBox">'+defaulValue+'</textarea>'
		+ '</div>'
		+ '<div id="' + id + '_previewPaneArea" style="display: none; width: 100%;">'
		+ '<iframe id="' + id + '_previewPane" style="padding: 0px; width: 100%; height: ' + height + ';" src="about:blank" class="DesignBox"></iframe>'
		+ '</div>'
		+ '</td></tr>';

	if (displayTabs)
	{
		// Tab area
		textboxHTML += '<tr><td style="padding: 0 2px 2px 2px; margin: 0; font-size: 0;">'
			+ '<div style="clear: both;">'
			+ '<table cellpadding="0" cellspacing="0" border="0" width="100%">'
			+ '<tr id="' + id + '_TabRow">'
			+ '<td class="StartTabOn">&nbsp;</td>'
			+ '<td class="TabOn" id="' + id + '_designModeTab" width="60" nowrap="nowrap">'
			+ '<label><img src="'+imagePath+'spacer.gif" alt="" class="MergeClipVM6" style="background-position: -378px 0px;"/>&nbsp;Design</label>'
			+ '</td>'
			+ '<td class="TabOffRight" id="' + id + '_htmlModeTab" width="60" nowrap="nowrap">'
			+ '<label><img src="'+imagePath+'spacer.gif" alt="" class="MergeClipVM6" style="background-position: -399px 0px;"/>&nbsp;HTML</label>'
			+ '</td>'
			+ '<td class="EndTab" rowspan="2"><div id="'+id+'_AncestorArea" class="AncestorArea"></div></td>';
			
		if (enableSizingGrip)
			textboxHTML += '<td class="TabBottomEnd" rowspan="2"><img id="'+id+'_SizingGrip" src="'+imagePath+'spacer.gif" class="MergeClip" style="width: 11px; height: 20px; cursor: nw-resize; background-position: -231px -60px;" alt=""/></td>';
			
		textboxHTML += '</tr>'
			+ '<tr><td class="TabBottom" colspan="3">&nbsp;</td></tr>'
			+ '</table></div></td></tr>'
	}

	textboxHTML += "</table>";
	
	document.write(textboxHTML);
	
	FTB_Names.push(id);
    FTB_API[id] = new FTB_FreeTextBox(
		id,								// ID
		enabletoolbars,					// enableToolbars
		readonly,						// readOnly
		GetButtons(id),					// Toolbar buttons
		GetDDButtons(id), 				// Gets the dropdown buttons
		new Array(),					// Toolbar comboboxes
		FTB_BREAK_BR,					// breakMode [FTB_BREAK_P, FTB_BREAK_BR]
		FTB_PASTE_DEFAULT,				// pasteMode
		FTB_TAB_INSERTSPACES,			// tabMode
		displaymode, 					// startMode [FTB_MODE_DESIGN, FTB_MODE_HTML]
		null,							// clientSideTextChanged, can be set later
		null,							// editoroptions, can be set later
		'',								// designModeCss
		'',								// designModeBodyTagCssClass
		'',								// baseUrl
		'',								// textDirection ['', 'rtl']
		'',								// buttonImageFormat
		imagePath,						// imgPath		usually: js/img/
		receivefocus					// receiveFocus
		); 
		
	return FTB_API[id];
}





// ------------------------------------------------------------
//
// Toolbar generator functions
//
// ------------------------------------------------------------


function GenerateToolBars(id, arrayToolbars, alignment, imagePath)
{
	var toolbarStr = "";
	for (var i = 0; i < arrayToolbars.length; i++)
	{
		switch(arrayToolbars[i].toLowerCase())
		{
			// default toolbars --------------------------------
			case "paragraphsettings": toolbarStr += GenerateParagraphSettings(id, alignment, imagePath); break;
			case "insert": toolbarStr += GenerateInsertToolbar(id, alignment, imagePath); break;
			// default toolbars end -----------------------------
			
			// extended toolbars --------------------------------
			// fontstyle + create/remove link (from paragraphsetting):
			case "fontstyle+link": toolbarStr += GenerateFontStyleCommentToolbar(id, alignment, imagePath); break;
			// fileedit without print and save buttons:
			case "fileedit-print-save": toolbarStr += GenerateFileEdit_NoPrintNoSave(id, alignment, imagePath); break;
			// extended toolbars end ----------------------------
		}
	}
	
	return toolbarStr;
}
function GenerateToolbarStart(alignment, width)
{
	return '<div class="Toolbar"' + (alignment == "horizontal" ? 'style="width: ' + width + 'px;"' : "") + '>'
			+ '<div class="ToolbarStart"></div>'
			+ '<div style="' + (alignment == "horizontal" ? "float: left; padding-top: 2px;" : "padding-left: 1px;") + '">';
}
function GenerateToolbarEnd() { return '</div><div class="ToolbarEnd"></div></div>'; }
function GenerateSeparator() { return '<div class="ToolbarSeparator"></div>'; }


function GenerateFontStyleCommentToolbar(id, alignment, imagePath)
{
	return GenerateToolbarStart(alignment, 242)
		+ '<div id="'+id+'_1_0" class="Button_Off_Out"><img title="Bold"           src="'+imagePath+'spacer.gif" class="MergeClip" style="background-position:   0px 0px;" alt=""/></div>'
		+ '<div id="'+id+'_1_1" class="Button_Off_Out"><img title="Italic"         src="'+imagePath+'spacer.gif" class="MergeClip" style="background-position: -21px 0px;" alt=""/></div>'
		+ '<div id="'+id+'_1_2" class="Button_Off_Out"><img title="Underline"      src="'+imagePath+'spacer.gif" class="MergeClip" style="background-position: -42px 0px;" alt=""/></div>'
		+ '<div id="'+id+'_1_3" class="Button_Off_Out"><img title="Strike Through" src="'+imagePath+'spacer.gif" class="MergeClip" style="background-position: -63px 0px;" alt=""/></div>'
		+ GenerateSeparator()
		+ '<div id="'+id+'_1_4" class="Button_Off_Out"><img title="Superscript" src="'+imagePath+'spacer.gif" class="MergeClip" style="background-position: -84px 0px;" alt=""/></div>'
		+ '<div id="'+id+'_1_5" class="Button_Off_Out"><img title="Subscript"   src="'+imagePath+'spacer.gif" class="MergeClip" style="background-position: -105px 0px;" alt=""/></div>'
		+ '<div id="'+id+'_1_6" class="Button_Off_Out"><img title="Remove All Formatting" src="'+imagePath+'spacer.gif" class="MergeClip" style="background-position: -126px 0px;" alt=""/></div>'
		+ GenerateSeparator()
		+ '<div id="'+id+'_2_10" class="Button_Off_Out"><img title="Create Link" src="'+imagePath+'spacer.gif" class="MergeClip" style="background-position: -168px -20px;" alt=""/></div>'
		+ '<div id="'+id+'_2_11" class="Button_Off_Out"><img title="Remove Link" src="'+imagePath+'spacer.gif" class="MergeClip" style="background-position: -189px -20px;" alt=""/></div>'
		+ GenerateToolbarEnd();
}

function GenerateParagraphSettings(id, alignment, imagePath)
{
	return GenerateToolbarStart(alignment, 288)
		+ '<div id="'+id+'_2_0" class="Button_Off_Out"><img title="Justify Left"   src="'+imagePath+'spacer.gif" class="MergeClip" style="background-position:   0px -20px;" alt=""/></div>'
		+ '<div id="'+id+'_2_1" class="Button_Off_Out"><img title="Justify Right"  src="'+imagePath+'spacer.gif" class="MergeClip" style="background-position: -21px -20px;" alt=""/></div>'
		+ '<div id="'+id+'_2_2" class="Button_Off_Out"><img title="Justify Center" src="'+imagePath+'spacer.gif" class="MergeClip" style="background-position: -42px -20px;" alt=""/></div>'
		+ '<div id="'+id+'_2_3" class="Button_Off_Out"><img title="Justify Full"   src="'+imagePath+'spacer.gif" class="MergeClip" style="background-position: -63px -20px;" alt=""/></div>'
		+ GenerateSeparator()
		+ '<div id="'+id+'_2_5" class="Button_Off_Out"><img title="Bulled List"   src="'+imagePath+'spacer.gif" class="MergeClip" style="background-position:  -84px -20px;" alt=""/></div>'
		+ '<div id="'+id+'_2_6" class="Button_Off_Out"><img title="Numbered List" src="'+imagePath+'spacer.gif" class="MergeClip" style="background-position: -105px -20px;" alt=""/></div>'
		+ '<div id="'+id+'_2_7" class="Button_Off_Out"><img title="Indent"        src="'+imagePath+'spacer.gif" class="MergeClip" style="background-position: -126px -20px;" alt=""/></div>'
		+ '<div id="'+id+'_2_8" class="Button_Off_Out"><img title="Outdent"       src="'+imagePath+'spacer.gif" class="MergeClip" style="background-position: -147px -20px;" alt=""/></div>'
		+ GenerateSeparator()
		+ '<div id="'+id+'_2_10" class="Button_Off_Out"><img title="Create Link" src="'+imagePath+'spacer.gif"  class="MergeClip" style="background-position: -168px -20px;" alt=""/></div>'
		+ '<div id="'+id+'_2_11" class="Button_Off_Out"><img title="Remove Link" src="'+imagePath+'spacer.gif"  class="MergeClip" style="background-position: -189px -20px;" alt=""/></div>'
		+ '<div id="'+id+'_2_12" class="Button_Off_Out"><img title="Insert Image" src="'+imagePath+'spacer.gif" class="MergeClip" style="background-position: -210px -20px;" alt=""/></div>'
		+ GenerateToolbarEnd();
}

function GenerateFileEdit_NoPrintNoSave(id, alignment, imagePath)
{
	return GenerateToolbarStart(alignment, 168)
		+ '<div id="'+id+'_3_0" class="Button_Off_Out"><img title="Cut"    src="'+imagePath+'spacer.gif" class="MergeClip" style="background-position: -147px 0px;" alt=""/></div>'
		+ '<div id="'+id+'_3_1" class="Button_Off_Out"><img title="Copy"   src="'+imagePath+'spacer.gif" class="MergeClip" style="background-position: -168px 0px;" alt=""/></div>'
		+ '<div id="'+id+'_3_2" class="Button_Off_Out"><img title="Paste"  src="'+imagePath+'spacer.gif" class="MergeClip" style="background-position: -189px 0px;" alt=""/></div>'
		+ '<div id="'+id+'_3_3" class="Button_Off_Out"><img title="Delete" src="'+imagePath+'spacer.gif" class="MergeClip" style="background-position: -210px 0px;" alt=""/></div>'
		+ GenerateSeparator()
		+ '<div id="'+id+'_3_5" class="Button_Off_Out"><img title="Undo" src="'+imagePath+'spacer.gif" class="MergeClip" style="background-position: -231px 0px;" alt=""/></div>'
		+ '<div id="'+id+'_3_6" class="Button_Off_Out"><img title="Redo" src="'+imagePath+'spacer.gif" class="MergeClip" style="background-position: -252px 0px;" alt=""/></div>'
		+ GenerateToolbarEnd();
}

function GenerateInsertToolbar(id, alignment, imagePath)
{
	return GenerateToolbarStart(alignment, 158)
		+ '<div id="'+id+'_5_0" class="Button_Off_Out"><img title="Insert Rule" src="'+imagePath+'spacer.gif" class="MergeClip" style="background-position: -315px 0px;" alt=""/></div>'
		+ '<div id="'+id+'_5_1" class="Button_Off_Out"><img title="Insert Date" src="'+imagePath+'spacer.gif" class="MergeClip" style="background-position: -336px 0px;" alt=""/></div>'
		+ '<div id="'+id+'_5_2" class="Button_Off_Out"><img title="Insert Time" src="'+imagePath+'spacer.gif" class="MergeClip" style="background-position: -357px 0px;" alt=""/></div>'
		+ '<div id="'+id+'_5_3" class="ButtonDD_Off_Out"><img title="Insert smiley" src="'+imagePath+'spacer.gif" class="MergeClip" style="background-position: -60px -60px; width: 30px;" alt=""/>' + GenerateSmileyDropDown(id + "_5_3", imagePath) + '</div>'
		+ '<div id="'+id+'_5_4" class="ButtonDD_Off_Out"><img title="Insert symbol" src="'+imagePath+'spacer.gif" class="MergeClip" style="background-position: -90px -60px; width: 30px;" alt=""/>' + GenerateSymbolDropDown(id + "_5_4", imagePath) + '</div>'
		+ GenerateToolbarEnd();
}


// -------------------------------------------------------------------------
//
// Toolbar register functions
//
// -------------------------------------------------------------------------

function GetButtons(id)
{
	var result = new Array();
	var tbCount = 0;
	
	var possibleButtonIDs = new Array(
		id + '_1_0', id + '_1_1', id + '_1_2', id + '_1_3', id + '_1_4', id + '_1_5', id + '_1_6', 
		id + '_2_0', id + '_2_1', id + '_2_2', id + '_2_3', id + '_2_5', id + '_2_6', id + '_2_7', id + '_2_8', 
		id + '_2_10', id + '_2_11', id + '_2_12',
		id + '_3_0', id + '_3_1', id + '_3_2', id + '_3_3', id + '_3_5', id + '_3_6', id + '_3_7', id + '_3_8', 
		id + '_5_0', id + '_5_1', id + '_5_2'
		);
	
	for (var i = 0; i < possibleButtonIDs.length; i++)
	{
		var obj = this.document.getElementById(possibleButtonIDs[i]);
		if (obj == null)
			continue;
		
		switch (possibleButtonIDs[i])
		{
			case id + "_1_0": result[tbCount++] = new FTB_Button(id + '_1_0', 'bold', null,null,false,null); break;
			case id + "_1_1": result[tbCount++] = new FTB_Button(id + '_1_1', 'italic', null,null,false,null); break;
			case id + "_1_2": result[tbCount++] = new FTB_Button(id + '_1_2', 'underline', null,null,false,null); break;
			case id + "_1_3": result[tbCount++] = new FTB_Button(id + '_1_3', 'strikethrough', null,null,false,null); break;
			case id + "_1_4": result[tbCount++] = new FTB_Button(id + '_1_4', 'superscript', null,null,false,null); break;
			case id + "_1_5": result[tbCount++] = new FTB_Button(id + '_1_5', 'subscript', null,null,false,null); break;
			case id + "_1_6": result[tbCount++] = new FTB_Button(id + '_1_6', 'removeformat', null,null,false,null); break;
			
			case id + "_2_0": result[tbCount++] = new FTB_Button(id + '_2_0','justifyleft',null,null,false,null); break;
			case id + "_2_1": result[tbCount++] = new FTB_Button(id + '_2_1','justifyright',null,null,false,null); break;
			case id + "_2_2": result[tbCount++] = new FTB_Button(id + '_2_2','justifycenter',null,null,false,null); break;
			case id + "_2_3": result[tbCount++] = new FTB_Button(id + '_2_3','justifyfull',null,null,false,null); break;
			case id + "_2_5": result[tbCount++] = new FTB_Button(id + '_2_5','insertunorderedlist',null,null,false,null); break;
			case id + "_2_6": result[tbCount++] = new FTB_Button(id + '_2_6','insertorderedlist',null,null,false,null); break;
			case id + "_2_7": result[tbCount++] = new FTB_Button(id + '_2_7','indent',null,null,false,null); break;
			case id + "_2_8": result[tbCount++] = new FTB_Button(id + '_2_8','outdent',null,null,false,null); break;
			case id + "_2_10": result[tbCount++] = new FTB_Button(id + '_2_10','createlink',function() { this.ftb.CreateLink(); },null,false,null); break;
			case id + "_2_11": result[tbCount++] = new FTB_Button(id + '_2_11','unlink',null,null,false,function() { this.disabled = !(this.ftb.GetParentElement().tagName.toLowerCase() == 'a') }); break;
			case id + "_2_12": result[tbCount++] = new FTB_Button(id + '_2_12','insertimage',function() { this.ftb.InsertImage(); },null,false,null); break;
			
			case id + "_3_0": result[tbCount++] = new FTB_Button(id + '_3_0','cut',function() { this.ftb.Cut(); },null,true,null); break;
			case id + "_3_1": result[tbCount++] = new FTB_Button(id + '_3_1','copy',function() { this.ftb.Copy(); },null,true,null); break;
			case id + "_3_2": result[tbCount++] = new FTB_Button(id + '_3_2','paste',function() { this.ftb.Paste(); },null,true,null); break;
			case id + "_3_3": result[tbCount++] = new FTB_Button(id + '_3_3','',function() { this.ftb.DeleteContents(); },null,false,null); break;
			case id + "_3_5": result[tbCount++] = new FTB_Button(id + '_3_5','undo',function() { this.ftb.Undo(); },null,false,function() { this.disabled=!this.ftb.CanUndo(); }); break;
			case id + "_3_6": result[tbCount++] = new FTB_Button(id + '_3_6','redo',function() { this.ftb.Redo(); },null,false,function() { this.disabled=!this.ftb.CanRedo(); }); break;
			
			case id + "_5_0": result[tbCount++] = new FTB_Button(id + '_5_0','inserthorizontalrule', null, null, false, null); break;
			case id + "_5_1": result[tbCount++] = new FTB_Button(id + '_5_1','',function() { var d = new Date();this.ftb.InsertHtml(d.toLocaleDateString()); }, null, false, null); break;
			case id + "_5_2": result[tbCount++] = new FTB_Button(id + '_5_2','',function() { var d = new Date();this.ftb.InsertHtml(d.toLocaleTimeString()); }, null, false, null); break;
		}
	}
	
	return result;
}

function GetDDButtons(id)
{
	var result = new Array();
	var tbCount = 0;
	
	var possibleButtonIDs = new Array(id + '_5_3', id + '_5_4');
	
	for (var i = 0; i < possibleButtonIDs.length; i++)
	{
		var obj = this.document.getElementById(possibleButtonIDs[i]);
		if (obj == null)
			continue;
			
		switch (possibleButtonIDs[i])
		{
			case id + "_5_3": result[tbCount++] = new FTB_ButtonDropDown(id + '_5_3', "smiley", null, false, null); break;
			case id + "_5_4": result[tbCount++] = new FTB_ButtonDropDown(id + '_5_4', "symbol", null, false, null); break;
		}			
	}
	return result;
}

// 
// Smiley generator functions
//

function FillSmileys()
{
	var count = 0;
	var smileyPack = new Array();
	
	smileyPack[count++] = new Array('N', 'angry', 'normal/angry.gif');
	smileyPack[count++] = new Array('N', 'annoyed', 'normal/annoyed.gif');
	smileyPack[count++] = new Array('N', 'arrogant', 'normal/arrogant.gif');
	smileyPack[count++] = new Array('N', 'ashamed', 'normal/ashamed.gif');
	smileyPack[count++] = new Array('N', 'awful', 'normal/awful.gif');
	smileyPack[count++] = new Array('N', 'bigsmile', 'normal/big_smile.gif');
	smileyPack[count++] = new Array('N', 'blush', 'normal/blush.gif');
	smileyPack[count++] = new Array('N', 'confused', 'normal/confused.gif');
	smileyPack[count++] = new Array('N', 'cool', 'normal/cool.gif');
	smileyPack[count++] = new Array('N', 'cry', 'normal/cry.gif');
	smileyPack[count++] = new Array('N', 'cry2', 'normal/cry2.gif');
	smileyPack[count++] = new Array('N', 'dead', 'normal/dead.gif');
	smileyPack[count++] = new Array('N', 'disappointed', 'normal/disappointed.gif');
	smileyPack[count++] = new Array('N', 'dontgetit', 'normal/dontgetit.gif');
	smileyPack[count++] = new Array('N', 'evil', 'normal/evil.gif');
	smileyPack[count++] = new Array('N', 'evilwink', 'normal/evil_wink.gif');
	smileyPack[count++] = new Array('N', 'evilmad', 'normal/evilmad.gif');
	smileyPack[count++] = new Array('N', 'gah', 'normal/gah.gif');
	smileyPack[count++] = new Array('N', 'happy', 'normal/happy.gif');
	smileyPack[count++] = new Array('N', 'happy2', 'normal/happy2.gif');
	smileyPack[count++] = new Array('N', 'huh', 'normal/huh.gif');
	smileyPack[count++] = new Array('N', 'idontthinkso', 'normal/idontthinkso.gif');
	smileyPack[count++] = new Array('N', 'letmethink', 'normal/letmethink.gif');
	smileyPack[count++] = new Array('N', 'lol', 'normal/lol.gif');
	smileyPack[count++] = new Array('N', 'matrix', 'normal/matrix.gif');
	smileyPack[count++] = new Array('N', 'matrixcool', 'normal/matrixcool.gif');
	smileyPack[count++] = new Array('N', 'mwsmile', 'normal/mw_smile.gif');
	smileyPack[count++] = new Array('N', 'noidea', 'normal/no_idea.gif');
	smileyPack[count++] = new Array('N', 'notfunny', 'normal/not_funny.gif');
	smileyPack[count++] = new Array('N', 'notimpressed', 'normal/notimpressed.gif');
	smileyPack[count++] = new Array('N', 'ohno', 'normal/ohno.gif');
	smileyPack[count++] = new Array('N', 'really', 'normal/really.gif');
	smileyPack[count++] = new Array('N', 'sad', 'normal/sad.gif');
	smileyPack[count++] = new Array('N', 'sad2', 'normal/sad2.gif');
	smileyPack[count++] = new Array('N', 'smile', 'normal/smile.gif');
	smileyPack[count++] = new Array('N', 'sorry', 'normal/sorry.gif');
	smileyPack[count++] = new Array('N', 'suspicious', 'normal/suspicious.gif');
	smileyPack[count++] = new Array('N', 'tired', 'normal/tired.gif');
	smileyPack[count++] = new Array('N', 'tongue', 'normal/tongue.gif');
	smileyPack[count++] = new Array('N', 'tongue2', 'normal/tongue2.gif');
	smileyPack[count++] = new Array('N', 'weird', 'normal/weird.gif');
	smileyPack[count++] = new Array('N', 'whatever', 'normal/whatever.gif');
	smileyPack[count++] = new Array('N', 'wink', 'normal/wink.gif');
	smileyPack[count++] = new Array('N', 'wow', 'normal/wow.gif');
	smileyPack[count++] = new Array('N', 'zzz', 'normal/zzz.gif');
	smileyPack[count++] = new Array('N', 'bleh', 'normal/bleh.gif');
	smileyPack[count++] = new Array('N', 'blush2', 'normal/blush2.gif');
	smileyPack[count++] = new Array('N', 'laughing', 'normal/laughing.gif');
	smileyPack[count++] = new Array('N', 'mad', 'normal/mad.gif');
	smileyPack[count++] = new Array('N', 'tongue3', 'normal/tongue3.gif');
	
	smileyPack[count++] = new Array('R', 'angel', 'rare/angel.gif');
	smileyPack[count++] = new Array('R', 'cry3', 'rare/cry3.gif');
	smileyPack[count++] = new Array('R', 'no', 'rare/no.gif');
	smileyPack[count++] = new Array('R', 'no2', 'rare/no2.gif');
	smileyPack[count++] = new Array('R', 'unsure', 'rare/unsure.gif');
	smileyPack[count++] = new Array('R', 'yes', 'rare/yes.gif');
	smileyPack[count++] = new Array('R', 'wink2', 'rare/wink2.gif');
	smileyPack[count++] = new Array('R', 'wtf', 'rare/wtf.gif');
	smileyPack[count++] = new Array('R', 'yucky', 'rare/yucky.gif');
	smileyPack[count++] = new Array('R', 'bawl', 'rare/bawl.gif');
	smileyPack[count++] = new Array('R', 'cold', 'rare/cold.gif');
	smileyPack[count++] = new Array('R', 'doublefuck', 'rare/double_fuck.gif');
	smileyPack[count++] = new Array('R', 'dry', 'rare/dry.gif');
	smileyPack[count++] = new Array('R', 'eekyello', 'rare/eek_yello.gif');
	smileyPack[count++] = new Array('R', 'eerrrr', 'rare/eerrrr.gif');
	smileyPack[count++] = new Array('R', 'eyebrow', 'rare/eyebrow.gif');
	smileyPack[count++] = new Array('R', 'look', 'rare/look.gif');
	smileyPack[count++] = new Array('R', 'geek', 'rare/geek.gif');
	smileyPack[count++] = new Array('R', 'naughty', 'rare/naughty.gif');
	smileyPack[count++] = new Array('R', 'nosebleed', 'rare/nose_bleed.gif');
	smileyPack[count++] = new Array('R', 'noseup', 'rare/nose_up.gif');
	smileyPack[count++] = new Array('R', 'rotfl', 'rare/rotfl.gif');
	smileyPack[count++] = new Array('R', 'shifty', 'rare/shifty.gif');
	smileyPack[count++] = new Array('R', 'shutup', 'rare/shutup.gif');
	smileyPack[count++] = new Array('R', 'sleep', 'rare/sleep.gif');
	smileyPack[count++] = new Array('R', 'tired', 'rare/tired.gif');
	smileyPack[count++] = new Array('R', 'wacko', 'rare/wacko.gif');
	smileyPack[count++] = new Array('R', 'yawn', 'rare/yawn.gif');
	smileyPack[count++] = new Array('R', 'zipped', 'rare/zipped.gif');
	smileyPack[count++] = new Array('R', 'whistle', 'rare/whistle.gif');
	smileyPack[count++] = new Array('R', 'wavecry', 'rare/wavecry.gif');
	smileyPack[count++] = new Array('R', 'wave', 'rare/wave.gif');
	smileyPack[count++] = new Array('R', 'wall', 'rare/wall.gif');
	smileyPack[count++] = new Array('R', 'surrender', 'rare/surrender.gif');
	smileyPack[count++] = new Array('R', 'worshippy', 'rare/worshippy.gif');
	smileyPack[count++] = new Array('R', 'whistling', 'rare/whistling.gif');
	smileyPack[count++] = new Array('R', 'help', 'rare/help.gif');
	smileyPack[count++] = new Array('R', 'broaf', 'rare/broaf.gif');
	smileyPack[count++] = new Array('R', 'swear', 'rare/swear.gif');

	smileyPack[count++] = new Array('E', 'beer', 'extra/beer.gif');
	smileyPack[count++] = new Array('E', 'beer2', 'extra/beer2.gif');
	smileyPack[count++] = new Array('E', 'book', 'extra/book.gif');
	smileyPack[count++] = new Array('E', 'cap', 'extra/cap.gif');
	smileyPack[count++] = new Array('E', 'censored', 'extra/censored.gif');
	smileyPack[count++] = new Array('E', 'cool2', 'extra/cool2.gif');
	smileyPack[count++] = new Array('E', 'console', 'extra/console.gif');
	smileyPack[count++] = new Array('E', 'dumbells', 'extra/dumbells.gif');
	smileyPack[count++] = new Array('E', 'eat', 'extra/eat.gif');
	smileyPack[count++] = new Array('E', 'eat2', 'extra/eat2.gif');
	smileyPack[count++] = new Array('E', 'flex', 'extra/flex.gif');
	smileyPack[count++] = new Array('E', 'fuckyou', 'extra/fuck_you.gif');
	smileyPack[count++] = new Array('E', 'gun1', 'extra/gun1.gif');
	smileyPack[count++] = new Array('E', 'gun2', 'extra/gun2.gif');
	smileyPack[count++] = new Array('E', 'gun3', 'extra/gun3.gif');
	smileyPack[count++] = new Array('E', 'graduated', 'extra/graduated.gif');
	smileyPack[count++] = new Array('E', 'hug', 'extra/hug.gif');
	smileyPack[count++] = new Array('E', 'kamikaze', 'extra/kamikaze.gif');
	smileyPack[count++] = new Array('E', 'kissing', 'extra/kissing.gif');
	smileyPack[count++] = new Array('E', 'ninja', 'extra/ninja.gif');
	smileyPack[count++] = new Array('E', 'passifier', 'extra/passifier.gif');
	smileyPack[count++] = new Array('E', 'rambo', 'extra/rambo.gif');
	smileyPack[count++] = new Array('E', 'rocker', 'extra/rocker.gif');
	smileyPack[count++] = new Array('E', 'thumbup', 'extra/thumbup.gif');
	smileyPack[count++] = new Array('E', 'tooth', 'extra/tooth.gif');
	smileyPack[count++] = new Array('E', 'rotfl2', 'extra/rotfl2.gif');
	smileyPack[count++] = new Array('E', 'upsidedown', 'extra/upsidedown.gif');
	smileyPack[count++] = new Array('E', 'whip', 'extra/whip.gif');

	smileyPack[count++] = new Array('S', 'alien', 'sign/alien.gif');
	smileyPack[count++] = new Array('S', 'arrowdown', 'sign/arrow_down.gif');
	smileyPack[count++] = new Array('S', 'arrowleft', 'sign/arrow_left.gif');
	smileyPack[count++] = new Array('S', 'arrowright', 'sign/arrow_right.gif');
	smileyPack[count++] = new Array('S', 'arrowup', 'sign/arrow_up.gif');
	smileyPack[count++] = new Array('S', 'clover', 'sign/clover.gif');
	smileyPack[count++] = new Array('S', 'excl', 'sign/excl.gif');
	smileyPack[count++] = new Array('S', 'holloween', 'sign/holloween.gif');
	smileyPack[count++] = new Array('S', 'idea', 'sign/idea.gif');
	smileyPack[count++] = new Array('S', 'love', 'sign/love.gif');
	smileyPack[count++] = new Array('S', 'nuke', 'sign/nuke.gif');
	smileyPack[count++] = new Array('S', 'question', 'sign/question.gif');
	smileyPack[count++] = new Array('S', 'skull', 'sign/skull.gif');
	smileyPack[count++] = new Array('S', 'yinyang', 'sign/yinyang.gif');
	
	return smileyPack;
}

function GenerateSmileyDropDown(id, imagePath)
{
	var smileyPath = imagePath + "smiley/";
	
	var groupIDs = new Array("N", "R", "E", "S");
	
	var result = ""
		+ "<div id=\"" + id + "_SmileyContainerBase\" class=\"DDContainerBase\">\n"
		+ "<div id=\"" + id + "_SmileyContainer\" class=\"DDContainer\">\n"
		+ "<table style=\"width: 100%; border: 0px;\" cellpadding=\"0\" cellspacing=\"0\">\n"
		+ "<tr><td style=\"height: 2px;\" /></tr>\n"
		+ "<tr><td style=\"width: 2px;\" />\n"
		+ "<td colspan=\"5\" class=\"DDGroup\">\n";

	var smileyPack = FillSmileys();
	for (var i = 0; i < groupIDs.length; i++)
	{
		var idG = groupIDs[i];

		result += "<div id=\"" + id + "_SmileyGroup" + idG + "\" class=\"DDGroup\" align=\"center\">\n";
		
		for (var j = 0; j < smileyPack.length; j++)
		{
			var sm = smileyPack[j];
			if (sm[0] != idG)
				continue;
					
			result += "<img src=\"" + smileyPath + sm[2] + "\" class=\"SmileyList\" alt=\"\" id=\"" + sm[1] + "\" onmouseover='this.className=\"SmileyListOM\"' onmouseout='this.className=\"SmileyList\"' />\n";
		}
		
		result += "</div>\n\n";
	}

	result += "</td>\n<td style=\"width: 2px;\" />\n</tr>\n<tr><td style=\"width: 2px;\" />\n";
		
	for (var i = 0; i < groupIDs.length; i++)
		result += "<td id=\"" + id + "_SmileyGrpSel" + groupIDs[i] + "\" align=\"center\" onmouseover=\"this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.button.ShowGroup('" + id + "_SmileyGrpSel" + groupIDs[i] + "'); this.className='DDGrpSelOM';\" onmouseout='this.className=\"DDGrpSelSel\"' />\n";
	
	result += ""
		+ "<td id=\""+id+"_SmileyClose\" class=\"DDGrpClose\" onmouseover=\"this.firstChild.style.backgroundPosition='-195px -60px'\" onmouseout=\"this.firstChild.style.backgroundPosition='-180px -60px'\">"
		+ "<img src=\""+imagePath+"spacer.gif\" class=\"MergeClip\" style=\"vertical-align: -4px; width: 16px; height: 16px; background-position: -180px -60px;\" title=\"Cancel\" alt=\"X\" />"
		+ "</td>\n"
		+ "<td style=\"width: 2px;\" /></tr>\n"
		
		+ "<tr><td style=\"height: 2px;\" /></tr>\n"
		+ "</table>\n</div>\n</div>\n";

	// document.write(result);
	
	return result;
}

function GenerateSymbolDropDown(id, imagePath)
{
	var symbols = new Array(
		new Array("&#8364;", "&#162;", "&#163;", "&#165;",  			// currencies: eur, cent, font, yen
				  "&#167;", "&#169;", "&#174;",	"&#8482;", "&#402;", "@",	// paragraph, C R TM f @
				  "&#8451;", "&#8470;", "&#181;",						// Celsius, No, micro
				  "&#338;", "&#339;", "&#198;", "&#230;", "&#199;", "&#231;", "&#197;", "&#229;", "&#xD8;", "&#xF8;",
				  "&#8230;", "&#191;", "&#161;", 						// ..., capsized ?, capsized !
				  "&#176;", "&#183;", "&#9674;", "&#8226;", 			// list bullets
				  "&#8211;", "&#8212;", "&#8216;", "&#8217;", "&#8220;", "&#8221;", 
				  "&#171;", "&#187;", "&#182;", "&#164;"
				  ),
		new Array("&#9824;", "&#9827;", "&#9829;", "&#9830;",			 // card symbols
				  "&#8592;", "&#8593;", "&#8594;", "&#8595;", "&#8596;", // arrow
				  "&#8656;", "&#8657;", "&#8658;", "&#8659;", "&#8660;", // double arrow
//				  "&#8968;", "&#8969;", "&#8970;", "&#8971;", 			 // ceiling/bottoms
				  "&#9792;", "&#9794;",									 // gender signs
				  "&#9798;", "&#9799;", "&#9800;", "&#9801;", "&#9802;", "&#9803;", "&#9804;", 
				  "&#9805;", "&#9806;", "&#9807;", "&#9808;", "&#9809;", // astrological signs
				  "&#x1D11E;", "&#x1D122;", "&#9833;", "&#9834;", "&#9835;", "&#9836;", "&#9837;", "&#9838;", "&#9839;" // note signs
				  ),
		new Array("&#8704;", "&#8707;", "&#8712;", "&#8713;", "&#8715;", "&#8719;", "&#8721;",
				  "&#8711;", "&#8709;",
				  "&#8730;", "&#8733;", "&#8734;", "&#8747;", "&#8756;",
				  "&#8776;", "&#8800;", "&#8801;", "&#8804;", "&#8805;", 
				  "&#8745;", "&#8746;", "&#8834;", "&#8835;", "&#8836;", "&#8838;", "&#8839;",
				  "&#8240;", "&#247;", "&#177;", "&#215;",
				  "&#185;", "&#178;", "&#179;",
				  "&#189;", "&#8531;", "&#8532;", "&#188;", "&#190;", "&#8533;", "&#8534;", 
				  "&#8535;", "&#8536;", "&#8537;", "&#8538;", "&#8539;", "&#8540;", "&#8541;", "&#8542;" 
				  ),
		new Array("&#913;", "&#914;", "&#915;", "&#916;", "&#917;", "&#918;", "&#919;", "&#920;", 
				  "&#921;", "&#922;", "&#923;", "&#924;", "&#925;", "&#926;", "&#927;", "&#928;", 
				  "&#929;", "&#931;", "&#932;", "&#933;", "&#934;", "&#935;", "&#936;", "&#937;", 
				  "&#945;", "&#946;", "&#947;", "&#948;", "&#949;", "&#950;", "&#951;", "&#952;", 
				  "&#953;", "&#954;", "&#955;", "&#956;", "&#957;", "&#958;", "&#959;", "&#960;", 
				  "&#961;", "&#962;", "&#963;", "&#964;", "&#965;", "&#966;", "&#967;", "&#968;", 
				  "&#960;"));
	
	var groupIDs = new Array("1", "G", "M", "H");
	
	var result = ""
		+ "<div id=\"" + id + "_ContainerBase\" class=\"DDContainerBase\">\n"
		+ "<div id=\"" + id + "_Container\" class=\"DDContainer\">\n"
		+ "<table style=\"width: 100%; border: 0px;\" cellpadding=\"0\" cellspacing=\"0\">\n"
		+ "<tr><td style=\"height: 2px;\" /></tr>\n"
		+ "<tr><td style=\"width: 2px;\" />\n"
		+ "<td colspan=\"5\" class=\"DDGroup\">\n";

	for (var i = 0; i < groupIDs.length; i++)
	{
		var idG = groupIDs[i];
		
		result += "<div unselectable=\"on\" id=\"" + id + "_Group" + idG + "\" class=\"DDGroup\" align=\"center\">\n";
		
		for (var j = 0; j < symbols[i].length; j++)
			result += "<div unselectable=\"on\" id=\""+symbols[i][j]+"\" class=\"SymbolList\" onmouseover='this.className=\"SymbolListOM\"' onmouseout='this.className=\"SymbolList\"'>"+symbols[i][j]+"</div>";
		
		result += "</div>\n\n";
	}

	result += "</td>\n<td style=\"width: 2px;\" />\n</tr>\n<tr><td style=\"width: 2px;\" />\n";
		
	for (var i = 0; i < groupIDs.length; i++)
		result += "<td id=\"" + id + "_GrpSel" + groupIDs[i] + "\" align=\"center\" onmouseover=\"this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.button.ShowGroup('" + id + "_GrpSel" + groupIDs[i] + "'); this.className='DDGrpSelOM';\" onmouseout='this.className=\"DDGrpSelSel\"' />\n";
	
	result += ""
		+ "<td id=\""+id+"_Close\" class=\"DDGrpClose\" onmouseover=\"this.firstChild.style.backgroundPosition='-195px -60px'\" onmouseout=\"this.firstChild.style.backgroundPosition='-180px -60px'\">"
		+ "<img src=\""+imagePath+"spacer.gif\" class=\"MergeClip\" style=\"vertical-align: -4px; width: 16px; height: 16px; background-position: -180px -60px;\" title=\"Cancel\" alt=\"X\" />"
		+ "</td>\n"
		+ "<td style=\"width: 2px;\" /></tr>\n"
		
		+ "<tr><td style=\"height: 2px;\" /></tr>\n"
		+ "</table>\n</div>\n</div>\n";

	return result;
}


// ------------------------------------------------------------
//
// PopupDisplayArea generator functions
//
// ------------------------------------------------------------

function GenerateLinkEditorHtml(id, text, linkhref, className, target, customTarget, linkEditorOptions)
{
	if (!text) text = "";
	if (!linkhref) linkhref = "http://";
	if (!className) className = "";
	if (!target) target = "";
	if (!customTarget) customTarget = "";

	var isDetailed = true;	
	var showTitle = true;
	if (linkEditorOptions != null)
	{
		isDetailed = linkEditorOptions.isDetailed;
		showTitle = linkEditorOptions.showTitle;
		className = (className == "" ? linkEditorOptions.defaultClassName : className);
		target = (target == "" ? linkEditorOptions.defaultTarget : target);
		customTarget = (customTarget == "" ? linkEditorOptions.defaultCustomTarget : customTarget);
	}
	
	var isCustom = (target=="_custom");
	
	var result = ""
//		+ "<form action='' onsubmit='FTB_LETInsertLink(event);'>"
		+ "<table class='PPTable'>"
		+ "<tr><td colspan='2' class='PPHeader'>Link Editor</td></tr>"
		+ "<tr><td class='space'></td></tr>"
		+ "<tr><td class='PPFieldTitleObl'>URL:</td><td><input type='text' id='"+id+"_LETLinkHRef' value='"+linkhref+"' class='LETInput' /></td></tr>"
		+ (showTitle ? "<tr><td class='PPFieldTitle'>Title:</td><td><input type='text' id='"+id+"LETLinkTitle' value='"+text+"' class='LETInput' /></td></tr>" : "")
		
		+ (isDetailed ? "<tr><td class='PPFieldTitle'>Class:</td><td><input type='text' id='"+id+"LETLinkCssClass' value='"+className+"' class='LETInput' /></td></tr>"
		+ "<tr>"
			+ "<td class='PPFieldTitle'>Target:</td>"
			+ "<td>"
				+ "<select id='"+id+"_LETLinkTarget' class='LETSelect' onchange='FTB_LETLinkTargetChanged(event);'>"
					+ "<option value='' "+(target==""?"selected='1'":"")+">None</option>"
					+ "<option value='_blank' "+(target=="_blank"?"selected='1'":"")+">New Window (_blank)</option>"
					+ "<option value='_top' "+(target=="_top"?"selected='1'":"")+">Top Frame (_top)</option>"
					+ "<option value='_parent' "+(target=="_parent"?"selected='1'":"")+">Parent Frame (_parent)</option>"
					+ "<option value='_self' "+(target=="_self"?"selected='1'":"")+">Same Frame (_self)</option>"
					+ "<option value='_custom' "+(target=="_custom"?"selected='1'":"")+">Custom Target</option>"
				+ "</select>&nbsp;"
				+ "<input type='text' id='"+id+"_LETCustomTarget' value='"+customTarget+"' class='LETInput' style='width: 95px;' disabled='"+(isCustom?"false":"true")+"' />"
			+ "</td>"
		+ "</tr>"
		+ "<tr><td class='space'></td></tr>" : "<tr><td class='space'>"
		+ "<input type='hidden' id='"+id+"LETLinkCssClass' value='"+className+"'/>"
		+ "<input type='hidden' id='"+id+"_LETLinkTarget' value='"+target+"'/>"
		+ "<input type='hidden' id='"+id+"_LETCustomTarget' value='"+customTarget+"'/>"
		+ "</td></tr>")
		
		+ "<tr>"
			+ "<td colspan='2' class='PPFooter'>"
				+ "<button type='button' id='"+id+"_LETInsertLinkButton' onclick='FTB_LETInsertLink(event);' class='PPButton'>OK</button>"
				+ "<button type='button' id='"+id+"_LETCancelButton' onclick='FTB_PPACancel(event);' class='PPButton'>Cancel</button>"
			+ "</td>"
		+ "</tr>"
		+ "</table>";
//		+ "</form>";

	return result;
}
