/**
* SelectiveQuote for phpBB3.com by kaefpe [ awozniak.com ]
* Version Number: 1.0 (20th January 2008)
*/

function quoteselect(post_id, username)
{
	var message_name = 'message_' + post_id;
	var theSelection = '';
	var divarea = false;
	if (document.all) { divarea = document.all[message_name]; } else { divarea = document.getElementById(message_name); }
	if (window.getSelection) { theSelection = window.getSelection().toString(); }
	else if (document.getSelection) { theSelection = document.getSelection(); }
	else if (document.selection) { theSelection = document.selection.createRange().text; }

	if (theSelection == '' || typeof theSelection == 'undefined' || theSelection == null)
	{
		if (divarea.innerHTML)
		{
			theSelection = divarea.innerHTML.replace(/<br>/ig, '\n');
			theSelection = theSelection.replace(/<br\/>/ig, '\n');
			theSelection = theSelection.replace(/&lt\;/ig, '<');
			theSelection = theSelection.replace(/&gt\;/ig, '>');
			theSelection = theSelection.replace(/&amp\;/ig, '&');
			theSelection = theSelection.replace(/&nbsp\;/ig, ' ');
		}
		else if (document.all) { theSelection = divarea.innerText; }
		else if (divarea.textContent) { theSelection = divarea.textContent; }
		else if (divarea.firstChild.nodeValue) { theSelection = divarea.firstChild.nodeValue; }
	}

	theSelection = false;
	if (selectedText) theSelection = selectedText;
	else if (document.selection && document.selection.createRange) theSelection = document.selection.createRange().text;

	if (theSelection)
	{
		if (username == '') {
			insert_text('[quote]'+theSelection+'[/quote]');
			selectedText = QuoteAuthor = theSelection = '';
		}
		else
		{
			insert_text('[quote="' + username + '"]' + theSelection + '[/quote]');
			selectedText = QuoteAuthor = theSelection = '';
		}
	}
	return;
}


function qo()
{
	selectedText = document.selection? document.selection.createRange().text : document.getSelection();
}

function qc()
{
	QuoteAuthor = '';
}
