var lang=0;
var layout=1;
var hebrewStart=1487;


function getNextStateHebrewLayout(lastInput,currentInput,change)
{
switch(currentInput)
{
case"t":return String.fromCharCode(hebrewStart+1);
case"c":return String.fromCharCode(hebrewStart+2);
case"d":return String.fromCharCode(hebrewStart+3);
case"s":return String.fromCharCode(hebrewStart+4);
case"v":return String.fromCharCode(hebrewStart+5);
case"u":return String.fromCharCode(hebrewStart+6);
case"z":return String.fromCharCode(hebrewStart+7);
case"j":return String.fromCharCode(hebrewStart+8);
case"y":return String.fromCharCode(hebrewStart+9);
case"h":return String.fromCharCode(hebrewStart+10);
case"l":return String.fromCharCode(hebrewStart+11);
case"f":return String.fromCharCode(hebrewStart+12);
case"k":return String.fromCharCode(hebrewStart+13);
case"o":return String.fromCharCode(hebrewStart+14);
case"n":return String.fromCharCode(hebrewStart+15);
case"i":return String.fromCharCode(hebrewStart+16);
case"b":return String.fromCharCode(hebrewStart+17);
case"x":return String.fromCharCode(hebrewStart+18);
case"g":return String.fromCharCode(hebrewStart+19);
case";":return String.fromCharCode(hebrewStart+20);
case"p":return String.fromCharCode(hebrewStart+21);
case".":return String.fromCharCode(hebrewStart+22);
case"m":return String.fromCharCode(hebrewStart+23);
case"e":return String.fromCharCode(hebrewStart+24);
case"r":return String.fromCharCode(hebrewStart+25);
case"a":return String.fromCharCode(hebrewStart+26);
case",":return String.fromCharCode(hebrewStart+27);
case"q":return new String("/");
case"w":return new String("'");
case"'":return new String(",");
case"/":return new String(".");
case"&#65533;":return new String(";");
case "1":return "1";
case "2":return "2";
case "3":return "3";
case "4":return "4";
case "5":return "5";
case "6":return "6";
case "7":return "7";
case "8":return "8";
case "9":return "9";
case "0":return "0";
case "!":return "!";
case "@":return "@";
case "#":return "#";
case "$":return "$";
case "%":return "%";
case "^":return "^";
case "&":return "&";
case "*":return "*";
case "(":return "(";
case ")":return ")";
case "`":return ";";
case "~":return "~";
}
return currentInput;
}
function getNextStatePhoneticLayout(lastInput,currentInput,change)
{
switch(lastInput.charCodeAt(0))
{
case hebrewStart+18:
	if(currentInput=="s")
	{
		if (change) eraseLastChar();
		return String.fromCharCode(hebrewStart+26);
	}
	break;
case hebrewStart+27:
	if(currentInput=="t")
	{
		if (change) eraseLastChar();
		return String.fromCharCode(hebrewStart+9);
	}
	break;
case hebrewStart+7:
	if(currentInput=="z")
	{
		if (change) eraseLastChar();
		return String.fromCharCode(hebrewStart+23);
	}
	break;
}
switch(currentInput)
{
case"a":return String.fromCharCode(hebrewStart+1);
case"b":return String.fromCharCode(hebrewStart+2);
case"c":return String.fromCharCode(hebrewStart+12);
case"d":return String.fromCharCode(hebrewStart+4);
case"e":return String.fromCharCode(hebrewStart+19);
case"p":return String.fromCharCode(hebrewStart+21);
case"g":return String.fromCharCode(hebrewStart+3);
case"h":return String.fromCharCode(hebrewStart+5);
case"i":return String.fromCharCode(hebrewStart+10);
case"k":return String.fromCharCode(hebrewStart+24);
case"l":return String.fromCharCode(hebrewStart+13);
case"m":return String.fromCharCode(hebrewStart+15);
case"n":return String.fromCharCode(hebrewStart+17);
case"r":return String.fromCharCode(hebrewStart+25);
case"s":return String.fromCharCode(hebrewStart+18);
case"t":return String.fromCharCode(hebrewStart+27);
case"v":return String.fromCharCode(hebrewStart+6);
case"z":return String.fromCharCode(hebrewStart+7);
case"x":return String.fromCharCode(hebrewStart+8);
}
return currentInput;
}
function initKeyboard()
{
	setKeyboardButtons();
}
function changeEndOfWord(character)
{
switch(character)
{
case(hebrewStart+12):
return hebrewStart+11;
break;
case(hebrewStart+15):
return hebrewStart+14;
break;
case(hebrewStart+17):
return hebrewStart+16;
break;
case(hebrewStart+21):
return hebrewStart+20;
break;
case(hebrewStart+23):
return hebrewStart+22;
break;
}
return character;
}

function getNextState(lastInput,currentInput,change)
{
switch(layout)
{
case 0:return getNextStatePhoneticLayout(lastInput,currentInput,change);
case 1:return getNextStateHebrewLayout(lastInput,currentInput,change);
}
}

