
function VirtualKey()
{
	
	this.sParentId = "";
	this.oParent = null;
	this.sTextboxId = "";
	this.oKey = document.createElement( 'div' );
	this.oKey.sChrSmall = "";
	this.oKey.sChrCapital = "";
	this.oKey.oTbHndlr = null;
	this.oKey.sCssClassNameOn = "onFocusKey";
	this.oKey.sCssClassNameOff = "offFocusKey";
	this.oKey.sCursorStyle = "default";
	this.oKey.oTextInKey = document.createTextNode( this.oKey.sChrSmall );
	
}

VirtualKey.prototype.setParentId = function( _sParentId )
{
	
	this.sParentId = _sParentId;
	this.oParent = document.getElementById( _sParentId );
	
}

VirtualKey.prototype.getParentId = function()
{
	
	return this.sParentId;
	
}

VirtualKey.prototype.setParent = function( _oParent )
{
	
	this.oParent = _oParent;
	this.sParentId = this.oParent.id;
	
}

VirtualKey.prototype.getParent = function()
{
	
	return this.oParent;
	
}

VirtualKey.prototype.setTextboxId = function( _sTextboxId )
{
	
	this.sTextboxId = _sTextboxId;
	
}

VirtualKey.prototype.getTextboxId = function()
{
	
	return this.sTextboxId;
	
}

VirtualKey.prototype.setDiv = function( _oKey )
{
	
	this.oKey = _oKey;
	
}

VirtualKey.prototype.getDiv = function()
{
	
	return this.oKey;
	
}

VirtualKey.prototype.setChrSmall = function( _sChrSmall )
{
	
	this.oKey.sChrSmall = _sChrSmall;
	
}

VirtualKey.prototype.getChrSmall = function()
{
	
	return this.oKey.sChrSmall;
	
}

VirtualKey.prototype.setChrCapital = function( _sChrCapital )
{
	
	this.oKey.sChrCapital = _sChrCapital;
	
}

VirtualKey.prototype.getChrCapital = function()
{
	
	return this.oKey.sChrCapital;
	
}

VirtualKey.prototype.setTbHndlr = function( _oTbHandler )
{
	
	this.oKey.oTbHndlr = _oTbHandler;
	
}

VirtualKey.prototype.getTbHndlr = function()
{
	
	return this.oKey.oTbHndlr;
	
}

VirtualKey.prototype.setCssClassNameOn = function( _sCssClassNameOn )
{
	
	this.oKey.sCssClassNameOn = _sCssClassNameOn;
	
}

VirtualKey.prototype.getCssClassNameOn = function()
{
	
	return this.oKey.sCssClassNameOn;
	
}

VirtualKey.prototype.setCssClassNameOff = function( _sCssClassNameOff )
{
	
	this.oKey.sCssClassNameOff = _sCssClassNameOff;
	
}

VirtualKey.prototype.getCssClassNameOff = function()
{
	
	return this.oKey.sCssClassNameOff; 
	
}

VirtualKey.prototype.setTextInDiv = function( _oTextInDiv )
{
	
	this.oKey.oTextInKey = _oTextInDiv;
	
}

VirtualKey.prototype.getTextInDiv = function()
{
	
	return this.oKey.oTextInKey;
	
}

VirtualKey.prototype.setCursorStyle = function( _sCursorStyle )
{
	
	this.oKey.sCursorStyle = _sCursorStyle;
	
}

VirtualKey.prototype.getCursorStyle = function()
{
	
	return this.oKey.sCursorStyle;
	
}

