

var REMOVE_TYPE = {      

    CONTACT		:   0,
	CHAT		:   1,
    HISTORY		:   2,
}


function SceneRemove(options) {
	
	this.options = options;
	
	this.TargetIndex	= null;				//to use pluginApi to remove history
			
	this.RemoveView = null;	
	this.RemovePopupView = null;
	this.RemoveDim	= null;
	
	this.BodyMsg	= null;
	this.OkBtn		= null;
	this.CancelBtn	= null;

	//flag
//	this.InProgressMode = false;

	//timer
    this.CloseTimer = false;	 
}

SceneRemove.prototype.initialize = function () {
	alert("SceneRemove.initialize()");
	this.create();

}

SceneRemove.prototype.handleShow = function () {
	alert("SceneRemove.handleShow()");
			
	this.RemoveDim.show();
	this.ResetPopup();    

    this.startTimer();
}

SceneRemove.prototype.handleHide = function () {
	alert("SceneRemove.handleHide()");
	this.RemoveDim.hide();
	
	if(this.InProgressMode){		
//		this.OkBtn.blur();
//		this.CancelBtn.blur();
		this.InProgressMode = false;
	}
	else{
		this.highlight(null);	
	}

    if (this.CloseTimer ==true)
    {
        this.stopTimer();
    }
	
}

SceneRemove.prototype.handleFocus = function () {
	alert("SceneRemove.handleFocus()");
	
    var currentHighlight =  this.RemoveView.getCurrentHighlight();

    if(currentHighlight ==null)
    {
        this.highlight(this.CancelBtn);
    }
    else
    {
         this.highlight(currentHighlight);
    }
	
}

SceneRemove.prototype.handleBlur = function () {
	alert("SceneRemove.handleBlur()");
	
}

SceneRemove.prototype.handleKeyDown = function (keyCode) {
	alert("SceneRemove.handleKeyDown(" + keyCode + ")");
	PluginAPIMgr.PlayAudio(keyCode);
	if(ProcMgr.checkWidgetHighlight()==false){
		return;
	}
	
	switch (keyCode) {
		case sf.key.LEFT:
		case sf.key.RIGHT:
			this.resetTimer();
			this.processLEFTKey();
			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;
	}
}

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

SceneRemove.prototype.create = function(){
    alert("SceneRemove.create()");
	
    this.RemoveView = new View("Remove");
    this.RemovePopupView = new View("RemoveBg");
    this.RemovePopupView.CreatePopupBG(1,"RemoveBg");
	
	this.RemoveDim = new DimBg("RemoveDim", "Remove");  
    this.BodyMsg 	= new Label(null,"RemoveMassage");	

	var This_ = sf.scene.get('Remove');

    this.OkBtn = new ButtonBase();
    this.OkBtn.Create("Remove_OkButton",BUTTON_BASE_TYPE.BG_TEXT, 20);
    this.OkBtn.SetBgImage(BUTTON_BASE_STATE.NORMAL, g_Image.IMAGE_POPUP_BTN_NORMAL);
    this.OkBtn.SetBgImage(BUTTON_BASE_STATE.HIGHLIGHT, g_Image.IMAGE_POPUP_BTN_NORMALFOCUS);	
	this.OkBtn.SetTextStyle(BUTTON_BASE_STATE.NORMAL,"cPopup_btn_text_high");
	//this.OkBtn.SetTextStyle(BUTTON_BASE_STATE.HIGHLIGHT,"cButton_Text_Highlight_Style"); 
    this.OkBtn.SetText(SID_YES);
    this.OkBtn.SetOnClickCallbackFunc(this.ClickOkBtn);
 
	this.CancelBtn = new ButtonBase();
    this.CancelBtn.Create("Remove_CancelButton",BUTTON_BASE_TYPE.BG_TEXT, 20);
    this.CancelBtn.SetBgImage(BUTTON_BASE_STATE.NORMAL, g_Image.IMAGE_POPUP_BTN_NORMAL);
    this.CancelBtn.SetBgImage(BUTTON_BASE_STATE.HIGHLIGHT, g_Image.IMAGE_POPUP_BTN_NORMALFOCUS);	
	this.CancelBtn.SetTextStyle(BUTTON_BASE_STATE.NORMAL,"cPopup_btn_text_high");
	//this.CancelBtn.SetTextStyle(BUTTON_BASE_STATE.HIGHLIGHT,"cButton_Text_Highlight_Style");
    this.CancelBtn.SetText(SID_NO);
    this.CancelBtn.SetOnClickCallbackFunc(this.ClickCancelBtn);

	this.OkBtn.SetOnMouseOverCallbackFunc(function(obj) {This_.processMouseOver(obj);});
	this.CancelBtn.SetOnMouseOverCallbackFunc(function(obj) {This_.processMouseOver(obj);});
}

