/*********************************************************************************************************************************/
//Content of malayalam.js alone.Start
/*********************************************************************************************************************************/
var panchariData = "";
var panchariDataHeading = "";
var panArr = {
	 10 :"\n",//for putting paragraphs added by luap
	 31 : "",//blank
	 32 : " ",//space
	 33 : "1",     //Mapped by Anson Thomas
	 34 : "«",     //Mapped by Anson Thomas
	 35 : "3",     //Mapped by Anson Thomas
	 36 : "4",     //Mapped by Anson Thomas
	 37 : "5",     //Mapped by Anson Thomas
	 38 : "7",     //Mapped by Anson Thomas
	 39 : "!",     //Mapped by Anson Thomas
	 40 : "9",     //Mapped by Anson Thomas
	 41 : "0",     //Mapped by Anson Thomas
	 42 : "8",     //Mapped by Anson Thomas
	 43 : ")",     //Mapped by Anson Thomas
	 44 : "í",     //Mapped by Anson Thomas
	 45 : "",
	 46 : "{",     //Mapped by Anson Thomas
	 47 : "Ö",     //Mapped by Anson Thomas
	 48 : "Â",     //Mapped by Anson Thomas
	 49 : "Á",     //Mapped by Anson Thomas
	 50 : "¿",
	 51 : "¶",     //Mapped by Anson Thomas
	 52 : "Ç",     //Mapped by Anson Thomas
	 53 : "»",     //Mapped by Anson Thomas
	 54 : "Í",     //Mapped by Anson Thomas
	 55 : "Å",     //Mapped by Anson Thomas
	 56 : "¸",     //Mapped by Anson Thomas
	 57 : "À",     //Mapped by Anson Thomas
	 58 : ":",
	 59 : "°",     //Mapped by Anson Thomas
	 60 : ".",     //Mapped by Anson Thomas
	 61 : "Ë",     //Mapped by Anson Thomas
	 62 : "Ý",     //Mapped by Anson Thomas
	 63 : "æ",     //Mapped by Anson Thomas
	 64 : "2",     //Mapped by Anson Thomas
	 65 : "£",
	 66 : "=",     //Mapped by Anson Thomas
	 67 : "´",    //Mapped by Anson Thomas
	 68 : "'",
	 69 : "¦",     //Mapped by Anson Thomas
	 70 : "X",     //Mapped by Anson Thomas
	 71 : "Y",     //Mapped by Anson Thomas
	 72 : "ç",     //Mapped by Anson Thomas
	 73 : "W",     //Mapped by Anson Thomas 
	 74 : "¢",     //Mapped by Anson Thomas 
	 75 : ",",     //Mapped by Anson Thomas
	 76 : "ì",     //Mapped by Anson Thomas
	 77 : "?",     //Mapped by Anson Thomas
	 78 : "%",     //Mapped by Anson Thomas
	 79 : "§",     //Mapped by Anson Thomas
	 80 : "©",     //Mapped by Anson Thomas
	 81 : "f",     //Mapped by Anson Thomas
	 82 : "b",
	 83 : "",
	 84 : "d",     //Mapped by Anson Thomas
	 85 : "ã",     //Mapped by Anson Thomas
	 86 : "³",     //Mapped by Anson Thomas
	 87 : ":‍",     //Mapped by Anson Thomas
	 88 : "V",     //Mapped by Anson Thomas
	 89 : ";‍",     //Mapped by Anson Thomas
	 90 : "Z‍",     //Mapped by Anson Thomas
	 91 : "²",     //Mapped by Anson Thomas
	 92 : "ã",     //Mapped by Anson Thomas
	 93 : "ó",     //Mapped by Anson Thomas
	 94 : "6",     //Mapped by Anson Thomas
	 95 : "(",     //Mapped by Anson Thomas
	 96 : "¼",     //Mapped by Anson Thomas
	 97 : "¥",     //Mapped by Anson Thomas
	 98 : "Ì",     //Mapped by Anson Thomas
	 99 : "¾",      //Mapped by Anson Thomas
	 100 : "Æ",     //Mapped by Anson Thomas
	 101 : "Þ",     //Mapped by Anson Thomas
	 102 : "È",     //Mapped by Anson Thomas
	 103 : "Ã",     //Mapped by Anson Thomas
	 104 : "Î",     //Mapped by Anson Thomas
	 105 : "Ü",     //Mapped by Anson Thomas
	 106 :"·",      //Mapped by Anson Thomas
	 107 : "¯",     //Mapped by Anson Thomas
	 108 : "à",     //Mapped by Anson Thomas
	 109 : "®",     //Mapped by Anson Thomas
	 110 : "É",     //Mapped by Anson Thomas
	 111 : "ò",     //Mapped by Anson Thomas
	 112 : "",
	 113 : "×",     //Mapped by Anson Thomas
	 114 : "Õ",     //Mapped by Anson Thomas
	 115 : "Ø",     //Mapped by Anson Thomas
	 116 : "ø",     //Mapped by Anson Thomas
	 117 : "Ï",     //Mapped by Anson Thomas
	 118 : "º",     //Mapped by Anson Thomas
	 119 : "µ",     //Mapped by Anson Thomas
	 120 : "ù",     //Mapped by Anson Thomas
	 121 : "Ä",     //Mapped by Anson Thomas
	 122 : "Ù",     //Mapped by Anson Thomas
	 123 : "½",
	 124 : "/",     //Mapped by Anson Thomas
	 125 : "â",
	 126 : "¹",     //Mapped by Anson Thomas
	 127 : "",
	 128 : "",
	 129 : "",
	 130 : "",
	 131 : "",
	 132 : "",
	 133 : "",
	 134 : "",
	 135 : "",
	 136 : "",
	 137 : "",
	 138 : "",
	 139 : "",
	 140 : "",
	 141 : "",
	 142 : "",
	 143 : "",
	 144 : "",
	 145 : "",
	 146 : "",
	 147 : "",
	 148 : "",
	 149 : "",
	 150 : "",
	 151 : "", 
	 152 : "",
	 153 : "",
	 154 : "",
	 155 : "",
	 156 : "",
	 157 : "",
	 158 : "",
	 159 : "",
	 160 : "",
	 161 : "",
	 162 : "",
	 163 : "",
	 164 : "",
	 165 : "",
	 166 : "",
	 167 : "",
	 168 : "",
	 169 : "",
	 170 : "",
	 171 : "",
	 172 : "",
	 173 : "",
	 174 : "",
	 175 : "",
	 176 : "",
	 177 : "",
	 178 : "",
	 179 : "",
	 180 : "",
	 181 : "",
	 182 : "",
	 183 : "",
	 184 : "",
	 185 : "",
	 186 : "",
	 187 : "",
	 188 : "",
	 189 : "",
	 190 : "",
	 191 : "",
	 192 : "",
	 193 : "",
	 194 : "",
	 195 : "",
	 196 : "",
	 197 : "",
	 198 : "",
	 199 : "",
	 200 : "",
	 201 : "",
	 202 : "",
	 203 : "",
	 204 : "",
	 205 : "",
	 206 : "",
	 207 : "",
	 208 : "",
	 209 : "",
	 210 : "",
	 211 : "",
	 212 : "",
	 213 : "",
	 214 : "",
	 215 : "",
	 216 : "",
	 217 : "",
	 218 : "",
	 219 : "",
	 220 : "",
	 221 : "",
	 222 : "",
	 223 : "",
	 224 : "",
	 225 : "",
	 226 : "",
	 227 : "",
	 228 : "",
	 229 : "",
	 230 : "",
	 231 : "",
	 232 : "",
	 233 : "",
	 234 : "",
	 235 : "",
	 236 : "",
	 237 : "",
	 238 : "",
	 239 : "",
	 240 : "",
	 241 : "",
	 242 : "",
	 243 : "",
	 244 : "",
	 245 : "",
	 246 : "",
	 247 : "",
	 248 : "",
	 249 : "",
	 250 : "",
	 251 : "",
	 252 : "",
	 253 : "",
	 254 : "",
	 255 : "",
	 256 : "",
	 257 : "",
	 258 : "‍",//ZWJ is there in between
	 259 : "",//it is to be ZWSP ZWJ and aa.All are there but meera doesn't support ZWSP     not mapped
	 260 : "​‍",//it is to be ZWSP ZWJ and am          not mapped
	 261 : "",//Vn Added                             not mapped
	 262 : "‌"//Vin Added                             not mapped
     };

