var text_input = "文字";
var help_mode = "UBB 代码 - 帮助信息\n\n点击相应的代码按钮即可获得相应的说明和提示";
var adv_mode = "UBB 代码 - 直接插入\n\n点击代码按钮后不出现提示即直接插入相应代码";
var normal_mode = "UBB 代码 - 提示插入\n\n点击代码按钮后出现向导窗口帮助您完成代码插入";
var email_help = "插入邮件地址\n\n插入邮件地址连接。\n例如：\n[email]webmaster@xxx.com[/email]\n[email=webmaster@xxx.com]Loveyuki[/email]";
var email_normal = "请输入链接显示的文字，如果留空则直接显示邮件地址。";
var email_normal_input = "请输入邮件地址。";
var fontsize_help = "设置字号\n\n将标签所包围的文字设置成指定字号。\n例如：[size=3]文字大小为 3[/size]";
var fontsize_normal = "请输入要设置为指定字号的文字。";
var font_help = "设定字体\n\n将标签所包围的文字设置成指定字体。\n例如：[font=仿宋]字体为仿宋[/font]";
var font_normal = "请输入要设置成指定字体的文字。";
var bold_help = "插入粗体文本\n\n将标签所包围的文本变成粗体。\n例如：[b]文字[/b]";
var bold_normal = "请输入要设置成粗体的文字。";
var italicize_help = "插入斜体文本\n\n将标签所包围的文本变成斜体。\n例如：[i]文字[/i]";
var italicize_normal = "请输入要设置成斜体的文字。";
var quote_help = "插入引用\n\n将标签所包围的文本作为引用特殊显示。\n例如：[quote]文字[/quote]";
var quote_normal = "请输入要作为引用显示的文字。";
var color_help = "定义文本颜色\n\n将标签所包围的文本变为制定颜色。\n例如：[color=red]红颜色[/color]";
var color_normal = "请输入要设置成指定颜色的文字。";
var center_help = "居中对齐\n\n将标签所包围的文本居中对齐显示。\n例如：[align=center]内容居中[/align]";
var center_normal = "请输入要居中对齐的文字。";
var link_help = "插入超级链接\n\n插入一个超级连接。\n例如：\n[url]http://www.xxx.com[/url]\n[url=http://www.xxx.com]文字[/url]";
var link_normal = "请输入链接显示的文字，如果留空则直接显示链接。";
var link_normal_input = "请输入 URL。";
var image_help = "插入图像\n\n在文本中插入一幅图像。\n例如：[img]http://www.xxx.com/images/logo.gif[/img]";
var image_normal = "请输入图像的 URL。";
var flash_help = "插入 Flash\n\n在文本中插入 flash 动画。\n例如：[swf]http://www.xxx.com/images/banner.swf[/swf]";
var flash_normal = "请输入 Fash 动画的 URL。";
var code_help = "插入代码\n\n插入程序或脚本原始代码。\n例如：[code]Response.Write(这里是文字)[/code]";
var code_normal = "'请输入要插入的代码。";
var list_help = "插入列表\n\n插入可由浏览器显示来的规则列表项。\n例如：\n[list]\n[*]；列表项 #1\n[*]；列表项 #2\n[*]；列表项 #3\n[/list]";
var list_normal = "'请选择列表格式：字母式列表输入 \"A\"；数字式列表输入 \"1\"。此处也可留空。";
var list_normal_error = "错误：列表格式只能选择输入 \"A\" 或 \"1\"。";
var list_normal_input = "请输入列表项目内容，如果留空表示项目结束。";
var underline_help = "插入下划线\n\n'给标签所包围的文本加上下划线。\n例如：[u]文字[/u]";
var underline_normal = "请输入要加下划线的文字。";
var texton = false;
defmode = "advmode";		// default mode (normalmode, advmode, 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(help_mode);
        } else if (swtch == 0) {
                helpmode = false;
                normalmode = false;
                advmode = true;
                alert(adv_mode);
        } else if (swtch == 2) {
                helpmode = false;
                advmode = false;
                normalmode = true;
                alert(normal_mode);
        }
}

function AddText(NewCode) {
        if(document.all){
        	insertAtCaret(document.form1.content, NewCode);
        	setfocus();
        } else{
        	document.form1.content.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 - 2) == ' ' ? text + ' ' : text;
        } else if(textEl) {
                textEl.value += text;
        } else {
        	textEl.value = text;
        }
}

