if(!this.RecogMgr) {
	this.RecogMgr = new Object();
}

//for voice recognition command string
if(!this.g_Voice) {
	this.g_Voice = new Object();
}

RecogMgr ={
	
	isVoiceRecog : false,
	voiceHelpbarInfo : new Object(),
	voiceHelpbarInfo : { helpbarItemsList: new Array() , candidateList : new Array()},
	categoryList : new Array(),	
	contactList : new Array(),
	callList : new Array(),
	incomingCallList : new Array(),
	voiceCallText : "",
	videoCallText : "",
	declineText : "",
	cancelText : "",
	exitText : "",
	answerText : "",
	
	isFaceRegistrationAfterSignin : false, //init
	isSigninAfterPwdCheck : false, //init
	CountOfRecogFail : 0,
	CountOfTrainingFail : 0,
	
	voiceRecogStep : "Init",
	recogContactIndex : 0,
	recogContactName : 0,
	
	//add by minseok
	isTraining : false,
	trainArray : new Array(),
	trainIndex : 0,
	isSuccessTraining : false,
	faceIndex : 0,
	trainResult : null
}
///////Face Recognition //////////////////////////////////////////////////////////////////////
RecogMgr.OnFaceRecogEvent = function(strEvent, Result)
{
	alert("****RecogMgr.OnFaceRecogEvent");
	
	if((StateMgr.GetCurrentState()!="FaceRecogSignin") &&(StateMgr.GetCurrentState()!="FaceRecogRegistration"))
	{
		alert("Can not process this Event");
		return;
	}
	
	switch(strEvent)
	{
		case "EVENT_FR_ON_RECOGNIZING":
			this.ProcessOnRecognizing(Result, false);
		break;
		
		case "EVENT_FR_RECOGNITION_RESULT":
			this.ProcessOnRecognizing(Result, true);
			this.ProcessRecogResult(Result);
		break;
		
		case "EVENT_FR_RECOGNITION_FAIL":
			this.ProcessRecogFail();
		break;
		
		case "EVENT_FR_DETECT_FACE":
			this.ProcessDetectFace(Result);
		break;
		
		case "EVENT_FR_DETECTION_FAIL":
			if(StateMgr.GetCurrentState()=="FaceRecogSignin" && this.isTraining==true){
				RecogMgr.ProcessTrainThumnailResult(false);
			}
		break;
		
		case "EVENT_FR_TRAIN_RESULT":
			this.ProcessTrainResult(Result);		
		break;
	}
}

RecogMgr.ProcessOnRecognizing = function(face_info, recoged)
{
	alert("ProcMgr.ProcessOnRecognizing");
	
	var result = JSON.parse(face_info);
	var result_info = null;
	
	if(recoged==false)
	{
		if(result.detectResult==null)
		{
			return;	
		}
		else
		{
			result_info = result.detectResult;
		}
	}
	else
	{
		result_info= result.recognitionResult;
	}

	var areaInfo = new Array();
	var inside_stroke =2;
	var area_x = 146;
	var area_y = 237;
	var area_width =600;
	var area_height =450;
	// var area_width =640;
	// var area_height =360;
	
	this.CountOfRecogInfo++;
	var index =0;
	// this.DrawFace(result_info);
	this.faceIndex = 0;
	$("#drawface_div").remove();
	var HTMLString = "<div id='drawface_div'><div>";
	$("#FaceRecogSignin").append(HTMLString);
	for(var i=0; i<result_info.length;i++){
		//1080 -> 720
		var x=result_info[i].x*0.66;
		var y=result_info[i].y*0.66;
		var w=result_info[i].w*0.66;
		var h=result_info[i].h*0.66; 
		
		x+=113.9;	y+=220;
		// y+=145;		w*=0.8;	h*=0.8;
		if(x<area_x || x+w > (area_width+area_x) || y<area_y || y+h > (area_height+area_y))
		{
			alert("ProcMgr.ProcessOnRecognizing -> out of area : "+i);
			 continue;
		}
		areaInfo[index]=new Object();
		areaInfo[index].x = x;
		areaInfo[index].y = y;
		areaInfo[index].w = w;
		areaInfo[index].h = h;
		
		var id = -1; 
		if(recoged==false)
		{
			id = result_info[i].nDetectID; 
		}
		else
		{
			id = result_info[i].nFaceRecogID;
		}
		
		if(id == -1)			//no id detected
		{
			areaInfo[index].registered = false;
		}
		else
		{
			areaInfo[index].registered = true;
		}
		
		index++;
		
	}
	g_Data.SetFaceRecogAreaInfo(areaInfo);
	for(var i=0;i<areaInfo.length;i++){
		this.DrawFace(areaInfo[i]);
	}
	
}

