helpstat = false;
stprompt = false;
basic = true;

function insertsmilie(smilieface){
	AddText(smilieface);
}

function thelp(swtch){
	if (swtch == 1){
		basic = false;
		stprompt = false;
		helpstat = true;
	} else if (swtch == 0) {
		helpstat = false;
		stprompt = false;
		basic = true;
	} else if (swtch == 2) {
		helpstat = false;
		basic = false;
		stprompt = true;
	}
}

function getActiveText(selectedtext) { 
	text = (document.all) ? document.selection.createRange().text : document.getSelection();
	if (selectedtext.createTextRange) {	
   		selectedtext.caretPos = document.selection.createRange().duplicate();	
  	}
	return true;
}

function AddText(NewCode) {
	if (document.PostTopic.Message.createTextRange && document.PostTopic.Message.caretPos) {
		var caretPos = document.PostTopic.Message.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? NewCode + ' ' : NewCode;
		document.PostTopic.Message.focus();
	}
	else {
		document.PostTopic.Message.value+=NewCode
	}
}

function strike() {
	if (helpstat) {
		alert("strike Tag Makes the enlosed text striked.\n\nUSE: [s]This is some striked text[/]");
	} else if (basic) {
		AddTxt="[s]"+text+"[/s]";
		AddText(AddTxt);
	} else {   
		txt=prompt("Text to be striked","Text");     
		if (txt!=null) {           
			AddTxt="[s]"+txt+"[/s]";
			AddText(AddTxt);
		}	        
	}
}

function aleft() {
 	if (helpstat) {
		alert("Align left tag aligns the enclosed text left.\n\nUSE: [left]This text is aligned left[/left]");
	} else if (basic) {
		AddTxt="[left]"+text+"[/left]";
		AddText(AddTxt);
	} else {  
		txt=prompt("Text to be aligned left","Text");     
		if (txt!=null) {          
			AddTxt="[left]"+txt+"[/left]";
			AddText(AddTxt);
		}	       
	}
}

function aright() {
 	if (helpstat) {
		alert("Align right tag aligns the enclosed text right.\n\nUSE: [right]This text is aligned right[/right]");
	} else if (basic) {
		AddTxt="[right]"+text+"[/right]";
		AddText(AddTxt);
	} else {  
		txt=prompt("Text to be aligned left","Text");     
		if (txt!=null) {          
			AddTxt="[right]"+txt+"[/right]";
			AddText(AddTxt);
		}	       
	}
}

function pre() {
 	if (helpstat) {
		alert("Pre tag allows you to write freely.\n\nUSE: [pre]This   text   is   written   freely[/pre]");
	} else if (basic) {
		AddTxt="[pre]"+text+"[/pre]";
		AddText(AddTxt);
	} else {  
		txt=prompt("Text to be pre","Text");     
		if (txt!=null) {          
			AddTxt="[pre]"+txt+"[/pre]";
			AddText(AddTxt);
		}	       
	}
}

function marquee() {
 	if (helpstat) {
		alert("Marquee tag moves the enclosed text.\n\nUSE: [marquee]This text is moving[/marquee]");
	} else if (basic) {
		AddTxt="[marquee]"+text+"[/marquee]";
		AddText(AddTxt);
	} else {  
		txt=prompt("Text to be moved","Text");     
		if (txt!=null) {          
			AddTxt="[marquee]"+txt+"[/marquee]";
			AddText(AddTxt);
		}	       
	}
}

function sup() {
 	if (helpstat) {
		alert("Sup tag writes the enclosed text as sup.\n\nUSE: [sup]This text is sup[/sup]");
	} else if (basic) {
		AddTxt="[sup]"+text+"[/sup]";
		AddText(AddTxt);
	} else {  
		txt=prompt("Text to be written sup","Text");     
		if (txt!=null) {          
			AddTxt="[sup]"+txt+"[/sup]";
			AddText(AddTxt);
		}	       
	}
}

