function preview_update(source)
{
	var target;
	if (source && document.getElementById)
	{
		target = document.getElementById('preview_area');
		if (target)
		{
			target.innerHTML = '<p>'+ preview_format_text(source.value) + '</p>';
		}
	}
}

function preview_format_text(text)
{
	text = text.replace(/</ig, '&lt;');
	text = text.replace(/>/ig, '&gt;');

	text = text.replace(/'/ig, '&rsquo;');
	text = text.replace(/\.\.\./ig, '&hellip;');
	text = text.replace(/ - /ig, '&nbsp;&ndash; ');
	text = text.replace(/"(.+?)"/, '&bdquo;$1&ldquo;');
	text = text.replace(/(\*.+?\*)/g, '<strong>$1</strong>');
	text = text.replace(/(\_.+?\_)/g, '<u>$1</u>');

	text = text.replace(/:-\)/g, '<img src="/img/emoticons/smiley-smile.gif" width="18" height="18" alt=":-)" style="border: none" align="middle">');
	text = text.replace(/:-\(/g, '<img src="/img/emoticons/smiley-frown.gif" width="18" height="18" alt=":-(" style="border: none" align="middle">');

	text = text.replace(/8-\)/g, '<img src="/img/emoticons/smiley-cool.gif" width="18" height="18" alt="8-)" style="border: none" align="middle">');
	text = text.replace(/:\'-\(/g, '<img src="/img/emoticons/smiley-cry.gif" width="18" height="18" alt=":\'-(" style="border: none" align="middle">');
	text = text.replace(/;\.\.\(/g, '<img src="/img/emoticons/smiley-cry.gif" width="18" height="18" alt=";..(" style="border: none" align="middle">');

	text = text.replace(/:-\*/g, '<img src="/img/emoticons/smiley-kiss.gif" width="18" height="18" alt=":-*" style="border: none" align="middle">');
	text = text.replace(/:-D/g, '<img src="/img/emoticons/smiley-laughing.gif" width="18" height="18" alt=":-D" style="border: none" align="middle">');
	text = text.replace(/\$-\)/g, '<img src="/img/emoticons/smiley-money-mouth.gif" width="18" height="18" alt="$-)" style="border: none" align="middle">');
	text = text.replace(/:-x/g, '<img src="/img/emoticons/smiley-sealed.gif" width="18" height="18" alt=":-x" style="border: none" align="middle">');

	text = text.replace(/:-o/g, '<img src="/img/emoticons/smiley-surprised.gif" width="18" height="18" alt=":-o" style="border: none" align="middle">');
	text = text.replace(/:-O/g, '<img src="/img/emoticons/smiley-surprised.gif" width="18" height="18" alt=":-O" style="border: none" align="middle">');

	text = text.replace(/:-p/g, '<img src="/img/emoticons/smiley-tongue-out.gif" width="18" height="18" alt=":-p" style="border: none" align="middle">');
	text = text.replace(/:-P/g, '<img src="/img/emoticons/smiley-tongue-out.gif" width="18" height="18" alt=":-P" style="border: none" align="middle">');
	text = text.replace(/:-q/g, '<img src="/img/emoticons/smiley-tongue-out.gif" width="18" height="18" alt=":-q" style="border: none" align="middle">');

	text = text.replace(/:-\//g, '<img src="/img/emoticons/smiley-undecided.gif" width="18" height="18" alt=":-/" style="border: none" align="middle">');
	text = text.replace(/:-\\/g, '<img src="/img/emoticons/smiley-undecided.gif" width="18" height="18" alt=":-\\" style="border: none" align="middle">');

	text = text.replace(/;-\)/g, '<img src="/img/emoticons/smiley-wink.gif" width="18" height="18" alt=";-)" style="border: none" align="middle">');
	text = text.replace(/:-@/g, '<img src="/img/emoticons/smiley-yell.gif" width="18" height="18" alt=":-@" style="border: none" align="middle">');

	text = text.replace(/(https?:\/\/([^\s]+))/ig, '<a href="$1">$2</a>');
	text = text.replace(/\r?\n\r?/g, '<br>');

	return(text);
}

