﻿
var maxHeight, currentHeight;
var interval;
var divAnimation, divSource;
var divTranslit;
var thisObj ;
function OnLoadKey()
{

gettext(); 
	//var tt=document.all.CommentTxt;
	//tt.focus();
		
	
	//var r = tt.createTextRange();	
	//alert("chars");
	//r.text = tt.value;
	
	
	
	kbdflags=0;
	lastkbdflags=0;
	kbdmode=0;
	savetext="";
	lines=1;
	areaexist=false;


	
	

	
	chars=new Array(7);
	chars[0]=new Array(48);
	chars[0][0]="ё";
	chars[0][1]="1";
	chars[0][2]="2";
	chars[0][3]="3";
	chars[0][4]="4";
	chars[0][5]="5";
	chars[0][6]="6";
	chars[0][7]="7";
	chars[0][8]="8";
	chars[0][9]="9";
	chars[0][10]="0";
	chars[0][11]="-";
	chars[0][12]="=";
	chars[0][13]="\\";
	chars[0][14]="й";
	chars[0][15]="ц";
	chars[0][16]="у";
	chars[0][17]="к";
	chars[0][18]="е";
	chars[0][19]="н";
	chars[0][20]="г";
	chars[0][21]="ш";
	chars[0][22]="щ";
	chars[0][23]="з";
	chars[0][24]="х";
	chars[0][25]="ъ";
	chars[0][26]="ф";
	chars[0][27]="ы";
	chars[0][28]="в";
	chars[0][29]="а";
	chars[0][30]="п";
	chars[0][31]="р";
	chars[0][32]="о";
	chars[0][33]="л";
	chars[0][34]="д";
	chars[0][35]="ж";
	chars[0][36]="э";
	chars[0][37]="я";
	chars[0][38]="ч";
	chars[0][39]="с";
	chars[0][40]="м";
	chars[0][41]="и";
	chars[0][42]="т";
	chars[0][43]="ь";
	chars[0][44]="б";
	chars[0][45]="ю";
	chars[0][46]=".";
	chars[0][47]=" ";
	chars[1]=new Array();
	chars[1][0]="Ё";
	chars[1][1]="!";
	chars[1][2]="\"";
	chars[1][3]="№";
	chars[1][4]=";";
	chars[1][5]="%";
	chars[1][6]=":";
	chars[1][7]="?";
	chars[1][8]="*";
	chars[1][9]="(";
	chars[1][10]=")";
	chars[1][11]="_";
	chars[1][12]="+";
	chars[1][13]="/";
	chars[1][14]="Й";
	chars[1][15]="Ц";
	chars[1][16]="У";
	chars[1][17]="К";
	chars[1][18]="Е";
	chars[1][19]="Н";
	chars[1][20]="Г";
	chars[1][21]="Ш";
	chars[1][22]="Щ";
	chars[1][23]="З";
	chars[1][24]="Х";
	chars[1][25]="Ъ";
	chars[1][26]="Ф";
	chars[1][27]="Ы";
	chars[1][28]="В";
	chars[1][29]="А";
	chars[1][30]="П";
	chars[1][31]="Р";
	chars[1][32]="О";
	chars[1][33]="Л";
	chars[1][34]="Д";
	chars[1][35]="Ж";
	chars[1][36]="Э";
	chars[1][37]="Я";
	chars[1][38]="Ч";
	chars[1][39]="С";
	chars[1][40]="М";
	chars[1][41]="И";
	chars[1][42]="Т";
	chars[1][43]="Ь";
	chars[1][44]="Б";
	chars[1][45]="Ю";
	chars[1][46]=",";
	chars[1][47]=" ";
	chars[2]=new Array();
	chars[2][0]="`";
	chars[2][1]="1";
	chars[2][2]="2";
	chars[2][3]="3";
	chars[2][4]="4";
	chars[2][5]="5";
	chars[2][6]="6";
	chars[2][7]="7";
	chars[2][8]="8";
	chars[2][9]="9";
	chars[2][10]="0";
	chars[2][11]="-";
	chars[2][12]="=";
	chars[2][13]="\\";
	chars[2][14]="q";
	chars[2][15]="w";
	chars[2][16]="e";
	chars[2][17]="r";
	chars[2][18]="t";
	chars[2][19]="y";
	chars[2][20]="u";
	chars[2][21]="i";
	chars[2][22]="o";
	chars[2][23]="p";
	chars[2][24]="[";
	chars[2][25]="]";
	chars[2][26]="a";
	chars[2][27]="s";
	chars[2][28]="d";
	chars[2][29]="f";
	chars[2][30]="g";
	chars[2][31]="h";
	chars[2][32]="j";
	chars[2][33]="k";
	chars[2][34]="l";
	chars[2][35]=";";
	chars[2][36]="'";
	chars[2][37]="z";
	chars[2][38]="x";
	chars[2][39]="c";
	chars[2][40]="v";
	chars[2][41]="b";
	chars[2][42]="n";
	chars[2][43]="m";
	chars[2][44]=",";
	chars[2][45]=".";
	chars[2][46]="/";
	chars[2][47]=" ";
	chars[3]=new Array();
	chars[3][0]="~";
	chars[3][1]="!";
	chars[3][2]="@";
	chars[3][3]="#";
	chars[3][4]="$";
	chars[3][5]="%";
	chars[3][6]="^";
	chars[3][7]="&";
	chars[3][8]="*";
	chars[3][9]="(";
	chars[3][10]=")";
	chars[3][11]="_";
	chars[3][12]="+";
	chars[3][13]="|";
	chars[3][14]="Q";
	chars[3][15]="W";
	chars[3][16]="E";
	chars[3][17]="R";
	chars[3][18]="T";
	chars[3][19]="Y";
	chars[3][20]="U";
	chars[3][21]="I";
	chars[3][22]="O";
	chars[3][23]="P";
	chars[3][24]="{";
	chars[3][25]="}";
	chars[3][26]="A";
	chars[3][27]="S";
	chars[3][28]="D";
	chars[3][29]="F";
	chars[3][30]="G";
	chars[3][31]="H";
	chars[3][32]="J";
	chars[3][33]="K";
	chars[3][34]="L";
	chars[3][35]=":";
	chars[3][36]="\"";
	chars[3][37]="Z";
	chars[3][38]="X";
	chars[3][39]="C";
	chars[3][40]="V";
	chars[3][41]="B";
	chars[3][42]="N";
	chars[3][43]="M";
	chars[3][44]="<";
	chars[3][45]=">";
	chars[3][46]="?";
	chars[3][47]=" ";
	chars[4]=new Array();
	chars[4][0]="`";
	chars[4][1]="1";
	chars[4][2]="2";
	chars[4][3]="3";
	chars[4][4]="4";
	chars[4][5]="5";
	chars[4][6]="6";
	chars[4][7]="7";
	chars[4][8]="8";
	chars[4][9]="9";
	chars[4][10]="0";
	chars[4][11]="-";
	chars[4][12]="=";
	chars[4][13]="\\";
	chars[4][14]="/";
	chars[4][15]="'";
	chars[4][16]=String.fromCharCode(1511); //ч
	chars[4][17]=String.fromCharCode(1512); //ш
	chars[4][18]=String.fromCharCode(1488); //а
	chars[4][19]=String.fromCharCode(1496); //и
	chars[4][20]=String.fromCharCode(1493); //е
	chars[4][21]=String.fromCharCode(1503); //п
	chars[4][22]=String.fromCharCode(1501); //н
	chars[4][23]=String.fromCharCode(1508); //ф
	chars[4][24]="["
	chars[4][25]="]";
	chars[4][26]=String.fromCharCode(1513); //щ
	chars[4][27]=String.fromCharCode(1491); //г
	chars[4][28]=String.fromCharCode(1490); //в
	chars[4][29]=String.fromCharCode(1499); //л
	chars[4][30]=String.fromCharCode(1506); //т
	chars[4][31]=String.fromCharCode(1497); //й
	chars[4][32]=String.fromCharCode(1495); //з
	chars[4][33]=String.fromCharCode(1500); //м
	chars[4][34]=String.fromCharCode(1498); //к
	chars[4][35]=String.fromCharCode(1507); //у
	chars[4][36]=",";
	chars[4][37]=String.fromCharCode(1494); //ж
	chars[4][38]=String.fromCharCode(1505); //с
	chars[4][39]=String.fromCharCode(1489); //б
	chars[4][40]=String.fromCharCode(1492); //д
	chars[4][41]=String.fromCharCode(1504); //р
	chars[4][42]=String.fromCharCode(1502); //о
	chars[4][43]=String.fromCharCode(1510); //ц
	chars[4][44]=String.fromCharCode(1514); //ъ
	chars[4][45]=String.fromCharCode(1509); //х
	chars[4][46]=".";
	chars[4][47]=" ";
	chars[5]=new Array();
	chars[5][0]="~";
	chars[5][1]="!";
	chars[5][2]="@";
	chars[5][3]="#";
	chars[5][4]="$";
	chars[5][5]="%";
	chars[5][6]="^";
	chars[5][7]="&";
	chars[5][8]="*";
	chars[5][9]="(";
	chars[5][10]=")";
	chars[5][11]="_";
	chars[5][12]="+";
	chars[5][13]="|";
	chars[5][14]="/";
	chars[5][15]="'";
	chars[5][16]=String.fromCharCode(1511); //ч
	chars[5][17]=String.fromCharCode(1512); //ш
	chars[5][18]=String.fromCharCode(1488); //а
	chars[5][19]=String.fromCharCode(1496); //и
	chars[5][20]=String.fromCharCode(1493); //е
	chars[5][21]=String.fromCharCode(1503); //п
	chars[5][22]=String.fromCharCode(1501); //н
	chars[5][23]=String.fromCharCode(1508); //ф
	chars[5][24]="{"
	chars[5][25]="}";
	chars[5][26]=String.fromCharCode(1513); //щ
	chars[5][27]=String.fromCharCode(1491); //г
	chars[5][28]=String.fromCharCode(1490); //в
	chars[5][29]=String.fromCharCode(1499); //л
	chars[5][30]=String.fromCharCode(1506); //т
	chars[5][31]=String.fromCharCode(1497); //й
	chars[5][32]=String.fromCharCode(1495); //з
	chars[5][33]=String.fromCharCode(1500); //м
	chars[5][34]=String.fromCharCode(1498); //к
	chars[5][35]=":"; 
	chars[5][36]=String.fromCharCode(34); //"
	chars[5][37]=String.fromCharCode(1494); //ж
	chars[5][38]=String.fromCharCode(1505); //с
	chars[5][39]=String.fromCharCode(1489); //б
	chars[5][40]=String.fromCharCode(1492); //д
	chars[5][41]=String.fromCharCode(1504); //р
	chars[5][42]=String.fromCharCode(1502); //о
	chars[5][43]=String.fromCharCode(1510); //ц
	chars[5][44]="<";
	chars[5][45]=">";
	chars[5][46]="?";
	chars[5][47]=" ";
	chars[6]=new Array();
	chars[6][0]=" ";
	chars[6][1]=" ";
	chars[6][2]=" ";
	chars[6][3]=" ";
	chars[6][4]=" ";
	chars[6][5]=" ";
	chars[6][6]=" ";
	chars[6][7]=" ";
	chars[6][8]=" ";
	chars[6][9]=" ";
	chars[6][10]="°";
	chars[6][11]="—";
	chars[6][12]="±";
	chars[6][13]=" ";
	chars[6][14]=" ";
	chars[6][15]=" ";
	chars[6][16]=" ";
	chars[6][17]="®";
	chars[6][18]="™";
	chars[6][19]=" ";
	chars[6][20]=" ";
	chars[6][21]=" ";
	chars[6][22]=" ";
	chars[6][23]="§";
	chars[6][24]=" ";
	chars[6][25]=" ";
	chars[6][26]=" ";
	chars[6][27]=" ";
	chars[6][28]=" ";
	chars[6][29]=" ";
	chars[6][30]=" ";
	chars[6][31]=" ";
	chars[6][32]=" ";
	chars[6][33]=" ";
	chars[6][34]=" ";
	chars[6][35]=" ";
	chars[6][36]=" ";
	chars[6][37]=" ";
	chars[6][38]=" ";
	chars[6][39]="©";
	chars[6][40]=" ";
	chars[6][41]=" ";
	chars[6][42]="№";
	chars[6][43]=" ";
	chars[6][44]="«";
	chars[6][45]="»";
	chars[6][46]=" ";
	chars[6][47]=" ";
	}