var consonants = {"~":"ങ","`":"ജ","1":"ഡ","2":"ട","3":"ഖ","4":"ധ","5":"ഛ","6":"ഭ","7":"ഥ","8":"ഘ","9":"ഠ","0":"ഢ","=":"ഫ",
			"q":"ഷ","w":"ക","r":"വ","t":"ര","y":"ത","u":"യ","i":"ല","{":"ഝ","s":"സ","d":"ദ","f":"ന","g":"ണ","h":"മ","j":"ഗ",
			"z":"ഹ","x":"റ","c":"ഞ","v":"ച","b":"ബ","n":"പ",">":"ഴ",".":"ള","/":"ശ"};
var capsArray = {"ക്w":"ക്ക","ങ്~":"ങ്ങ","ങ്w":"ങ്ക","ഞ്c":"ഞ്ഞ","ഞ്v":"ഞ്ച","ട്2":"ട്ട","ണ്g":"ണ്ണ",
				"ണ്2":"ണ്ട","ത്y":"ത്ത","ന്f":"ന്ന","ന്y":"ന്ത","പ്n":"പ്പ","മ്h":"മ്മ","മ്n":"മ്പ","ഗ്j":"ഗ്ഗ",
				"സ്s":"സ്സ","ള്.":"ള്ള",
		"ന്x":"ന്റ","ക്q":"ക്ഷ","ദ്d":"ദ്ദ","ദ്4":"ദ്ധ","ത്7":"ത്ഥ","ണ്1":"ണ്ഡ",     "ഗ്f":"ഗ്ന","ണ്h":"ണ്മ","ത്6":"ത്ഭ","ത്s":"ത്സ","ന്7":"ന്ഥ","ന്4":"ന്ധ",
				"ഗ്h":"ഗ്മ","ത്h":"ത്മ","ന്d":"ന്ദ",
				"റ്x":"റ്റ","ത്f":"ത്ന","ന്h":"ന്മ","മ്i":"മ്ല",
				"ക്i":"ക്ല","ഗ്i":"ഗ്ല","ച്v":"ച്ച","പ്i":"പ്ല","ബ്b":"ബ്ബ","ഹ്i":"ഹ്ല","ബ്i":"ബ്ല","യ്u":"യ്യ","ല്i":"ല്ല","ശ്i":"ശ്ല","സ്i":"സ്ല",
				"വ്r":"വ്വ","ഹ്f":"ഹ്ന","ശ്/":"ശ്ശ","Q":"ക്ഷ"};