RecogMgr.ProcessRecogResult= function(face_info)
{
	alert("ProcMgr.ProcessRecogResult");
	
	this.isFaceRegistrationAfterSignin = false; //init
	this.isSigninAfterPwdCheck=false; //init
	
	ProcMgr.PauseFaceRecog(false);
	
	var result = JSON.parse(face_info);

	var saved_info = PluginAPIMgr.GetMyStorageInfo();
	var info = null;
	var i=0;
	var j=0;
	var index =0;
	g_Data.SetFaceRecogResultData(result);
	
	
	var confirmResult = new Array();
	/**
	 * saved_info == info
	 * "SkypeAccount":[
	 * 		{
	 * 			"id" :
	 * 			"face" :
	 * 			"face_id" : 
	 * 			"pwd_check" : 
	 * 			"pwd" :  
	 * 		}
	 * ]
	 * 
	 * face_info == result
	 * "recognitionResult" : [
	 *		{
	 * 			"h" : 
	 * 			"imageFilePath" : 
	 * 			"nFaceRecogID" :
	 * 			"w" : 
	 * 			"x" : 
	 * 			"y" : 
	 * 		} 
	 * ]
	 */
	
	
	if(saved_info)
	{
		info = JSON.parse(saved_info);
		
		alert("***** ProcMgr.ProcessRecogResult() --> saved_info : "+saved_info);	
		
		for (i=0; i < result.recognitionResult.length; i++ )		
		{	
			for(j=0; j < info.SkypeAccount.length; j++)
			{
				if(info.SkypeAccount[j].face == result.recognitionResult[i].imageFilePath)
				{	
					confirmResult[index] =new Object();
					confirmResult[index].face = result.recognitionResult[i].imageFilePath;				
					confirmResult[index].id = info.SkypeAccount[j].id;
					confirmResult[index].pwd = info.SkypeAccount[j].pwd;
					confirmResult[index].registered = true;
					if(info.SkypeAccount[j].pwd_check == 'undefined')
					{
						confirmResult[index].pwd_check = false;
					}
					else
					{
						confirmResult[index].pwd_check = info.SkypeAccount[j].pwd_check ;
					}
					
					index++;
					break;					
				}
			}
		}
		
		var registeredResult = confirmResult;
		
		for (i=0; i < result.recognitionResult.length; i++ )		
		{
			var saved = false
			for(j=0; j < registeredResult.length; j++)
			{
				if(registeredResult[j].face == result.recognitionResult[i].imageFilePath)
				{	
					saved = true;
					break;					
				}
			}
			
			if(saved==false)
			{
				confirmResult[index] =new Object();
				confirmResult[index].face = result.recognitionResult[i].imageFilePath;				
				confirmResult[index].id = "none";
				confirmResult[index].pwd = "none";
				confirmResult[index].registered = false;
				confirmResult[index].pwd_check = false;
				
				index++;
			}
		}		
	}
	else
	{
		for (i=0; i < result.recognitionResult.length; i++ )		
		{
			confirmResult[index] =new Object();
			confirmResult[index].face = result.recognitionResult[i].imageFilePath;				
			confirmResult[index].id = "none";
			confirmResult[index].pwd = "none";
			confirmResult[index].registered = false;
			confirmResult[index].pwd_check = false;
			
			index++;
		}
	}
	
	alert("ProcMgr.ProcessRecogResult -> number of confirmResult : "+confirmResult.length);
	
	if(confirmResult.length==1 && confirmResult[0].id != "none")
	{
		if(confirmResult[0].pwd_check==false)
		{
			ProcMgr.Signin(confirmResult[0].id, confirmResult[0].pwd, false);
		}
		else
		{
			g_Data.SetFaceRecogResult(confirmResult);
			ProcMgr.ProcessSigninAfterPwdCheck(0);
		}		
	}
	else
	{		
		g_Data.SetFaceRecogResult(confirmResult);
		this.ProcessTrainThumnail();
		// WndMgr.ResultStepFaceRecogSignin();
	}
	
	this.CountOfRecogFail=0;
}
/**
 * result ={
 * 	face : 
 *  id : 
 *  pwd : 
 *  registered : 
 *  pwd_check:
 * }
 */
