

function SceneSignout(options) {
	this.options = options;
    
    this.SignoutView=null;
	this.SignoutDim=null;
	this.SignoutViewBG=null;
    
    this.PopupMsg = null;
    this.YesBtn = null;
    this.NoBtn = null;
    
    this.flagWaiting = false;
	
	this.CloseTimer = false;
   
}

SceneSignout.prototype.initialize = function () {
	alert("SceneSignout.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();
}

SceneSignout.prototype.handleShow = function () {
	alert("SceneSignout.handleShow()");
	// this function will be called when the scene manager show this scene 
	this.SignoutDim.show();
    this.highlight(this.NoBtn);
		
	WndMgr.startPopupHideTimer(30000);
}

SceneSignout.prototype.handleHide = function () {
	alert("SceneSignout.handleHide()");
	// this function will be called when the scene manager hide this scene 
	this.SignoutDim.hide(); 
	
	WndMgr.stopPopupHideTimer();	
}

SceneSignout.prototype.handleFocus = function () {
	alert("SceneSignout.handleFocus()");
	// this function will be called when the scene manager focus this scene
	
    var currentObj =  this.SignoutView.getCurrentHighlight();
    
	if(currentObj)
	{
		this.highlight(currentObj);
	}
	else
	{
		this.highlight(this.NoBtn);
	}
	
}

SceneSignout.prototype.handleBlur = function () {
	alert("SceneSignout.handleBlur()");
	// this function will be called when the scene manager move focus to another scene from this scene
    this.enableButton();
    
    var currentObj =  this.SignoutView.getCurrentHighlight();
	if(currentObj)
	{
		currentObj.blur();
	}
}

SceneSignout.prototype.handleKeyDown = function (keyCode) {
	alert("SceneSignout.handleKeyDown(" + keyCode + ")");
	// TODO : write an key event handler when this scene get focued
	PluginAPIMgr.PlayAudio(keyCode);
	if(ProcMgr.checkWidgetHighlight()==false){
		return;
	}
	switch (keyCode) {
		case sf.key.LEFT:
		case sf.key.RIGHT:		
		WndMgr.resetPopupHideTimer();
        this.processLeftRightKey(keyCode);
			break;
		case sf.key.UP:

			break;
		case sf.key.DOWN:

			break;

		case sf.key.ENTER:
             this.processEnterKey();
			break;
            
        case sf.key.RETURN:
        case sf.key.EXIT:
            this.processReturnKey();
            //2013 modify by minseok
            sf.key.preventDefault();
            //sf.key.block(event);
			break;

         case 147:  //infolink
         case 261:  //contents
         case 115:  //wiselink
            ProcMgr.processInfolinkKey(); 
			break;
	}
}

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

SceneSignout.prototype.create = function(){
    alert("SceneSignout.create()");
    this.SignoutView = new View("Signout");
    // this.SignoutView.SetBgImage(WndMgr.Bg_Popup.src); 
	this.SignoutViewBG = new View("SignoutBG");
	this.SignoutViewBG.CreatePopupBG(1,"Signout_popup_BG");
	this.SignoutDim = new DimBg("SignoutDim", "Signout");    
    
    this.PopupMsg = new Label(null,"signout_message");
    this.PopupMsg.SetTextStyle("signout_message_style");
    this.PopupMsg.SetText(TV_SID_DO_YOU_WANT_TO_SIGN_OUT);
    
    var this_ = sf.scene.get("Signout");
    var clickCF =  function(obj){this_.processClickEvent(obj);};
    var overCF =  function(obj){this_.processMouseOverEvent(obj);};

    this.YesBtn = new Button();
    this.YesBtn.SetImageObjId("signout_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.SetBgImage(BtnImgIndex.BTN_DIM_IMG, g_Image.IMAGE_POPUP_BTN_DIM);
    this.YesBtn.SetTextObjId("signout_yes_btn_text");
    this.YesBtn.SetText(SID_OK_KR_YES);
    this.YesBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_NORMAL_STYLE,"cPopup_btn_text");
    this.YesBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_FOCUS_STYLE,"cPopup_btn_text_high");
    this.YesBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_DIM_STYLE,"cPopup_btn_text_dim");
    this.YesBtn.SetOnClickCallbackFunc(clickCF);
    this.YesBtn.SetOnMouseOverCallbackFunc(overCF);
    
    this.NoBtn = new Button();
    this.NoBtn.SetImageObjId("signout_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.SetBgImage(BtnImgIndex.BTN_DIM_IMG, g_Image.IMAGE_POPUP_BTN_DIM);
    this.NoBtn.SetTextObjId("signout_no_btn_text");
    this.NoBtn.SetText(SID_CANCEL);
    this.NoBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_NORMAL_STYLE,"cPopup_btn_text");
    this.NoBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_FOCUS_STYLE,"cPopup_btn_text_high");
    this.NoBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_DIM_STYLE,"cPopup_btn_text_dim");
	this.NoBtn.SetOnClickCallbackFunc(clickCF);
	this.NoBtn.SetOnMouseOverCallbackFunc(overCF);
}

