//#################################################################################
//## Copyright (C) 2000-02 Michael Anderson, Pierre Gorissen,
//##                       Huw Reddick and Richard Kinser
//##
//## This program is free software; you can redistribute it and/or
//## modify it under the terms of the GNU General Public License
//## as published by the Free Software Foundation; either version 2
//## of the License, or any later version.
//##
//## All copyright notices regarding Snitz Forums 2000
//## must remain intact in the scripts and in the outputted HTML
//## The "powered by" text/logo with a link back to
//## http://forum.snitz.com in the footer of the pages MUST
//## remain visible when the pages are viewed on the internet or intranet.
//##
//## This program is distributed in the hope that it will be useful,
//## but WITHOUT ANY WARRANTY; without even the implied warranty of
//## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//## GNU General Public License for more details.
//##
//## You should have received a copy of the GNU General Public License
//## along with this program; if not, write to the Free Software
//## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
//##
//## Support can be obtained from support forums at:
//## http://forum.snitz.com
//##
//## Correspondence and Marketing Questions can be sent to:
//## reinhold@bigfoot.com
//##
//## or
//##
//## Snitz Communications
//## C/O: Michael Anderson
//## PO Box 200
//## Harpswell, ME 04079
//#################################################################################

helpstat = false;
stprompt = false;
basic = true;

function thelp(swtch){
        if (swtch == 1){
                basic = false;
                stprompt = false;
                helpstat = true;
        } else if (swtch == 0) {
                helpstat = false;
                stprompt = false;
                basic = true;
        } else if (swtch == 2) {
                helpstat = false;
                basic = false;
                stprompt = true;
        }
}

//function AddText(NewCode) {
//        document.PostTopic.Message.value+=NewCode
//}

function AddText(NewCode) {
        if (document.PostTopic.Message.createTextRange && document.PostTopic.Message.caretPos) {
                var caretPos = document.PostTopic.Message.caretPos;
                caretPos.text = NewCode;
        } else {
                document.PostTopic.Message.value+=NewCode;
        }
        document.PostTopic.Message.focus();
}

function bold() {
        var text = getText();
        if (helpstat) {
                alert("Fett-Tags lassen den eingeschlossenen Text fett erscheinen.\n\nBEISPIEL: [b]Das ist fetter Text[/b]");
        } else if (basic) {
                AddTxt="[b]" + text + "[/b]";
                AddText(AddTxt);
        } else {
                if (text) {
                        txt=prompt("Text, der fett angezeigt werden soll.",text);
                } else {
                        txt=prompt("Text, der fett angezeigt werden soll.","Text");
                }
                if (txt!=null) {
                        AddTxt="[b]"+txt+"[/b]";
                        AddText(AddTxt);
                }
        }
}
function spoiler() {
        var text = getText();
        if (helpstat) {
                alert("Spoiler-Tags verdecken den Text, welcher nur gelesen werden kann, wenn er mit der Maus markiert wird.\n\nBEISPIEL: [spoiler]Dies ist ein Spoiler[/spoiler]");
        } else if (basic) {
                AddTxt="[spoiler]" + text + "[/spoiler]";
                AddText(AddTxt);
        } else {
                if (text) {
                        txt=prompt("Text, der als Spoiler angezeigt werden soll.",text);
                } else {
                        txt=prompt("Text, der als Spoiler angezeigt werden soll.","Text");
                }
                if (txt!=null) {
                        AddTxt="[spoiler]"+txt+"[/spoiler]";
                        AddText(AddTxt);
                }
        }
}
function italicize() {
        var text = getText();
        if (helpstat) {
                alert(" Kursiv-Tags lassen den Text kursiv erscheinen.\n\nBEISPIEL: [i]Das ist kursiver Text[/i]");
        } else if (basic) {
                AddTxt="[i]" + text + "[/i]";
                AddText(AddTxt);
        } else {
                if (text) {
                        txt=prompt("Text der kursiv erscheinen soll",text);
                } else {
                        txt=prompt("Text der kursiv erscheinen soll","Text");
                }
                if (txt!=null) {
                        AddTxt="[i]"+txt+"[/i]";
                        AddText(AddTxt);
                }
        }
}

function underline() {
        var text = getText();
          if (helpstat) {
                alert("Der Unterstreichen - Tag unterstreicht den eingeschlossenen Text.\n\nBEISPIEL: [u]Dieser Text ist unterstrichen[/u]");
        } else if (basic) {
                AddTxt="[u]" + text + "[/u]";
                AddText(AddTxt);
        } else {
                if (text) {
                        txt=prompt("Text der unterstrichen werden soll.",text);
                } else {
                        txt=prompt("Dieser Text ist unterstrichen.","Text");
                }
                if (txt!=null) {
                        AddTxt="[u]"+txt+"[/u]";
                        AddText(AddTxt);
                }
        }
}

