
var OneBtnPopupIndex ={ 
////invalid pwd (signup) ////////////////////////////////////////////////
        NOT_AVAILABLE_KEY : 1, 
        
        NOT_AVAILABLE_DURING_CALL_IN_CONTACT_LIST : 2,
        
        ADDED_NEW_CONTACT : 3,
        BLOCKED_NEW_CONTACT :4,
        
        FUNCTION_ISNT_AVAILABLE :5,
        

        CREATE_CALL_FAIL_NETWORK_ERROR: 11, 
		CREATE_CALL_FAIL_PHONE_NUMBER_ERROR: 12,  

 };


function SceneminiOneButtonPopup(options) {
	this.options = options;
    
    this.PopupType = 0;
    this.PopupCallbackFn = null;
	this.PopupData="";
    
    this.miniOneBtnPopupView=null;

    this.PopupMsg = null;
    this.OkBtn = null;
	this.PopupMsgWithIcon = null;
	this.WarningIcon = null;
	this.CenterPopupMsg = null;
   
    this.PopupTimer = false;

}

SceneminiOneButtonPopup.prototype.initialize = function () {
	alert("SceneminiOneButtonPopup.initialize()");
	// this function will be called only once when the scene manager show this scene first time
	// initialize the scene controls and styles, and initialize your variables here 
	// scene HTML and CSS will be loaded before this function is called
    
   this.create();
}

SceneminiOneButtonPopup.prototype.handleShow = function () {
	alert("SceneminiOneButtonPopup.handleShow()");
	// this function will be called when the scene manager show this scene 
	//this.miniOneButtonPopupDim.show();
	$("#miniOneButtonPopup_id").show();
	$("#skype_default_dim").show();
    this.update();
    this.startTimer();
    
}

SceneminiOneButtonPopup.prototype.handleHide = function () {
	alert("SceneminiOneButtonPopup.handleHide()");
	// this function will be called when the scene manager hide this scene
	//this.miniOneButtonPopupDim.hide();  
	$("#miniOneButtonPopup_id").hide();
	$("#skype_default_dim").hide();
    if (this.PopupTimer == true)
    {
        this.stopTimer();
    }

	/*
	if(ResMgr.GetCurLanguage() == ENUM_TV_LANGUAGE.TAM)
	{
		$("#one_button_popup_btn").css('top', "130px");
		}*/
	

}

SceneminiOneButtonPopup.prototype.handleFocus = function () {
	alert("SceneminiOneButtonPopup.handleFocus()");
	// this function will be called when the scene manager focus this scene
	 this.highlight(this.OkBtn);
}

SceneminiOneButtonPopup.prototype.handleBlur = function () {
	alert("SceneminiOneButtonPopup.handleBlur()");
	// this function will be called when the scene manager move focus to another scene from this scene
}

SceneminiOneButtonPopup.prototype.handleKeyDown = function (keyCode) {
	alert("SceneminiOneButtonPopup.handleKeyDown(" + keyCode + ")");
	// TODO : write an key event handler when this scene get focued
//	if (SocialTV.keyHandler(keyCode)) return;
	
	PluginAPIMgr.PlayAudio(keyCode);
	switch (keyCode) {
		case $.sfKey.LEFT:
		case $.sfKey.RIGHT:
		case $.sfKey.UP:
		case $.sfKey.DOWN:
			$.sfKey.block(event);
			break;

		case $.sfKey.ENTER:
             this.processEnterKey();
            $.sfKey.block(event);
			break;
            
        case $.sfKey.RETURN:
        case $.sfKey.EXIT:
            this.processReturnKey();
            $.sfKey.block(event);
			break;

        case 147:  //infolink
        case 261:  //contents
        case 115:  //wiselink
            $.sfKey.block(event);
			break;
	}
	if(Flag_Hidden_State==false)
	event.stopPropagation();
}

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

