var sInitColor=null;
function copyText(oControl) {
	var ancestorID = oControl.parentNode.id;
	var contentareaID = ancestorID.replace('uiRT', 'uiContentrich');
	var contentstoreID = ancestorID.replace('uiRT', 'uiContentstore');
	document.getElementById(contentstoreID).value = document.getElementById(contentareaID).innerHTML;
}
function RTHeader() {
	var oRange = document.selection.createRange();
	var sHtml = oRange.htmlText;
	sHtml = "<span class='rte_header'>" + sHtml + "</span>";
	document.selection.createRange().pasteHTML(sHtml);
}
function RTFormat(sCommand, oControl) {
	var ancestorID = oControl.parentNode.parentNode.parentNode.parentNode.parentNode.id;
	var contentareaID = ancestorID.replace('uiRT', 'uiContentrich');
	document.getElementById(contentareaID).focus();
	document.execCommand(sCommand);
}
function changeForeColour() {
	if (sInitColor == null) { var sColor = document.dlgHelper.ChooseColorDlg(); }
	else { var sColor = document.dlgHelper.ChooseColorDlg(sInitColor); }
	sColor = sColor.toString(16);
	if (sColor.length < 6) {
		var sTempString = '000000'.substring(0,6-sColor.length);
		sColor = sTempString.concat(sColor);
	}
	document.execCommand('ForeColor', false, sColor);
	sInitColor = sColor;
}
function cleanMSWordHtml(oControl) {
	var arr_find = [
		String.fromCharCode(8220), //“
		String.fromCharCode(8221), //”
		String.fromCharCode(8216), //‘
		String.fromCharCode(8217), //‘
		String.fromCharCode(8211), //–
		String.fromCharCode(8212), //—
		String.fromCharCode(189), //½
		String.fromCharCode(188), //¼
		String.fromCharCode(190), //¾
		String.fromCharCode(169), //©
		String.fromCharCode(174), //®
		String.fromCharCode(8230) //…
	];
	var arr_replace = ['"','"',"'","'","-","--","1/2","1/4","3/4","(C)","(R)","..."];
	var ancestorID = oControl.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.id;
	var contentareaID = ancestorID.replace('uiRT', 'uiContentrich');
	var sHtml = document.getElementById(contentareaID).innerHTML;
	if ( (sHtml.indexOf('class=Mso') >= 0) || (sHtml.indexOf('mso-') >=0) ) {
		// kill unwanted tags
		sHtml = sHtml.replace(/<\?xml:[^>]*>/g, ''); // Word xml
		sHtml = sHtml.replace(/<\/?st1:[^>]*>/g,''); // Word SmartTags
		sHtml = sHtml.replace(/<\/?[a-z]\:[^>]*>/g,''); // All other funny Word non-HTML stuff
		sHtml = sHtml.replace(/<\/?font[^>]*>/gi,''); // Disable if you want to
		sHtml = sHtml.replace(/ class=[^\s|>]*/gi,'');
		sHtml = sHtml.replace(/ style=\"[^>]*(mso)*\"/gi,'');
		for ( var i=0; i<arr_find.length; i++ ) {
			var regex = new RegExp(arr_find[i], "gi");
			sHtml = sHtml.replace(regex, arr_replace[i]);
		}
	}
	//sHtml = sHtml.replace(/ <\\/o:[pP]>/g, ''); "; // Remove all instances of 
	//sHtml = sHtml.replace(/o:/g, ''); "; // delete all o: prefixes
	//sHtml = sHtml.replace(//g, ''); "; // delete all smarttags
	//sHtml = sHtml.replace(/<[pP]><\\/[pP]>/g, ''); "; // delete all empty paragraph tags
	//sHtml = sHtml.replace(/<[pP]> <\\/[pP]>/g, ''); "; // delete all empty paragraph tags
	document.getElementById(contentareaID).innerHTML = sHtml;
}
