function selecao(obj, def_texto_padrao)
{
	if(obj.constructor == String)
	{
		obj = document.getElementById(obj);
	}

	var def_texto = (def_texto_padrao) ? function(text) { obj.value += text; } : function() { return false; };
	var selecao = { text: "", defTexto: def_texto };

	if(document.selection)
	{
		var faixa = document.selection.createRange().text;
		if(faixa.text)
		{
			selecao.text = faixa.text;
			selecao.defTexto = function(text)
			{
				faixa.text = text.replace(/\r?\n/g, "\r\n");
			}
		}
	}

	else if(typeof(obj.selectionStart) != "undefined")
	{
		selecao.text = obj.value.substring(obj.selectionStart, obj.selectionEnd);
		selecao.defTexto = function(text)
		{
			obj.value = obj.value.substring(0, obj.selectionStart) + text + obj.value.substring(obj.selectionEnd);
			return false;
		}
	}

	else if(window.getSelection)
	{
		selecao.text = window.getSelection().toString();
	}
	return selecao;
}

function selTexto(obj, antes, depois)
{
	var selecionado = selecao(obj, true);
	selecionado.defTexto(antes + selecionado.text + depois);
}