function fckeditor_GetContents(item_name){
	// Get the editor instance that we want to interact with.
	var oEditor = FCKeditorAPI.GetInstance(item_name) ;
	// Get the editor contents in XHTML.
	return oEditor.GetXHTML( false ) ;// "true" means you want it formatted.
}
function fckeditor_GetHtmlLength(item_name) {
	var oEditor = FCKeditorAPI.GetInstance(item_name) ;
	var oDOM = oEditor.EditorDocument ;
	var iLength ;
	if(document.all){
		iLength = oDOM.body.innerText.length ;
	} else {
		var r = oDOM.createRange() ;
		r.selectNodeContents( oDOM.body ) ;
		iLength = r.toString().length ;
	}
	return iLength;
}
function fckeditor_GetTextLength(item_name) {
	var oEditor = FCKeditorAPI.GetInstance(item_name) ;
	var oDOM = oEditor.EditorDocument ;
	var iLength ;
	if(document.all){
		iLength = oDOM.body.innerText.length ;
	} else {
		var r = oDOM.createRange() ;
		r.selectNodeContents( oDOM.body ) ;
		iLength = r.toString().length ;
	}
	return iLength;
}
function fckeditor_ExecuteCommand(commandName,item_name) {
	// Get the editor instance that we want to interact with.
	var oEditor = FCKeditorAPI.GetInstance(item_name) ;

	// Execute the command.
	oEditor.Commands.GetCommand( commandName ).Execute() ;
}
function fckeditor_GetInnerText(item_name) {
	var oEditor = FCKeditorAPI.GetInstance(item_name) ;
	var oDOM = oEditor.EditorDocument ;
	if(document.all){
		return oDOM.body.innerText;
	} else { // If Gecko.
		var r = oDOM.createRange() ;
		r.selectNodeContents( oDOM.body ) ;
		return r.toString();
	}
}
function fckeditor_cbyte(strvalue){
  var chnvalue;
  var ptnChinese = /[^\u4E00-\u9FA5]/gi;
  chnvalue = strvalue.replace(ptnChinese,"");
  return (strvalue.length+chnvalue.length);
}

function fckeditor_InsertHTML(fckeditor_name,contentHTML) {
  // Get the editor instance that we want to interact with.
  var oEditor = FCKeditorAPI.GetInstance(fckeditor_name) ;
	var contentHTML = new String(contentHTML);

  // Check the active editing mode.
  if ( oEditor.EditMode == FCK_EDITMODE_WYSIWYG )
  {
    // Insert the desired HTML.
		if(contentHTML!='') {
    	oEditor.InsertHtml( contentHTML ) ;
		}
  }
  else
    alert( 'You must be on WYSIWYG mode!' ) ;
}