function KeyPressed()
{
	if (event.keyCode == '13')
	{
		
			puttext();
		
		//window.close();
	}
}

function SpecialChar13Press()
{
	var res = new String();
	if (document.all.char13.value == "\\")
		document.all.CommentTxt.value += '\\';
	else
		document.all.CommentTxt.value += document.all.char13.value;
}
			



function z()
{
	window.focus();
}

function setmode(val)
{
if (val==4)
{
	switch (kbdflags)
	{
		case 0:
			kbdflags+=2;
			break;
		case 1:
			kbdflags+=2;
			break;
		case 2:
			kbdflags-=2;
			break;
		case 3:
			kbdflags+=2;
			break;			
		case 4:
			kbdflags=0;
			break;
		case 5:
			kbdflags=1;
			break;
		default:
			kbdflags=0;
	}
}
else
{
	if (val==6)
	{
		if (kbdflags==6)
		{
			kbdflags=lastkbdflags;
		}
		else
		{
			lastkbdflags=kbdflags;
			kbdflags=6;
		}
	}
	else
	{
		kbdflags^=val;
	}
}

//with (document.forms.kbd){
	if (kbdflags==6)
		;//document.all.mode[3].checked=true;
	else{
		if (kbdflags&4)
			document.all.mode[2].checked=true;
		else
		{
			document.all.mode[0].checked=!(kbdflags&2);
			document.all.mode[1].checked=(kbdflags&2)
		}
	}
	document.all.shift.checked=kbdflags&1;
	kbdmode=(kbdflags>6)?6:kbdflags;

	for (i=0;i<=47;i++) 
	{
		eval("document.all.char"+i+".value=(chars[kbdmode]["+i+"]==' ')?' ':chars[kbdmode]["+i+"];");
	}
	document.all.char47.value="SPACE";
	if ((kbdflags==4) || (kbdflags==5))
	{
		document.all.CommentTxt.dir="rtl";
		//if (areaexist) openerFrm.elements[openerElmNum].dir = "rtl";
	}
	if ((kbdflags>=0) && (kbdflags<=3))
	{
		document.all.CommentTxt.dir="ltr";
		//if (areaexist) openerFrm.elements[openerElmNum].dir = "ltr";
	}
//}
}

