/* generated javascript */
var skin = 'monobook';
var stylepath = '/w/skins';

/* MediaWiki:Common.js */
/* Any JavaScript here will be loaded for all users on every page load. */

/* Adding buttons for lipi and sup on the Edit page toolbar. */
var btn_lipi = {
	"imageFile": "images/button_translipi.png", 
	"speedTip": "Marks text for lipi-fication", 
	"tagOpen": "<lipi>",
	"tagClose": "</lipi>",
	"sampleText": ""
};
mwCustomEditButtons.push(btn_lipi);

var btn_sup = {
	"imageFile": "images/button_sup.png", 
	"speedTip": "Superscript", 
	"tagOpen": "<sup>",
	"tagClose": "</sup>",
	"sampleText": ""
};
mwCustomEditButtons.push(btn_sup);

/* 
 * --- transLipi ---
 * This is copyrighted material.
 * (c) Srikanth S.
 * Gmail: srikanthsubram
 */

if(window.attachEvent)
  window.attachEvent('onload', translipi);
else if(window.addEventListener)
  window.addEventListener('load', translipi, false);

var doneonce = false;
var origText = new Array();
var scriptChoice = "en";

var RomanTab = {	
	"M" : "m&#x0323;",
	"H" : "h&#x0323;",
	"a" : "a",
	"A" : "&#x0101;",
	"i" : "i",
	"I" : "&#x012B;",
	"u" : "u",
	"U" : "&#x016B;",
	"R" : "r&#x0323;",
	"RR" : "r&#x0323;&#x0304;",
	"lR" : "l",
	"lRR" : "l",
	"e" : "e",
	"E" : "&#x0113;",
	"ai$" : "ai",
	"o" : "o",
	"O" : "&#x014D;",
	"au" : "au",
	"k" : "k",
	"kh" : "kh",
	"g" : "g",
	"gh" : "gh",
	"G" : "n&#x0307;",
	"c" : "c",
	"ch" : "ch",
	"j" : "j",
	"jh" : "jh",
	"J" : "&#x00F1;",
	"T" : "t&#x0323;",
	"Th" : "t&#x0323;h",
	"D" : "d&#x0323;",
	"Dh" : "d&#x0323;h",
	"N" : "n&#x0323;",
	"t" : "t",
	"th" : "th",
	"d" : "d",
	"dh" : "dh",
	"n" : "n",
	"nN" : "n",
	"p" : "p",
	"ph" : "ph",
	"b" : "b",
	"bh" : "bh",
	"m" : "m",
	"y" : "y",
	"r" : "r",
	"rR" : "r&#x0331;",
	"l" : "l",
	"L" : "l&#x0323;",
	"zh" : "zh",
	"v" : "v",
	"w" : "w",
	"z" : "&#x015B;",
	"S" : "s&#x0323;",
	"s" : "s",
	"h" : "h",	
//	"a$" : "",
	"A$" : "&#x0101;",
	"i$" : "i",
	"I$" : "&#x012B;",
	"u$" : "u",
	"U$" : "&#x016B;",
	"R$" : "r&#x0323;",
	"RR$" : "r&#x0323;&#x0304;",
	"lR$" : "lR",
	//"lRR$" : "lRR",
	"e$" : "e",
	"E$" : "&#x0113;",
	"ai$" : "ai",
	"o$" : "o",
	"O$" : "&#x014D;",
	"au$" : "au",
	"V$" : "&#x0C4D;",
	"f" : "f",
	"Z" : "z"
};


