if(typeof(MVJS)=="undefined")
{
	MVJS={};
}

MVJS.IndicLanguage = function()
{
	return new MVJS._IndicLanguage();
};
MVJS._IndicLanguage = function(){
	this.language = "hindi";
	this.__base = new Object();
	this.__mod = new Object();
	this.adder = 0;
};

MVJS._IndicLanguage.prototype.setLanguage = function(lang)
{
	this.language = lang.toLowerCase();
        switch (lang.toLowerCase())
           {
           case "bengali": 
                this.adder = 128;
                break;
            case "gujarati": 
                this.adder = 384;
                break;
            case "hindi": 
                this.adder = 0;
                break;
            case "malayalam": 
                this.adder = 1024;
                break;
            case "punjabi": 
                this.adder = 256;
                break;
            case "telugu": 
                this.adder = 768;
                break;
            case "kannada": 
                this.adder = 896;
                break;
            case "tamil": 
                this.adder = 640;
                break;
           }
        this.__clearLanguage();
        this.__initLanguage();
        switch (lang.toLowerCase())
           {case "gujarati": 
                this.__initGujarati();
                break;
            case "hindi": 
                this.__initHindi();
                break;
            case "malayalam": 
                this.__initMalayalam();
                break;
            case "punjabi": 
                this.__initPunjabi();
                break;
            case "telugu": 
                this.__initTelugu();
                break;
            case "kannada": 
                this.__initKannada();
                break;
            case "bengali": 
                this.__initBengali();
                break;
            case "tamil": 
                this.__initTamil();
                break;
           }
};
   
MVJS._IndicLanguage.prototype.getBase = function(key)
{
	return this.__base[key];
};
   
MVJS._IndicLanguage.prototype.getMod = function(key)
{
	return this.__mod[key];
};
   
MVJS._IndicLanguage.prototype.__clearLanguage = function()
{
	for (var i in this.__base)
	{
		delete this.__base[i];
	}
	for (var i in this.__mod)
	{
		delete this.__mod[i];
	}
};
   
MVJS._IndicLanguage.prototype.__initTamil = function()
{
	delete this.__mod["94"];
        delete this.__base["82"];
        delete this.__base["8282"];
        this.__base["69"] = "\u0b8e";
        this.__base["79"] = "\u0b92";
        delete this.__base["107104"];
        delete this.__base["103"];
        delete this.__base["103104"];
        delete this.__base["67104"];
        delete this.__base["122"];
        delete this.__base["84104"];
        delete this.__base["68"];
        delete this.__base["68104"];
        delete this.__base["116104"];
        delete this.__base["100"];
        delete this.__base["100104"];
        this.__base["7878"] = "\u0ba9";
        delete this.__base["102"];
        delete this.__base["112104"];
        delete this.__base["98"];
        delete this.__base["98104"];
        this.__base["114114"] = "\u0bb1";
        this.__base["7676"] = "\u0bb4";
        this.__base["115104"] = "\u0bb7";
        delete this.__mod["82"];
        delete this.__mod["8282"];
        this.__mod["69"] = "\u0bc6";
        this.__mod["79"] = "\u0bca";
        delete this.__mod["42"];
        delete this.__base["36"];
        delete this.__base["7977"];
        this.__mod["9785"] = "\u0bd7";
        this.__base["4964"] = "\u0bf0";
        this.__base["4936"] = "\u0bf1";
        this.__base["49126"] = "\u0bf2";
};
   
MVJS._IndicLanguage.prototype.__initTelugu = function()
{
	this.__base["114114"] = "\u0c31";
        delete this.__mod["42"];
        delete this.__base["7977"];
        this.__mod["126"] = "\u0c55";
        this.__mod["9773"] = "\u0c56";
        delete this.__mod["81"];
        delete this.__mod["8181"];
};
   
MVJS._IndicLanguage.prototype.__initPunjabi = function()
{
	delete this.__mod["94"];
        delete this.__mod["58"];
        delete this.__base["82"];
        delete this.__base["81"];
        delete this.__base["69"];
        delete this.__base["79"];
        delete this.__base["76"];
        delete this.__base["83104"];
        delete this.__mod["85"];
        delete this.__mod["82"];
        delete this.__mod["8282"];
        delete this.__mod["69"];
        delete this.__mod["79"];
        this.__base["7977"] = "\u0a74";
        this.__base["114114"] = "\u0a5c";
        this.__mod["126"] = "\u0a70";
        this.__mod["64"] = "\u0a71";
        this.__base["7382"] = "\u0a72";
        this.__base["8582"] = "\u0a73";
};
   
