 
function finn_format(txtArea, formatType){
	var substitute = "";
	var prepend = "";
	var	append = "";
	switch(formatType){
		case "heading":
			prepend = "\n[[[";
			append = "]]]\n";
			break;
		case "bold":
			prepend = "[[";
			append = "]]";
			break;
		default:
			substitute = formatType;
			break;
	}
	if(txtArea){
		txtArea.focus();
		if( document.selection) {
			var range = document.selection.createRange();
			if(substitute != "") { 
				range.text = substitute;				  
			} else if (range.text.length>0){
				range.text = prepend + range.text + append;
			}
			txtArea.focus();
		} else if(txtArea.textLength!= undefined && txtArea.selectionStart!= undefined && txtArea.selectionEnd!= undefined)  {
			var sLen = txtArea.textLength;
			var sBeg = txtArea.selectionStart;
			var sEnd = txtArea.selectionEnd; 
			var sTop = txtArea.scrollTop; 
			if (sEnd == 1 || sEnd == 2) sEnd = sLen; 
			
			var before = (txtArea.value).substring(0,sBeg);
			var sText = (txtArea.value).substring(sBeg, sEnd)
			var after = (txtArea.value).substring(sEnd, sLen);
			if(substitute != "") {
				txtArea.value= (before + substitute + after );
			} else if (sText.length>0){
				txtArea.value= (before + prepend + sText + append + after );
			}
			txtArea.scrollTop = sTop;
			txtArea.focus();
			
		} else {
			alert("This function is not available in your browser. Please insert the special formatting directly in the text");
		}
		return false;
	}
	
	 
	
} 