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

ProcMgr ={
	isWelcomeMode : true,
	
	flagQuit : false,
	
	loggedIn : false,
	cblSync : false,
	
	isLoginCencel : false,
	
	isConferenceCall: false,
	isCalling : false,
	isCallCencel : false,
	isVoiceMailSending : false,
	callHoldTimer : false,
	callResumeTimer : false,
	
	callEndWaitingTimer : false,
	isLogoutAfterCallEnd : false,
	isQuitAfterCallEnd : false,
	isCloseAfterCallEnd : false,
	isExitAfterCallEnd : false,
		
	isCallStartAfterCallEnd : false,
	isCallingFail : false,
	
	isIncomingCall : false,
	isReceivingVideo : false,
	isPauseVideo : false,
	
	isChatting: false,
	isTypingChatMsg : false,
	numOfChatMember :0,
	ChatMember :"",
	ChatParticipants : "",
	ChatMemberSkypeName :"",
	
	isVoiceMailPlaying : false,
	
	isKeyRegister: false,
	isCallKeyRegister: false,
	
	isTTXMIX: false,
	isGenoaS: false,
	ModelCode : null,
	isVideoAvailable:false,

	MainListFuncType : null,
	start_main : false,
	
	isExitAfterSignout : false,
	
	//isGestureRecognition : false,
	
	isAutoFocus:false,
	
	isFaceRecog : false,
	isFaceDetect : false,
	isFaceTraining : false,
	
	FaceRecogResultIndex : 0,
	
	FaceRecogTimer:false,
	FaceDetectTimer:false,
	
	CountOfRecogFail : 0,
	CountOfTrainingFail :0,
	CountOfRecogInfo : 0,
	
	isRegisteredFace : false,
	isReRegisterFace : false,
	FaceRegistrationCallerState : "",
	isFaceRegistrationAfterSignin : false,
	isSigninAfterPwdCheck : false,

	HoldReceiveVideo : false , 
	
	CallInfo : new Object(),
	ProductInfo : new Object(),
		
	SourceMode : false,
	CurOutputMixVolume : 0,
	//call end --> source
	flag_ExitAfterWatchingTV : false,
	blockName :null,
	unblockName:null,
	isRidgeFlick:false,
	
	flag_show_exit_popup:false
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////  TV Model / Target location / remote control ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

ProcMgr.getProductInfo =function()
{
	alert('ProcMgr.getProductInfo');	
	//1. check model name
	var tv_model = PluginAPIMgr.GetTVModel();	
	//model string  T-GASAKUC , T-GAPAKUC , T-MST10PDEUC , T-FXPAKUC , TB-FXPAKU
		
	var dash_index = tv_model.indexOf("-");
	var model_checker = tv_model.substring(dash_index+1,dash_index+3);

	this.ProductInfo.sub_info_code = "none";
	if(model_checker == "FX")
	{
		if(dash_index == 1)
		{
			this.ProductInfo.model_code = TV_MODEL_CODE.FOX;
			
			//9000 UD model
			var sub_checker = tv_model.substring(dash_index+4,dash_index+5);
			if(sub_checker == "9")
			{
				//9500 NT model
				var NTV_checker = tv_model.substring(dash_index+4,dash_index+6);
				if(NTV_checker == "9N")
				{
					this.ProductInfo.sub_info_code = "NTV";
				}
				else
				{
					this.ProductInfo.sub_info_code = "UD";
				}
			}	
		}
		else if(dash_index == 2)
		{
			this.ProductInfo.model_code = TV_MODEL_CODE.FOX_SBB;
		}
		else
		{
			this.ProductInfo.model_code = TV_MODEL_CODE.NORMAL;
		}
	}
	else
	{
		model_checker = tv_model.substring(dash_index+1,dash_index+6);
		if(model_checker == 'MST12')
		{
			this.ProductInfo.model_code = TV_MODEL_CODE.X12;
		}
		else
		{
			this.ProductInfo.model_code = TV_MODEL_CODE.NORMAL;
		}
	}
	alert('ModelCode='+this.ProductInfo.model_code);
	this.ModelCode = this.ProductInfo.model_code;
	
	//2. check multitasking!!
	if(PluginAPIMgr.IsSkypeSupportMultitasking() == 1)
	{
		this.ProductInfo.support_multitasking = true;
	}
	else
	{
		this.ProductInfo.support_multitasking = false;
	}

	//3. check mixing Video
	if(this.ModelCode != TV_MODEL_CODE.X12)
	{
		this.ProductInfo.support_mixing_video = true;
		this.ProductInfo.support_cam_adjustment = true;
	}
	else
	{
		this.ProductInfo.support_mixing_video = false;
		this.ProductInfo.support_cam_adjustment = false;
	}


	//4. check mixing Audio
	if(this.ModelCode == TV_MODEL_CODE.X12)
	{
		this.ProductInfo.support_mixing_audio = true;
	}
	else
	{
		this.ProductInfo.support_mixing_audio = false;
	}

	this.getCameraInfo();
	ProcMgr.Check14CameraForKPILog();
}

ProcMgr.getCameraInfo = function()
{
	alert('ProcMgr.getCameraInfo');
	// check ePTZ
	var camera_state = PluginAPIMgr.GetCameraState();

    if(camera_state == ENUM_CAM_STATE.CAM_STATE_DISCONNECTED || camera_state == ENUM_CAM_STATE.CAM_STATE_CONNECTING)
	{
		this.ProductInfo.capability_eptz = false;
		this.ProductInfo.capability_face_tracking = false;
		return;
	}

	if(PluginAPIMgr.GetCamCapability(ENUM_CAM_CAPABILITY.CAM_CAPABILITY_ZOOM) == 1 && 
		PluginAPIMgr.GetCamCapability(ENUM_CAM_CAPABILITY.CAM_CAPABILITY_SIGNAL_TYPE) == 1)
	{
		this.ProductInfo.capability_eptz = true;
	}
	else
	{
		this.ProductInfo.capability_eptz = false;
	}
		
	// check atuo face tracking
	if(PluginAPIMgr.GetCamCapability(ENUM_CAM_CAPABILITY.CAM_CAPABILITY_FACE_TRACKING) == 1)
	{
		this.ProductInfo.capability_face_tracking = true;
	}
	else
	{
		this.ProductInfo.capability_face_tracking = false;
	}
}

ProcMgr.getIMERemoconAreaId = function()
{
	alert("ZeroLeft -> " + IMEvar.productInfor.ZeroLeft); 
	
	if(IMEvar.productInfor.ZeroLeft == 'TTX/MIX')
	{
		this.isTTXMIX = true;
	}
	else
	{
		this.isTTXMIX = false;
	}
}

ProcMgr.isTTXMIXEnable =function()
{
    return this.isTTXMIX;
}

ProcMgr.setDefaultRemoteType=function()
{
	alert("***** ProcMgr.setDefaultRemoteType()");

//temp : for webkit
/*
	curWidget.setInputType(24);
*/
}

ProcMgr.setNumericRemoteType=function()
{
	alert("***** ProcMgr.setNumericRemoteType()");

//temp : for webkit
/*
	curWidget.setInputType(27);
*/
}



/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////  Key  register / unregister / process  ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

ProcMgr.registerKey =function()
{   
	alert("***** ProcMgr.registerKey()");
	
	if(Flag_Hidden_State == true)
	{
		alert("***** hidden mode!!! it is impossible to register key");
		return;
	}
	
	var p = sf.core.plugin('TVMW');
	var i=0;
	for(i=0; i < KEY_CODE_LIST.length; i++)
	{
		//sf.key.registerKey(KEY_CODE_LIST[i]);
		if(p){
	        p.RegisterKey(KEY_CODE_LIST[i]);
	    }
	}	
	this.isKeyRegister=true;
}

ProcMgr.unregisterKey =function()
{  
	alert("***** ProcMgr.unregisterKey ()");
	if(this.isKeyRegister== true && this.isCalling==false)
	{
		var p = sf.core.plugin('TVMW');
		var i=0;
		for(i=0; i < KEY_CODE_LIST.length; i++)
		{
			//sf.key.unregisterKey(KEY_CODE_LIST[i]);
			if(p){
		        p.UnregisterKey(KEY_CODE_LIST[i]);
		    }
		}
		this.isKeyRegister = false;
	}
}

ProcMgr.registerCallKey =function()
{	
	alert("***** ProcMgr.registerCallKey()");

	if(Flag_Hidden_State == true)
	{
		alert("***** hidden mode!!! it is impossible to register call key");
		return;
	}

	var p = sf.core.plugin('TVMW');

	var i=0;
	for(i=0; i < CALL_BLOCK_KEY_CODE_LIST.length; i++)
	{         
	    if(p){
	        p.RegisterKey(CALL_BLOCK_KEY_CODE_LIST[i]);
	    }
	}
	g_AppCommon.RegisterKey(PL_APPCOMMON_KEY_EMANUAL);
	
	if(this.ProductInfo.sub_info_code == "NTV")
	{
		g_AppCommon.RegisterKey(ENUM_CALL_BLOCK_KEY_CODE.DUALVIEW);
	}
	
	this.isCallKeyRegister=true;

}

ProcMgr.unregisterCallKey  =function()
{
	alert("***** ProcMgr.unregisterCallKey ()");
	 if(this.isCallKeyRegister== true && this.isCalling==false)
	 {
		var p = sf.core.plugin('TVMW');
	
		var i=0;
		for(i=0; i < CALL_BLOCK_KEY_CODE_LIST.length; i++)
		{             
		    if(p){
		        p.UnregisterKey(CALL_BLOCK_KEY_CODE_LIST[i]);
		    }
		}
		
		g_AppCommon.UnregisterKey(PL_APPCOMMON_KEY_EMANUAL);
		if(this.ProductInfo.sub_info_code == "NTV")
		{
			g_AppCommon.UnregisterKey(ENUM_CALL_BLOCK_KEY_CODE.DUALVIEW);
		}	
		
		this.isCallKeyRegister=false;
	}
}

ProcMgr.processBlockKey  =function(key_code)
{
    alert("***** ProcMgr.processBlockKey () key_code : " + key_code);
    
    if(key_code== 40000002 || key_code== 40000003 || key_code== 40000004 || key_code== 40000005)
    {
    	return;
    }
    
    //check ridge
    if(key_code > 50100000 && key_code < 50500000)
    {
		return;
    }    
    
	var BlockKey = false;
    var i=0;
    for(i=0; i < CHANNEL_KEY_CODE_LIST.length; i++)
    {             
        if (CHANNEL_KEY_CODE_LIST[i] == key_code) 
		{
            if(this.isCalling == true  && StateMgr.GetCurrentSubState().length <= 0)
            {
				if(g_NumObj != null)
				{
					g_NumObj.blur();	
				}	
					
                WndMgr.StartOneBottonPopup(OneBtnPopupIndex.NOT_AVAILABLE_KEY);
				BlockKey = true;
				sf.key.preventDefault();
            }
			else
			{
				return;
			}
        }
    }
	
	for(i=0; i < CALL_BLOCK_KEY_CODE_LIST.length; i++)
    {             
        if (CALL_BLOCK_KEY_CODE_LIST[i] == key_code) 
		{
			if(this.isCalling == true  && StateMgr.GetCurrentSubState().length <= 0)
			{
				if(g_NumObj != null)
				{
					g_NumObj.blur();	
				}	
				WndMgr.StartOneBottonPopup(OneBtnPopupIndex.NOT_AVAILABLE_KEY);
				BlockKey = true;
				alert('[Skypeapp]Call preventDefault()');
				sf.key.preventDefault();
				//alert('[Skypeapp]Call (Common.API.Widge) WidgetAPI.blockNavigation(event)');
				//g_WidgetAPI.blockNavigation(event);
				//alert('event.preventDefault');
				//event.preventDefault();
			}
			else
			{
				return;
			}
        }
    }
	for(i=0; i < KEY_CODE_LIST.length; i++)
	{         
	    if(KEY_CODE_LIST[i] == key_code){
	        if(StateMgr.GetCurrentSubState().length <= 0)
	        {
				if(g_NumObj != null)
				{
					g_NumObj.blur();	
				}	
				
	            WndMgr.StartOneBottonPopup(OneBtnPopupIndex.NOT_AVAILABLE_KEY);
			
	        }
	    }
	    else{
	    	return;
	    }
	}
/*
	if(BlockKey==false)
	{
		if(StateMgr.GetCurrentSubState().length <= 0)
        {
			if(g_NumObj != null)
			{
				g_NumObj.blur();	
			}	
			
            WndMgr.StartOneBottonPopup(OneBtnPopupIndex.NOT_AVAILABLE_KEY);
			
        }
        
		sf.key.preventDefault();
	}*/

}

ProcMgr.processInfolinkKey = function()
{
    alert("***** ProcMgr.processInfolinkKey ()");
     
    if(this.isCalling == true || StateMgr.GetCurrentSubState().length > 0 || ProcMgr.isShowNotyOfMainState() == true)
    {
    	//only main call state
        if(this.isCalling == true && StateMgr.GetCurrentSubState().length <= 0)
        {
			if(g_NumObj != null)
			{
				g_NumObj.blur();
			}	
				
            WndMgr.StartOneBottonPopup(OneBtnPopupIndex.NOT_AVAILABLE_KEY);
        }

        sf.key.preventDefault();
    }
    else
    {
		this.CloseWidget();
        sf.key.preventDefault();
    }
}


//process infolink key when calling 
ProcMgr.processInfolinkKeyInCall = function()
{
    alert("***** ProcMgr.processInfolinkKeyInCall ()");
    
    if(ProcMgr.CallInfo.IsTvMode == true)
    {
    	if(StateMgr.GetCurrentSubState().length <= 0)
    	{
    		WndMgr.StartOneBottonPopup(OneBtnPopupIndex.NOT_AVAILABLE_KEY);
    	}
    }
    else
    {
    	this.CloseWidget();
    }
    
    sf.key.preventDefault();
}

ProcMgr.isShowNotyOfMainState =function()
{
    alert("***** ProcMgr.isShowNotyOfMainState ()");
    
    var result = false;
    
    if(StateMgr.GetCurrentState()=="CreateAccountSuccess")
    {
    	if(WndMgr.CreateAccountSuccessStep != "Success")
    	{
    		result=true;
    	}
    }
    else if(StateMgr.GetCurrentState()=="FaceRecogSignin")
    {
		if(WndMgr.FaceRecogSigninStep != "FaceRecog" && WndMgr.FaceRecogSigninStep != "Result")
    	{
			result=true;
    	}
    }
    else if(StateMgr.GetCurrentState()=="FaceRecogRegistration")
    {
		if(WndMgr.FaceRecogRegistrationStep != "FaceDetect")
    	{
			result=true;
    	}
    }
    else
    {
    	result=false;
    }
    
    return result;    
}


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///// Widget Start /  Stop  ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

ProcMgr.StartWidget = function()
{     
    alert("***** ProcMgr.StartWidget()");
    	
	PluginAPIMgr.WidgetHandleIncomingCall(1); //to display Incomgin Call scene of widget 
	
    this.start_main = PluginAPIMgr.SetSkypeWidgetState(1);
    var LoginState = PluginAPIMgr.GetLoginState();
	//check..
	ProcMgr.InitCameraOption();

    if(LoginState == "0")  //logged out state
    {
       if(PluginAPIMgr.IsDefaultAccountAvailable() ==1) // auto login
      {
            PluginAPIMgr.AutoLogin(); 
       }
       else  //manual login 
       {
			StateMgr.Start_Welcome_State();		
       }
    }
    else if(LoginState == "2")
    {
    	alert('>>>>>> start:'+g_Data.WIDGET_PARAM.start + ' mode:' + g_Data.WIDGET_PARAM.mode);
		
		if(g_Data.WIDGET_PARAM.socail == true)
        {
        	alert('start jump!!!!');
			if(g_Data.WIDGET_PARAM.mode == 'Voicemail')
            {
		        ProcMgr.PlayVoicemailforJump(g_Data.WIDGET_PARAM.timestamp);
            }
			else if(g_Data.WIDGET_PARAM.mode == 'Calling')
			{
				ProcMgr.CreateCallforJump(g_Data.WIDGET_PARAM.skypename,g_Data.WIDGET_PARAM.calltype);
        	}
    		else if(g_Data.WIDGET_PARAM.mode =='MissedCallHistory')
        	{
        		//ProcMgr.CheckMissedCallList();
        		StateMgr.Start_Jump_To_Main_State(1,0);
        	}
	        	
			this.SetCallInfoPrevState('Source');
			//PluginAPIMgr.HideConnectingWnd();
    	}       
		//check native code
        else if(this.start_main == "1")
        {
         	if(PluginAPIMgr.IsCallInProgress())
         	{        		
         		//Temp Code by donghee lee 
         		//this.SetCallInfoPrevState('Source');
         		this.StartCall();
         	}
         	else
         	{
         		if(PluginAPIMgr.IsInCall()==1) //incoming call
         		{
         			/*PluginAPIMgr.StopRing();
         			PluginAPIMgr.StartIncomingRing();*/
         			var NNaviPlugin = sf.core.plugin('NNavi');
					NNaviPlugin.SetBannerState(1);
         			PluginAPIMgr.MuteSpeaker(false);
         			if(!PluginAPIMgr.IsConference())
         			{
         				ProcMgr.IncomingCall();
         			}
         			else
         			{
         				ProcMgr.IncomingConferenceCall();
         			}         			
         		}
         		else
         		{
         			StateMgr.Start_Main_State();
         		}
         		
            	//RecogMgr.StartVoiceRecog();
         	}

        }
    }       

	RecogMgr.StartVoiceRecog();
}

ProcMgr.CloseWidget = function()
{
	alert("***** ProcMgr.CloseWidget()");
	
	if(StateMgr.GetCurrentState()== "VideoSnapshot" || StateMgr.GetCurrentState()== "CameraCheckConnected")
	{
		PluginAPIMgr.StopPreview();	
	}
	
	//test
	if(typeof(widgetAPI.setPrevSourceInfo) ==='undefined')
	{
		alert('widgetAPI.setPrevSourceInfo() undefined ');
	}
	else
	{
		alert('widgetAPI.setPrevSourceInfo() defined ');
		ProcMgr.setLastSource();
	}
	
	setTimeout("WaitTimerCF()", 0);
	WaitTimerCF = function(){
		//2013 modify by minseok
		sf.core.exit(false);
    }
}

ProcMgr.ExitWidget = function()
{
	alert("***** ProcMgr.ExitWidget()");
	
	if(StateMgr.GetCurrentState()== "VideoSnapshot" || StateMgr.GetCurrentState()== "CameraCheckConnected")
	{
		PluginAPIMgr.StopPreview();	
	}
	
	//test
	if(typeof(widgetAPI.setPrevSourceInfo) ==='undefined')
	{
		alert('widgetAPI.setPrevSourceInfo() undefined ');
	}
	else
	{
		alert('widgetAPI.setPrevSourceInfo() defined ');
		ProcMgr.setLastSource();
	}
	
	setTimeout("WaitTimerCF()", 0);
	WaitTimerCF = function(){
     //2013 modify by minseok
		sf.core.exit(true);
    }
}

ProcMgr.setLastSource= function()
{
	var last_source = PluginAPIMgr.GetLastSourceMode(); 
	if((last_source != ENUM_SOUECE_TYPE.PL_TVMW_SOURCE_MEDIA) && (last_source != ENUM_SOUECE_TYPE.PL_TVMW_SOURCE_NONE))
	{
		alert("***** ProcMgr.setLastSource()");
		widgetAPI.setPrevSourceInfo(last_source);
	}			
}



/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////Signin , Create Account, Signout, Exit////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////

ProcMgr.Signin = function(id, pwd, savePwd)
{    
    alert("***** ProcMgr.Signin ()");
     
    g_Data.SetSigninInputInfo(id, pwd , savePwd);

    PluginAPIMgr.Login();
    
    if(StateMgr.GetCurrentState()=="Signin")
    {
    	WndMgr.NextStepSignin();
    }
    
    if(StateMgr.GetCurrentState()=="FaceRecogSignin")
    {
    	WndMgr.NextStepFaceRecogSignin();
    }    
}

ProcMgr.CancelSignin = function()
{    
    alert("***** ProcMgr.CancelSignin ()");
    
    this.loggedIn = false;  //init
    this.cblSync = false;  //init
    
    this.isLoginCencel = true;
    ProcMgr.Signout(false);
}

ProcMgr.CreateAccount = function()
{
    alert("***** ProcMgr.CreateAccount()");

    PluginAPIMgr.Register();
    WndMgr.NextStepCreateAccount();        
}

ProcMgr.CreateAccountWithNewSkypeName = function(id)
{
    alert("***** ProcMgr.CreateAccountWithNewSkypeName ()");
    g_Data.SetCreateAccountSkypeName(id);
	WndMgr.UpdateCreateAccount(id);
	
    PluginAPIMgr.Register();
    WndMgr.NextStepCreateAccount();
}
//2013 add by minseok
ProcMgr.ShowLicensePopup = function(index){
	WndMgr.ShowLicensePopup(index);
}
ProcMgr.CloseLicensePopup = function(){
	WndMgr.CloseLicensePopup();
}

ProcMgr.ReceivedLoggedIn= function()
{
    alert("***** ProcMgr.ReceivedLoggedIn()");
    
    this.loggedIn = true;
    
	if(StateMgr.GetCurrentState() =="CreateAccount")
    {
        PluginAPIMgr.SetFullName(g_Data.DATA_CREATE_ACCOUNT_INPUT_INFO.full_name);
		PluginAPIMgr.SetCallForwardTimer(g_Data.DATA_DEFAULT_CALL_FORWARDING_TIME);
		
		var is_auto_signin = PluginAPIMgr.IsAutoSignInSet();
		if(is_auto_signin==false)
		{
			var is_auto_start =PluginAPIMgr.IsAutoStartSet();
			if(is_auto_start==true)
			{
				PluginAPIMgr.SetAutoStart(false);
			}
		}
    }

    if(this.cblSync==true)
    {
        ProcMgr.HandleLoggedIn();
    }
}

ProcMgr.ReceivedCblSync= function()
{
    alert("***** ProcMgr.ReceivedCblSync()");
    
    this.cblSync = true;
     
    if(this.loggedIn==true)
    {
        ProcMgr.HandleLoggedIn();
    }
}

ProcMgr.SavePwd= function()
{
    if(StateMgr.GetCurrentState()=="Signin")
    {
    	alert("***** ProcMgr.SavePwd(): Siginin");
    	this.SetMyPwd(g_Data.DATA_SIGNIN_INPUT_INFO.pwd);
    	PluginAPIMgr.SetLoginMode(0);    	
    }
    
    if(StateMgr.GetCurrentState()=="CreateAccount")
    {
    	alert("***** ProcMgr.SavePwd(): CreateAccount");
    	this.SetMyPwd(g_Data.DATA_CREATE_ACCOUNT_INPUT_INFO.pwd);
    	PluginAPIMgr.SetLoginMode(0); 
    }
    
    if(StateMgr.GetCurrentState()=="FaceRecogSignin")
    {
    	if(this.isFaceRegistrationAfterSignin== true || this.isSigninAfterPwdCheck == true)
    	{
	    	alert("***** ProcMgr.SavePwd(): FaceRecogSignin");
    		this.SetMyPwd(g_Data.DATA_SIGNIN_INPUT_INFO.pwd);    		
    	}
    	
    	PluginAPIMgr.SetLoginMode(1); 
    }
    
}

ProcMgr.HandleLoggedIn= function()
{
    alert("***** ProcMgr.HandleLoggedIn()");
    
    /*if(PluginAPIMgr.RecognitionPluginAvailable == true)
    {*/
    	this.SavePwd();
    /*}*/	
    
    WndMgr.DisableLoading();
   
   	if(StateMgr.GetCurrentState()=="FaceRecogSignin")
	{
		WndMgr.StopLoading();
		if(this.isFaceRegistrationAfterSignin==true)
		{
			// WndMgr.StartOneBottonPopup(OneBtnPopupIndex.FACE_RECOG_RE_REGISTRATION);
			/*train thumnail...*/
			alert("[FaceRecogSignin]success signin")
			this.SuccessFaceRecogSigninRegist();	//trainThumnail... don`t remove T.T
			/*train thumnail...*/
					
		}
		else
		{
			this.StopFaceRecogSignin();		//stop cam & recog
			WndMgr.StartOneBottonPopup(OneBtnPopupIndex.FACE_RECOG_LOGGEDIN);
		}
		// WndMgr.NextStepFaceRecogSignin();	
	}
	else
	{
		//2013 modify by minseok
		this.StartLoggedInState();
		/*if(StateMgr.GetCurrentState()=="Signin"){
			WndMgr.StartOneBottonPopup(OneBtnPopupIndex.LOGGED_IN_SUCESS);
			WndMgr.StopLoading();
			// sf.scene.get("Loading").showSuccessSignin();
		}else{
			this.StartLoggedInState();
		} 	*/
	
	} 	

    this.loggedIn = false;  //init
    this.cblSync = false;  //init
    this.isFaceRegistrationAfterSignin = false; //init
    this.isSigninAfterPwdCheck = false; //init
}

ProcMgr.StartLoggedInState = function()
{
    alert("***** ProcMgr.StartLoggedInState()");
    //2013 add by minseok : for app jump!
    if(g_Data.GetWidgetParamJumpFlag()==true){
    	this.CloseWithSignIn();
    	StateMgr.Start_Main_State();
    	return;
    }
	alert("StateMgr.GetCurrentState() : "+StateMgr.GetCurrentState());
	if(StateMgr.GetCurrentState()=="CreateAccount")
	{
		if(PluginAPIMgr.RecognitionPluginAvailable == true)
		{
			StateMgr.Start_Create_Account_Success_State();
			return;
		}
	}

	var camera_state = PluginAPIMgr.GetCameraState();

    if(camera_state == ENUM_CAM_STATE.CAM_STATE_DISCONNECTED || camera_state == ENUM_CAM_STATE.CAM_STATE_CONNECTING) 
	{
		if(PluginAPIMgr.RecognitionPluginAvailable == false)
		{
			StateMgr.Start_Camera_Check_Disconnected_State();
		}
		else
		{
			StateMgr.Start_Main_State();
		}							
	}
	else
	{				
		var camera_check_disable = PluginAPIMgr.GetCameraCheckDisable();
		
		if(camera_check_disable==false)
		{	
			StateMgr.Start_Camera_Check_Connected_State();
		}
		else
		{
			StateMgr.Start_Main_State();
		}
	}
	
	RecogMgr.StartVoiceRecog();
}

ProcMgr.Signout = function(flag_quit)
{    
    alert("***** ProcMgr.Signout () Quit : " + flag_quit);
     
     if(this.isCalling ==true)
     {
            if(flag_quit == true)
            {
                this.isQuitAfterCallEnd = true;
            }
            else
            {
                this.isLogoutAfterCallEnd = true;
            }
            WndMgr.CloseVideoCallRect();
            ProcMgr.DisconnectCall();
            return;
     }
     
    if(this.isChatting ==true)
    {
        ProcMgr.DisconnectChat(); 
    }
     
    if(StateMgr.GetCurrentState()== "VideoSnapshot" || StateMgr.GetCurrentState()== "CameraCheckConnected")
	{
		PluginAPIMgr.StopPreview();	
	}
		
	setTimeout("WaitTimerCF()", 0);
	WaitTimerCF = function(){
     
	    ProcMgr.flagQuit = flag_quit;
	    
	    if( ProcMgr.flagQuit == true)
	    {
	        PluginAPIMgr.Logout(0);
	    }
	    else
	    {
	        PluginAPIMgr.Logout(1);
	    }
   }
}

ProcMgr.CloseWithSignIn= function()
{
	if(PluginAPIMgr.IsSkypeSupportMultitasking()==0)
	{
     	if(this.isCalling == true)
	    {
			this.isCloseAfterCallEnd = true;
			WndMgr.CloseVideoCallRect();
	        ProcMgr.DisconnectCall();
			
			return;
	    }
	}
	else
	{
		this.ChangeVoiceCall();
	}
	
	if(PluginAPIMgr.IsWidgetSupportMultitasking() == 1)
	{
		if(PluginAPIMgr.RunPreviousApp()==1)  //previous auto return
		{
			return;
		}
	}
    
    //this.isCalling = false; 
    
    if(this.isChatting ==true)
    {
        ProcMgr.DisconnectChat(); 
    }
    	
    //Initialize
    g_Data.SetWidgetParamJumpFlag(false);
    this.CloseWidget();
}

ProcMgr.ExitWithSignIn= function()
{
	if(PluginAPIMgr.IsSkypeSupportMultitasking()==0)
	{
	    if(this.isCalling == true)
	    {
			this.isExitAfterCallEnd = true;
			WndMgr.CloseVideoCallRect();
	        ProcMgr.DisconnectCall();
			return;
	    }
	}
	else
	{		
		this.ChangeVoiceCall();		//check InCall in function
	}
    
    //this.isCalling = false;
    
     if(this.isChatting ==true)
    {
        ProcMgr.DisconnectChat(); 
    }
    
	this.ExitWidget();
}

ProcMgr.GoOutWithSignIn = function(go_tv)
{
	alert('ProcMgr.GoOutWithSignIn');
	
	if(go_tv == true)
	{
		//go to tv source
		this.ExitWidget();
	}
	//return to app
	else
	{
		if(PluginAPIMgr.IsWidgetSupportMultitasking() == 1)	//IsSkypeSupportMultitasking
		{
			if(PluginAPIMgr.RunPreviousApp() == 0)
			{
				this.CloseWidget();
			}
		}
		else
		{
			this.CloseWidget();
		}
	}

	if(this.isCalling == false)
	{
		StateMgr.Start_Main_State();
	}
}

ProcMgr.CloseWithSignOut= function()
{
    this.isExitAfterSignout = false;
	this.Signout(true);
}

ProcMgr.ExitWithSignOut= function()
{
    this.isExitAfterSignout = true;
    this.Signout(true);
}


ProcMgr.HandleLoggedOut= function()
{
	alert("***** ProcMgr.HandleLoggedOut()");
	
	RecogMgr.StopVoiceRecog(true);
    
	var LoggedOut_Reason = PluginAPIMgr.GetLogoutReason();
	alert("Reason is : "+LoggedOut_Reason); 
    switch(LoggedOut_Reason)
    {
        case ENUM_LOGOUTREASON.LOGOUT_CALLED : 
		
            if(this.flagQuit == false)
            {
                if(this.isLoginCencel == true)
                {
                	if(StateMgr.GetCurrentState() =="Signin") 
                    {
	                    WndMgr.BackStepSignin();
						StateMgr.Start_Signin_State();
                    }
                	else if(StateMgr.GetCurrentState() =="FaceRecogSignin") 
                    {
	                    WndMgr.BackStepFaceRecogSignin();
						//WndMgr.ReturnFaceRecogSignin();
						// StateMgr.Start_Welcome_State();
                    }

                    this.isLoginCencel = false; //init
                    
					return;
                }
				              
			   	StateMgr.Start_Welcome_State();           
            }
            else
            {
            	//2013 modify by minseok
            	sf.core.exit(this.isExitAfterSignout);
            }
            
        break;
 ///synchronous login, regiteration
		case ENUM_LOGOUTREASON.HTTPS_PROXY_AUTH_FAILED :
		case ENUM_LOGOUTREASON.SOCKS_PROXY_AUTH_FAILED : 
		case ENUM_LOGOUTREASON.P2P_CONNECT_FAILED :

			if(StateMgr.GetCurrentState() =="Signin")
            {
                WndMgr.BackStepSignin();
				WndMgr.StartOneBottonPopup(OneBtnPopupIndex.LOGGEDOUT_EXTERNAL_NETWORK_CONNECTION_FAIL);
            }
            else if(StateMgr.GetCurrentState() =="CreateAccount")
            {
                WndMgr.BackStepCreateAccount();
				WndMgr.StartOneBottonPopup(OneBtnPopupIndex.LOGGEDOUT_EXTERNAL_NETWORK_CONNECTION_FAIL);
            }
        	else if(StateMgr.GetCurrentState() =="FaceRecogSignin") 
            {
                WndMgr.BackStepFaceRecogSignin();
				WndMgr.StartOneBottonPopup(OneBtnPopupIndex.LOGGEDOUT_EXTERNAL_NETWORK_CONNECTION_FAIL);
            }
            else
            {
                if(PluginAPIMgr.IsDefaultAccountAvailable() ==1) // auto login
                {
                     StateMgr.Start_Welcome_State();
                }
            }

        break;
		
		case ENUM_LOGOUTREASON.SERVER_CONNECT_FAILED : 
		case ENUM_LOGOUTREASON.SERVER_OVERLOADED :
		
			if(StateMgr.GetCurrentState() =="Signin")
            {
                WndMgr.BackStepSignin();
				WndMgr.StartOneBottonPopup(OneBtnPopupIndex.LOGGEDOUT_SERVER_CONNECTION_FAIL);
            }
            else if(StateMgr.GetCurrentState() =="CreateAccount")
            {
                WndMgr.BackStepCreateAccount();
				WndMgr.StartOneBottonPopup(OneBtnPopupIndex.LOGGEDOUT_SERVER_CONNECTION_FAIL);
            }
        	else if(StateMgr.GetCurrentState() =="FaceRecogSignin") 
            {
                WndMgr.BackStepFaceRecogSignin();
				WndMgr.StartOneBottonPopup(OneBtnPopupIndex.LOGGEDOUT_SERVER_CONNECTION_FAIL);
            }
            else
            {
                if(PluginAPIMgr.IsDefaultAccountAvailable() ==1) // auto login
                {
                     StateMgr.Start_Welcome_State();
                }
            }
   
        break;
		
		case ENUM_LOGOUTREASON.DB_IN_USE :

			if(StateMgr.GetCurrentState() =="Signin")
            {
                WndMgr.BackStepSignin();
				WndMgr.StartOneBottonPopup(OneBtnPopupIndex.LOGGEDOUT_IMPOSSIBLE);
            }
            else if(StateMgr.GetCurrentState() =="CreateAccount")
            {
                WndMgr.BackStepCreateAccount();
				WndMgr.StartOneBottonPopup(OneBtnPopupIndex.LOGGEDOUT_IMPOSSIBLE);
            }
        	else if(StateMgr.GetCurrentState() =="FaceRecogSignin") 
            {
                WndMgr.BackStepFaceRecogSignin();
				WndMgr.StartOneBottonPopup(OneBtnPopupIndex.LOGGEDOUT_IMPOSSIBLE);
            }
            else
            {
                if(PluginAPIMgr.IsDefaultAccountAvailable() ==1) // auto login
                {
                     StateMgr.Start_Welcome_State();
                }
            } 

        break;
 ///synchronous regiteration
		case ENUM_LOGOUTREASON.INVALID_SKYPENAME : 

			WndMgr.BackStepCreateAccount();
            WndMgr.StartOneBottonPopup(OneBtnPopupIndex.LOGGEDOUT_INVALID_SKYPENAME);
			
        break;
		case ENUM_LOGOUTREASON.INVALID_EMAIL : 

			WndMgr.BackStepCreateAccount();
            WndMgr.StartOneBottonPopup(OneBtnPopupIndex.LOGGEDOUT_INVALID_EMAIL);
			
        break;
		case ENUM_LOGOUTREASON.UNACCEPTABLE_PASSWORD : 

			WndMgr.BackStepCreateAccount();
            WndMgr.StartOneBottonPopup(OneBtnPopupIndex.LOGGEDOUT_UNACCEPTABLE_PASSWORD);
			
        break;
		case ENUM_LOGOUTREASON.SKYPENAME_TAKEN : 
		
            WndMgr.StopLoading();
            WndMgr.StartOneBottonPopup(OneBtnPopupIndex.LOGGEDOUT_SKYPENAME_TAKEN);
			
        break;
		case ENUM_LOGOUTREASON.REJECTED_AS_UNDERAGE :

			WndMgr.BackStepCreateAccount();
        	WndMgr.StartOneBottonPopup(OneBtnPopupIndex.LOGGEDOUT_REJECTED_AS_UNDERAGE);
			
        break;
 ///synchronous  login
		case ENUM_LOGOUTREASON.NO_SUCH_IDENTITY :

		  if(PluginAPIMgr.IsDefaultAccountAvailable() ==1) // auto login
          {
                 StateMgr.Start_Welcome_State();
          }
          else
          {
            if(StateMgr.GetCurrentState() =="Signin")
            {
            	WndMgr.BackStepSignin();
            }            
        	else if(StateMgr.GetCurrentState() =="FaceRecogSignin") 
            {
                WndMgr.BackStepFaceRecogSignin();
            }
            
			WndMgr.StartOneBottonPopup(OneBtnPopupIndex.LOGGEDOUT_NO_SUCH_IDENTITY);
          }

        break;
		case ENUM_LOGOUTREASON.INCORRECT_PASSWORD :

		  if(PluginAPIMgr.IsDefaultAccountAvailable() ==1) // auto login
          {
                 StateMgr.Start_Welcome_State();
          }
          else
          {
                if(StateMgr.GetCurrentState() =="Signin")
	            {
	            	WndMgr.BackStepSignin();
	            	WndMgr.StartOneBottonPopup(OneBtnPopupIndex.LOGGEDOUT_INCORRECT_PASSWORD);
	            }            
	        	else if(StateMgr.GetCurrentState() =="FaceRecogSignin") 
	            {	            	
	                WndMgr.BackStepFaceRecogSignin();
	                if(this.isFaceRegistrationAfterSignin == true || this.isSigninAfterPwdCheck== true)
	                {
	                	WndMgr.StartOneBottonPopup(OneBtnPopupIndex.LOGGEDOUT_INCORRECT_PASSWORD);
	                }
	                else
	                {
	                	PluginAPIMgr.SetLoginMode(0);
	                	WndMgr.StartOneBottonPopup(OneBtnPopupIndex.LOGGEDOUT_PASSWORD_HAS_CHANGED);
	                }	                
	            }
          }

        break;
		case ENUM_LOGOUTREASON.TOO_MANY_LOGIN_ATTEMPTS :
		
          if(PluginAPIMgr.IsDefaultAccountAvailable() ==1) // auto login
          {
                 StateMgr.Start_Welcome_State();
          }
          else
          {
            if(StateMgr.GetCurrentState() =="Signin")
            {
            	WndMgr.BackStepSignin();
            }            
        	else if(StateMgr.GetCurrentState() =="FaceRecogSignin") 
            {
                WndMgr.BackStepFaceRecogSignin();
            }
            
			WndMgr.StartOneBottonPopup(OneBtnPopupIndex.LOGGEDOUT_TOO_MANY_LOGIN_ATTEMPTS);
          }
            
        break;
/// Asynchronous 
		case ENUM_LOGOUTREASON.PASSWORD_HAS_CHANGED : 
			PluginAPIMgr.SetLoginMode(0);
            WndMgr.StartOneBottonPopup(OneBtnPopupIndex.LOGGEDOUT_PASSWORD_HAS_CHANGED);
        break;
		case ENUM_LOGOUTREASON.PERIODIC_UIC_UPDATE_FAILED : 
            WndMgr.StartOneBottonPopup(OneBtnPopupIndex.LOGGEDOUT_PERIODIC_UIC_UPDATE_FAILED);
        break;
		case ENUM_LOGOUTREASON.DB_DISK_FULL : 
            WndMgr.StartOneBottonPopup(OneBtnPopupIndex.LOGGEDOUT_DB_DISK_FULL);
        break;
		case ENUM_LOGOUTREASON.DB_IO_ERROR :
		case ENUM_LOGOUTREASON.DB_CORRUPT : 
		case ENUM_LOGOUTREASON.DB_FAILURE :
            WndMgr.StartOneBottonPopup(OneBtnPopupIndex.LOGGEDOUT_DB_PROBLEM);
        break;
        
/// don't use
		case ENUM_LOGOUTREASON.INVALID_APP_ID : 
        break;
		case ENUM_LOGOUTREASON.APP_ID_BLACKLISTED  : 
        break;
    }
}



//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///// Main Update  ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


ProcMgr.AccountAvataImageChanged= function()
{
    alert("***** ProcMgr.AccountAvataImageChanged()");
     if(StateMgr.GetCurrentState() =="Main")
    {
        sf.scene.get('ListMain').updateAvata();
        var profile =  sf.scene.get('ListMainProfile');
        if(profile.init)
        	profile.UpdatePicture();
    }
}

ProcMgr.AccountCreditChanged= function()
{
    alert("***** ProcMgr.AccountCreditChanged()");
     if(StateMgr.GetCurrentState() =="Main")
    {
          sf.scene.get('ListMain').updateCredit();
    }
	else if(StateMgr.GetCurrentState() =="SkypeOutCall")
	{
		WndMgr.UpdateSkypeOutCallCredit();
	}
	else if(StateMgr.GetCurrentState() =="VideoCall")
	{
		WndMgr.UpdateVideoCallCredit();
	}	
}

ProcMgr.AccountAvailabilityChanged= function()
{
    alert("***** ProcMgr.AccountAvailabilityChanged()");
    if(StateMgr.GetCurrentState() =="Main")
    {
          sf.scene.get('ListMain').updateOnlineStatus();
    }
}

ProcMgr.AccountMoodMsgChanged= function()
{
    alert("***** ProcMgr.AccountMoodMsgChanged()");
     if(StateMgr.GetCurrentState() =="Main")
    {
          sf.scene.get('ListMain').updateMoodMessage();
    }
}


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//// Call  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

ProcMgr.IncomingCall = function()
{
    alert("***** ProcMgr.IncomingCall()");
   this.isConferenceCall = false;
   
   	if(this.callEndWaitingTimer == false)
	{
		if(StateMgr.GetCurrentState()!= "Calling" && StateMgr.MainStateList[MAIN_STATE.CALLING].flagLoading == false)
		{
			this.isIncomingCall = true;
			this.registerCallKey();			
			StateMgr.Start_Noti_State(NOTI_STATE.INCOMING_CALL);
			
			RecogMgr.ChangeVoiceHelpbar();
		}
	}
}

ProcMgr.IncomingConferenceCall = function()
{
    alert("***** ProcMgr.IncomingConferenceCall()");
   this.isConferenceCall = true;

   	if(this.callEndWaitingTimer == false)
	{
		if(StateMgr.GetCurrentState()!= "Calling" && StateMgr.MainStateList[MAIN_STATE.CALLING].flagLoading == false)
		{
			this.isIncomingCall = true;
			this.registerCallKey();
			StateMgr.Start_Noti_State(NOTI_STATE.INCOMING_CALL);
			
			RecogMgr.ChangeVoiceHelpbar();
		}
	}
}

ProcMgr.AnswerByVideo = function()
{
	alert("***** ProcMgr.AnswerByVideo()");
	RecogMgr.StopVoiceRecog(true);
	PluginAPIMgr.ShowConnectingWnd();
	PluginAPIMgr.StopPreview();
	PluginAPIMgr.AnswerWithVideo();
}

ProcMgr.AnswerByVoice = function()
{
	alert("***** ProcMgr.AnswerByVoice()");
	RecogMgr.StopVoiceRecog(true);
	PluginAPIMgr.ShowConnectingWnd();
	PluginAPIMgr.StopPreview();
	PluginAPIMgr.AnswerWithVoice();
}

ProcMgr.DeclineIncomingCall = function()
{
    alert("***** ProcMgr.DeclineIncomingCall()");
	PluginAPIMgr.RejectCall();
}

ProcMgr.DeclineIncomingConferenceCall = function()
{
    alert("***** ProcMgr.DeclineIncomingConferenceCall()");
	PluginAPIMgr.DisconnectCall(0);
}

ProcMgr.GetIsInCall = function(){
	
	return this.isCalling;
}

ProcMgr.GetIsConferenceCall = function(){
	
	return this.isConferenceCall; 
}

ProcMgr.CreateCall = function(callee_name, call_type)
{
    alert("***** ProcMgr.CreateCall()");
    
	if(PluginAPIMgr.GetAccountInfo(ENUM_ACCOUNT_PROPERTY.P_AVAILABILITY) == ENUM_ACCOUNT_AVAILABILITY.CONNECTING )
    {
		if(WndMgr.iCurrentSubScene < 2){

			var scene = sf.scene.get(WndMgr.MainSubScene[WndMgr.iCurrentSubScene].Id);
			if(scene)
			{
				scene.Activation();
			}			
		}
			
		WndMgr.StartOneBottonPopup(OneBtnPopupIndex.CREATE_CALL_FAIL_NETWORK_ERROR);
		return;	
	}
  
    g_Data.SetCreateCallInputInfo(callee_name, call_type);

	StateMgr.Start_Calling_State();
}

ProcMgr.CreateCallforJump = function(callee_name, call_type)
{	
	
	if(PluginAPIMgr.GetAccountInfo(ENUM_ACCOUNT_PROPERTY.P_AVAILABILITY) == ENUM_ACCOUNT_AVAILABILITY.CONNECTING )
    {
    	StateMgr.Start_Main_State();
    	//error		
		WndMgr.StartOneBottonPopup(OneBtnPopupIndex.CREATE_CALL_FAIL_NETWORK_ERROR);
		return;	
	}
	
	var camera_state = PluginAPIMgr.GetCameraState();
	var IS_CAMERA_RUNING = true;

    if(camera_state == ENUM_CAM_STATE.CAM_STATE_DISCONNECTED || camera_state == ENUM_CAM_STATE.CAM_STATE_CONNECTING)
	{
		IS_CAMERA_RUNING = false;
	}	
	
	var IS_PSTN = false;
	
	if(PluginAPIMgr.GetContactPropWithName(callee_name,ENUM_CONTACT_PROPERTY.P_PSTNNUMBER))
	{
		IS_PSTN = true;
	}
	else if(callee_name == 'echo123')
	{
		IS_PSTN = true;
	}
		
    if(IS_CAMERA_RUNING == false || IS_PSTN == true)
	{
		g_Data.SetCreateCallInputInfo(callee_name,0);
	}
	else
	{
		g_Data.SetCreateCallInputInfo(callee_name, call_type);
	}
				
	StateMgr.Start_Calling_State();
	
}

//create call in calling window
ProcMgr.ProcessCall = function()
{
    alert("***** ProcMgr.ProcessCall()");

	setTimeout("processCallTimerCF()", 500);
	processCallTimerCF = function()
	{
	    if(PluginAPIMgr.CreateCall()==1)
		{
			sf.scene.get('Calling').visiblePreview();	
			RecogMgr.StopVoiceRecog(true);
			ProcMgr.registerCallKey();
		} 
		else
		{			
			WndMgr.StartOneBottonPopup(OneBtnPopupIndex.CREATE_CALL_FAIL_PHONE_NUMBER_ERROR);
		}
	}
}

ProcMgr.DisconnectCall = function(endType)
{
    alert("***** ProcMgr.DisconnectCall()");
        
    this.unregisterCallKey();
    PluginAPIMgr.DisconnectCall(endType);
    
    if(this.isQuitAfterCallEnd == true || this.isLogoutAfterCallEnd == true || this.isExitAfterCallEnd == true || this.isCloseAfterCallEnd==true)
    {
	   // don't display call end scene
       return;  
    }
    
    //show confirm popup
	if(this.CallInfo.IsTvMode == true && (g_Data.WIDGET_PARAM.start == false || 
		(g_Data.WIDGET_PARAM.start == true && g_Data.WIDGET_PARAM.mode != 'InCallFormTV' && this.ProductInfo.support_multitasking == false )))
	{
		
		this.CallInfo.IsProcesingEnd = true;
		StateMgr.Start_Call_Confirm_State(3);

		this.CallInfo.IsBlockIncomingCall = true;
		PluginAPIMgr.BlockIncomingCall();
	}
	//goto main list or close widget
	else
	{
		StateMgr.Start_Call_Ending_State(true);
	}
}

ProcMgr.CancelCall = function()
{
    alert("***** ProcMgr.CancelCall()");
    this.isCallCencel = true;
    PluginAPIMgr.DisconnectCall();
}

 ProcMgr.InprogressCall= function()
 {
    alert("***** ProcMgr.InprogressCall()");
    
    //close preview of  calling wnd
    WndMgr.CloseCallingPreView();
    
    this.getCallInfo();
    
    this.isIncomingCall= false;
    
    if(this.isCalling == true)
    {
        if(g_Data.GetCallRemoteHold() == true)
        {
            this.Resume();
        }
		else 
		{
			if(this.isConferenceCall==true && StateMgr.GetCurrentState()=="ConferenceCall")
			{
				WndMgr.UpdateConferenceCallMemberInfo();
			}
		}
		
		alert("update inprogress in call");
        return;
    }
    else
    {
        this.isCalling = true;
    }
    //init vol. & mic.
	if(this.ProductInfo.support_mixing_audio == false)
	{
		alert("turn on call mix volume");
		this.CurOutputMixVolume = 0;
		PluginAPIMgr.SetTVMixVolume(0);
		PluginAPIMgr.SetCallMixVolume(100);						
	}
	PluginAPIMgr.MuteMic(false);		
	    
	var camera_state = PluginAPIMgr.GetCameraState();
	
	if(this.CallInfo.IsSendingVideo == true && (camera_state == ENUM_CAM_STATE.CAM_STATE_DISCONNECTED || camera_state == ENUM_CAM_STATE.CAM_STATE_CONNECTING))
	{
		PluginAPIMgr.StopSendVideo();  
	}
	
	this.StartCall(); 
 }

ProcMgr.StartCall = function()
{
    alert("***** ProcMgr.StartCall()");
    
    RecogMgr.StopVoiceRecog(true);
	
	this.isCalling = true;
	this.registerCallKey();
    
    this.getCallInfo();  // add for multitasking
	this.flag_show_exit_popup = false;
	
	if(this.CallInfo.IsConference == true) 
    {
		if(this.CallInfo.IsSendingVideo == true || this.isReceivingVideo == true)
		{
			if(this.CallInfo.IsSendingVideo == true)
			{
				ProcMgr.Sync_FaceTracking_ePTZ_State();
			}			
			StateMgr.Start_Video_Call_State();
		}
		else
		{
			StateMgr.Start_Conference_Call_State();
		}
        
    }
    else if(this.CallInfo.CallType == ENUM_CALL_MEMBE_TYPE.INCOMING_P2P  ||  this.CallInfo.CallType == ENUM_CALL_MEMBE_TYPE.OUTGOING_P2P)  
    {
    	//check
		if(this.CallInfo.IsVideo == true)
		{
	        if(this.CallInfo.IsSendingVideo == false)
	        {
	        	alert('##################################################################################');        	
	        	alert('######################### isReceivingVideo = true ################################');
	        	alert('##################################################################################');        	
	            this.isReceivingVideo = true;
	        }
	        else
	        {
	        	ProcMgr.Sync_FaceTracking_ePTZ_State();
	        }
		}
				
		if(g_Data.WIDGET_PARAM.mode =='InCallFormTV' && this.IsDualViewMode() == false && PluginAPIMgr.IsPrevISPSource() == false)
    	{
    		alert('start call from tv');
			this.ChangeSourceMode(true);
    	}
		
    	StateMgr.Start_Video_Call_State();
    			
		setTimeout("startTimerCF()", 1000);
		startTimerCF = function(){
	
			//check video allow
			var showAllowPopup = ProcMgr.ProcessReceiveVideo();
			if(showAllowPopup == false)
			{
				var camera_state = PluginAPIMgr.GetCameraState();				
				if(camera_state == ENUM_CAM_STATE.CAM_STATE_DISCONNECTED || camera_state == ENUM_CAM_STATE.CAM_STATE_CONNECTING)
				{
					if (PluginAPIMgr.IsInCall() == 1)
					WndMgr.StartOneBottonPopup(OneBtnPopupIndex.CALL_START_WITHOUT_CAMERA);
				}
			}
		}
    } 
     else if(this.CallInfo.CallType == ENUM_CALL_MEMBE_TYPE.INCOMING_PSTN  ||  this.CallInfo.CallType == ENUM_CALL_MEMBE_TYPE.OUTGOING_PSTN)
    {
        StateMgr.Start_Skype_Out_Call_State(); 
    }        
}
 
ProcMgr.GoCall = function()
{
    alert("***** ProcMgr.GoCall()");
    
    if(StateMgr.currentState == "Main" ||  StateMgr.currentState == "Chat")
    {
          this.StartCall();
                   
          if(this.CallInfo.IsTvMode == true)
          {
				sf.service.setChannelControl(true);
          }
    }
    else
    { 
          StateMgr.ReturnToMainState(); 
    }    
}

ProcMgr.EndCall = function()
{
	
	alert("***** ProcMgr.EndCall()" );	
	///////////////////Set 1 ///////////////////////////
	
	if(this.callEndWaitingTimer == true)
	{
		alert("***** ProcMgr.EndCall()-> aready call ending" );
		if(this.isIncomingCall ==true)
		{
			this.isIncomingCall =false;
		}
		return;
	}
	
	if(StateMgr.GetCurrentState()!="Calling" && StateMgr.MainStateList[MAIN_STATE.CALLING].flagLoading != true && this.isCalling==false)
	{
		if(PluginAPIMgr.IsWidgetActivatedByAnswer()==0) 
		{
			if(this.isIncomingCall==false)
			{
				return;
			}
		}
	}
	
	//direct come in & showing connecting wind
	if(g_Data.WIDGET_PARAM.start == true && g_Data.WIDGET_PARAM.tryHideConnectWnd == false)
	{
		PluginAPIMgr.HideConnectingWnd();
	}
				
	//show confirm popup message
	if(this.CallInfo.IsTvMode == true && (g_Data.WIDGET_PARAM.start == false || 
		(g_Data.WIDGET_PARAM.start == true && g_Data.WIDGET_PARAM.mode != 'InCallFormTV' && this.ProductInfo.support_multitasking == false )))
	{
				
		if(this.CallInfo.IsProcesingEnd == false)
		{
			this.CallInfo.IsProcesingEnd = true;
			StateMgr.Start_Call_Confirm_State(3);
		}

		if(this.CallInfo.IsBlockIncomingCall == false)
		{
			this.CallInfo.IsBlockIncomingCall = true;
			PluginAPIMgr.BlockIncomingCall();
		}
		
		return;
	}
	///////////////////Set 2 ///////////////////////////
	
	if(this.callHoldTimer== true) //init
	{
		this.callHoldTimer= false;
		PluginAPIMgr.StopOSDTimer(ENUM_TIMER_TYPE.CALL_HOLD);
	}
	
	if(this.callResumeTimer== true) //init
	{
		this.callResumeTimer= false;
		PluginAPIMgr.StopOSDTimer(ENUM_TIMER_TYPE.CALL_HOLD);
	}
	
    if(this.isCalling == true)
    {
	    //init camera & volume setting
		this.Reset_FaceTracking_ePTZ_State();
		
		if(this.ProductInfo.support_mixing_audio == false)
		{
			alert("turn on tv mix volume");
			PluginAPIMgr.SetTVMixVolume(100);
			PluginAPIMgr.SetCallMixVolume(0);
			this.CurOutputMixVolume = 1;
		}
		PluginAPIMgr.MuteMic(false);
	}	
	
    g_Data.SetCallRemoteHold(false);//init
    this.isCalling = false; //init
    this.isConferenceCall = false; //init
    this.isVoiceMailSending = false; //init
    this.isReceivingVideo =false; //init
    g_Data.SetCallQualityGauge(1); //init
    g_Data.SetCallMemberVideoResolution("SD"); //init
	this.isPauseVideo = false; //init
	
	this.CallInfo.alreadyGetData = false;
        	
	var NNaviPlugin = sf.core.plugin('NNavi');
	NNaviPlugin.SetBannerState(1);
	
	//init speaker
	if(this.CallInfo.IsSpeakerMute == true)
	{	
		this.processVolumeMute(false);
	}
		
	///////////////////Set 3 ///////////////////////////
    
	if(this.isCloseAfterCallEnd== true)
	{
		alert("***** ProcMgr.EndCall()-> isCloseAfterCallEnd : " + this.isCloseAfterCallEnd);
		
		if(this.CallInfo.IsBlockIncomingCall == true)
		{
			this.CallInfo.IsBlockIncomingCall = false;
			PluginAPIMgr.UnblockIncomingCall(0);
		}
		this.isCloseAfterCallEnd = false; //init
		this.CloseWidget();
		return;
	}
	
	if(this.isExitAfterCallEnd== true)
	{
		alert("***** ProcMgr.EndCall()-> isExitAfterCallEnd : " + this.isExitAfterCallEnd);
		
		if(this.CallInfo.IsBlockIncomingCall == true)
		{
			this.CallInfo.IsBlockIncomingCall = false;
			PluginAPIMgr.UnblockIncomingCall(0);
		}
		
		this.isExitAfterCallEnd = false; //init
		this.ExitWidget();
		return;
	}

     if(this.isQuitAfterCallEnd == true)
    {
		alert("***** ProcMgr.EndCall()-> isQuitAfterCallEnd : " + this.isQuitAfterCallEnd);
		
		if(this.CallInfo.IsBlockIncomingCall == true)
		{
			this.CallInfo.IsBlockIncomingCall = false;
			PluginAPIMgr.UnblockIncomingCall(0);
		}
				
        this.isQuitAfterCallEnd = false; //init
		this.Signout(true);
        return;
    }
    
    if(this.isLogoutAfterCallEnd == true)
    {
		alert("***** ProcMgr.EndCall()-> isLogoutAfterCallEnd : " + this.isLogoutAfterCallEnd);

		if(this.CallInfo.IsBlockIncomingCall == true)
		{
			this.CallInfo.IsBlockIncomingCall = false;
			PluginAPIMgr.UnblockIncomingCall(0);
		}
		
		this.isLogoutAfterCallEnd = false; //init
		this.Signout(false);
		return;
    }
    
    if(this.isIncomingCall ==true)  // incoming call reject
    {
		alert("***** ProcMgr.EndCall()-> isIncomingCall : " + this.isIncomingCall);
		
        this.isIncomingCall =false;
		if(StateMgr.GetCurrentSubState()!="Calling" && StateMgr.MainStateList[MAIN_STATE.CALLING].flagLoading != true)
		{			
	   		if(StateMgr.GetCurrentState()!="Init")
			{
				this.unregisterCallKey();
				PluginAPIMgr.HideConnectingWnd();
				StateMgr.Stop_Noti_State();	
				
			}
			else
			{
				PluginAPIMgr.HideConnectingWnd();
				StateMgr.Start_Main_State();
				StateMgr.Hide_Noti_State();
			}

			if(PluginAPIMgr.IsWidgetActivatedByAnswer() == 1)
			{
				g_Data.WIDGET_PARAM.start = false;
			}			

			if(this.flag_show_exit_popup == true)
			{
				this.flag_show_exit_popup = false;
				StateMgr.Start_Exit_State(false);
			}
			
			if(this.CallInfo.IsBlockIncomingCall == true)
			{
				this.CallInfo.IsBlockIncomingCall = false;
				PluginAPIMgr.UnblockIncomingCall(0);
			}
			
			return;
		}
    }
   	
   	///////////////////Set 4 ///////////////////////////
    this.unregisterCallKey();
    	
	if(StateMgr.GetCurrentState()!="Init")
	{
		PluginAPIMgr.HideConnectingWnd();
	}


	///////////////////Set 5 ///////////////////////////
	// exit widget after call end
	if(this.flag_ExitAfterWatchingTV == true)
	{
		alert('exit widget after confirm popup');
		
		//End Skype widtet
		this.flag_ExitAfterWatchingTV = false;
		PluginAPIMgr.UnblockIncomingCall(0);
		this.CallInfo.IsBlockIncomingCall = false;
		
		g_Data.InitWidgetParam();
		this.GoOutWithSignIn(true);
	}
	else
	{
		alert('show call end popup window');
		
		if(this.CallInfo.IsBlockIncomingCall == false)
		{
			PluginAPIMgr.BlockIncomingCall();
			this.CallInfo.IsBlockIncomingCall = true;
		}
		
	    StateMgr.Start_Call_Ending_State(false);
		
		this.callEndWaitingTimer = true;
		if(this.isCallingFail == false)
		{
			PluginAPIMgr.StartOSDTimer("2000" , function() { ProcMgr.EndCallTimerCallback();}, ENUM_TIMER_TYPE.CALL_END);  
		}
		else
		{
			PluginAPIMgr.StartOSDTimer("10000" , function() { ProcMgr.EndCallTimerCallback();}, ENUM_TIMER_TYPE.CALL_END);  
		}
	}
}

 ProcMgr.DropCall = function()
 {
    alert("***** ProcMgr.DropCall()");
    WndMgr.CloseVideoCallRect();
    WndMgr.UpdateCallDroppedStatus();
 }

ProcMgr.EndCallTimerCallback = function()
{
	alert("***** ProcMgr.EndCallTimerCallback()");
	this.callEndWaitingTimer = false;
	this.isCallingFail = false;
	
	PluginAPIMgr.UnblockIncomingCall(0);
	this.CallInfo.IsBlockIncomingCall = false;

	if(g_Data.WIDGET_PARAM.start == true)
	{
		alert('exit widget after entering tv');

		if(g_Data.WIDGET_PARAM.mode == 'InCallFormTV')
		{
			this.GoOutWithSignIn(true);
		}
		else
		{
			if(this.ProductInfo.support_multitasking == false)
			{
				StateMgr.Start_Main_State();
				RecogMgr.StartVoiceRecog();
				
				if(this.flag_show_exit_popup == true)
				{
					this.flag_show_exit_popup = false;
					StateMgr.Start_Exit_State(false);
				}
			}
			else
			{
				this.GoOutWithSignIn(false);
			}
		}
	}
	else
	{
		StateMgr.Start_Main_State();
		RecogMgr.StartVoiceRecog();

		if(this.flag_show_exit_popup == true)
		{
			this.flag_show_exit_popup = false;
			StateMgr.Start_Exit_State(false);
		}
	}
	
	g_Data.InitWidgetParam();
 }
 
ProcMgr.ProcessCallingFail = function(fail_reason)
{
	alert("***** ProcMgr.ProcessCallingFail() reason -> " + fail_reason );
	this.isCallingFail = true;
	WndMgr.UpdateCallingMessage(fail_reason);
}

ProcMgr.StopCallingFailMsg = function()
{
	alert("***** ProcMgr.StopCallingFailMsg()");
	if(this.isCallingFail == true)
	{
		if(this.callEndWaitingTimer== true)
		{
			 PluginAPIMgr.StopOSDTimer(ENUM_TIMER_TYPE.CALL_END); 
		}
		ProcMgr.EndCallTimerCallback();
	}
}


//retrun true  
//return false
ProcMgr.ProcessReceiveVideo= function()
{
    alert("***** ProcMgr.ProcessReceiveVideo()-> this.isVideoAvailable : "+ this.isVideoAvailable);
	if(this.IsReceivingVideo()== true)
	{
		alert("***** ProcMgr.ProcessReceiveVideo()-> already receive video");
		return false;
	}	
	
	//video available event 
	if(this.isVideoAvailable == false && this.CallInfo.IsRecvVideoAvailable == false)
		{
		alert("***** no video *****");
			return false;
		}		
	
	//init
    this.isVideoAvailable = false; 
	
	//don't change during conf call.
	if(this.CallInfo.IsAutoRecvVieo == true  || this.CallInfo.IsConference == true) 
	{
		 return false;
	}
	else
	{
		StateMgr.Start_Call_Confirm_State(1);
		return true;
	}
	
	return false;
 }
 
ProcMgr.SetStartReceiveVideo= function()
{
	alert("***** ProcMgr.SetStartReceiveVideo()");
	PluginAPIMgr.StartReceiveVideo();
}
 
 ProcMgr.StartReceiveVideo= function()
 {
    alert("***** ProcMgr.StartReceiveVideo()");
    
	this.isPauseVideo = false;
	this.isReceivingVideo = true;
     
	WndMgr.UpdateVideoCallYourVideo();

 }

ProcMgr.HoldReceiveVideo= function()
{
	this.HoldReceiveVideo = true;
}

ProcMgr.StopReceiveVideo= function()
{
    alert("***** ProcMgr.StopReceiveVideo()");
    
    this.isReceivingVideo = false;
    
	WndMgr.UpdateVideoCallYourVideo();
}
 
ProcMgr.IsReceivingVideo= function()
{
    alert("***** ProcMgr.IsReceivingVideo()" + this.isReceivingVideo);	
   return  this.isReceivingVideo;
}

ProcMgr.StartSendVideo= function()
{
    alert("***** ProcMgr.StartSendVideo()");
    
    this.Sync_FaceTracking_ePTZ_State();
    
	PluginAPIMgr.StartSendVideo();
	WndMgr.UpdateVideoCallMyVideo();
	
	this.CallInfo.IsSendingVideo = true;
}
 
ProcMgr.StopSendVideo= function()
{
    alert("***** ProcMgr.StopSendVideo()");
    	
	this.Reset_FaceTracking_ePTZ_State();
    
    PluginAPIMgr.StopSendVideo();

	WndMgr.UpdateVideoCallMyVideo();
	
	this.CallInfo.IsSendingVideo = false;
}

ProcMgr.InitCameraOption= function()
{
	alert("***** ProcMgr.InitCameraOption()");

	this.isAutoFocusEnable();
	PluginAPIMgr.SetAutoFocus(PluginAPIMgr.GetAutoFocus()); 
	PluginAPIMgr.SetMicVolume(PluginAPIMgr.GetMicVolume());
}

ProcMgr.isAutoFocusEnable= function()
{
	alert("***** ProcMgr.isAutoFocusEnable()");
	if(PluginAPIMgr.isAutoFocusEnable()==1)
	{
		ProcMgr.isAutoFocus = true;
	}
	
	return ProcMgr.isAutoFocus;
}
ProcMgr.InitEPTZState = function(){
	alert("***** ProcMgr.InitEPTZState()");
	
	PluginAPIMgr.SaveDBAutoTracking(false);
	PluginAPIMgr.SaveDBZoom(0);
	PluginAPIMgr.SaveDBPan(0);
	PluginAPIMgr.SaveDBTilt(0);
	
	PluginAPIMgr.FaceTracking(false);
	PluginAPIMgr.SetZoomState(0);
	PluginAPIMgr.SetPanState(0);
	PluginAPIMgr.SetTiltState(0);
}
ProcMgr.UpdateCameraState= function()
{
    alert("***** ProcMgr.UpdateCameraState()");
    var currentState = StateMgr.GetCurrentState();
    //WndMgr.UpdateVoiceCallCameraState();
    WndMgr.UpdateSkypeOutCallCameraState();
    WndMgr.UpdateConferenceCallCameraState();

//Modified by Donghee
	if(this.isCalling == true)
	{
	   if(PluginAPIMgr.IsSendingVideo() ==0)
	   {
	        WndMgr.UpdateVideoCallCameraState();
	   }
	   else
	   {
	   		//Modified by Donghee
	   		// if(this.isCalling == true)
			ProcMgr.StopSendVideo(); 
	   }
	} 
   
   WndMgr.UpdateVideoSnapshotCameraState();   

   WndMgr.UpdateChangePictureCameraState();	
   WndMgr.UpdateMainCameraState();

   WndMgr.UpdateCameraCheckState();
      
   // for face recog
   PluginAPIMgr.ToggleFaceRecogEnable();
   WndMgr.UpdateSigninCameraState();
   if(currentState == 'FaceRecogSignin'){
		if(WndMgr.FaceRecogSigninStep=="FaceRecog"){
			if(StateMgr.MainStateList[MAIN_STATE.SIGNIN].flagLoad == true)
                {
                	WndMgr.DestroySignin();  //init 
                }
			StateMgr.Start_Signin_State();
		}
   }else if(currentState==="FaceRecogRegistration"){
   		if(WndMgr.FaceRecogRegistrationStep=="FaceDetect"){
   			ProcMgr.ReturnToFaceRecogRegistrationCaller();
		}else if(WndMgr.FaceRecogRegistrationStep=="Complete"){
			sf.scene.get("FaceRecogSecureComplete").updateButton();
		}
   }
   // call setting popup hide;
   WndMgr.UpdateCallSettingPopupState();
     // eptz
    WndMgr.UpdateCallCameraControlState();
    // listmainsetting
    WndMgr.UpdateListMainSettingCameraState();
    // videosetting popup
    WndMgr.UpdateVideoSettingsCameraState();
    alert("***** ProcMgr.UpdateCameraState() End");
   
}
 
  ProcMgr.ChangeToConferenceCall= function()
 {
    alert("***** ProcMgr.ChangeToConferenceCall() -> isConferenceCall : " + this.isConferenceCall);
    
    if(this.isCalling==true && this.isConferenceCall == false)
    {
    	if(this.CallInfo.IsTvMode == true)
    	{
    		this.ChangeSourceMode(false);
    	}
    	
        this.isConferenceCall = true;
        PluginAPIMgr.StopSendVideo();
		
		if(StateMgr.GetCurrentState()=="Main" && WndMgr.MainSubScene[3].Id == "ListMainLiveCall")
		{
			return;  // don't change to conf call	
		}
			
        StateMgr.Start_Conference_Call_State();
     }
 }
 
 ProcMgr.UpdateCallDuration = function( time)
{
    alert("***** ProcMgr.UpdateCallDuration()" + time);
    
    WndMgr.UpdateVideoCallDuration(time);
    WndMgr.UpdateConferenceCallDuration(time);
    WndMgr.UpdateSkypeOutCallDuration(time);
    WndMgr.UpdateVoiceMailRecordingDuration(time);
	WndMgr.UpdateHistoryVMDuration(time);
	WndMgr.UpdateContactListCallDuration(time);

}
 
 ProcMgr.UpdateCallMemberStatus = function()
 {
    alert("***** ProcMgr.UpdateCallMemberStatus()");
    
    WndMgr.UpdateConferenceCallMemberInfo();
 }
 
  ProcMgr.UpdateCallQuality = function(level)
 {
    alert("***** ProcMgr.UpdateCallQuality()");
	if(this.isCalling== true)
	{
		g_Data.SetCallQualityGauge(level);
		WndMgr.UpdateVideoCallQuality();
	}
 }
 
 ProcMgr.SendDTMF = function(keyValue)
 {
     alert("***** ProcMgr.SendDTMF() keycode : "+keyValue);
     
     switch(keyValue)
     {          
        case 0:
            PluginAPIMgr.SendDTMF(ENUM_DTMF.DTMF_1);
            break;
        case 1:
            PluginAPIMgr.SendDTMF(ENUM_DTMF.DTMF_2);
            break;
        case 2:
            PluginAPIMgr.SendDTMF(ENUM_DTMF.DTMF_3);
            break;
        case 3:
            PluginAPIMgr.SendDTMF(ENUM_DTMF.DTMF_4);
            break;
        case 4:
            PluginAPIMgr.SendDTMF(ENUM_DTMF.DTMF_5);
            break;
        case 5:
            PluginAPIMgr.SendDTMF(ENUM_DTMF.DTMF_6);
            break;
        case 6:
            PluginAPIMgr.SendDTMF(ENUM_DTMF.DTMF_7);
            break;
        case 7:
            PluginAPIMgr.SendDTMF(ENUM_DTMF.DTMF_8);
            break;
        case 8:
            PluginAPIMgr.SendDTMF(ENUM_DTMF.DTMF_9);            
            break;
        case 9:
            PluginAPIMgr.SendDTMF(ENUM_DTMF.DTMF_STAR);
            break;
        case 10:
            PluginAPIMgr.SendDTMF(ENUM_DTMF.DTMF_0);
            break;            
		case 11 :
            PluginAPIMgr.SendDTMF(ENUM_DTMF.DTMF_POUND);
            break; 
     } 
 }
 
 ProcMgr.ToggleLocalHold = function()
 {
    alert("***** ProcMgr.ToggleLocalHold()");
	
	if(this.callHoldTimer==true || this.callResumeTimer==true)
	{
		return;
	}

    if(g_Data.GetCallLocalHold() ==true)
    {
    	if(StateMgr.GetCurrentState()== "VideoCall")
    	{
    		this.callResumeTimer= true;
    		PluginAPIMgr.StartOSDTimer("700" ,
			function() { if (ProcMgr.isCalling == true) {
						ProcMgr.callResumeTimer = false;
						PluginAPIMgr.Hold(false);
				}}, 
				ENUM_TIMER_TYPE.CALL_HOLD); 
    	}
    	else
    	{
    		PluginAPIMgr.Hold(false);
    	}
    }
    else
    {
		if(StateMgr.GetCurrentState()== "VideoCall")
		{
			this.callHoldTimer= true;
			ProcMgr.LocalHoldWait();
			PluginAPIMgr.StartOSDTimer("2000" ,
				 function() { if (ProcMgr.isCalling == true) {
					ProcMgr.callHoldTimer = false;
					PluginAPIMgr.Hold(true);
			}}, 
			ENUM_TIMER_TYPE.CALL_HOLD);   
		}
		else
		{
			PluginAPIMgr.Hold(true);
		}
    }
 }
 
 ProcMgr.LocalHoldWait = function()
 {
 	if(g_Data.GetCallLocalHold()!=true && g_Data.GetCallRemoteHold()!=true)
	{
		WndMgr.VideoCallLocalHoldWait();
	} 	
 }
 
  ProcMgr.LocalHold = function()
 {
    alert("***** ProcMgr.LocalHold()");
    // g_Data.SetCallRemoteHold(false);
    // WndMgr.VideoCallLocalHold();
    // WndMgr.ConferenceCallLocalHold();
    // WndMgr.SkypeOutCallLocalHold();
    // WndMgr.MainLiveCallLocalHold();
 }

  ProcMgr.RemoteHold = function()
 {
    alert("***** ProcMgr.RemoteHold()");
    g_Data.SetCallRemoteHold(true);
    WndMgr.VideoCallRemoteHold();
    WndMgr.ConferenceCallRemoteHold();
    WndMgr.SkypeOutCallRemoteHold();
 }

  ProcMgr.Resume = function()
 {
    alert("***** ProcMgr.Resume()");
    g_Data.SetCallRemoteHold(false);
    WndMgr.VideoCallResume();
    WndMgr.ConferenceCallResume();
    WndMgr.SkypeOutCallResume();
 }
 
ProcMgr.SelectCallSwitch = function()
{
	alert("***** ProcMgr.SelectCallSwitch()");
	StateMgr.Start_Call_Switch_State(); 
	
}

ProcMgr.StartCallSwitch = function()
{
	alert("***** ProcMgr.StartCallSwitch()");
	this.isCallStartAfterCallEnd = true;
	ProcMgr.DisconnectCall();
	
}

ProcMgr.CancelCallSwitch = function()
{
	alert("***** ProcMgr.CancelCallSwitch()");

	StateMgr.Stop_Call_Switch_State(true);	
}


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//// Voice Mail  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

 
ProcMgr.SendingVoiceMail= function()
{
    alert("***** ProcMgr.SendingVoiceMail()");
     this.isCalling = false; //init
    this.isVoiceMailSending = true;
    g_Data.SetVoiceMailInputInfo(g_Data.DATA_CREATE_CALL_INPUT_INFO.callee_name);
    
    ProcMgr.registerCallKey();
    StateMgr.Start_Voice_Mail_State();
    
	WndMgr.HidePreview();
}

ProcMgr.LeaveVoicemail= function(callee_name)
{
    alert("***** ProcMgr.LeaveVoicemail()");
    this.isCalling = false; //init
    this.isVoiceMailSending = true;
    g_Data.SetVoiceMailInputInfo(callee_name);
    PluginAPIMgr.LeaveVoicemail(); 
    
    ProcMgr.registerCallKey();
    StateMgr.Start_Voice_Mail_State();
}

ProcMgr.UploadVoiceMail= function()
{
    alert("***** ProcMgr.UploadVoiceMail()");
    PluginAPIMgr.DisconnectCall();
    
}

ProcMgr.CancelVoiceMail= function()
{
    alert("***** ProcMgr.CancelVoiceMail()");
    
    PluginAPIMgr.CancelVoicemail();
    
}

ProcMgr.EndVoiceMail= function()
{
     alert("***** ProcMgr.EndVoiceMail()");
    this.isVoiceMailSending = false; //init
	
	this.callEndWaitingTimer= true;
	PluginAPIMgr.StartOSDTimer("2000" , function() { ProcMgr.EndCallTimerCallback();}, ENUM_TIMER_TYPE.CALL_END);  
}

ProcMgr.PlayHistoryVoicemail = function(nIndex)
{
	alert("***** ProcMgr.PlayHistoryVoicemail() : index = " + nIndex);
	var result = PluginAPIMgr.PlayHistoryVoicemail(nIndex);
	
	if(result == '1')
	{
		this.isVoiceMailPlaying=true;
	}
	else
	{
		this.isVoiceMailPlaying=false;
	}
	
	return result;
}

ProcMgr.StopHistoryVoicemail = function(nIndex)
{
	alert("***** ProcMgr.StopHistoryVoicemail() : index = " + nIndex);
	var result = PluginAPIMgr.StopHistoryVoicemail(nIndex);
	this.isVoiceMailPlaying=false;
	
	return result;   	
}
 
 
 
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////  Chatting  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

ProcMgr.OpenChatWithContact = function(skype_name)
{
    g_Data.SetChatMemberInfo(skype_name);
    
    if(this.isChatting == true &&  StateMgr.currentState =="Chat") //temp code
    {
		if(  StateMgr.currentSubState =="LiveContactSwitch")
		{
			StateMgr.Stop_Live_Contact_List_State(false); 
		}
		
		PluginAPIMgr.CloseChat();
		WndMgr.InitChat();
		sf.scene.get('Chat').init();
		
		PluginAPIMgr.OpenChatWithContact(skype_name);
		this.isChatting =true;	
		
		sf.scene.focus('Chat');	 
		setTimeout("UpdateTimerCF()", 0);
		UpdateTimerCF = function(){
			sf.scene.get("Chat").updateMsgBox();
		}
    }
    else
    {
        this.isChatting =true;
        PluginAPIMgr.OpenChatWithContact(skype_name);
        StateMgr.Start_Chat_State(); 
     }
}

ProcMgr.OpenChat = function(chat_name)
{
     if(this.isChatting == true &&  StateMgr.currentState =="Chat") //temp code
    {
		if(  StateMgr.currentSubState =="LiveContactSwitch")
		{
			this.Stop_Live_Contact_List_State(false); 
		}
		
		PluginAPIMgr.CloseChat();
		sf.scene.get('Chat').init();
		
		PluginAPIMgr.OpenChat(chat_name);
		this.isChatting =true;
		
		sf.scene.focus('Chat');
		setTimeout("UpdateTimerCF()", 0);
		UpdateTimerCF = function(){
			sf.scene.get("Chat").updateMsgBox();
		}
    }
    else
    {
        this.isChatting =true;
        PluginAPIMgr.OpenChat(chat_name);
        StateMgr.Start_Chat_State(); 
    }
}

ProcMgr.DisconnectChat = function()
{
    this.isChatting = false;  //init
    this.ChatParticipants = ""; //init
    
    PluginAPIMgr.CloseChat();
}

ProcMgr.CloseChat = function()
{      
    StateMgr.Start_Main_State(); 
}

ProcMgr.SendMessage = function(send_msg)
{
    PluginAPIMgr.SendMessage(send_msg);
    StateMgr.Stop_Chat_Msg_Send_State(true);
}

ProcMgr.UpdateChat =function()
{
    alert("***** WndMgr.UpdateChat()");
    /*if(WndMgr.ShowStateOfChatWnd()){
        sf.scene.get("Chat").updateMsgBox();   
    }
    else
    {
		if(this.MainListFuncType == MAIN_LIST_POPUP_FUNCTION_TYPE.CHAT_REMOVE){
			
			this.MainListFuncType = MAIN_LIST_POPUP_FUNCTION_TYPE.NOTHING;
			
			var Scene = sf.scene.get(WndMgr.GetMainSubSceneID());	
			Scene.Activation();
					
			StateMgr.Stop_Remove_State(true);
		}		
		else if(StateMgr.MainStateList[MAIN_STATE.MAIN].flagLoad == true && WndMgr.GetMainSubIndex() == 1){
				
			sf.scene.get("ListMainProfile").Refresh();
		}		
	}*/
}	
	
ProcMgr.NewChat = function()
{   
	//WndMgr.UpdateNewChatMsg();
}

ProcMgr.CallandChatMemberUpdate = function()
{
	alert("***** ProcMgr.CallandChatMemberUpdate()");
	
	WndMgr.UpdateVideoCallMemberInfo();
	WndMgr.UpdateConferenceCallMemberInfo();

}

ProcMgr.GetCurrentChatMember= function()
{
	this.ChatParticipants =  PluginAPIMgr.GetCurrentChatProperty(ENUM_CHAT_PROPERTY.P_PARTICIPANTS);

	alert("***** ProcMgr.GetCurrentChatMember() this.ChatParticipants --> " + this.ChatParticipants);
	var s = this.ChatParticipants;
	var pos =0;
	this.ChatMember = "";
	this.ChatMemberSkypeName = "";
	var my_id = PluginAPIMgr.GetMySkyeName();
	var end_pos =0;
	this.numOfChatMember = 0;
	
	for(pos =0 ; pos <this.ChatParticipants.length; )
	{
		end_pos = s.indexOf(" ");
		if(end_pos== -1)
		{
			if(s!=my_id)
			{
				if(this.ChatMember.length ==0)
				{
					
					this.ChatMember = this.ChatMember+PluginAPIMgr.GetChatMemberDisplayName(s);
					this.ChatMemberSkypeName = this.ChatMemberSkypeName+s;
					this.numOfChatMember++;
				}
				else
				{
					this.ChatMember = this.ChatMember+", "+PluginAPIMgr.GetChatMemberDisplayName(s);
					this.ChatMemberSkypeName = this.ChatMemberSkypeName+", "+s;
					this.numOfChatMember++;
				}				
			}
			break;
		}
		else
		{
			var mem_id = this.ChatParticipants.substring(pos, pos+end_pos);
			if(mem_id!=my_id)
			{
				if(this.ChatMember.length ==0)
				{
					this.ChatMember = this.ChatMember+PluginAPIMgr.GetChatMemberDisplayName(mem_id);
					this.ChatMemberSkypeName = this.ChatMemberSkypeName+mem_id;
					this.numOfChatMember++;
				}
				else
				{
					this.ChatMember = this.ChatMember+", "+PluginAPIMgr.GetChatMemberDisplayName(mem_id);
					this.ChatMemberSkypeName = this.ChatMemberSkypeName+", "+mem_id;
					this.numOfChatMember++;
				}				
			}	
					
			s=s.substring(end_pos+1);
			alert("s : " + s);			
		}
		
		pos =pos+ end_pos+1;
	}
	alert("***** ProcMgr.GetCurrentChatMember() --> " + this.ChatMember);
	return this.ChatMember;
}

ProcMgr.GetNumberOfChatMember= function()
{
	return this.numOfChatMember;
}

ProcMgr.GetChatMemberSkypeName= function()
{
	return this.ChatMemberSkypeName;
}


ProcMgr.UpdateChatMember = function()
{   
	WndMgr.UpdateChatMember();
}



///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 
//// Settings  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

////  Online State
ProcMgr.SetOnlineStatus= function(setIndex)
{
    alert("***** ProcMgr.SetOnlineStatus()");
    PluginAPIMgr.SetAvailability(setIndex);
    StateMgr.Stop_Online_Status_State(true);
}

////  Change Picture
ProcMgr.SetAvatar = function(avatarImg)
{
    alert("***** ProcMgr.SetAvatar()");
	PluginAPIMgr.SetMyAvatar(avatarImg)
    StateMgr.Stop_Change_Picture_State(true);
}

////  Change Password
ProcMgr.ChangePassword= function(old_pwd, new_pwd, re_pwd)
{  
    alert("***** ProcMgr.ChangePassword()");
    
    g_Data.SetChangePWDInfo(old_pwd, new_pwd, re_pwd);
    
     WndMgr.NextStepChangePassword();
     
     if(new_pwd !=re_pwd)
     {       
        ProcMgr.HandleChangePassword( OneBtnPopupIndex.PWD_NEW_REPEAT_PWD_NOT_MATCH);
     }
     else
     {
        PluginAPIMgr.ChangePassword();
     }
}

ProcMgr.HandleChangePassword= function(result)
{
    alert("***** ProcMgr.HandleChangePassword()");
    WndMgr.NextStepChangePassword();
    
    if(result == OneBtnPopupIndex.PWD_INVALID_NEW_PWD)
    {
        var error_type = PluginAPIMgr.ValidatePasswd(PluginAPIMgr.GetMySkyeName() , g_Data.DATA_CHANGE_PWD_INPUT_INFO.new_pwd);
        
         switch(error_type)
        {
            case ENUM_PWD_VALIDATERESULT.NOT_VALIDATED :
                WndMgr.StartOneBottonPopup(OneBtnPopupIndex.PWD_INVALID_NEW_PWD);
                break;
            case ENUM_PWD_VALIDATERESULT.TOO_SHORT :
                WndMgr.StartOneBottonPopup(OneBtnPopupIndex.PWD_TOO_SHORT);
                break;
            case ENUM_PWD_VALIDATERESULT.TOO_LONG : 
                WndMgr.StartOneBottonPopup(OneBtnPopupIndex.PWD_TOO_LONG);
                break;
            case ENUM_PWD_VALIDATERESULT.CONTAINS_INVALID_CHAR :
                WndMgr.StartOneBottonPopup(OneBtnPopupIndex.PWD_CONTAINS_INVALID_CHAR);
                break;
            case ENUM_PWD_VALIDATERESULT.CONTAINS_SPACE : 
                WndMgr.StartOneBottonPopup(OneBtnPopupIndex.PWD_CONTAINS_SPACE);
                break;
            case ENUM_PWD_VALIDATERESULT.SAME_AS_USERNAME : 
                WndMgr.StartOneBottonPopup(OneBtnPopupIndex.PWD_SAME_AS_USERNAME);
                break;
            case ENUM_PWD_VALIDATERESULT.INVALID_FORMAT : 
                WndMgr.StartOneBottonPopup(OneBtnPopupIndex.PWD_INVALID_FORMAT);
                break;
            case ENUM_PWD_VALIDATERESULT.CONTAINS_INVALID_WORD : 
                WndMgr.StartOneBottonPopup(OneBtnPopupIndex.PWD_CONTAINS_INVALID_WORD);
                break;
            case ENUM_PWD_VALIDATERESULT.TOO_SIMPLE : 
                WndMgr.StartOneBottonPopup(OneBtnPopupIndex.PWD_TOO_SIMPLE);
                break;
                
             default:
                 WndMgr.StartOneBottonPopup(OneBtnPopupIndex.PWD_INVALID_NEW_PWD);
                break;
                
        }
    }
    else
    {
        WndMgr.StartOneBottonPopup(result);
    }
}

ProcMgr.SaveChangedPassword= function()
{
    alert("***** ProcMgr.SaveChangedPassword()");
    
    if(PluginAPIMgr.RecognitionPluginAvailable==false)
    {
    	return;
    }

    var new_pwd = g_Data.GetChangedPWDInfo();
    
    ProcMgr.SetMyPwd(new_pwd);
}

        



/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//// add contact /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

ProcMgr.SearchNewContact = function(contact_name)
{
    var normalized_contact_name = PluginAPIMgr.NormalizeIdentity(contact_name);
    
    if(normalized_contact_name.length >0)
    {
         alert("***** ProcMgr.SearchNewContact() : true");
    PluginAPIMgr.SearchNewContact(contact_name);
    }
    else
    {
        alert("***** ProcMgr.SearchNewContact() : false");
        PluginAPIMgr.SearchNewContact(contact_name);
    }
    
    WndMgr.NextStepAddContact(); 
}

ProcMgr.HandleSearchFailNewContact = function(result)
{
    alert("***** ProcMgr.HandleSearchNewContact()");
    WndMgr.BackStepAddContact();
    WndMgr.StartOneBottonPopup(result);
}

ProcMgr.SearchContactProfile = function(contact_name)
{
    alert("***** ProcMgr.SearchContactProfile()");
    WndMgr.NextStepAddContact(); 
    PluginAPIMgr.SearchContactProfile(contact_name);    
}

ProcMgr.AddContact = function(skype_name, hello_msg)
{   
     alert("***** ProcMgr.AddContact() : skype_name = "+skype_name);

     if(PluginAPIMgr.IsBlocked(skype_name) == 1)
     {
        WndMgr.NextStepAddContact(); 
         WndMgr.StartOneBottonPopup(OneBtnPopupIndex.IS_BLOCKED_SKYPE_NAME);
     }
     else if(PluginAPIMgr.IsMyName(skype_name) == 1)
     {
        WndMgr.NextStepAddContact();
         WndMgr.StartOneBottonPopup(OneBtnPopupIndex.IS_MY_SKYPE_NAME);
     }
     else if(PluginAPIMgr.IsMyBuddy(skype_name) == 1)
     {
        WndMgr.NextStepAddContact();
        WndMgr.StartOneBottonPopup(OneBtnPopupIndex.IS_ALREADY_EXIST_SKYPE_NAME, skype_name);
     }
     else
     {
        PluginAPIMgr.AddContact(skype_name, hello_msg);
        
        WndMgr.NextStepAddContact();
        WndMgr.StartOneBottonPopup(OneBtnPopupIndex.ADD_CONTACT_SENT);
    }
}

ProcMgr.AddSkypeOutContact = function(phone_number, diplay_name)
{   
    alert("***** ProcMgr.AddSkypeOutContact()");
	 if(phone_number.length <=0)
	 {
	        WndMgr.NextStepAddContact(); 
	        WndMgr.StartOneBottonPopup(OneBtnPopupIndex.INVALID_PHONE_NUMBER);
	 }
     else if(PluginAPIMgr.IsBlocked(phone_number) == 1)
     {
        WndMgr.NextStepAddContact(); 
         WndMgr.StartOneBottonPopup(OneBtnPopupIndex.IS_BLOCKED_PHONE_NUMBER);
     }
     else if(PluginAPIMgr.IsMyBuddy(phone_number) == 1)
     {
        WndMgr.NextStepAddContact();
        WndMgr.StartOneBottonPopup(OneBtnPopupIndex.IS_ALREADY_EXIST_PHONE_NUMBER, phone_number);
     }
     else
     {
        PluginAPIMgr.AddSkypeOutContact(phone_number, diplay_name);
        WndMgr.NextStepAddContact();
        WndMgr.StartOneBottonPopup(OneBtnPopupIndex.NEW_CONTACT_ADDED);
     }
}


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////TOOLS///////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

ProcMgr.BlockContact = function(skypeName,removeOption,type)
{
	this.blockName = skypeName;
	if(removeOption){

		if(type == MAIN_LIST_POPUP_FUNCTION_TYPE.CONTACT_BLOCK){
			
			this.MainListFuncType = MAIN_LIST_POPUP_FUNCTION_TYPE.CONTACT_BLOCK_REMOVE;
		}
		else if(type == MAIN_LIST_POPUP_FUNCTION_TYPE.HISTORY_BLOCK){
			
			this.MainListFuncType = MAIN_LIST_POPUP_FUNCTION_TYPE.HISTORY_BLOCK_REMOVE;
		}
		else if(type == MAIN_LIST_POPUP_FUNCTION_TYPE.CHAT_BLOCK){
			
			this.MainListFuncType = MAIN_LIST_POPUP_FUNCTION_TYPE.CHAT_BLOCK_REMOVE;
		}			
	}
	else{
		
		this.MainListFuncType = type;	
	}
	
	return PluginAPIMgr.BlockContact(skypeName,removeOption);
}

ProcMgr.UnblockContact = function(skypeName,type){
	//modify 12.11
	this.unblockName =skypeName;
	this.MainListFuncType = type;
	PluginAPIMgr.UnblockContact(skypeName);
}

ProcMgr.AuthorizeContact = function(skypeName){
	
	PluginAPIMgr.AuthorizeContact(skypeName);
}

ProcMgr.IgnoreAuthReqContact = function(skypeName){
	
	PluginAPIMgr.RejectAndBlock(skypeName, "0");
}

ProcMgr.BlockAuthReqContact = function(skypeName){
	
    alert("***** ProcMgr.BlockAuthReqContact() : skypeName = " + skypeName);
	this.blockName = skypeName;
	this.MainListFuncType = MAIN_LIST_POPUP_FUNCTION_TYPE.CONTACT_BLOCK_REQEST;
	PluginAPIMgr.RejectAndBlock(skypeName, "1");
}

ProcMgr.Blocked = function(){

 	var sceneId = WndMgr.GetMainSubSceneID();
	var Scene = null;
	var Display_name = null;
	alert("sceneId---------------------------------- "+sceneId);
	if(sceneId=="ListMainContact"||sceneId=="ListMainHistory"){
		Scene = sf.scene.get(sceneId);
		Display_name = Scene.list.GetCurDisplayName();
	}
	var skype_name	= "";
	var finalName = ""; 

	if((sceneId == "ListMainContact") && (this.MainListFuncType == MAIN_LIST_POPUP_FUNCTION_TYPE.CONTACT_BLOCK_REQEST))
		skype_name = this.blockName;
	else if(Display_name)
		skype_name = Display_name; 
	else{
		if(sceneId=="ListMainContact"||sceneId=="ListMainHistory"){
			skype_name = Scene.list.GetCurIdentityName(); // Identity_name
		}else{
			skype_name = this.blockName;
		}
	}

	if(skype_name.length > 15){
		
		finalName = skype_name.slice(0,14) + '...';
	}
	else{
		finalName = skype_name;
	}

	alert("ProcMgr.Blocked : finalName = " + finalName);

	switch(this.MainListFuncType) {
		
		case MAIN_LIST_POPUP_FUNCTION_TYPE.CONTACT_BLOCK_REQEST:	
			WndMgr.StartOneBottonPopup(OneBtnPopupIndex.BLOCKED_NEW_CONTACT, finalName);
			this.blockName = null;
			break;
			
		case MAIN_LIST_POPUP_FUNCTION_TYPE.CONTACT_BLOCK:
			sf.scene.hide('Block');
			WndMgr.StartOneBottonPopup(OneBtnPopupIndex.CONTACT_LIST_BLOCKED, finalName);
			break;
			
		case MAIN_LIST_POPUP_FUNCTION_TYPE.CONTACT_BLOCK_REMOVE:
			sf.scene.hide('Block');			
			WndMgr.StartOneBottonPopup(OneBtnPopupIndex.CONTACT_LIST_BLOCK_REMOVED, finalName);
			break;
			
		case MAIN_LIST_POPUP_FUNCTION_TYPE.HISTORY_BLOCK:			
			sf.scene.hide('Block');
			WndMgr.StartOneBottonPopup(OneBtnPopupIndex.HISTORY_LIST_BLOCKED, finalName);
			break;
			
		case MAIN_LIST_POPUP_FUNCTION_TYPE.HISTORY_BLOCK_REMOVE:
			sf.scene.hide('Block');
			WndMgr.StartOneBottonPopup(OneBtnPopupIndex.HISTORY_LIST_BLOCK_REMOVED, finalName);
			break;
			
		case MAIN_LIST_POPUP_FUNCTION_TYPE.CHAT_BLOCK:
			sf.scene.hide('Block');
			WndMgr.StartOneBottonPopup(OneBtnPopupIndex.CHAT_LIST_BLOCKED, finalName);
			break;
			
		case MAIN_LIST_POPUP_FUNCTION_TYPE.CHAT_BLOCK_REMOVE:		
			sf.scene.hide('Block');
			WndMgr.StartOneBottonPopup(OneBtnPopupIndex.CHAT_LIST_BLOCK_REMOVED, finalName);
			break;
			
		case MAIN_LIST_POPUP_FUNCTION_TYPE.OPTION_BLOCK:			
			var SettingsBlockScene = sf.scene.get("SettingsBlockedContacts");
			SettingsBlockScene.update();
			WndMgr.StartOneBottonPopup(OneBtnPopupIndex.OPTION_BLOCKED, finalName);
			break;	
			
		default:
			this.BlockedByAnotherDevice();
			break;
			
	}
		
	this.MainListFuncType = MAIN_LIST_POPUP_FUNCTION_TYPE.NOTHING;
}

ProcMgr.BlockedByAnotherDevice = function(){

	//Skip
	alert("ProcMgr.BlockedByAnotherDevice");

	// && WndMgr.GetCurrentOptionsSubscene == 'OptionsBlockedUsers'
	alert("StateMgr.GetCurrentSubState() = "+StateMgr.GetCurrentSubState());
	if(StateMgr.GetCurrentSubState() == SUB_STATE.SETTINGSBLOCKEDCONTACTS){
			
		var SettingsBlockScene = sf.scene.get("SettingsBlockedContacts");
		SettingsBlockScene.update();		
	}
}

ProcMgr.UnBlocked = function(){

	var sceneId = WndMgr.GetMainSubSceneID();
	var Scene = null;
	var Display_name = null;
	alert("sceneId---------------------------------- "+sceneId);
	if(sceneId=="ListMainContact"||sceneId=="ListMainHistory"){
		Scene = sf.scene.get(sceneId);
		Display_name = Scene.list.GetCurDisplayName();
	}
	var skype_name	= "";
	var finalName = ""; 

	if(Display_name)
		skype_name = Display_name; 
	else{
		if(sceneId=="ListMainContact"||sceneId=="ListMainHistory"){
			skype_name = Scene.list.GetCurIdentityName(); // Identity_name
		}else{
			skype_name = this.unblockName;
		}
	}
		
	if(skype_name.length > 28){
		
		finalName = skype_name.slice(0,27) + '...';
	}
	else{
		finalName = skype_name;
	}

	alert("ProcMgr.UnBlocked : finalName = " + finalName);

	switch(this.MainListFuncType) {
		
		case MAIN_LIST_POPUP_FUNCTION_TYPE.CONTACT_UNBLOCK:
			sf.scene.hide('Block');
			WndMgr.StartOneBottonPopup(OneBtnPopupIndex.CONTACT_LIST_UNBLOCKED, finalName);
			break;
			
		case MAIN_LIST_POPUP_FUNCTION_TYPE.HISTORY_UNBLOCK:
			sf.scene.hide('Block');
			WndMgr.StartOneBottonPopup(OneBtnPopupIndex.HISTORY_LIST_UNBLOCKED, finalName);
			break;
			
		case MAIN_LIST_POPUP_FUNCTION_TYPE.CHAT_UNBLOCK:
			sf.scene.hide('Block');
			WndMgr.StartOneBottonPopup(OneBtnPopupIndex.CHAT_LIST_UNBLOCKED, finalName);
			break;
			
		case MAIN_LIST_POPUP_FUNCTION_TYPE.OPTION_UNBLOCK:
			var SettingsBlockScene = sf.scene.get("SettingsBlockedContacts");
			SettingsBlockScene.update();
			WndMgr.StartOneBottonPopup(OneBtnPopupIndex.OPTION_UNBLOCKED, finalName);
			break;	
				
		default:
			this.BlockedByAnotherDevice();
			break;			
	}

	this.MainListFuncType = MAIN_LIST_POPUP_FUNCTION_TYPE.NOTHING;
}

ProcMgr.RemoveItem = function(Index)
{
	
		this.MainListFuncType = MAIN_LIST_POPUP_FUNCTION_TYPE.HISTORY_REMOVE;
		PluginAPIMgr.RemoveHistory(Index);		
		StateMgr.Stop_Remove_State(true);		
		WndMgr.StartOneBottonPopup(OneBtnPopupIndex.HISTORY_REMOVED);					
	}

ProcMgr.UpdateHistoryList = function(){

	if(this.MainListFuncType == MAIN_LIST_POPUP_FUNCTION_TYPE.HISTORY_REMOVE){
        			
		this.MainListFuncType = MAIN_LIST_POPUP_FUNCTION_TYPE.NOTHING;
		
//		var Scene = sf.scene.get(WndMgr.GetMainSubSceneID());	
//		Scene.Activation();
				
//		StateMgr.Stop_Remove_State(true);		
	}
	else if(StateMgr.MainStateList[MAIN_STATE.MAIN].flagLoad == true && WndMgr.GetMainSubIndex() == 1){

        var scene = sf.scene.get("ListMainHistory");
        scene.Refresh();		
	}
}

ProcMgr.ProcessAuthRequest = function(){

	if(StateMgr.MainStateList[MAIN_STATE.MAIN].flagLoad == true && WndMgr.GetMainSubIndex() == 0){

		var scene = sf.scene.get("ListMainContact");
		scene.Refresh();
		WndMgr.StartOneBottonPopup(OneBtnPopupIndex.ADDED_NEW_CONTACT); 
	}
}

ProcMgr.IgnoreAuthRequest = function(){

	if (StateMgr.MainStateList[MAIN_STATE.MAIN].flagLoad == true && WndMgr.GetMainSubIndex() == 0) {
		
		var scene = sf.scene.get("ListMainContact");
		scene.Refresh();
		sf.scene.focus('ListMainContact');
	}	
}

ProcMgr.ShowPopupMessageForTextTest = function(data){

	var Index = data - 1;

	if(Index < 0){
		
		alert("Error!!");
		return;
	}
	
	WndMgr.StartOneBottonPopup(Index);
}


///////Face Recognition //////////////////////////////////////////////////////////////////////

///// management of ID, PWD, Face image path
ProcMgr.SyncFaceDB = function(){
	alert("ProcMgr.SyncFaceDB");
	var saved_info = PluginAPIMgr.GetMyStorageInfo();
	if(saved_info)
	{
		info = JSON.parse(saved_info);
		
		alert("***** ProcMgr.SyncFaceDB() --> saved_info : "+saved_info);
		for(var i=0;i<10;i++){
			var checkFlag = false;
			for(var j=0;j<info.SkypeAccount.length;j++){
				if(info.SkypeAccount[j].face_id==i){
					checkFlag = true;
					break;
				}
			}
			if(checkFlag){
				continue;
			}else{
				PluginAPIMgr.EraseFace(i);
			}
		}
	}else{							//there is no account info
		for(var i=0;i<10;i++){
			PluginAPIMgr.EraseFace(i);
		}
	}
	
}

ProcMgr.SetMyPwd = function(pwd)
{
	alert("ProcMgr.SetMyPwd");
		
	var myId = PluginAPIMgr.GetMySkyeName();
	
	var saved_info = PluginAPIMgr.GetMyStorageInfo();
	var info = null;
	var index =0;
	
	var flagSaved = false;
	
	if(saved_info)
	{
		info = JSON.parse(saved_info);
		
		alert("***** ProcMgr.SetMyPwd() --> saved_info : "+saved_info);	
		
		for(index=0; index<info.SkypeAccount.length; ++index)
		{
			if(info.SkypeAccount[index].id == myId)
			{
				flagSaved = true;
				break;
			}
		}	
	}
	else
	{
		info = new Object();
		info.SkypeAccount = new Array();
	}

	alert("***** ProcMgr.SetMyPwd() --> index : "+index);
		
	if(flagSaved == false)
	{
		info.SkypeAccount[index] = new Object();
		info.SkypeAccount[index].id = myId;
		info.SkypeAccount[index].face = "none";	
		info.SkypeAccount[index].face_id = -1;
		info.SkypeAccount[index].pwd_check = false;	
	}
	
	info.SkypeAccount[index].pwd = pwd;
	
	var info_string = JSON.stringify(info);	
	
	alert("***** ProcMgr.SetMyPwd() --> info_string : "+info_string);
	
	PluginAPIMgr.SetMyStorageInfo(info_string); 
}

ProcMgr.GetMyPwd = function(pwd)
{
	alert("ProcMgr.GetMyPwd");
	
	var myId = PluginAPIMgr.GetMySkyeName();
	
	var saved_info = PluginAPIMgr.GetMyStorageInfo();
	var info = null;
	var index =0;
	
	var myId_saved = false;
	
	if(saved_info)
	{
		info = JSON.parse(saved_info);
		alert("***** ProcMgr.GetMyPwd() --> saved_info : "+saved_info);	
		
		
		for(index=0; index<info.SkypeAccount.length; index++)
		{
			if(info.SkypeAccount[index].id == myId)
			{
				myId_saved = true;
				break;
			}
		}
	}
	else
	{
		return "";
	}
	
	var pwd = "";
	
	if(myId_saved==true)
	{
		pwd =info.SkypeAccount[index].pwd;
	}
	
	return pwd;
}

ProcMgr.SetMyFaceImagePath = function(path, recogId)
{
	alert("ProcMgr.SetMyFaceImagePath");
	
	var myId = PluginAPIMgr.GetMySkyeName();
	
	var saved_info = PluginAPIMgr.GetMyStorageInfo();
	var info = null;
	var index =0;
	
	if(saved_info)
	{
		info = JSON.parse(saved_info);
		alert("***** ProcMgr.SetMyFaceImagePath() --> saved_info : "+saved_info);	
		
		
		for(index=0; index<info.SkypeAccount.length; index++)
		{
			if(info.SkypeAccount[index].id == myId)
			{
				break;
			}
		}
	}
	if(info.SkypeAccount[index].face_id != -1){		//registered account remove pre face
		// var trainResult = JSON.stringify(RecogMgr.trainResult);
		// alert("***** ProcMgr.SetMyFaceImagePath()-->train result : )"+trainResult);
		// alert("overwrite to id : "+info.SkypeAccount[index].face_id);
		// PluginAPIMgr.OverWriteFace(trainResult,info.SkypeAccount[index].face_id);
		if(recogId != info.SkypeAccount[index].face_id){
			PluginAPIMgr.EraseFace(info.SkypeAccount[index].face_id);
			info.SkypeAccount[index].face = path;
			info.SkypeAccount[index].face_id = recogId;
		}
	}else{
		info.SkypeAccount[index].face = path;
		info.SkypeAccount[index].face_id = recogId;	
	}

	var info_string = JSON.stringify(info);	
	
	alert("***** ProcMgr.SetMyFaceImagePath() --> info_string : "+info_string);	
	
	PluginAPIMgr.SetMyStorageInfo(info_string); 
	
	g_Data.SetFaceRecogCompleteSkypeName(myId);	
}

ProcMgr.GetMyFaceImagePath = function()
{
	alert("ProcMgr.GetMyFaceImagePath");
	
	var myId = PluginAPIMgr.GetMySkyeName();
	
	var saved_info = PluginAPIMgr.GetMyStorageInfo();
	var info = null;
	var index =0;
	
	this.isRegisteredFace = false;
	
	if(saved_info)
	{
		info = JSON.parse(saved_info);
		alert("***** ProcMgr.GetMyFaceImagePath() --> saved_info : "+saved_info);	
				
		for(index=0; index<info.SkypeAccount.length; index++)
		{
			if(info.SkypeAccount[index].id == myId)
			{
				break;
			}
		}
	}
	else
	{
		return "";
	}
	
	var path = info.SkypeAccount[index].face;
	
	if(path == "none")
	{
		return "";
	}
	else
	{
		this.isRegisteredFace = true;
		alert("***** ProcMgr.GetMyFaceImagePath() : "+path);
		return path;
	}	
}

ProcMgr.InitMyFaceImagePath = function()
{
	alert("ProcMgr.InitMyFaceImagePath");
	
	var myId = PluginAPIMgr.GetMySkyeName();
	
	var saved_info = PluginAPIMgr.GetMyStorageInfo();
	var info = null;
	var index =0;
	
	if(saved_info)
	{
		info = JSON.parse(saved_info);
		alert("***** ProcMgr.SetMyFaceImagePath() --> saved_info : "+saved_info);	
		
		
		for(index=0; index<info.SkypeAccount.length; index++)
		{
			if(info.SkypeAccount[index].id == myId)
			{
				break;
			}
		}
	}

	PluginAPIMgr.EraseFace(info.SkypeAccount[index].face_id);
	
	info.SkypeAccount[index].face = "none";	
	info.SkypeAccount[index].face_id = -1;
	
	var info_string = JSON.stringify(info);	
	
	alert("***** ProcMgr.InitMyFaceImagePath() --> info_string : "+info_string);	
	
	PluginAPIMgr.SetMyStorageInfo(info_string);
	
	this.isRegisteredFace = false; 	
}

ProcMgr.CheckImageDuplicate= function(path, recogId)
{
	alert("ProcMgr.CheckImageDuplicate");
	
	var myId = PluginAPIMgr.GetMySkyeName();
	
	var saved_info = PluginAPIMgr.GetMyStorageInfo();
	var info = null;
	var index =0;
	
	if(saved_info)
	{
		info = JSON.parse(saved_info);
		alert("***** ProcMgr.CheckImageDuplicate() --> saved_info : "+saved_info);	
				
		for(index=0; index<info.SkypeAccount.length; index++)
		{
			if(info.SkypeAccount[index].id != myId)
			{
				if(info.SkypeAccount[index].face == path && info.SkypeAccount[index].face_id==recogId)
				{
					g_Data.SetFaceRecogDupliceteSkypeName(info.SkypeAccount[index].id);
					return true;
				}
			}
		}
	}
	
	return false;
}

ProcMgr.SetFlagPwdCheck = function(flagPwdCheck)
{
	alert("ProcMgr.SetFlagPwdCheck");
	
	var myId = PluginAPIMgr.GetMySkyeName();
	
	var saved_info = PluginAPIMgr.GetMyStorageInfo();
	var info = null;
	var index =0;
	
	if(saved_info)
	{
		info = JSON.parse(saved_info);
		alert("***** ProcMgr.SetFlagPwdCheck() --> saved_info : "+saved_info);	
				
		for(index=0; index<info.SkypeAccount.length; index++)
		{
			if(info.SkypeAccount[index].id == myId)
			{
				break;
			}
		}
	}

	info.SkypeAccount[index].pwd_check = flagPwdCheck;	

	var info_string = JSON.stringify(info);	
	
	alert("***** ProcMgr.SetFlagPwdCheck() --> info_string : "+info_string);	
	
	PluginAPIMgr.SetMyStorageInfo(info_string); 
}

ProcMgr.GetFlagPwdCheck = function()
{
	alert("ProcMgr.GetFlagPwdCheck");
	
	var myId = PluginAPIMgr.GetMySkyeName();
	
	var saved_info = PluginAPIMgr.GetMyStorageInfo();
	var info = null;
	var index =0;
	
	if(saved_info)
	{
		info = JSON.parse(saved_info);
		alert("***** ProcMgr.GetFlagPwdCheck() --> saved_info : "+saved_info);	
		
		
		for(index=0; index<info.SkypeAccount.length; index++)
		{
			if(info.SkypeAccount[index].id == myId)
			{
				break;
			}
		}
	}
	else
	{
		return false;
	}
		
	if(info.SkypeAccount[index].pwd_check == 'undefined')
	{
		alert("***** ProcMgr.GetFlagPwdCheck() : undefined");
		return false;
	}
	else
	{
		alert("***** ProcMgr.GetFlagPwdCheck() : "+info.SkypeAccount[index].pwd_check);
		return info.SkypeAccount[index].pwd_check;
	}	
}
ProcMgr.DeleteFaceRecog = function(){
	WndMgr.HideSettingsFaceRecognition();
	WndMgr.StartConfirmPopup(ConfirmPopupIndex.FACE_DELETE);
}
ProcMgr.LinkAccount = function(){
	alert("ProcMgr.LinkAccount");
	WndMgr.FaceRecogSigninStep = "LinkAccount";
	WndMgr.NextStepFaceRecogSignin();
}
/// Account Manager
ProcMgr.CheckInputPwd = function(input_pwd)
{
	alert("ProcMgr.CheckInputPwd");
	//2013 modify by minseok : for facerecog
	var currentSubState = StateMgr.GetCurrentSubState(); 
	alert("Current Sub State is "+currentSubState)
	if(currentSubState=="AccountManager")
	{
		ProcMgr.CheckInputPwdForAccountManager(input_pwd);
	}
	else if(currentSubState == "SettingsFaceRecognition"){
		ProcMgr.CheckInputPwdForFaceRegister(input_pwd);
	}
	else
	{
		ProcMgr.CheckInputPwdForSignin(input_pwd);
	}
}

ProcMgr.CancelCheckPwd= function()
{
	alert("ProcMgr.CancelCheckPwd");
	var currentState = StateMgr.GetCurrentState();
	var currentSubState = StateMgr.GetCurrentSubState();
	if(currentState=="FaceRecogSignin"){
		if(WndMgr.isShowCheckPwd= true){
			WndMgr.HideCheckPwd();
		}
		if(WndMgr.FaceRecogSigninStep=="ChooseAccount"){
			WndMgr.ReturnFaceRecogSignin();
		}else{
		WndMgr.BackStepFaceRecogSignin();
	}
	}
	else if(currentSubState=="AccountManager")
	{
		WndMgr.BackStepAccountManager();
	}
	else if(currentSubState=="SettingsFaceRecognition"){
		alert("stop facerecog State");
		StateMgr.Stop_SettingsFaceRecognition_State(true);
	}
	else
	{
		//WndMgr.BackStepFaceRecogSignin();
		if(WndMgr.isShowCheckPwd= true){
			WndMgr.HideCheckPwd();
		}
		StateMgr.Start_Welcome_State();
	}
}
ProcMgr.CheckInputPwdForFaceRegister = function(input_pwd){
	alert("ProcMgr.CheckInputPwdForFaceRegister");
	var curr_pwd = ProcMgr.GetMyPwd();
	
	if(curr_pwd==input_pwd){
		alert("pwd is correct!!");
		WndMgr.ShowSettingsFaceRecognition();
		
	}else{
		WndMgr.StartOneBottonPopup(OneBtnPopupIndex.ACCOUNT_INCORRECT_PASSWORD);
		StateMgr.Stop_SettingsFaceRecognition_State(true);
	}
	
}
ProcMgr.CheckInputPwdForAccountManager= function(input_pwd)
{
	alert("ProcMgr.CheckInputPwdForAccountManager");
	WndMgr.NextStepAccountManager();
	
	var curr_pwd = ProcMgr.GetMyPwd();
	
	if(curr_pwd==input_pwd)
	{
		if(this.isRegisteredFace==true)
		{
			if(this.isReRegisterFace==true)
			{
				ProcMgr.StartFaceRecogRegistration();
			}
			else
			{
				WndMgr.NextStepAccountManager();
			}
			
		}
		else
		{
			ProcMgr.StartFaceRecogRegistration();
		}		
	}
	else
	{
		WndMgr.StopLoading();
		
		WndMgr.StartOneBottonPopup(OneBtnPopupIndex.ACCOUNT_INCORRECT_PASSWORD);
		WndMgr.BackStepAccountManager();
	}
}

ProcMgr.CheckInputPwdForSignin= function(input_pwd)
{	
	alert("ProcMgr.CheckInputPwdForSignin");
	
	// var index = g_Data.GetFaceRecogSelectedIndex();
	var accountName = null;
	//2013 modify by minseok
	var RecogResult = g_Data.GetFaceRecogSelectedAccount();
	if(RecogResult){
		alert("id is "+RecogResult.Name);
		alert("ProcMgr.CheckInputPwdForSignin "+RecogResult.Pwd);
		accountName = RecogResult.Name;
		ProcMgr.RequestFaceRegistrationAfterSignin(accountName, input_pwd);
	}else{
		var confirmResult = g_Data.GetFaceRecogResult();
		var index = g_Data.GetFaceRecogSelectedIndex();
		alert("id is "+confirmResult[index].id);
		accountName = confirmResult[index].id;
		ProcMgr.Signin(accountName, input_pwd, false);	
	}
	
	
	// WndMgr.NextStepFaceRecogSignin();
	
	/*if(RecogResult[index].pwd==input_pwd)
	{
		ProcMgr.Signin(RecogResult[index].id, RecogResult[index].pwd, false);		
	}
	else
	{
		WndMgr.StopLoading();
		
		WndMgr.StartOneBottonPopup(OneBtnPopupIndex.FACE_RECOG_INCORRECT_PASSWORD);
		WndMgr.BackStepFaceRecogSignin();
	}*/
	
	// ProcMgr.Signin(RecogResult.Name, input_pwd, false);	 
		 
}
/**
 * rawData.recognitionResult[i]=>{
	 *			"h" : 
	 * 			"imageFilePath" : 
	 * 			"nFaceRecogID" :
	 * 			"w" : 
	 * 			"x" : 
	 * 			"y" :
 * }
 */
ProcMgr.SuccessFaceRecogSigninRegist= function(){
	alert("ProcMgr.SuccessFaceRecogSigninRegist : ");
	
	var selectedObj = g_Data.GetFaceRecogSelectedItem();
	alert("image Path = "+selectedObj.Avata);
	var pathLen = selectedObj.Avata.indexOf("?");
	var fixedPath = selectedObj.Avata.substring(0, pathLen);
	alert("fixed image Path = "+fixedPath);
	// PluginAPIMgr.SubscribeFaceRecogEvent();
	// PluginAPIMgr.FaceTrainingThumnail(fixedPath);
	RecogMgr.SetTrainResultFromPath(fixedPath);
	this.StartFaceRegistrationFromTrainThumnail();
	
}
ProcMgr.ProcessReRegisterFace= function()
{
	alert("ProcMgr.ProcessReRegisterFace");
	this.isReRegisterFace = true;
	
	ProcMgr.InitMyFaceImagePath();
	WndMgr.NextStepAccountManager();
}

ProcMgr.ProcessDeleteFace= function()					
{
	alert("ProcMgr.ProcessDeleteFace");
	ProcMgr.InitMyFaceImagePath();
	
	WndMgr.StartOneBottonPopup(OneBtnPopupIndex.ACCOUNT_DELETE_PWD_COMPLETE);
	// WndMgr.NextStepAccountManager();
}

ProcMgr.ProcessSigninAfterPwdCheck = function(index)
{
	alert("ProcMgr.ProcessSigninAfterPwdCheck");
	this.isSigninAfterPwdCheck=true;
	g_Data.SetFaceRecogSelectedIndex(index);
	
	WndMgr.InputPwdStepFaceRecogSignin(); 
}

ProcMgr.InputPwdAgainforFaceSignin= function()
{
	alert("ProcMgr.InputPwdAgainforFaceSignin");
	
	if(this.isFaceRegistrationAfterSignin == true)
	{
		// sf.scene.get('AccountConnection').InputPWDAgain();
		// WndMgr.InputInfoStepFaceRecogSignin();
		WndMgr.ReturnFaceRecogSignin();
	}
	else if(this.isSigninAfterPwdCheck== true)
	{
		WndMgr.InputPwdStepFaceRecogSignin();
	}
}


/// Signin

ProcMgr.StartFaceRecogSignin = function()
{
	alert("ProcMgr.StartFaceRecogSignin");
	this.isFaceRegistrationAfterSignin = false; //init
	this.isSigninAfterPwdCheck =false;//init
	this.CountOfRecogFail=0;
	this.CountOfRecogInfo =0;
	g_Data.SetFaceRecogSelectedAccount(null);		//init
	
	// PluginAPIMgr.StartCameraForFaceRecognition(320,174,1280,720); 16:9
	//(146,237,600,450) * 1.5 = (219, 355.5, 900, 675) 
	//ProcMgr.SyncFaceDB();		//sync engine db -> move FaceRecogSignin.js
	StateMgr.Start_Face_Recog_Signin_State();
	
	PluginAPIMgr.StartCameraForFaceRecognition(11,330,1280,720);
		
	PluginAPIMgr.SubscribeFaceRecogEvent();
	
	this.FaceRecogTimer = true;

}

ProcMgr.RetryFaceRecogSignin = function()
{
	alert("ProcMgr.RetryFaceRecogSignin");
	
	this.isFaceRegistrationAfterSignin = false; //init
	this.isSigninAfterPwdCheck=false; //init
	this.CountOfRecogFail=0;
	this.CountOfRecogInfo =0;
	
	PluginAPIMgr.StartCameraForFaceRecognition(11,330,1280,720);
	// PluginAPIMgr.StartCameraForFaceRecognition(320,174,1280,720);

	WndMgr.BackStepFaceRecogSignin();
	
	PluginAPIMgr.SubscribeFaceRecogEvent();
}

ProcMgr.StopFaceRecogSignin  = function()
{	
	alert("ProcMgr.StopFaceRecogSignin");
	
	if(this.FaceRecogTimer==true)
	{
		this.FaceRecogTimer = false;
		PluginAPIMgr.StopOSDTimer(ENUM_TIMER_TYPE.POPUP_WND);
	}
	
	ProcMgr.StopFaceRecog();
	WndMgr.InitFaceRecogArea();
		
	PluginAPIMgr.StopCameraForFaceRecognition();
}

ProcMgr.StartFaceRecog = function()
{
	alert("ProcMgr.StartFaceRecog");
	this.isFaceRecog = true;

	PluginAPIMgr.StartFaceRecognitionAll();
}

ProcMgr.PauseFaceRecog = function(flagByUser)
{
	if(this.FaceRecogTimer==true)
	{
		this.FaceRecogTimer = false;
		PluginAPIMgr.StopOSDTimer(ENUM_TIMER_TYPE.POPUP_WND);
	}
	
	if(flagByUser==true)
	{
		this.CountOfRecogFail=0;
	}
	
	this.CountOfRecogInfo =0;
	
	alert("ProcMgr.PauseFaceRecog");
	if(this.isFaceRecog== true)
	{
		this.isFaceRecog = false;
		PluginAPIMgr.StopFaceRecognition();
	}
}

ProcMgr.RetryFaceRecog = function()
{
	alert("ProcMgr.RetryFaceRecog");
	if(this.isFaceRecog== false)
	{
		this.isFaceRecog = true;
		PluginAPIMgr.StartFaceRecognitionAll();
	}
}

ProcMgr.StopFaceRecog = function()
{
	if(this.isFaceRecog== true)
	{
		this.isFaceRecog = false;
		PluginAPIMgr.StopFaceRecognition();				
	}
	
	PluginAPIMgr.UnsubscribeFaceRecogEvent(); 		
}


ProcMgr.ProcessSelectedRecogResult= function(index)
{
	alert("ProcMgr.ProcessSelectedRecogResult");
	this.isFaceRegistrationAfterSignin = false; //init
	this.isSigninAfterPwdCheck=false; //init
	
	this.FaceRecogResultIndex = index;
	var RecogResult = g_Data.GetFaceRecogResult();
	
	if(RecogResult[index].registered == true){			
		//if(RecogResult[0].pwd_check==false)
		if(RecogResult[index].pwd_check==false)
		{
			ProcMgr.Signin(RecogResult[index].id, RecogResult[index].pwd, false);
		}
		else
		{
			ProcMgr.ProcessSigninAfterPwdCheck(index);
		}		
	}
	else						//unknown
	{
		WndMgr.NotRegisteredStepFaceRecogSignin();
	}
}

ProcMgr.RequestFaceRegistrationAfterSignin = function(id, pwd)
{
	alert("ProcMgr.RequestFaceRegistrationAfterSignin");
	
	this.isFaceRegistrationAfterSignin = true;
	ProcMgr.Signin(id, pwd, false);
}


/// Registration

ProcMgr.RequestFaceRecogRegistration = function()
{
	alert("ProcMgr.RequestFaceRecogRegistration");
	
	if(StateMgr.GetCurrentSubState()=="SettingsFaceRecognition")
	{
		WndMgr.NextStepAccountManager();
	}
	else if(StateMgr.GetCurrentState() == "CreateAccountSuccess")
	{
		ProcMgr.StartFaceRecogRegistration();
	}
	else if(StateMgr.GetCurrentState() == "FaceRecogSignin")
	{
		WndMgr.NextStepFaceRecogSignin();
	}	
}

ProcMgr.SkipFaceRecogRegistration = function()
{
	alert("ProcMgr.SkipFaceRecogRegistration");
	if(StateMgr.GetCurrentSubState()=="SettingsFaceRecognition")
	{
		WndMgr.BackStepAccountManager();
	}
	else if(StateMgr.GetCurrentState() == "CreateAccountSuccess")
	{
		WndMgr.BackStepCreateAccountSuccess();
	}
	else if(StateMgr.GetCurrentState() == "FaceRecogSignin")
	{
		WndMgr.BackStepFaceRecogSignin();
	}	
}

ProcMgr.StartFaceRecogRegistration = function()
{
	alert("ProcMgr.StartFaceRecogRegistration");
	this.isReRegisterFace = false; // init
	this.CountOfTrainingFail =0;
	
	// PluginAPIMgr.StartCameraForFaceRecognition(320,174,1280,720); 16:9
	//(146,237,600,450) * 1.5 = (219, 355.5, 900, 675) 
	ProcMgr.SyncFaceDB();		//sync engine db
	PluginAPIMgr.StartCameraForFaceRecognition(11,330,1280,720);
	
	if(StateMgr.GetCurrentSubState().length > 0)
	{
		alert("save CallerState : "+StateMgr.GetCurrentSubState());
		this.FaceRegistrationCallerState = StateMgr.GetCurrentSubState();
	}
	else
	{
		alert("save CallerState : "+StateMgr.GetCurrentState());
		this.FaceRegistrationCallerState=StateMgr.GetCurrentState();
	}	
	
	StateMgr.Start_Face_Recog_Registration_State();	

}

ProcMgr.CompliteFaceRecogRegistration = function(flagPwdCheck)
{
	alert("ProcMgr.CompliteFaceRecogRegistration");
	
	ProcMgr.SetFlagPwdCheck(flagPwdCheck);
	
	if(this.FaceRegistrationCallerState == "SettingsFaceRecognition")	//2013 modify by minseok
	{
		StateMgr.Start_Main_State();
		// StateMgr.Start_Account_Manager_State();
	}
	else
	{
		ProcMgr.StartLoggedInState();
	}
}

ProcMgr.ReturnToFaceRecogRegistrationCaller = function()
{
	alert("ProcMgr.ReturnToFaceRecogRegistrationCaller");
	if(RecogMgr.trainResult){		//remove pre face
		PluginAPIMgr.EraseFace(RecogMgr.trainResult.detectResult);
	}
	if(this.FaceRegistrationCallerState == "SettingsFaceRecognition")		//2013 modify by minseok
	{
		StateMgr.Start_Main_State();
		StateMgr.Start_SettingsFaceRecognition_State(true);
		// StateMgr.Start_Account_Manager_State();
	}
	else if(this.FaceRegistrationCallerState == "CreateAccountSuccess")
	{
		StateMgr.Start_Create_Account_Success_State();
	}
	else
	{
		ProcMgr.StartLoggedInState();
	}
}

ProcMgr.RetryFaceRecogRegistration = function()			//back to face detect Step
{
	alert("ProcMgr.RetryFaceRecogRegistration");
	
	/*var faceImagePath = ProcMgr.GetMyFaceImagePath();
	if(faceImagePath.length>0)
	{
		ProcMgr.InitMyFaceImagePath();
	}*/
	if(RecogMgr.trainResult){		//remove pre face
		PluginAPIMgr.EraseFace(RecogMgr.trainResult.detectResult);
	}
	
	PluginAPIMgr.StartCameraForFaceRecognition(11,330,1280,720);
	/*2012 scenario
	PluginAPIMgr.SubscribeFaceRecogEvent();
	ProcMgr.RetryFaceDetect();*/
	
	WndMgr.BackStepFaceRecogRegistration();		//
}

ProcMgr.StopFaceRecogRegistration= function()
{
	alert("ProcMgr.StopFaceRecogRegistration");
	
	if(this.FaceDetectTimer==true)
	{
		this.FaceDetectTimer = false;
		PluginAPIMgr.StopOSDTimer(ENUM_TIMER_TYPE.POPUP_WND);
	}
	
	ProcMgr.StopFaceTraining();
	ProcMgr.StopFaceDetect();
	
	PluginAPIMgr.StopCameraForFaceRecognition();		
}
/**
 * add by minseok
 */
ProcMgr.StartFaceRegistrationFromTrainThumnail = function(){
	alert("ProcMgr.StartFaceRegistrationFromTrainThumnail");
	this.isReRegisterFace = false; // init
	this.CountOfTrainingFail =0;
	
	if(StateMgr.GetCurrentSubState().length > 0)
	{
		alert("save CallerState : "+StateMgr.GetCurrentSubState());
		this.FaceRegistrationCallerState = StateMgr.GetCurrentSubState();
	}
	else
	{
		alert("save CallerState : "+StateMgr.GetCurrentState());
		this.FaceRegistrationCallerState=StateMgr.GetCurrentState();
	}	
	
	StateMgr.Start_Face_Recog_Registration_State("TrainThumnail");	
}
ProcMgr.StartFaceDetect = function()
{
	alert("ProcMgr.StartFaceDetect");
	this.isFaceDetect = true;
	
	PluginAPIMgr.StartFaceDetection();
}

ProcMgr.PauseFaceDetect = function(flagByUser)
{
	alert("ProcMgr.PauseFaceDetect");
	
	if(this.FaceDetectTimer==true)
	{
		this.FaceDetectTimer = false;
		PluginAPIMgr.StopOSDTimer(ENUM_TIMER_TYPE.POPUP_WND);
	}
	
	if(flagByUser==true)
	{
		this.CountOfTrainingFail =0;
		WndMgr.UpdateFaceRecogBoxColor(g_Image.IMAGE_FACE_RECOG_REGISTRATION_BOX_RED);
	}
	
	if(this.isFaceDetect== true)
	{
		this.isFaceDetect = false;
		PluginAPIMgr.StopFaceDetection();
	}
	
	if(this.isFaceTraining== true)
	{
		ProcMgr.StopFaceTraining(); 
	}
}

ProcMgr.RetryFaceDetect = function()
{
	alert("ProcMgr.RetryFaceDetect");
	if(this.isFaceTraining== true)
	{
		ProcMgr.StopFaceTraining(); 
	}
	
	if(this.isFaceDetect== false)
	{
		this.isFaceDetect = true;
		PluginAPIMgr.StartFaceDetection();
	}
}

ProcMgr.StopFaceDetect = function()
{
	if(this.isFaceDetect== true)
	{
		this.isFaceDetect = false;
		PluginAPIMgr.StopFaceDetection();				
	}	
	
	PluginAPIMgr.UnsubscribeFaceRecogEvent(); 	
}


ProcMgr.StartFaceTraining = function(face_info)
{
	alert("ProcMgr.StartFaceTraining");
	if(this.isFaceTraining== false)
	{
		this.isFaceTraining = true;
	
		WndMgr.UpdateFaceRecogBoxColor(g_Image.IMAGE_FACE_RECOG_REGISTRATION_BOX_RED);
		PluginAPIMgr.StartFaceTraining(face_info);
	}
}

ProcMgr.StopFaceTraining = function()
{
	alert("ProcMgr.StopFaceTraining");
	if(this.isFaceTraining== true)
	{
		this.isFaceTraining = false;
	
		PluginAPIMgr.StopFaceTraining();
	}

}

ProcMgr.SetCallInfoPrevState = function(prev_state)
{
	/*
	 Source/App/Skype 
	 */	
	this.CallInfo.PrevState = prev_state;
	
}

//only inprogress... 
ProcMgr.getCallInfo = function()
{	
	alert("getCallInfo");	
	if(this.CallInfo.alreadyGetData == true)
	{		
		return;
	}
	
	var callInfoMsg = PluginAPIMgr.GetCallInfo();	
	alert("callInfoMsg=" + callInfoMsg);

	if(callInfoMsg)
	{
		var STX = String.fromCharCode(2);
		var ETX = String.fromCharCode(3);
		var splitter = ETX + STX;
		
		var Result = callInfoMsg.split(splitter);
		
		//1. IsConferneceCall
		if(Result[0] == '1')
		{
			this.CallInfo.IsConference = true;
		}
		else
		{
			this.CallInfo.IsConference = false;
		}
		//2.Call type
		if(Result[1] == '1')
		{
			this.CallInfo.IsVideo = true;
		}
		else
		{
			this.CallInfo.IsVideo = false;
		}	
	
		//3.Call member type
		this.CallInfo.CallType = parseInt(Result[2]);
		
		//4. Call Identity
		this.CallInfo.Identity = Result[3];	
	
		//5. Call displayName
		this.CallInfo.DisplayName = Result[4];
	
		//6. Call avata image
		this.CallInfo.AvataImg = Result[5];			
		
		if(this.CallInfo.Identity == 'echo123' || this.CallInfo.AvataImg.length ==0)
		{		
			var ResStr = sf.env.getResolution();
			var AvatarPath = "images/"+ResStr+"/thumbnail/";
			
			if(this.CallInfo.Identity == 'echo123')
			{
				alert("test call");
				//g_Image.IMAGE_CALL_BLANK_AVATAR_166_TEST;
				this.CallInfo.AvataImg = AvatarPath + "testcall_avatar_166.png";
			}
			else if(this.CallInfo.CallType == ENUM_CALL_MEMBE_TYPE.INCOMING_PSTN || this.CallInfo.CallType == ENUM_CALL_MEMBE_TYPE.OUTGOING_PSTN)
			{
				alert("no AvataImg -- PSTN");
				//g_Image.IMAGE_CALL_BLANK_AVATAR_166_PSTN;
				this.CallInfo.AvataImg =  AvatarPath + "pstn_contact_166.png";
			}
			else
			{
				alert("no AvataImg -- pepeople");
				//g_Image.IMAGE_CALL_BLANK_AVATAR_166_MAN;
				this.CallInfo.AvataImg = AvatarPath + "blank_avatar_166.png";
			}		
		}
			
		//7. sending video
		if(Result[6] == '1')
		{
			this.CallInfo.IsSendingVideo = true;
		}
		else
		{
			this.CallInfo.IsSendingVideo = false;
		}		
	
		//8. receicving video
		if(Result[7] == '1')
		{
			this.CallInfo.IsRecvVideoAvailable = true;
		}
		else
		{
			this.CallInfo.IsRecvVideoAvailable = false;
		}
	
		//9. auto recieve
		if(Result[8] == '1')
		{
			this.CallInfo.IsAutoRecvVieo = true;
		}
		else
		{
			this.CallInfo.IsAutoRecvVieo = false;
		}		
	}
		
	//check status
	this.CallInfo.IsSpeakerMute = false
	this.CallInfo.IsMicMute = false;	
	this.CallInfo.IsTvMode = false;

	this.CallInfo.IsProcesingEnd = false;
	this.CallInfo.IsBlockIncomingCall = false;
	
	this.CallInfo.firstDefaultAutoFaceTrackingOn = false;
	this.CallInfo.alreadyGetData = true;
}

ProcMgr.StartPreviewOfVideoSnapshot = function()
{
	if(WndMgr.Is1366x768Panel() == true)
	{
		PluginAPIMgr.StartPreview(299,117,768,432,true);//416,100,768,432
	}
	else
	{
		PluginAPIMgr.StartPreview(422,164,1080,608,true);
	}
}

ProcMgr.StartPreviewOfCameraCheckConnected = function()
{
	if(this.ProductInfo.sub_info_code == "UD")
	{
		setTimeout("StartVideoTimerCF()", 1700);

		StartVideoTimerCF = function()
		{
			if(StateMgr.GetCurrentState() == 'CameraCheckConnected')
			{
				PluginAPIMgr.StartPreview(628,329,672,381,false);
			}
	    }
	}
	else
	{
		if(WndMgr.Is1366x768Panel() == true)
		{
			PluginAPIMgr.StartPreview(448,235,480,270,false);
		}
		else
		{
			PluginAPIMgr.StartPreview(628,329,672,381,false);
		}
	}
}


ProcMgr.ChangeSourceMode = function(TurnOn)
{
	//set flag
	if(this.CallInfo)
	{
		this.CallInfo.IsTvMode = TurnOn;
	}
	
	this.SourceMode = TurnOn;
	
	//turn off mic mute becase of disapper mic. mute icon
	ProcMgr.CallInfo.IsMicMute = false;
	
	PluginAPIMgr.StartOSDTimer("500",
		function() {
			
			//show/hide source 
			PluginAPIMgr.SetSourceMode(TurnOn);
			//turn on/off channel banner
			sf.service.setChannelControl(TurnOn);
						
			if(ProcMgr.ProductInfo.support_mixing_audio == false)
			{
				alert("turn on call mix volume, turn off tv mix volume");
				//initialize
				PluginAPIMgr.SetTVMixVolume(0);
				PluginAPIMgr.SetCallMixVolume(100);
				ProcMgr.CurOutputMixVolume = 0;
			}
			PluginAPIMgr.MuteMic(false);
		},
		ENUM_TIMER_TYPE.CALL_HOLD
	);
}

ProcMgr.CheckMissedCallList = function()
{
	if(StateMgr.GetCurrentState() != "Main")
	{
		StateMgr.Start_Main_State();	
	}	
	
	WndMgr.FocusToItemOfHistoryList(0); 
}

ProcMgr.ContextLoading = function()
{
	StateMgr.Start_Noti_State(NOTI_STATE.CONTEXT_LOADING);
	//check... prevent incoming call
}

ProcMgr.PlayVoicemailforJump = function(history_timestamp)
{
	var history_index = PluginAPIMgr.GetIndexOfHistory(history_timestamp);
	StateMgr.Start_Jump_To_Main_State(1,history_index);
	sf.scene.get("ListMainHistory").enterPlaybtn();
}

/// start call...
ProcMgr.Sync_FaceTracking_ePTZ_State = function()
{
	if(PluginAPIMgr.SyncAutoFaceTracking() == false)
	{
		PluginAPIMgr.SyncZoomState();
		PluginAPIMgr.SyncPanState();
		PluginAPIMgr.SyncTiltState();
	}
}

//call end & onHide...
ProcMgr.Reset_FaceTracking_ePTZ_State = function()
{
	PluginAPIMgr.FaceTracking(false);

	PluginAPIMgr.SetZoomState(0);
	PluginAPIMgr.SetPanState(0);
	PluginAPIMgr.SetTiltState(0);
}
			        
ProcMgr.processVolumeMute = function(mute)
{
	if(mute == this.CallInfo.IsSpeakerMute)
	{
		alert('processVolumeMute same value!!!');
		return;
	}	
	
	if(mute == false)
	{
		this.CallInfo.IsSpeakerMute = false;
	}
	else
	{
		this.CallInfo.IsSpeakerMute = true;
	}
		
	PluginAPIMgr.MuteSpeaker(this.CallInfo.IsSpeakerMute);
}

//check widget highlight
ProcMgr.checkWidgetHighlight = function(){
	alert("*****ProcMgr.checkWidgetHighlight()");
	if(EventMgr.isHighlight==true){		//Skype Highlighted
		alert("retur true");
		return true;
	}else{								//another widget highlighted
		alert("retur false");
		return false;
	}	

}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////  Ridge Flick Timer  ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

ProcMgr.StartRidgeTimer = function()
{
	alert('ProcMgr.StartRidgeTimer');
	ProcMgr.isRidgeFlick = true;
	PluginAPIMgr.StartOSDTimer("700" , function() { ProcMgr.isRidgeFlick = false;}, ENUM_TIMER_TYPE.POPUP_WND);
}

ProcMgr.GetRidgeFlick = function()
{
	alert('ProcMgr.GetRidgeFlick -- ' + this.isRidgeFlick);

	return ProcMgr.isRidgeFlick;
}


//////// two hand gesture ///////////
ProcMgr.StartTwoHandGesture = function()
{
	PluginAPIMgr.SubscribeGestureEvent();
	
	var gestureHelpbar = '{"helpbarType":"HELPBAR_TYPE_GESTURE_CUSTOMIZE","itemList":[{"itemType":"HELPBAR_GESTURE_ITEM_ZOOM_OUT_IN"}]}';		
	PluginAPIMgr.SetGestureHelpbarInfo(gestureHelpbar);
}

ProcMgr.StopTwoHandGesture = function()
{
	PluginAPIMgr.UnsubscribeGestureEvent();

	var gestureHelpbar = '{"helpbarType":"HELPBAR_TYPE_GESTURE_CUSTOMIZE","itemList":[]}';
	PluginAPIMgr.SetGestureHelpbarInfo(gestureHelpbar);	
}

///////////////Setting Video Rect////////////////////////

ProcMgr.SetVideoCallRect = function(flag_start)
{
	if(WndMgr.Is1366x768Panel() == true)
	{
		PluginAPIMgr.SetTVRecvRect(971,113,300,225);
		PluginAPIMgr.SetTVPreviewRect(971,367,300,225);
		
		if(flag_start == true)
		{
			PluginAPIMgr.SetTVRect(91,113,864,486);	
		}
		
		PluginAPIMgr.SetNormalRecvRect(0,0,1366,768);
		PluginAPIMgr.SetNormalPreviewRect(1041,519,300,225);
		
		PluginAPIMgr.SetCallingViewRect(580,426,207,207);
		
	}
	else
	{
		PluginAPIMgr.SetTVRecvRect(1365, 160, 424,318);
		PluginAPIMgr.SetTVPreviewRect(1365, 516, 424,318);
		
		if(flag_start == true)
		{
			PluginAPIMgr.SetTVRect(129, 160, 1200, 675);	
		}
				

		//normal
		PluginAPIMgr.SetNormalRecvRect(0, 0, 1920, 1080);
		PluginAPIMgr.SetNormalPreviewRect(1464,730,424,318);
		
		//Calling
		PluginAPIMgr.SetCallingViewRect(816,600,288,288);			  
	}

}

ProcMgr.ExchangeVideoRect = function(Preview_full)
{
	if(Preview_full == true)
	{
		if(WndMgr.Is1366x768Panel() == true)
		{
			PluginAPIMgr.SetMainVideoRect(1041,519,300,225);
		    PluginAPIMgr.SetSubVideoRect(0,0,1366,768);			
		}
		else
		{
			PluginAPIMgr.SetMainVideoRect(1464,730,424,318);
		    PluginAPIMgr.SetSubVideoRect(0,0,1920,1080);
		}
	
	}
	else
	{
		if(WndMgr.Is1366x768Panel() == true)
		{
		    PluginAPIMgr.SetSubVideoRect(1041,519,300,225);
		    PluginAPIMgr.SetMainVideoRect(0,0,1366,768);			
		}
		else
		{
		    PluginAPIMgr.SetSubVideoRect(1464,730,424,318);
		    PluginAPIMgr.SetMainVideoRect(0,0,1920,1080);
		}
	}

}

/////////////////////////////////////////////

ProcMgr.OpenPluginAboutNTV = function()
{
	if(this.ProductInfo.sub_info_code == "NTV")
	{
		PluginAPIMgr.OpenScreenPlugin();
	}
}

ProcMgr.ClosePluginAboutNTV = function()
{
	if(this.ProductInfo.sub_info_code == "NTV")
	{
		PluginAPIMgr.CloseScreenPlugin();
	}	
}


ProcMgr.IsDualViewMode = function()
{
	if(this.ProductInfo.sub_info_code == "NTV")
	{
		if(PluginAPIMgr.IsDualViewMode() == 1)
		{
			return true;
		}
	}
	return false;
}

/////////////////////////////////////////////

ProcMgr.ChangeVoiceCall = function()
{
	alert("ProcMgr.ChangeVoiceCall");
	
	if(this.isCalling == true)
	{
		//If tv mode, turn it off!!!
		if(this.CallInfo.IsTvMode == true)
		{
			alert("***TV mode off***");
			this.CallInfo.IsTvMode = false;			
			sf.service.setChannelControl(false);
			PluginAPIMgr.SetSourceMode(false);
		}
		//for multitasking, video call change to voice call
		if(StateMgr.GetCurrentState() == "CallCameraControl")
		{
			StateMgr.Start_Video_Call_State();
		}
		
		PluginAPIMgr.StopReceiveVideo();
		this.StopReceiveVideo();
		this.StopSendVideo();
		this.CallInfo.IsVideo = false;		
		PluginAPIMgr.CloseExtVideo();
	}
}
/////////////////////////////////////////////
//140528 minseok add for kpi log '14 camera
ProcMgr.Check14CameraForKPILog = function(){
	alert("ProcMgr.Check14CameraForKPILog() tv_model -> "+this.ProductInfo.model_code);
	var return_value;
	if(this.ProductInfo.model_code === undefined){
		alert("model code not initialized yet");
	}else if(this.ProductInfo.model_code === TV_MODEL_CODE.X12){
		return_value = PluginAPIMgr.GetCamCapability(ENUM_CAM_CAPABILITY.CAM_CAPABILITY_RESERVED_1);
		alert("return value : "+return_value);
		if(return_value == true){	//14 camera
			KPI_LOG.addLog(KPI_EVENT.CAM_CHECK,"true");
		}else{
			KPI_LOG.addLog(KPI_EVENT.CAM_CHECK,"false");
		}
	};
}