var numeralsArray = {"!": "1","@": "2","#": "3","$": "4","%": "5","^": "6","&": "7","*": "8","(": "9",")": "0"};
var othersArray = {"-":"-","_":"(","+":")","|":"/",   "W":":","Y":";","p":"",    "S":"‘","D":"’","K":",","'":"!",
				"B":"=","N":"%","M":"?","<":"."};// slight difference in 'S','D', and befor ! from 'others'
var vowels = '"H":"\\u200Bേ\\u200B","?":"\\u200Bെ\\u200B","\\u200Bെ\\u200B?":"\\u200Bൈ\\u200B",'
				+
				'"e":"ാ","o":"ി","l":"ീ","]":"ു","}":"ൂ",'
				+ 
				'"\\u005C":"ൃ",' //escape character \
				+ 
				'"R":"്വ","U":"്യ",'//sva,sya
				+ 
				'"L":"ൗ","T":"\\u200B\\u200D\\u0D4D\\u0D30\\u200B",';//pra
var roman = '"~":"ങ","`":"ജ","1":"ഡ","2":"ട","3":"ഖ","4":"ധ","5":"ഛ","6":"ഭ","7":"ഥ","8":"ഘ","9":"ഠ","0":"ഢ","=":"ഫ",'
			+
			'"q":"ഷ","w":"ക","r":"വ","t":"ര","y":"ത","u":"യ","i":"ല","{":"ഝ",'
			+
			'"s":"സ","d":"ദ","f":"ന","g":"ണ","h":"മ","j":"ഗ",'
			+
			'"z":"ഹ","x":"റ","c":"ഞ","v":"ച","b":"ബ","n":"പ",">":"ഴ",".":"ള","/":"ശ",';
var chill = '"G":"\\u0D23\\u0D4D\\u200D","F":"\\u0D28\\u0D4D\\u200D","X":"\\u0D30\\u0D4D\\u200D","I":"\\u0D32\\u0D4D\\u200D","Z":"\\u0D33\\u0D4D\\u200D",';
var swaram = '"a":"അ","E":"ആ","O":"ഇ","ഇL":"ഈ","P":"ഉ","ഉL":"ഊ",'
				+ 
				"'\"':'ഋ'," //escape character "
				+ 
				'"m":"എ","k":"ഏ",";":"ഐ","[":"ഒ","V":"ഓ","C":"ഔ",":":"ഃ","A":"ഃ","J":"ം",';
