	function addtext(texty)
	{
		var newtext = texty;
		document.addnews.post.value += newtext;
	}

	function addimage()
	{
		//Detects selected text in the textbox
		var begin = document.addnews.post.value.substr(0, document.addnews.post.selectionStart); 
		var selection = document.addnews.post.value.substr(document.addnews.post.selectionStart, document.addnews.post.selectionEnd - document.addnews.post.selectionStart); 
		var end = document.addnews.post.value.substr(document.addnews.post.selectionEnd);
		
		if (selection.length > 0)
		{
			document.addnews.post.value = begin + '[img]' + selection + '[/img]' + end;
			document.addnews.post.focus();
		}
		else
		{
			var newtext = prompt('Enter the URL of the picture here:', '');
			if (newtext == null)
			{
				newtext = "None";
			}
			newtext = '[img]' + newtext + '[/img]';
			document.addnews.post.value = begin + selection + newtext + end;
			document.addnews.post.focus();
		}
	}

	function addyoutube()
	{
		//Detects selected text in the textbox
		var begin = document.addnews.post.value.substr(0, document.addnews.post.selectionStart); 
		var selection = document.addnews.post.value.substr(document.addnews.post.selectionStart, document.addnews.post.selectionEnd - document.addnews.post.selectionStart); 
		var end = document.addnews.post.value.substr(document.addnews.post.selectionEnd);
		
		if (selection.length > 0)
		{
			document.addnews.post.value = begin + '[youtube]' + selection + '[/youtube]' + end;
			document.addnews.post.focus();
		}
		else
		{
			var newtext = prompt('Enter the URL of the youtube link here, for example \nhttp://www.youtube.com/watch?v=EwTZ2xpQwpA:', '');
			if (newtext == null)
			{
				newtext = "None";
			}
			newtext = '[youtube]' + newtext + '[/youtube]';
			document.addnews.post.value = begin + selection + newtext + end;
			document.addnews.post.focus();
		}
	}
	
	function addurl()
	{
		//Detects selected text in the textbox
		var begin = document.addnews.post.value.substr(0, document.addnews.post.selectionStart); 
		var selection = document.addnews.post.value.substr(document.addnews.post.selectionStart, document.addnews.post.selectionEnd - document.addnews.post.selectionStart); 
		var end = document.addnews.post.value.substr(document.addnews.post.selectionEnd);
		
		if (selection.length > 0)
		{
			document.addnews.post.value = begin + '[url="' + selection + '"]' + selection + '[/url]' + end;
			document.addnews.post.focus();
		}
		else
		{
			var newurl = prompt('Enter the website address (URL) you want to link to:', 'http://');
			if (newurl == null)
			{
				newurl = "None";
			}
			var newdesc = prompt('Enter the name of the website (optional):', '');
			if ((newdesc == null)||(newdesc == ""))
			{
				newdesc = newurl;
			}
			var newtext = '[url="' + newurl + '"]' + newdesc + '[/url]';
			document.addnews.post.value = begin + selection + newtext + end;
			document.addnews.post.focus();
		}
	}
	
	function addemail()
	{
		//Detects selected text in the textbox
		var begin = document.addnews.post.value.substr(0, document.addnews.post.selectionStart); 
		var selection = document.addnews.post.value.substr(document.addnews.post.selectionStart, document.addnews.post.selectionEnd - document.addnews.post.selectionStart); 
		var end = document.addnews.post.value.substr(document.addnews.post.selectionEnd);
		
		if (selection.length > 0)
		{
			document.addnews.post.value = begin + '[mail="' + selection + '"]' + selection + '[/mail]' + end;
			document.addnews.post.focus();
		}
		else
		{
			var newurl = prompt('Enter the email address you want to link to:', 'someome@example.com');
			if (newurl == null)
			{
				newurl = "None";
			}
			var newdesc = prompt('Enter an alias for the recipient (optional):', '');
			if ((newdesc == null)||(newdesc == ""))
			{
				newdesc = newurl;
			}
			var newtext = '[mail="' + newurl + '"]' + newdesc + '[/mail]';
			document.addnews.post.value = begin + selection + newtext + end;
			document.addnews.post.focus();
		}
	}
	
	function addbbcode(bbcode)
	{
		var bb = bbcode;
		var text1 = "[" + bb + "]";
		var text2 = "[/" + bb + "]";
		
		//Detects selected text in the textbox
		var begin = document.addnews.post.value.substr(0, document.addnews.post.selectionStart); 
		var selection = document.addnews.post.value.substr(document.addnews.post.selectionStart, document.addnews.post.selectionEnd - document.addnews.post.selectionStart); 
		var end = document.addnews.post.value.substr(document.addnews.post.selectionEnd);
		
		document.addnews.post.value = begin + text1 + selection + text2 + end;
		document.addnews.post.focus();
	}