//Variables for controlling opening and closing tags (function tag)
//Functions written by boyashi (boyashi@gmail.com)

var b = 2;
var i = 2;
var u = 2;
var q = 2;
var c = 2;
var url = 2;
var img = 2;

//Function for creating non-font tags

function tag(v, tagadd, newbut, tagclose, oldbut, name) {
    if (eval(v)%2 == 0) {
        eval("window.document.editpost."+name+".value = newbut;");
        var ffbody = window.document.editpost.ffbody.value;
        window.document.editpost.ffbody.value = ffbody + tagadd;
        window.document.editpost.ffbody.focus();
    } else {
        eval("window.document.editpost."+name+".value = oldbut;");
        var ffbody = window.document.editpost.ffbody.value;
        window.document.editpost.ffbody.value = ffbody + tagclose;
        window.document.editpost.ffbody.focus();
    }
    eval(v+"++;");
}
//Function for adding font color and size tags

function font(bbopen, bbclose) {
        var ffbody = document.editpost.ffbody;
        ffbody.value += bbopen + bbclose;
        ffbody.focus();
        return;
}
//Function for adding smilies

function smilie (smilie) {
        var ffbody = document.editpost.ffbody;
        ffbody.value += smilie;
        ffbody.focus();
        return;
}
//Helpbox messages
bold_help = "Testo Grassetto: [b]text[/b]";
italic_help = "Testo Italico: [i]text[/i]";
underline_help = "Testo Sottolineato: [u]text[/u]";
quote_help = "Cita Testo: [quote]text[/quote] oppure [quote=name]text[/quote]";
code_help = "Codice: [code]code[/code]";
img_help = "Inserisci Immagine: [img]http://image_url[/img]";
url_help = "Inserisci URL: [url]http://url[/url] oppure [url=http://url]URL text[/url]";
fontcolor_help = "Colore Font: [color=red]text[/color]  Suggerimento: puoi usare anche color=#FF0000";
fontsize_help = "Dimensione Font: [size=50%]small text[/size]";

//Function for displaying help information

// Shows the help messages in the helpline window
function helpline(help) {
        var helpbox = document.editpost.helpbox;
        helpbox.value = eval(help + "_help");
}
//Function to confirm reset

function confirm_reset () {
        if(confirm("Confermando perderai quanto inserito fino ad ora.\n\n" +
                "Clicca su OK per procedere e ricominciare.\n\nOppure clicca su Annulla per continuare " +
                "a scrivere il tuo messaggio.")){ return true;}
        else {return false;}
}
//Check the form submission for errors

function checkForm() {
        var subj = document.editpost.subj;
        var ffbody = document.editpost.ffbody;

        //Check to make sure post lengths are sensible

        if (subj.value.length < 2 && ffbody.value.length < 2) {
                alert("This is a short post!" + " \n \n " +
                                "We require that each post (and subject) \n" +
                                "be at least 2 characters long. \n \n" +
                                "Go back and try again.");
                return false;
        }
        else { if (subj.value.length < 2) {
                        alert("We require that the subject  \n" +
                                "be at least 2 characters long. \n \n" +
                                "Go back and try again.");
                                return false;
                }
                else { if (ffbody.value.length < 2) {
                alert("We require that each post  \n" +
                        "be at least 2 characters long. \n \n" +
                        "Go back and try again.");
                        return false;
                        }
                        else {
                                return true;
                        }
                }
        }
}