RecogMgr.ProcessTrainThumnail = function(){
	alert("RecogMgr.ProcessTrainThumnail()");
	if(this.isTraining==false){		//init
		alert("init data....")
		this.isTraining = true;
		this.trainIndex = 0;
		this.trainArray = new Array();
	}
	var result = g_Data.GetFaceRecogResult();
	var length = result.length;
	alert(this.trainIndex);
	if(length < 1){								//no result, end train
		this.isTraining = false;
		// g_Data.SetFaceRecogResult(result);
		WndMgr.ResultStepFaceRecogSignin();
	}else{
		alert(result[this.trainIndex].id);
		if(result[this.trainIndex].id=="none"){						//unknown id
			var path = result[this.trainIndex].face;
			alert("trainThumnail path : "+path);
			PluginAPIMgr.FaceTrainingThumnail(path);
		}else{													//registered face
			this.ProcessTrainThumnailResult(true);
		}
	}
}
RecogMgr.ProcessTrainThumnailResult = function(resultFlag,train_result){
	alert("RecogMgr.ProcessTrainThumnailResult()");
	var result = g_Data.GetFaceRecogResult();
	var length = result.length;
	if(resultFlag==true){	//event : EVENT_FR_TRAIN_RESULT		
		alert("event : EVENT_FR_TRAIN_RESULT");
		if(train_result==undefined){
			result[this.trainIndex].train_result = null; 
		}else{
			result[this.trainIndex].train_result = train_result;
		}
		this.trainArray.push(result[this.trainIndex]);
	}else{					//event : EVENT_FR_DETECTION_FAIL

	}
	this.trainIndex++;
	if(this.trainIndex>=result.length){	//end training, go next step
		g_Data.SetFaceRecogResult(this.trainArray);
		this.isTraining=false;
		WndMgr.ResultStepFaceRecogSignin();
	}else{
		this.ProcessTrainThumnail();				//train thumnail next item
	}
}
RecogMgr.SetTrainResultFromPath= function(imagePath){
	alert("RecogMgr.SetTrainResultFromPath() : "+imagePath);
	var result = g_Data.GetFaceRecogResult();
	for(var i=0;i<result.length;i++){
		if(result[i].face==imagePath){
			alert("match face : "+result[i].face);
			this.trainResult = result[i].train_result;
		}
	}
}
RecogMgr.ProcessRecogFail= function()
{	
	this.isFaceRegistrationAfterSignin = false; //init
	this.isSigninAfterPwdCheck=false; //init
	
	this.CountOfRecogFail++;
	var confirmResult = new Array();
	
	alert("RecogMgr.ProcessRecogFail-> count of fail : "+ this.CountOfRecogFail);
	
	if(this.CountOfRecogFail>=10)
	{
		g_Data.SetFaceRecogResult(confirmResult);
		WndMgr.ResultStepFaceRecogSignin();
		this.CountOfRecogFail=0;
	}
	else
	{
		ProcMgr.PauseFaceRecog(false);
		ProcMgr.RetryFaceRecog();
	}	
}
/**
 * face_info 
 * face_info={
 * 	"detectResult" : -10
 * 	"h" : 
 *  "imageFilePath" : return image path
 * 	"w" : 
 * 	"x" : 
 * 	"y" : 
 * }
 */
RecogMgr.ProcessTrainResult= function(face_info)
{
	alert("RecogMgr.ProcessTrainResult -> count of fail : "+this.CountOfTrainingFail);
	var result = JSON.parse(face_info);
	var result_id = result.detectResult;
	
	this.trainResult = null;
	
	if(result_id<0)
	{
		this.CountOfTrainingFail++;
		if(this.CountOfTrainingFail==100)
		{
			ProcMgr.StopFaceTraining();
			WndMgr.RetryNotyStepFaceRecogRegistration();		
			
			this.CountOfTrainingFail=0; //init
			// ProcMgr.RetryFaceDetect();
			return;
		}
		
		if(result_id==-10)
		{
			alert("Training..., please wait");
		}
		else
		{
			var currentState =StateMgr.GetCurrentState();
			if(currentState=="FaceRecogSignin" && this.isTraining==true){
				alert("From TrainThumbnail!!!");
				ProcMgr.StopFaceTraining();
				if( result_id==-100)
				{
					alert("too many face.. : full engine DB");
					sf.scene.get('FaceRecogSignin').initRecogArea();		//init area
					WndMgr.NotRegisteredStepFaceRecogSignin();
				}
			}else{
				WndMgr.UpdateFaceRecogBoxColor(g_Image.IMAGE_FACE_RECOG_REGISTRATION_BOX_RED);
				ProcMgr.StopFaceTraining();
				if( result_id==-100)
				{
					alert("too many face..");
					//if(this.CountOfTrainingFail>90){
						WndMgr.RetryNotyStepFaceRecogRegistration();
					/*}else{
						ProcMgr.RetryFaceDetect();
					}*/
				}
				else
				{
					alert("Fail face training~!!");
					ProcMgr.RetryFaceDetect();				
				}	
			}
		}
	}	
	else
	{
		alert("Success face training~!!");
		var flagDuplicate = ProcMgr.CheckImageDuplicate(result.imageFilePath, result_id);
		if(flagDuplicate== true)
		{
			ProcMgr.StopFaceRecogRegistration();
			WndMgr.DuplicateStepFaceRecogRegistration();
		}
		else
		{
			this.CountOfTrainingFail=0; //init
			this.isSuccessTraining = true;
			this.trainResult = result;
			// ProcMgr.StopFaceDetect();
			// ProcMgr.StopFaceTraining();
			var currentState =StateMgr.GetCurrentState();
			
			if(currentState=="FaceRecogSignin" && this.isTraining==true){
				alert("From TrainThumbnail!!!");
				RecogMgr.ProcessTrainThumnailResult(true,result);
				// ProcMgr.StartFaceRegistrationFromTrainThumnail();
			}else{
			
				WndMgr.UpdateFaceRecogBoxColor(g_Image.IMAGE_FACE_RECOG_REGISTRATION_BOX_GREEN+g_Data.GetImgSuffixPath());
				setTimeout(function(){
				ProcMgr.StopFaceDetect();
				ProcMgr.StopFaceTraining();
				// ProcMgr.SetMyFaceImagePath(result.imageFilePath, result_id); 		
				WndMgr.NextStepFaceRecogRegistration();	
				},500);
			}
		}
	}
}
/**
 * Result = {
   "detectResult" : [
      {
         "h" : 240,
         "nDetectID" : 1,
         "w" : 240,
         "x" : 292,
         "y" : 330
      }
   ]
}

Result = {
   "detectResult" : [
      {
         "h" : 198,
         "nDetectID" : 2,
         "w" : 258,
         "x" : 339,
         "y" : 60
      },
      {
         "h" : 186,
         "nDetectID" : 6,
         "w" : 216,
         "x" : 552,
         "y" : 105
      },
      {
         "h" : 198,
         "nDetectID" : 9,
         "w" : 198,
         "x" : 120,
         "y" : 90
      }
   ]
}
 */
