function rich_editor_insert_bbcode(format, target, text) {

    var insert = '';
    
    if (!target) {
        target = 'insertTarget';
    }
    
    switch(format) {
    
        case 'url':
            var url = prompt("Enter the address of the web page you are linking", "http://");
            var title = prompt("Enter the title of the web page you are linking to.", "");
            insert = "[URL="+url+"]"+title+"[/URL]";
        break;
        
        case 'email':
            var email = prompt("Enter the complete email address (someone@somewhere.com) that you wish to add.", "");
            insert = "[EMAIL]"+email+"[/EMAIL]";
        break;
            
        case 'image':
            var image = prompt("Enter the complete URL for the image you wish to display.", "http://");
            insert = "[IMG]"+image+"[/IMG]";    
        break;
                
        case 'bold':
            var bold = prompt("Enter the text that you wish to make bold.", "");
            insert = "[B]"+bold+"[/B]";
        break;
        
        case 'italics':
            var italics = prompt("Enter the text that you wish to italicize.", "");
            insert = "[I]"+italics+"[/I]";    
        break;
        
        case 'underline':
            var underline = prompt("Enter the text that you wish to underline.", "");
            insert = "[U]"+underline+"[/U]";
        break;

        case 'spoiler':
            insert = "[SPOILER]\n\n[/SPOILER]";
        break;
                    
        case 'quote':
            if(text == null) {
                insert = "[QUOTE]\n\n[/QUOTE]";
            } else {
                insert = "[QUOTE]\n"+text+"\n[/QUOTE]";
            }
        break;
                
        case 'code':
            insert = "[CODE]\n\n[/CODE]";    
        break;
        
        case 'smile':
            insert = "::smile";
        break;
        
        case 'laugh':
            insert = "::laugh";
        break;
        
        case 'finger':
            insert = "::finger";
        break;
        
        case 'surprise':
            insert = "::surprise";
        break;
        
        case 'sinister':
            insert = "::sinister";
        break;
        
        case 'confused':
            insert = "::confused";
        break;
        
        case 'looking':
            insert = "::looking";
        break;
        
        case 'animatedlaugh':
            insert = "::animatedlaugh";
        break;
        
        case 'stare':
            insert = "::stare";
        break;
        
        case 'pouting':
            insert = "::pouting";
        break;
        
        case 'cocky_stare':
            insert = "::c_stare";
        break;
        
        case 'animatedsmile':
            insert = "::animatedsmile";
        break;  
        
    }
    
    document.getElementById(target).value += insert;
    document.getElementById(target).focus();
               
}