MVJS._IndicLanguage.prototype.__initMalayalam = function()
{
	delete this.__mod["94"];
        this.__base["69"] = "\u0d0e";
        this.__base["79"] = "\u0d12";
        this.__base["114114"] = "\u0d31";
        this.__base["122104"] = "\u0d34";
        delete this.__mod["42"];
        delete this.__base["36"];
        delete this.__mod["8282"];
        this.__mod["69"] = "\u0d46";
        this.__mod["79"] = "\u0d4a";
        this.__mod["9785"] = "\u0d57";
        delete this.__mod["81"];
        delete this.__mod["8181"];
};
   
MVJS._IndicLanguage.prototype.__initKannada = function()
{
	delete this.__mod["94"];
        this.__base["69"] = "\u0c8e";
        this.__base["79"] = "\u0c92";
        this.__base["114114"] = "\u0cb1";
        delete this.__mod["42"];
        delete this.__base["36"];
        this.__mod["69"] = "\u0cc6";
        this.__mod["79"] = "\u0cca";
        this.__mod["101101"] = "\u0cd5";
        this.__mod["9773"] = "\u0cd6";
        this.__base["70"] = "\u0cde";
        delete this.__mod["81"];
        delete this.__mod["8181"];
};
   
MVJS._IndicLanguage.prototype.__initBengali = function()
{
        delete this.__base["69"];
        delete this.__base["79"];
        this.__base["118"] = "\u09ac";
        this.__base["119"] = "\u09ac";
        delete this.__mod["69"];
        this.__mod["9785"] = "\u09d7";
        delete this.__base["7977"];
        this.__base["8182"] = "\u09f0";
        this.__base["8281"] = "\u09f1";
        this.__base["126"] = "\u09fa";
};
   
MVJS._IndicLanguage.prototype.__initGujarati = function(){};
   
MVJS._IndicLanguage.prototype.__initHindi = function()
{
        this.__base["97126"] = "\u0904";
        this.__base["69126"] = "\u090e";
        this.__base["79126"] = "\u0912";
        this.__mod["126"] = "\u0946";
        this.__mod["126126"] = "\u094a";
        this.__mod["33"] = "\u0951";
        this.__mod["95"] = "\u0952";
        this.__mod["92"] = "\u0953";
        this.__mod["47"] = "\u0954";
        this.__base["64"] = "\u0970";
        this.__base["6464"] = "\u0971";
};
   