function sub() {
 	if (helpstat) {
		alert("Sub tag writes the enclosed text as sub.\n\nUSE: [sub]This text is sub[/sub]");
	} else if (basic) {
		AddTxt="[sub]"+text+"[/sub]";
		AddText(AddTxt);
	} else {  
		txt=prompt("Text to be written sub","Text");     
		if (txt!=null) {          
			AddTxt="[sub]"+txt+"[/sub]";
			AddText(AddTxt);
		}	       
	}
}

function tt() {
 	if (helpstat) {
		alert("Teletype tag writes the enclosed text as TeleType.\n\nUSE: [tt]This text is TeleType[/tt]");
	} else if (basic) {
		AddTxt="[tt]"+text+"[/tt]";
		AddText(AddTxt);
	} else {  
		txt=prompt("Text to be written as TeleType","Text");     
		if (txt!=null) {          
			AddTxt="[tt]"+txt+"[/tt]";
			AddText(AddTxt);
		}	       
	}
}

function bigchar() {
  	if (helpstat) {
		alert("BigChar Tag writes the enclosed text as BigChar.\n\nUSE: [bigchar]This text is BigChar[/bigchar]");
	} else if (basic) {
		AddTxt="[bigchar]"+text+"[/bigchar]";
		AddText(AddTxt);
	} else {  
		txt=prompt("Text to be written as BigChar.","Text");     
		if (txt!=null) {           
			AddTxt="[bigchar]"+txt+"[/bigchar]";
			AddText(AddTxt);
		}	        
	}
}

function hr() {
  	if (helpstat) {
		alert("Horizontal Rule Tag adds a horizontal rule.\n\nUSE: Horizontal Rule[hr]");
	} else if (basic) {
		AddTxt="[hr]";
		AddText(AddTxt);
	} else {  
		txt=prompt("","Text");     
		if (txt!=null) {           
			AddTxt="[hr]";
			AddText(AddTxt);
		}	        
	}
}


function hl() {
  	if (helpstat) {
		alert("Highlight Tag highlights the enclosed text yellow.\n\nUSE: [hl]This text is highlighted with yellow[/hl]");
	} else if (basic) {
		AddTxt="[hl]"+text+"[/hl]";
		AddText(AddTxt);
	} else {  
		txt=prompt("Text to be highlighted yellow.","Text");     
		if (txt!=null) {           
			AddTxt="[hl]"+txt+"[/hl]";
			AddText(AddTxt);
		}	        
	}
}

function email() {
	if (helpstat) {
		alert("Email Tag Turns an email address into a mailto hyperlink.\n\nUSE #1: [url]someone\@anywhere.com[/url] \nUSE #2: [url=\"someone\@anywhere.com\"]link text[/url]");
		}
	else if (basic) {
		AddTxt="[url]"+text+"[/url]";
		AddText(AddTxt);
		}
	else { 
		txt2=prompt("Text to be shown for the link. Leave blank if you want the url to be shown for the link.",""); 
		if (txt2!=null) {
			txt=prompt("URL for the link.","mailto:");      
			if (txt!=null) {
				if (txt2=="") {
					AddTxt="[url]"+txt+"[/url]";
					AddText(AddTxt);
				} else {
					AddTxt="[url=\""+txt+"\"]"+txt2+"[/url]";
					AddText(AddTxt);
				}         
			} 
		}
	}
}
function showsize(size) {
	if (helpstat) {
		alert("Size Tag Sets the text size. Possible values are 1 to 6.\n1 being the smallest and 6 the largest.\n\nUSE: [size="+size+"]This is size "+size+" text[/size="+size+"]");
	} else if (basic) {
		AddTxt="[size="+size+"]"+text+"[/size="+size+"]";
		AddText(AddTxt);
	} else {                       
		txt=prompt("Text to be size "+size,"Text"); 
		if (txt!=null) {             
			AddTxt="[size="+size+"]"+txt+"[/size="+size+"]";
			AddText(AddTxt);
		}        
	}
}

function bold() {
	if (helpstat) {
		alert("Bold Tag Makes the enlosed text bold.\n\nUSE: [b]This is some bold text[/b]");
	} else if (basic) {
		AddTxt="[b]"+text+"[/b]";
		AddText(AddTxt);
	} else {  
		txt=prompt("Text to be made BOLD.","Text");     
		if (txt!=null) {           
			AddTxt="[b]"+txt+"[/b]";
			AddText(AddTxt);
		}       
	}
}

