defmode = \"normalmode\"; // default mode. either normalmode, advmode, or helpmode


if (defmode == \"advmode\") {
        helpmode = false;
        normalmode = false;
        advmode = true;
} else if (defmode == \"helpmode\") {
        helpmode = true;
        normalmode = false;
        advmode = false;
} else {
        helpmode = false;
        normalmode = true;
        advmode = false;
}
function chmode(swtch){
        if (swtch == 1){
                advmode = false;
                normalmode = false;
                helpmode = true;
                alert(\"$lang_bbcode_helpmode\");
        } else if (swtch == 0) {
                helpmode = false;
                normalmode = false;
                advmode = true;
                alert(\"$lang_bbcode_advmode\");
        } else if (swtch == 2) {
                helpmode = false;
                advmode = false;
                normalmode = true;
                alert(\"$lang_bbcode_normode\");
        }
}


function AddText(NewCode) {
        if(document.all){
        insertAtCaret(document.input.message,NewCode);
        setfocus();
        }else{
        document.input.message.value+=NewCode;
        setfocus();
        }
}
function storeCaret (textEl){
        if(textEl.createTextRange){
                textEl.caretPos = document.selection.createRange().duplicate();
        }
}


function insertAtCaret (textEl, text){
        if (textEl.createTextRange && textEl.caretPos){
                var caretPos = textEl.caretPos;
                caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == \' \' ? text + \' \' : text;
        }else{
                textEl.value  = text;
        }
}


function email() {
        if (helpmode) {
                alert(\"$lang_bbcode_help_email\");
        } else if (advmode) {
                AddTxt=\"[email] [/email]\";
                AddText(AddTxt);
        } else { 
                txt2=prompt(\"$lang_bbcode_prompt_email\",\"\"); 
                if (txt2!=null) {
                        txt=prompt(\"$lang_bbcode_prompt_emailerror\",\"name@domain.com\");      
                        if (txt!=null) {
                                if (txt2==\"\") {
                                        AddTxt=\"[email]\"+txt+\"[/email]\";
                
                                } else {
                                        AddTxt=\"[email=\"+txt+\"]\"+txt2+\"[/email]\";
                                } 
                                AddText(AddTxt);                
                        }
                }
        }
}



function chsize(size) {
        if (helpmode) {
                alert(\"$lang_bbcode_help_size\");
        } else if (advmode) {
                AddTxt=\"[size=\"+size+\"] [/size]\";
                AddText(AddTxt);
        } else {                       
                txt=prompt(\"$lang_bbcode_prompt_size \"+size,\"Text\"); 
                if (txt!=null) {             
                        AddTxt=\"[size=\"+size+\"]\"+txt+\"[/size]\";
                        AddText(AddTxt);
                }        
        }
}


function chfont(font) {
        if (helpmode){
                alert(\"$lang_bbcode_help_font\");
        } else if (advmode) {
                AddTxt=\"[font=\"+font+\"] [/font]\";
                AddText(AddTxt);
        } else {                  
                txt=prompt(\"$lang_bbcode_prompt_font \"+font,\"Text\");
                if (txt!=null) {             
                        AddTxt=\"[font=\"+font+\"]\"+txt+\"[/font]\";
                        AddText(AddTxt);
                }        
        }  
}



function bold() {
        if (helpmode) {
                alert(\"$lang_bbcode_help_bold\");
        } else if (advmode) {
                AddTxt=\"[b] [/b]\";
                AddText(AddTxt);
        } else {  
                txt=prompt(\"$lang_bbcode_prompt_bold\",\"Text\");     
                if (txt!=null) {           
                        AddTxt=\"[b]\"+txt+\"[/b]\";
                        AddText(AddTxt);
                }       
        }
}


function italicize() {
        if (helpmode) {
                alert(\"$lang_bbcode_help_italic\");
        } else if (advmode) {
                AddTxt=\"[i] [/i]\";
                AddText(AddTxt);
        } else {   
                txt=prompt(\"$lang_bbcode_prompt_italic\",\"Text\");     
                if (txt!=null) {           
                        AddTxt=\"[i]\"+txt+\"[/i]\";
                        AddText(AddTxt);
                }               
        }
}


function quote() {
        if (helpmode){
                alert(\"$lang_bbcode_help_quote\");
        } else if (advmode) {
                AddTxt=\"\\r[quote]\\r[/quote]\";
                AddText(AddTxt);
        } else {   
                txt=prompt(\"$lang_bbcode_prompt_quote\",\"Text\");     
                if(txt!=null) {          
                        AddTxt=\"\\r[quote]\\r\"+txt+\"\\r[/quote]\";
                        AddText(AddTxt);
                }               
        }
}


function chcolor(color) {
        if (helpmode) {
                alert(\"$lang_bbcode_help_color\");
        } else if (advmode) {
                AddTxt=\"[color=\"+color+\"] [/color]\";
                AddText(AddTxt);
        } else {  
        txt=prompt(\"$lang_bbcode_prompt_color \"+color,\"Text\");
                if(txt!=null) {
                        AddTxt=\"[color=\"+color+\"]\"+txt+\"[/color]\";
                        AddText(AddTxt);        
                } 
        }
}


function center() {
        if (helpmode) {
                alert(\"$lang_bbcode_help_center\");
        } else if (advmode) {
                AddTxt=\"[align=center] [/align]\";
                AddText(AddTxt);
        } else {  
                txt=prompt(\"$lang_bbcode_prompt_center\",\"Text\");     
                if (txt!=null) {          
                        AddTxt=\"\\r[align=center]\"+txt+\"[/align]\";
                        AddText(AddTxt);
                }              
        }
}


function hyperlink() {
        if (helpmode) {
                alert(\"$lang_bbcode_help_link\");
        } else if (advmode) {
                AddTxt=\"[url] [/url]\";
                AddText(AddTxt);
        } else { 
                txt2=prompt(\"$lang_bbcode_prompt_link1\",\"\"); 
                if (txt2!=null) {
                        txt=prompt(\"$lang_bbcode_prompt_link2\",\"http://\");      
                        if (txt!=null) {
                                if (txt2==\"\") {
                                        AddTxt=\"[url]\"+txt+\"[/url]\";
                                        AddText(AddTxt);
                                } else {
                                        AddTxt=\"[url=\"+txt+\"]\"+txt2+\"[/url]\";
                                        AddText(AddTxt);
                                }         
                        } 
                }
        }
}


function image() {
        if (helpmode){
                alert(\"$lang_bbcode_help_image\");
        } else if (advmode) {
                AddTxt=\"[img] [/img]\";
                AddText(AddTxt);
        } else {  
                txt=prompt(\"$lang_bbcode_prompt_image\",\"http://\");    
                if(txt!=null) {            
                        AddTxt=\"\\r[img]\"+txt+\"[/img]\";
                        AddText(AddTxt);
                }       
        }
}


function code() {
        if (helpmode) {
                alert(\"$lang_bbcode_help_code\");
        } else if (advmode) {
                AddTxt=\"\\r[code]\\r[/code]\";
                AddText(AddTxt);
        } else {   
                txt=prompt(\"$lang_bbcode_prompt_code\",\"\");     
                if (txt!=null) {          
                        AddTxt=\"\\r[code]\"+txt+\"[/code]\";
                        AddText(AddTxt);
                }              
        }
}


function list() {
        if (helpmode) {
                alert(\"$lang_bbcode_help_list\");
        } else if (advmode) {
                AddTxt=\"\\r[list]\\r[*]\\r[*]\\r[*]\\r[/list]\";
                AddText(AddTxt);
        } else {  
                txt=prompt(\"$lang_bbcode_prompt_list_start\",\"\");               
                while ((txt!=\"\") && (txt!=\"A\") && (txt!=\"a\") && (txt!=\"1\") && (txt!=null)) {
                        txt=prompt(\"$lang_bbcode_prompt_list_error\",\"\");               
                }
                if (txt!=null) {
                        if (txt==\"\") {
                                AddTxt=\"\\r[list]\\r\\n\";
                        } else {
                                AddTxt=\"\\r[list=\"+txt+\"]\\r\";
                        } 
                        txt=\"1\";
                        while ((txt!=\"\") && (txt!=null)) {
                                txt=prompt(\"$lang_bbcode_prompt_list_end\",\"\"); 
                                if (txt!=\"\") {             
                                        AddTxt+=\"[*]\"+txt+\"\\r\"; 
                                }                   
                        } 
                        AddTxt+=\"[/list]\\r\\n\";
                        AddText(AddTxt); 
                }
        }
}


function underline() {
        if (helpmode) {
                alert(\"$lang_bbcode_help_underline\");
        } else if (advmode) {
                AddTxt=\"[u] [/u]\";
                AddText(AddTxt);
        } else {  
                txt=prompt(\"$lang_bbcode_prompt_underline\",\"Text\");     
                if (txt!=null) {           
                        AddTxt=\"[u]\"+txt+\"[/u]\";
                        AddText(AddTxt);
                }               
        }
}


function setfocus() {
        document.input.message.focus();
}