// -*- mode: java; -*-

// Indian Language Converter - transliterates from Roman scripts to
// Indic scripts.

// Copyright (C) 2005, 2006 Vijay Lakshminarayanan <liyer.vijay@gmail.com>

// Indian Language Converter is free software; you can redistribute it
// and/or modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2 of
// the License, or (at your option) any later version.

// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
// 02110-1301, USA.

// 	$Id: converter.js,v 1.1.1.1 2006-05-26 11:49:07 vijay Exp $	
// 	Author: Vijay Lakshminarayanan	
// 	$Date: 2006-05-26 11:49:07 $	

var brhEngine = function()
{
	this.vowels = "(A)|(E)|(H)|(I)|(M)|(O)|(U)|(a((a)|(e)|(i)|(u))?)|(e(e)?)|(i)|(o((a)|(o)|(u))?)|(u)";
	
	this.consonants = "((Q)|(kSh)|(k(h)?)|(g(h)?)|(G)|(c(h)?)|(C(h)?)|(j)|(J)|(jh)|(T(h)?)|(((K)|(G)|(J)|(T(h)?)|(D(h)?)|(N)|(t(h)?)|(d(h)?)|(n)|(p(h)?)|(P)|(f)|(b(h)?)|(B)|(m)|(v)|(w)|(y)|(Y)|(r)|(R)|(l)|(L)|(sh)|(Sh)|(s)|(S)|(h))(a((a)|(i)|(u))?)?)|(a)|(e(e)?)|(E)|(R((u)|(U))?)|(o(o)?)|(O)|(k))";
	this.consonants = this.consonants + "((a((a)|(u)|(i))?)|(A)|(e(e)?)|(E)|(i)|(I)|(R((u)|(U))?)|(u)|(U)|(o(o)?)|(O))?";
	
	this.letter_codes = {
	"~a" : "&#67;",
	"~aa" : "&#68;",
	"~A" : "&#68;",
	"~i" : "&#69;",
	"~ee" : "&#70;",
	"~I" : "&#70;",
	"~u" : "&#71;",
	"~oo" : "&#72;",
	"~U" : "&#72;",
	"~e" : "&#74;",
	"~Ru" : "&#73;&#196;",
	"~RU" : "&#73;&#198;",
	"~ae" : "&#75;",
	"~E" : "&#75;",
	"~ai" : "&#76;",
	"~o" : "&#77;",
	"~oa" : "&#78;",
	"~O" : "&#78;",
	"~au" : "&#79;",
	"~ou" : "&#79;",
	"~tR" : "vïæ",
	"~TR" : "mïæ",
	"~j" : "&#203;",
	
	"a" : "&#67;",
	"aa" : "&#68;",
	"A" : "&#68;",
	"i" : "&#69;",
	"ee" : "&#70;",
	"I" : "&#70;",
	"u" : "&#71;",
	"oo" : "&#72;",
	"U" : "&#72;",
	"e" : "&#74;",
	"Ru" : "&#73;&#196;",
	"RU" : "&#73;&#198;",
	"ae" : "&#75;",
	"E" : "&#75;",
	"ai" : "&#76;",
	"o" : "&#77;",
	"oa" : "&#78;",
	"O" : "&#78;",
	"au" : "&#79;",
	"ou" : "&#79;",
	
	"M" : "&#65;",
	"H" : "&#66;",
	"~M" : "&#65;",
	"~H" : "&#66;",
	"*" : "",
	
	
	"^n" : "&#223;",
	
	
	//ka
	"k" : "&#80;&#239;",
	"ka" : "&#80;&#192;",
	"kaa" : "&#80;&#193;",
	"kA" : "&#80;&#193;",
	"ki" : "&#81;",
	"kI" : "&#81;&#195;",
	"kee" : "&#81;&#195;",
	"ku" : "&#80;&#192;&#196;", 
	"kU" : "&#80;&#192;&#198;", 
	"koo" : "&#80;&#192;&#198;", 
	"ke" : "&#80;&#201;", 
	"kE" : "&#80;&#201;&#195;", 
	"kRu" : "&#80;&#192;&#200;", 
	"kRU" : "&#80;&#192;&#241;", 
	"kai" : "&#80;&#201;&#202;",
	"ko" : "&#80;&#201;&#198;", 
	"kO" : "&#80;&#201;&#198;&#195;", 
	"kau" : "&#80;&#203;",
	
	//Ka
	"K" : "&#83;&#239;",
	"kh" : "&#83;&#239;",
	"Ka" : "&#82;",
	"KA" : "&#83;&#193;",
	"Kaa" : "&#83;&#193;",
	"Ki" : "&#84;", 
	"KI" : "&#84;&#195;", 
	"Ku" : "&#82;&#196;", 
	"KU" : "&#82;&#198;", 
	"Koo" : "&#82;&#198;", 
	"Ke" : "&#83;&#201;", 
	"KE" : "&#83;&#201;&#195;", 
	"Ko" : "&#83;&#201;&#198;", 
	"KO" : "&#83;&#201;&#198;&#195;", 
	"KRu" : "&#82;&#200;", 
	"KRU" : "&#82;&#241;", 
	"Kai" : "&#83;&#201;&#202;",
	"Kau" : "&#83;&#203;",
	
	// kh
	"kh" : "&#83;&#239;",
	"kha" : "&#82;",
	"khA" : "&#83;&#193;",
	"khaa" : "&#83;&#193;",
	"khi" : "&#84;", 
	"khI" : "&#84;&#195;", 
	"khu" : "&#82;&#196;", 
	"khU" : "&#82;&#198;", 
	"khoo" : "&#82;&#198;", 
	"khe" : "&#83;&#201;", 
	"khE" : "&#83;&#201;&#195;", 
	"kho" : "&#83;&#201;&#198;", 
	"khO" : "&#83;&#201;&#198;&#195;", 
	"khRu" : "&#82;&#200;", 
	"khRU" : "&#82;&#241;", 
	"khai" : "&#83;&#201;&#202;",
	"khau" : "&#83;&#203;",
	
	
	//ga
	"g" : "&#85;&#239;",
	"ga" : "&#85;&#192;", 
	"gA" : "&#85;&#193;",
	"gi" : "&#86;",
	"gI" : "&#86;&#195;",
	"gee" : "&#86;&#195;",
	"gu" : "&#85;&#192;&#196;", 
	"gU" : "&#85;&#192;&#198;", 
	"goo" : "&#85;&#192;&#198;", 
	"ge" : "&#85;&#201;", 
	"gE" : "&#85;&#201;&#195;", 
	"go" : "&#85;&#201;&#198;", 
	"gO" : "&#85;&#201;&#198;&#195;", 
	"gRu" : "&#85;&#192;&#200;", 
	"gRU" : "&#85;&#192;&#241;", 
	"gai" : "&#85;&#201;&#202;", 
	"gau" : "&#85;&#203;", 
	
	//Ga
	"G" : "&#87;&#239;",
	"gh" : "&#87;&#239;",
	"Ga" : "&#87;&#192;",
	"GA" : "&#87;&#193;",
	"Gi" : "&#88;",
	"GI" : "&#88;&#195;",
	"Gee" : "&#88;&#195;",
	"Gu" : "&#87;&#192;&#196;", 
	"GU" : "&#87;&#192;&#198;", 
	"Goo" : "&#87;&#192;&#198;", 
	"Ge" : "&#87;&#201;", 
	"GE" : "&#87;&#201;&#195;", 
	"Go" : "&#87;&#201;&#198;", 
	"GO" : "&#87;&#201;&#198;&#195;", 
	"GRu" : "&#87;&#192;&#200;", 
	"GRU" : "&#87;&#192;&#241;", 
	"Gai" : "&#87;&#201;&#202;", 
	"Gau" : "&#87;&#203;", 
	
	//gha
	"gh" : "&#87;&#239;",
	"ghh" : "&#87;&#239;",
	"gha" : "&#87;&#192;",
	"ghA" : "&#87;&#193;",
	"ghi" : "&#88;",
	"ghI" : "&#88;&#195;",
	"ghee" : "&#88;&#195;",
	"ghu" : "&#87;&#192;&#196;", 
	"ghU" : "&#87;&#192;&#198;", 
	"ghoo" : "&#87;&#192;&#198;", 
	"ghe" : "&#87;&#201;", 
	"ghE" : "&#87;&#201;&#195;", 
	"gho" : "&#87;&#201;&#198;", 
	"ghO" : "&#87;&#201;&#198;&#195;", 
	"ghRu" : "&#87;&#192;&#200;", 
	"ghRU" : "&#87;&#192;&#241;", 
	"ghai" : "&#87;&#201;&#202;", 
	"ghau" : "&#87;&#203;", 
	
	
	//c
	"c" : "&#90;&#239;",
	"ca" : "&#90;&#192;",
	"cA" : "&#90;&#193;",
	"ci" : "&#97;",
	"cI" : "&#97;&#195;",
	"cee" : "&#97;&#195;",
	"cu" : "&#90;&#192;&#196;", 
	"cU" : "&#90;&#192;&#198;", 
	"coo" : "&#90;&#192;&#198;", 
	"ce" : "&#90;&#201;", 
	"cE" : "&#90;&#201;&#195;", 
	"co" : "&#90;&#201;&#198;", 
	"cO" : "&#90;&#201;&#198;&#195;", 
	"cRu" : "&#90;&#192;&#200;", 
	"cRU" : "&#90;&#192;&#241;", 
	"cai" : "&#90;&#201;&#202;", 
	"cau" : "&#90;&#203;", 
	
	//ch
	"ch" : "&#90;&#239;",
	"cha" : "&#90;&#192;",
	"chA" : "&#90;&#193;",
	"chi" : "&#97;",
	"chI" : "&#97;&#195;",
	"chee" : "&#97;&#195;",
	"chu" : "&#90;&#192;&#196;", 
	"chU" : "&#90;&#192;&#198;", 
	"choo" : "&#90;&#192;&#198;", 
	"che" : "&#90;&#201;", 
	"chE" : "&#90;&#201;&#195;", 
	"cho" : "&#90;&#201;&#198;", 
	"chO" : "&#90;&#201;&#198;&#195;", 
	"chRu" : "&#90;&#192;&#200;", 
	"chRU" : "&#90;&#192;&#241;", 
	"chai" : "&#90;&#201;&#202;", 
	"chau" : "&#90;&#203;", 
	
	
	//Ch
	"C" : "&#98;&#239;",
	"Ch" : "&#98;&#239;",
	"Cha" : "&#98;&#192;",
	"Chaa" : "&#98;&#193;",
	"ChA" : "&#98;&#193;",
	"Chi" : "&#99;",
	"ChI" : "&#99;&#195;",
	"Chee" : "&#99;&#195;",
	"Chu" : "&#98;&#192;&#196;", 
	"ChU" : "&#98;&#192;&#198;", 
	"Choo" : "&#98;&#192;&#198;", 
	"Che" : "&#98;&#201;", 
	"ChE" : "&#98;&#201;&#195;", 
	"Cho" : "&#98;&#201;&#198;", 
	"ChO" : "&#98;&#201;&#198;&#195;", 
	"ChRu" : "&#98;&#192;&#200;", 
	"ChRU" : "&#98;&#192;&#241;", 
	"Chai" : "&#98;&#201;&#202;", 
	"Chau" : "&#98;&#203;", 
	
	
	//j
	"j" : "&#101;&#239;",
	"ja" : "&#100;",
	"jA" : "&#101;&#193;",
	"ji" : "&#102;",
	"jI" : "&#102;&#195;",
	"jee" : "&#102;&#195;",
	"ju" : "&#100;&#196;", 
	"jU" : "&#100;&#198;", 
	"joo" : "&#100;&#198;", 
	"je" : "&#101;&#201;", 
	"jE" : "&#101;&#201;&#195;", 
	"jo" : "&#101;&#201;&#198;", 
	"jO" : "&#101;&#201;&#198;&#195;", 
	"jRu" : "&#100;&#200;", 
	"jRU" : "&#100;&#241;", 
	"jau" : "&#101;&#203;",
	"jai" : "&#101;&#201;&#202;", 
	"jau" : "&#101;&#203;", 
	
	
	//Ja
	"J" : "&#103;&#192;&#104;&#105;",
	"Jh" : "&#103;&#192;&#104;&#105;",
	"Ja" : "&#103;&#192;&#104;&#196;",
	"JA" : "&#103;&#192;&#104;&#105;&#193;",
	"Ji" : "&#106;&#104;&#196;",
	"JI" : "&#106;&#104;&#196;&#195;",
	"Jee" : "&#106;&#104;&#196;&#195;",
	"Ju" : "&#103;&#192;&#104;&#196;&#196;",
	"JU" : "&#103;&#192;&#104;&#196;&#198;",
	"Joo" : "&#103;&#192;&#104;&#196;&#198;",
	"Je" : "&#103;&#201&#104;&#196;",
	"JE" : "&#103;&#201&#104;&#196;&#195;",
	"Jo" : "&#103;&#201;&#104;&#198;", 
	"JO" : "&#103;&#201;&#104;&#198;&#195;", 
	"JRu" : "&#103;&#192;&#104;&#196;&#200;", 
	"JRU" : "&#103;&#192;&#104;&#196;&#241;", 
	"Jai" : "&#103;&#201;&#104;&#196;&#202;", 
	"Jau" : "&#103;&#192;&#104;&#105;&#203;", 
	
	//T
	"T" : "&#109;&#239;",
	"Ta" : "&#108;",
	"Taa" : "&#109;&#193;",
	"TA" : "&#109;&#193;",
	"Ti" : "&#110;",
	"TI" : "&#110;&#195;",
	"Tee" : "&#110;&#195;",
	"Tu" : "&#108;&#196;", 
	"TU" : "&#108;&#198;", 
	"TRu" : "&#108;&#200;", 
	"TRU" : "&#108;&#241;", 
	"Te" : "&#109;&#201;", 
	"TE" : "&#109;&#201;&#195;", 
	"To" : "&#109;&#201;&#198;", 
	"TO" : "&#109;&#201;&#198;&#195;", 
	"Tai" : "&#109;&#201;&#202;",
	"Tau" : "&#109;&#203;",
	"Tr" : "&#109;&#253;",
	
	//Th
	"Th" : "&#111;&#239;",
	"Tha" : "&#111;&#192;",
	"Thaa" : "&#111;&#193;",
	"ThA" : "&#111;&#193;",
	"Thi" : "&#112;",
	"ThI" : "&#112;&#195;",
	"Thee" : "&#112;&#195;",
	"Thu" : "&#111;&#192;&#196;", 
	"ThU" : "&#111;&#192;&#198;", 
	"ThRu" : "&#111;&#192;&#200;", 
	"ThRU" : "&#111;&#192;&#241;", 
	"The" : "&#111;&#201;", 
	"ThE" : "&#111;&#201;&#195;", 
	"Tho" : "&#111;&#201;&#198;", 
	"ThO" : "&#111;&#201;&#198;&#195;", 
	"Thai" : "&#111;&#201;&#202;",
	"Thau" : "&#111;&#203;",
	"Thr" : "&#111;&#253;",
	
	
	//D
	"D" : "&#113;&#239;",
	"Da" : "&#113;&#192;",
	"Daa" : "&#113;&#193;",
	"DA" : "&#113;&#193;",
	"Di" : "&#114;",
	"DI" : "&#114;&#195;",
	"Dee" : "&#114;&#195;",
	"Du" : "&#113;&#192;&#196;", 
	"DU" : "&#113;&#192;&#198;", 
	"DRu" : "&#113;&#192;&#200;", 
	"DRU" : "&#113;&#192;&#241;", 
	"De" : "&#113;&#201;", 
	"DE" : "&#113;&#201;&#195;", 
	"Do" : "&#113;&#201;&#198;", 
	"DO" : "&#113;&#201;&#198;&#195;", 
	"Dai" : "&#113;&#201;&#202;",
	"Dau" : "&#113;&#203;",
	"Dr" : "&#113;&#253;",
	
	
	//Dh
	"Dh" : "&#113;&#115;&#239;",
	"Dha" : "&#113;&#115;&#192;",
	"Dhaa" : "&#113;&#115;&#193;",
	"DhA" : "&#113;&#115;&#193;",
	"Dhi" : "&#114;&#252;",
	"DhI" : "&#114;&#252;&#195;",
	"Dhee" : "&#114;&#252;&#195;",
	"Dhu" : "&#113;&#115;&#192;&#196;", 
	"DhU" : "&#113;&#115;&#192;&#198;", 
	"DhRu" : "&#113;&#115;&#192;&#200;", 
	"DhRU" : "&#113;&#115;&#192;&#241;", 
	"Dhe" : "&#113;&#115;&#201;", 
	"DhE" : "&#113;&#115;&#201;&#195;", 
	"Dho" : "&#113;&#115;&#201;&#198;", 
	"DhO" : "&#113;&#115;&#201;&#198;&#195;", 
	"Dhai" : "&#113;&#115;&#201;&#202;",
	"Dhau" : "&#113;&#115;&#203;",
	"Dhr" : "&#113;&#115;&#253;",
	
	
	//N
	"N" : "&#117;&#239;",
	"Na" : "&#116;",
	"Naa" : "&#117;&#193;",
	"NA" : "&#117;&#193;",
	"Ni" : "&#116;&#194;",
	"NI" : "&#116;&#194;&#195;",
	"Nee" : "&#116;&#194;&#195;",
	"Nu" : "&#116;&#196;", 
	"NU" : "&#116;&#198;", 
	"Ne" : "&#117;&#201;", 
	"NE" : "&#117;&#201;&#195;", 
	"Noo" : "&#116;&#198;", 
	"NRu" : "&#116;&#200;", 
	"NRU" : "&#116;&#241;", 
	"Nai" : "&#117;&#201;&#202;",
	"No" : "&#117;&#201;&#198;", 
	"NO" : "&#117;&#201;&#198;&#195;", 
	"Nau" : "&#117;&#203;",
	"Nr" : "&#117;&#253;",
	
	
	//t
	"t" : "&#118;&#239;",
	"ta" : "&#118;&#192;",
	"taa" : "&#118;&#193;",
	"tA" : "&#118;&#193;",
	"ti" : "&#119;",
	"tI" : "&#119;&#195;",
	"tee" : "&#119;&#195;",
	"tu" : "&#118;&#192;&#196;", 
	"tU" : "&#118;&#192;&#198;", 
	"too" : "&#118;&#192;&#198;", 
	"te" : "&#118;&#201;", 
	"tE" : "&#118;&#201;&#195;", 
	"tRu" : "&#118;&#192;&#200;", 
	"tRU" : "&#118;&#192;&#241;", 
	"tai" : "&#118;&#201;&#202;",
	"to" : "&#118;&#201;&#198;", 
	"tO" : "&#118;&#201;&#198;&#195;", 
	"tau" : "&#118;&#203;",
	"tr" : "&#118;&#239;&#230;",
	
	
	//th
	"th" : "&#120;&#239;",
	"tha" : "&#120;&#192;",
	"thaa" : "&#120;&#193;",
	"thA" : "&#120;&#193;",
	"thi" : "&#121;",
	"thI" : "&#121;&#195;",
	"thee" : "&#119;&#195;",
	"thu" : "&#120;&#192;&#196;", 
	"thU" : "&#120;&#192;&#198;", 
	"thoo" : "&#120;&#192;&#198;", 
	"the" : "&#120;&#201;", 
	"thE" : "&#120;&#201;&#195;", 
	"thRu" : "&#120;&#192;&#200;", 
	"thRU" : "&#120;&#192;&#241;", 
	"thai" : "&#120;&#201;&#202;",
	"tho" : "&#120;&#201;&#198;", 
	"thO" : "&#120;&#201;&#198;&#195;", 
	"thau" : "&#120;&#203;",
	"thr" : "&#118;&#239;&#230;",
	
	
	
	//d
	"d" : "&#122;&#239;",
	"da" : "&#122;&#192;",
	"daa" : "&#122;&#193;",
	"dA" : "&#122;&#193;",
	"di" : "&#162;",
	"dI" : "&#162;&#195;",
	"dee" : "&#162;&#195;",
	"du" : "&#122;&#192;&#196;", 
	"dU" : "&#122;&#192;&#198;", 
	"doo" : "&#122;&#192;&#198;", 
	"de" : "&#122;&#201;", 
	"dE" : "&#122;&#201;&#195;", 
	"dRu" : "&#122;&#192;&#200;", 
	"dRU" : "&#122;&#192;&#241;", 
	"dai" : "&#122;&#201;&#202;",
	"do" : "&#122;&#201;&#198;", 
	"dO" : "&#122;&#201;&#198;&#195;", 
	"dau" : "&#122;&#203;",
	"dr" : "&#118;&#239;&#230;",
	
	
	//dh
	"dh" : "&#122;&#115;&#239;",
	"dha" : "&#122;&#115;&#192;",
	"dhaa" : "&#122;&#115;&#193;",
	"dhA" : "&#122;&#115;&#193;",
	"dhi" : "&#162;&#252;",
	"dhI" : "&#162;&#252;&#195;",
	"dhee" : "&#162;&#252;&#195;",
	"dhu" : "&#122;&#115;&#192;&#196;", 
	"dhU" : "&#122;&#115;&#192;&#198;", 
	"dhRu" : "&#122;&#115;&#192;&#200;", 
	"dhRU" : "&#122;&#115;&#192;&#241;", 
	"dhe" : "&#122;&#115;&#201;", 
	"dhE" : "&#122;&#115;&#201;&#195;", 
	"dho" : "&#122;&#115;&#201;&#198;", 
	"dhO" : "&#122;&#115;&#201;&#198;&#195;", 
	"dhai" : "&#122;&#115;&#201;&#202;",
	"dhau" : "&#122;&#115;&#203;",
	"dhr" : "&#122;&#115;&#253;",
	
	
	//n
	"n" : "&#163;&#239;",
	"na" : "&#163;&#192;",
	"naa" : "&#163;&#193;",
	"nA" : "&#163;&#193;",
	"ni" : "&#164;",
	"nI" : "&#164;&#195;",
	"nee" : "&#164;&#195;",
	"nu" : "&#163;&#192;&#196;", 
	"nU" : "&#163;&#192;&#198;", 
	"ne" : "&#163;&#201;", 
	"nE" : "&#163;&#201;&#195;", 
	"noo" : "&#163;&#192;&#198;", 
	"nRu" : "&#163;&#192;&#200;", 
	"nRU" : "&#163;&#192;&#241;", 
	"nai" : "&#163;&#201;&#202;",
	"no" : "&#163;&#201;&#198;", 
	"nO" : "&#163;&#201;&#198;&#195;", 
	"nau" : "&#163;&#203;",
	"nr" : "&#163;&#253;",
	
	
	//p
	"p" : "&#165;&#239;",
	"pa" : "&#165;&#192;",
	"paa" : "&#165;&#193;",
	"pA" : "&#165;&#193;",
	"pi" : "&#166;",
	"pI" : "&#166;&#195;",
	"pee" : "&#166;&#195;",
	"pu" : "&#165;&#192;&#197;", 
	"pU" : "&#165;&#192;&#199;", 
	"poo" : "&#165;&#192;&#199;", 
	"pe" : "&#165;&#201;", 
	"pE" : "&#165;&#201;&#195;", 
	"pRu" : "&#165;&#192;&#200;", 
	"pRU" : "&#165;&#192;&#241;", 
	"pai" : "&#165;&#201;&#202;",
	"po" : "&#165;&#201;&#199;", 
	"pO" : "&#165;&#201;&#199;&#195;", 
	"pau" : "&#165;&#203;",
	"pr" : "&#165;&#239;&#230;",
	
	
	//P
	"P" : "&#165;&#115;&#239;",
	"Pa" : "&#165;&#115;&#192;",
	"Paa" : "&#165;&#115;&#193;",
	"PA" : "&#165;&#115;&#193;",
	"Pi" : "&#166;&#252;",
	"PI" : "&#166;&#252;&#195;",
	"Pee" : "&#166;&#252;&#195;",
	"Pu" : "&#165;&#115;&#192;&#197;", 
	"PU" : "&#165;&#115;&#192;&#199;", 
	"Poo" : "&#165;&#115;&#192;&#199;", 
	"Pe" : "&#165;&#115;&#201;", 
	"PE" : "&#165;&#115;&#201;&#195;", 
	"PRu" : "&#165;&#115;&#192;&#200;", 
	"PRU" : "&#165;&#115;&#192;&#241;", 
	"Pai" : "&#165;&#115;&#201;&#202;",
	"Po" : "&#165;&#115;&#201;&#199;", 
	"PO" : "&#165;&#115;&#201;&#199;&#195;", 
	"Pau" : "&#165;&#115;&#203;",
	
	//ph
	"ph" : "&#165;&#115;&#239;",
	"pha" : "&#165;&#115;&#192;",
	"phaa" : "&#165;&#115;&#193;",
	"phA" : "&#165;&#115;&#193;",
	"phi" : "&#166;&#252;",
	"phI" : "&#166;&#252;&#195;",
	"phee" : "&#166;&#252;&#195;",
	"phu" : "&#165;&#115;&#192;&#197;", 
	"phU" : "&#165;&#115;&#192;&#199;", 
	"phoo" : "&#165;&#115;&#192;&#199;", 
	"phe" : "&#165;&#115;&#201;", 
	"phE" : "&#165;&#115;&#201;&#195;", 
	"phRu" : "&#165;&#115;&#192;&#200;", 
	"phRU" : "&#165;&#115;&#192;&#241;", 
	"phai" : "&#165;&#115;&#201;&#202;",
	"pho" : "&#165;&#115;&#201;&#199;", 
	"phO" : "&#165;&#115;&#201;&#199;&#195;", 
	"phau" : "&#165;&#115;&#203;",
	
	//f
	"f" : "&#165;&#115;&#243;&#239;",
	"fa" : "&#165;&#115;&#243;&#192;",
	"faa" : "&#165;&#115;&#243;&#193;",
	"fA" : "&#165;&#115;&#243;&#193;",
	"fi" : "&#166;&#252;&#251;",
	"fI" : "&#166;&#252;&#251;&#195;",
	"fee" : "&#166;&#252;&#251;&#195;",
	"fu" : "&#165;&#115;&#243;&#192;&#197;", 
	"fU" : "&#165;&#115;&#243;&#192;&#199;", 
	"foo" : "&#165;&#115;&#243;&#192;&#199;", 
	"fe" : "&#165;&#115;&#243;&#201;", 
	"fE" : "&#165;&#115;&#243;&#201;&#195;", 
	"fRu" : "&#165;&#115;&#243;&#192;&#200;", 
	"fRU" : "&#165;&#115;&#243;&#192;&#241;", 
	"fai" : "&#165;&#115;&#243;&#201;&#202;",
	"fo" : "&#165;&#115;&#243;&#201;&#199;", 
	"fO" : "&#165;&#115;&#243;&#201;&#199;&#195;", 
	"fau" : "&#165;&#115;&#243;&#203;",
	
	
	//b
	"b" : "&#168;&#239;",
	"ba" : "&#167;",
	"baa" : "&#168;&#193;",
	"bA" : "&#168;&#193;",
	"bi" : "&#169;",
	"bI" : "&#169;&#195;",
	"bee" : "&#169;&#195;",
	"bu" : "&#167;&#196;", 
	"bU" : "&#167;&#198;", 
	"boo" : "&#167;&#198;", 
	"be" : "&#168;&#201;", 
	"bE" : "&#168;&#201;&#195;", 
	"bRu" : "&#167;&#200;", 
	"bRU" : "&#167;&#241;", 
	"bai" : "&#168;&#201;&#202;",
	"bo" : "&#168;&#201;&#198;", 
	"bO" : "&#168;&#201;&#198;&#195;", 
	"bau" : "&#168;&#203;",
	"br" : "&#168;&#239;&#230;",
	
	
	//bh
	"bh" : "&#168;&#115;&#239;",
	"bha" : "&#168;&#192;&#252;",
	"bhaa" : "&#168;&#115;&#193;",
	"bhA" : "&#168;&#115;&#193;",
	"bhi" : "&#169;&#252;",
	"bhI" : "&#169;&#252;&#195;",
	"bhee" : "&#169;&#252;&#195;",
	"bhu" : "&#168;&#192;&#252;&#196;", 
	"bhU" : "&#168;&#192;&#252;&#198;", 
	"bhoo" : "&#168;&#192;&#252;&#198;", 
	"bhe" : "&#168;&#115;&#201;", 
	"bhE" : "&#168;&#115;&#201;&#195;", 
	"bhRu" : "&#168;&#192;&#252;&#200;", 
	"bhRU" : "&#168;&#192;&#252;&#241;", 
	"bhai" : "&#168;&#115;&#201;&#202;",
	"bho" : "&#168;&#115;&#201;&#198;", 
	"bhO" : "&#168;&#115;&#201;&#198;&#195;", 
	"bhau" : "&#168;&#115;&#203;",
	
	//B
	"B" : "&#168;&#115;&#239;",
	"Ba" : "&#168;&#192;&#252;",
	"Baa" : "&#168;&#115;&#193;",
	"BA" : "&#168;&#115;&#193;",
	"Bi" : "&#169;&#252;",
	"BI" : "&#169;&#252;&#195;",
	"Bee" : "&#169;&#252;&#195;",
	"Bu" : "&#168;&#192;&#252;&#196;", 
	"BU" : "&#168;&#192;&#252;&#198;", 
	"Boo" : "&#168;&#192;&#252;&#198;", 
	"Be" : "&#168;&#115;&#201;", 
	"BE" : "&#168;&#115;&#201;&#195;", 
	"BRu" : "&#168;&#192;&#252;&#200;", 
	"BRU" : "&#168;&#192;&#252;&#241;", 
	"Bai" : "&#168;&#115;&#201;&#202;",
	"Bo" : "&#168;&#115;&#201;&#198;", 
	"BO" : "&#168;&#115;&#201;&#198;&#195;", 
	"Bau" : "&#168;&#115;&#203;",
	
	
	//m
	"m" : "&#170;&#192;&#105;&#239;",
	"ma" : "&#170;&#192;&#196;",
	"maa" : "&#170;&#192;&#105;&#193;",
	"mA" : "&#170;&#192;&#105;&#193;",
	"mi" : "&#171;&#196;",
	"mI" : "&#171;&#196;&#195;",
	"mee" : "&#171;&#196;&#195;",
	"mu" : "&#170;&#192;&#196;&#196;", 
	"mU" : "&#170;&#192;&#196;&#198;", 
	"moo" : "&#170;&#192;&#196;&#198;", 
	"me" : "&#170;&#201;&#196;", 
	"mE" : "&#170;&#201;&#196;&#195;", 
	"mRu" : "&#170;&#192;&#196;&#200;", 
	"mRU" : "&#170;&#192;&#196;&#241;", 
	"mai" : "&#170;&#201;&#196;&#202;",
	"mo" : "&#170;&#201;&#198;", 
	"mO" : "&#170;&#201;&#198;&#195;", 
	"mau" : "&#170;&#192;&#105;&#203;",
	
	
	//y
	"y" : "&#65;&#105;&#192;&#105;&#239;",
	"ya" : "&#65;&#105;&#192;&#196;",
	"yaa" : "&#65;&#105;&#192;&#105;&#193;",
	"yA" : "&#65;&#105;&#192;&#105;&#193;",
	"yi" : "&#172;&#196;",
	"yI" : "&#172;&#196;&#195;",
	"yee" : "&#172;&#196;&#195;",
	"yu" : "&#65;&#105;&#192;&#196;&#196;", 
	"yU" : "&#65;&#105;&#192;&#196;&#198;", 
	"yoo" : "&#65;&#105;&#192;&#196;&#198;", 
	"ye" : "&#65;&#105;&#201;&#196;", 
	"yE" : "&#65;&#105;&#201;&#196;&#195;", 
	"yRu" : "&#65;&#105;&#192;&#196;&#200;", 
	"yRU" : "&#65;&#105;&#192;&#196;&#241;", 
	"yai" : "&#65;&#105;&#201;&#196;&#202;",
	"yo" : "&#65;&#105;&#201;&#198;", 
	"yO" : "&#65;&#105;&#201;&#198;&#195;", 
	"yau" : "&#65;&#105;&#192;&#105;&#203;",
	
	//Y
	"Y" : "&#65;&#105;&#192;&#105;&#239;",
	"Ya" : "&#65;&#105;&#192;&#196;",
	"Yaa" : "&#65;&#105;&#192;&#105;&#193;",
	"YA" : "&#65;&#105;&#192;&#105;&#193;",
	"Yi" : "&#172;&#196;",
	"YI" : "&#172;&#196;&#195;",
	"Yee" : "&#172;&#196;&#195;",
	"Yu" : "&#65;&#105;&#192;&#196;&#196;", 
	"YU" : "&#65;&#105;&#192;&#196;&#198;", 
	"Yoo" : "&#65;&#105;&#192;&#196;&#198;", 
	"Ye" : "&#65;&#105;&#201;&#196;", 
	"YE" : "&#65;&#105;&#201;&#196;&#195;", 
	"YRu" : "&#65;&#105;&#192;&#196;&#200;", 
	"YRU" : "&#65;&#105;&#192;&#196;&#241;", 
	"Yai" : "&#65;&#105;&#201;&#196;&#202;",
	"Yo" : "&#65;&#105;&#201;&#198;", 
	"YO" : "&#65;&#105;&#201;&#198;&#195;", 
	"Yau" : "&#65;&#105;&#192;&#105;&#203;",
	
	
	//r
	"r" : "&#103;&#239;",
	"ra" : "&#103;&#192;",
	"raa" : "&#103;&#193;",
	"rA" : "&#103;&#193;",
	"ri" : "&#106;",
	"rI" : "&#106;&#195;",
	"ree" : "&#106;&#195;",
	"ru" : "&#103;&#192;&#196;", 
	"rU" : "&#103;&#192;&#198;", 
	"roo" : "&#103;&#192;&#198;", 
	"re" : "&#103;&#201;", 
	"rE" : "&#103;&#201;&#195;", 
	"rRu" : "&#103;&#192;&#200;", 
	"rRU" : "&#103;&#192;&#241;", 
	"rai" : "&#103;&#201;&#202;",
	"ro" : "&#103;&#201;&#198;", 
	"rO" : "&#103;&#201;&#198;&#195;", 
	"rau" : "&#103;&#203;",
	
	
	//R
	"R" : "&#103;&#239;",
	"Ra" : "&#103;&#192;",
	"Raa" : "&#103;&#193;",
	"RA" : "&#103;&#193;",
	"Ri" : "&#106;",
	"RI" : "&#106;&#195;",
	"Ree" : "&#106;&#195;",
	// "Ru" : "&#103;&#192;&#196;", 
	// "RU" : "&#103;&#192;&#198;", 
	"Roo" : "&#103;&#192;&#198;", 
	"Re" : "&#103;&#201;", 
	"RE" : "&#103;&#201;&#195;", 
	"RRu" : "&#103;&#192;&#200;", 
	"RRU" : "&#103;&#192;&#241;", 
	"Rai" : "&#103;&#201;&#202;",
	"Ro" : "&#103;&#201;&#198;", 
	"RO" : "&#103;&#201;&#198;&#195;", 
	"Rau" : "&#103;&#203;",
	
	
	//l
	"l" : "&#175;&#239;",
	"la" : "&#174;",
	"laa" : "&#175;&#193;",
	"lA" : "&#175;&#193;",
	"li" : "&#176;",
	"lI" : "&#176;&#195;",
	"lee" : "&#176;&#195;",
	"lu" : "&#174;&#196;", 
	"lU" : "&#174;&#198;", 
	"loo" : "&#174;&#198;", 
	"le" : "&#175;&#201;", 
	"lE" : "&#175;&#201;&#195;", 
	"lRu" : "&#174;&#200;", 
	"lRU" : "&#174;&#241;", 
	"lai" : "&#175;&#201;&#202;",
	"lo" : "&#175;&#201;&#198;", 
	"lO" : "&#175;&#201;&#198;&#195;", 
	"lau" : "&#175;&#203;",
	
	
	//v
	"v" : "&#170;&#239;",
	"va" : "&#170;&#192;",
	"vaa" : "&#170;&#193;",
	"vA" : "&#170;&#193;",
	"vi" : "&#171;",
	"vI" : "&#171;&#195;",
	"vee" : "&#171;&#195;",
	"vu" : "&#170;&#192;&#197;", 
	"vU" : "&#170;&#192;&#199;", 
	"voo" : "&#170;&#192;&#199;", 
	"ve" : "&#170;&#201;", 
	"vE" : "&#170;&#201;&#195;", 
	"vRu" : "&#170;&#192;&#200;", 
	"vRU" : "&#170;&#192;&#241;", 
	"vai" : "&#170;&#201;&#202;",
	"vo" : "&#170;&#201;&#199;", 
	"vO" : "&#170;&#201;&#199;&#195;", 
	"vau" : "&#170;&#203;",
	
	//w
	"w" : "&#170;&#239;",
	"wa" : "&#170;&#192;",
	"waa" : "&#170;&#193;",
	"wA" : "&#170;&#193;",
	"wi" : "&#171;",
	"wI" : "&#171;&#195;",
	"wee" : "&#171;&#195;",
	"wu" : "&#170;&#192;&#197;", 
	"wU" : "&#170;&#192;&#199;", 
	"woo" : "&#170;&#192;&#199;", 
	"we" : "&#170;&#201;", 
	"wE" : "&#170;&#201;&#195;", 
	"wRu" : "&#170;&#192;&#200;", 
	"wRU" : "&#170;&#192;&#241;", 
	"wai" : "&#170;&#201;&#202;",
	"wo" : "&#170;&#201;&#199;", 
	"wO" : "&#170;&#201;&#199;&#195;", 
	"wau" : "&#170;&#203;",
	
	
	//sh
	"sh" : "&#177;&#239;",
	"sha" : "&#177;&#192;",
	"shaa" : "&#177;&#193;",
	"shA" : "&#177;&#193;",
	"shi" : "&#178;",
	"shI" : "&#178;&#195;",
	"shee" : "&#178;&#195;",
	"shu" : "&#177;&#192;&#196;", 
	"shU" : "&#177;&#192;&#198;", 
	"shoo" : "&#177;&#192;&#198;", 
	"she" : "&#177;&#201;", 
	"shE" : "&#177;&#201;&#195;", 
	"shRu" : "&#177;&#192;&#200;", 
	"shRU" : "&#177;&#192;&#241;", 
	"shai" : "&#177;&#201;&#202;",
	"sho" : "&#177;&#201;&#198;", 
	"shO" : "&#177;&#201;&#198;&#195;", 
	"shau" : "&#177;&#203;",
	
	//S
	"S" : "&#177;&#239;",
	"Sa" : "&#177;&#192;",
	"Saa" : "&#177;&#193;",
	"SA" : "&#177;&#193;",
	"Si" : "&#178;",
	"SI" : "&#178;&#195;",
	"See" : "&#178;&#195;",
	"Su" : "&#177;&#192;&#196;", 
	"SU" : "&#177;&#192;&#198;", 
	"Soo" : "&#177;&#192;&#198;", 
	"Se" : "&#177;&#201;", 
	"SE" : "&#177;&#201;&#195;", 
	"SRu" : "&#177;&#192;&#200;", 
	"SRU" : "&#177;&#192;&#241;", 
	"Sai" : "&#177;&#201;&#202;",
	"So" : "&#177;&#201;&#198;", 
	"SO" : "&#177;&#201;&#198;&#195;", 
	"Sau" : "&#177;&#203;",
	
	//Sh
	"Sh" : "&#181;&#239;",
	"Sha" : "&#181;&#192;",
	"Shaa" : "&#181;&#193;",
	"ShA" : "&#181;&#193;",
	"Shi" : "&#182;",
	"ShI" : "&#182;&#195;",
	"Shee" : "&#182;&#195;",
	"Shu" : "&#181;&#192;&#196;", 
	"ShU" : "&#181;&#192;&#198;", 
	"Shoo" : "&#181;&#192;&#198;", 
	"She" : "&#181;&#201;", 
	"ShE" : "&#181;&#201;&#195;", 
	"ShRu" : "&#181;&#192;&#200;", 
	"ShRU" : "&#181;&#192;&#241;", 
	"Shai" : "&#181;&#201;&#202;",
	"Sho" : "&#181;&#201;&#198;", 
	"ShO" : "&#181;&#201;&#198;&#195;", 
	"Shau" : "&#181;&#203;",
	
	
	//s
	"s" : "&#184;&#239;",
	"sa" : "&#184;&#192;",
	"saa" : "&#184;&#193;",
	"sA" : "&#184;&#193;",
	"si" : "&#185;",
	"sI" : "&#185;&#195;",
	"see" : "&#185;&#195;",
	"su" : "&#184;&#192;&#196;", 
	"sU" : "&#184;&#192;&#198;", 
	"soo" : "&#184;&#192;&#198;", 
	"se" : "&#184;&#201;", 
	"sE" : "&#184;&#201;&#195;", 
	"sRu" : "&#184;&#192;&#200;", 
	"sRU" : "&#184;&#192;&#241;", 
	"sai" : "&#184;&#201;&#202;",
	"so" : "&#184;&#201;&#198;", 
	"sO" : "&#184;&#201;&#198;&#195;", 
	"sau" : "&#184;&#203;",
	
	
	//h
	"h" : "&#186;&#239;",
	"ha" : "&#186;&#192;",
	"haa" : "&#186;&#193;",
	"hA" : "&#186;&#193;",
	"hi" : "&#187;",
	"hI" : "&#187;&#195;",
	"hee" : "&#187;&#195;",
	"hu" : "&#186;&#192;&#196;", 
	"hU" : "&#186;&#192;&#198;", 
	"hoo" : "&#186;&#192;&#198;", 
	"he" : "&#186;&#201;", 
	"hE" : "&#186;&#201;&#195;", 
	"hRu" : "&#186;&#192;&#200;", 
	"hRU" : "&#186;&#192;&#241;", 
	"hai" : "&#186;&#201;&#202;",
	"ho" : "&#186;&#201;&#198;", 
	"hO" : "&#186;&#201;&#198;&#195;", 
	"hau" : "&#186;&#203;",
	
	
	//L
	"L" : "&#188;&#239;",
	"La" : "&#188;&#192;",
	"Laa" : "&#188;&#193;",
	"LA" : "&#188;&#193;",
	"Li" : "&#189;",
	"LI" : "&#189;&#195;",
	"Lee" : "&#189;&#195;",
	"Lu" : "&#188;&#192;&#196;", 
	"LU" : "&#188;&#192;&#198;", 
	"Loo" : "&#188;&#192;&#198;", 
	"Le" : "&#188;&#201;", 
	"LE" : "&#188;&#201;&#195;", 
	"LRu" : "&#188;&#192;&#200;", 
	"LRU" : "&#188;&#192;&#241;", 
	"Lai" : "&#188;&#201;&#202;",
	"Lo" : "&#188;&#201;&#198;", 
	"LO" : "&#188;&#201;&#198;&#195;", 
	"Lau" : "&#188;&#203;",
	
	//kSha
	"kSh" : "&#80;&#239;&#235;",
	"kSha" : "&#80;&#192;&#235;",
	"kShaa" : "&#80;&#193;&#235;",
	"kShA" : "&#80;&#193;&#235;",
	"kShi" : "&#81;&#235;",
	"kShI" : "&#81;&#195;&#235;",
	"kShee" : "&#81;&#195;&#235;",
	"kShu" : "&#80;&#192;&#196;&#235;", 
	"kShU" : "&#80;&#192;&#198;&#235;", 
	"kShoo" : "&#80;&#192;&#198;&#235;", 
	"kShe" : "&#80;&#201;&#235;", 
	"kShE" : "&#80;&#201;&#235;&#195;", 
	"kShRu" : "&#80;&#192;&#235;&#200;", 
	"kShRU" : "&#80;&#192;&#235;&#241;", 
	"kShai" : "&#80;&#201;&#235;&#202;",
	"kSho" : "&#80;&#201;&#235;&#198;", 
	"kShO" : "&#80;&#201;&#198;&#235;&#195;", 
	"kShau" : "&#80;&#203;&#235;",
	
	// subscript letter codes
	"^k": "&#204;",
	"^kh": "&#205;",
	"^K": "&#205;",
	"^g": "&#206;",
	"^gh": "&#207;",
	"^G": "&#207;",
	"^c": "&#209;",
	"^ch": "&#209;",
	"^C": "&#210;",
	"^Ch": "&#210;",
	"^j": "&#211;",
	"^J": "&#212;",
	"^T": "&#214;",
	"^Th": "&#215;",
	"^D": "&#216;",
	"^N": "&#218;",
	"^t": "&#219;",
	"^Th": "&#220;",
	"^th": "&#220;",
	"^d": "&#221;",
	"^dh": "&#222;",
	"^n": "&#223;",
	"^p": "&#224;",
	"^ph": "&#225;",
	"^P": "&#225;",
	"^f": "&#225;",
	"^b": "&#226;",
	"^bh": "&#227;",
	"^B": "&#227;",
	"^m": "&#228;",
	"^^m": "&#228;",
	"^y": "&#229;",
	"^r": "&#230;",
	"^l": "&#232;",
	"^v": "&#233;",
	"^w": "&#233;",
	"^sh": "&#234;",
	"^S": "&#234;",
	"^s": "&#236;",
	"^h": "&#237;",
	"^^h": "&#237;",
	"^L": "&#238;",
	"^^r": "&#240;",
	"^Q": "&#213;"
	}
	
	this.subscript_letter_codes = "(k(h)?)|(K)|(g(h)?)|(G)|(c(h)?)|(C(h)?)|(j)|(J)|(T(h)?)|(D)|(N)|(t(h)?)|(d(h)?)|(n)|(p(h)?)|(P)|(f)|(b(h)?)|(B)|(m)|(y)|(r)|(l)|(v)|(w)|(S)|(s(h)?)|(h)|(L)|(r)|(Q)";
	this.split_consonants = "(k(h)?)|(K)|(g(h)?)|(G)|(c(h)?)|(C(h)?)|(j(h)?)|(J)|(T(h)?)|(D(h)?)|(N)|(t(h)?)|(d(h)?)|(n)|(p(h)?)|(P)|(f)|(b(h)?)|(B)|(m)|(y)|(Y)|(r)|(R)|(l)|(L)|(v)|(s(h)?)|(Sh)|(S)|(h)";
	this.special_case_letters = "(j~)";	
}