var numerals = '"!": "1","@": "2","#": "3","$": "4","%": "5","^": "6","&": "7","*": "8","(": "9",")": "0",';
var conjuncts = '"ന്‍t":"ന്റ്","ന്റ്h":"ന്ത്","ന്‍k":"ങ്ക്","ന്‍n":"ന്ന്","ണ്‍N":"ണ്ണ്","ള്‍L":"ള്ള്","ല്‍l":"ല്ല്","ംm":"മ്മ്","ന്‍m":"ന്മ്","ന്ന്g":"ങ്ങ്","ന്‍d":"ന്ദ്","ണ്‍m":"ണ്മ്","ല്‍p":"ല്പ്","ംp":"മ്പ്","റ്റ്t":"ട്ട്","ന്‍T":"ണ്ട്","ണ്‍T":"ണ്ട്","്ര്^":"ൃ","ന്‍c":"ന്‍\\u200D","ന്‍\\u200Dh":"ഞ്ച്","ണ്‍D":"ണ്ഡ്",';
var others = '"-":"-","_":"(","+":")","|":"/",   "W":":","Y":";","p":"",    "S":"\\u2018","D":"\\u2019","K":",","\\u0027":"!",'
				+
				'"B":"=","N":"%","M":"?","<":".",",":"്",';
var caps = '"ക്w":"ക്ക","ങ്~":"ങ്ങ","ങ്w":"ങ്ക","ഞ്c":"ഞ്ഞ","ഞ്v":"ഞ്ച","ട്2":"ട്ട","ണ്g":"ണ്ണ",'
				+
			'"ണ്2":"ണ്ട","ത്y":"ത്ത","ന്f":"ന്ന","ന്y":"ന്ത","പ്n":"പ്പ","മ്h":"മ്മ","മ്n":"മ്പ","ഗ്j":"ഗ്ഗ",'
				+
			'"സ്s":"സ്സ","ള്.":"ള്ള",'
				+
	'"ന്x":"ന്റ","ക്q":"ക്ഷ","ദ്d":"ദ്ദ","ദ്4":"ദ്ധ","ത്7":"ത്ഥ","ണ്1":"ണ്ഡ",     "ഗ്f":"ഗ്ന","ണ്h":"ണ്മ","ത്6":"ത്ഭ","ത്s":"ത്സ","ന്7":"ന്ഥ","ന്4":"ന്ധ",'
				+
			'"ഗ്h":"ഗ്മ","ത്h":"ത്മ","ന്d":"ന്ദ",'
				+
			'"റ്x":"റ്റ","ത്f":"ത്ന","ന്h":"ന്മ","മ്.":"മ്ല",'
				+
			'"ക്.":"ക്ല","ഗ്.":"ഗ്ല","ച്v":"ച്ച","പ്.":"പ്ല","ബ്b":"ബ്ബ","ഹ്.":"ഹ്ല","ബ്.":"ബ്ല","യ്u":"യ്യ","ല്i":"ല്ല","ശ്.":"ശ്ല","സ്.":"സ്ല",'
				+
			'"വ്r":"വ്വ","ഹ്f":"ഹ്ന","ശ്/":"ശ്ശ","Q":"ക്ഷ",';
//var ZWNJ = '"_":"\\u200C"';
var specialCases='"ഋL":"ഋ\\u200Dൗ",';//added by luap
var ZWNJ = '"":""';
var conversionHash = undefined;
var translitHash = undefined;
var maxcyrlength = 0;
var stateHash = new Array();