SceneminiOneButtonPopup.prototype.create = function(){
    alert("SceneminiOneButtonPopup.create()");
    
    this.miniOneBtnPopupView =  new View("miniOneButtonPopup");
    this.miniOneBtnPopupView.CreatePopupBG(1,"miniOneButton_popup_BG");
	
    
    this.PopupMsg = new Label(null,"mini_one_button_popup_message");
	// this.PopupMsg.SetIsTextInTable(true);
    this.PopupMsg.SetTextStyle("mini_one_button_popup_message_style");
	
	this.PopupMsgWithIcon = new Label(null,"mini_one_button_popup_message_with_icon");
    this.PopupMsgWithIcon.SetTextStyle("mini_one_button_popup_message_with_icon_style");
	this.PopupMsgWithIcon.hiddenObj();
	
	this.CenterPopupMsg = new Label(null,"mini_one_button_popup_center_message");
    this.CenterPopupMsg.SetTextStyle("mini_one_button_popup_center_message_style");
	this.CenterPopupMsg.hiddenObj();
	
	var this_ = $.sfScene.get({id:'miniOneButtonPopup',scope:WIDGET.id})
	var clickCF =  function(obj){this_.processClickEvent(obj);};

    this.OkBtn = new Button();
    this.OkBtn.SetImageObjId("mini_one_button_popup_btn",8,11);
    this.OkBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_IMG, g_Image.IMAGE_POPUP_BUTTON_NORMAL);
    this.OkBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_FOCUS_IMG, g_Image.IMAGE_POPUP_BUTTON_HIGHLIGHT);	
    this.OkBtn.SetTextObjId("mini_one_button_popup_btn_text");
    this.OkBtn.SetText(SID_OK);
    this.OkBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_NORMAL_STYLE,"mini_one_button_popup_btn_text_style");
	this.OkBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_FOCUS_STYLE,"mini_one_button_popup_btn_text_style");
	this.OkBtn.SetOnClickCallbackFunc(clickCF);
	this.OkBtn.setTextKPILog(KPI_LOG_ITEM_ID.OK_BTN);
    
	this.WarningIcon= new Label("mini_one_button_popup_warning_icon", null);
    this.WarningIcon.SetBgImage(g_Image.IMAGE_BUTTON_POPUP_WARNING_ICON);
	this.WarningIcon.hiddenObj();
}

SceneminiOneButtonPopup.prototype.highlight=function(obj)
{
    this.miniOneBtnPopupView.setCurrenHighlight(obj);

}

SceneminiOneButtonPopup.prototype.startTimer = function()
{
    alert("SceneminiOneButtonPopup.startTimer() ");

	this.PopupTimer = true;
	PluginAPIMgr.StartOSDTimer("20000" , function() { $.sfScene.get({id:'miniOneButtonPopup',scope:WIDGET.id}).popupTimerCallback();}, ENUM_TIMER_TYPE.POPUP_WND);
}

SceneminiOneButtonPopup.prototype.stopTimer = function()
{
    alert("SceneminiOneButtonPopup.stopTimer() ");

	this.PopupTimer = false;
	PluginAPIMgr.StopOSDTimer(ENUM_TIMER_TYPE.POPUP_WND);
}

SceneminiOneButtonPopup.prototype.popupTimerCallback = function()
{
    alert("SceneminiOneButtonPopup.popupTimerCallback() ");
	if(this.PopupTimer == false)
	{
		return;
	}
	this.PopupTimer = false;
	
    WndMgr.StopOneBottonPopup(); 
}

SceneminiOneButtonPopup.prototype.processEnterKey = function(){
    alert("SceneminiOneButtonPopup.processEnterKey() ");
    
    var currentHighlight =  this.miniOneBtnPopupView.getCurrentHighlight();
    
    switch(currentHighlight)
    {
        case this.OkBtn:
            WndMgr.StopOneBottonPopup(); 
            break;
    }
}

SceneminiOneButtonPopup.prototype.processReturnKey = function(){
    alert("SceneminiOneButtonPopup.processReturnKey() ");
    
    WndMgr.StopOneBottonPopup(); 
}

SceneminiOneButtonPopup.prototype.callBack = function()
{
     if(this.PopupCallbackFn != null)
    {
        this.PopupCallbackFn();
    }
}

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


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