brhEngine.prototype.split_word = function(word)
{
  var syllables = new Array(0);
  var vowel_start_p = true;
  while (word.length) {
    re = new RegExp(this.vowels);
    var index = word.search(this.vowels);
    if (index == 0) {  //the vowel's at the start of word
      var matched = re.exec(word)[0]; //what is it?
      if (vowel_start_p) {
	syllables.push(("~"+matched)); //one more to the syllables
      } else {
	syllables.push(matched);
      }
      vowel_start_p = true;
      word = word.substring(matched.length);
    } else {
      re = new RegExp(this.consonants);
      var index = word.search(this.consonants);
      if (index == 0) {
	var matched = re.exec(word)[0];
	syllables.push(matched);
	vowel_start_p = false;
	word = word.substring(matched.length);

	//look ahead for virama setting
	var next = word.search(this.vowels);
	if (next != 0 || word.length == 0)
	  syllables.push('*');
      } else {
	syllables.push(word.charAt(0));
	word = word.substring(1);
      }
    }
  }
  return syllables;
}


brhEngine.prototype.match_code = function(syllable_mcc)
{
  var matched = this.letter_codes[syllable_mcc];

  if (matched != null) return matched;
  return syllable_mcc;
}


brhEngine.prototype.one_word = function(word_ow)
{
  if (!word_ow) return "";
  var syllables_ow = this.split_word(word_ow);
  var letters_ow = new Array(0);

  /*
   *  Author: Raghava Kotekar
   *  reformat the syllables_ow for subscript charecters
   */
  
  syllables_ow = this.find_modifiy_for_subscripts(syllables_ow);
  
  for (var i_ow = 0; i_ow < syllables_ow.length; i_ow++) {
    letters_ow.push(this.match_code(syllables_ow[i_ow]));
  }
  return letters_ow.join("");
}