function checkradio()
{
kbdflags=((document.all.shift.checked)?1:0)|((document.all.mode[1].checked)?2:0)|((document.all.mode[2].checked)?6:0);//|((document.all.mode[3].checked)?6:0);
setmode(0);
}

function addchar(val)
{
	document.all.CommentTxt.value+=chars[kbdmode][val];
	setmain();
}

function setmain()
{
//if (areaexist) eval(area+"=\""+document.all.CommentTxt.value+"\"")
//if (areaexist) openerFrm.elements[openerElmNum].value=document.all.CommentTxt.value;
}

function doenter()
{
if (lines>1) document.all.CommentTxt.value+="\n";else alert("Перевод строки в однострочном тексте не допускается!");
setmain();
}

function backspace()
{
with (document.all.CommentTxt) value=(value.charAt(value.length-1)=="\n")?value.substr(0,value.length-2):value.substr(0,value.length-1);
setmain();
}

function gettext()
{
	init='';
	
	
	//openerFrm = window.opener.kbdFrm;
	//openerElmNum = window.opener.elmNum;
	area="document.all."+openerElmNum.id+".value";
	
	if (eval(area+"=='Наберите слово'")) eval(area+"=''");
	
	areaexist=(area=="document.forms..value" || opener==null)?false:(""+eval("typeof "+area))=="string";


if (areaexist){
	savetext=eval(area);
	document.all.CommentTxt.value=(init!='')?init:savetext;
	setmain();
}
}