var TeluguTab = {	
	"M" : "&#x0C02;",
	"H" : "&#x0C03;",
	"a" : "&#x0C05;",
	"A" : "&#x0C06;",
	"i" : "&#x0C07;",
	"I" : "&#x0C08;",
	"u" : "&#x0C0C;",
	"U" : "&#x0C0A;",
	"R" : "&#x0C0B;",
	"RR" : "&#x0C60;",
	"lR" : "&#x0C0C;",
	"lRR" : "&#x0C61;",
	"e" : "&#x0C0E;",
	"E" : "&#x0C0F;",
	"ai" : "&#x0C10;",
	"o" : "&#x0C12;",
	"O" : "&#x0C13;",
	"au" : "&#x0C14;",
	"k" : "&#x0C15;",
	"kh" : "&#x0C16;",
	"g" : "&#x0C17;",
	"gh" : "&#x0C18;",
	"G" : "&#x0C19;",
	"c" : "&#x0C1A;",
	"ch" : "&#x0C1B;",
	"j" : "&#x0C1C;",
	"jh" : "&#x0C1D;",
	"J" : "&#x0C1E;",
	"T" : "&#x0C1F;",
	"Th" : "&#x0C20;",
	"D" : "&#x0C21;",
	"Dh" : "&#x0C22;",
	"N" : "&#x0C23;",
	"t" : "&#x0C24;",
	"th" : "&#x0C25;",
	"d" : "&#x0C26;",
	"dh" : "&#x0C27;",
	"n" : "&#x0C28;",
	"nN" : "&#x0C28;",
	"p" : "&#x0C2A;",
	"ph" : "&#x0C2B;",
	"b" : "&#x0C2C;",
	"bh" : "&#x0C2D;",
	"m" : "&#x0C2E;",
	"y" : "&#x0C2F;",
	"r" : "&#x0C30;",
	"rR" : "&#x0C31;",
	"l" : "&#x0C32;",
	"L" : "&#x0C33;",
	"zh" : "&#x0C33;",
	"v" : "&#x0C35;",
	"w" : "&#x0C35;",
	"z" : "&#x0C36;",
	"S" : "&#x0C37;",
	"s" : "&#x0C38;",
	"h" : "&#x0C39;",	
//	"a$" : "",
	"A$" : "&#x0C3E;",
	"i$" : "&#x0C3F;",
	"I$" : "&#x0C40;",
	"u$" : "&#x0C41;",
	"U$" : "&#x0C42;",
	"R$" : "&#x0C43;",
	"RR$" : "&#x0C44;",
	"lR$" : "&#x0C62;",
	//"lRR$" : "&#x0C63;",
	"e$" : "&#x0C46;",
	"E$" : "&#x0C47;",	
	"ai$" : "&#x0C48;",
	"o$" : "&#x0C4A;",
	"O$" : "&#x0C4B;",	
	"au$" : "&#x0C4C;",	
	"V$" : "&#x0C4D;",
	"f" : "&#x0C2B;",
	"Z" : "&#x0C1C;"	
};


var TamilTab = {	
	"M" : "&#x0BAE;&#x0BCD;",
	"H" : ":",
	"a" : "&#x0B85;",
	"A" : "&#x0B86;",
	"i" : "&#x0B87;",
	"I" : "&#x0B88;",
	"u" : "&#x0B89;",
	"U" : "&#x0B8A;",
	"R" : "&#x0BB0;&#x0BC1;",
	"RR" : "&#x0BB0;&#x0BC2;",
	"lR" : "&#x0BB2;&#x0BC1;",
	"lRR" : "&#x0BB2;&#x0BC2;",
	"e" : "&#x0B8E;",
	"E" : "&#x0B8F;",
	"ai" : "&#x0B90;",
	"o" : "&#x0B92;",
	"O" : "&#x0B93;",
	"au" : "&#x0B94;",
	"k" : "&#x0B95;",
	"kh" : "&#x0B95;",
	"g" : "&#x0B95;",
	"gh" : "&#x0B95;",
	"G" : "&#x0B99;",
	"c" : "&#x0B9A;",
	"ch" : "&#x0B9A;",
	"j" : "&#x0B9C;",
	"jh" : "&#x0B9C;",
	"J" : "&#x0B9E;",
	"T" : "&#x0B9F;",
	"Th" : "&#x0B9F;",
	"D" : "&#x0B9F;",
	"Dh" : "&#x0B9F;",
	"N" : "&#x0BA3;",
	"t" : "&#x0BA4;",
	"th" : "&#x0BA4;",
	"d" : "&#x0BA4;",
	"dh" : "&#x0BA4;",
	"n" : "&#x0BA8;",
	"nN" : "&#x0BA9;",
	"p" : "&#x0BAA;",
	"ph" : "&#x0BAA;",
	"b" : "&#x0BAA;",
	"bh" : "&#x0BAA;",
	"m" : "&#x0BAE;",
	"y" : "&#x0BAF;",
	"r" : "&#x0BB0;",
	"rR" : "&#x0BB1;",
	"l" : "&#x0BB2;",
	"L" : "&#x0BB3;",
	"zh" : "&#x0BB4;",
	"v" : "&#x0BB5;",
	"w" : "&#x0BB5;",
	"z" : "&#x0B9A;",
	"S" : "&#x0BB7;",
	"s" : "&#x0BB8;",
	"h" : "&#x0BB9;",	
	"A$" : "&#x0BBE;",
	"i$" : "&#x0BBF;",
	"I$" : "&#x0BC0;",
	"u$" : "&#x0BC1;",
	"U$" : "&#x0BC2;",
	"R$" : "&#x0BCD;&#x0BB0;&#x0BC1;",
	"RR$" : "&#x0BCD;&#x0BB0;&#x0BC2;",
	"lR$" : "&#x0BCD;&#x0BB2;&#x0BC1;",
	//"lRR$" : "&#x0BC4;",
	"e$" : "&#x0BC6;",
	"E$" : "&#x0BC7;",	
	"ai$" : "&#x0BC8;",
	"o$" : "&#x0BCA;",
	"O$" : "&#x0BCB;",	
	"au$" : "&#x0BCC;",	
	"V$" : "&#x0BCD;",
	"f" : "&#x0B83;&#x0BAA;",
	"Z" : "&#x0B9C;",
	"zrI" : "&#x0BB8;&#x0BCD;&#x0BB0;&#x0BC0;"
};