MVJS._IndicLanguage.prototype.__initLanguage = function()
{
        var VIRAM = 1;
        this.__mod["94"] = "\u0901";
        this.__mod["77"] = "\u0902";
        this.__mod["58"] = "\u0903";
        this.__base["97"] = "\u0905";
        this.__base["65"] = "\u0906";
        this.__base["9797"] = "\u0906";
        this.__base["105"] = "\u0907";
        this.__base["73"] = "\u0908";
        this.__base["117"] = "\u0909";
        this.__base["85"] = "\u090a";
        this.__base["111111"] = "\u090a";
        this.__base["82"] = "\u090b";
        this.__base["81"] = "\u090c";
        this.__base["69"] = "\u090d";
        this.__base["101"] = "\u090f";
        this.__base["97105"] = "\u0910";
        this.__base["79"] = "\u0911";
        this.__base["111"] = "\u0913";
        this.__base["97117"] = "\u0914";
        this.__base["107"] = "\u0915";
        this.__base["107104"] = "\u0916";
        this.__base["103"] = "\u0917";
        this.__base["103104"] = "\u0918";
        this.__base["7871"] = "\u0919";
        this.__base["99104"] = "\u091a";
        this.__base["67104"] = "\u091b";
        this.__base["106"] = "\u091c";
        this.__base["122"] = "\u091d";
        this.__base["7889"] = "\u091e";
        this.__base["84"] = "\u091f";
        this.__base["84104"] = "\u0920";
        this.__base["68"] = "\u0921";
        this.__base["68104"] = "\u0922";
        this.__base["78"] = "\u0923";
        this.__base["116"] = "\u0924";
        this.__base["116104"] = "\u0925";
        this.__base["100"] = "\u0926";
        this.__base["100104"] = "\u0927";
        this.__base["110"] = "\u0928";
        this.__base["112"] = "\u092a";
        this.__base["102"] = "\u092b";
        this.__base["112104"] = "\u092b";
        this.__base["98"] = "\u092c";
        this.__base["98104"] = "\u092d";
        this.__base["109"] = "\u092e";
        this.__base["121"] = "\u092f";
        this.__base["114"] = "\u0930";
        this.__base["108"] = "\u0932";
        this.__base["76"] = "\u0933";
        this.__base["118"] = "\u0935";
        this.__base["119"] = "\u0935";
        this.__base["115104"] = "\u0936";
        this.__base["83104"] = "\u0937";
        this.__base["115"] = "\u0938";
        this.__base["104"] = "\u0939";
        this.__base["120"] = "\u0915\u094d\u0937";
        this.__base["74104"] = "\u091c\u094d\u091e";
        this.__mod["42"] = "\u093c";
        this.__base["36"] = "\u093d";
        this.__mod["9797"] = "\u093e";
        this.__mod["65"] = "\u093e";
        this.__mod["105"] = "\u093f";
        this.__mod["73"] = "\u0940";
        this.__mod["117"] = "\u0941";
        this.__mod["85"] = "\u0942";
        this.__mod["82"] = "\u0943";
        this.__mod["8282"] = "\u0944";
        this.__mod["69"] = "\u0945";
        this.__mod["101"] = "\u0947";
        this.__mod["97105"] = "\u0948";
        this.__mod["79"] = "\u0949";
        this.__mod["111"] = "\u094b";
        this.__mod["97117"] = "\u094c";
        this.__mod[VIRAM] = "\u094d";
        this.__base["7977"] = "\u0950";
        this.__base["8282"] = "\u0960";
        this.__base["8181"] = "\u0961";
        this.__mod["81"] = "\u0962";
        this.__mod["8181"] = "\u0963";
        this.__base["48"] = "\u0966";
        this.__base["49"] = "\u0967";
        this.__base["50"] = "\u0968";
        this.__base["51"] = "\u0969";
        this.__base["52"] = "\u096a";
        this.__base["53"] = "\u096b";
        this.__base["54"] = "\u096c";
        this.__base["55"] = "\u096d";
        this.__base["56"] = "\u096e";
        this.__base["57"] = "\u096f";
        for (var key in this.__base)
           {var result="";for (var i = 0;i < (this.__base[key]).length;i++) result = result.toString() + String.fromCharCode((this.__base[key]).charCodeAt(i) + this.adder);
            this.__base[key] = result;
           }
        for (var key in this.__mod)
           {var result = "";
            for (var i = 0;i < (this.__mod[key]).length;i++) result = result.toString() + String.fromCharCode((this.__mod[key]).charCodeAt(i) + 
              this.adder);
            this.__mod[key] = String.fromCharCode((this.__mod[key]).charCodeAt(0) + this.adder);
           }
        this.__mod["97"] = "";
        this.__base["124"] = "\u0964";
        this.__base["124124"] = "\0965";
};
MVJS.PhoneticTypePad=function(ElementID, language){	
	return new MVJS._PhoneticTypePad(ElementID, language);
};

MVJS._PhoneticTypePad=function(ElementID, language)
{
	this.prevkey = 32;
	this.hidden = false;
	this.posChanged = true;
	this.isEng = false;
	this.VIRAM = 1;
	this.previousConsonant = false;
	this.previouspreviousConsonant = false;
	this.il = MVJS.IndicLanguage();
	this.objID = ElementID;
	this.objEle = document.getElementById(ElementID);
	this.language = language;
	this.count = 0;
	this.callbackName = "";
	this.MSIE = document.all ? true: false;
	
	this.setLanguage(language);
	this.addEventHandler(this);	
};