function restoretext()
{

//if (areaexist){
	document.all.CommentTxt.value=savetext;
	setmain();
	window.close();
//}

}
function DoEnterasse()
{
	puttext();	
	OpenHideKeyboard();
}
function puttext()
{
areaexist = true;

//if (areaexist){



	setmain();
	
	

		
	
	//window.close();
//}else{
//	if (confirm("Закрыть без сохранения набранного Вами текста?")) window.close();
//	else{
//		document.all.CommentTxt.focus();
//		document.all.CommentTxt.select();
//	}
//}
}

function ClearInterval()
{
	clearInterval(interval);
}

function OpenHideTranslit()
{

    divSource = document.getElementById("divSource");
	divAnimation = document.getElementById("divAnimation");
	divTranslit = document.getElementById("divTranslit");
	thisObj = divTranslit;
	SetMaxHeight(80);
	ClearInterval();
	if (divSource.style.display == "block")
	{
		divSource.style.display = "none";
	}
	if (divTranslit.style.display == "block")
	{
		AutoTranslate = false;
		CloseObject();
		}
	else
	{
		AutoTranslate = true;		
		OpenObject();
		}
	
}
			
function OpenHideKeyboard()
{
	divSource = document.getElementById("divSource");
	divAnimation = document.getElementById("divAnimation");
	divTranslit = document.getElementById("divTranslit");
	thisObj = divSource;	
	SetMaxHeight(190);
	ClearInterval();
	AutoTranslate = false;
	if (divTranslit.style.display == "block")
	{
		divTranslit.style.display = "none";
	}
	if (divSource.style.display == "block")
		CloseObject();
	else
		OpenObject( );
}


