

function numWords(string)
{
	string = string + ' ';
	string = string.replace(/^[^A-Za-z0-9]+/gi, "");
	//string = string.replace(/[^A-Za-z0-9]+/gi, " ");
	var items = string.split(" ");
	return items.length -1;
}

function countwords(wtext){


if (wtext==''){wtext=" ";}else{wtext+=" ";}
var regu=/&nbsp;|,|\.|;|:|!|\?|\(|\)|{|}|\[|\]|-|\+|=|#|$|%|"|'/g

wtext=wtext.replace(regu," ")
wtext=wtext.replace(/\s+/g," ")
//wtext=wtext.replace(/\s+$/,"")
wtext=wtext.replace(/^\s+/,"")
if (wtext==''){wordcount=0}
	else{
	wordtab=wtext.match(/\s+/g)
	wordcount=wordtab.length
	}


return wordcount
}


function removeHTML(htmltext)
{
	if (htmltext==''){return '';}
	var regEx = /&lt;[^0-9 =][^&]*&gt;|<[^0-9 =][^<>]*>/g;
	

	text= htmltext.replace(regEx, "");
	text=text.replace(/&nbsp;/g,"")
	return text

}

dispheight=100
function increase(tagid){

if (!window.document.getElementById(tagid)){return;}
var newheight=parseInt(document.getElementById(tagid).offsetHeight)+dispheight;
document.getElementById(tagid).style.height=newheight.toString()+'px';

}

function decrease(tagid){

if (!window.document.getElementById(tagid)){return;}
if ((parseInt(document.getElementById(tagid).offsetHeight)-dispheight)>40){
	var newheight=parseInt(document.getElementById(tagid).offsetHeight)-dispheight;
	document.getElementById(tagid).style.height=newheight.toString()+'px';
	}

}

function editorincrease(tagid){
alert(tagid)
alert(window.document.getElementById(tagid))
if (!window.document.getElementById(tagid)){alert('none');return;}
document.getElementById(tagid).style.height='500px'

}

function getwordnb(count){

if (count.id.search(/_editor/)==-1){holder = document.getElementById(count.id + 'WordCount');}else{
		if (!count.value){return;}
		countid=count.id.replace(/_editor/g,"")
		countid=countid.replace(/_/g,"")
		holder = document.getElementById(countid+ 'WordCount');
		
		}

if (!holder)
	return;
			
var characterlimit=65500
		var htmltext=count.value
		var wtext=removeHTML(htmltext)
		var charlimit
		if (htmltext===''){htmltextlength=0;}else{htmltextlength=htmltext.length;}
		
		if (wtext===''){wtextlength=0;}else{wtextlength=wtext.length;}
		
		if (htmltext.length>characterlimit){charlimit=" <div align='center' style='font-size:11px'><br><table><tr><td valign=top><span style='color:red'>Warning:</span></td><td valign=top>The physical character limit is <b>"+characterlimit+"</b> <br>That limit has been exceeded by <b>"+(htmltextlength-characterlimit)+"</b> characters <br>HTML code currently using <b>"+(htmltextlength-wtextlength)+"</b> characters</td></tr></table></div>" }else{charlimit=""}

		holder.innerHTML = countwords(wtext)+charlimit;

}

