var gAddMeanPron = true;
var gCommand = 'recognize';
var gLabels = new Array();
var gLetterResult = new Array();
var gMeanResult = new Array();
var gAction;
var gTabelRow = 0;

function recognizeHanja()
{		
	var btObj = document.getElementById("btnRecognition");
	btObj.style.display = "none";

	gCommand = 'recognize';
	
	inputPanelCommand('getRowdata');

	if (gAction == "HanjaPractice")
		hideHint();
}

function checkMeanPron(inputObj)
{
	gAddMeanPron = inputObj.checked;
}


function initRecognitionResult(bVisible)
{	
	if(bVisible == undefined)
		bVisible =  true;
	var divObj = document.getElementById("resultNothing");
	divObj.style.display = bVisible ? "inline-block" : "none";
}
function initResultTable()
{
	oTable = document.getElementById('__resultList');	
	for(j = oTable.rows.length-1 ; j >= 2 ; j--)
		oTable.rows[j].removeNode(true);
}

function recognizeCallback(value)
{
	reset();
	initRecognitionResult(false);
	
	initResultTable();
	var re = null;
	
	if(gAddMeanPron)
	{
		re = /\[(.+?):(.+?):(.*?)\]/g;
	}
	else
	{
		re = /\[(.+?):(.+?)\]/g;
	}
	
	var i = 0;
	var arr;

	var arrData = [];
	
	// Loop over all the regular expression matches in the string.
	var obj = document.getElementById("InputPanel");
	while ((arr = re.exec(value)) != null)
	{
		gLetterResult[i] = new Array();
		gLetterResult[i] = arr[2].split(',');

		gMeanResult[i] = new Array();
		gMeanResult[i] = arr[3].split(',');		
		i++;		
		gTabelRow = i;
	}	
	show(g('resultArea'));	

	for (var i = 0; i < gLetterResult.length ; i++ )
	{
		insertRow(g('__resultList'), [
			i+1,
			"<div style='font-size:14pt;font-weight:bold;padding:4px;'>" + gLetterResult[i].join(',') + "</div>",
			"<div style='text-align:left;'>" + gMeanResult[i].join(',') + "</div>"
		]);
	}

	var btObj = document.getElementById("btnRecognition");
	btObj.style.display = "inline";	

	// 결과가 없는 경우,
	if (i == 1)
	{
		alert('[시스템 장애]\n\n언어닷컴 한자 모양 인식 서버와 연결 할 수 없습니다. 관리자에게 문의하여 주십시오\n\n계속 같은 메시지가 나온다면 새로고침을 해보시기 바랍니다.');
		
	}
}

function reset()
{
	gLabels = new Array();
	initRecognitionResult();	
	initResultTable();
	inputPanelCommand('reset');

}

function inputPanelCommand(command)
{
	var obj = document.getElementById("InputPanel");

	if(obj)
		obj.setVariable("execFunction", command);
}