VirtualKey.prototype.placeKey = function()
{
	
	this.oKey.style.cursor = this.oKey.sCursorStyle;
	this.oKey.className = this.oKey.sCssClassNameOff;
	
	this.oKey.onmouseover = function ( oEvent )
	{
		
		if ( !oEvent )
		{
			
			var oEvent = window.event;
			
		}
		
		var bShift = oEvent.shiftKey;
		
		if ( bShift )
		{
			
			this.oTextInKey.data = this.sChrCapital;
			
		}
		
		this.className = this.sCssClassNameOn;
		
	}
	
	this.oKey.onmouseout = function ( oEvent )
	{
		
		this.oTextInKey.data = this.sChrSmall;
		
		this.className = this.sCssClassNameOff;
	
	}
	
	this.oKey.onmousemove = function ( oEvent )
	{
		
		if ( !oEvent )
		{
			
			var oEvent = window.event;
			
		}
		
		var bShift = oEvent.shiftKey;
		
		if ( bShift )
		{
			
			this.oTextInKey.data = this.sChrCapital;
			
		}
		
		else
		{
			
			this.oTextInKey.data = this.sChrSmall;
			
		}
		
	}
	
	this.oKey.onclick = function ( oEvent )
	{		
		this.oTbHndlr.setChr( this.sChrSmall );
		
		
		if ( !oEvent )
		{
			
			var oEvent = window.event;
			
		}
		
		var bShift = oEvent.shiftKey;
		
		if ( bShift )
		{
			
			this.oTbHndlr.setChr( this.sChrCapital );
			
		}
		
		this.oTbHndlr.insAtCursor();		
	}
	
	this.oKey.onselectstart = function ()
	{
		
		return false;
		
	}
	
	this.oKey.oTextInKey.data = this.oKey.sChrSmall;
	
	if ( !this.oParent )
	{
		
		// TODO: valamiert itt null az oParent
		
		this.oParent = document.getElementById( this.sParentId );
		
	}
	
	this.oKey.appendChild( this.oKey.oTextInKey );
	this.oParent.appendChild( this.oKey );
	
}

VirtualKey.prototype.storeCursorPos = function()
{
	
	this.oKey.oTbHndlr.getCarPos();
	
}

function VirtualKeyboard( _sLang, _sTextboxId, _sParentId )
{
	
	this.sParentId = _sParentId;
	this.sLang = _sLang;
	this.sTextboxId = _sTextboxId;
	this.aKeyArray = new Array();
	this.oTbHndlr = null;
}

VirtualKeyboard.prototype.setLang = function( _sLang )
{
	
	this.sLang = _sLang;
	
}

VirtualKeyboard.prototype.getLang = function()
{
	
	return this.sLang;
	
}

VirtualKeyboard.prototype.setParentId = function( _sParentId )
{
	
	this.sParentId = _sParentId;
	
}

VirtualKeyboard.prototype.getParentId = function()
{
	
	return this.sParentId;
	
}

VirtualKeyboard.prototype.setTextboxId = function( _sTextboxId )
{
	
	this.sTextboxId = _sTextboxId;
	
}

VirtualKeyboard.prototype.getTextboxId = function()
{
	
	return this.sTextboxId;
	
}

VirtualKeyboard.prototype.getKeyArray = function()
{
	
	return this.aKeyArray;
	
}

VirtualKeyboard.prototype.setTextboxHandler = function( _oTextboxHandler )
{
	
	this.oTbHndlr = _oTextboxHandler;
	
}

VirtualKeyboard.prototype.getTextboxHandler = function()
{
	
	return this.oTbHndlr;
	
}

