function charConvert(input, type)
{
		  
	//declare variables
	var fromIndex;
	var toIndex;
	var parts;
	var regExp;
		  	
	//set from and to indexes for choosing which part of the 
	//array to use for conversion based on type parameter
		  	
  	//1: character -> html
  	//2: character -> octal
  	//3: octal -> html
  	//4: octal -> character
  	//5: html -> octal
  	//6: html -> character
  	switch (type)
  	{
  		case 1:
  			fromIndex = 2;
  			toIndex = 1;
  			break;
  			
  		case 2:
  			fromIndex = 2;
  			toIndex = 0;
  			break;
 
   		case 3:
  			fromIndex = 0;
  			toIndex = 1;
  			break;
 
   		case 4:
  			fromIndex = 0;
  			toIndex = 2;
  			break;
 
   		case 5:
  			fromIndex = 1;
  			toIndex = 0;
  			break;
  			
    	case 6:
  			fromIndex = 1;
  			toIndex = 2;
  			break;
  			
  		//if no type was specified or type doesn't exist, exit
  		default:
  			return input;	
  	}
  	
  	//build array
  	var assocArray = new Array();
  		assocArray.push("\242|&cent;|¢","\243|&pound;|£","\245|&yen;|¥",
  						"\274|&frac14;|¼","\275|&frac12;|½","\276|&frac34;|¾",
						"\241|&iexcl;|¡","\253|&laquo;|«","\273|&raquo;|»",
						"\277|&iquest;|¿","\300|&Agrave;|À","\301|&Aacute;|Á",
						"\302|&Acirc;|Â","\303|&Atilde;|Ã","\304|&Auml;|Ä",
						"\305|&Aring;|Å","\306|&AElig;|Æ","\307|&Ccedil;|Ç",
						"\310|&Egrave;|È","\311|&Eacute;|É","\312|&Ecirc;|Ê",
						"\313|&Euml;|Ë","\314|&Igrave;|Ì","\315|&Iacute;|Í",
						"\316|&Icirc;|Î","\317|&Iuml;|Ï","\320|&ETH;|Ð",
						"\321|&Ntilde;|Ñ","\322|&Ograve;|Ò","\323|&Oacute;|Ó",
						"\324|&Ocirc;|Ô","\325|&Otilde;|Õ","\326|&Ouml;|Ö",
						"\330|&Oslash;|Ø","\331|&Ugrave;|Ù","\332|&Uacute;|Ú",
						"\333|&Ucirc;|Û","\334|&Uuml;|Ü","\335|&Yacute;|Ý",
						"\336|&THORN;|Þ","\337|&szlig;|ß","\340|&agrave;|à",
						"\341|&aacute;|á","\342|&acirc;|â","\343|&atilde;|ã",
						"\344|&auml;|ä","\345|&aring;|å","\346|&aelig;|æ",
						"\347|&ccedil;|ç","\350|&egrave;|è","\351|&eacute;|é",
						"\352|&ecirc;|ê","\353|&euml;|ë","\354|&igrave;|ì",
						"\355|&iacute;|í","\356|&icirc;|î","\357|&iuml;|ï",
						"\360|&eth;|ð","\361|&ntilde;|ñ","\362|&ograve;|ò",
						"\363|&oacute;|ó","\364|&ocirc;|ô","\365|&otilde;|õ",
						"\366|&ouml;|ö","\370|&oslash;|ø","\371|&ugrave;|ù",
						"\372|&uacute;|ú","\373|&ucirc;|û","\374|&uuml;|ü",
						"\375|&yacute;|ý","\376|&thorn;|þ","\377|&yuml;|ÿ");

	
	var output = input;
	
	//loop through all elements in assocArray and replace all instances of
	//special characters (based on type)
	for (var i = 0; i < assocArray.length; i++)
	{
		//split array element
		parts = assocArray[i].toString().split("|");
		
		//build new RegExp object with global search flag
		regExp = new RegExp(parts[fromIndex],"g");
		
		output = output.replace(regExp, parts[toIndex]);
	}
  	
  	return output;
}


 function replaceAll(str, search, repl) {
  var modifier = str.length;

 while (str.indexOf(search) != -1)
    str = str.replace(search, repl);
 return str;
 } 
 
function charConvertStats(input)
{
    //declare variables
    var str= input;

 var spec = new Array("&eacute;", "&Eacute;", "&egrave;", "&Egrave;", "&ecric;", "&Ecric;", "&euml;", "&Euml;","&aelig;","&Aelig;", "&agrave;", "&Agrave;","&aacute;","&Aacute;","&Acirc;","&acirc;",
                        "&ograve;","&Ograve;","&ocirc;","&Ocirc;","&oelig;","&OElig;", "&ugrave;", "&Ugrave;", "&ccedil;", "&Ccedil;","'"," ","&rsquo;","%u2019","&lsquo;" ,"&lsaquo;","&raquo;"," ","%uFFFD","&#8216;","39","%27","%E2","%80","%99");
 var norm = new Array("e" ,"E", "e", "E", "e", "E", "e", "E","ae","Ae", "a", "A","a","A","a","A" ,"o","O","o","O","oe","Oe","u", "U", "c", "C", "_", "_","_","_","_","_","_","_","_","_","_","_","_","_","_");
 for (var i = 0; i < spec.length; i++) 
 str = replaceAll(str, spec[i], norm[i]); 
 
 var modifier = str.length;
 
 while (modifier >=0)
  {
   if(str.charAt(modifier-1)=='_')
   {
    str = str.substring(0, modifier-1)
   }
   else
   {
     break;
   }
  modifier = modifier - 1;
  }

    return (str);

}