brhEngine.prototype.many_words = function(sentence)
{
//  var regex = "((" + this.vowels + ")|(" + this.consonants + ")|(" + special_chars + "))+";
  var regex = "((" + this.vowels + ")|(" + this.consonants + "))+";
  var words = new Array(0);
  while (sentence.length >= 1) 
  {
  	/*
  	 * Extract the <lang=eng> and <lang=kan> specific tag values
  	 */
	
    re = new RegExp("^``" + regex);
    var match = re.exec(sentence);
    if (match != null) 
	{
      match = match[0];
      words.push("`");
      words.push(this.one_word(match.substring(2)));
      sentence = sentence.substring(match.length);
    } 
	else 
	{
      re = new RegExp("^`" + regex);
      match = re.exec(sentence);
      if (match != null) 
	  {
		match = match[0];
		words.push(match.substring(1));
		sentence = sentence.substring(match.length);
      } 
	  else 
	  {
		re = new RegExp("^" + regex);
		match = re.exec(sentence);
		if (match != null) 
		{
		  match = match[0];
		  words.push(this.one_word(match));
		  sentence = sentence.substring(match.length);
		} 
		else 
		{
			if (sentence.indexOf('<lang=eng>') == 0) 
			{
				var pos = sentence.indexOf('<lang=kan>');
				if (pos != -1) {
					words.push('<span class="english">' + sentence.substr(10, pos-10) + '</span>');
					sentence = sentence.substring(pos + 10, sentence.length);
				}
				else {
//					words.push(sentence.substr(10));
					words.push('<span class="english">' + sentence.substr(10) + '</span>');
					sentence = '';
				}
			}
			else if (sentence.indexOf('<lang=kan>') == 0) 
			{
				sentence = sentence.substring(10);
			}
			else {
				words.push(sentence.charAt(0));
				sentence = sentence.substring(1);
			}
		}
      }
    }
  }
  return words.join("");
}