var DevanagariTab = {	
	"M" : "&#x0902;",
	"H" : "&#x0903;",
	"a" : "&#x0905;",
	"A" : "&#x0906;",
	"i" : "&#x0907;",
	"I" : "&#x0908;",
	"u" : "&#x0909;",
	"U" : "&#x090A;",
	"R" : "&#x090B;",
	"RR" : "&#x0960;",
	"lR" : "&#x090C;",
	"lRR" : "&#x0961;",
	"e" : "&#x090E;",
	"E" : "&#x090F;",
	"ai" : "&#x0910;",
	"o" : "&#x0912;",
	"O" : "&#x0913;",
	"au" : "&#x0914;",
	"k" : "&#x0915;",
	"kh" : "&#x0916;",
	"g" : "&#x0917;",
	"gh" : "&#x0918;",
	"G" : "&#x0919;",
	"c" : "&#x091A;",
	"ch" : "&#x091B;",
	"j" : "&#x091C;",
	"jh" : "&#x091D;",
	"J" : "&#x091E;",
	"T" : "&#x091F;",
	"Th" : "&#x0920;",
	"D" : "&#x0921;",
	"Dh" : "&#x0922;",
	"N" : "&#x0923;",
	"t" : "&#x0924;",
	"th" : "&#x0925;",
	"d" : "&#x0926;",
	"dh" : "&#x0927;",
	"n" : "&#x0928;",
	"nN" : "&#x0928;",
	"p" : "&#x092A;",
	"ph" : "&#x092B;",
	"b" : "&#x092C;",
	"bh" : "&#x092D;",
	"m" : "&#x092E;",
	"y" : "&#x092F;",
	"r" : "&#x0930;",
	"rR" : "&#x0931;",
	"l" : "&#x0932;",
	"L" : "&#x0933;",
	"zh" : "&#x0934;",
	"v" : "&#x0935;",
	"w" : "&#x0935;",
	"z" : "&#x0936;",
	"S" : "&#x0937;",
	"s" : "&#x0938;",
	"h" : "&#x0939;",
	"'" : "&#x093D;",	
	"A$" : "&#x093E;",
	"i$" : "&#x093F;",
	"I$" : "&#x0940;",
	"u$" : "&#x0941;",
	"U$" : "&#x0942;",
	"R$" : "&#x0943;",
	"RR$" : "&#x0944;",
	"lR$" : "&#x0962;",
	//"lRR$" : "&#x0963;",
	"e$" : "&#x0946;",
	"E$" : "&#x0947;",	
	"ai$" : "&#x0948;",
	"o$" : "&#x094A;",
	"O$" : "&#x094B;",	
	"au$" : "&#x094C;",	
	"V$" : "&#x094D;",
	"f" : "&#x095E;",
	"Z" : "&#x095B;",
	"|" : "&#x0964;",
	"||" : "&#x0965;"
};


