function ShowEduTask8(id)
{
    TaskId = id;
    MakeDataRequest(Handler8, 8);
}



function Handler8(data)
{

	var oAnswersDiv = ShowContent(data, ButtonHandler8);
	oAnswersDiv.id = 'EduVariantDiv';

	var contSpan= document.createElement('span');
	contSpan.id = "contSpan";

	var strCon = data.getAttribute("content");
	
	strCon = strCon.replace(/<v>(.*?)<\/V>/ig,'<span class="variantClass">$1</span>');
	strCon = strCon.replace(/<word>(.*?)<\/Word>/ig,'<span class="wordClass">$1</span>');
	strCon = strCon.replace(/<w>(.*?)<\/W>/ig,'<span class="wordClass">$1</span>');
	strCon = strCon.replace(/<l.*?size="(.*?)".*?\/>/gi, '<span class="letClass"><input type="text" size="$1" /></span>');
	strCon = strCon.replace(/<l\/>/ig, '<span class="letClass"><input type="text" size="1"/></span>');
	strCon = strCon.replace(/<para\/>/ig, '<br/>');
	
	contSpan.innerHTML=strCon;
	
	for (var i =0 ; i < contSpan.childNodes.length; i++)
	{
		if (contSpan.childNodes[i].nodeName == "span".toUpperCase( ))
		{
		checkL (contSpan.childNodes[i]);
		}
	}
	oAnswersDiv.appendChild(contSpan);
	

	var oContentDiv = document.getElementById('EduVariantDiv');
	var activeBox = oContentDiv.getElementsByTagName('input');

		
	var tipSpan= document.createElement('div');
	tipSpan.id = "tipSpan";
	tipSpan.innerHTML="Accept (ENTER)";
	var mainDv= document.getElementById('Maindv');
	mainDv.appendChild(tipSpan);
	
	nextActive(0);
	
function nextActive (i)
{
	
	if (i ==(activeBox.length)) 
	{
	var mainDv= document.getElementById('Maindv');
	var tip = document.getElementById('tipSpan');
	mainDv.removeChild(tip);
	return 0;
	}
	
	activeBox[i].disabled=false;
	activeBox[i].focus();
	
	
	var tip = document.getElementById('tipSpan');
	var x = pageX(activeBox[i]);
	var y = pageY(activeBox[i]);
	tip.style.left=x+ 25 + 'px';
	tip.style.top=y - 25+ 'px';
	
	var letter= document.createElement('span');
	letter.id = "letter";

	activeBox[i].onkeydown=catchEnter;

	function catchEnter(event)
	{
		var key;
		var answer;
		if (window.event)
		key =window.event.keyCode;
		else 
		key = event.keyCode;
		
		if (key == 13)
		{
			if (activeBox[i].value == ' ')
			{
			letter.innerHTML= '&nbsp';
			answer="_";
			}
			else
			{
			letter.innerHTML=activeBox[i].value;
			answer=activeBox[i].value;
			if (activeBox[i].value == "")
			answer="^";
			}
			
			var pSpan = activeBox[i].parentNode;
			activeBox[i].disabled=true; 
			activeBox[i].style.display='none';
			pSpan.appendChild(letter); 
		
			
			var an = document.getElementById('txtbox'+i).id + '=' + answer; 
			
			//alert(an);
			
			ProcessAjax
			({
			method: 'GET',
			data: an,
			url: 'Answer.xml',
			callback: function(resp){
			var obj = resp.getElementsByTagName('answer');
			var answ = obj[0];
			var code = answ.getAttribute('code');
			if (code==1)
			{
			showError(answ);
			letter.className="wrongLet";
			}
			else
			{
			nextActive(i+1);
			letter.className="rightLet";
			}
			},
			errback: 'undefined',
			beforeSend: 'undefined'
			});

			
			function showError(answ)
			{
			var errSpan= document.createElement('div');
			errSpan.id = "errSpan";
			errSpan.innerHTML= answ.getAttribute('header') + '<br/>'+ answ.getAttribute('title') + '<br/>' + answ.getAttribute('rule') + '<br/>'; 
			var mainDv= document.getElementById('Maindv');
			errSpan.style.left=x+ 'px';
			errSpan.style.top=y + 'px';
			var butOk = document.createElement('input');
			butOk.id="butOk";
			butOk.type = "button";
			butOk.value = "OK";
			butOk.onclick = function () {mainDv.removeChild(errSpan); nextActive(i+1);}
			errSpan.appendChild(butOk);
			mainDv.appendChild(errSpan);
		
			}
			
			
			
		}

	}
}	
}


var txtboxId=0;

function checkL (child)
{
var  childObj = child;
	for (var i =0 ; i< childObj.childNodes.length; i++)
	{
		if (childObj.childNodes[i].nodeName == "span".toUpperCase( )) 
		checkL (childObj.childNodes[i]);
			
		if (childObj.childNodes[i].nodeName == "input".toUpperCase( )) 
		{
			var txtSize = childObj.childNodes[i].getAttribute('size');
			var pan= document.createElement('span');
			pan.id = "pan";
			
			var oTextbox = document.createElement('input'); 
			oTextbox.type = 'text'; 
			oTextbox.id = 'txtbox' + txtboxId;
			txtboxId++;
				if (txtSize==1)
				oTextbox.className = 'pix';
			oTextbox.size = txtSize;
			oTextbox.maxLength = txtSize;
			oTextbox.disabled = true;
			//oTextbox.tabIndex = 1;	
			pan.appendChild(oTextbox);
			childObj.replaceChild(pan,childObj.childNodes[i]); 
		}
	}
}





function pageX(elem) {
       return elem.offsetParent ?
               elem.offsetLeft + pageX( elem.offsetParent ) :
               elem.offsetLeft;
}

function pageY(elem) {
       return elem.offsetParent ?
               elem.offsetTop + pageY( elem.offsetParent ) :
               elem.offsetTop;
}






function ButtonHandler8()
{
	var sAnswers = "Пустая строка";
	alert(sAnswers);	
	var mainDv= document.getElementById('Maindv');
	var tip = document.getElementById('tipSpan');
	mainDv.removeChild(tip);
	SendReply(sAnswers);
}