function italicize() {
	if (helpstat) {
		alert("Italicize Tag Makes the enlosed text italicized.\n\nUSE: [i]This is some italicized text[/i]");
	} else if (basic) {
		AddTxt="[i]"+text+"[/i]";
		AddText(AddTxt);
	} else {   
		txt=prompt("Text to be italicized","Text");     
		if (txt!=null) {           
			AddTxt="[i]"+txt+"[/i]";
			AddText(AddTxt);
		}	        
	}
}

function quote() {
	if (helpstat){
		alert("Quote tag Quotes the enclosed text to reference something specific that someone has posted.\n\nUSE: [quote]This is a quote[/quote]");
	} else if (basic) {
		AddTxt=" [quote]"+text+"[/quote]";
		AddText(AddTxt);
	} else {   
		txt=prompt("Text to be quoted","Text");     
		if(txt!=null) {          
			AddTxt=" [quote] "+txt+" [/quote]";
			AddText(AddTxt);
		}	        
	}
}

function showcolor(color) {
	if (helpstat) {
		alert("Color Tag Sets the text color. Any named color can be used.\n\nUSE: ["+color+"]This is some "+color+" text[/"+color+"]");
	} else if (basic) {
		AddTxt="["+color+"]"+text+"[/"+color+"]";
		AddText(AddTxt);
	} else {  
     	txt=prompt("Text to be "+color,"Text");
		if(txt!=null) {
			AddTxt="["+color+"]"+txt+"[/"+color+"]";
			AddText(AddTxt);        
		} 
	}
}

function center() {
 	if (helpstat) {
		alert("Centered tag Centers the enclosed text.\n\nUSE: [center]This text is centered[/center]");
	} else if (basic) {
		AddTxt="[center]"+text+"[/center]";
		AddText(AddTxt);
	} else {  
		txt=prompt("Text to be centered","Text");     
		if (txt!=null) {          
			AddTxt="[center]"+txt+"[/center]";
			AddText(AddTxt);
		}	       
	}
}

function hyperlink() {
	if (helpstat) {
		alert("Hyperlink Tag \nTurns an url into a hyperlink.\n\nUSE: [url]http://www.anywhere.com[/url]\n\nUSE: [url=http://www.anywhere.com]link text[/url]");
	} else if (basic) {
		AddTxt="[url]"+text+"[/url]";
		AddText(AddTxt);
	} else { 
		txt2=prompt("Text to be shown for the link.\nLeave blank if you want the url to be shown for the link.",""); 
		if (txt2!=null) {
			txt=prompt("URL for the link.","http://");      
			if (txt!=null) {
				if (txt2=="") {
					AddTxt="[url]"+txt+"[/url]";
					AddText(AddTxt);
				} else {
					AddTxt="[url=\""+txt+"\"]"+txt2+"[/url]";
					AddText(AddTxt);
				}         
			} 
		}
	}
}

function image() {
	if (helpstat){
		alert("Image Tag Inserts an image into the post.\n\nUSE: [img]http://www.anywhere.com/image.gif[/img]");
	} else if (basic) {
		AddTxt="[img]"+text+"[/img]";
		AddText(AddTxt);
	} else {  
		txt=prompt("URL for graphic","http://");    
		if(txt!=null) {            
			AddTxt="[img]"+txt+"[/img]";
			AddText(AddTxt);
		}	
	}
}

function showcode() {
	if (helpstat) {
		alert("Code Tag Blockquotes the text you reference and preserves the formatting.\nUsefull for posting code.\n\nUSE: [code]This is formated text[/code]");
	} else if (basic) {
		AddTxt=" [code]"+text+"[/code]";
		AddText(AddTxt);
	} else {   
		txt=prompt("Enter code","");     
		if (txt!=null) {          
			AddTxt="[code]"+txt+"[/code]";
			AddText(AddTxt);
		}	       
	}
}