MVJS._PhoneticTypePad.prototype.setLanguage = function(language)
{    
	if (language != null && (language == 'bengali' || language == 'gujarati' || language == 'hindi' || language == 'malayalam' || language == 'punjabi' || language == 'telugu' || 
	  language == 'kannada' || language == 'tamil'))
	   {this.language = language;
	    this.il.setLanguage(language);
	    this.isEng = false;
	   }
	else this.isEng = true;
};
MVJS._PhoneticTypePad.prototype.getLanguage = function()
{
	return this.isEng ? "english": this.language;
};
   
MVJS._PhoneticTypePad.prototype.onLanguageChange = function(cbName)
{
	this.callbackName = cbName;
};
   
MVJS._PhoneticTypePad.prototype.positionChange = function(e)
{
	var keyCode = document.all ? e.keyCode: e.which;
	if (keyCode == 123)
	   {if (this.language != 'english') this.isEng = ! this.isEng;
	    if (this.callbackName != "") this.callbackName(this.isEng ? "english": this.language);
	   }
	if (keyCode >= 37 && keyCode <= 40) this.posChanged = true;
};
   
MVJS._PhoneticTypePad.prototype.changeCursor = function(e)
{
	if(!this.objEle) return;	
	if (this.objEle.createTextRange) this.objEle.cursorPos = document.selection.createRange().duplicate();
};   

