
defmode = "nmod";		// default mode (nmod, amod, helpmode)

if (defmode == "amod") {
	helpmode = false;
	nmod = false;
	amod = true;
}
else {
	helpmode = false;
	nmod = true;
	amod = false;
}

function chmode(sw,ahlp,nhlp){
	if (sw == 0) {
		helpmode = false;
		nmod = false;
		amod = true;
		alert(ahlp);
	} else if (sw == 2) {
		helpmode = false;
		amod = false;
		nmod = true;
		alert(nhlp);
	}
}

function AddText(nc) {
	if(document.all){
		insertAtCaret(document.forms['input'].elements['message'], nc);
		setfocus();
	} else{
		document.forms['input'].elements['message'].value += nc;
		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(txt,addr) {
	if (document.selection && document.selection.type == "Text") {
		var range = document.selection.createRange();
		range.text = "[email]" + range.text + "[/email]";
	} else if (amod) {
		AddTxt="[email] [/email]";
		AddText(AddTxt);
	} else { 
		txt2=prompt(txt,""); 
		if (txt2!=null) {
			txt=prompt(addr,"name@domain.com");      
			if (txt!=null) {
				if (txt2=="") {
					AddTxt="[email]"+txt+"[/email]";
		
				} else {
					AddTxt="[email="+txt+"]"+txt2+"[/email]";
				} 
				AddText(AddTxt);		
			}
		}
	}
}


function chsize(size,txt,msg) {
	if (document.selection && document.selection.type == "Text") {
		var range = document.selection.createRange();
		range.text = "[size=" + size + "]" + range.text + "[/size]";
	} else if (amod) {
		AddTxt="[size="+size+"] [/size]";
		AddText(AddTxt);
	} else {		       
		txt=prompt(msg,txt); 
		if (txt!=null) {	     
			AddTxt="[size="+size+"]"+txt;
			AddText(AddTxt);
			AddText("[/size]");
		}	
	}
}

function chfont(font,txt,msg) {
	if (document.selection && document.selection.type == "Text") {
		var range = document.selection.createRange();
		range.text = "[font=" + font + "]" + range.text + "[/font]";
	} else if (amod) {
		AddTxt="[font="+font+"] [/font]";
		AddText(AddTxt);
	} else {		  
		txt=prompt(msg,txt);
		if (txt!=null) {	     
			AddTxt="[font="+font+"]"+txt;
			AddText(AddTxt);
			AddText("[/font]");
		}
	}  
}


function bold(txt,msg) {
	if (document.selection && document.selection.type == "Text") {
		var range = document.selection.createRange();
		range.text = "[b]" + range.text + "[/b]";
	} else if (amod) {
		AddTxt="[b] [/b]";
		AddText(AddTxt);
	} else {  
		txt=prompt(msg,txt);     
		if (txt!=null) {	   
			AddTxt="[b]"+txt;
			AddText(AddTxt);
			AddText("[/b]");
		}       
	}
}

function italicize(txt,msg) {
       if (document.selection && document.selection.type == "Text") {
		var range = document.selection.createRange();
		range.text = "[i]" + range.text + "[/i]";
	} else if (amod) {
		AddTxt="[i] [/i]";
		AddText(AddTxt);
	} else {   
		txt=prompt(msg,txt);     
		if (txt!=null) {	   
			AddTxt="[i]"+txt;
			AddText(AddTxt);
			AddText("[/i]");
		}	       
	}
}


function underline(txt,msg) {
	if (document.selection && document.selection.type == "Text") {
		var range = document.selection.createRange();
		range.text = "[u]" + range.text + "[/u]";
	} else if (amod) {
		AddTxt="[u] [/u]";
		AddText(AddTxt);
	} else {  
		txt=prompt(msg,txt);
		if (txt!=null) {	   
			AddTxt="[u]"+txt;
			AddText(AddTxt);
			AddText("[/u]");
		}	       
	}
}


function center(txt,msg) {
	if (document.selection && document.selection.type == "Text") {
		var range = document.selection.createRange();
		range.text = "[align=center]" + range.text + "[/align]";
	} else if (amod) {
		AddTxt="[align=center] [/align]";
		AddText(AddTxt);
	} else {  
		txt=prompt(msg,txt);     
		if (txt!=null) {	  
			AddTxt="\r[align=center]"+txt;
			AddText(AddTxt);
			AddText("[/align]");
		}	      
	}
}


function quote(txt,msg) {
	if (document.selection && document.selection.type == "Text") {
		var range = document.selection.createRange();
		range.text = "[quote]" + range.text + "[/quote]";
	} else if (amod) {
		AddTxt="\r[quote]\r[/quote]";
		AddText(AddTxt);
	} else {   
		txt=prompt(msg,txt);     
		if(txt!=null) {	  
			AddTxt="\r[quote]\r"+txt;
			AddText(AddTxt);
			AddText("\r[/quote]");
		}	       
	}
}

function chcolor(color,txt,msg) {
	if (document.selection && document.selection.type == "Text") {
		var range = document.selection.createRange();
		range.text = "[color=" + color + "]" + range.text + "[/color]";
	} else if (amod) {
		AddTxt="[color="+color+"] [/color]";
		AddText(AddTxt);
	} else {  
	txt=prompt(msg,txt);
		if(txt!=null) {
			AddTxt="[color="+color+"]"+txt;
			AddText(AddTxt);
			AddText("[/color]");
		}
	}
}


function hyperlink(txt, msg) {
	if (amod) {
		AddTxt="[url] [/url]";
		AddText(AddTxt);
	} else { 
		txt2=prompt(txt,""); 
		if (txt2!=null) {
			txt=prompt(msg,"http://");      
			if (txt!=null) {
				if (txt2=="") {
					AddTxt="[url]"+txt;
					AddText(AddTxt);
					AddText("[/url]");
				} else {
					AddTxt="[url="+txt+"]"+txt2;
					AddText(AddTxt);
					AddText("[/url]");
				}	 
			} 
		}
	}
}

function image(msg) {
	if (amod) {
		AddTxt="[img] [/img]";
		AddText(AddTxt);
	} else {  
		txt=prompt(msg,"http://");    
		if(txt!=null) {	    
			AddTxt="\r[img]"+txt;
			AddText(AddTxt);
			AddText("[/img]");
		}       
	}
}

function flash(msg) {
	if (amod) {
		AddTxt="[swf] [/swf]";
		AddText(AddTxt);
	} else {  
		txt=prompt(msg,"http://");    
		if(txt!=null) {	    
			AddTxt="\r[swf]"+txt;
			AddText(AddTxt);
			AddText("[/swf]");
		}       
	}
}

function code(msg) {
	if (document.selection && document.selection.type == "Text") {
		var range = document.selection.createRange();
		range.text = "[code]" + range.text + "[/code]";
	} else if (amod) {
		AddTxt="\r[code]\r[/code]";
		AddText(AddTxt);
	} else {   
		txt=prompt(msg,"");     
		if (txt!=null) {	  
			AddTxt="\r[code]"+txt;
			AddText(AddTxt);
			AddText("[/code]");
		}	      
	}
}

function list(m1,m2) {
	if (amod) {
		AddTxt="\r[list]\r[*]\r[*]\r[*]\r[/list]";
		AddText(AddTxt);
	} else {  
		txt=prompt(m2,"");
		if ((txt!="") && (txt!="A") && (txt!="a") && (txt!="1") && (txt!=null)) {
			txt=""	
		}
		if (txt!=null) {
			if (txt=="") {
				AddTxt="\r[list]\r\n";
			} else {
				AddTxt="\r[list="+txt+"]\r";
			} 
			txt="1";
			while ((txt!="") && (txt!=null)) {
				txt=prompt(m1,""); 
				if (txt!="") {	     
					AddTxt+="[*]"+txt+"\r"; 
				}		   
			} 
			AddTxt+="[/list]\r\n";
			AddText(AddTxt); 
		}
	}
}



function blogquote(objID,strAuthor,strTime){
	document.forms['input'].elements['message'].value += "[quote][b][color=blue]"+strAuthor+"[/color]@"+strTime+":[/b]\n"+document.getElementById(objID).innerText+"[/quote]\n";
	setfocus();
}

function setfocus() {
	document.forms['input'].elements['message'].focus();
}
