RadEditorTestModule.prototype = new RadEditorModuleBase();
RadEditorTestModule.prototype.base = RadEditorModuleBase.prototype.constructor;

function RadEditorTestModule(moduleArgs)
{	
	moduleArgs.ModuleElement = document.createElement("DIV");	
	this.base(moduleArgs);	
	this.WordsString = "Words";
	this.CharactersString = "Characters:";
};

RadEditorTestModule.prototype.OnCreate = function()
{
	var selfPointer = this;
	this.AttachEventHandler("onkeydown",  function(){ selfPointer.DoCount(); });

	if (this.Editor.Document.body) this.AttachEventHandler("onblur", function(){ selfPointer.DoCount(); });

	var isEnabled = this.IsEnabled;
	this.IsEnabled = true;
	this.DoCount();
	this.IsEnabled = isEnabled;
};

RadEditorTestModule.prototype.DoCount = function ()
{
	if (!this.IsEnabled || !this.Editor.Document.body) return;
	var content = this.Editor.GetText();
	var words = 0;
	var chars = 0;
	if (content)
	{
		punctRegX = /[!\.?;,:&_\-\-\{\}\[\]\(\)~#'"]/g;
		content = content.replace(punctRegX, "");
		trimRegX = /(^\s+)|(\s+$)/g;
		content = content.replace(trimRegX, "");
		if (content)
		{
			splitRegX = /\s+/;
			var array = content.split(splitRegX);
			words = array.length;
			chars = content.length;
		}
	}
	this.ModuleElement.innerHTML = "<span style='line-height:22px'>" + this.WordsString + " " + words +  " " + this.CharactersString + " " + chars + "&nbsp;</span>";
};
