
// 0. no highlight
// 1. yes button
// 2. no button

var CONFIRM_BUTTON = {  
 	NOTHING		: 0,
 	YES			: 1,
	NO			: 2
}

function SceneCallConfirmPopup(options) {
	this.options = options;
    
    this.PopupView			= null;
    this.PopupViewDim		= null;
    this.PopupViewBG		= null;
    this.YesBtn				= null;
    this.NoBtn				= null;
	this.PopupType			= null;
	this.MessageLabel		= null;
	this.current_highlight	= CONFIRM_BUTTON.NOTHING;
}

SceneCallConfirmPopup.prototype.initialize = function () {
	alert("SceneCallConfirmPopup.initialize()");

   this.create();
}

SceneCallConfirmPopup.prototype.handleShow = function () {
	alert("SceneCallConfirmPopup.handleShow()");
	this.PopupViewDim.show();	
	this.update();
	
  	var CallConfirmCBF =  function(){
  		sf.scene.get('CallConfirmPopup').processReturnKey();
  	};
  	
	WndMgr.startPopupHideTimer(30000,CallConfirmCBF);
}

SceneCallConfirmPopup.prototype.handleHide = function () {
	alert("SceneCallConfirmPopup.handleHide()");
	WndMgr.stopPopupHideTimer();
	this.PopupViewDim.hide();
}

SceneCallConfirmPopup.prototype.handleFocus = function () {
	alert("SceneCallConfirmPopup.handleFocus()");
	this.highlight(this.NoBtn);
}

SceneCallConfirmPopup.prototype.handleBlur = function () {
	alert("SceneCallConfirmPopup.handleBlur()");
	this.highlight(null);
}

SceneCallConfirmPopup.prototype.handleKeyDown = function (keyCode) {
	alert("SceneCallConfirmPopup.handleKeyDown(" + keyCode + ")");

	if(ProcMgr.checkWidgetHighlight()==false){
		return;
	}
	switch (keyCode) {
		case sf.key.LEFT:
		case sf.key.RIGHT:
        	this.processLeftRightKey(keyCode);
        	WndMgr.resetPopupHideTimer();
			break;

		case sf.key.ENTER:
			this.processEnterKey();
			break;
            
        case sf.key.RETURN:
        case sf.key.EXIT:
            this.processReturnKey();
            sf.key.preventDefault();
			break;
            
         case 147:  //infolink
         case 261:  //contents
         case 115:  //wiselink
            ProcMgr.processInfolinkKey(); 
			break;
	}
}

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

SceneCallConfirmPopup.prototype.create = function(){
    alert("SceneCallConfirmPopup.create()");

	var this_ = sf.scene.get("CallConfirmPopup");

    this.PopupView = new View("CallConfirmPopup");
    
    this.PopupViewBG = new View("CallConfirmPopupBG");  
	this.PopupViewBG.CreatePopupBG(1,'CallConfirmPopup_popup_BG');
    this.PopupViewDim = new DimBg("CallConfirmPopupDim", "CallConfirmPopupBG");  

	this.MessageLabel = new Label(null,'callconfirm_popup_message');
	this.MessageLabel.SetTextStyle("confirm_popup_message_style");
	this.MessageLabel.SetText(IDWS_MOIP_SKYPE_SIGNIN);
	

	var clickCF =  function(obj){this_.processClickEvent(obj);};

    this.YesBtn = new Button();
    this.YesBtn.SetImageObjId("callconfirm_popup_yes_btn",20);
    this.YesBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_IMG, g_Image.IMAGE_POPUP_BTN_NORMAL);
	this.YesBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_FOCUS_IMG, g_Image.IMAGE_POPUP_BTN_NORMALFOCUS);	
    this.YesBtn.SetTextObjId("callconfirm_popup_yes_btn_text");
    this.YesBtn.SetText(SID_YES);
    this.YesBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_NORMAL_STYLE, "popup_btn_text_normal_style");
	this.YesBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_FOCUS_STYLE, "popup_btn_text_focus_style");
	this.YesBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_DIM_STYLE, "popup_btn_text_dimmed_style");
	this.YesBtn.SetOnClickCallbackFunc(clickCF);
	
    this.NoBtn = new Button();
    this.NoBtn.SetImageObjId("callconfirm_popup_no_btn",20);
    this.NoBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_IMG, g_Image.IMAGE_POPUP_BTN_NORMAL);
	this.NoBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_FOCUS_IMG, g_Image.IMAGE_POPUP_BTN_NORMALFOCUS);		
    this.NoBtn.SetTextObjId("callconfirm_popup_no_btn_text");
    this.NoBtn.SetText(SID_NO);
    this.NoBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_NORMAL_STYLE, "popup_btn_text_normal_style");
	this.NoBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_FOCUS_STYLE, "popup_btn_text_focus_style");
	this.NoBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_DIM_STYLE, "popup_btn_text_dimmed_style");
	this.NoBtn.SetOnClickCallbackFunc(clickCF);
	this.YesBtn.SetOnMouseOverCallbackFunc(function(obj) {
		this_.processMouseOver(obj);
	});
	this.NoBtn.SetOnMouseOverCallbackFunc(function(obj) {
		this_.processMouseOver(obj);
	});
}