function getConversionHash() {
	if (conversionHash == undefined) {
		// TODO
		//var opr = "{" + vowels + roman + chill + swaram + numerals ;//+ conjuncts + caps + others;
		var opr = "{"+ vowels  +  roman + chill +  swaram + numerals /*;+ conjuncts */+ caps + others + specialCases;
		for (var consonant in consonants) {
			//These coding is needed as we have to interchange the order for correct display.
			//===================================
			opr += '"\\u200B\\u200D\\u0D4D\\u0D30\\u200B'  + consonant + '":"' + consonants[consonant] + '\\u0D4D\\u0D30",';//sra
			//===================================
			opr += '"\\u200Bെ\\u200B' + consonant + '":"' + consonants[consonant] + 'െ",';
			opr += '"\\u200Bേ\\u200B' + consonant + '":"' + consonants[consonant] + 'േ",';
			opr += '"\\u200Bൈ\\u200B' + consonant+ '":"' + consonants[consonant] + 'ൈ",';
			//=====>automatcally takes for ko and kro,kyo,kvo etc(as kro's last is ra along with k)
			opr += '"' + consonants[consonant] + 'െ'+ 'e' + '":"' + consonants[consonant] + 'ൊ",';
			opr += '"' + consonants[consonant] + 'േ'+ 'e' + '":"' + consonants[consonant] + 'ോ",';
			opr += '"' + consonants[consonant] + 'െ'+ 'L' + '":"' + consonants[consonant] + 'ൌ",';
			//===================================
			//for kr
			opr += '"\\u200Bെ\\u200B' + '\\u200B\\u200D\\u0D4D\\u0D30\\u200B' + consonant 
					+ '":"' +
					consonants[consonant] + '\\u0D4D\\u0D30' + 'െ",';//kra
			opr += '"\\u200Bേ\\u200B' + '\\u200B\\u200D\\u0D4D\\u0D30\\u200B' + consonant 
					+ '":"' +
					consonants[consonant] + '\\u0D4D\\u0D30' + 'േ",';//kre
			opr += '"\\u200Bൈ\\u200B' + '\\u200B\\u200D\\u0D4D\\u0D30\\u200B' + consonant 
					+ '":"' +
					consonants[consonant] + '\\u0D4D\\u0D30' + 'ൈ",';//kri
			//code written at =====> not needed as same code handles kro(as kro's last is ra along with k)
			//===================================
			//for ky
			opr += '"' + consonants[consonant] + 'െ' + 'U'	+ '":"' + consonants[consonant] + '്യ' + 'െ",';//kya
			opr += '"' + consonants[consonant] + 'േ' + 'U'	+ '":"' + consonants[consonant] + '്യ' + 'േ",';//kye
			opr += '"' + consonants[consonant] + 'ൈ' + 'U'	+ '":"' + consonants[consonant] + '്യ' + 'ൈ",';//kyi
			//code written at =====> not needed as same code handles kyo(as kyo's last is ya along with k)
			//===================================
			//for kv
			opr += '"' + consonants[consonant] + 'െ' + 'R'	+ '":"' + consonants[consonant] + '്വ' + 'െ",';//kva
			opr += '"' + consonants[consonant] + 'േ' + 'R'	+ '":"' + consonants[consonant] + '്വ' + 'േ",';//kve
			opr += '"' + consonants[consonant] + 'ൈ' + 'R'	+ '":"' + consonants[consonant] + '്വ' + 'ൈ",';//kvi
			//code written at =====> not needed as same code handles kvo(as kvo's last is va along with k)
			//===================================
			//when kr,'U','R' comes together it is handled automatically
			//===================================
			//===================================
		}
		for (var capsVal in capsArray) {// kuuttasharam
			//These coding is needed as we have to interchange the order for correct display.
			//===================================
			opr += '"\\u200B\\u200D\\u0D4D\\u0D30\\u200B'  + capsVal + '":"' + capsArray[capsVal] + '\\u0D4D\\u0D30",';//kkra
			//===================================
			opr += '"\\u200Bെ\\u200B' + capsVal + '":"' + capsArray[capsVal] + 'െ",';
			opr += '"\\u200Bേ\\u200B' + capsVal + '":"' + capsArray[capsVal] + 'േ",';
			opr += '"\\u200Bൈ\\u200B' + capsVal+ '":"' + capsArray[capsVal] + 'ൈ",';
			//=>=>automatcally takes for kko and kkro(as kkro's last is ra along with kk)forget this comment
			opr += '"' + capsArray[capsVal] + 'െ'+ 'e' + '":"' + capsArray[capsVal] + 'ൊ",';
			opr += '"' + capsArray[capsVal] + 'േ'+ 'e' + '":"' + capsArray[capsVal] + 'ോ",';
			opr += '"' + capsArray[capsVal] + 'െ'+ 'L' + '":"' + capsArray[capsVal] + 'ൌ",';
			//===================================
			//when kr,'U','R' comes together it is handled automatically
			//===================================
		}
		for (var capsVal in capsArray) // for kuuttasharam with other parts
			 {		
			 //when we are in the process of creating kuuttasharam,when all characters are available we convert to kuutasharam
			 //a etc
			 capsComponents=capsVal.split('്');//capsComponents[0]==>'ക'capsComponents[0]==>'w'
			opr += '"' + capsComponents[0] + 'െ' + '്' + capsComponents[1] + '":"' + 
					 capsComponents[0] + '്' + consonants[capsComponents[1]] + 'െ",';
			opr += '"' + capsComponents[0] + 'േ' + '്' + capsComponents[1] + '":"' + 
					 capsComponents[0] + '്' + consonants[capsComponents[1]] + 'േ",';
			opr += '"' + capsComponents[0] + 'ൈ' + '്' + capsComponents[1] + '":"' + 
					 capsComponents[0] + '്' + consonants[capsComponents[1]] + 'ൈ",';
			//=================================== ra alone 
			opr += '"' + capsComponents[0] + '\\u0D4D\\u0D30' + '്' + capsComponents[1] +  '":"' + 
					 capsComponents[0] + '്' + consonants[capsComponents[1]] + '\\u0D4D\\u0D30' + '",';
			//===================================ra and a etc
			opr += '"' + capsComponents[0] + '\\u0D4D\\u0D30' + 'െ' + '്' + capsComponents[1] + 
					'":"' + capsComponents[0] + '്' + consonants[capsComponents[1]] + '\\u0D4D\\u0D30' + 'െ",';
			opr += '"' + capsComponents[0] + '\\u0D4D\\u0D30' + 'േ' + '്' + capsComponents[1] + 
					'":"' + capsComponents[0] + '്' + consonants[capsComponents[1]] + '\\u0D4D\\u0D30' + 'േ",';
			opr += '"' + capsComponents[0] + '\\u0D4D\\u0D30' + 'ൈ' + '്' + capsComponents[1] + 
					'":"' + capsComponents[0] + '്' + consonants[capsComponents[1]] + '\\u0D4D\\u0D30' + 'ൈ",';
			 }
		opr += ZWNJ + "}";
		// var tb = document.getElementById('txtBox');
		// tb.value = opr;
		conversionHash = eval("("+opr+")");
		//maxcyrlength=6;
		maxcyrlength=20;
	}

	return conversionHash;
}