var KannadaTab = {	
	"M" : "&#x0C82;",
	"H" : "&#x0C83;",
	"a" : "&#x0C85;",
	"A" : "&#x0C86;",
	"i" : "&#x0C87;",
	"I" : "&#x0C88;",
	"u" : "&#x0C89;",
	"U" : "&#x0C8A;",
	"R" : "&#x0C8B;",
	"RR" : "&#x0CE0;",
	"lR" : "&#x0C8C;",
	"lRR" : "&#x0CE1;",
	"e" : "&#x0C8E;",
	"E" : "&#x0C8F;",
	"ai" : "&#x0C90;",
	"o" : "&#x0C92;",
	"O" : "&#x0C93;",
	"au" : "&#x0C94;",
	"k" : "&#x0C95;",
	"kh" : "&#x0C96;",
	"g" : "&#x0C97;",
	"gh" : "&#x0C98;",
	"G" : "&#x0C99;",
	"c" : "&#x0C9A;",
	"ch" : "&#x0C9B;",
	"j" : "&#x0C9C;",
	"jh" : "&#x0C9D;",
	"J" : "&#x0C9E;",
	"T" : "&#x0C9F;",
	"Th" : "&#x0CA0;",
	"D" : "&#x0CA1;",
	"Dh" : "&#x0CA2;",
	"N" : "&#x0CA3;",
	"t" : "&#x0CA4;",
	"th" : "&#x0CA5;",
	"d" : "&#x0CA6;",
	"dh" : "&#x0CA7;",
	"n" : "&#x0CA8;",
	"nN" : "&#x0CA8;",
	"p" : "&#x0CAA;",
	"ph" : "&#x0CAB;",
	"b" : "&#x0CAC;",
	"bh" : "&#x0CAD;",
	"m" : "&#x0CAE;",
	"y" : "&#x0CAF;",
	"r" : "&#x0CB0;",
	"rR" : "&#x0CB1;",
	"l" : "&#x0CB2;",
	"L" : "&#x0CB3;",
	"zh" : "&#x0CB3;",
	"v" : "&#x0CB5;",
	"w" : "&#x0CB5;",
	"z" : "&#x0CB6;",
	"S" : "&#x0CB7;",
	"s" : "&#x0CB8;",
	"h" : "&#x0CB9;",
	"A$" : "&#x0CBE;",
	"i$" : "&#x0CBF;",
	"I$" : "&#x0CC0;",
	"u$" : "&#x0CC1;",
	"U$" : "&#x0CC2;",
	"R$" : "&#x0CC3;",
	"RR$" : "&#x0CC4;",
	"lR$" : "&#x0CC4;",
	//"lRR$" : "&#x0CC4;",
	"e$" : "&#x0CC6;",
	"E$" : "&#x0CC7;",	
	"ai$" : "&#x0CC8;",
	"o$" : "&#x0CCA;",
	"O$" : "&#x0CCB;",	
	"au$" : "&#x0CCC;",	
	"V$" : "&#x0CCD;",
	"Z" : "&#x0C9C;",
	"f" : "&#x0CDE;"
};


var MalayalamTab = {	
	"M" : "&#x0D02;",
	"H" : "&#x0D03;",
	"a" : "&#x0D05;",
	"A" : "&#x0D06;",
	"i" : "&#x0D07;",
	"I" : "&#x0D08;",
	"u" : "&#x0D09;",
	"U" : "&#x0D0A;",
	"R" : "&#x0D0B;",
	"RR" : "&#x0D60;",
	"lR" : "&#x0D0C;",
	"lRR" : "&#x0D61;",
	"e" : "&#x0D0E;",
	"E" : "&#x0D0F;",
	"ai" : "&#x0D10;",
	"o" : "&#x0D12;",
	"O" : "&#x0D13;",
	"au" : "&#x0D14;",
	"k" : "&#x0D15;",
	"kh" : "&#x0D16;",
	"g" : "&#x0D17;",
	"gh" : "&#x0D18;",
	"G" : "&#x0D19;",
	"c" : "&#x0D1A;",
	"ch" : "&#x0D1B;",
	"j" : "&#x0D1C;",
	"jh" : "&#x0D1D;",
	"J" : "&#x0D1E;",
	"T" : "&#x0D1F;",
	"Th" : "&#x0D20;",
	"D" : "&#x0D21;",
	"Dh" : "&#x0D22;",
	"N" : "&#x0D23;",
	"t" : "&#x0D24;",
	"th" : "&#x0D25;",
	"d" : "&#x0D26;",
	"dh" : "&#x0D27;",
	"n" : "&#x0D28;",
	"nN" : "&#x0D28;",
	"p" : "&#x0D2A;",
	"ph" : "&#x0D2B;",
	"b" : "&#x0D2C;",
	"bh" : "&#x0D2D;",
	"m" : "&#x0D2E;",
	"y" : "&#x0D2F;",
	"r" : "&#x0D30;",
	"rR" : "&#x0D31;",
	"l" : "&#x0D32;",
	"L" : "&#x0D33;",
	"zh" : "&#x0D34;",
	"v" : "&#x0D35;",
	"w" : "&#x0D35;",
	"z" : "&#x0D36;",
	"S" : "&#x0D37;",
	"s" : "&#x0D38;",
	"h" : "&#x0D39;",
	"'" : "&#x02BC;",	
	"A$" : "&#x0D3E;",
	"i$" : "&#x0D3F;",
	"I$" : "&#x0D40;",
	"u$" : "&#x0D41;",
	"U$" : "&#x0D42;",
	"R$" : "&#x0D43;",
	"RR$" : "&#x0D43;",
	"lR$" : "&#x0D43;",
	//"lRR$" : "&#x0D44;",
	"e$" : "&#x0D46;",
	"E$" : "&#x0D47;",	
	"ai$" : "&#x0D48;",
	"o$" : "&#x0D4A;",
	"O$" : "&#x0D4B;",	
	"au$" : "&#x0D4C;",	
	"V$" : "&#x0D4D;",
	"Z" : "&#x0D1C;",
	"f" : "&#x0D2B;"	
};