function strike() {
        var text = getText();
        if (helpstat) {
                alert("Der Durchstreichen - Tag lässt den eingeschlossenen Text durchgestrichen erscheinen.\n\nBEISPIEL: [s]Dieser Text ist durchgestrichen[/s]");
        } else if (basic) {
                AddTxt="[s]" + text + "[/s]";
                AddText(AddTxt);
        } else {
                if (text) {
                        txt=prompt("Dieser Text ist durchgestrichen.",text);
                } else {
                        txt=prompt("Dieser Text ist durchgestrichen.","Text");
                }
                if (txt!=null) {
                        AddTxt="[s]"+txt+"[/s]";
                        AddText(AddTxt);
                }
        }
}

function left() {
        var text = getText();
         if (helpstat) {
                alert("Der Links - Tag richtet den eingeschlossenen Text links aus.\n\nBEISPIEL: [left]Dieser Text ist links ausgerichtet[/left]");
        } else if (basic) {
                AddTxt="[left]" + text + "[/left]";
                AddText(AddTxt);
        } else {
                if (text) {
                        txt=prompt("Text der links ausgerichtet ist.",text);
                } else {
                        txt=prompt("Text der links ausgerichtet ist.","Text");
                }
                if (txt!=null) {
                        AddTxt="[left]"+txt+"[/left]";
                        AddText(AddTxt);
                }
        }
}

function center() {
        var text = getText();
         if (helpstat) {
                alert("Der Zentrieren - Tag zentriert den eingeschlossenen Text.\n\nBEISPIEL: [center]Dieser Text ist zentriert[/center]");
        } else if (basic) {
                AddTxt="[center]" + text + "[/center]";
                AddText(AddTxt);
        } else {
                if (text) {
                        txt=prompt("Text der zentriert ist.",text);
                } else {
                        txt=prompt("Text der zentriert ist.","Text");
                }
                if (txt!=null) {
                        AddTxt="[center]"+txt+"[/center]";
                        AddText(AddTxt);
                }
        }
}

function right() {
        var text = getText();
         if (helpstat) {
                alert("Der Rechts - Tag richtet den eingeschlossenen Text rechts aus.\n\nUSE: [right]Dieser Text ist rechts ausgerichtet[/right]");
        } else if (basic) {
                AddTxt="[right]" + text + "[/right]";
                AddText(AddTxt);
        } else {
                if (text) {
                        txt=prompt("Text der rechts ausgerichtet ist",text);
                } else {
                        txt=prompt("Text der rechts ausgerichtet ist","Text");
                }
                if (txt!=null) {
                        AddTxt="[right]"+txt+"[/right]";
                        AddText(AddTxt);
                }
        }
}

function hr() {
        var text = getText();
        if (helpstat) {
                alert("Horizontale Linie erstellt eine horizontale Line unter Ihrem Beitrag.\n\nBEISPIEL: [hr]");
        } else {
                AddTxt="[hr]" + text;
                AddText(AddTxt);
        }
}

function hyperlink() {
        var text = getText();
        if (helpstat) {
                alert("Hyperlink Tag \nWandelt eine Url in einen Hyperlink um.\n\nBEISPIEL: [url]http://www.anywhere.com[/url]\n\nBEISPIEL: [url=\"http://www.anywhere.com\"]link text[/url]");
        } else if (basic) {
                AddTxt="[url]" + text + "[/url]";
                AddText(AddTxt);
        } else {
                txt2=prompt("Text der als Link angezeigt werden soll.\nKeine Eingabe, wenn die URL als Link angezeigt werden soll.","");
                if (txt2!=null) {
                        txt=prompt("URL für einen Link.","http://");
                        if (txt!=null) {
                                if (txt2=="") {
                                        AddTxt="[url]"+txt+"[/url]";
                                        AddText(AddTxt);
                                } else {
                                        AddTxt="[url=\""+txt+"\"]"+txt2+"[/url]";
                                        AddText(AddTxt);
                                }
                        }
                }
        }
}