VirtualKeyboard.prototype.createKeyboard = function( _sLang )
{
	
	//if ( _sLang != undefined ) { this.mLang = _sLang; }
	if ( _sLang != undefined ) { this.sLang = _sLang; }
	
	var langArray = new Array();
	
	if ( this.sLang == 'HUN' )
	{

		/*
		 * hungarian
		 */
		var hun = new Array();
		hun[0] = new Array( '\u00E1', '\u00E9', '\u00ED', '\u00F3', '\u00F6', '\u0151', '\u00FA', '\u00FC', '\u0171' );
		hun[1] = new Array( '\u00C1', '\u00C9', '\u00CD', '\u00D3', '\u00D6', '\u0150', '\u00DA', '\u00DC', '\u0170' );
		
		langArray = hun;
		
	}
	
	else if ( this.sLang == 'GER' )
	{

		/*
		 * german
		 */
		var deu = new Array();
		deu[0] = new Array('\u00E4', '\u00F6', '\u00FC', '\u00DF');
		deu[1] = new Array('\u00C4', '\u00D6', '\u00DC', '\u00DF');
		
		
		langArray = deu;
		
	}
	
	else if ( this.sLang == 'FRA' )
	{

		/*
		 * french
		 */
		var fra = new Array();
		fra[0] = new Array('\u00E0', '\u00E2', '\u00E7', '\u00E8', '\u00E9', '\u00EA', '\u00EB', '\u00F4', '\u00F9');
		fra[1] = new Array('\u00C0', '\u00C2', '\u00C7', '\u00C8', '\u00C9', '\u00CA', '\u00CB', '\u00D4', '\u00D9');
		
		/* Will change to this:
		//                    à        â	     è	       é         ê          ë         î         ï        ô           ù       û          ü        ÿ          ç
		fra[0] = new Array('\u00E0', '\u00E2', '\u00E8', '\u00E9', '\u00EA', '\u00EB', '\u00EE', '\u00EF', '\u00F4', '\u00F9', '\u00FB', '\u00FC', '\u00FF', '\u00E7');
		fra[1] = new Array('\u00C0', '\u00C2', '\u00C8', '\u00C9', '\u00CA', '\u00CB', '\u00CE', '\u00CF', '\u00D4', '\u00D9', '\u00DB', '\u00DC', '\u00DF', '\u00C8');		
		*/		
		
		langArray = fra;
		
	}
	
	else if ( this.sLang == 'ITA' )
	{

		/*
		 * italian
		 */
		var ita = new Array();
		ita[0] = new Array('\u00E0', '\u00E7', '\u00E8', '\u00E9', '\u00EC', '\u00F2', '\u00F9');
		ita[1] = new Array('\u00C0', '\u00C7', '\u00C8', '\u00C9', '\u00CC', '\u00D2', '\u00D9');
		
		
		langArray = ita;
			
	}
	
	else if ( this.sLang == 'POL' )
	{

		/*
		 * polish
		 */
		var pol = new Array();
		pol[0] = new Array('\u0105', '\u0107', '\u0119', '\u0142', '\u0144', '\u00F3', '\u015B', '\u017C', '\u017A');
		pol[1] = new Array('\u0104', '\u0106', '\u0118', '\u0141', '\u0143', '\u00D3', '\u015A', '\u017B', '\u0179');
		
		
		langArray = pol;
		
	}
	
	else
	{

		/*
		 * No language match was found
		 */
		langArray = null;
		
	}
		
	if ( langArray != null )
	{
		
		for(var i=0; langArray[0] != null && i < langArray[0].length; i++)
		{
	
			var chrSmall = langArray[0][i];
			var chrCapital = langArray[1][i];
			
			this.createKey( chrSmall, chrCapital );
	
		}
	
	}		
	else{
		var noKeysText = document.createTextNode(vk_no_special_chars_msg/*'nincs speci\u00E1lis bet\u0171'*/);
		var noKeysPar = document.createElement('div')
		noKeysPar.appendChild(noKeysText);
		noKeysPar.id="noKeysDiv";
		document.getElementById(this.getParentId()).appendChild(noKeysPar);
	}
	
}

VirtualKeyboard.prototype.removeKeyboard = function()
{
	
	var parentElement = document.getElementById(this.sParentId);
		
	while ( parentElement.firstChild )
	{
			
		parentElement.removeChild( parentElement.firstChild );
			
	};
	
	this.aKeyArray = [];
	
}

VirtualKeyboard.prototype.createKey = function( _sChrSmall, _sChrCapital )
{
	
	var newKey = new VirtualKey();
	newKey.setTextboxId( this.sTextboxId );
	newKey.setParentId( this.sParentId );	
	newKey.setChrCapital( _sChrCapital );
	newKey.setChrSmall( _sChrSmall );
	newKey.setTbHndlr( this.oTbHndlr );
	
	this.aKeyArray[this.aKeyArray.length] = newKey;
	newKey.placeKey();
	
}