function list() {
	if (helpstat) {
		alert("List Tag Builds a bulleted, numbered, or alphabetical list.\n\nUSE: [list] [*]item1[/*] [*]item2[/*] [*]item3[/*] [/list]");
	} else if (basic) {
		AddTxt=" [list][*]  [/*][*]  [/*][*]  [/*][/list]";
		AddText(AddTxt);
	} else {  
		type=prompt("Type of list Enter \'A\' for alphabetical, \'1\' for numbered, Leave blank for bulleted.","");               
		while ((type!="") && (type!="A") && (type!="a") && (type!="1") && (type!=null)) {
			txt=prompt("ERROR! The only possible values for type of list are blank 'A' and '1'.","");               
		}
		if (type!=null) {
			if (type=="") {
				AddTxt="[list]";
			} else {
				AddTxt="[list="+type+"]";
			} 
			txt="1";
			while ((txt!="") && (txt!=null)) {
				txt=prompt("List item Leave blank to end list",""); 
				if (txt!="") {             
					AddTxt+="[*]"+txt+"[/*]"; 
				}                   
			} 
			if (type=="") {
				AddTxt+="[/list] ";
			} else {
				AddTxt+="[/list="+type+"]";
			} 
			AddText(AddTxt); 
		}
	}
}

function underline() {
  	if (helpstat) {
		alert("Underline Tag Underlines the enclosed text.\n\nUSE: [u]This text is underlined[/u]");
	} else if (basic) {
		AddTxt="[u]"+text+"[/u]";
		AddText(AddTxt);
	} else {  
		txt=prompt("Text to be Underlined.","Text");     
		if (txt!=null) {           
			AddTxt="[u]"+txt+"[/u]";
			AddText(AddTxt);
		}	        
	}
}

function showfont(font) {
 	if (helpstat){
		alert("Font Tag Sets the font face for the enclosed text.\n\nUSE: [font="+font+"]The font of this text is "+font+"[/font]");
	} else if (basic) {
		AddTxt="[font="+font+"]"+text+"[/font="+font+"]";
		AddText(AddTxt);
	} else {                  
		txt=prompt("Text to be in "+font,"Text");
		if (txt!=null) {             
			AddTxt="[font="+font+"]"+txt+"[/font="+font+"]";
			AddText(AddTxt);
		}        
	}  
}

//#################################################################################
//## Allowed User - Selection Code
//#################################################################################

function selectUsers()
{
	if (document.PostTopic.AuthUsers.length == 1)
	{
		document.PostTopic.AuthUsers.options[0].value = "";
		return;
	}
	if (document.PostTopic.AuthUsers.length == 2)
		document.PostTopic.AuthUsers.options[0].selected = true
	else
	for (x = 0;x < document.PostTopic.AuthUsers.length - 1 ;x++)
		document.PostTopic.AuthUsers.options[x].selected = true;
}

function MoveWholeList(strAction)
{
	if (strAction == "Add")
	{
		if (document.PostTopic.AuthUsersCombo.length > 1)
		{
		for (x = 0;x < document.PostTopic.AuthUsersCombo.length - 1 ;x++)
			document.PostTopic.AuthUsersCombo.options[x].selected = true;
			InsertSelection("Add");
		}
	}
	else
	{
		if (document.PostTopic.AuthUsers.length > 1)
		{
		for (x = 0;x < document.PostTopic.AuthUsers.length - 1 ;x++)
			document.PostTopic.AuthUsers.options[x].selected = true;
			InsertSelection("Del");
		}
	}
}

