// JavaScript Document
function getSelectedValues(txtarea){
	var selectedValue	=	'';
	//document.getElementById('testTextArea').innerHTML = '\'\'\'Bold text\'\'\'';
	if(document.selection && document.selection.createRange().text != ''){ // FOR IE
		selectedValue = document.selection.createRange().text;
	}
	else{
		selectedValue = (txtarea.value).substring(txtarea.selectionStart,txtarea.selectionEnd);  
	}
	return selectedValue;
}
function replaceSelection(txtarea,text){
	var scroll_top = txtarea.scrollTop;
	if(!!document.selection){
		txtarea.focus();
		var range = (this.range) ? this.range : document.selection.createRange();
		range.text = text;
		range.select();
	}else if(!!txtarea.setSelectionRange){
		var selection_start = txtarea.selectionStart;
		txtarea.value = txtarea.value.substring(0,selection_start) + text + txtarea.value.substring(txtarea.selectionEnd);
		txtarea.setSelectionRange(selection_start + text.length,selection_start + text.length);
	}
	txtarea.focus();
	txtarea.scrollTop = scroll_top;
}
function fncMakeSelectionBold(txtarea){
	selectedValue = getSelectedValues(txtarea);
	replacedValue = '\'\'\''+selectedValue+'\'\'\'';
	replaceSelection(txtarea,replacedValue);
}
function fncMakeSelectionItalics(txtarea){
	selectedValue = getSelectedValues(txtarea);
	replacedValue = '\'\''+selectedValue+'\'\'';
	replaceSelection(txtarea,replacedValue);
}
function fncMakeSelectionHyperlink(txtarea){
	selectedValue = getSelectedValues(txtarea);
	replacedValue = '[['+selectedValue+']]';
	replaceSelection(txtarea,replacedValue);
}
function fncMakeSelectionExternalHyperlink(txtarea){
	selectedValue = getSelectedValues(txtarea);
	replacedValue = '['+selectedValue+']';
	replaceSelection(txtarea,replacedValue);
}
function fncMakeSelectionHeading(txtarea){
	selectedValue = getSelectedValues(txtarea);
	replacedValue = '\n== '+selectedValue+' ==\n';
	replaceSelection(txtarea,replacedValue);
}
function fncMakeSelectionEmbedFile(txtarea){
	selectedValue = getSelectedValues(txtarea);
	replacedValue = '[[Image:'+selectedValue+']]';
	replaceSelection(txtarea,replacedValue);
}
function fncMakeSelectionHorizondalRule(txtarea){
	selectedValue = getSelectedValues(txtarea);
	replacedValue = '\n----\n'+selectedValue;
	replaceSelection(txtarea,replacedValue);
}
