objtowrite = null;

function addURL(obj)
{
	var prmpt1;
	var prmpt2;

	prmpt1 = prompt("Inserisci L'indirizzo URL","http://");
	if (prmpt1!=null)
	{
		if (document.selection)
		{
			obj.focus();
			sel = document.selection.createRange();

			prmpt2 = prompt("Inserisci il Link visualizzato", sel.text);
			if (prmpt2!=null)
			{
				sel.text = "[url=" + prmpt1 + "]" + prmpt2  + "[/url]";
			}
		}
		else
		if ( typeof obj.selectionStart != 'undefined' )
		{
			var before, selection, after;
			before = obj.value.substring(0, obj.selectionStart);
			selection = obj.value.substring(obj.selectionStart, obj.selectionEnd);
			after = obj.value.substring(obj.selectionEnd, obj.value.length);

			selst = obj.selectionStart;
			selnd = obj.selectionEnd;
			selr = ( obj.value.length - selnd );

			prmpt2 = prompt("Inserisci il Link visualizzato", selection);

			if (prmpt2 != null)
			{
				obj.value = before + "[url=" + prmpt1 + "]" + prmpt2  + "[/url]" + after;

				selnd = ( obj.value.length - selr );
				obj.setSelectionRange(selst, selnd);
			}
		}
		else
		{
			obj.value += "[url=" + prmpt1 + "]" + "[/url]";
		}
	}
}

function addTag(obj, tag)
{
	if (document.selection)
	{
		obj.focus();
		sel = document.selection.createRange();

		sel.text = "[" + tag + "]" + sel.text + "[/" + tag + "]";
	}
	else
	if ( typeof obj.selectionStart != 'undefined' )
	{
		var before, selection, after;
		before = obj.value.substring(0, obj.selectionStart);
		selection = obj.value.substring(obj.selectionStart, obj.selectionEnd);
		after = obj.value.substring(obj.selectionEnd, obj.value.length);

		selst = obj.selectionStart;
		selnd = obj.selectionEnd;
		selr = ( obj.value.length - selnd );

		obj.value = before + "[" + tag + "]" + selection + "[/" + tag + "]" + after;

		selnd = ( obj.value.length - selr );
		obj.setSelectionRange(selst, selnd);
	}
	else
	{
		obj.value += "[" + tag + "]" + "[/" + tag + "]";
	}
}

function addTag2(obj, tag)
{
	prmpt1 = prompt("Inserisci Il testo qui","");
	if (prmpt1!=null)
	{
		if (document.selection)
		{
			obj.focus();
			sel = document.selection.createRange();

			sel.text = "[" + tag + "]" + prmpt1 + "[/" + tag + "]";
		}
		else
		if ( typeof obj.selectionStart != 'undefined' )
		{
			var before, selection, after;
			before = obj.value.substring(0, obj.selectionStart);
			selection = obj.value.substring(obj.selectionStart, obj.selectionEnd);
			after = obj.value.substring(obj.selectionEnd, obj.value.length);

			selst = obj.selectionStart;
			selnd = obj.selectionEnd;
			selr = ( obj.value.length - selnd );

			obj.value = before + "[" + tag + "]" + prmpt1 + "[/" + tag + "]" + after;

			selnd = ( obj.value.length - selr );
			obj.setSelectionRange(selst, selnd);
		}
		else
		{
			obj.value += "[" + tag + "]" + "[/" + tag + "]";
		}
	}
}
