function roundfuntion(Num, Position) {
   if (Position > 0) {
      if ((Num.toString().length - Num.toString().lastIndexOf('.')) > (Position + 1)) {
         var Rounder = Math.pow(10, Position);
         return Math.round(Num * Rounder) / Rounder;
      }
      else return Num;
   }
   else return Math.round(Num);
}

function FindRatio(){
	if (document.RatioFrom.textsearch.value==""){
		alert("Paste a text to analize.");
		document.RatioFrom.textsearch.focus();
	}                                            
	if ((document.RatioFrom.word1.value=="")&&(document.RatioFrom.word2.value=="")&&(document.RatioFrom.word3.value=="")){
		alert("Enter a keyword.");
		document.RatioFrom.word1.focus();
	}                                            
	if ((document.RatioFrom.word1.value==" ")||(document.RatioFrom.word2.value==" ")||(document.RatioFrom.word3.value==" ")){
		alert("Enter a keyword instead a blank space.");
		document.RatioFrom.word1.focus();
	}

	counter=1;
	counter2=0;
	textsearchvar=document.RatioFrom.textsearch.value;
	textsearchLC=textsearchvar.toLowerCase()
	finalfs=textsearchLC.indexOf(".",textsearchLC.length-1);
	if(finalfs>=0)
		textsearchLC=textsearchLC.substring(0,textsearchLC.length-1);
		while(counter>=0){
			counter = textsearchLC.indexOf("<",0);
			if (counter >= 0){
				counter2 = textsearchLC.indexOf(">",counter);
				textsubstring=textsearchLC.substring(counter,counter2+1);
				textsearchLC=textsearchLC.replace(textsubstring," ");
			}
		}
		
		textsearchLC=textsearchLC.replace("and"," ");
		textsearchLC=textsearchLC.replace("but"," ");
		textsearchLC=textsearchLC.replace("for"," ");
		textsearchLC=textsearchLC.replace("from"," ");
		textsearchLC=textsearchLC.replace("here"," ");
		textsearchLC=textsearchLC.replace("her"," ");
		textsearchLC=textsearchLC.replace("his"," ");
		textsearchLC=textsearchLC.replace("how"," ");
		textsearchLC=textsearchLC.replace("not"," ");
		textsearchLC=textsearchLC.replace("than"," ");
		textsearchLC=textsearchLC.replace("that"," ");
		textsearchLC=textsearchLC.replace("the"," ");
		textsearchLC=textsearchLC.replace("them"," ");
		textsearchLC=textsearchLC.replace("then"," ");
		textsearchLC=textsearchLC.replace("these"," ");
		textsearchLC=textsearchLC.replace("they"," ");
		textsearchLC=textsearchLC.replace("this"," ");
		textsearchLC=textsearchLC.replace("was"," ");
		textsearchLC=textsearchLC.replace("were"," ");
		textsearchLC=textsearchLC.replace("with"," ");
		textsearchLC=textsearchLC.replace(". "," ");
		textsearchLC=textsearchLC.replace("@ "," ");
		UnicodetranslateSum="";
		Unicodetranslate="";
		for(i=0; i<textsearchLC.length; i++){
			Unicode=textsearchLC.charCodeAt(i);
		
			if ((Unicode>=65 && Unicode<=90) || (Unicode>=97 && Unicode<=122) || (Unicode>=48 && Unicode<=57)){
				Unicodetranslate=textsearchLC.charAt(i);
			}else{
				Unicodetranslate=" ";
			}
			UnicodetranslateSum=UnicodetranslateSum+Unicodetranslate
		}

		textsearchLC=UnicodetranslateSum.split(" ");
		eachword="";
		full_text="";
		count=0
		for(i=0; i<textsearchLC.length; i++){
			eachword=textsearchLC[i];
			if (eachword.length>2){
				count=count+1;
				full_text=full_text+" "+eachword;
			}
		}
//////////////////////////////word 1
		if (document.RatioFrom.word1.value!=""){
			wordvalue=document.RatioFrom.word1.value;
			UnicodetranslateSum="";
			Unicodetranslate="";
			for(i=0; i<wordvalue.length; i++){
				Unicode=wordvalue.charCodeAt(i);
				if ((Unicode>=65 && Unicode<=90) || (Unicode>=97 && Unicode<=122) || (Unicode>=48 && Unicode<=57)){
					Unicodetranslate=wordvalue.charAt(i);
				}else{
					Unicodetranslate=" ";
				}
				UnicodetranslateSum=UnicodetranslateSum+Unicodetranslate
			}
			wordvalue=UnicodetranslateSum;
			wordvaluesplit=wordvalue.split(" ");
			if(wordvaluesplit.length>1){
				wordvalue=wordvalue.toLowerCase()
				countwordvalue=0.1;
				wordvaluetotal=0;
				while(countwordvalue>=0){
					if (countwordvalue>=0.1 && countwordvalue<0.2){
						countwordvalue = full_text.indexOf(wordvalue,0);
					}else{
						end=countwordvalue+wordvalue.length;
						countwordvalue = full_text.indexOf(wordvalue,end);
					}
					if (countwordvalue >= 0){
						wordvaluetotal=wordvaluetotal+1;
					}
				}
				if (wordvaluesplit.length>count){
					document.RatioFrom.ratio1.value=0;
				}else{
					document.RatioFrom.ratio1.value=roundfuntion(wordvaluetotal/(count+1-wordvaluesplit.length)*100,1);
				}
			}else{
				if (document.RatioFrom.word1.value!=""){
					word1=document.RatioFrom.word1.value;
					word1LC=word1.toLowerCase()
					word1LCs=word1+"s";
					countword1=0;
					for(i=0; i<textsearchLC.length; i++){
						eachword=textsearchLC[i];
						if (eachword.length>1){
							if (eachword==word1LC || eachword==word1LCs){
								countword1=countword1+1;
							}
						}
					}
					document.RatioFrom.ratio1.value=roundfuntion(countword1/count*100,1);
				}
			}
		}
////////////////////////////word 2
		if (document.RatioFrom.word2.value!=""){
			wordvalue=document.RatioFrom.word2.value;
			UnicodetranslateSum="";
			Unicodetranslate="";
			for(i=0; i<wordvalue.length; i++){
				Unicode=wordvalue.charCodeAt(i);
				if ((Unicode>=65 && Unicode<=90) || (Unicode>=97 && Unicode<=122) || (Unicode>=48 && Unicode<=57)){
					Unicodetranslate=wordvalue.charAt(i);
				}else{
					Unicodetranslate=" ";
				}
				UnicodetranslateSum=UnicodetranslateSum+Unicodetranslate
			}
			wordvalue=UnicodetranslateSum;
			
			wordvaluesplit=wordvalue.split(" ");
			if(wordvaluesplit.length>1){
				wordvalue=wordvalue.toLowerCase()
				countwordvalue=0.1;
				wordvaluetotal=0;
				while(countwordvalue>=0){
					if (countwordvalue>=0.1 && countwordvalue<0.2){
						countwordvalue = full_text.indexOf(wordvalue,0);
					}else{
						end=countwordvalue+wordvalue.length;
						countwordvalue = full_text.indexOf(wordvalue,end);
					}
				
					if (countwordvalue >= 0){
						wordvaluetotal=wordvaluetotal+1;
					}
				}
				if (wordvaluesplit.length>count){
					document.RatioFrom.ratio2.value=0;
				}else{
					document.RatioFrom.ratio2.value=roundfuntion(wordvaluetotal/(count+1-wordvaluesplit.length)*100,1);
				}
			}else{
				if (document.RatioFrom.word2.value!=""){
					word2=document.RatioFrom.word2.value;
					wordl2=word2.toLowerCase()
					word2s=wordl2+"s";
					countword2=0;
					for(i=0; i<textsearchLC.length; i++){
						eachword=textsearchLC[i];
						if (eachword.length>1){
							if (eachword==wordl2 || eachword==word2s){
								countword2=countword2+1;
							}
						}
					}
					document.RatioFrom.ratio2.value=roundfuntion(countword2/count*100,1);
				}
			}
		}
///////////////////////////// word 3
	if (document.RatioFrom.word3.value!=""){
		wordvalue=document.RatioFrom.word3.value;
		UnicodetranslateSum="";
		Unicodetranslate="";
		for(i=0; i<wordvalue.length; i++){
			Unicode=wordvalue.charCodeAt(i);
			if ((Unicode>=65 && Unicode<=90) || (Unicode>=97 && Unicode<=122) || (Unicode>=48 && Unicode<=57)){
				Unicodetranslate=wordvalue.charAt(i);
			}else{
				Unicodetranslate=" ";
			}
			UnicodetranslateSum=UnicodetranslateSum+Unicodetranslate
		}
		wordvalue=UnicodetranslateSum;
		wordvaluesplit=wordvalue.split(" ");
		if(wordvaluesplit.length>1){
			wordvalue=wordvalue.toLowerCase()
			countwordvalue=0.1;
			wordvaluetotal=0;
			while(countwordvalue>=0){
				if (countwordvalue>=0.1 && countwordvalue<0.2){
					countwordvalue = full_text.indexOf(wordvalue,0);
				}else{
					end=countwordvalue+wordvalue.length;
					countwordvalue = full_text.indexOf(wordvalue,end);
				}
				if (countwordvalue >= 0){
					wordvaluetotal=wordvaluetotal+1;
				}
			}
			if (wordvaluesplit.length>count){
				document.RatioFrom.ratio3.value=0;
			}else{
				document.RatioFrom.ratio3.value=roundfuntion(wordvaluetotal/(count+1-wordvaluesplit.length)*100,1);
			}
		}else{
			if (document.RatioFrom.word3.value!=""){
				word3=document.RatioFrom.word3.value;
				wordl3=word3.toLowerCase()
				word3s=wordl3+"s";
				countword3=0;
				for(i=0; i<textsearchLC.length; i++){
					eachword=textsearchLC[i];
					if (eachword.length>1){
						if (eachword==wordl3 || eachword==word3s){
							countword3=countword3+1;
						}
					}
				}
				document.RatioFrom.ratio3.value=roundfuntion(countword3/count*100,1);
			}
		}
	}
/////////////////////////////////word 4
if (document.RatioFrom.word4.value!=""){
		wordvalue=document.RatioFrom.word4.value;
		UnicodetranslateSum="";
		Unicodetranslate="";
		for(i=0; i<wordvalue.length; i++){
			Unicode=wordvalue.charCodeAt(i);
			if ((Unicode>=65 && Unicode<=90) || (Unicode>=97 && Unicode<=122) || (Unicode>=48 && Unicode<=57)){
				Unicodetranslate=wordvalue.charAt(i);
			}else{
				Unicodetranslate=" ";
			}
			UnicodetranslateSum=UnicodetranslateSum+Unicodetranslate
		}
		wordvalue=UnicodetranslateSum;
		wordvaluesplit=wordvalue.split(" ");
		if(wordvaluesplit.length>1){
			wordvalue=wordvalue.toLowerCase()
			countwordvalue=0.1;
			wordvaluetotal=0;
			while(countwordvalue>=0){
				if (countwordvalue>=0.1 && countwordvalue<0.2){
					countwordvalue = full_text.indexOf(wordvalue,0);
				}else{
					end=countwordvalue+wordvalue.length;
					countwordvalue = full_text.indexOf(wordvalue,end);
				}
				if (countwordvalue >= 0){
					wordvaluetotal=wordvaluetotal+1;
				}
			}
			if (wordvaluesplit.length>count){
				document.RatioFrom.ratio4.value=0;
			}else{
				document.RatioFrom.ratio4.value=roundfuntion(wordvaluetotal/(count+1-wordvaluesplit.length)*100,1);
			}
		}else{
			if (document.RatioFrom.word4.value!=""){
				word4=document.RatioFrom.word4.value;
				wordl4=word4.toLowerCase()
				word4s=wordl4+"s";
				countword4=0;
				for(i=0; i<textsearchLC.length; i++){
					eachword=textsearchLC[i];
					if (eachword.length>1){
						if (eachword==wordl4 || eachword==word4s){
							countword4=countword4+1;
						}
					}
				}
				document.RatioFrom.ratio4.value=roundfuntion(countword4/count*100,1);
			}
		}
	}
	
		return (false);
}