SceneminiOneButtonPopup.prototype.initPopup = function(typeIndex, data)
{
    this.PopupType =  typeIndex;
	
	if(data)
	{
		this.PopupData=data;
	}
	else
	{
		this.PopupData="";
	}
}

SceneminiOneButtonPopup.prototype.update = function()
{
    alert("SceneminiOneButtonPopup.update() ");
	this.PopupMsg.SetTextStyle("mini_one_button_popup_message_style");
	this.PopupMsg.visibleObj();
	this.PopupMsgWithIcon.hiddenObj();
	this.WarningIcon.hiddenObj();
	this.CenterPopupMsg.hiddenObj();
	
    this.updatePopupMsg();
    this.updatePopupCallbakcFn();
}

SceneminiOneButtonPopup.prototype.updatePopupMsg = function()
{
    alert("SceneminiOneButtonPopup.updatePopupMsg() ");
    
    var CurLangID = ResMgr.GetCurLanguage();
    var FinalString = "";
    
    switch(this.PopupType)
    {
     case OneBtnPopupIndex.NOT_AVAILABLE_KEY :
	 	this.PopupMsgWithIcon.SetText(SID_NOT_AVAILABLE);
		this.PopupMsg.hiddenObj();	
		this.PopupMsgWithIcon.visibleObj();
		this.WarningIcon.visibleObj();
			return;
        break;
		case OneBtnPopupIndex.NOT_AVAILABLE_DURING_CALL_IN_CONTACT_LIST : 
		//	this.PopupMsgWithIcon.hiddenObj();
			FinalString = TV_SID_THIS_FEATURE_IS_NOT_AVAILABLE_DURING_THE_CALL;
		//	this.PopupMsg.visibleObj();
		//	this.WarningIcon.hiddenObj();
			break;
		case OneBtnPopupIndex.ADDED_NEW_CONTACT : 
			FinalString = IDWS_MOIP_CONTACT_ADDED;
		//	this.PopupMsgWithIcon.hiddenObj();
		//	this.PopupMsg.visibleObj();
		//	this.WarningIcon.hiddenObj();
			break;		
			
		case OneBtnPopupIndex.BLOCKED_NEW_CONTACT :
			FinalString = g_Data.CombinateStrings(SID_MIX_BLOCKED_FROM_CONTACTS, this.PopupData);
        	break;			
        
        case OneBtnPopupIndex.FUNCTION_ISNT_AVAILABLE :
			FinalString = TV_SID_THIS_FUNCTION_ISNT_AVAILABLE;
        	break;
        	
       	case OneBtnPopupIndex.CREATE_CALL_FAIL_NETWORK_ERROR : 
	 		FinalString = IDWS_MOIP_PROBLEM_WITH_EXTERNAL_NETWORK;//IDWS_MOIP_NETWORK_ERROR; 
			break;	
		case OneBtnPopupIndex.CREATE_CALL_FAIL_PHONE_NUMBER_ERROR:
			FinalString = IDWS_MOIP_SKYPEOUT_FAIL12;  
        break;			
    }
		this.PopupMsg.SetText(FinalString);
    }

SceneminiOneButtonPopup.prototype.updatePopupCallbakcFn = function()
{
    alert("SceneminiOneButtonPopup.updatePopupCallbakcFn() ");
	
	this.PopupCallbackFn = null; //init
	
    switch(this.PopupType)
    {
    	case OneBtnPopupIndex.NOT_AVAILABLE_DURING_CALL_IN_CONTACT_LIST :
		case OneBtnPopupIndex.ADDED_NEW_CONTACT :
        case OneBtnPopupIndex.BLOCKED_NEW_CONTACT :
       case OneBtnPopupIndex.NOT_AVAILABLE_KEY : 	      
        case OneBtnPopupIndex.FUNCTION_ISNT_AVAILABLE :
        case OneBtnPopupIndex.CREATE_CALL_FAIL_NETWORK_ERROR : 
        case OneBtnPopupIndex.CREATE_CALL_FAIL_PHONE_NUMBER_ERROR:
        	this.PopupCallbackFn = function(){StateMgr.ReturnToMainState();};
        	break;
    }
}