function to_cyrillic(src, output, chunks) {
	if (src == undefined || src == "" || src == null)
		return src;
		//alert(src);
		//alert("Position="+src.lastIndexOf('1'));
		//alert("Length="+src.length);
		//added by luap
		//to retain numerals and other non malayalam characters as such.
		//logic is we convert the numerals back to its original characters.example '1' ==>'!' etc
		//so that it is again converted to '1'.We exclude the last character as ,if it is '1' it has to be converted to malayalam
		//numerals and others array are converted back
			 srcTemp=src;
			 srcFinal='';
		for(iSrc=0;iSrc<src.length-1;++iSrc)//'-1' to exclude last character
		 {
			  valFound=false;
			  singleCharacter=srcTemp.substring(0,1);
			  srcTemp=srcTemp.substring(1);
		for (var numeralsVal in numeralsArray) 
			{
			  if(singleCharacter==numeralsArray[numeralsVal])
			   {
			   srcFinal=srcFinal+numeralsVal;
			   valFound=true;
			   break;
			   }
			}
		if(!valFound)/**/
			for (var othersVal in othersArray) 
				{
				  if(singleCharacter==othersArray[othersVal])
				   {
			// alert(singleCharacter);
				   srcFinal=srcFinal+othersVal;
				   valFound=true;
				   break;
				   }
				}
		if(!valFound)
			  srcFinal=srcFinal+singleCharacter;//if some other caharacter.
		 }
		 //alert(srcFinal);
		if(srcFinal!='')//if more than one character was checked
			 src=srcFinal+src.substring(src.length-1);//this character is the typed one
		 //alert(src.substring(src.length-1));
		 //alert(src);
		//added by luap
	if (output == undefined)
		output = new String();

	var hash = getConversionHash();
	
	var location = 0;
//		while (location < src.length && src[location]!='\\u200C') {
while (location < src.length) {
		var len = Math.min(maxcyrlength, src.length - location);
		var arr = undefined;
		var sub;
		while (len > 0) {
			sub = src.substr(location, len);
			arr = hash[sub];
			if (arr != undefined) 
				break;
			else 
				len--;
		}
		
		// need this for translit on the fly
		if (chunks != undefined)
			chunks[chunks.length] = sub;
			
		if (arr == undefined) {
			output += sub;
			location ++;
		}
		else {

			// case analysis
			var newChar = arr;
			
			if (sub.toLowerCase() == sub.toUpperCase() && arr.length > 1 && arr[1] && (newChar.toUpperCase() != newChar.toLowerCase())) {
			
				// need translit hash to determine if previous character (and possibly the one before it) 
				// were converted and are in upper case
				
				// set prevDud to true previous is not a translated character or simply a blank
				// set prevCap to true if previous was translated and was upper case

				var prevCh = output.length == 0 ? null : output.substr(output.length - 1, 1);
				var prevDud = !prevCh || !getTranslitString(prevCh);
				var prevCap = (!prevDud && prevCh == prevCh.toUpperCase());

				// sub is caseless but result isn't. case will depend on lookbehind and lookahead
				if (prevDud || !prevCap) {
					output += newChar.toLowerCase();
					prevCap = false;
				}
				else {
					var next = " ";
					if (location + len < src.length)
						next = src.substr(location + len, 1);

					if (next != next.toUpperCase() && next == next.toLowerCase() ) {
						//next is lowercase (and not caseless)
						output += newChar.toLowerCase();
					}
					else if (next == next.toUpperCase() && next != next.toLowerCase() ) {
						// next is uppercase (and not caseless)
						output += newChar.toUpperCase();
					}
					else {
						// next is caseless. output case determined by the case of output[length - 2]
						var pprevCh = output.length == 1 ? null : output.substr(output.length - 2, 1);
						var pprevDud = !pprevCh || !getTranslitString(pprevCh);
						if (!pprevDud && (pprevCh == pprevCh.toUpperCase())) {
							//pre-prev is in upper case. output is also uppercase
							output += newChar.toUpperCase();
						}
						else {
							output += newChar.toLowerCase();
						}
						
					}
				}
					
			}
			else if ((sub.toLowerCase() == sub.toUpperCase()) && (arr.length < 2 || !arr[1])) {
				
				// literal treatment of newChar
				output += newChar;

			}
			else if (sub != sub.toLowerCase()) {
			
				// sub not all-lowercase
				output += newChar.toUpperCase();
			}
			else {
					
					
					
				// sub is lowercase
				output += newChar.toLowerCase();
			}
			location += len;
		}
	}
		//alert(output);

	return output;
}


