// JavaScript Document
function autosize(txtBox){
	var nCols = txtBox.cols;
	if(nCols<0){
		nCols = 40;
	}
	
	var sVal = txtBox.value;
	var nVal = sVal.length;
	var nRowCnt = 1;
	
	for (i=0;i<nVal;i++){ 
		if (sVal.charAt(i).charCodeAt(0) == 13 || sVal.charAt(i).charCodeAt(0) == 10){ 
			nRowCnt +=1; 
		} 
	}
	
	if (nRowCnt < (nVal / nCols)) { 
		nRowCnt = 1 + (nVal / nCols); 
	}
	
	if(nRowCnt<4){nRowCnt=4;}
	if(nRowCnt>40){nRowCnt=40;}
	
	txtBox.rows = nRowCnt;
}

<!--
var agt = navigator.userAgent.toLowerCase();
var oText;
var iWebLink = 1;
var iEmailLink = 2;
var iImageLink = 3;
var isIE = (agt.indexOf("msie") != -1);

function heading(oTextArea)
{
	var sAlertText = 'Enter the text to make Heading';
	var sPromptText = '';
	var sStartTag = '[H]';
	var sEndTag = '[/H]';
	setFormElement(oTextArea);
  doReplace(sStartTag, sEndTag, sAlertText, sPromptText, false, false);
}
function bold(oTextArea)
{
	var sAlertText = 'Enter the text to make Bold';
	var sPromptText = '';
	var sStartTag = '[B]';
	var sEndTag = '[/B]';
	setFormElement(oTextArea);
  doReplace(sStartTag, sEndTag, sAlertText, sPromptText, false, false);
}

function clearTextBox(oTextArea)
{
  if (confirm('Are you sure you want to clear all the text above?'))
  {
    oTextArea.value = '';
    setFocus(oTextArea);
  }
}

function color(oTextArea, oControl)
{
	setFormElement(oTextArea);
  if (trim(getSelectedValue(oControl)).length != 0)
  {
	  var sColor = getSelectedValue(oControl);
	  sColor = sColor.toLowerCase();
	  var sColorName = getSelectedText(oControl);
	  var sAlertText = 'Enter the text you want to change to ' + sColorName;
	  var sPromptText = '';
	  var sStartTag = '[COLOUR=' + sColor + ']';
	  var sEndTag = '[/COLOUR]';
	  doReplace(sStartTag, sEndTag, sAlertText, sPromptText, false, false);
	}
	else
	{
		oControl.selectedIndex = 0;
	}
}

function doReplace(startTag, endTag, alertText, promptText, embedValue, applyPadding)
{
	var oRange;
	var sSelected;
	var insertText = '';
	var insertTextEmbed = '';
	
	if (isIE)
	{
		// Internet Explorer.
		if (document.selection && document.selection.createRange)
		{
			var oRange = document.selection.createRange();
			var sSelected = oRange.text;
		}
		if (sSelected && (oText.value.indexOf(sSelected) >= 0))
		{
			// There is highlighted text.
			oRange.text = startTag + sSelected + endTag;
			oText.focus();
			return;
		}
	}
	else
	{
		// Mozilla etc.
		if (oText.selectionStart < oText.selectionEnd)
		{
			// We have some highlighted text.
			sSelected = oText.value.substring(oText.selectionStart, oText.selectionEnd);
			oText.value = oText.value.substring(0, oText.selectionStart) + startTag + oText.value.substring(oText.selectionStart, oText.selectionEnd) + endTag + oText.value.substring(oText.selectionEnd, oText.value.length);
			oText.focus();
			return;
		}
	}
	
	// There is no highlighted text. Prompt the user to provide text.
	if (embedValue == false)
	{
		insertText = prompt(alertText, promptText);
		if (insertText == null)
		{
			return false;
		}
		else
		{
			insertAtCursor(startTag + insertText + endTag, applyPadding);
		}
	}
	else
	{
		insertText = prompt(alertText, promptText);
		if (insertText == null)
		{
			return false;
		}
		insertTextEmbed = prompt("Enter the text you want to display for your link", insertText);
		
		if (insertTextEmbed == null)
		{
			return false;
		}
		else
		{
			insertAtCursor(startTag + insertText + ']' + insertTextEmbed + endTag, applyPadding);
		}
	}
}

function getSelectedText(oObject)
{
	return oObject.options[oObject.selectedIndex].text;
}

