function edButton(id, display, tagStart, tagEnd, access, open) {
this.id = id; // used to name the toolbar button
this.display = display; // label on button
this.tagStart = tagStart; // open tag
this.tagEnd = tagEnd; // close tag
this.access = access; // set to -1 if tag does not need to be closed
this.open = open; // set to -1 if tag does not need to be closed
}
function edLink(display, URL, newWin) {
this.display = display;
this.URL = URL;
if (!newWin) {
newWin = 0;
}
this.newWin = newWin;
}
function edShowButton(button, i) {
if (button.access) {
var accesskey = ' accesskey = "' + button.access + '"'
}
else {
var accesskey = '';
}
switch (button.id) {
case 'ed_img':
document.write('
');
break;
case 'ed_link':
document.write('
');
break;
case 'ed_close':
document.write('
');
break;
default:
document.write('
');
break;
}
}
function edShowLinks() {
var tempStr = '
';
document.write(tempStr);
}
function edAddTag(button) {
if (edButtons[button].tagEnd != '') {
edOpenTags[edOpenTags.length] = button;
document.getElementById(edButtons[button].id).value = '/' + document.getElementById(edButtons[button].id).value;
}
}
function edRemoveTag(button) {
for (i = 0; i < edOpenTags.length; i++) {
if (edOpenTags[i] == button) {
edOpenTags.splice(i, 1);
document.getElementById(edButtons[button].id).value = document.getElementById(edButtons[button].id).value.replace('/', '');
}
}
}
function edCheckOpenTags(button) {
var tag = 0;
for (i = 0; i < edOpenTags.length; i++) {
if (edOpenTags[i] == button) {
tag++;
}
}
if (tag > 0) {
return true; // tag found
}
else {
return false; // tag not found
}
}
function edCloseAllTags() {
var count = edOpenTags.length;
for (o = 0; o < count; o++) {
edInsertTag(edCanvas, edOpenTags[edOpenTags.length - 1]);
}
}
function edQuickLink(i, thisSelect) {
if (i > -1) {
var newWin = '';
if (edLinks[i].newWin == 1) {
newWin = ' target="_blank"';
}
var tempStr = '
'
+ edLinks[i].display
+ '
';
thisSelect.selectedIndex = 0;
edInsertContent(edCanvas, tempStr);
}
else {
thisSelect.selectedIndex = 0;
}
}
function edToolbar() {
document.write('
');
for (i = 0; i < extendedStart; i++) {
edShowButton(edButtons[i], i);
}
for (i = extendedStart; i < edButtons.length; i++) {
edShowButton(edButtons[i], i);
}
// edShowLinks();
document.write('
');
}
// insertion code
function edInsertTag(myField, i) {
//IE support
if (document.selection) {
myField.focus();
sel = document.selection.createRange();
if (sel.text.length > 0) {
sel.text = edButtons[i].tagStart + sel.text + edButtons[i].tagEnd;
}
else {
if (!edCheckOpenTags(i) || edButtons[i].tagEnd == '') {
sel.text = edButtons[i].tagStart;
edAddTag(i);
}
else {
sel.text = edButtons[i].tagEnd;
edRemoveTag(i);
}
}
myField.focus();
}
//MOZILLA/NETSCAPE support
else if (myField.selectionStart || myField.selectionStart == '0') {
var startPos = myField.selectionStart;
var endPos = myField.selectionEnd;
var cursorPos = endPos;
var scrollTop = myField.scrollTop;
if (startPos != endPos) {
myField.value = myField.value.substring(0, startPos)
+ edButtons[i].tagStart
+ myField.value.substring(startPos, endPos)
+ edButtons[i].tagEnd
+ myField.value.substring(endPos, myField.value.length);
cursorPos += edButtons[i].tagStart.length + edButtons[i].tagEnd.length;
}
else {
if (!edCheckOpenTags(i) || edButtons[i].tagEnd == '') {
myField.value = myField.value.substring(0, startPos)
+ edButtons[i].tagStart
+ myField.value.substring(endPos, myField.value.length);
edAddTag(i);
cursorPos = startPos + edButtons[i].tagStart.length;
}
else {
myField.value = myField.value.substring(0, startPos)
+ edButtons[i].tagEnd
+ myField.value.substring(endPos, myField.value.length);
edRemoveTag(i);
cursorPos = startPos + edButtons[i].tagEnd.length;
}
}
myField.focus();
myField.selectionStart = cursorPos;
myField.selectionEnd = cursorPos;
myField.scrollTop = scrollTop;
}
else {
if (!edCheckOpenTags(i) || edButtons[i].tagEnd == '') {
myField.value += edButtons[i].tagStart;
edAddTag(i);
}
else {
myField.value += edButtons[i].tagEnd;
edRemoveTag(i);
}
myField.focus();
}
}
function edInsertContent(myField, myValue) {
//IE support
if (document.selection) {
myField.focus();
sel = document.selection.createRange();
sel.text = myValue;
myField.focus();
}
//MOZILLA/NETSCAPE support
else if (myField.selectionStart || myField.selectionStart == '0') {
var startPos = myField.selectionStart;
var endPos = myField.selectionEnd;
var scrollTop = myField.scrollTop;
myField.value = myField.value.substring(0, startPos)
+ myValue
+ myField.value.substring(endPos, myField.value.length);
myField.focus();
myField.selectionStart = startPos + myValue.length;
myField.selectionEnd = startPos + myValue.length;
myField.scrollTop = scrollTop;
} else {
myField.value += myValue;
myField.focus();
}
}
function edInsertLink(myField, i, defaultValue) {
if (!defaultValue) {
defaultValue = 'http://';
}
if (!edCheckOpenTags(i)) {
var URL = prompt('Enter the URL' ,defaultValue);
if (URL) {
edButtons[i].tagStart = '
';
edInsertTag(myField, i);
}
}
else {
edInsertTag(myField, i);
}
}
function edInsertImage(myField) {
var myValue = prompt('Enter the URL of the image', 'http://');
if (myValue) {
myValue = '
';
edInsertContent(myField, myValue);
}
}
function countInstances(string, substr) {
var count = string.split(substr);
return count.length - 1;
}
/**************************************/
var edButtons = new Array();
var edLinks = new Array();
var edOpenTags = new Array();
edButtons[edButtons.length] = new edButton('ed_strong', 'b', '
', '
', 'b');edButtons[edButtons.length] = new edButton('ed_em', 'i', '
', '
', 'i');edButtons[edButtons.length] = new edButton('ed_del', 'del', '
', '
', 'd');edButtons[edButtons.length] = new edButton('ed_link', 'ÃÂÃÂÃÂðòøÃÂàÃÂÃÂÃÂûúÃÂ', '
', '
', '');edButtons[edButtons.length] = new edButton('ed_img', 'ÃÂÃÂÃÂðòøÃÂàúðÃÂÃÂøýúÃÂ', '
', '', '');edButtons[edButtons.length] = new edButton('ed_block', 'b-quote', '
', '
', 'q');edButtons[edButtons.length] = new edButton('ed_code', 'code', '
', '
', 'c');edButtons[edButtons.length] = new edButton('ed_close', 'Close Tags', '', '', '');
var extendedStart = edButtons.length;
Â