function wordcount(counts) {
var cnt;
var words = counts.replace(/\r/,"");
var words2 = words.split(/\s/);
cnt = words2.length;
var ele = document.getElementById('w_count');
ele.value = cnt;
document.wordcounter.wcount.value = cnt;
}

function math_round(Num, Places) {
   if (Places > 0) {
      if ((Num.toString().length - Num.toString().lastIndexOf('.')) > (Places + 1)) {
         var Rounder = Math.pow(10, Places);
         return Math.round(Num * Rounder) / Rounder;
      }
      else return Num;
   }
   else return Math.round(Num);
}
function setTimer(){
timvar=setInterval("lkcsearch()",1000);
//timvar=setTimeout("alert('me is fine')",1000);
}
function clearTimer(){
//clearInterval(timvar);
}
function lkcsearch(){
//if (document.wordcounter.myArticle.value==""){
//alert("Body of text is a required filed.");
//document.wordcounter.myArticle.focus();
//return (false);
//}    
                                        
//if ((document.wordcounter.kw1.value=="")&&(document.wordcounter.kw2.value=="")){
//alert("At least one keyword field must be filed before search.");
//document.wordcounter.kw1.focus();
//return (false);
//}

index=1;
pindex=0;
endwhile=0
bodyt=document.wordcounter.myArticle.value;
bodyl=bodyt.toLowerCase()
finalfs=bodyl.indexOf(".",bodyl.length-1);
if(finalfs>=0)
bodyl=bodyl.substring(0,bodyl.length-1);
while(index>=0){
index = bodyl.indexOf("<",0);
if (index >= 0)
{
pindex = bodyl.indexOf(">",index);
bodyank=bodyl.substring(index,pindex+1);
bodyl=bodyl.replace(bodyank," ");
}
}
//then, these, they, this, was, were, with.
bodyl=bodyl.replace("and"," ");
bodyl=bodyl.replace("but"," ");
bodyl=bodyl.replace("for"," ");
bodyl=bodyl.replace("from"," ");
bodyl=bodyl.replace("here"," ");
bodyl=bodyl.replace("her"," ");
bodyl=bodyl.replace("his"," ");
bodyl=bodyl.replace("how"," ");
bodyl=bodyl.replace("not"," ");
bodyl=bodyl.replace("than"," ");
bodyl=bodyl.replace("that"," ");
bodyl=bodyl.replace("the"," ");
bodyl=bodyl.replace("them"," ");
bodyl=bodyl.replace("then"," ");
bodyl=bodyl.replace("these"," ");
bodyl=bodyl.replace("they"," ");
bodyl=bodyl.replace("this"," ");
bodyl=bodyl.replace("was"," ");
bodyl=bodyl.replace("were"," ");
bodyl=bodyl.replace("with"," ");
bodyl=bodyl.replace(". "," ");
bodyl=bodyl.replace("@ "," ");
rm_ext_char="";
real_chr="";
for(i=0; i<bodyl.length; i++){
one_chr=bodyl.charCodeAt(i);

if ((one_chr>=65 && one_chr<=90) || (one_chr>=97 && one_chr<=122) || (one_chr>=48 && one_chr<=57)){
real_chr=bodyl.charAt(i);
}else{
real_chr=" ";
}
rm_ext_char=rm_ext_char+real_chr
}

bodyl=rm_ext_char.split(" ");
rm_s_d="";
full_text="";
count=0
for(i=0; i<bodyl.length; i++){
rm_s_d=bodyl[i];
if (rm_s_d.length>2){
count=count+1;
full_text=full_text+" "+rm_s_d;
}
}

//document.wordcounter.myArticle.value=full_text;
if (document.wordcounter.kw1.value!=""){
kf=document.wordcounter.kw1.value;
rm_ext_char="";
real_chr="";
for(i=0; i<kf.length; i++){
one_chr=kf.charCodeAt(i);
if ((one_chr>=65 && one_chr<=90) || (one_chr>=97 && one_chr<=122) || (one_chr>=48 && one_chr<=57)){
real_chr=kf.charAt(i);
}else{
real_chr=" ";
}
rm_ext_char=rm_ext_char+real_chr
}
kf=rm_ext_char;
kslen=kf.split(" ");
if(kslen.length>1){
kf=kf.toLowerCase()
countkf=0.1;
kftotal=0;
while(countkf>=0){
if (countkf>=0.1 && countkf<0.2)
{
countkf = full_text.indexOf(kf,0);
}
else
{
end=countkf+kf.length;
countkf = full_text.indexOf(kf,end);
}

if (countkf >= 0)
{
kftotal=kftotal+1;
}
}
if (kslen.length>count)
document.wordcounter.rt1.value=0;
else
document.wordcounter.rt1.value=math_round(kftotal/(count+1-kslen.length)*100,1);
}else{

if (document.wordcounter.kw1.value!=""){
kw1=document.wordcounter.kw1.value;
kl=kw1.toLowerCase()
ks=kw1+"s";
countkw1=0;
for(i=0; i<bodyl.length; i++){
rm_s_d=bodyl[i];
if (rm_s_d.length>1){
if (rm_s_d==kl || rm_s_d==ks){
		countkw1=countkw1+1;
	}
  }
}

document.wordcounter.rt1.value=math_round(countkw1/count*100,1);

}




}
}




if (document.wordcounter.kw2.value!=""){
kf=document.wordcounter.kw2.value;
rm_ext_char="";
real_chr="";
for(i=0; i<kf.length; i++){
one_chr=kf.charCodeAt(i);
if ((one_chr>=65 && one_chr<=90) || (one_chr>=97 && one_chr<=122) || (one_chr>=48 && one_chr<=57)){
real_chr=kf.charAt(i);
}else{
real_chr=" ";
}
rm_ext_char=rm_ext_char+real_chr
}
kf=rm_ext_char;

kslen=kf.split(" ");
if(kslen.length>1){
kf=kf.toLowerCase()
countkf=0.1;
kftotal=0;
while(countkf>=0){
if (countkf>=0.1 && countkf<0.2)
{
countkf = full_text.indexOf(kf,0);
}
else
{
end=countkf+kf.length;
countkf = full_text.indexOf(kf,end);
}

if (countkf >= 0)
{
kftotal=kftotal+1;
}
}
if (kslen.length>count)
document.wordcounter.rt2.value=0;
else
document.wordcounter.rt2.value=math_round(kftotal/(count+1-kslen.length)*100,1);
}else{
if (document.wordcounter.kw2.value!=""){
kw2=document.wordcounter.kw2.value;
kl2=kw2.toLowerCase()
kw2s=kl2+"s";
countkw2=0;
for(i=0; i<bodyl.length; i++){
rm_s_d=bodyl[i];
if (rm_s_d.length>1){
if (rm_s_d==kl2 || rm_s_d==kw2s){
		countkw2=countkw2+1;
	}
  }
}

document.wordcounter.rt2.value=math_round(countkw2/count*100,1);

}



}
}


return (false);
}