RecogMgr.ProcessDetectFace= function(face_info)
{
	alert("RecogMgr.ProcessDetectFace");
	var currentState =StateMgr.GetCurrentState();
	if(currentState=="FaceRecogSignin"){
		alert("dont face detect!!");
		return;
	}
	var info = JSON.parse(face_info);
	//defect : exception
	if(info.detectResult==null){
		alert("Result is Null!!!")
		return;
	}	
	var num = info.detectResult.length;
	var pos= new Array(num);
	// this.DrawFace(info.detectResult);
	var result = this.CheckArrayIsInTheBox(info.detectResult);
	if(result.length>0){
		ProcMgr.PauseFaceDetect(false);
		if(result.length==1){
			// this.DrawFace(result);
			var jsonText = this.GetFaceDetectJSONObject(result[0]);
			// ProcMgr.PauseFaceDetect(false);
			this.isSuccessTraining = false;
			ProcMgr.StartFaceTraining(jsonText);
		}else{
			// this.DrawFace(result);
			var distanceArray = new Array(result.length);
			for(var i=0;i<result.length;i++){
				distanceArray[i] = this.GetDistance(result[i]);
			}
			var index = this.GetMinDistanceIndex(distanceArray);
			// this.DrawFace(result);
			var jsonText = this.GetFaceDetectJSONObject(result[index]);
			// ProcMgr.PauseFaceDetect(false);
			this.isSuccessTraining = false;
			ProcMgr.StartFaceTraining(jsonText);
		}
	}
	
	// ProcMgr.PauseFaceDetect(false);
	// this.isSuccessTraining = false;
	// ProcMgr.StartFaceTraining(face_info);
	
}

RecogMgr.GetFaceDetectJSONObject = function(obj){
	alert("RecogMgr.GetFaceDetectJSONObject : "+obj);
	var Result = new Object();
	Result.detectResult = new Array(1);
	Result.detectResult[0] = new Object();
	Result.detectResult[0].h = obj.h;
	Result.detectResult[0].nDetectID = obj.nDetectID;
	Result.detectResult[0].w = obj.w;
	Result.detectResult[0].x = obj.x;
	Result.detectResult[0].y = obj.y;
	var jsonText = JSON.stringify(Result);
	alert(jsonText);
	return jsonText;
}
//get Minimum distance
RecogMgr.GetMinDistanceIndex = function(distance_array){
	var resultIndex = 0;
	for(var i=0;i<distance_array.length;i++){
		if(distance_array[resultIndex]>distance_array[i]){
			resultIndex = i;
		}
	}
	alert("distance index : "+resultIndex);
	return resultIndex;
}
//distance of face to point
RecogMgr.GetDistance = function(obj){
	var point_X = 446;
	var point_Y = 462
	var w = obj.w*0.66;
	var h = obj.h*0.66;
	var x = obj.x*0.66;
	var y = obj.y*0.66;	
	x+=113.9;	y+=220;
	// y += 155;	w*=0.75;	h*=0.75;
	var center_X = x + (w/2);
	var center_Y = y + (h/2);
	var tempX = point_X-center_X; 	
	var tempY = point_Y-center_Y; 	
	// var distance = Math.sqrt((tempX*tempX) + (tempY*tempY));		//dont need...just compare distance
	var distance = (tempX*tempX) + (tempY*tempY);
	return distance;
}
//face is belongs to point box??
RecogMgr.IsInThebox = function(result_obj){
	var w = result_obj.w*0.66;
	var h = result_obj.h*0.66;
	var x = result_obj.x*0.66;
	var y = result_obj.y*0.66;
	x+=113.9;	y+=220;	
	// y += 155;	w*=0.75;	h*=0.75;
	var center_X = x + (w/2);
	var center_Y = y + (h/2);
	alert("center coor : (x,y) = "+center_X+", "+center_Y);
	if(center_X>371 && center_X<520){
		if(center_Y>387 && center_Y<537){
			alert("in the box!!!!")
			return true;
		}
	}	
	return false;
}
//check array, remove face not in the box
RecogMgr.CheckArrayIsInTheBox = function(result_array){
	var num = result_array.length;
	var obj_in_box = new Array();
	for(var i=0;i<num;i++){
		if(this.IsInThebox(result_array[i])){
			obj_in_box.push(result_array[i]);
		}
	}
	alert("result obj length : "+obj_in_box.length);
	return obj_in_box;
}
/**
 * for testing...
 */

