function
getPageCoords (elementId) {
var
element;
if
(document.all) {
element = document.all[elementId];
}
else
if
(document.getElementById) {
element = document.getElementById(elementId);
}
if
(element) {
var
coords = {x: 0, y: 0};
do
{
coords.x += element.offsetLeft;
coords.y += element.offsetTop;
element = element.offsetParent;
}
while
(element)
return
coords;
}
else
return
null;
}
function
hide_color() {
if
(document.getElementById(
"colorinput"
).style.display==
"block"
) {
document.getElementById(
"colorinput"
).style.display=
"none"
;
}
else
{
var
pos = getPageCoords(
"bbcode_color_button"
);
document.getElementById(
"colorinput"
).style.top = pos.y - 15 +
"px"
;
document.getElementById(
"colorinput"
).style.left = pos.x - 130 - document.getElementsByTagName(
'div'
)[0].offsetLeft +
"px"
;
document.getElementById(
"colorinput"
).style.display=
"block"
;
}
}
function
bbcode_insert(tag,boxtext) {
var
formular = document.forms[
'form'
].elements[
'txt'
];
formular.focus();
var
begin_tag =
"["
+tag+
"]"
;
var
end_tag =
"[/"
+tag+
"]"
;
var
list_x =
''
;
var
list_text =
''
;
if
(typeof document.selection !=
'undefined'
) {
var
range = document.selection.createRange();
var
prompt_box;
if
(tag ==
'list'
) {
if
(range.text == null || range.text ==
''
) {
while
( list_x != null ) {
list_x = prompt (boxtext);
if
( list_x != null ) {
list_text = list_text +
"[*]"
+ list_x +
"\n"
;
}
}
if
( list_text !=
''
) {
prompt_box = list_text;
}
}
else
{
while
( list_x != null ) {
list_x = prompt (boxtext,range.text);
if
( list_x != null ) {
list_text = list_text +
"[*]"
+ list_x +
"\n"
;
}
}
if
( list_text !=
''
) {
prompt_box = list_text;
}
}
}
else
{
if
(range.text == null || range.text ==
''
) {
prompt_box = prompt(boxtext,
""
);
}
else
{
prompt_box = prompt(boxtext,range.text);
}
}
if
(prompt_box != null && prompt_box !=
''
) {
range.text = begin_tag + prompt_box + end_tag;
range = document.selection.createRange();
if
(prompt_box.length == 0) {
range.move(
'character'
, -end_tag.length);
}
else
{
range.moveStart(
'character'
, begin_tag.length + prompt_box.length + end_tag.length);
}
range.select();
}
}
else
if
(typeof formular.selectionStart !=
'undefined'
) {
var
start = formular.selectionStart;
var
end
= formular.selectionEnd;
var
prompt_box;
if
(tag ==
'list'
) {
if
(formular.value.substring(start,
end
) == null || formular.value.substring(start,
end
) ==
''
) {
while
( list_x != null ) {
list_x = prompt (boxtext);
if
( list_x != null ) {
list_text = list_text +
"[*]"
+ list_x +
"\n"
;
}
}
if
( list_text !=
''
) {
prompt_box = list_text;
}
}
else
{
while
( list_x != null ) {
list_x = prompt (boxtext,formular.value.substring(start,
end
));
if
( list_x != null ) {
list_text = list_text +
"[*]"
+ list_x +
"\n"
;
}
}
if
( list_text !=
''
) {
prompt_box = list_text;
}
}
}
else
{
if
(formular.value.substring(start,
end
) == null || formular.value.substring(start,
end
) ==
''
) {
prompt_box = prompt(boxtext,
""
);
}
else
{
prompt_box = prompt(boxtext,formular.value.substring(start,
end
));
}
}
if
(prompt_box != null && prompt_box !=
''
) {
if
(tag ==
'list'
) {
formular.value = formular.value.
substr
(0, start) + begin_tag +
"\n"
+ prompt_box + end_tag + formular.value.
substr
(
end
);
}
else
{
formular.value = formular.value.
substr
(0, start) + begin_tag + prompt_box + end_tag + formular.value.
substr
(
end
);
}
var
pos;
if
(prompt_box.length == 0) {
pos = start + begin_tag.length;
}
else
{
if
(tag ==
'list'
) {
pos = start + begin_tag.length + prompt_box.length + end_tag.length +1;
}
else
{
pos = start + begin_tag.length + prompt_box.length + end_tag.length;
}
}
formular.selectionStart = pos;
formular.selectionEnd = pos;
}
}
function
simple_insert(aTag,eTag) {
var
input = document.forms[
'form'
].elements[
'txt'
];
input.focus();
if
(typeof document.selection !=
'undefined'
) {
var
range = document.selection.createRange();
var
insText = range.text;
range.text = aTag + insText + eTag;
range = document.selection.createRange();
if
(insText.length == 0) {
range.move(
'character'
, -eTag.length);
}
else
{
range.moveStart(
'character'
, aTag.length + insText.length + eTag.length);
}
range.select();
}
else
if
(typeof input.selectionStart !=
'undefined'
)
{
var
start = input.selectionStart;
var
end
= input.selectionEnd;
var
insText = input.value.substring(start,
end
);
input.value = input.value.
substr
(0, start) + aTag + insText + eTag + input.value.
substr
(
end
);
var
pos;
if
(insText.length == 0) {
pos = start + aTag.length;
}
else
{
pos = start + aTag.length + insText.length + eTag.length;
}
input.selectionStart = pos;
input.selectionEnd = pos;
}
else
{
var
pos = input.value.length;
var
insText = prompt(
"Bitte geben Sie den zu formatierenden Text ein:"
);
input.value = input.value.
substr
(0, pos) + aTag + insText + eTag + input.value.
substr
(pos);
}
}
function
insertvote(){
var
x =
''
;
var
l =
''
;
var
i = 0;
var
q = prompt(
"Hier die Umfragebeschreibung eingeben:"
);
while
( x != null ) {
x = prompt (
"Hier die Optionen der Umfrage einzeln eintragen, jede mit OK bestätigen!\nUm die Aufnahme von Optionen zu beenden 'Abbrechen' drücken"
);
i++;
if
( x != null ) {
l = l +
"[option="
+ i +
"]"
+ x +
"\n"
;
}
}
if
( (( q !=
''
) && ( l !=
''
)) && (i >= 2) ) {
l =
"[vote]\n"
+
'[question]'
+ q +
'[/question]\n'
+ l +
"[/vote]"
;
simple_insert ( l,
''
);
}
}
}
}
function
bbcode_insert_with_value_2(tag,boxtext1,boxtext2) {
var
formular = document.forms[
'form'
].elements[
'txt'
];
formular.focus();
var
default_text;
if
(tag ==
'video'
) {
default_text =
"MyVideo"
;
}
else
{
default_text =
""
;
}
if
(typeof document.selection !=
'undefined'
) {
var
range = document.selection.createRange();
var
prompt_text1;
var
prompt_text2;
var
prompt_box;
prompt_text2 = prompt(boxtext2,default_text);
if
(range.text == null || range.text ==
''
) {
prompt_text1 = prompt(boxtext1,
""
);
}
else
{
prompt_text1 = prompt(boxtext1,range.text);
}
if
(prompt_text1 != null && prompt_text1 !=
''
) {
if
(prompt_text2 != null && prompt_text2 !=
''
) {
prompt_box =
"["
+tag+
"="
+prompt_text2+
"]"
+prompt_text1+
"[/"
+tag+
"]"
;
}
}
else
if
(tag ==
'url'
|| tag ==
'email'
) {
if
(prompt_text2 != null && prompt_text2 !=
''
) {
prompt_box =
"["
+tag+
"]"
+prompt_text2+
"[/"
+tag+
"]"
;
}
}
if
(prompt_box != null && prompt_box !=
''
) {
range.text = prompt_box;
range = document.selection.createRange();
if
(prompt_box.length == 0) {
range.move(
'character'
, -tag.length);
}
else
{
range.moveStart(
'character'
, prompt_box.length);
}
range.select();
}
}
else
if
(typeof formular.selectionStart !=
'undefined'
) {
var
start = formular.selectionStart;
var
end
= formular.selectionEnd;
var
prompt_text1;
var
prompt_text2;
var
prompt_box;
prompt_text2 = prompt(boxtext2,default_text);
if
(formular.value.substring(start,
end
) == null || formular.value.substring(start,
end
) ==
''
) {
prompt_text1 = prompt(boxtext1,
""
);
}
else
{
prompt_text1 = prompt(boxtext1,formular.value.substring(start,
end
));
}
if
(prompt_text1 != null && prompt_text1 !=
''
) {
if
(prompt_text2 != null && prompt_text2 !=
''
) {
prompt_box =
"["
+tag+
"="
+prompt_text2+
"]"
+prompt_text1+
"[/"
+tag+
"]"
;
}
}
else
if
(tag ==
'url'
|| tag ==
'email'
) {
if
(prompt_text2 != null && prompt_text2 !=
''
) {
prompt_box =
"["
+tag+
"]"
+prompt_text2+
"[/"
+tag+
"]"
;
}
}
if
(prompt_box != null && prompt_box !=
''
) {
formular.value = formular.value.
substr
(0, start) + prompt_box + formular.value.
substr
(
end
);
var
pos;
if
(prompt_box.length == 0) {
pos = start + tag.length;
}
else
{
pos = start + prompt_box.length;
}
formular.selectionStart = pos;
formular.selectionEnd = pos;
}
}
}
function
bbcode_code_insert(tag,color) {
var
formular = document.forms[
'form'
].elements[
'txt'
];
formular.focus();
if
(color ==
"0"
){
var
begin_tag =
"["
+tag+
"]"
;
var
end_tag =
"[/"
+tag+
"]"
;
if
(document.form.code != undefined) {
document.form.code.options[
'0'
].selected = true;
}
}
else
if
(tag ==
"code"
|| tag ==
"php"
|| tag ==
"html"
|| tag ==
"css"
) {
prompt_text1 = prompt(
"Format: dateiname;5 (Im Beispiel ist die Startzeile 5)\nSie können hier nun einen Dateinamen und eine Startzeile mit angeben,\nwobei die Startzeile optional ist und auch das komplette Feld leer gelassen werden kann.)"
,
""
);
if
(prompt_text1 !=
""
&& prompt_text1 != null) {
var
begin_tag =
"["
+tag+
"="
+prompt_text1+
"]"
;
}
else
{
var
begin_tag =
"["
+tag+
"]"
;
}
var
end_tag =
"[/"
+tag+
"]"
;
}
else
{
var
begin_tag =
"["
+tag+
"="
+color+
"]"
;
var
end_tag =
"[/"
+tag+
"]"
;
}
if
(typeof document.selection !=
'undefined'
) {
var
range = document.selection.createRange();
var
prompt_box = range.text;
if
(tag ==
"php"
&& prompt_box.match(/(\<\?)/i) && prompt_box.match(/(\?\>)/i)) {
prompt_box;
}
else
if
(tag ==
"php"
) {
prompt_box =
"<?php\n"
+prompt_box+
"\n?>"
;
}
range.text = begin_tag + prompt_box + end_tag;
range = document.selection.createRange();
if
(prompt_box.length == 0) {
range.move(
'character'
, -end_tag.length);
}
else
{
range.moveStart(
'character'
, begin_tag.length + prompt_box.length + end_tag.length);
}
range.select();
}
else
if
(typeof formular.selectionStart !=
'undefined'
) {
var
start = formular.selectionStart;
var
end
= formular.selectionEnd;
var
prompt_box = formular.value.substring(start,
end
);
if
(tag ==
"php"
&& prompt_box.match(/(\<\?)/i) && prompt_box.match(/(\?\>)/i)) {
prompt_box;
}
else
if
(tag ==
"php"
) {
prompt_box =
"<?php\n"
+prompt_box+
"\n?>"
;
}
formular.value = formular.value.
substr
(0, start) + begin_tag + prompt_box + end_tag + formular.value.
substr
(
end
);
var
pos;
if
(prompt_box.length == 0) {
pos = start + begin_tag.length;
}
else
{
pos = start + begin_tag.length + prompt_box.length + end_tag.length;
}
formular.selectionStart = pos;
formular.selectionEnd = pos;
}
}
function
bbcode_code_insert_codes(tag) {
if
(tag !=
"0"
) {
bbcode_code_insert(tag,
'1'
);
}
}
function
simple_insert(aTag,eTag) {
var
input = document.forms[
'form'
].elements[
'txt'
];
input.focus();
if
(typeof document.selection !=
'undefined'
) {
var
range = document.selection.createRange();
var
insText = range.text;
range.text = aTag + insText + eTag;
range = document.selection.createRange();
if
(insText.length == 0) {
range.move(
'character'
, -eTag.length);
}
else
{
range.moveStart(
'character'
, aTag.length + insText.length + eTag.length);
}
range.select();
}
else
if
(typeof input.selectionStart !=
'undefined'
)
{
var
start = input.selectionStart;
var
end
= input.selectionEnd;
var
insText = input.value.substring(start,
end
);
input.value = input.value.
substr
(0, start) + aTag + insText + eTag + input.value.
substr
(
end
);
var
pos;
if
(insText.length == 0) {
pos = start + aTag.length;
}
else
{
pos = start + aTag.length + insText.length + eTag.length;
}
input.selectionStart = pos;
input.selectionEnd = pos;
}
else
{
var
pos = input.value.length;
var
insText = prompt(
"Bitte geben Sie den zu formatierenden Text ein:"
);
input.value = input.value.
substr
(0, pos) + aTag + insText + eTag + input.value.
substr
(pos);
}
}
function
insertvote(){
var
x =
''
;
var
l =
''
;
var
i = 0;
var
q = prompt(
"Hier die Umfragebeschreibung eingeben:"
);
while
( x != null ) {
x = prompt (
"Hier die Optionen der Umfrage einzeln eintragen, jede mit OK bestätigen!\nUm die Aufnahme von Optionen zu beenden 'Abbrechen' drücken"
);
i++;
if
( x != null ) {
l = l +
"[option="
+ i +
"]"
+ x +
"\n"
;
}
}
if
( (( q !=
''
) && ( l !=
''
)) && (i >= 2) ) {
l =
"[vote]\n"
+
'[question]'
+ q +
'[/question]\n'
+ l +
"[/vote]"
;
simple_insert ( l,
''
);
}