brhEngine.prototype.print_many_words = function(inputEle, outputEle)
{
  var text_pmw = inputEle.value;

  text_pmw = text_pmw.replace(/\^/g, '¶');
  text_pmw = text_pmw.replace(/\~j/g, 'Q');
  text_pmw = this.many_words(text_pmw);


  var ans = "";
   while (text_pmw.length) {
    var unicode_chars = /&#[0-9]+;/;
    re = unicode_chars;
    var matche = re.exec(text_pmw);
    if (matche != null) {
      matche = matche[0];
      search = text_pmw.search(unicode_chars);
      ans += text_pmw.substring(0, search);
      ans += String.fromCharCode(matche.match(/[0-9]+/));
      text_pmw = text_pmw.substring(search + matche.length);
    } else {
      ans += text_pmw.substring(0);
      text_pmw = "";
    }
  }

  ans = ans.replace(/¶/g, '');
  ans = ans.replace(/\n/g, '<br/>');
  outputEle.innerHTML = ans;

  var html_txt = "";
  for (i=0; i<ans.length; i++) {
    var unicode_character = ans.charCodeAt(i);
    switch (unicode_character) {
    case 32:
      html_txt += " ";
      break;
    case 10:
    case 13:
      html_txt += "<br/>\n";
      break;
    default:
      html_txt += "&#" + unicode_character + ";";
    }
  }

//  document.convarea.html_text.value = html_txt;
}