SceneCallConfirmPopup.prototype.update = function()
{
	alert("SceneCallConfirmPopup.update -- " + this.PopupType);
		
	var main_text;
	var yes_text;
	var no_text;
		
	if(this.PopupType == 1)
	{
		main_text = g_Data.CombinateStrings(SID_MIX_IS_CALLING_VIA_VIDEO,PluginAPIMgr.GetCallMemberDisplayName());
	}
	else if(this.PopupType == 2)
	{
		main_text = TV_SID_DO_YOU_WANT_TO_END_CALL;
	}
	else if(this.PopupType == 3)
	{
		if(ProcMgr.CallInfo.IsProcesingEnd == true)
		{
			var CurLangID = ResMgr.GetCurLanguage();
			if(CurLangID == ENUM_TV_LANGUAGE.KOR || CurLangID == ENUM_TV_LANGUAGE.SLK || CurLangID == ENUM_TV_LANGUAGE.UKR)
			{
				main_text = IDWS_MOIP_SKYPE_CALL_ENDED + TV_SID_WANT_TO_CONTINUE_WATCHING_TV;
			}
			else
			{
				main_text = IDWS_MOIP_SKYPE_CALL_ENDED + '. ' + TV_SID_WANT_TO_CONTINUE_WATCHING_TV;
			}
		}
		else
		{
			main_text = TV_SID_WANT_TO_CONTINUE_WATCHING_TV;
		}	
	}
	
	this.MessageLabel.SetText(main_text);
}
	
SceneCallConfirmPopup.prototype.setType = function(popupType)
{
	this.PopupType = popupType;
}
SceneCallConfirmPopup.prototype.highlight=function(obj)
{
	alert("SceneCallConfirmPopup.highlight() ");
    this.PopupView.setCurrenHighlight(obj);
}

SceneCallConfirmPopup.prototype.processBtnOver = function()
{		
	this.processLeftRightKey(keyCode);
}
		
SceneCallConfirmPopup.prototype.processLeftRightKey = function(keyCode){
	alert("CallConfirmPopup.processLeftRightKey() : "+keyCode);
	
	if(keyCode===sf.key.LEFT){
		this.highlight(this.YesBtn);
	}
	else if(keyCode===sf.key.RIGHT){
		this.highlight(this.NoBtn);
	}
}
SceneCallConfirmPopup.prototype.processEnterKey = function()
{	
	alert("CallConfirmPopup.processEnterKey()");
	
	var currentHighlight = this.PopupView.getCurrentHighlight();
	if(currentHighlight == this.YesBtn)
	{
		this.processYesBtn();
	}
	else
	{
		this.processNoBtn();
	}
}

SceneCallConfirmPopup.prototype.processReturnKey = function()
{
	alert("SceneCallConfirmPopup.processReturnKey() ");
		
	if(this.PopupType == 3)
	{
		if(ProcMgr.CallInfo.IsProcesingEnd == true)
		{
			StateMgr.Stop_Call_Confirm_State(false);
						
			sf.service.setChannelControl(false);
			ProcMgr.flag_ExitAfterWatchingTV = false;
			ProcMgr.CallInfo.IsProcesingEnd = false;
			ProcMgr.CallInfo.IsTvMode = false;
			ProcMgr.EndCall();
		}
		else
		{
			StateMgr.Stop_Call_Confirm_State(true);
		}
	}
	else
	{
		StateMgr.Stop_Call_Confirm_State(true);
	}
}
	

