// FCKeditor_OnComplete is a special function that is called when an editor
// instance is loaded ad available to the API. It must be named exactly in
// this way.
function FCKeditor_OnComplete( editorInstance )
{
}

function FCKeditor_InsertHTML(pInstanceName, pHtml)
{
	// Get the editor instance that we want to interact with.
	var oEditor = FCKeditorAPI.GetInstance(pInstanceName) ;

	// Check the active editing mode.
	if ( oEditor.EditMode == FCK_EDITMODE_WYSIWYG )
	{
		// Insert the desired HTML.
		oEditor.InsertHtml(pHtml) ;
	}
	else
		alert( 'You must be on WYSIWYG mode!' ) ;
}

function FCKeditor_SetContents(pInstanceNamem, pHtml)
{
	// Get the editor instance that we want to interact with.
	var oEditor = FCKeditorAPI.GetInstance(pInstanceName) ;

	// Set the editor contents (replace the actual one).
	oEditor.SetData(pHtml) ;
}

function FCKeditor_GetContents(pInstanceName)
{
	// Get the editor instance that we want to interact with.
	var oEditor = FCKeditorAPI.GetInstance(pInstanceName) ;

	// Get the editor contents in XHTML.
	return oEditor.GetXHTML( true );		// "true" means you want it formatted.
}

function FCKeditor_ExecuteCommand(pInstanceName, commandName )
{
	// Get the editor instance that we want to interact with.
	var oEditor = FCKeditorAPI.GetInstance(pInstanceName) ;

	// Execute the command.
	oEditor.Commands.GetCommand( commandName ).Execute() ;
}

function FCKeditor_GetLength(pInstanceName)
{
	// This functions shows that you can interact directly with the editor area
	// DOM. In this way you have the freedom to do anything you want with it.

	// Get the editor instance that we want to interact with.
	var oEditor = FCKeditorAPI.GetInstance(pInstanceName) ;

	// Get the Editor Area DOM (Document object).
	var oDOM = oEditor.EditorDocument ;

	var iLength ;

	// The are two diffent ways to get the text (without HTML markups).
	// It is browser specific.

	if ( document.all )		// If Internet Explorer.
	{
		iLength = oDOM.body.innerText.length ;
	}
	else					// If Gecko.
	{
		var r = oDOM.createRange() ;
		r.selectNodeContents( oDOM.body ) ;
		iLength = r.toString().length ;
	}

	return iLength ;
}

function FCKeditor_GetInnerHTML(pInstanceName)
{
	// Get the editor instance that we want to interact with.
	var oEditor = FCKeditorAPI.GetInstance(pInstanceName) ;

	return oEditor.EditorDocument.body.innerHTML;
}

function FCKeditor_CheckIsDirty(pInstanceName)
{
	// Get the editor instance that we want to interact with.
	var oEditor = FCKeditorAPI.GetInstance(pInstanceName) ;
	return oEditor.IsDirty();
}

function FCKeditor_ResetIsDirty()
{
	// Get the editor instance that we want to interact with.
	var oEditor = FCKeditorAPI.GetInstance(pInstanceName) ;
	oEditor.ResetIsDirty() ;
	alert( 'The "IsDirty" status has been reset' ) ;
}

