var postMax = 10000;
var selText = "";
var prompt_text = "Geben Sie einen Text ein:";
var prompt_link_text = "Geben Sie einen Linknamen ein (optional)";
var prompt_link_url = "Geben Sie jetzt die volle Adresse des Links ein";
var prompt_link_email = "Geben Sie eine eMail Adresse ein";
var prompt_list_typ = "Um eine nummerierte Liste zu erstellen gebe '1' ein oder für eine punktierte 'a' oder nichts.";
var prompt_list_item = "Geben Sie einen Listenpunkt ein, oder drücken Sie 'abbrechen' um die Liste fertigzustellen.";
var textStart = 0;
var textEnd = 0;

//# liefert den aktuell selektierten Text
function getActiveText(textBox) {
    // IE
    if (document.selection) {
        theSelection = window.document.selection.createRange();
        selText = theSelection.text;
        
    // Mozilla
    } else if (window.getSelection) {
        oldValue = textBox.value;
        textStart = textBox.selectionStart;
        textEnd = textBox.selectionEnd;
        if ((textEnd-textStart)+1 > 0) {
            selText = oldValue.substring(textStart, textEnd);
        } else {
            selText = "";
        }
        
    // other
    } else {
        selText = "";
    }
    
    return true;
}
//# hinzufÃ¼gen des Board-Codes
function AddCode(theForm, theText) {
    
    theForm.focus();
    
    // IE
    if (document.selection) {
        theSelection = window.document.selection.createRange();
        theSelection.text = theText;
        
    // Mozilla
    } else if (window.getSelection) {
        oldValue = new String(theForm.value);
        textStart = theForm.selectionStart;
        textEnd = theForm.selectionEnd;
        theForm.value = oldValue.substring(0, textStart) + theText + oldValue.substring(textEnd, oldValue.length);
        
    // other
    } else {
        theForm.value += theText;
    }
}
//# Popup fÃ¼r 'bbcodes'
function bbcodes(theform,bbcode,prompttext) {
    advtext = (prompttext) ? prompttext : selText;
    inserttext = prompt(prompt_text+' ['+bbcode+']xxx[/'+bbcode+']', advtext);
    if ((inserttext != null) && (inserttext != '')) {
        AddCode(theform.text,'['+bbcode+']'+inserttext+'[/'+bbcode+']');
    }
}
//# Popup fuer 'Schrift-Formatierung'
function bbfont(theform,bbvalue,thetype) {
    if (bbvalue != 0) {
        advtext = (selText) ? selText : '';
        inserttext = prompt(prompt_text+' '+thetype, advtext);
        if ((inserttext != null) && (inserttext != '')) {
            AddCode(theform.text,'['+thetype+'='+bbvalue+']'+inserttext+'[/'+thetype+']');
        }
    }
    theform.select_size.selectedIndex = 0;
    theform.select_font.selectedIndex = 0;
    theform.select_color.selectedIndex = 0;
    theform.select_align.selectedIndex = 0;
}
//# Popup fÃ¼r 'Liste'
function bblist(theform) {
    listtype = prompt(prompt_list_typ, '');
    if ((listtype == 'a') || (listtype == '1')) {
        list_anf = '[list='+listtype+']\n';
        list_end = '[/list='+listtype+'] ';
    } else {
        list_anf = '[list]\n';
        list_end = '[/list]';
    }
    list_entry = 'anf';
    list_values = '';
    while ((list_entry != '') && (list_entry != null)) {
        list_entry = prompt(prompt_list_item, '');
        if ((list_entry != '') && (list_entry != null)) {
            list_values = list_values+'[*]'+list_entry+'\n';
        }
    }
    if (list_values != '') {
        AddCode(theform.text, list_anf+list_values+list_end);
    }
}
//# Popup fÃ¼r 'benannten Link'
function bbnamed(theform,thetype) {
    advtext = (selText) ? selText : '';
    link_text = prompt(prompt_link_text, advtext);
    if (thetype == 'URL') {
        ptext = prompt_link_url;
        advtext = 'http://';
    } else {
        ptext = prompt_link_email;
        advtext = '';
    }
    link_url = prompt(ptext,advtext);
    if ((link_url != null) && (link_url != '')) {
        if ((link_text != null) && (link_text != '')) {
            AddCode(theform.text,'['+thetype+'='+link_url+']'+link_text+'[/'+thetype+']');
        } else {
            AddCode(theform.text,'['+thetype+']'+link_url+'[/'+thetype+']');
        }
    }
}
//# Smilies :)
function bbsmilie(thesmilie) {
    AddCode(document.bbform.text, thesmilie);
}
//# Nachricht nicht leer ?!
function validate(theform, disableForm) {
    if (theform.message.value=='') {
        alert("Nachrichtfeld muß ausgefüllt werden!");
        return false;
    } else if (theform.message.value.length > postMax) {
        alert("Ihre Nachricht ist zu lang. Bitte reduzieren Sie diese auf "+postMax+" Zeichen. Momentan ist sie "+theform.message.value.length+" Zeichen.");
        return false;
    } else {
        if (disableForm) disableForm.disabled=true;
        return true;
    }
}
//# laenge der Nachricht
function checklength(theform) {
    if (theform.message.value != '') {
        message = "Die maximale Länge liegt bei "+postMax+" Zeichen.";
    } else {
        message = "";
    }
    alert("Ihre Nachricht ist "+theform.message.value.length+" Zeichen lang. "+message);
}