//Variables for controlling opening and closing tags (function tag)

var b = 2;
var i = 2;
var u = 2;
var lft = 2;
var ctr = 2;
var rgt = 2;
var url = 2;
var img = 2;
var eml = 2;

//Functions for creating copy-cut-paste action

function down(butin, name) { eval("window.document.editform."+name+".src = butin;"); }

function up(n, name, butout) {
	eval("window.document.editform."+name+".src = butout;");
	txtarea=document.editform.rpagetext;
	txtarea.focus();
	copied=document.selection.createRange();
	copied.execCommand(n);
}

function out(name, butout) { 
	eval("window.document.editform."+name+".src = butout;");
	helpline("none");
	}




//Functions for creating non-font tags

function tagdwn(td, butin, name) {
	if (eval(td)%2 == 0) { eval("window.document.editform."+name+".src = butin;"); }
	}

function tagup(tu, tagadd, tagclose, butout, name) {
    if (eval(tu)%2 == 0) {
        var rpagetext = window.document.editform.rpagetext.value;
        window.document.editform.rpagetext.value = rpagetext + tagadd;
        window.document.editform.rpagetext.focus();
    } else {
	eval("window.document.editform."+name+".src = butout;");
	var rpagetext = window.document.editform.rpagetext.value;
	window.document.editform.rpagetext.value = rpagetext + tagclose;
	window.document.editform.rpagetext.focus();
    }
    eval(tu+"++;");
}

function tagout(to, butout, butin, name) {
    if (eval(to)%2 == 0) {
	eval("window.document.editform."+name+".src = butout;");
	helpline("none");
    } else {
	eval("window.document.editform."+name+".src = butin;");
	helpline("none");
    }
}


//Function for adding font color and size tags

function font(bbopen, bbclose) {
        var rpagetext = document.editform.rpagetext;
        rpagetext.value += bbopen + bbclose;
        rpagetext.focus();
        return;
}


//Function for adding smilies

function smilie (smilie) {
        var rpagetext = document.editform.rpagetext;
        rpagetext.value += smilie;
        rpagetext.focus();
        return;
}


//Helpbox messages

none_help = "";

copy_help = "Kopiëren (CTRL + C)";
cut_help = "Knippen (CTRL + X)";
paste_help = "Plakken (CTRL + V)";

bold_help = "Vet: [b]tekst[/b]";
italic_help = "Cursief: [i]tekst[/i]";
underline_help = "Onderstrepen: [u]tekst[/u]";

left_help = "Links uitlijnen: [left]tekst[/left]";
center_help = "Centreren: [center]tekst[/center]";
right_help = "Rechts uitlijnen: [right]tekst[/right]";

img_help = "Afbeelding: [img]http://www.mijnpage.nl/afbeelding.jpg[/img]";
url_help = "Link: [url]http://[/url] of [url=http://]Mijn Page[/url]";
email_help = "E-mail: [email]ik@mail.nl[/email] of [email=ik@mail.nl]Mijn mail[/email]";

fontcolor_help = "Tekstkleur: [color=red]tekst[/color] of [color=#FF0000]tekst[/color]";
fontstyle_help = "Lettertype: [font=arial]tekst[/font]";
fontsize_help = "Tekengroote: [size=9]tekst[/size]";

smiley_help ="Smiley: klik om de smiley toe te voegen";


//Function for displaying help information

function helpline(help) {
        var helpbox = document.editform.helpbox;
        helpbox.value = eval(help + "_help");
}


//Function to confirm reset

function confirm_reset () {
        if(confirm("If you continue you will loose everything you have entered so far. \n \n" +
                "Click OK to proceed and start again.  \n \n Alternatively click cancel to continue " +
                "working on your rpagetext.")) {
                        return true;
                                }
                else {
                        return false;
                                }
}


//Check the form submission for errors

function checkForm() {
        var subject = document.editform.subject;
        var rpagetext = document.editform.rpagetext;

        //Check to make sure rpagetext lengths are sensible

        if (subject.value.length < 2 && rpagetext.value.length < 2) {
                alert("This is a short rpagetext!" + " \n \n " +
                                "We require that each rpagetext (and subject) \n" +
                                "be at least 2 characters long. \n \n" +
                                "Go back and try again.");
                return false;
        }
        else { if (subject.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 (rpagetext.value.length < 2) {
                        alert("We require that each rpagetext  \n" +
                                "be at least 2 characters long. \n \n" +
                                "Go back and try again.");
                                return false;
                                }
                                else {
                                        return true;
                                }
                        }
        }
}