RecogMgr.DrawFace = function(obj){
	alert("RecogMgr.DrawFace");
	
	var w = obj.w;
		var h = obj.h;
		var x = obj.x;
		var y = obj.y;
		alert("h : "+h+",w : "+w+",x : "+x+",y : "+y);
		HTMLString = "<div id='drawface"+this.faceIndex+"'></div>";
		$("#drawface_div").append(HTMLString);
		$("#drawface"+this.faceIndex).css('position','absolute');
		$("#drawface"+this.faceIndex).css('width',w+'px');
		$("#drawface"+this.faceIndex).css('height',h+'px');
		$("#drawface"+this.faceIndex).css('top',y+'px');
		$("#drawface"+this.faceIndex).css('left',x+'px');
		$("#drawface"+this.faceIndex).css('border','solid');
		$("#drawface"+this.faceIndex).css('-webkit-border-radius','50% 50%');
		
		alert("obj regitered : "+obj.registered);
		if(obj.registered==true){
			$("#drawface"+this.faceIndex).css('border-color','#00ff10');
		}else{
			$("#drawface"+this.faceIndex).css('border-color','red');
		}
	
	this.faceIndex++;
	
}

///////Voice Recognition //////////////////////////////////////////////////////////////////////

RecogMgr.OnVoiceRecogEvent = function(strEvent, Result)
{
	alert("****RecogMgr.OnVoiceRecogEvent -> "+ strEvent);
	
	switch(strEvent)
	{
		case "EVENT_VOICE_BEGIN_MONITOR"+"-"+EventMgr.WidgetName:
		case "EVENT_VOICE_BTSOUND_START"+"-"+EventMgr.WidgetName:
		
			this.ProcessVoiceRecogStart();
			
		break;
		
		case "EVENT_VOICE_RECOG_RESULT"+"-"+EventMgr.WidgetName:
			this.ProcessVoiceRecogResult(Result); 
		break
		
		default:
		
		break;
		
	}	
}


RecogMgr.StartVoiceRecog= function()
{
	if(ProcMgr.IsDualViewMode()==true)
	{
		alert("***IsDualViewMode : Cannot StartVoiceRecog");
	    	return;
	}

	if(this.isVoiceRecog==false)
	{	
		if(Flag_Hidden_State==true)
		{
			return;
		}
		
		var LoginState = PluginAPIMgr.GetLoginState();
		if(LoginState != "2")
		{
			return;
		}
		
		if(PluginAPIMgr.IsCallInProgress())
		{
			return;	
		}
		
		if(PluginAPIMgr.IsInCall()==1)  // calling 
		{
			if(ProcMgr.isIncomingCall != true)
			{
				return;
			}
		}
		
		alert("***RecogMgr.StartVoiceRecog");
		PluginAPIMgr.SubscribeVoiceRecogEvent(); 
		this.isVoiceRecog = true;
		
		PluginAPIMgr.VoiceHelpbarIsActivated();
		
		RecogMgr.ProcessVoiceRecogStart();
	}
}

RecogMgr.StopVoiceRecog= function(flagHide)
{
	if(this.isVoiceRecog==true)
	{	
		if(flagHide)
		{
			RecogMgr.HideVoiceHelpbar();
		}
		
		alert("***RecogMgr.StopVoiceRecog");
		PluginAPIMgr.UnsubscribeVoiceRecogEvent();
		RecogMgr.SetHelpbarType("Init"); 
		this.isVoiceRecog = false;
	}
}

RecogMgr.HideVoiceHelpbar= function()
{
	alert("***RecogMgr.HideVoiceHelpbar");
	PluginAPIMgr.HideVoiceHelpbar();
}