SceneSignout.prototype.highlight=function(obj)
{
    this.SignoutView.setCurrenHighlight(obj);

}

SceneSignout.prototype.requestSignout = function()
{
    alert("SceneSignout.requestSignout() ");
    
    this.disableButton();
    ProcMgr.Signout(false);     
}


SceneSignout.prototype.processLeftRightKey = function(keyCode){
    alert("SceneSignout.processLeftRightKey() ");
    
    if(this.flagWaiting ==true)
    {
        return;
    }
    
    var currentHighlight =  this.SignoutView.getCurrentHighlight();
    
    switch(currentHighlight)
    {
        case this.YesBtn:
        	if(keyCode==sf.key.RIGHT){
        		this.highlight(this.NoBtn);	
        	}
           
            break;
            
        case this.NoBtn:
        	if(keyCode==sf.key.LEFT){
        		this.highlight(this.YesBtn);	
        	}
           
            break;
    }
}

SceneSignout.prototype.processEnterKey = function(){
    alert("SceneSignout.processEnterKey() ");
    
     if(this.flagWaiting ==true)
    {
        return;
    }
    
    var currentHighlight =  this.SignoutView.getCurrentHighlight();
    
    switch(currentHighlight)
    {
        case this.YesBtn:
            this.requestSignout();
            break;
            
        case this.NoBtn:
           StateMgr.Stop_Signout_State(true);
            break;
    }
}

SceneSignout.prototype.enableButton = function(){
    alert("SceneSignout.enableButton() ");
    
    this.PopupMsg.SetText(TV_SID_DO_YOU_WANT_TO_SIGN_OUT);
    this.YesBtn.SetFlagDim(false);
    this.NoBtn.SetFlagDim(false);
    
     this.flagWaiting = false;
}

SceneSignout.prototype.disableButton = function(){
    alert("SceneSignout.disableButton() ");
    
	WndMgr.stopPopupHideTimer();
	
     this.flagWaiting = true;
     this.PopupMsg.SetText(TV_SID_WAITING_DOT);
     
    this.YesBtn.blur();
    
    this.YesBtn.SetFlagDim(true);
    this.NoBtn.SetFlagDim(true);
    
}


SceneSignout.prototype.processReturnKey = function(){
    alert("SceneSignout.processReturnKey() ");
    
     if(this.flagWaiting ==true)
    {
        return;
    }
    
    StateMgr.Stop_Signout_State(true);
}

///////// Processing Click evnet  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
SceneSignout.prototype.processMouseOver = function(obj) {
    alert("SceneSignout.processMouseOver() " + obj);

	var currentHighlight = this.SignoutView.getCurrentHighlight();
	if(currentHighlight != obj) {
		WndMgr.resetPopupHideTimer();
		this.highlight(obj);
	}
}


SceneSignout.prototype.processClickEvent = function(obj){
	alert("SceneSignout.processClickEvent() ");
	
	/*var currentHighlight =  this.SignoutView.getCurrentHighlight();
    if(currentHighlight != obj)
    {
    	this.highlight(obj);
    }
	*/
	this.processEnterKey();
}
SceneSignout.prototype.processMouseOverEvent = function(obj){
	alert("SceneSignout.processMouseOverEvent() ");
	
	var currentHighlight =  this.SignoutView.getCurrentHighlight();
    if(currentHighlight != obj)
    {
    	this.highlight(obj);
    }
	
	// this.processEnterKey();
}