var Tables = {
	"sa" : DevanagariTab,
	"en" : RomanTab,
	"kn" : KannadaTab,
	"ml" : MalayalamTab,
	"ta" : TamilTab,
	"te" : TeluguTab
};
	// Removes leading whitespaces
	function LTrim( value ) {
		var re = /\s*((\S+\s*)*)/;
		return value.replace(re, "$1");
	}
	
	// Removes ending whitespaces
	function RTrim( value ) {	
		var re = /((\s*\S+)*)\s*/;
		return value.replace(re, "$1");	
	}
	
	// Removes leading and ending whitespaces
	function trim( value ) {	
		return LTrim(RTrim(value));	
	}

	/* Cross-Browser Split v0.1; MIT-style license By Steven Levithan <http://stevenlevithan.com> An ECMA-compliant, uniform cross-browser split method */ 
	String.prototype.split = function(separator, limit) { 
		var flags = ""; /* Behavior for separator: If it's... - Undefined: Return an array containing one element consisting of the entire string - A regexp or string: Use it - Anything else: Convert it to a string, then use it */  
		if (separator === undefined) { 
			return [this.toString()]; // toString is used because the typeof this is object  
		} else if (separator === null || separator.constructor !== RegExp) { 
		// Convert to a regex with escaped metacharacters  
			separator = new RegExp(String(separator).replace(/[.*+?^${}()|[\]\/\\]/g, "\\$&"), "g"); 
		} else { 
			flags = separator.toString().replace(/^[\S\s]+\//, ""); 
			if (!separator.global) { 
				separator = new RegExp(separator.source, "g" + flags); 
			} 
		} // Used for the IE non-participating capturing group fix  
		var separator2 = new RegExp("^" + separator.source + "$", flags); 
		/* Behavior for limit: If it's... - Undefined: No limit - 
		Zero: Return an empty array - 
		A positive number: Use limit after dropping any decimal value (if it's then zero, return an empty array) - 
		A negative number: No limit, same as if limit is undefined - 
		A type/value which can be converted to a number: Convert, then use the above rules - 
		A type/value which cannot be converted to a number: Return an empty array */  
		if (limit === undefined || +limit < 0) { limit = false; } 
		else { limit = Math.floor(+limit); 
			if (!limit) return []; // NaN and 0 (the values which will trigger the condition here) are both falsy  
		} 
		var match, output = [], lastLastIndex = 0, i = 0; 
		while ((limit ? i++ <= limit : true) && (match = separator.exec(this))) { 
		// Fix IE's infinite-loop-resistant but incorrect RegExp.lastIndex  
			if ((match[0].length === 0) && (separator.lastIndex > match.index)) { 
				separator.lastIndex--; 
			} 
			if (separator.lastIndex > lastLastIndex) { 
			/* Fix IE to return undefined for non-participating capturing groups (NPCGs). 
			Although IE incorrectly uses empty strings for NPCGs with the exec method, it uses undefined for NPCGs with the replace method. 
			Conversely, Firefox incorrectly uses empty strings for NPCGs with the replace and split methods, but uses undefined with the exec method. Crazy! */  
				if (match.length > 1) { 
					match[0].replace(separator2, function() { 
						for (var j = 1; j < arguments.length - 2; j++){ 
							if (arguments[j] === undefined) match[j] = undefined; 
						}}
						); 
				} 
				output = output.concat(this.substring(lastLastIndex, match.index), (match.index === this.length ? [] : match.slice(1))); lastLastIndex = separator.lastIndex; 
			} 
			if (match[0].length === 0) { 
				separator.lastIndex++; 
			} 
		} 
		return (lastLastIndex === this.length) ? (separator.test("") ? output : output.concat("")) : (limit ? output : output.concat(this.substring(lastLastIndex))); 
	};

		function transliterate(input, lang, option)
		{
			var resTags = /(<[^<]+>)/;
			var output="";
			var strings = input.split(resTags);
			for (var x=0; x < strings.length; x++) {
				if(strings[x].match(resTags)) {
					output += strings[x];			
				}					
				else {
					//alert("Input = _"+strings[x]+"_");
					var curOutput = performTransliteration(strings[x], lang, option);		
					if(curOutput != null) output+=curOutput;			
				}
			}      
			//alert("Complete Output"+output);
			return output;			
		}
		function performTransliteration(input, lang, option) {	
			var i=0,j=1;
			var output="", current="", previous="";

			if(lang == "ta") {
				var reAlveolarN = /\Bn(?=[^tdN])/gm
				//var reAlveolarN = /\Bn(?=[aAiIuUReEoO]\b)|\Bn\b/gm			
				input = input.replace(reAlveolarN, "nN");
				var reAlveolarN2 = /\Bn(?=nN)/gm
				input = input.replace(reAlveolarN2, "nN");
				var reNasalG = /\BM(?=[kg])/gm
				input = input.replace(reNasalG, "G");	
				var reNasalJ = /\BM(?=[cj])/gm
				input = input.replace(reNasalJ, "J");
				var reNasaln = /\BM(?=[td])/gm
				input = input.replace(reNasaln, "n");	
				//alert("Alveolar N: "+input);

				/* Tamil subscripts */
				var reSoft = /([gDdb][aAiIuUeEoO][iu]*)/gm
				input = input.replace(reSoft, "$1<sub>3</sub>");	
				var reSoft2 = /([gDdb])(?=[\s])/gm
				input = input.replace(reSoft2, "$1<sub>3</sub>");
				var reSoft3 = /([gDdb])$/gm
				input = input.replace(reSoft3, "$1<sub>3</sub>");
				var reSoft4 = /([gDdb])(?=[kgGcjJTDNtdnpbmyrlvwzSsR])/gm
				input = input.replace(reSoft4, "$1<sub>3</sub>");
				
				var reSoftAsp = /([gDdb]h[aAiIuUeEoO]*[iu]*)/gm
				input = input.replace(reSoftAsp, "$1<sub>4</sub>");	
				
				var reHardAsp = /([kcTtp]h[aAiIuUeEoO]*[iu]*)/gm
				input = input.replace(reHardAsp, "$1<sub>2</sub>");		
			}
			else if(option != "strict" && (lang == "kn" || lang == "te")) {	
				var reNasals = /(\BG(?=[^GJNnmaAiIuUReEoO]\B))|(\BJ(?=[^GJNnmaAiIuUReEoO]\B))|(\BN(?=[^GJNnmaAiIuUReEoO]\B))|(\Bn(?=[^nmNyraAiIuUReEoO]\B))|\Bm(?=[^nmyraAiIuUReEoO])|\Bm\b/gm							
				input = input.replace(reNasals, "M");				
			}
			else if(option != "strict" && lang == "ml") {
				var endM = /\Bm\b/gm
				input = input.replace(endM, "M");
			}
			else if(option != "strict" && lang == "sa") {
				var reNasalG = /\BG(?=[^aAiIuUReEoO])\B/gm
				input = input.replace(reNasalG, "M");	
			}

			//input = trim(input);
			var inputlen = input.length;
			var tab = Tables[lang];
//			alert("\nLength of input '"+input+"' = "+input.length);
			do
			{
				current="";
				//1. Parse and tokenise: Find the biggest substring found in the hash table
				if((i+3) >= input.length) j = input.length - i;
				else j = 3;
				//document.write("Value of j = "+j);
//				alert("Looking for '"+input.substr(i,j)+"'");
				for(;j>0;j--) {
					var substr = input.substr(i,j);
					//document.write(j+" '"+substr+"':"+tab[substr]);
					if(tab[substr]!= undefined) {
						// Check if avagraha or quote.

						if(substr == "'") {

							if((previous == "") || (i+j == input.length)) 

								break;

							if(!isVowel(input[i+1]) && !isConsonant(input[i+1]))

								break;

						}
						current = input.substr(i,j);
						break;
					}
				}
				
				if(current=="") {	//No match.
					j = 1;
					if(input.substr(i,j) == "<") {
						do { j++;
						} while(input.substr(i+j-1,1)!=">" && (i+j) < inputlen);						
					}
					
					//alert("No match for '"+input.substr(i,j)+"'. j = "+j);
				}
				
				//2. Match with syntax and take appropriate action								
				
//				alert("PC: "+previous+current);
				//alert("\nCurrent substring: "+current);
				if(lang == "en") {
					if(current) output += tab[current];
					else output += input.substr(i,j);
				}
				else if(isConsonant(previous) && isVowel(current)) //CV
				{
					//alert("CV: "+previous+current);
					if(current != "a") output += tab[current+"$"]; //Abugida
				}
				else if(isConsonant(previous)) //CC or C*
				{
					//document.write("CC or C*");
					output+=tab["V$"];
					if(current != "") output += tab[current];
					else	output += input.substr(i,j);
				}
				else if(current != "")
					output+= tab[current];
				else
					output += input.substr(i,j);
					
				previous = current; i+=j;
				//alert("i="+i+" j="+j+". Input len ="+input.length+" i+j="+(i+j)+"condition: "+((i+j) <= (inputlen)));
			}
			while((i) < (inputlen));
			if(lang != "en" && isConsonant(previous)) 
				output+=tab["V$"];
			if(lang == "en") output = "<span style='font-family: tahoma'>"+output+"</span>";
			else if(lang == "ml") output = "<span style='font-size: 130%'>"+output+"</span>";
			else if(lang == "te" ) output = "<span style='font-size: 130%'>"+output+"</span>";
			else if(lang == "kn" || lang == "sa") output = "<span style='font-size: 110%'>"+output+"</span>";
						
			//alert("\nThe result is "+output);
			
			return output;
		}
		

	function isConsonant(str)
		{
			var consonants=["k","kh","g","gh","G","c","ch","j","jh","J","T","Th","D","Dh","N", "nN", "t","th","d","dh","n","p","ph","b","bh","m","y","r","rR","l","L","zh","v","w","z","S","s","h","f","Z"];
			if(str=="") return false;
			for(var i=0; i < consonants.length; i++)
			{
				if(str == consonants[i])
					return true;
			}
			return false;
		}

		function isVowel(str)
		{
			var vowels = ["a","A","i","I","u","U","R","RR","lR","lRR","e","E","ai","o","O","au"];
			if(str=="") return false;
			for(var i=0; i < vowels.length; i++)
			{
				if(vowels[i] == str)
					return true;
			}
			return false;
		}

	function storeLipiChoice() {
		scriptChoice = document.frmTranslipi.cbScriptChoice.value;
		createCookie("lipiChosen", scriptChoice, 1);
		translipi();
	}
		
	function translipi() {						
		var scriptFromCookie = readCookie("lipiChosen");		

		if(scriptFromCookie != null) {			
			scriptChoice = scriptFromCookie;
			document.frmTranslipi.cbScriptChoice.value=scriptChoice;
		} else {			
			scriptChoice = "en";
			document.frmTranslipi.cbScriptChoice.value = scriptChoice;
		}

		walkLipiElements(document.body, scriptChoice);
		doneonce = true;
	}
	
function walkLipiElements(n, scriptChoice) {                         

	if (n.nodeType == 1 /*Node.ELEMENT_NODE*/) {  // Check if n is an Element
        var val = n.getAttribute("lipi");
		if (val != null) { // Check if n is an Element	
			if(!doneonce) {
				n.lipi = -1;					
				n.lipi = origText.push(n.innerHTML) - 1;	
				//alert("Pushed "+origText[n.lipi]);				
			}
			var txt = origText[n.lipi];			
			n.innerHTML = transliterate(txt,scriptChoice, val);		
			return;
		}
    var children = n.childNodes;                
    for(var i=0; i < children.length; i++) {    		
        walkLipiElements(children[i], scriptChoice);      // Recurse on each one
    }
	}
    return;  
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
 var location = document.cookie.indexOf(nameEQ);
 if(location == -1) return null;
 var lipi=document.cookie.substr(location+nameEQ.length, 2);
  return lipi;	
}

function handleSearch()
{  
  if(document.pressed == 'Go')
  {
   document.searchform.action ="<?php $this->text('searchaction'); ?>";
   alert("Go not working."+"<?php $this->text('searchaction'); ?>");
  }
  else if(document.pressed == 'Search')
  {    
    document.searchform.action ="http://sahityam.net/w/index.php/Sahityam:GoogleSearch";
    document.searchform.search.name = "q";
    alert("Search not working.");
  }
  return true;
}

var linktxt = {"true": "Show Details", "false": "Hide Details"};
var styletxt = {"true": "block", "false": "none"};

function handleStanzaDetails(which) {
     var len = which.parentNode.childNodes.length;
	 var displaydetails = !!which.name;
     for (var i=0; i<which.parentNode.childNodes.length; i++){
	    var elem = which.parentNode.childNodes[i];
		if(elem.id == null) continue;
		if (elem.id == "divDetailed") {
			elem.style.display = styletxt[displaydetails];
//alert("display: "+elem.innerHTML);
}
		else if(elem.id == "divOriginal")
			elem.style.display=styletxt[!displaydetails];
		if(displaydetails) which.name = "";
		else which.name="true";
		which.innerHTML = linktxt[!displaydetails];
	}
}

var totalItems=0, curItem = 0; // Items returned. 
var divprefix="sug_item";
var savedSearchText='';
var resultHasFocus = false;

//Gets the browser specific XmlHttpRequest Object
function getXmlHttpRequestObject() {
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		return new ActiveXObject("Microsoft.XMLHTTP");
	} 
}

