var focusedField = "";

function getFocusedFieldName(field)
{
	focusedField = field.name;
}

function charsleft(field)
{
	var count = field.value.length;
	if (count > 250 )
	{
		field.value = field.value.substring(0,250);
	}
}

function add(text)
{
	var text = ' ' + text + ' ';

	if (document.forms["pmn_add_new_form"].elements[focusedField].createTextRange && 
			document.forms["pmn_add_new_form"].elements[focusedField].caretPos)
	{
		var caretPos = document.forms["pmn_add_new_form"].elements[focusedField].caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 2) == ' ' ? text + ' ' : text;
		document.forms["pmn_add_new_form"].elements[focusedField].focus();
	}
	else
	{
		document.forms["pmn_add_new_form"].elements[focusedField].value  += text;
		document.forms["pmn_add_new_form"].elements[focusedField].focus();
	}
	document.forms["pmn_add_new_form"].elements[focusedField].focus();
}

function storeCaret(textEl)
{
	if (textEl.createTextRange)
		textEl.caretPos = document.selection.createRange().duplicate();
}