function OpenObject(obj)
{
	divAnimation.style.display = "block";
	interval = window.setInterval(DoOpenStep, 10);						
}

function CloseObject()
{
	thisObj.style.display = "none";
	divAnimation.style.display = "block";
	interval = window.setInterval(DoCloseStep, 10);						
}

function DoOpenStep()
{

	if (parseInt(divAnimation.style.height) < GetMaxHeight())
	{
		divAnimation.style.height = parseInt(divAnimation.style.height) + 10 + "px";
	}
	else
	{
		divAnimation.style.display = "none";
		thisObj.style.display = "block";
		ClearInterval();		
		document.all.CommentTxt.focus();
	}	
}


function DoCloseStep()
{
	var precision;

	if (parseInt(divAnimation.style.height) > 0)
	{	
		if (GetMaxHeight() < 10)
			precision = GetMaxHeight() * -1;
		else
			precision = -10;
			
		divAnimation.style.height = parseInt(divAnimation.style.height) + precision + "px";
	}
	else
	{
		divAnimation.style.display = "none";
		divSource.style.display = "none";
		ClearInterval();
		document.getElementById("imgKeyboard").style.display = "block";
		document.all.CommentTxt.focus();
	}
}





function GetMaxHeight()
{
	return parseInt(divAnimation.getAttribute("maxHeight"));
}
function SetMaxHeight(val)
{
	
	divAnimation.setAttribute("maxHeight" ,val) ;
}