//Our XmlHttpRequest object to get the auto suggest
var searchReq = getXmlHttpRequestObject();

//Called from keyup on the search textbox.
//Starts the AJAX request.
function searchSuggest(e) {			
	//alert(e);
	if (!e) var e = window.event;		
	var str = document.getElementById('searchInput').value;		
	//Trim
	str = trim(str);		
	if(str.length < 1) {		
		turnOffResults();
		return;
	}
	
	if (searchReq.readyState == 4 || searchReq.readyState == 0) {			
		var onlyNP;		// only non-printable chars	
		var code;
		if (e.keyCode) code = e.keyCode;
		else if (e.which) code = e.which;
		onlyNP = processKey(str, code);
		//else		onlyNP = processKey(ev.keyCode);
		if(onlyNP) return;
		
		// Capitalise first letter.
		var tmpChar = str.substring(0,1).toUpperCase();
		var restOfStr = str.substring(1,str.length);
		var str = tmpChar + restOfStr;

		str = escape(str); //url-encoding
		searchReq.open("GET", "http://sahityam.net/w/api.php?action=query&list=allpages&format=json&apprefix="+str, true);
		searchReq.onreadystatechange = handleSearchSuggest; 
		searchReq.send(null);
	}		
}

function processKey(txt, key) {
	if(curItem == 0) savedSearchText = txt;
	
	if(key == 40 || key == 38) {
		var prevSel = document.getElementById(divprefix + curItem);
		if(prevSel) suggestOut(prevSel);				
		if(key == 40)	curItem = (curItem + 1) % totalItems; //Down
		else			curItem = (curItem - 1) % totalItems; // Up
		
		if(curItem == 0) {
			document.getElementById('searchInput').value = savedSearchText;
		}			
		else {
			if(curItem < 0) curItem += totalItems;
			var item = document.getElementById(divprefix + curItem);		
			suggestOver(item);
			document.getElementById('searchInput').value = item.innerHTML;		
		}
		return true;	
	}
	else if(key == 27) { //Escape
		turnOffResults();	
		return true;
	}
	return false;
}

