function ValueInArray (Value, InArray)
{
for (Index=0; Index<=InArray.length - 1; Index++)
{
if (InArray[Index] == Value)
{
return true;
}
}
return false;
}
function BTCodeEditorCreate (ID, Disallow)
{
Buttons = '';
if ((Disallow == null) || (!ValueInArray('b', Disallow)))
{
Buttons = Buttons + '<input type="button" value="Bold" onclick="BTCodeEditorBold(' + ID + ');" />' ;
}
if ((Disallow == null) || (!ValueInArray('i', Disallow)))
{
Buttons = Buttons + '<input type="button" value="Italic" onclick="BTCodeEditorItalic(' + ID + ');" />';
}
if ((Disallow == null) || (!ValueInArray('u', Disallow)))
{
Buttons = Buttons + '<input type="button" value="Underline" onclick="BTCodeEditorUnderline(' + ID + ');" />';
}
if ((Disallow == null) || (!ValueInArray('code', Disallow)))
{
Buttons = Buttons + '<input type="button" value="Code" onclick="BTCodeEditorCode(' + ID + ');" />';
}
if ((Disallow == null) || (!ValueInArray('quote', Disallow)))
{
Buttons = Buttons + '<input type="button" value="Quote" onclick="BTCodeEditorQuote(' + ID + ');" />';
}
if ((Disallow == null) || (!ValueInArray('link', Disallow)))
{
Buttons = Buttons + '<input type="button" value="Link" onclick="BTCodeEditorLink(' + ID + ');" />';
}
if ((Disallow == null) || (!ValueInArray('image', Disallow)))
{
Buttons = Buttons + '<input type="button" value="Image" onclick="BTCodeEditorImage(' + ID + ');" />';
}
Memo = document.getElementById(ID);
Parent = Memo.parentNode;
NewDiv = document.createElement('div');
NewDiv.className = 'BTCodeEditor';
Parent.insertBefore (NewDiv, Memo);
NewSpan = document.createElement('span');
NewSpan.innerHTML = Buttons;
NewDiv.appendChild (NewSpan);
NewSpan = document.createElement('span');
NewDiv.appendChild (NewSpan);
NewSpan.appendChild (Memo);
}
function BTCodeEditorAddTag (ID, TagStart, TagEnd)
{
if (ID.setSelectionRange)
{
// Mozilla
ID.value = ID.value.substring (0, ID.selectionStart) +
TagStart +
ID.value.substring(ID.selectionStart, ID.selectionEnd) +
TagEnd +
ID.value.substring(ID.selectionEnd, ID.value.length);
} // Moz
else
{
// Internet Explorer
var SelectedRange = document.selection.createRange();
// If text selected is in element
if (SelectedRange.parentElement() == ID)
{
var SelectStr = document.selection.createRange().text;
document.selection.createRange().text = TagStart + SelectStr + TagEnd;
}
// Else selection is not in element
else if (document.selection && document.selection.createRange)
{
ID.focus();
var Range = document.selection.createRange();
Range.text = TagStart + TagEnd + Range.text;
}
} // IE
}
function BTCodeEditorBold (ID)
{
BTCodeEditorAddTag (ID, '[b]', '[/b]');
}
function BTCodeEditorItalic (ID)
{
BTCodeEditorAddTag (ID, '[i]', '[/i]');
}
function BTCodeEditorUnderline (ID)
{
BTCodeEditorAddTag (ID, '[u]', '[/u]');
}
function BTCodeEditorCode (ID)
{
BTCodeEditorAddTag (ID, '[code]', '[/code]');
}
function BTCodeEditorQuote (ID)
{
BTCodeEditorAddTag (ID, '[quote]', '[/quote]');
}
function BTCodeEditorLink (ID)
{
var URL = prompt('URL', '');
var Text = prompt('Display text', '');
BTCodeEditorAddTag (ID, '[link:' + URL + ']' + Text + '[/link]', '');
}
function BTCodeEditorImage (ID)
{
var URL = prompt('Images URL', '');
var Text = prompt('Alternate Text', '');
BTCodeEditorAddTag (ID, '[image:' + URL + ']' + Text + '[/image]', '');
}