SceneRemove.prototype.highlight=function(obj)
{
	alert("SceneRemove.highlight()");
	
    this.RemoveView.setCurrenHighlight(obj);
	
}

SceneRemove.prototype.Init = function(Index){
    alert("SceneRemove.Init() : TargetIndex = " + Index);

	this.TargetIndex	= Index;

}

SceneRemove.prototype.ResetPopup = function(){
	alert("SceneRemove.ResetPopup() ");

		this.BodyMsg.SetText(IDWS_MOIP_CLEAR_HISTORY);	
}

	
SceneRemove.prototype.processEnterKey = function(){
    alert("SceneRemove.processEnterKey() ");

    var currentHighlight =  this.RemoveView.getCurrentHighlight();
    
	
	if(currentHighlight == this.OkBtn){
	
		this.highlight(null);
		this.InProgressMode = true;
		
		ProcMgr.RemoveItem(this.TargetIndex);
	}
	else{
	
		this.processReturnKey();	
	}
	
}



SceneRemove.prototype.processReturnKey = function(){
    alert("SceneRemove.processReturnKey() ");

	StateMgr.Stop_Remove_State(true);

	//TEMPCODE: for only hisorty..   because no event
	/*
	var Scene = sf.scene.get(WndMgr.GetMainSubSceneID());	
		Scene.Activation();*/
	
	
	
}

SceneRemove.prototype.processLEFTKey = function(){
    alert("SceneRemove.processLEFTKey() ");

    var currentHighlight =  this.RemoveView.getCurrentHighlight();
    
    switch(currentHighlight)
    {
        case this.OkBtn:
            this.highlight(this.CancelBtn);
            break;
            
        case this.CancelBtn:
            this.highlight(this.OkBtn);
            break;
    }
    
}

SceneRemove.prototype.startTimer = function()
{
    alert("SceneRemove.startTimer() ");
	
	this.CloseTimer = true;
	PluginAPIMgr.StartOSDTimer("30000" , function() { sf.scene.get('Remove').popupTimerCallback();}, ENUM_TIMER_TYPE.POPUP_WND);
}

SceneRemove.prototype.resetTimer = function()
{
    alert("SceneRemove.resetTimer() ");
	
	if(this.CloseTimer == true)
	{
		PluginAPIMgr.RestartOSDTimer("30000" ,ENUM_TIMER_TYPE.POPUP_WND);
	}
}

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

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

SceneRemove.prototype.popupTimerCallback = function()
{
    alert("SceneRemove.popupTimerCallback() ");
	
	if (this.CloseTimer == false)
	{
		return;
	}
	this.CloseTimer = false;	
		
	this.processReturnKey();
}

SceneRemove.prototype.processMouseOver = function(obj) {
    alert("SceneRemove.processMouseOver() " + obj);

	var currentHighlight = this.RemoveView.getCurrentHighlight();
	if(currentHighlight != obj) {
		this.highlight(obj);
	}
}

SceneRemove.prototype.ClickOkBtn = function(){

	var This_ = sf.scene.get('Remove');
	
	This_.highlight(null);
	This_.InProgressMode = true;	
	
	ProcMgr.RemoveItem(This_.TargetIndex);
}

SceneRemove.prototype.ClickCancelBtn = function(){

	var This_ = sf.scene.get('Remove');
	This_.processReturnKey();
}