//Called when the AJAX response is returned.
function handleSearchSuggest() {	
	if (searchReq.readyState == 4) {	
		var ss = document.getElementById('search_suggest')
		ss.innerHTML = '';			
		result_obj = eval("(" + searchReq.responseText + ")");		
		obj2 = result_obj["query"]["allpages"];		
		var str = searchReq.responseText.split("\n");
		var i = 0;
		for(var prop in obj2) {
			i++;
			var suggest = '<div id="'+(divprefix)+i+'" onmouseover="javascript:suggestOver(this);" ';
			suggest += 'onmouseout="javascript:suggestOut(this);" ';			
			suggest += 'onclick="javascript:setSearch(this.innerHTML);" ';
			suggest += 'class="suggest_link">' + obj2[prop]["title"] + '</div>';
			ss.innerHTML += suggest;			
		}
		if(i>0) turnOnResults();
		totalItems = i + 1;		
	}
}

//Mouse over function
function suggestOver(div_value) {
	div_value.className = 'suggest_link_over';
resultHasFocus = true;
}
//Mouse out function
function suggestOut(div_value) {
	div_value.className = 'suggest_link';
	resultHasFocus = false;
}
//Click function
function setSearch(value) {
	document.getElementById('searchInput').value = value;
	turnOffResults();
}		
function turnOnResults() {
	var resultsDiv = document.getElementById('search_suggest');	
	resultsDiv.className = "search_result_appear";
}

function turnOffResults() {
	var resultsDiv = document.getElementById('search_suggest');
	resultsDiv.innerHTML = '';
	resultsDiv.className = "search_result_disappear";
	curItem = 0;
}

function handleSearchInputBlur() {
	if(!resultHasFocus) turnOffResults();
}

/* MediaWiki:Monobook.js (deprecated; migrate to Common.js!) */
/* Deprecated; use [[MediaWiki:common.js]] */