// HiTrans transliteration scheme 
// by Vinay P Jain
// Based on ITRANS
// Copyright Vinay P Jain under Creative Commons (by-nc-sa)
// http://creativecommons.org/licenses/by-nc-sa/2.5/
// -----------------------------------------------------
// Changes from ITRANS 
// -----------------------------------------------------
// ld gives ld instead of L 
// added ~ for avagrah
// Kh is another way to write nuqtaayukt kh, in addition to K
// oo is another way to write ba.Dii uu maatraa 
// ee is another way to write ba.Dii ii maatraa 
// R is another way to write .D
// Rh is another way to write .Dh
// JN is another way to write GY
// Gh is another way to write G
// a.u gives chandra aa (e.g. both Daa.ukTar and Daa.ckTar are same)
// .e gives chandra as .c 
// puurNaviraam changed. use pipe (|) for Da.nDaa (|), period (.) for period 
// ITRANS escape character (\) not needed before hyphen (-) or any other symbol
// -----------------------------------------------------

antar=[["a","\u0905",""],["aa","\u0906","\u093E"],["A","\u0906","\u093E"],["i","\u0907","\u093F"],["ii","\u0908","\u0940"],["I","\u0908","\u0940"],["a.u","\u0905","\u0945"],["u","\u0909","\u0941"],["uu","\u090A","\u0942"],["U","\u090A","\u0942"],["e","\u090F","\u0947"],["ee","\u0908","\u0940"],["ai","\u0910","\u0948"],["o","\u0913","\u094B"],["oo","\u090A","\u0942"],["O","\u0911","\u0949"],["au","\u0914","\u094C"],["aM","\u0905\u0902","\u0902"],["aH","\u0905\u0903","\u0903"],["aa.c","\u0911","\u0949"],["aa.u","\u0911","\u0949"],["a.c","\u0905","\u0945"],["RRi","\u090B","\u0943"],["R^i","\u090B","\u0943"],["Ru","\u090B","\u0943"],["RRI","\u0960","\u0944"],["R^I","\u0960","\u0944"],["LLi","\u090C","\u0962"],["L^i","\u090C","\u0962"],["LLI","\u0961","\u0963"],["L^I","\u0961","\u0963"],["k","\u0915"],["kh","\u0916"],["g","\u0917"],["gh","\u0918"],["~N","\u0919\u094D"],["ch","\u091A"],["chh","\u091B"],["Ch","\u091B"],["j","\u091C"],["jh","\u091D"],["~n","\u091E\u094D"],["T","\u091F"],["Th","\u0920"],["D","\u0921"],["Dh","\u0922"],["N","\u0923"],["t","\u0924"],["th","\u0925"],["d","\u0926"],["dh","\u0927"],["n","\u0928"],["p","\u092A"],["ph","\u092B"],["b","\u092C"],["bh","\u092D"],["m","\u092E"],["y","\u092F"],["r","\u0930"],["l","\u0932"],["v","\u0935"],["w","\u0935"],["sh","\u0936"],["Sh","\u0937"],["shh","\u0937"],["s","\u0938"],["h","\u0939"],["L","\u0933"],["kSh","\u0915\u094D\u0937"],["x","\u0915\u094D\u0937"],["GY","\u091C\u094D\u091E"],["JN","\u091C\u094D\u091E"],["j~n","\u091C\u094D\u091E"],["dny","\u091C\u094D\u091E"],["shr","\u0936\u094D\u0930"],["q","\u0958"],["Kh","\u0959"],["K","\u0959"],["Gh","\u095A"],["G","\u095A"],["z","\u095B"],["J","\u095B"],["f","\u095E"],[".Dh","\u095D"],[".D","\u095C"],["Rh","\u095D"],["R","\u095C"],["AUM","\u0950"],["OM","\u0950"],[".n","\u0902"],[".m","\u0902"],["M","\u0902"],[".e","\u0945"],[".c","\u0945"],["`","\u093C"],[".N","\u0901"],[".h","\u094D"],["H","\u0903"],[".a","\u093D"],["~","\u093D"],["0","\u0966"],["1","\u0967"],["2","\u0968"],["3","\u0969"],["4","\u096A"],["5","\u096B"],["6","\u096C"],["7","\u096D"],["8","\u096E"],["9","\u096F"],["|","\u0964"],["*","\u0970"],["_",""]];
viraam="\u094d";
swar=/^0|1|2|3|4|5|6|7|8|9|(AUM)|(LLI)|(LLi)|(L\^I)|(L\^i)|(OM)|(RRI)|(RRi)|(R\^i)|(R\^i)|(\.N)|(\.a)|(\.c)|(\.h)|(\.n)|(\.m)|M|A|I|U|(aH)|(aM)|(\H)|(a\.c)|(a\.e)|(aa)|(aa\.c)|(aa\.u)|(ai)|(au)|(ee)|(ii)|(oo)|(uu)|a|e|i|o|O|u|`|~|\_|\*|\|/;
axar=/^((AUM)|(Ch)|(Dh)|(GY)|(JN)|(LLI)|(LLi)|(L\^I)|(L\^i)|(OM)|(RRI)|(RRi)|(R\^i)|(R\^I)|(Sh)|(Th)|(aa\.c)|(aa\.u)|(\.Dh)|(\.D)|(\.N)|(\.a)|(\.e)|(\.c)|(\.h)|(\.m)|(\.n)|M|(Rh)|(Gh)|(Kh)|(aa)|(ee)|(ai)|(au)|(aH)|(aM)|(chh)|(bh)|(ch)|(dny)|(dh)|(gh)|(ii)|(oo)|(jh)|(j~n)|(kSh)|(shh)|(kh)|(ph)|(shr)|(sh)|(th)|(uu)|(~N)|(~n)|A|D|G|H|I|J|K|L|N|O|R|T|U|Y|a|b|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|0|1|2|3|4|5|6|7|8|9|\_|`|~|\*|\|)/;

//pahachaano ki maatraa kaa prayog hogaa yaa akShar kaa
function b(e,r){
var i=0;
for(i=0;i<antar.length;i++){
if(antar[i][0]==e){
// maatraa yadi
if(r&&antar[i].length==3)return antar[i][2];
// anyathaa svar 
else return antar[i][1];
}
}
return e;
}

function j(e){
l="";
d=0;
a=0;
g=false;
h=false;
while(e.length){
c=axar.exec(e);
if(c&&!(h)){
	d=swar.test(c[0]);
	if(l.length&&g){
		if(!(d||a))l=l+viraam+b(c[0],0);
		else if(!a&&d&&c[0]!="a")l=l+b(c[0],1);
		else if(a&&d)l=l+b(c[0],0);
		else if(a&&!d)l=l+b(c[0],0);
	}
else l=l+b(c[0],0);
e=e.substr(c[0].length);
g=true;a=d;}else{
if(e.charAt(0)=="<"){h=true;}
else if(e.charAt(0)==">"){h=false;}
else{l=l+e.charAt(0);}
e=e.substr(1);
g=false;
}
}
return l;
}

function hix(s,t){
sourceElement=document.getElementById(s);
targetElement=document.getElementById(t);
textToConvert=sourceElement.value;
convertedText=j(textToConvert);
if(convertedText.length){targetElement.value=convertedText;}
}