RecogMgr.ProcessVoiceRecogStart= function()
{
	alert("***RecogMgr.ProcessVoiceRecogStart");
	
	var v_lang = PluginAPIMgr.GetCurrentVoiceLanguage();
	if(v_lang === 'undefined' || v_lang.length ==0)
	{
		v_lang ='en';
	}
	
	sf.core.loadJS("lang_voice/"+v_lang+".js", function(){
		
		if(ProcMgr.isIncomingCall == true)
		{
			RecogMgr.StartVoiceHelpbar("IncomingCall"); 
		}
		else
		{
			var LoginState = PluginAPIMgr.GetLoginState();
			/*if(LoginState == "0")
			{
				RecogMgr.StartVoiceHelpbar("Welcome"); 
			}
			else*/ if(LoginState == "2")
			{
				RecogMgr.StartVoiceHelpbar("Main"); 
			}
				
		}
	});
}

RecogMgr.ChangeVoiceHelpbar = function()
{
	alert("***RecogMgr.ChangeVoiceHelpbar");
	
	if(this.isVoiceRecog==true)
	{
		if(ProcMgr.isIncomingCall == true)
		{
			if(this.voiceRecogStep !="IncomingCall")
			{
				RecogMgr.StartVoiceHelpbar("IncomingCall"); 
			}		
		}
		else
		{
			if(this.voiceRecogStep !="StartCall" && this.voiceRecogStep =="Main")
			{
				RecogMgr.StartVoiceHelpbar("Main");
			}
		}
	}	
}

RecogMgr.StartVoiceHelpbar = function(step)
{
	alert("***RecogMgr.StartVoiceHelpbar");
	
	RecogMgr.SetRecogStep(step);
	
	if(this.voiceRecogStep =="Main")
	{
		this.InitVoiceHelpbarInfo("HELPBAR_TYPE_VOICE_EMBED_GUIDE", g_Voice.TV_SID_GUIDE_CALL_PERSON ,"", true ); 
		
		/*f(StateMgr.GetCurrentState()!="Main")
		{
			this.SetHelpbarItem(this.skypeText);
		}
		else
		{
			this.SetHelpbarItem(this.skypeText);
		}*/
		
		var i=0;
		var curr_main_index = this.categoryList.length;
		if(StateMgr.GetCurrentState()=="Main")
		{
			curr_main_index = WndMgr.GetMainSubIndex();
		}
		
		for(i=0; i<this.categoryList.length; i++)
		{
			if(curr_main_index==i)
			{
				continue;
			}
			
			RecogMgr.SetHelpbarItem(this.categoryList[i]);
		}
	
		for(i=0; i<this.contactList.length; i++)
		{
			RecogMgr.SetHelpbarItem(this.contactList[i]);
		}
		
		//this.SetHelpbarItem(this.exitText);
	}
	else if(this.voiceRecogStep =="StartCall")
	{
		this.InitVoiceHelpbarInfo("HELPBAR_TYPE_VOICE_CUSTOMIZE", "" ,"", true ); 

		var i=0;
		for(i=0; i<this.callList.length; i++)
		{
			RecogMgr.SetHelpbarItem(this.callList[i]);
		}
		
		this.SetHelpbarItem(this.cancelText);
		//this.SetHelpbarItem(this.exitText);
	}
	else if(this.voiceRecogStep =="IncomingCall")
	{
		this.InitVoiceHelpbarInfo("HELPBAR_TYPE_VOICE_CUSTOMIZE", "" ,"", true ); 

		var i=0;
		for(i=0; i<this.incomingCallList.length; i++)
		{
			RecogMgr.SetHelpbarItem(this.incomingCallList[i]);
		}	
		
		//this.SetHelpbarItem(this.exitText);
	}
	/*else if(this.voiceRecogStep =="Welcome")
	{
		this.InitVoiceHelpbarInfo("HELPBAR_TYPE_VOICE_CUSTOMIZE", "" ,"", true ); 
		
		if(StateMgr.GetCurrentState()!="Welcome")
		{
			this.SetHelpbarItem(this.skypeText);
		}
		else
		{
			this.SetHelpbarItem(this.skypeText);
		}
		
		//this.SetHelpbarItem(this.exitText);
	}*/

	var voiceHelpbarInfo_string = JSON.stringify(this.voiceHelpbarInfo);
	PluginAPIMgr.SetVoiceHelpbarInfo(voiceHelpbarInfo_string);	
}

RecogMgr.SetRecogStep = function(step)
{
	this.voiceRecogStep = step;
}