SceneCallConfirmPopup.prototype.processYesBtn = function(){
	alert("SceneCallConfirmPopup.processYesBtn() ");

	if(this.PopupType == 1)
	{
		StateMgr.Stop_Call_Confirm_State(true);
		ProcMgr.SetStartReceiveVideo();
	}
	else if(this.PopupType == 2)
	{
		StateMgr.Stop_Call_Confirm_State(true);
		WndMgr.CloseVideoCallRect();
		ProcMgr.DisconnectCall();
	}
	else if(this.PopupType == 3)
	{
		if(PluginAPIMgr.IsWidgetSupportMultitasking() == 0)
		{
			StateMgr.Stop_Call_Confirm_State(false);
				ProcMgr.flag_ExitAfterWatchingTV = true;
			//reset flag
			ProcMgr.CallInfo.IsTvMode = false;
			ProcMgr.CallInfo.IsProcesingEnd = false;
			sf.service.setChannelControl(false);
			//show call ending popup
			ProcMgr.EndCall();
		}
		else
		{	
			StateMgr.Stop_Call_Confirm_State(true);//false
			//go out with call end
			if(ProcMgr.CallInfo.IsProcesingEnd == true)
			{
				ProcMgr.flag_ExitAfterWatchingTV = true;
				ProcMgr.CallInfo.IsProcesingEnd = false;
				ProcMgr.CallInfo.IsTvMode = false;
				sf.service.setChannelControl(false);
				ProcMgr.EndCall();
			}
			//exit widget
			//go out with in call
			else
			{
				//change mode to normal
				if(ProcMgr.CallInfo.IsTvMode == true)
				{
					ProcMgr.CallInfo.IsTvMode = false;
					sf.service.setChannelControl(false);
					PluginAPIMgr.SetSourceMode(false);
				}
				ProcMgr.GoOutWithSignIn(true);
			}
		}		
	}
	else
	{
		alert('[error] PopupType is not nomal number')
		StateMgr.Stop_Call_Confirm_State(true);
	}
}

SceneCallConfirmPopup.prototype.processNoBtn = function(){
	alert("SceneCallConfirmPopup.processNoBtn() ");
	
	if(this.PopupType == 1)
	{
		StateMgr.Stop_Call_Confirm_State(true);
	}
	else if(this.PopupType == 2)
	{
		StateMgr.Stop_Call_Confirm_State(true);
	}
	else if(this.PopupType == 3)
	{
		if(PluginAPIMgr.IsWidgetSupportMultitasking() == 0)
		{
			StateMgr.Stop_Call_Confirm_State(false);
			ProcMgr.flag_ExitAfterWatchingTV = false;
			//reset flag
			ProcMgr.CallInfo.IsTvMode = false;
			ProcMgr.CallInfo.IsProcesingEnd = false;
			sf.service.setChannelControl(false);
			//show call ending popup
			ProcMgr.EndCall();
		}
		else
		{
			StateMgr.Stop_Call_Confirm_State(false);
			sf.service.setChannelControl(false);
			
			if(ProcMgr.CallInfo.IsProcesingEnd == true)
			{
				ProcMgr.flag_ExitAfterWatchingTV = false;
				ProcMgr.CallInfo.IsProcesingEnd = false;
				ProcMgr.CallInfo.IsTvMode = false;
				ProcMgr.EndCall();
			}
			else
			{
				StateMgr.Start_Main_State();
			}
		}
	}
	else
	{
		alert('[error] PopupType is not nomal number')
		StateMgr.Stop_Call_Confirm_State(true);
	}
}

SceneCallConfirmPopup.prototype.processClickEvent = function()
{
	alert("SceneCallConfirmPopup.processClickEvent() ");
		
	this.processEnterKey();
}

SceneCallConfirmPopup.prototype.processMouseOver = function(obj)
{
	var currentHighlight = this.PopupView.getCurrentHighlight();
	if(currentHighlight != obj) {
		this.highlight(obj);
	}
}