function convertIt(src,converter){
 var resultbuffer=""; 
	for(var i=0;i<src.length;i++){
	resultbuffer=converter(resultbuffer+src[i]);
	}
		return converter(resultbuffer);

}

function initTranslit() {
	if (translitHash == undefined) {
		translitHash = new Array();

		for (var i = 0; i < conversionHash.length; i++) {
			var ch = conversionHash[i][1];
			// if the translit string is not caseless, convert cyr string to upper case
			// otherwise maintain its case
			if (conversionHash[i][0].toUpperCase() != conversionHash[i][0].toLowerCase())
				ch = ch.toUpperCase();
				
			if (translitHash[ch] == undefined)
				translitHash[ch] = conversionHash[i][0];
		}
	}
}

//-- translit on-the-fly -- 

function replaceValue(node, value, stepback) {
	if (stepback == undefined)
		stepback = 0;
		
	if (isExplorer()) {
		var range = document.selection.createRange();
		range.moveStart("character", -stepback);
		range.text = value;
		range.collapse(false);
		range.select();
	}
	else {
		var scrollTop = node.scrollTop;
		var cursorLoc =  node.selectionStart;
		node.value = node.value.substring(0, node.selectionStart - stepback) + value + 
				node.value.substring(node.selectionEnd, node.value.length);
		node.scrollTop = scrollTop;
		node.selectionStart = cursorLoc + value.length - stepback;
		node.selectionEnd = cursorLoc + value.length - stepback;
	}
}

// compare positions
function positionIsEqual(other) {
	if (isExplorer())
		return this.position.isEqual(other.position);
	else
		return this.position == other.position;
  
}

function resetState() {
	this.position = new Position(this.node);
	this.transBuffer = "";
	this.cyrBuffer = "";
}


function transliterateKey(event,txtId) {//OLD VIN commented function transliterateKey(event) {
	if (event == undefined)
		event = window.event;
	
	var node = null;
	if (event.target) {
		node = event.target;
		}
	else if (event.srcElement) {
		node = event.srcElement;
		}
		
		
	// initialize state
	var state = stateHash[node];
	//if (state == null) {//modified below by luap.Initially type 'a'.delete it ,then type 'a'.In IE it comes outside so corrected.
	if (state == null || textBox.value=="") {
		state = new StateObject(node);
		stateHash[node] = state;
	}
	if ( (pressedKey(event) > 20) && !event.ctrlKey && !event.altKey && !event.metaKey) {

		var c = String.fromCharCode(pressedKey(event));
		// process input
		var result = process_translit(state, c);
		//Vin added
		var charCode = pressedKey(event);
		if(txtId == "str_description")
		{
			for(var numC in panArr)
			{
				if(charCode== numC)
				{
					//alert(numC);
					panchariData += panArr[numC];
					break;
				}
			}
		}
		if(txtId == "str_heading")
		{
			for(var numC in panArr)
			{
				if(charCode== numC)
				{
					panchariDataHeading += panArr[numC];
					break;
				}
			}
		}
		//Vin added ends
		// finish up
		if (c != result.out || result.replace != 0) {
		  if (isExplorer())
			event.returnValue = false;
		  else
			event.preventDefault();
		  
		  replaceValue(node, result.out, result.replace);
		  
		  state.position = new Position(node);

		}
	}
	
}