function email() {
        if (helpstat) {
                alert("Email Tag wandelt eine Email Adresse in einen mailto hyperlink.\n\nUSE #1: someone\@anywhere.com \nBEISPIEL #2: [url=\"someone\@anywhere.com\"]Link Text[/url]");
                }
        else {
                txt2=prompt("Text der für den Link erscheinen soll. Keine Eingabe, wenn die Adresse selbst angezeigt werden soll.","");
                if (txt2!=null) {
                        txt=prompt("URL für den Link.","mailto:");
                        if (txt!=null) {
                                if (txt2=="") {
                                        AddTxt=txt;
                                        AddText(AddTxt);
                                } else {
                                        AddTxt="[url=\""+txt+"\"]"+txt2+"[/url]";
                                        AddText(AddTxt);
                                }
                        }
                }
        }
}

function image() {
        var text = getText();
        if (helpstat){
                alert("Der Bild Tag fügt ein Bild in den Beitrag ein.\n\nBEISPIEL: [img]http://www.anywhere.com/image.gif[/img]");
        } else if (basic) {
                AddTxt="[img]" + text + "[/img]";
                AddText(AddTxt);
        } else {
                txt=prompt("URL für das Bild","http://");
                if(txt!=null) {
                        AddTxt="[img]"+txt+"[/img]";
                        AddText(AddTxt);
                }
        }
}

function showcode() {
        var text = getText();
        if (helpstat) {
                alert("Code-Tags bewahren den Text vor einer Formatierung.\nNützlich, wenn Sie Code einfügen wollen.\n\nBEISPIEL: [code]Das ist Ihr Code[/code]");
        } else if (basic) {
                AddTxt="[code]" + text + "[/code]";
                AddText(AddTxt);
        } else {
                txt=prompt("Ihren Code eingeben","");
                if (txt!=null) {
                        AddTxt="[code]"+txt+"[/code]";
                        AddText(AddTxt);
                }
        }
}

function quote() {
        var text = getText();
        if (helpstat){
                alert("Zitat Tag zitiert den eingeschlossenen Text, um Bezug auf einen Beitrag einer anderen Person zu nehmen.\n\nBEISPIEL: [quote]Das ist ein Zitat[/quote]");
        } else if (basic) {
                AddTxt=" [quote]" + text + "[/quote]";
                AddText(AddTxt);
        } else {
                if (text) {
                        txt=prompt("Text der zitiert werden soll",text);
                } else {
                        txt=prompt("Text der zitiert werden soll","Text");
                }
                if(txt!=null) {
                        AddTxt=" [quote] "+txt+" [/quote]";
                        AddText(AddTxt);
                }
        }
}

function list() {
        if (helpstat) {
                alert("Listen-Tags erstellen eine ungeordnete, nummerierte oder alphabetische Liste.\n\nBEISPIEL: [list] [*]Punkt1[/*] [*]Punkt2[/*] [*]Punkt3[/*] [/list]");
        } else if (basic) {
                AddTxt=" [list][*]  [/*][*]  [/*][*]  [/*][/list]";
                AddText(AddTxt);
        } else {
                type=prompt("Art der Liste, tippen Sie \'A\' für alphabetisch, \'1\' für numeriert, keine Eingabe für ungeordnet.","");
                while ((type!="") && (type!="A") && (type!="a") && (type!="1") && (type!=null)) {
                        type=prompt("FEHLER! Die möglichen Eingaben sind, 'keine Eingabe', 'A' und '1'.","");
                }
                if (type!=null) {
                        if (type=="") {
                                AddTxt="[list]";
                        } else {
                                AddTxt="[list="+type+"]";
                        }
                        txt="1";
                        while ((txt!="") && (txt!=null)) {
                                txt=prompt("Um die Liste zu beenden, lassen Sie das Eingabefeld leer.","");
                                if (txt!="") {
                                        AddTxt+="[*]"+txt+"[/*]";
                                }
                        }
                        if (type=="") {
                                AddTxt+="[/list] ";
                        } else {
                                AddTxt+="[/list="+type+"]";
                        }
                        AddText(AddTxt);
                }
        }
}

function showfont(font) {
        var text = getText();
         if (font) {
                 if (helpstat) {
                        alert("Schriftarten-Tags bestimmen die Schriftart des eingeschlossenen Textes.\n\nBEISPIEL: [font="+font+"]Die Schriftart dieses Textes ist "+font+"[/font]");
                } else if (basic) {
                        AddTxt="[font="+font+"]" + text + "[/font="+font+"]";
                        AddText(AddTxt);
                } else {
                        if (text) {
                                txt=prompt("Text in "+font,text);
                        } else {
                                txt=prompt("Text in "+font,"Text");
                        }
                        if (txt!=null) {
                                AddTxt="[font="+font+"]"+txt+"[/font="+font+"]";
                                AddText(AddTxt);
                        }
                }
        document.PostTopic.Font.selectedIndex = 0;
        }
}

