//Variables for controlling opening and closing tags (function tag)

var bbcode = new Array;
bbcode['b'] = 2;
bbcode['i'] = 2;
bbcode['u'] = 2;
bbcode['c'] = 2;
bbcode['url'] = 2;
bbcode['img'] = 2;
bbcode['popup'] = 2;
bbcode['movie'] = 2;

//Function for creating non-font tags
function tag(id, v, tagadd, newbut, tagclose, oldbut, name) {
    if (!id) { return; }
    var b = document.getElementById('bbcode_'+name);
    var p = document.getElementById(id);
    if (eval("bbcode['"+v+"']")%2 == 0) {
        b.value = newbut;
        var post = p.value;
        p.value = post + tagadd;
        p.focus();
    } else {
        b.value = oldbut;
        var post = p.value;
        p.value = post + tagclose;
        p.focus();
    }
    eval("bbcode['"+v+"']++;");
}


//Function for adding font color and size tags
function font(id, bbopen, bbclose) {
    if (!id) { return; }
    var p = document.getElementById(id);
    p.value += bbopen + bbclose;
    p.focus();
}

//Helpbox messages
var helpmessages = new Array;
helpmessages['bold'] = "[b]Bold Text[/b]";
helpmessages['italic'] = "[i]Italic[/i]";
helpmessages['underline'] = "[u]Underlined Text[/u]";
helpmessages['code'] = "[code]Code Text[/code]";
helpmessages['img'] = "[img]http://www.domain.com/image.jpg[/img]";
helpmessages['url'] = "[url]http://www.domain.com[/url] or [url=http://www.domain.com]Text Link[/url]";
helpmessages['fontcolor'] = "[color=red]Colored Text[/color=&nbsp;&nbsp;(You can manually enter RGB colors (i.e. #FF0000) instead of color names.)";
helpmessages['fontsize'] = "[size=50%]Resized Text[/size]";
helpmessages['popup'] = "[popup=width:height:icon_name:http://www.domain.com/page.html]label[/popup]";
helpmessages['movie'] = "[popup=width:height]path/to/movie.mov[/popup]";


//Function for displaying help information

// Shows the help messages in the helpline window
function helpline(help) {
    var helpbox = document.getElementById('bbcode_helpbox');
    helpbox.innerHTML = "<strong>Usage:</strong> "+helpmessages[help];
}