MVJS._PhoneticTypePad.prototype.charHandler = function(e)
{
	
	if (this.isEng) return true;
	var element = this.objEle;
	var displace = 0;
	var text = '';
	var previousValue = "";
	var key = 0;
	var keychar = '';
	var bComb = '';
	var mComb = '';
	var base = '';
	var mod = '';
	if (e.altKey || e.ctrlKey) return true;
	key = this.MSIE ? e.keyCode: e.which;	
	if ((key < 32) || (key > 33 && key < 47 && key != 42 && key != 36) || (key >= 59 && key <= 62) || (key >= 91 && 
	  key <= 96 && key != 94 && key != 95 && key != 92) || (key >= 123 && key <= 127 && key != 126 && key != 124)) return true;	  
	 
	 if (MVJS.IsIE()){ var SourceElement=(window.event)?window.event.srcElement:event.target; if (SourceElement!=this.objEle) return true; }
	 
	keychar = String.fromCharCode(key);
	if (element.contentWindow) element = element.contentWindow;
	if (this.posChanged)
	   {this.prevkey = 32;
	    this.hidden = false;
	    prevpos = 0;
	    this.previousConsonant = false;
	    this.previouspreviousConsonant = false;
	   }
	bComb = this.il.getBase(this.prevkey.toString() + key.toString());
	mComb = this.il.getMod(this.prevkey.toString() + key.toString());
	base = this.il.getBase(key.toString());
	mod = this.il.getMod(key.toString());
	switch (keychar)
	   {case "a": 
	    case "e": 
	    case "i": 
	    case "o": 
	    case "u": 
	    case "A": 
	    case "I": 
	    case "U": 
	    case "O": 
	    case "E": 
		if (this.previousConsonant)
		   {displace--;
		    text = mod;
		   }
		else if (typeof (mComb) != 'undefined' && this.previouspreviousConsonant)
		   {displace = 0;
		    text = mComb;
		    key = 32;
		   }
		else if (typeof (bComb) != 'undefined')
		   {displace--;
		    text = bComb;
		    key = 32;
		   }
		else if (typeof (base) != 'undefined')
		   {displace = 0;
		    text = base;
		   }
		this.previouspreviousConsonant = this.previousConsonant;
		this.previousConsonant = false;
		this.hidden = false;
		break;
	    case 'Q': 
	    case 'R': 
		if (typeof (bComb) != 'undefined')
		   {if (this.previouspreviousConsonant && typeof (mComb) != 'undefined')
		       {displace--;
			text = mComb;
			key = 32;
		       }
		    else 
		       {displace--;
			text = bComb;
			key = 32;
		       }
		   }
		else if (this.previousConsonant)
		   {if (typeof (mod) != 'undefined')
		       {displace--;
			text = mod;
		       }
		   }
		else if (typeof (base) != 'undefined')
		   {displace = 0;
		    text = base;
		   }
		this.previouspreviousConsonant = this.previousConsonant;
		this.previousConsonant = false;
		this.hidden = false;
		break;
	    case':': 
	    case 'M': 
		if (typeof (bComb) != 'undefined')
		   {displace--;
		    text = bComb;
		    key = 32;
		   }
		else 
		   {if (this.previousConsonant) displace--;
		    else displace = 0;
		    if (typeof (mod) != 'undefined') text = mod;
		    else text = keychar.toString();
		   }
		this.previouspreviousConsonant = this.previousConsonant;
		this.previousConsonant = false;
		this.hidden = false;
		break;
	    case ' ': 
		if (this.previousConsonant) displace--;
		else displace = 0;
		text = ' ';
		this.previouspreviousConsonant = this.previousConsonant;
		this.previousConsonant = false;
		this.hidden = false;
		break;
	    case '|': 
	    case '@': 
	    case '~': 
	    case '0': 
	    case '1': 
	    case '2': 
	    case '3': 
	    case '4': 
	    case '5': 
	    case '6': 
	    case '7': 
	    case '8': 
	    case '9': 
	    case '$': 
		if (typeof (bComb) != 'undefined')
		   {displace--;
		    text = bComb;
		    key = 32;
		   }
		else if (typeof (mComb) != 'undefined')
		   {displace--;
		    text = mComb;
		    key = 32;
		   }
		else if (this.previousConsonant && typeof (base) != 'undefined')
		   {displace--;
		    text = base;
		   }
		else if (typeof (base) != 'undefined')
		   {                   displace = 0;
		    text = base;
		   }
		else                if (typeof (mod) != 'undefined')
		   {displace--;
		    text = mod;
		   }
		else 
		   {displace = 0;
		    text = keychar.toString();
		   }
		this.previouspreviousConsonant = this.previousConsonant;
		this.previousConsonant = false;
		this.hidden = false;
		break;
	    default: 
		if (this.hidden)
		   {if (typeof (bComb) != 'undefined')
		       {displace = 0;
			text = bComb + this.il.getMod(this.VIRAM);
			this.previouspreviousConsonant = this.previousConsonant;
			this.previousConsonant = true;
		       }
		    else if (typeof (base) != 'undefined')
		       {displace = 0;
			text = base + this.il.getMod(this.VIRAM);
			this.previouspreviousConsonant = this.previousConsonant;
			this.previousConsonant = true;
			this.hidden = false;
		       }
		    else 
		       {displace = 0;
			this.previouspreviousConsonant = this.previousConsonant;
			this.previousConsonant = false;
		       }
		   }
		else 
		   {if (typeof (bComb) != 'undefined')
		       {displace -= 2;
			text = bComb + this.il.getMod(this.VIRAM);
			this.previouspreviousConsonant = this.previousConsonant;
			this.previousConsonant = true;
		       }
		    else if (typeof (base) != 'undefined')
		       {displace = 0;
			text = base + this.il.getMod(this.VIRAM);
			this.previouspreviousConsonant = this.previousConsonant;
			this.previousConsonant = true;
		       }
		    else if (typeof (mod) != 'undefined')
		       {displace--;
			text = mod;
			this.previouspreviousConsonant = this.previousConsonant;
			this.previousConsonant = false;
		       }
		    else if ((key >= 97 && key <= 122) || (key >= 65 && key <= 90))
		       {this.previouspreviousConsonant = this.previousConsonant;
			this.previousConsonant = true;
			this.hidden = true;
		       }
		    else 
		       {displace = 0;
			text = keychar.toString();
			this.previouspreviousConsonant = this.previousConsonant;
			previousConsonant = false;
			this.hidden = false;
		       }
		   }
	   }
	this.prevkey = key;
	if (this.MSIE)
	   {var doc = element.document;
	    var r = doc.selection.createRange();
	    r.moveStart('character', displace);
	    r.text = (r.text.charAt(r.text.length - 1) == ' ' ? text + ' ': text);
	    r.collapse(false);
	    e.returnValue = false;
	   }
	else 
	   {if (element.getSelection)
	       {var s, r, nd, offset, s1 = "", s2 = "";
			
				s = element.getSelection();
				
				if (typeof (s) != 'undefined')
				{
					r = s.getRangeAt(0);
				}
				else
				{
					r = element.document.createRange();			
					
				}
				
				nd = r.startContainer;
				offset = r.startOffset;
				
				if (nd.nodeType == 3)
				   {s1 = nd.nodeValue.substring(0, offset + displace);
				    s2 = nd.nodeValue.substring(offset);
				   }
				else 
				   {var nod = document.createTextNode(text);
				    nd.appendChild(nod);
				    nd = nod;
				   }
				nd.nodeValue = (s1 + text.toString() + s2.toString());
					
					
				try
				{
					r = element.document.createRange();					
					r.setStart(nd, (offset + displace + (text.length)));					
				}
				catch (ex){				
					s.removeAllRanges();	
					element.focus ();
					return false;
					/*if (offset > nd.nodeValue.length) offset = nd.nodeValue.length;					*/
				}
				
				r.setEnd(nd, offset + displace + text.length);				
				s.removeAllRanges();
				s.addRange(r);	

			
	       }
	    else 
	       {
			var pos = element.selectionStart;
			var post = pos + displace;
			element.value = element.value.substring(0, pos + displace) + text + element.value.substring(pos, 
			element.value.length);
			if (typeof (text) != 'undefined') pos = pos + text.length;
			element.setSelectionRange(pos, pos);
	       }
	    e.preventDefault();
	   }
	this.posChanged = false;
	return false;
};
   