function showsize(size) {
        var text = getText();
        if (size) {
                if (helpstat) {
                        alert("Größe Tag bestimmt die Textgröße. Mögliche Werte sind 1 bis 6.\n1 die kleinste und 6 der größte Schriftgröße.\n\nBEISPIEL: [size="+size+"]Das ist Größe "+size+" Text[/size="+size+"]");
                } else if (basic) {
                        AddTxt="[size="+size+"]" + text + "[/size="+size+"]";
                        AddText(AddTxt);
                } else {
                        if (text) {
                                txt=prompt("Text in Größe "+size,text);
                        } else {
                                txt=prompt("Text in Größe "+size,"Text");
                        }
                        if (txt!=null) {
                                AddTxt="[size="+size+"]"+txt+"[/size="+size+"]";
                                AddText(AddTxt);
                        }
                }
        document.PostTopic.Size.selectedIndex = 0;
        }
}

function showcolor(color) {
        var text = getText();
        if (color) {
                if (helpstat) {
                        alert("Farb Tag bestimmt die Textfarbe. Jede der aufgeführten Farben kann verwendet werden.\n\nBEISPIEL: ["+color+"]Das ist etwas Text in "+color+"[/"+color+"]");
                } else if (basic) {
                        AddTxt="["+color+"]" + text + "[/"+color+"]";
                        AddText(AddTxt);
                } else {
                        if (text) {
                                     txt=prompt("Text in Farbe "+color,text);
                        } else {
                                     txt=prompt("Text in Farbe "+color,"Text");
                        }
                        if(txt!=null) {
                                AddTxt="["+color+"]"+txt+"[/"+color+"]";
                                AddText(AddTxt);
                        }
                }
        document.PostTopic.Color.selectedIndex = 0;
        }
}

function resizeTextarea()
{
        if (document.PostTopic.SelectSize.value == 1)
        {
                document.PostTopic.Message.cols = 45;
                document.PostTopic.Message.rows = 11;
        }
        if (document.PostTopic.SelectSize.value == 2)
        {
                document.PostTopic.Message.cols = 70;
                document.PostTopic.Message.rows = 12;
        }
        if (document.PostTopic.SelectSize.value == 3)
        {
                document.PostTopic.Message.cols = 90;
                document.PostTopic.Message.rows = 12;
        }
        if (document.PostTopic.SelectSize.value == 4)
        {
                document.PostTopic.Message.cols = 130;
                document.PostTopic.Message.rows = 15;
        }
}

function storeCaret(ftext) {
        if (ftext.createTextRange) {
                ftext.caretPos = document.selection.createRange().duplicate();
        }
}

function getText() {
        if (document.PostTopic.Message.createTextRange && document.PostTopic.Message.caretPos) {
                return document.PostTopic.Message.caretPos.text;
        } else {
                return '';
        }
}

function OpenPreview()
{
        if (document.PostTopic.Message) {
                if (trim(document.PostTopic.Message.value)=="") {
                        alert("Nichts anzuzeigen!")
                        return false
                }
                popupWin = window.open('pop_preview.asp', 'preview_page', 'scrollbars=yes,width=750,height=450')
                return true
        }
}

function OpenSigPreview()
{
        if (document.Form1.Sig) {
                if (trim(document.Form1.Sig.value)=="") {
                        alert("Nichts anzuzeigen!")
                        return false
                }
                popupWin = window.open('pop_preview_sig.asp', 'preview_page', 'scrollbars=yes,width=750,height=450')
                return true
        }
}

function validate(){
        if (document.PostTopic.Subject) {
                if (trim(document.PostTopic.Subject.value)=="") {
                        alert("Geben Sie einen Betreff ein")
                        return false
                }
        }
        if (document.PostTopic.Message) {
                if (trim(document.PostTopic.Message.value)=="") {
                        alert("Geben Sie eine Nachtricht ein")
                        return false
                }
        }
        return true
}

function ResetForm(form) {
        var where_to= confirm("Möchten Sie wirklich alle Felder zurücksetzen?");
        if (where_to== true) {
                form.reset();
        }
}

//code below found here:  http://www.marzie.com/devtools/javascript/functions.asp

function ltrim(s) {
        return s.replace( /^\s*/, "" );
}
function rtrim(s) {
        return s.replace( /\s*$/, "" );
}
function trim ( s ) {
        return rtrim(ltrim(s));
}