/*
 * find_modifiy_for_subscripts
 */

brhEngine.prototype.find_modifiy_for_subscripts = function(arr)
{
	for(var i=0; i<arr.length; i++)
	{
		if(arr[i+1] != "*")
			i++;
		if(arr[i+2] != null)
		{
			    var format = "((" + this.split_consonants + "))+";
				var first_code = this.match_special_codes(arr[i], format);
				
				//	check for multiple ottakshara cases
				if(first_code == null)
				{
					if(arr[i].indexOf('^') != -1)
					{
						if (arr[i - 2]) 
						{
							format = "((" + this.vowels + ")|(" + this.consonants + "))+";
							var l = this.match_special_codes(arr[i + 2], format);
							
							var n = this.match_special_codes(arr[i + 2], this.subscript_letter_codes);
							if((l == n) && (arr[i+2].length != l.length))
							{
								var m = arr[i+2].substr(n.length, arr[i+2].length);
								arr[i-2] = arr[i-2] + m;
								arr[i+2] = '^' + n;
							}
							
						}
					}
				}
				
				if (first_code != null) 
				{
					format = "((" + this.vowels + ")|(" + this.consonants + "))+";
					var second_code = this.match_special_codes(arr[i], format);
					
					if ((first_code == second_code)) 
					{
						if (first_code != null) {
							var replace_code = this.match_special_codes(arr[i + 2], this.subscript_letter_codes);
							if (replace_code != null) 
							{
								// if (((first_code == 'r') || (first_code == 'm')) && (i)) {
								if(this.match_special_codes(first_code, "(Q)") == first_code)
								{
									arr[i] = arr[i + 2];
									arr[i + 2] = first_code;
								}
								else if (((this.match_special_codes(first_code, "(r)|(h)|(m)") == first_code) && (replace_code == this.match_special_codes(replace_code, "(k)|(m)|(n)|(h)|(d(h)?)|(t)|(g(h)?)|(G)"))) && (i)) 
								{
									arr[i] = arr[i + 2];
									arr[i + 2] = '^^' + first_code;
								}
								else 
								{
									arr[i] = first_code + arr[i + 2].substr(replace_code.length, arr[i + 2].length);
									arr[i + 2] = '^' + replace_code;
								}
								
								i++;
							}
						}
					}
				}
		}
	}
	return arr;
}


brhEngine.prototype.match_special_codes = function(sentence, format)
{
	var regex = "((" + format + "))";
	var re = new RegExp("^" + regex);
	var match = re.exec(sentence);

	if(match!=null)
	{
		return match[0];
	}
	else
		return null;
}


brhEngine.prototype.check_for_multiple_ottaksharas = function(arr, i)
{
	
}