function roundfuntion(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("FindRatio1()",1000);
	ccc=setInterval("changecontent()",1000)
}


function clearTimer(){
}


function FindRatio1(){
	if (document.RatioFrom.textsearch.value==""){
	}                                            
	if ((document.RatioFrom.word1.value=="")&&(document.RatioFrom.word2.value=="")&&(document.RatioFrom.word3.value=="")&&(document.RatioFrom.word4.value=="")){
		//alert("Enter a keyword.");
		//document.RatioFrom.word1.focus();
		
	} 

	counter=1;
	counter2=0;
	textsearchvar=document.RatioFrom.textsearch.value;
	textsearchLC=textsearchvar.toLowerCase()
	finalfs=textsearchLC.indexOf(".",textsearchLC.length-1);
	if(finalfs>=0)
		textsearchLC=textsearchLC.substring(0,textsearchLC.length-1);
		while(counter>=0){
			counter = textsearchLC.indexOf("<",0);
			if (counter >= 0){
				counter2 = textsearchLC.indexOf(">",counter);
				textsubstring=textsearchLC.substring(counter,counter2+1);
				textsearchLC=textsearchLC.replace(textsubstring," ");
			}
		}
		textsearchLC=textsearchLC.replace("and"," ");
		textsearchLC=textsearchLC.replace("but"," ");
		textsearchLC=textsearchLC.replace("for"," ");
		textsearchLC=textsearchLC.replace("from"," ");
		textsearchLC=textsearchLC.replace("here"," ");
		textsearchLC=textsearchLC.replace("her"," ");
		textsearchLC=textsearchLC.replace("his"," ");
		textsearchLC=textsearchLC.replace("how"," ");
		textsearchLC=textsearchLC.replace("not"," ");
		textsearchLC=textsearchLC.replace("than"," ");
		textsearchLC=textsearchLC.replace("that"," ");
		textsearchLC=textsearchLC.replace("the"," ");
		textsearchLC=textsearchLC.replace("them"," ");
		textsearchLC=textsearchLC.replace("then"," ");
		textsearchLC=textsearchLC.replace("these"," ");
		textsearchLC=textsearchLC.replace("they"," ");
		textsearchLC=textsearchLC.replace("this"," ");
		textsearchLC=textsearchLC.replace("was"," ");
		textsearchLC=textsearchLC.replace("were"," ");
		textsearchLC=textsearchLC.replace("with"," ");
		textsearchLC=textsearchLC.replace(". "," ");
		textsearchLC=textsearchLC.replace("@ "," ");
		UnicodetranslateSum="";
		Unicodetranslate="";
		for(i=0; i<textsearchLC.length; i++){
			Unicode=textsearchLC.charCodeAt(i);
			if ((Unicode>=65 && Unicode<=90) || (Unicode>=97 && Unicode<=122) || (Unicode>=48 && Unicode<=57)){
				Unicodetranslate=textsearchLC.charAt(i);
			}else{
				Unicodetranslate=" ";
			}
			UnicodetranslateSum=UnicodetranslateSum+Unicodetranslate
		}
	
		textsearchLC=UnicodetranslateSum.split(" ");
		eachword="";
		full_text="";
		count=0
		for(i=0; i<textsearchLC.length; i++){
			eachword=textsearchLC[i];
			if (eachword.length>2){
				count=count+1;
				full_text=full_text+" "+eachword;
			}
		}
/////////////////////////////// word 1	
		if (document.RatioFrom.word1.value!=""){
			wordvalue=document.RatioFrom.word1.value;
			UnicodetranslateSum="";
			Unicodetranslate="";
			for(i=0; i<wordvalue.length; i++){
				Unicode=wordvalue.charCodeAt(i);
				if ((Unicode>=65 && Unicode<=90) || (Unicode>=97 && Unicode<=122) || (Unicode>=48 && Unicode<=57)){
					Unicodetranslate=wordvalue.charAt(i);
				}else{
					Unicodetranslate=" ";
				}
				UnicodetranslateSum=UnicodetranslateSum+Unicodetranslate
			}
			wordvalue=UnicodetranslateSum;
			wordvaluesplit=wordvalue.split(" ");
			if(wordvaluesplit.length>1){
				wordvalue=wordvalue.toLowerCase()
				countwordvalue=0.1;
				wordvaluetotal=0;
				while(countwordvalue>=0){
					if (countwordvalue>=0.1 && countwordvalue<0.2){
						countwordvalue = full_text.indexOf(wordvalue,0);
					}else{
						end=countwordvalue+wordvalue.length;
						countwordvalue = full_text.indexOf(wordvalue,end);
					}
					if (countwordvalue >= 0){
						wordvaluetotal=wordvaluetotal+1;
					}
				}
				if (wordvaluesplit.length>count){
					document.RatioFrom.ratio1.value=0;
				}else{
					document.RatioFrom.ratio1.value=roundfuntion(wordvaluetotal/(count+1-wordvaluesplit.length)*100,1);
				}
			}else{
		
				if (document.RatioFrom.word1.value!=""){
					word1=document.RatioFrom.word1.value;
					wordl=word1.toLowerCase()
					words=word1+"s";
					countword1=0;
					for(i=0; i<textsearchLC.length; i++){
						eachword=textsearchLC[i];
						if (eachword.length>1){
							if (eachword==wordl || eachword==words){
								countword1=countword1+1;
							}
						}
					}
					document.RatioFrom.ratio1.value=roundfuntion(countword1/count*100,1);
				}
			}
		}else{
			document.RatioFrom.ratio1.value = "--";
		}

/////////////////////////////// word 2	



	if (document.RatioFrom.word2.value!=""){
		wordvalue=document.RatioFrom.word2.value;
		UnicodetranslateSum="";
		Unicodetranslate="";
		for(i=0; i<wordvalue.length; i++){
			Unicode=wordvalue.charCodeAt(i);
			if ((Unicode>=65 && Unicode<=90) || (Unicode>=97 && Unicode<=122) || (Unicode>=48 && Unicode<=57)){
				Unicodetranslate=wordvalue.charAt(i);
			}else{
				Unicodetranslate=" ";
			}
			UnicodetranslateSum=UnicodetranslateSum+Unicodetranslate
		}
		wordvalue=UnicodetranslateSum;
		
		wordvaluesplit=wordvalue.split(" ");
		if(wordvaluesplit.length>1){
			wordvalue=wordvalue.toLowerCase()
			countwordvalue=0.1;
			wordvaluetotal=0;
			while(countwordvalue>=0){
				if (countwordvalue>=0.1 && countwordvalue<0.2){
					countwordvalue = full_text.indexOf(wordvalue,0);
				}else{
					end=countwordvalue+wordvalue.length;
					countwordvalue = full_text.indexOf(wordvalue,end);
				}
			
				if (countwordvalue >= 0){
					wordvaluetotal=wordvaluetotal+1;
				}
			}
			if (wordvaluesplit.length>count){
				document.RatioFrom.ratio2.value=0;
			}else{
				document.RatioFrom.ratio2.value=roundfuntion(wordvaluetotal/(count+1-wordvaluesplit.length)*100,1);
			}
		}else{
			if (document.RatioFrom.word2.value!=""){
				word2=document.RatioFrom.word2.value;
				wordl2=word2.toLowerCase()
				word2s=wordl2+"s";
				countword2=0;
				for(i=0; i<textsearchLC.length; i++){
					eachword=textsearchLC[i];
					if (eachword.length>1){
						if (eachword==wordl2 || eachword==word2s){
							countword2=countword2+1;
						}
					}
				}
				document.RatioFrom.ratio2.value=roundfuntion(countword2/count*100,1);
			}
		}
	}else{
			document.RatioFrom.ratio2.value = "--";
		}

/////////////////////////////// word 3
	if (document.RatioFrom.word3.value!=""){
		wordvalue=document.RatioFrom.word3.value;
		UnicodetranslateSum="";
		Unicodetranslate="";
		for(i=0; i<wordvalue.length; i++){
			Unicode=wordvalue.charCodeAt(i);
			if ((Unicode>=65 && Unicode<=90) || (Unicode>=97 && Unicode<=122) || (Unicode>=48 && Unicode<=57)){
				Unicodetranslate=wordvalue.charAt(i);
			}else{
				Unicodetranslate=" ";
			}
			UnicodetranslateSum=UnicodetranslateSum+Unicodetranslate
		}
		wordvalue=UnicodetranslateSum;
		
		wordvaluesplit=wordvalue.split(" ");
		if(wordvaluesplit.length>1){
			wordvalue=wordvalue.toLowerCase()
			countwordvalue=0.1;
			wordvaluetotal=0;
			while(countwordvalue>=0){
				if (countwordvalue>=0.1 && countwordvalue<0.2){
					countwordvalue = full_text.indexOf(wordvalue,0);
				}else{
					end=countwordvalue+wordvalue.length;
					countwordvalue = full_text.indexOf(wordvalue,end);
				}
			
				if (countwordvalue >= 0){
					wordvaluetotal=wordvaluetotal+1;
				}
			}
			if (wordvaluesplit.length>count){
				document.RatioFrom.ratio3.value=0;
			}else{
				document.RatioFrom.ratio3.value=roundfuntion(wordvaluetotal/(count+1-wordvaluesplit.length)*100,1);
			}
		}else{
		
			if (document.RatioFrom.word3.value!=""){
				word3=document.RatioFrom.word3.value;
				wordl3=word3.toLowerCase()
				word3s=wordl3+"s";
				countword3=0;
				for(i=0; i<textsearchLC.length; i++){
					eachword=textsearchLC[i];
					if (eachword.length>1){
						if (eachword==wordl3 || eachword==word3s){
							countword3=countword3+1;
						}
					}
				}
				document.RatioFrom.ratio3.value=roundfuntion(countword3/count*100,1);
			}
		}
	
	
	}else{
			document.RatioFrom.ratio3.value = "--";
		}
		
/////////////////////////////// word 4
		
		if (document.RatioFrom.word4.value!=""){
			wordvalue=document.RatioFrom.word4.value;
			UnicodetranslateSum="";
			Unicodetranslate="";
			for(i=0; i<wordvalue.length; i++){
				Unicode=wordvalue.charCodeAt(i);
				if ((Unicode>=65 && Unicode<=90) || (Unicode>=97 && Unicode<=122) || (Unicode>=48 && Unicode<=57)){
					Unicodetranslate=wordvalue.charAt(i);
				}else{
					Unicodetranslate=" ";
				}
				UnicodetranslateSum=UnicodetranslateSum+Unicodetranslate
			}
			wordvalue=UnicodetranslateSum;
			wordvaluesplit=wordvalue.split(" ");
			if(wordvaluesplit.length>1){
				wordvalue=wordvalue.toLowerCase()
				countwordvalue=0.1;
				wordvaluetotal=0;
				while(countwordvalue>=0){
					if (countwordvalue>=0.1 && countwordvalue<0.2){
						countwordvalue = full_text.indexOf(wordvalue,0);
					}else{
						end=countwordvalue+wordvalue.length;
						countwordvalue = full_text.indexOf(wordvalue,end);
					}
					if (countwordvalue >= 0){
						wordvaluetotal=wordvaluetotal+1;
					}
				}
				if (wordvaluesplit.length>count){
					document.RatioFrom.ratio4.value=0;
				}else{
					document.RatioFrom.ratio4.value=roundfuntion(wordvaluetotal/(count+1-wordvaluesplit.length)*100,1);
				}
			}else{
		
				if (document.RatioFrom.word4.value!=""){
					word4=document.RatioFrom.word4.value;
					word4=word4.toLowerCase()
					word4s=word4+"s";
					countword4=0;
					for(i=0; i<textsearchLC.length; i++){
						eachword=textsearchLC[i];
						if (eachword.length>1){
							if (eachword==word4 || eachword==word4s){
								countword4=countword4+1;
							}
						}
					}
					document.RatioFrom.ratio4.value=roundfuntion(countword4/count*100,1);
				}
		
			}
		}else{
			document.RatioFrom.ratio4.value = "--";
		}
	
}