function email() {
	setfocus();
    if (helpmode) {
                alert(email_help);
	} else if (document.selection && document.selection.type == "Text") {
		var range = document.selection.createRange();
		range.text = "[email]" + range.text + "[/email]";
	} else if (advmode) {
	      AddTxt="[email] [/email]";
                AddText(AddTxt);
        } else { 
                txt2=prompt(email_normal,""); 
                if (txt2!=null) {
                        txt=prompt(email_normal_input,"name@domain.com");      
                        if (txt!=null) {
                                if (txt2=="") {
                                        AddTxt="[email]"+txt+"[/email]";
                
                                //} else {
                                //        AddTxt="[email="+txt+"]"+txt2+"[/email]";
                                } 
                                AddText(AddTxt);                
                        }
                }
        }
}



function bold() {
	setfocus();
    if (helpmode) {
                alert(bold_help);
	} else if (document.selection && document.selection.type == "Text") {
		var range = document.selection.createRange();
		range.text = "[b]" + range.text + "[/b]";
        } else if (advmode) {
                AddTxt="[b] [/b]";
                AddText(AddTxt);
        } else {  
                txt=prompt(bold_normal,text_input);     
                if (txt!=null) {           
                        AddTxt="[b]"+txt;
                        AddText(AddTxt);
                        AddText("[/b]");
                }       
        }
}

function italicize() {
    setfocus();
	if (helpmode) {
                alert(italicize_help);
	} else if (document.selection && document.selection.type == "Text") {
		var range = document.selection.createRange();
		range.text = "[i]" + range.text + "[/i]";
        } else if (advmode) {
                AddTxt="[i] [/i]";
                AddText(AddTxt);
        } else {   
                txt=prompt(italicize_normal,text_input);     
                if (txt!=null) {           
                        AddTxt="[i]"+txt;
                        AddText(AddTxt);
                        AddText("[/i]");
                }               
        }
}

function quote() {
    setfocus();
	if (helpmode){
                alert(quote_help);
	} else if (document.selection && document.selection.type == "Text") {
		var range = document.selection.createRange();
		range.text = "[quote]" + range.text + "[/quote]";
        } else if (advmode) {
                AddTxt="\r[quote]\r[/quote]";
                AddText(AddTxt);
        } else {   
                txt=prompt(quote_normal,text_input);     
                if(txt!=null) {          
                        AddTxt="\r[quote]\r"+txt;
                        AddText(AddTxt);
                        AddText("\r[/quote]");
                }               
        }
}


function center() {
    setfocus();
	if (helpmode) {
                alert(center_help);
	} else if (document.selection && document.selection.type == "Text") {
		var range = document.selection.createRange();
		range.text = "[align=center]" + range.text + "[/align]";
        } else if (advmode) {
                AddTxt="[align=center] [/align]";
                AddText(AddTxt);
        } else {  
                txt=prompt(center_normal,text_input);     
                if (txt!=null) {          
                        AddTxt="\r[align=center]"+txt;
                        AddText(AddTxt);
                        AddText("[/align]");
                }              
        }
}

function hyperlink() {
        if (helpmode) {
                alert(link_help);
        } else if (advmode) {
                AddTxt="[url] [/url]";
                AddText(AddTxt);
        } else { 
                txt2=prompt(link_normal,""); 
                if (txt2!=null) {
                        txt=prompt(link_normal_input,"http://");      
                        if (txt!=null) {
                                if (txt2=="") {
                                        AddTxt="[url]"+txt;
                                        AddText(AddTxt);
                                        AddText("[/url]");
                                } else {
                                        AddTxt="[url="+txt+"]"+txt2;
                                        AddText(AddTxt);
                                        AddText("[/url]");
                                }         
                        } 
                }
        }
}

function image() {
        if (helpmode){
                alert(image_help);
        } else if (advmode) {
                AddTxt="[img] [/img]";
                AddText(AddTxt);
        } else {  
                txt=prompt(image_normal,"http://");    
                if(txt!=null) {            
                        AddTxt="\r[img]"+txt;
                        AddText(AddTxt);
                        AddText("[/img]");
                }       
        }
}

function code() {
    setfocus();
	if (helpmode) {
                alert(code_help);
	} else if (document.selection && document.selection.type == "Text") {
		var range = document.selection.createRange();
		range.text = "[code]" + range.text + "[/code]";
        } else if (advmode) {
                AddTxt="\r[code]\r[/code]";
                AddText(AddTxt);
        } else {   
                txt=prompt(code_normal,"");     
                if (txt!=null) {          
                        AddTxt="\r[code]"+txt;
                        AddText(AddTxt);
                        AddText("[/code]");
                }              
        }
}