function getSelectedValue(oObject)
{
	return oObject.options[oObject.selectedIndex].value;
}

function getSelection()
{
	if (isIE)
	{
		// Internet Explorer.
		if (document.selection && document.selection.createRange)
		{
			var oRange = document.selection.createRange();
			return oRange.text;
		}
		else
		{
			return '';
		}
	}
	else
	{
		// Mozilla etc.
		if (oText.selectionStart < oText.selectionEnd)
		{
			// We have some highlighted text.
			return oText.value.substring(oText.selectionStart, oText.selectionEnd);
		}
		else
		{
			return '';
		}
	}
}

function insertAtCursor(text, applyPadding)
{
  if (applyPadding == true)
  {
		text = ' ' + text + ' ';
	}
	postWrite(text);
}

function insertSmiley(oTextArea, text, applyPadding)
{
	setFormElement(oTextArea);
  insertAtCursor(text, applyPadding);
}

function italic(oTextArea)
{
	var sAlertText = 'Enter the text to make Italic';
	var sPromptText = '';
	var sStartTag = '[I]';
	var sEndTag = '[/I]'
	setFormElement(oTextArea);
	doReplace(sStartTag, sEndTag, sAlertText, sPromptText, false, false);
}

function link(oTextArea, iType)
{
	var sURL;
	var sPromptText;
	var sAlertText;
	var sStartTag;
	var sEndTag;
	
  setFormElement(oTextArea);
	if (iType == iWebLink)
	{
		sPromptText = 'http://';
	  sAlertText = 'Enter the Web Address (URL) you want to use';
	  sStartTag = '[IMG]';
	  sEndTag = '[/IMG]'
		sURL = getSelection()
		
		if (sURL.length == 0)
		{
		  doReplace('[URL=', '[/URL]', sAlertText, sPromptText, true, false);
		}
		else
		{
		  doReplace('[URL=' + sURL + ']', '[/URL]', sAlertText, sPromptText, true, false);
		}
	}
	else if (iType == iImageLink)
	{
	  sPromptText = 'http://';
	  sAlertText = 'Enter the Web Address (URL) of the image you want to use';
	  sStartTag = '[IMG]';
	  sEndTag = '[/IMG]'
	  doReplace(sStartTag, sEndTag, sAlertText, sPromptText, false, false);
	}
	else
	{
		sPromptText = '';
	  sAlertText = 'Enter the E-mail Address you want to use';
	  sStartTag = '[IMG]';
	  sEndTag = '[/IMG]'
		sURL = getSelection()
		
		if (sURL.length == 0)
		{
		  doReplace('[EMAIL=', '[/EMAIL]', sAlertText, sPromptText, true, false);
		}
		else
		{
		  doReplace('[EMAIL=' + sURL + ']', '[/EMAIL]', sAlertText, sPromptText, true, false);
		}
	}
	oText.focus();
}

function postWrite(text)
{
	if (isIE)
	{
		if (oText.createTextRange && oText.caretPos)
		{
			var caretPos = oText.caretPos;
			caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ?	text + ' ' : text;
		}
		else
		{
			oText.value += text;
		}
	}
	else
	{
		// Mozilla etc.
		oText.value = oText.value.substring(0, oText.selectionStart) + text + oText.value.substring(oText.selectionStart, oText.selectionEnd) + oText.value.substring(oText.selectionEnd, oText.value.length);
	}
	oText.focus();
}

function setFocus(oObject)
{
	if (oObject)
	{
		oObject.focus();
	}
}

function setFormElement(oTextArea)
{
	oText = oTextArea;
}

function storeCaret(oTextArea)
{
	if (oTextArea.createTextRange)
	{
		oTextArea.caretPos = document.selection.createRange().duplicate();
	}
}

function strike(oTextArea)
{
	var sAlertText = 'Enter the text to Strike';
	var sPromptText = '';
	var sStartTag = '[S]';
	var sEndTag = '[/S]'
	setFormElement(oTextArea);
	doReplace(sStartTag, sEndTag, sAlertText, sPromptText, false, false);
}

function underline(oTextArea)
{
	var sAlertText = 'Enter the text to Underline';
	var sPromptText = '';
	var sStartTag = '[U]';
	var sEndTag = '[/U]'
	setFormElement(oTextArea);
	doReplace(sStartTag, sEndTag, sAlertText, sPromptText, false, false);
}
// -->