MVJS._PhoneticTypePad.prototype.addEventHandler = function()
{

	var obj = this.objEle;
	if (obj.contentWindow) obj = obj.contentWindow.document;
	else if (obj.contentDocument) obj = obj.contentDocument;
	else if (obj.document) obj = obj.document;
	var _this = this;
	if (this.MSIE)
	{
		obj.onkeypress = function (e) {_this.kblistener(e);};
		obj.onfocus = function (e) {_this.kbhandler(e);};
		obj.onclick = function (e) {_this.kbhandler(e);};
		obj.onkeyup = function (e) {_this.kbhandler(e);};
		obj.onkeydown = function (e) {_this.kbposition(e);};
	}
	else 
	{
		MVJS.EventHandler().AttachEvent(obj,"keypress",function (e){_this.kblistener(e);});
		MVJS.EventHandler().AttachEvent(obj,"focus",function (e){_this.kbhandler(e);});
		MVJS.EventHandler().AttachEvent(obj,"click",function (e){_this.kbhandler(e);});
		MVJS.EventHandler().AttachEvent(obj,"keyup",function (e){_this.kbhandler(e);});
		MVJS.EventHandler().AttachEvent(obj,"keydown",function (e){_this.kbposition(e);});
	}	
};
MVJS._PhoneticTypePad.prototype.removeEventHandler = function()
{

	var obj = this.objEle;
	if (obj.contentWindow) obj = obj.contentWindow.document;
	else if (obj.contentDocument) obj = obj.contentDocument;
	else if (obj.document) obj = obj.document;
	var _this = this;

	MVJS.EventHandler().RemoveEvent(this.objEle,"keypress",function (e){_this.kblistener(e);});
	MVJS.EventHandler().RemoveEvent(this.objEle,"focus",function (e){_this.kbhandler(e);});
	MVJS.EventHandler().RemoveEvent(this.objEle,"click",function (e){_this.kbhandler(e);});
	MVJS.EventHandler().RemoveEvent(this.objEle,"keyup",function (e){_this.kbhandler(e);});
	MVJS.EventHandler().RemoveEvent(this.objEle,"keydown",function (e){_this.kbposition(e);});

};
MVJS._PhoneticTypePad.prototype.kblistener = function (e)
{
	var evt;
	if (this.MSIE && this.objEle.contentWindow) evt = this.objEle.contentWindow.event;
	else evt = (window.event) ? window.event: e;
	return this.charHandler(evt);
};
MVJS._PhoneticTypePad.prototype.kbhandler = function(e)
{
	var evt;
	if (this.MSIE && this.objEle.contentWindow) evt = this.objEle.contentWindow.event;
	else evt = (window.event) ? window.event: e;
	return this.changeCursor(evt);
};

MVJS._PhoneticTypePad.prototype.kbposition = function(e)
{
	var evt;
	if (this.MSIE && this.objEle.contentWindow) evt = this.objEle.contentWindow.event;
	else evt = (window.event) ? window.event: e;
	return this.positionChange(evt);
};
    