RecogMgr.InitVoiceHelpbarInfo = function(helpbarType, guideTest, exampleText, bKeepCurrentInfo)
{
	this.voiceHelpbarInfo = new Object();
	
	this.SetHelpbarType(helpbarType);
	this.SetGuideText(guideTest);
	this.SetExampleText(exampleText);
	this.SetKeepCurrentInfo(bKeepCurrentInfo);
	
	this.voiceHelpbarInfo.candidateList = new Array();
	this.voiceHelpbarInfo.helpbarItemsList = new Array();
	
	//var v_lang = PluginAPIMgr.GetCurrentVoiceLanguage();
	//sf.core.loadJS("lang_voice/"+v_lang+".js", function(){RecogMgr.InitVoiceRecogCandidateData()});
	RecogMgr.InitVoiceRecogCandidateData();
}

RecogMgr.InitVoiceRecogCandidateData = function()
{
	//this.skypeText = g_Voice.SID_VOICE_SKYPE_HOME;
	this.cancelText = g_Voice.SID_CANCEL;
	this.exitText = g_Voice.SID_EXIT ;
	this.voiceCallText = g_Voice.IDWS_MOIP_VOICE_CALL_KR_VOICE;
	this.videoCallText = g_Voice.IDWS_MOIP_VIDEO_CALL_KR_VOICE;
	this.declineText = g_Voice.TV_SID_VOICE_DECLINE;
	this.answerText = g_Voice.TV_VCMD_ANSWER;
		
	if(this.voiceRecogStep =="Main")
	{
		this.categoryList = [
					g_Voice.TV_SID_VOICE_CONTACT, 
					g_Voice.TV_SID_VOICE_HISTORY, 
					g_Voice.TV_SID_VOICE_CALL_PHONES,
					g_Voice.TV_SID_VOICE_PROFILE,
					g_Voice.SID_SETTINGS, 
					];
						
		var STX = String.fromCharCode(2);
		var ETX = String.fromCharCode(3);
		var splitter = ETX + STX;
			
		var contactList_string = PluginAPIMgr.GetOnlineContacts();
		this.contactList = contactList_string.split(splitter);
		this.contactList.pop(); // delete empty item
	}
	else if(this.voiceRecogStep =="StartCall")
	{
		var pstn_name = PluginAPIMgr.GetPSTNNumberWithIndex(this.recogContactIndex);
		if(pstn_name.length > 0 || this.recogContactName == "echo123")
		{
			this.callList= [
					this.voiceCallText
					];
		}
		else
		{
			var camState = PluginAPIMgr.GetCameraState();
			if(camState ==  ENUM_CAM_STATE.CAM_STATE_READY || camState == ENUM_CAM_STATE.CAM_STATE_PLAYING)
			{
				this.callList= [ 
						this.videoCallText, 
						this.voiceCallText				
						];
				}
			else
			{
				this.callList= [
					this.voiceCallText
					];
			}
		}		
	}
	else if(this.voiceRecogStep =="IncomingCall")
	{
		if(PluginAPIMgr.IsConference() == 0)
		{
			var camState = PluginAPIMgr.GetCameraState();
			if(camState ==  ENUM_CAM_STATE.CAM_STATE_READY || camState == ENUM_CAM_STATE.CAM_STATE_PLAYING)
			{
				this.incomingCallList = [					
				this.videoCallText,
				this.voiceCallText,
				this.declineText
				];
			}
			else
			{
				this.incomingCallList = [					
					this.voiceCallText,
					this.declineText
					];
			}

		}
		else
		{
			this.incomingCallList = [					
					this.answerText,
					this.declineText
					];
		}
	}
}


RecogMgr.SetHelpbarType = function(type)
{
	this.voiceHelpbarInfo.helpbarType = type;
}

RecogMgr.SetGuideText = function(text)
{
	this.voiceHelpbarInfo.guideText = text;
}

RecogMgr.SetExampleText = function(text)
{
	this.voiceHelpbarInfo.exampleText = text;
}

RecogMgr.SetKeepCurrentInfo = function(flag)
{
	this.voiceHelpbarInfo.bKeepCurrentInfo = flag;
}

RecogMgr.SetCandidateList = function(candidate_string)
{
	var index = this.voiceHelpbarInfo.candidateList.length;
	
	this.voiceHelpbarInfo.candidateList[index]= new Object();
	this.voiceHelpbarInfo.candidateList[index].candidate = candidate_string;	
}

RecogMgr.SetHelpbarItemsList= function(item_text , command_string_list)
{
	var index = this.voiceHelpbarInfo.helpbarItemsList.length;
	
	this.voiceHelpbarInfo.helpbarItemsList[index]= new Object();
	this.voiceHelpbarInfo.helpbarItemsList[index].itemText = item_text;
	this.voiceHelpbarInfo.helpbarItemsList[index].commandList = new Array();
	
	var i=0;
	for(i=0; i<command_string_list.length; i++)
	{
		this.voiceHelpbarInfo.helpbarItemsList[index].commandList[i] = new Object();
		this.voiceHelpbarInfo.helpbarItemsList[index].commandList[i].command = command_string_list[i];
	}
}

