defmode = "normalmode";		// default mode (normalmode, advmode, helpmode)

function resizeimage(){
	var userupimage=[];
	userupimage=document.asso_note.userimage;
	if(userupimage.length>1){
		for(var i=0;userupimage[i];i++)
		{
			if(userupimage[i].width>350)
			userupimage[i].width=350;
		}
	}
	else{
		if(userupimage.width>350) userupimage.width=350;
	}
}
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.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 - 2) == ' ' ? text + ' ' : text;
        } else if(textEl) {
                textEl.value += text;
        } else {
        	textEl.value = text;
        }
}

function email() {
        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 chsize(size) {
        if (helpmode) {
                alert(fontsize_help);
	} else if (document.selection && document.selection.type == "Text") {
		var range = document.selection.createRange();
		range.text = "[size=" + size + "]" + range.text + "[/size]";
        } else if (advmode) {
                AddTxt="[size="+size+"] [/size]";
                AddText(AddTxt);
        } else {                       
                txt=prompt(fontsize_normal,text_input); 
                if (txt!=null) {             
                        AddTxt="[size="+size+"]"+txt;
                        AddText(AddTxt);
                        AddText("[/size]");
                }        
        }
}

function chfont(font) {
        if (helpmode){
                alert(font_help);
	} else if (document.selection && document.selection.type == "Text") {
		var range = document.selection.createRange();
		range.text = "[font=" + font + "]" + range.text + "[/font]";
        } else if (advmode) {
                AddTxt="[font="+font+"] [/font]";
                AddText(AddTxt);
        } else {                  
                txt=prompt(font_normal,text_input);
                if (txt!=null) {             
                        AddTxt="[font="+font+"]"+txt;
                        AddText(AddTxt);
                        AddText("[/font]");
                }        
        }  
}


function bold() {
        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() {
        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() {
        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 chcolor(color) {
        if (helpmode) {
                alert(color_help);
	} else if (document.selection && document.selection.type == "Text") {
		var range = document.selection.createRange();
		range.text = "[color=" + color + "]" + range.text + "[/color]";
        } else if (advmode) {
                AddTxt="[color="+color+"] [/color]";
                AddText(AddTxt);
        } else {  
        txt=prompt(color_normal,text_input);
                if(txt!=null) {
                        AddTxt="[color="+color+"]"+txt;
                        AddText(AddTxt);
                        AddText("[/color]");
                }
        }
}
function addbox(color) {
        if (helpmode) {
                alert(box_help);
	} else if (document.selection && document.selection.type == "Text") {
		var range = document.selection.createRange();
		range.text = "[box=" + color + "]" + range.text + "[/box]";
        } else if (advmode) {
                AddTxt="[box="+color+"] [/box]";
                AddText(AddTxt);
        } else {  
        txt=prompt(color_normal,text_input);
                if(txt!=null) {
                        AddTxt="[box="+color+"]"+txt;
                        AddText(AddTxt);
                        AddText("[/box]");
                }
        }
}
function center() {
        if (helpmode) {
                alert(center_help);
	} else if (document.selection && document.selection.type == "Text") {
		var range = document.selection.createRange();
		range.text = "[center]" + range.text + "[/center]";
        } 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 flash() {
        if (helpmode){
                alert(flash_help);
        } else if (advmode) {
                AddTxt="[swf] [/swf]";
                AddText(AddTxt);
        } else {  
                txt=prompt(flash_normal,"http://");    
                if(txt!=null) {            
                        AddTxt="\r[swf]"+txt;
                        AddText(AddTxt);
                        AddText("[/swf]");
                }       
        }
}

function code() {
        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 list() {
        if (helpmode) {
                alert(list_help);
        } else if (advmode) {
                AddTxt="\r[list]\r[*]\r[*]\r[*]\r[/list]";
                AddText(AddTxt);
        } else {  
                txt=prompt(list_normal,"");
                while ((txt!="") && (txt!="A") && (txt!="a") && (txt!="1") && (txt!=null)) {
                        txt=prompt(list_normal_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(list_normal_input,""); 
                                if (txt!="") {             
                                        AddTxt+="[*]"+txt+"\r"; 
                                }                   
                        } 
                        AddTxt+="[/list]\r\n";
                        AddText(AddTxt); 
                }
        }
}

function underline() {
        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.input.message.focus();
}
// ========== ?óè??ò??ìù°′?￥ Start ==========
function postpay() {
                if (document.selection && document.selection.type == "Text") {
                var range = document.selection.createRange();
                range.text = "[sell=]" + range.text + "";
        } else if (helpmode) {
                alert(pay_help);
        } else if (advmode) {
                AddTxt="[sell=]";
                AddText(AddTxt);
        } else { 
                txt2=prompt(pay_normal,""); 
                if (txt2!=null) {
                        txt=prompt(pay_normal_input,"");      
                        if (txt!=null) {
                                if (txt2=="") {
                                        AddTxt="[sell=]"+txt;
                                        AddText(AddTxt);
                                        AddText("[/sell]");
                                } else {
                                        AddTxt="[sell="+txt+"]"+txt2;
                                        AddText(AddTxt);
                                        AddText("[/sell]");
                                }         
                        } 
                }
        }
}
// ========== ?óè??ò??ìù°′?￥ End ========== 
	function ra() {
        if (helpmode){
                alert(ra_help);
        } else if (advmode) {
                AddTxt="[ra] [/ra]";
                AddText(AddTxt);
        } else {  
                txt=prompt(ra_normal,"http://");    
                if(txt!=null) {            
                        AddTxt="\r[ra]"+txt;
                        AddText(AddTxt);
                        AddText("[/ra]");
                }       
        }
}

function rm() {
        if (helpmode){
                alert(rm_help);
        } else if (advmode) {
                AddTxt="[rm] [/rm]";
                AddText(AddTxt);
        } else {  
                txt=prompt(rm_normal,"http://");    
                if(txt!=null) {            
                        AddTxt="\r[rm]"+txt;
                        AddText(AddTxt);
                        AddText("[/rm]");
                }       
        }
}

function wmv() {
        if (helpmode){
                alert(wmv_help);
        } else if (advmode) {
                AddTxt="[wmv] [/wmv]";
                AddText(AddTxt);
        } else {  
                txt=prompt(wmv_normal,"http://");    
                if(txt!=null) {            
                        AddTxt="\r[wmv]"+txt;
                        AddText(AddTxt);
                        AddText("[/wmv]");
                }       
        }
}


function mid() {
        if (helpmode){
                alert(mid_help);
        } else if (advmode) {
                AddTxt="[mid] [/mid]";
                AddText(AddTxt);
        } else {  
                txt=prompt(mid_normal,"http://");    
                if(txt!=null) {            
                        AddTxt="\r[mid]"+txt;
                        AddText(AddTxt);
                        AddText("[/mid]");
                }       
        }
}
function iframe() {
        if (helpmode){
                alert(iframe_help);
        } else if (advmode) {
                AddTxt="[iframe] [/iframe]";
                AddText(AddTxt);
        } else {  
                txt=prompt(iframe_normal,"http://");    
                if(txt!=null) {            
                        AddTxt="\r[iframe]"+txt;
                        AddText(AddTxt);
                        AddText("[/iframe]");
                }       
        }
}

function hide() {
        if (helpmode) {
                alert(hide_help);
        } else if (document.selection && document.selection.type == "Text") {
                var range = document.selection.createRange();
                range.text = "[hide]" + range.text + "[/hide]";
        } else if (advmode) {
                AddTxt="[hide] [/hide]";
                AddText(AddTxt);
        } else {  
                txt=prompt(hide_normal,text_input);
                if (txt!=null) {           
                        AddTxt="[hide]"+txt;
                        AddText(AddTxt);
                        AddText("[/hide]");
                }               
        }
}
function fly() {
        if (helpmode) {
                alert(fly_help);
        } else if (document.selection && document.selection.type == "Text") {
                var range = document.selection.createRange();
                range.text = "[fly]" + range.text + "[/fly]";
        } else if (advmode) {
                AddTxt="[fly] [/fly]";
                AddText(AddTxt);
        } else {  
                txt=prompt(fly_normal,text_input);
                if (txt!=null) {           
                        AddTxt="[fly]"+txt;
                        AddText(AddTxt);
                        AddText("[/fly]");
                }               
        }
}
function watermark() {
         if (document.selection && document.selection.type == "Text") {
                var range = document.selection.createRange();
                range.text = "[watermark]" + range.text + "[/watermark]";
        } else if (advmode) {
                AddTxt="\r[watermark]\r[/watermark]";
                AddText(AddTxt);
        } else {   
                txt=prompt("请输入需加水印的信息","");     
                if (txt!=null) {          
                        AddTxt="\r[watermark]"+txt;
                        AddText(AddTxt);
                        AddText("[/watermark]");
                }              
        }
}
function glow() {
         if (document.selection && document.selection.type == "Text") {
                var range = document.selection.createRange();
                range.text = "[glow]" + range.text + "[/glow]";
        } else if (advmode) {
                AddTxt="\r[glow]\r[/glow]";
                AddText(AddTxt);
        } else {   
                txt=prompt("请输入需要增加光晕效果的文字","");     
                if (txt!=null) {          
                        AddTxt="\r[b][size=5][color=White][glow=yellow,3]"+txt;
                        AddText(AddTxt);
                        AddText("[/glow][/color][/size][/b]");
                }              
        }
}
function blur() {
         if (document.selection && document.selection.type == "Text") {
                var range = document.selection.createRange();
                range.text = "[blur]" + range.text + "[/blur]";
        } else if (advmode) {
                AddTxt="\r[blur]\r[/blur]";
                AddText(AddTxt);
        } else {   
                txt=prompt("请输入需要增加动感效果的文字","");     
                if (txt!=null) {          
                        AddTxt="\r[b][size=5][color=Blue][blur=80,170]"+txt;
                        AddText(AddTxt);
                        AddText("[/blur][/color][/size][/b]");
                }              
        }
}
function shadow() {
         if (document.selection && document.selection.type == "Text") {
                var range = document.selection.createRange();
                range.text = "[shadow]" + range.text + "[/shadow]";
        } else if (advmode) {
                AddTxt="\r[shadow]\r[/shadow]";
                AddText(AddTxt);
        } else {   
                txt=prompt("请输入需要增加阴影效果的文字","");     
                if (txt!=null) {          
                        AddTxt="\r[b][size=5] [color=bule][shadow=Purple,3]"+txt;
                        AddText(AddTxt);
                        AddText("[/shadow] [/color] [/size][/b]");
                }              
        }
}
function dshadow() {
         if (document.selection && document.selection.type == "Text") {
                var range = document.selection.createRange();
                range.text = "[dshadow]" + range.text + "[/dshadow]";
        } else if (advmode) {
                AddTxt="\r[dshadow]\r[/dshadow]";
                AddText(AddTxt);
        } else {   
                txt=prompt("请输入需要增加阴影效果的文字","");     
                if (txt!=null) {          
                        AddTxt="\r[b][size=5] [color=bule][dshadow=Purple,3]"+txt;
                        AddText(AddTxt);
                        AddText("[/dshadow] [/color] [/size][/b]");
                }              
        }
}
function dao() {
         if (document.selection && document.selection.type == "Text") {
                var range = document.selection.createRange();
                range.text = "[dao]" + range.text + "[/dao]";
        } else if (advmode) {
                AddTxt="\r[dao]\r[/dao]";
                AddText(AddTxt);
        } else {   
                txt=prompt("请输入需要加倒转效果的文字","");     
                if (txt!=null) {          
                        AddTxt="\r[b][size=5] [color=bule][dao=400]"+txt;
                        AddText(AddTxt);
                        AddText("[/dao][/color] [/size][/b]");
                }              
        }
}
function diao() {
         if (document.selection && document.selection.type == "Text") {
                var range = document.selection.createRange();
                range.text = "[diao]" + range.text + "[/diao]";
        } else if (advmode) {
                AddTxt="\r[diao]\r[/diao]";
                AddText(AddTxt);
        } else {   
                txt=prompt("请输入需要加调转效果的文字","");     
                if (txt!=null) {          
                        AddTxt="\r[b][size=5] [color=bule][diao=200]"+txt;
                        AddText(AddTxt);
                        AddText("[/diao][/color] [/size][/b]");
                }              
        }
}
function crfont() {
        if (helpmode){
                alert(crfont_help);
        } else if (advmode) {
                AddTxt="[crfont] [crfont]";
                AddText(AddTxt);
        } else {  
                txt=prompt(crfont_normal,"");    
                if(txt!=null) {            
                        AddTxt="\r[crfont]"+txt;
                        AddText(AddTxt);
                        AddText("[/crfont]");
                }
        }
}
function typewriter() {
        if (helpmode){
                alert(typewriter_help);
        } else if (advmode) {
                AddTxt="[typewriter] [/typewriter]";
                AddText(AddTxt);
        } else {  
                txt=prompt(typewriter_normal,"");    
                if(txt!=null) {            
                        AddTxt="\r[typewriter]"+txt;
                        AddText(AddTxt);
                        AddText("[/typewriter]");
                }       
        }
}
