function limitText(fieldName, limitNum)
{
	limitCount = document.getElementById('charLimit');
	submitButton = document.getElementById('submit');
	charsLeft = limitNum - fieldName.value.length;
	limitCount.innerHTML = charsLeft;
	
	if (charsLeft >= 50) limitCount.style.color = '#000';
	if (charsLeft >= 30 & charsLeft <= 49) limitCount.style.color = '#800';
	if (charsLeft >= 10 & charsLeft <= 29) limitCount.style.color = '#b00';
	if (charsLeft <= 9) limitCount.style.color = '#d00';
	
	if (fieldName.value.length > limitNum)
	{ submitButton.disabled = 'disabled'; }
	else
	{ submitButton.disabled = ''; }
}

function insertText(open, close)
{
	msgfield = (document.all) ? document.all.message : ((document.getElementById('afocus') != null) ? (document.getElementById('afocus').news) : (document.getElementsByName('message')[0]));

	// IE support
	if (document.selection && document.selection.createRange)
	{
		msgfield.focus();
		sel = document.selection.createRange();
		sel.text = open + sel.text + close;
		msgfield.focus();
	}

	// Moz support
	else if (msgfield.selectionStart || msgfield.selectionStart == '0')
	{
		var startPos = msgfield.selectionStart;
		var endPos = msgfield.selectionEnd;
		
		msgfield.value = msgfield.value.substring(0, startPos) + open + msgfield.value.substring(startPos, endPos) + close + msgfield.value.substring(endPos, msgfield.value.length);
		msgfield.selectionStart = msgfield.selectionEnd = endPos + open.length + close.length;
		msgfield.focus();
	}

	// Fallback support for other browsers
	else
	{
		msgfield.value += open + close;
		msgfield.focus();
	}

	return;
}
	
function toggleDiv(id)
{
	div = document.getElementById( id );
	if (div != null)
	{
		if ( div.style.display == "none" )
		{ div.style.display = "block"; }
		else
		{ div.style.display = "none"; }
	}
}

function confirmDelete(lineNum)
{ 
	return confirm('Are you sure you want delete post ' + lineNum + '?');
}

window.onload = function()
{
	toggleDiv('login');
	toggleDiv('comment');
}