RecogMgr.SetHelpbarItem= function(command_string)
{
	var index = this.voiceHelpbarInfo.helpbarItemsList.length;
	
	this.voiceHelpbarInfo.helpbarItemsList[index]= new Object();
	this.voiceHelpbarInfo.helpbarItemsList[index].itemText = command_string;
	this.voiceHelpbarInfo.helpbarItemsList[index].commandList = new Array();
	
	this.voiceHelpbarInfo.helpbarItemsList[index].commandList[0] = new Object();
	this.voiceHelpbarInfo.helpbarItemsList[index].commandList[0].command = command_string;
}


RecogMgr.ProcessVoiceRecogResult = function(result)
{
	alert("***RecogMgr.ProcessVoiceRecogResult -> "+ result);
	
	/*if(this.skypeText == result)
	{
		var LoginState = PluginAPIMgr.GetLoginState();
		
		if(LoginState == "0")
		{
			StateMgr.Start_Welcome_State();
			this.StartVoiceHelpbar("Welcome");	
		}
		else if(LoginState == "2")
		{
			StateMgr.Start_Main_State();
			this.StartVoiceHelpbar("Main");
		}
		
		return;
	}
	
	if(this.exitText == result)
	{
		StateMgr.Start_Exit_State(false);
		return;
	}*/
	
	var i=0;
	var result_length = result.length;
	if(this.voiceRecogStep =="Main")
	{
		for(i=0; i<this.categoryList.length; i++)
		{
			if(this.categoryList[i].length == result_length)
			{
			if(this.categoryList[i]==result)
			{
				RecogMgr.RecognizeCatagory(i);
				this.StartVoiceHelpbar("Main");
				return;
			}	
		}
		}
	
		for(i=0; i<this.contactList.length; i++)
		{
			if(this.contactList[i].length == result_length)
			{
			if(this.contactList[i]==result)
			{
					this.recogContactName = PluginAPIMgr.GetSkypeNameWithDisplayName(result);
					
					if(this.recogContactName.length >0)
					{
						alert("***RecogMgr.ProcessVoiceRecogResult : Callee name -> "+ this.recogContactName);
				RecogMgr.RecognizeContact(result);
				this.StartVoiceHelpbar("StartCall");
				return;
			}	
		}
	}
	}
		
		this.StartVoiceHelpbar("Main");
	}
	else if(this.voiceRecogStep =="StartCall")	
	{
		if(this.cancelText == result)
		{
			this.StartVoiceHelpbar("Main");
			return;
		}
		
		for(i=0; i<this.callList.length; i++)
		{
			if(this.callList[i].length == result_length)
			{
			if(this.callList[i] == result)
			{
					if(this.videoCallText ==result)
					{
						ProcMgr.CreateCall(this.recogContactName, 1);
					}
					else
					{
						ProcMgr.CreateCall(this.recogContactName, 0);
					}
					
				return;	
			}					
		}	
					
		}	
	}
	else if(this.voiceRecogStep =="IncomingCall")
	{
		if(this.videoCallText ==result)
		{
			ProcMgr.AnswerByVideo();
		}
		else if(this.voiceCallText == result || this.answerText== result)
		{
			ProcMgr.AnswerByVoice();
		}
		else if(this.declineText == result)
		{
			if(PluginAPIMgr.IsConference() == 1)
			{
				ProcMgr.DeclineIncomingConferenceCall();
			}
			else
			{
				ProcMgr.DeclineIncomingCall();
			}		 
		}
	}
}


RecogMgr.RecognizeCatagory = function(index)
{
	//stop SubState
	StateMgr.ReturnToMainState();
	
	//Change Main state
	if(StateMgr.GetCurrentState() != "Main")
	{
		//StateMgr.Start_Main_State();	
		StateMgr.Start_Jump_To_Main_State(index, null);	
	}
	else
	{
		WndMgr.FocusToCategotyOfListMain(index);
	}	
	
	
}

RecogMgr.RecognizeContact = function(name)
{
	this.recogContactIndex = PluginAPIMgr.GetIndexOfContact(this.recogContactName);
	//this.recogContactName = PluginAPIMgr.GetContactNameWithIndex(this.recogContactIndex);
	alert("***RecogMgr.RecognizeContact -> index: "+ this.recogContactIndex +" name: "+this.recogContactName);
	
	//stop SubState
	StateMgr.ReturnToMainState();
	
	//Change Main state
	if(StateMgr.GetCurrentState() != "Main")
	{
		//StateMgr.Start_Main_State();
		StateMgr.Start_Jump_To_Main_State(0,parseInt(this.recogContactIndex ));	
	}
	else
	{
		WndMgr.FocusToItemOfContactList(parseInt(this.recogContactIndex ));	
	}	
}