function underline() {
    setfocus();
	if (helpmode) {
                alert(underline_help);
	} else if (document.selection && document.selection.type == "Text") {
		var range = document.selection.createRange();
		range.text = "[u]" + range.text + "[/u]";
        } else if (advmode) {
                AddTxt="[u] [/u]";
                AddText(AddTxt);
        } else {  
                txt=prompt(underline_normal,text_input);
                if (txt!=null) {           
                        AddTxt="[u]"+txt;
                        AddText(AddTxt);
                        AddText("[/u]");
                }               
        }
}


function setfocus() {
        document.form1.content.focus();
}

function addubbtextarea(){
	document.writeln("<div class=\"inputdiv\">");
	document.writeln("<label>Name<\/label>");
	document.writeln("<input name=\"name\" id=\"name\" type=\"text\" maxLength=\"30\" size=\"30\" class=\"uinput\"\/> ");
	document.writeln("<font color=\"#ff0000\">*<\/font>");
	document.writeln("<\/div>");
if (SYSqq=="1"){
		document.writeln("<div  class=\"inputdiv\">");
		document.writeln("<label>QQ<\/label>");
		document.writeln("<input name=\"qq\" id=\"qq\" type=\"text\" maxLength=\"50\" size=\"30\" class=\"uinput\"\/> ");
		document.writeln("<font color=\"#ff0000\">*<\/font>");
		document.writeln("<\/div>");
	}
	if (SYSmail=="1"){
		document.writeln("<div class=\"inputdiv\" {$GB_ismail}>");
		document.writeln("<label>Email<\/label>");
		document.writeln("<input name=\"email\" id=\"email\" type=\"text\" maxLength=\"30\" size=\"30\" class=\"uinput\"\/> ");
		document.writeln("<font color=\"#ff0000\">*<\/font>");
		document.writeln("<\/div>");
	}
	if (SYSweburl=="1"){
		document.writeln("<div  class=\"inputdiv\" {$GB_isweburl}>");
		document.writeln("<label>Url<\/label>");
		document.writeln("<input name=\"weburl\" id=\"weburl\" type=\"text\" maxLength=\"30\" size=\"30\" class=\"uinput\" value=\"http:\/\/\"\/> ");
		document.writeln("<font color=\"#ff0000\">*<\/font>");
		document.writeln("<\/div>");
	}
	document.writeln("<label>Your Message<\/label>");
	document.writeln("<div id=\"ubb\" style=\"width:"+Ubbwidth+";\">");
	if (SYSubb=="1"){
	document.writeln("<div class=\"bar\">");
	document.writeln("<a tabindex=9 href=\"javascript:bold();\"><img src=\"images\/ubb\/bb_bold.gif\" alt=\"插入粗体文本\" \/><\/a>");
	document.writeln("<a tabindex=9 href=\"javascript:italicize()\"><img src=\"images\/ubb\/bb_italicize.gif\" alt=\"插入斜体文本\" \/><\/a>");
	document.writeln("<a tabindex=9 href=\"javascript:underline()\"><img src=\"images\/ubb\/bb_underline.gif\" alt=\"插入下滑线\" \/><\/a>");
	document.writeln("<a tabindex=9 href=\"javascript:center()\"><img src=\"images\/ubb\/bb_center.gif\" alt=\"居中对齐\" \/><\/a>");
	document.writeln("<a tabindex=9 href=\"javascript:hyperlink()\"><img src=\"images\/ubb\/bb_url.gif\" alt=\"插入超级链接\" \/><\/a>");
	document.writeln("<a tabindex=9 href=\"javascript:email()\"><img src=\"images\/ubb\/bb_email.gif\" alt=\"插入邮件地址\" \/><\/a>");
	if (SYSimg=="1"){
	document.writeln("<a tabindex=9 href=\"javascript:image()\"><img src=\"images\/ubb\/bb_image.gif\" alt=\"插入图像\" \/><\/a>");
	}
	document.writeln("<a tabindex=9 href=\"javascript:code()\"> <img src=\"images\/ubb\/bb_code.gif\" alt=\"插入代码\" \/><\/a>");
	document.writeln("<a tabindex=9 href=\"javascript:quote()\"><img src=\"images\/ubb\/bb_quote.gif\" alt=\"插入引用\" \/><\/a>");
	document.writeln("<\/div>");
	}
	document.writeln("<textarea name=\"content\" id=\"content\" style=\"height:"+Ubbheight+";\" onfocus=\"texton=true;\" onblur=\"texton=false;\"><\/textarea>");
	document.writeln("<\/div>");
}