function process_translit(state, c) {
	// reset state if position changed
	if (!state.position.isEqual(new Position(state.node)))
		state.reset();
		
	var result = new TranslitResult();
	
	// initial backbuffer. Add to it as characters are converted
	var backbuffer = getBackBuffer(state.node, state.cyrBuffer.length, 2);
	var chunks = new Array();
	
	state.transBuffer = state.transBuffer+ c

	var str = to_cyrillic(state.cyrBuffer+c, backbuffer, chunks);

	// remove backbuffer from output
	str = str.substr(backbuffer.length);
	result.out = str; 
	//alert(result.out.lastIndexOf("1"));
	//alert(result.out);
	/* str is now left alone - it has the output matching contents of chunks and 
	   will be used to reinitialize backbuffers, along with chunks and state.transBuffer
	*/
	
	// get the difference between state.cyrBuffer and output
	for (var i = 0; i < Math.min(state.cyrBuffer.length, result.out.length); i++) {
		if (state.cyrBuffer.substr(i, 1) != result.out.substr(i, 1)) {
			result.replace = state.cyrBuffer.length - i;
			result.out = result.out.substr(i);
			break;
		}
	}
	if (result.replace == 0) {
			   if(result.out.length<state.cyrBuffer.length)
				result.replace=state.cyrBuffer.length- result.out.length;
		result.out = result.out.substr(Math.min(state.cyrBuffer.length, result.out.length));
				 
					   //    result.out+="\u0008"
						 
	}
	
	// update state: backbuffer, bufferArray
	if (chunks.length > 0 && chunks[chunks.length - 1] == result.out.substr(result.out.length - 1)) {
		// no convertion took place, reset state
		state.reset();
	}
	else {
		while (state.transBuffer.length > maxcyrlength) {
			state.transBuffer = state.transBuffer.substr(chunks[0].length);
			chunks.shift();
			str = str.substr(1);
		}
		state.cyrBuffer = str;
	}
	return result;
}

function getBackBuffer(node, offset, count) {
		
	if (isExplorer()) { //.tagName.toUpperCase() == "EDITOR") {
	
		var range = document.selection.createRange();
		range.moveStart("character", -offset);
		var result = range.text.substr(-count);
		if (!result)
			result = "";
			
		return result;

	} else {
		return node.value.substring(0, node.selectionStart - offset).substr(-count);
	}
}

// need this for bookmarklets
function getSelectedNode() {
  if (document.activeElement)
	return document.activeElement;
  else
	if (window.getSelection && window.getSelection() && window.getSelection().rangeCount > 0) {
		var range = window.getSelection().getRangeAt(0);
		if (range.startContainer && range.startContainer.childNodes && range.startContainer.childNodes.length > range.startOffset)
			return range.startContainer.childNodes[range.startOffset]
	}
  return null;
}
function getSelectedText() {
	if (isExplorer()) {
		return document.selection.createRange().text;
	}
	else {
		var node = getSelectedNode();
		if (node && node.value && node.selectionStart != undefined && node.selectionEnd != undefined)
			return node.value.substring(node.selectionStart, node.selectionEnd);
	}
	return "";
}
/*********************************************************************************************************************************/
//Content of malayalam.js alone.End
/*********************************************************************************************************************************/
/*********************************************************************************************************************************/
//Content of classes.js alone.Start
/*********************************************************************************************************************************/
function Position(node) {
  if (node.selectionStart != undefined)
	this.position = node.selectionStart;
  else if (document.selection && document.selection.createRange())
	this.position = document.selection.createRange();
	
  this.isEqual = positionIsEqual;
}

function StateObject(node) {
	this.node = node;
	this.reset = resetState;
	this.cyrBuffer = "";
	this.transBuffer = "";
	this.position = new Position(node);
}

function TranslitResult() {
	this.out = "";
	this.replace = 0;
}

/*********************************************************************************************************************************/
//Content of classes.js alone.End
/*********************************************************************************************************************************/
/*********************************************************************************************************************************/
//Content of utils.js alone.Start
/*********************************************************************************************************************************/
function pressedKey(event) {
  if (isExplorer())
	return event.keyCode;
  else
	return event.which;
}

function isExplorer() {
  return (document.selection != undefined && document.selection.createRange().isEqual != undefined);
}

/*********************************************************************************************************************************/
//Content of utils.js alone.End
/*********************************************************************************************************************************/

/*********************************************************************************************************************************/
//Content of UniEdit.html alone.End
/*********************************************************************************************************************************/
var defaultLang = 1;
var sellang = 1;  
var textBox;  
var e; 
var transupport = true;
function processKeys(event,txtId) {
	e = event || window.event;	e.keyValue = e.keyCode || e.which;
	var txtId = (txtId == null) ? "ta_ue" : txtId;// VIN added
	textBox= document.getElementById(txtId); //OLD Vin Commented textBox= document.getElementById('ta_ue');
	/*OLD
	e = event || window.event;	e.keyValue = e.keyCode || e.which;
	textBox= document.getElementById('ta_ue');
	*/
	if (sellang == 1) {
		// OLD VIN commented transliterateKey(event); // call transliteration function
		transliterateKey(event,txtId); // call transliteration function
	}
}
/*********************************************************************************************************************************/
//Content of UniEdit.html alone.End
/*********************************************************************************************************************************/