function InsertSelection(strAction)
{
	var pos,user,mText;
	var count,finished;

	if (strAction == "Add")
	{
		pos = document.PostTopic.AuthUsers.length;
		finished = false;
		count = 0;
		do //Add to destination
		{
		try{
			if (document.PostTopic.AuthUsersCombo.options[count].text == "")
			{
				finished = true;
				continue;
			}
		}
		catch(e)
		{
				finished = true;
				return;
		}
			if (document.PostTopic.AuthUsersCombo.options[count].selected)
			{
				document.PostTopic.AuthUsers.length +=1;
				document.PostTopic.AuthUsers.options[pos].value = document.PostTopic.AuthUsers.options[pos-1].value;
				document.PostTopic.AuthUsers.options[pos].text = document.PostTopic.AuthUsers.options[pos-1].text;
				document.PostTopic.AuthUsers.options[pos-1].value = document.PostTopic.AuthUsersCombo.options[count].value;
				document.PostTopic.AuthUsers.options[pos-1].text = document.PostTopic.AuthUsersCombo.options[count].text;
				document.PostTopic.AuthUsers.options[pos-1].selected = true;
			}
			pos = document.PostTopic.AuthUsers.length;
			count += 1;
		}while (!finished); //finished adding
		finished = false;
		count = document.PostTopic.AuthUsersCombo.length - 1;
		do //remove from source
		{
			try {
			if (document.PostTopic.AuthUsersCombo.options[count].text == "")
			{
				--count;
				continue;
			}
			}
			catch(e)
			{
				return;
			}
			if (document.PostTopic.AuthUsersCombo.options[count].selected )
			{
				for ( z = count ; z < document.PostTopic.AuthUsersCombo.length-1;z++)
				{
				if ((document.PostTopic.AuthUsers.length-count) == 2)
				{
						document.PostTopic.AuthUsers.options[z].value = "";
						document.PostTopic.AuthUsers.options[z].text = "";
				}
				else
				{
					document.PostTopic.AuthUsersCombo.options[z].value = document.PostTopic.AuthUsersCombo.options[z+1].value;
					document.PostTopic.AuthUsersCombo.options[z].text = document.PostTopic.AuthUsersCombo.options[z+1].text;
				}
				}
				document.PostTopic.AuthUsersCombo.length -= 1;
			}
			--count;
			if (count < 0)
				finished = true;
		}while(!finished) //finished removing
	}

	if (strAction == "Del")
	{
		pos = document.PostTopic.AuthUsersCombo.length;
		finished = false;
		count = 0;
		do //Add to destination
		{
			try{
			if (document.PostTopic.AuthUsers.options[count].text == "")
			{
				finished = true;
				continue;
			}
			}
			catch(e)
			{
				finished = true;
				return;
			}
			if (document.PostTopic.AuthUsers.options[count].selected)
			{
				document.PostTopic.AuthUsersCombo.length +=1;
				document.PostTopic.AuthUsersCombo.options[pos].value = document.PostTopic.AuthUsersCombo.options[pos-1].value;
				document.PostTopic.AuthUsersCombo.options[pos].text = document.PostTopic.AuthUsersCombo.options[pos-1].text;
				document.PostTopic.AuthUsersCombo.options[pos-1].value = document.PostTopic.AuthUsers.options[count].value;
				document.PostTopic.AuthUsersCombo.options[pos-1].text = document.PostTopic.AuthUsers.options[count].text;
				document.PostTopic.AuthUsersCombo.options[pos-1].selected = true;
			}
			count += 1;
			pos = document.PostTopic.AuthUsersCombo.length;
		}while (!finished); //finished adding
		finished = false;
		count = document.PostTopic.AuthUsers.length - 1;
		do //remove from source
		{
			try{
			if (document.PostTopic.AuthUsers.options[count].text == "")
			{
				--count;
				continue;
			}
			}
			catch(e)
			{
				return;
			}
			if (document.PostTopic.AuthUsers.options[count].selected )
			{
				for ( z = count ; z < document.PostTopic.AuthUsers.length-1;z++)
				{
					if ((document.PostTopic.AuthUsers.length-count) == 2)
						{
						document.PostTopic.AuthUsers.options[z].value = "";
						document.PostTopic.AuthUsers.options[z].text = "";
						}

					else
						{
						document.PostTopic.AuthUsers.options[z].value = document.PostTopic.AuthUsers.options[z+1].value;
						document.PostTopic.AuthUsers.options[z].text = document.PostTopic.AuthUsers.options[z+1].text;
						}
				}
				document.PostTopic.AuthUsers.length -= 1;
			}
			--count;
			if (count < 0)
				finished = true;
		}while(!finished) //finished removing
	}
}