function stripcode(oldstring)
{
var newstring = "";
var tag = false;
for(var x = 0; x < oldstring.length; x++)
{
if(oldstring.charAt(x) == '<')
{
tag = true;
}
if(oldstring.charAt(x) == '>')
{
tag = false;
x++;
}
if(tag==false)
{
newstring += oldstring.charAt(x);
}
}
return newstring;
}

   function removeHTMLTags(htmlString){
        if(htmlString){
          var mydiv = document.createElement("div");
           mydiv.innerHTML = htmlString;
 
            if (document.all) // IE Stuff
            {
                return mydiv.innerText;
               
            }   
            else // Mozilla does not work with innerText
            {
                return mydiv.textContent;
            }                           
      }
   } 	
function countWordsA(textarea_id)
{
var counter_name = textarea_id + "_counter";
var tiny_ID; //This is the ID of your tinyMCE content ID
var strip=removeHTMLTags(tinyMCE.activeEditor.getContent());
var fullStr = strip + " ";
var initial_whitespace_rExp = /^[^\S]+/gi;
var left_trimmedStr = fullStr.replace(initial_whitespace_rExp, "");
var non_alphanumerics_rExp = rExp = /[^\S]+/gi;
var cleanedStr = left_trimmedStr.replace(non_alphanumerics_rExp, " ");
var splitString = cleanedStr.split(" ");
var word_count = splitString.length -1;
document.getElementById(counter_name).value = word_count;
}
		
		tinyMCE.init({
		// General options
		language: "bg",
		mode : "exact",
		elements: "articleBody, articleResource",
		theme : "advanced",
		plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
		
		// Theme options
		theme_advanced_buttons1 : "newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,link,unlink,|,fontsizeselect",
		theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,insertdate,inserttime,preview,|,forecolor,backcolor",
		theme_advanced_buttons3 : "hr,removeformat,|,sub,sup,|,charmap,emotions,iespell",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true,

		// Example content CSS (should be your site CSS)
		content_css : "css/content.css",

		// Drop lists for link/image/media/template dialogs
		template_external_list_url : "lists/template_list.js",
		external_link_list_url : "lists/link_list.js",
		external_image_list_url : "lists/image_list.js",
		media_external_list_url : "lists/media_list.js",

		
		// Replace values for the template plugin
		template_replace_values : {
			username : "Some User",
			staffid : "991234"
		},
		
		// Replace values for the template plugin
		  setup : function (ed) {
        ed.onKeyUp.add(
            function (ed, evt) {
                //alert("Editor-ID: "+ed.id+"\nEvent: "+evt);
                countWordsA(ed.id);
            }
        );
    }

		
     
	});
