function SceneSettingsGeneral(options) {
	this.options = options;
	this.sceneId = "SettingsGeneral";
	this.SettingsGeneralView = null;
	this.SettingsGeneralDim = null;
	this.SettingsGeneralBG = null;

	this.AutoStartLabel = null;
	this.DisplayNotifyLabel = null;

	this.AutoStartBtn = null;
	this.DisplayNotifyBtn = null;

	this.InitAutoStart = null;
	this.InitDisplayNotify = null;

	this.IsChangeAutoStart = false;
	this.IsChangeDisplayNotify = false;

	this.SaveBtn = null;
	this.CancelBtn = null;

	this.flagEnable = true;

	this.ShownOnOffSubList = false;
	this.IsEnableSaveBtn = true;
	this.BeforeBtn = null;
}

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

SceneSettingsGeneral.prototype.handleShow = function() {
	alert("SceneSettingsGeneral.handleShow()");
	// this function will be called when the scene manager show this scene
	this.SettingsGeneralDim.show();
	WndMgr.startPopupHideTimer(60000);
	this.InitSettingsGeneral();
	this.ChangePopupUI();
	this.setSaveBtnEnable(false);
}

SceneSettingsGeneral.prototype.handleHide = function() {
	alert("SceneSettingsGeneral.handleHide()");
	// this function will be called when the scene manager hide this scene
	this.SettingsGeneralDim.hide();
	if(this.ShownOnOffSubList == true) {
		WndMgr.HideSettingsOnOffSubList();
	}
	WndMgr.stopPopupHideTimer();

	this.ShownOnOffSubList = false;
	this.highlight(null);
	this.BeforeBtn = null;
}

SceneSettingsGeneral.prototype.handleFocus = function() {
	alert("SceneSettingsGeneral.handleFocus()");
	// this function will be called when the scene manager focus this scene
	var obj = this.SettingsGeneralView.getCurrentHighlight();
	if(obj != null) {
		this.highlight(obj);
	} else if(this.BeforeBtn)
		this.highlight(this.BeforeBtn);
	else if(this.flagEnable) {
		this.highlight(this.AutoStartBtn);
	} else
		this.highlight(this.DisplayNotifyBtn);

	this.ShownOnOffSubList = false;
}

SceneSettingsGeneral.prototype.handleBlur = function() {
	alert("SceneSettingsGeneral.handleBlur()");
	// this function will be called when the scene manager move focus to another scene from this scene
	var obj = this.SettingsGeneralView.getCurrentHighlight();
	if(obj != null) {
		obj.blur();
	}
/*	if(this.ShownOnOffSubList)
		this.SaveBtn.SetFlagDim(true);*/
}

SceneSettingsGeneral.prototype.handleKeyDown = function(keyCode) {
	alert("SceneSettingsGeneral.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:
			WndMgr.resetPopupHideTimer();
			this.processLeftKey();
			break;
		case sf.key.RIGHT:
			WndMgr.resetPopupHideTimer();
			this.processRightKey();
			break;
		case sf.key.UP:
			WndMgr.resetPopupHideTimer();
			this.processUpKey();
			break;
		case sf.key.DOWN:
			WndMgr.resetPopupHideTimer();
			this.processDownKey();
			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;
	}
}

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

	StateMgr.Stop_SettingsGeneral_State(true);
}

SceneSettingsGeneral.prototype.processMouseOver = function(obj) {
	var currentHighlight = this.SettingsGeneralView.getCurrentHighlight();
	if(currentHighlight != obj) {
		this.highlight(obj);
	}
	WndMgr.resetPopupHideTimer();
}

SceneSettingsGeneral.prototype.highlight = function(obj) {
	alert("SceneSettingsGeneral.highlight() ");
	this.SettingsGeneralView.setCurrenHighlight(obj);
}

SceneSettingsGeneral.prototype.processClickEvent = function(obj) {
	alert("SceneSettingsGeneral.processClickEvent() ");

	var currentHighlight = this.SettingsGeneralView.getCurrentHighlight();
	if(currentHighlight != obj) {
		this.highlight(obj);
	}
	this.processEnterKey();
}
SceneSettingsGeneral.prototype.processUpKey = function() {
	alert("SceneSettingsGeneral.processUpKey()");
	var currentHighlight = this.SettingsGeneralView.getCurrentHighlight();
	switch(currentHighlight) {
		case this.DisplayNotifyBtn:
			if(this.flagEnable)
				this.highlight(this.AutoStartBtn);
			break;
		case this.CancelBtn:
			if(this.IsEnableSaveBtn)
				this.highlight(this.SaveBtn);
			break;
	}
}
SceneSettingsGeneral.prototype.processDownKey = function() {
	alert("SceneSettingsGeneral.processDownKey()");
	var currentHighlight = this.SettingsGeneralView.getCurrentHighlight();
	switch(currentHighlight) {
		case this.AutoStartBtn:
			this.highlight(this.DisplayNotifyBtn);
			break;
		case this.SaveBtn:
			this.highlight(this.CancelBtn);
			break;
	}
}
SceneSettingsGeneral.prototype.processLeftKey = function() {
	alert("SceneSettingsGeneral.processLeftKey()");
	var currentHighlight = this.SettingsGeneralView.getCurrentHighlight();
	switch(currentHighlight) {
		case this.SaveBtn:
			if(this.flagEnable)
				this.highlight(this.AutoStartBtn);
			else
				this.highlight(this.DisplayNotifyBtn);
			break;
		case this.CancelBtn:
			this.highlight(this.DisplayNotifyBtn);
			break;
	}
}

SceneSettingsGeneral.prototype.processRightKey = function() {
	alert("SceneSettingsGeneral.processRightKey()");
	var currentHighlight = this.SettingsGeneralView.getCurrentHighlight();

	switch(currentHighlight) {
		case this.AutoStartBtn:
			if(this.IsEnableSaveBtn != false)
				this.highlight(this.SaveBtn);
			else
				this.highlight(this.CancelBtn);
			break;
		case this.DisplayNotifyBtn:
			if(this.IsEnableSaveBtn != false)
				this.highlight(this.SaveBtn);
			else
				this.highlight(this.CancelBtn);
			break;
	}
}
SceneSettingsGeneral.prototype.processEnterKey = function() {
	alert("SceneSettingsGeneral.processEnterKey()");

	var currentHighlight = this.SettingsGeneralView.getCurrentHighlight();
	switch(currentHighlight) {
		case this.AutoStartBtn:
			this.BeforeBtn = this.AutoStartBtn;
			this.ShownOnOffSubList = true;
			WndMgr.StartSettingsOnOffSubList(this.AutoStartBtn, this.sceneId, this.SettingsGeneralView, this.AutoStartCallBack/*callback*/, this.AutoStartBtn.GetText());
			break;
		case this.DisplayNotifyBtn:
			this.ShownOnOffSubList = true;
			this.BeforeBtn = this.DisplayNotifyBtn;
			WndMgr.StartSettingsOnOffSubList(this.DisplayNotifyBtn, this.sceneId, this.SettingsGeneralView, this.DisplayNotifyCallBack/*callback*/, this.DisplayNotifyBtn.GetText());
			break;
		case this.SaveBtn:
			this.SaveGeneralSetting();
			break;
		case this.CancelBtn:
			this.processReturnKey();
			break;
	}
}
SceneSettingsGeneral.prototype.ChangePopupUI = function() {
	alert("SceneSettingsGeneral.ChangePopupUI()");
	//SettingsGeneral_popup_innerbox
	//SettingsGeneral_popup_BG
	var bgT = 172;
	var bgT_s = 202;
	var bgH = 391;
	var bgH_s = 351;
	var innerH = 234;
	var innerH_s = 190;
	var saveBtnTop = 139;
	var saveBtnTop_s = 119;
	if(this.flagEnable){
		this.SettingsGeneralBG.ChangePopupBGSize(null,null,bgT,null,bgH);
		$("#SettingsGeneral").css("top",bgT+"px");
		$("#SettingsGeneral").css("height",bgH-55+"px");
		this.SettingsGeneralBG.ChangeInnerBox(29, 81, 640, innerH);
		$("#settingsgeneral_save_btn").css("top",saveBtnTop+'px');
		$("#settingsgeneral_cancel_btn").css("top",saveBtnTop+60+'px');
		$("#settingsgeneral_display_noty_label").css("top",'222px');
		$("#settingsgeneral_display_noty_btn").css("top",'212px');
	}else{
		this.SettingsGeneralBG.ChangePopupBGSize(null,null,bgT_s,null,bgH_s);
		$("#SettingsGeneral").css("top",bgT_s+"px");
		$("#SettingsGeneral").css("height",bgH_s-55+"px");
		this.SettingsGeneralBG.ChangeInnerBox(29, 81, 640, innerH_s);
		$("#settingsgeneral_save_btn").css("top",saveBtnTop_s+'px');
		$("#settingsgeneral_cancel_btn").css("top",saveBtnTop_s+60+'px');
		$("#settingsgeneral_display_noty_label").css("top",'132px');
		$("#settingsgeneral_display_noty_btn").css("top",'122px');
	}
}

SceneSettingsGeneral.prototype.InitSettingsGeneral = function() {
	alert("SceneSettingsGeneral.InitSettingsGeneral()");
	var currentHighlight = this.SettingsGeneralView.getCurrentHighlight();
	this.InitAutoStart = PluginAPIMgr.GetAutoStart();
	this.InitDisplayNotify = PluginAPIMgr.GetDisplayNoty();

	this.AutoStartBtn.SetText(this.InitAutoStart);
	this.DisplayNotifyBtn.SetText(this.InitDisplayNotify);

	this.IsChangeDisplayNotify = false;
	this.IsChangeAutoStart = false;

	if(PluginAPIMgr.IsDefaultAccountAvailable() == 1)// auto login
	{
		this.AutoStartLabel.visibleObj();
		this.AutoStartBtn.visibleObj();
		this.flagEnable = true;
	} else {
		this.AutoStartLabel.hiddenObj();
		this.AutoStartBtn.hiddenObj();
		this.flagEnable = false;
	}
}
SceneSettingsGeneral.prototype.SaveSuccess = function() {
	alert("SceneSettingsGeneral.SaveSuccess()");
	this.InitAutoStart = this.AutoStartBtn.GetText();
	this.InitDisplayNotify = this.DisplayNotifyBtn.GetText();
	StateMgr.Stop_SettingsGeneral_State(true);
}
SceneSettingsGeneral.prototype.SaveGeneralSetting = function() {
	alert("SceneSettingsGeneral.SaveGeneralSetting()");
	var isChanged = false;
	if(this.IsChangeAutoStart == true) {
		isChanged = true;
		if(this.AutoStartBtn.GetText() == SID_ON) {
			PluginAPIMgr.SetAutoStart(true);
		} else {
			PluginAPIMgr.SetAutoStart(false);
		}
	}
	if(this.IsChangeDisplayNotify == true) {
		isChanged = true;
		PluginAPIMgr.SetDisplayNotyValue(this.DisplayNotifyBtn.GetText());
	}
	if(isChanged == true){
		WndMgr.SetCurrentPopupSceneId(this.sceneId);
		WndMgr.HideSettingsGeneral();
		WndMgr.StartOneBottonPopup(OneBtnPopupIndex.OPTIONS_OK);
	}
}
SceneSettingsGeneral.prototype.setSaveBtnEnable = function(flag_enable) {
	alert("SceneSettingsGeneral.setSaveBtnEnable() : "+flag_enable);

	if(flag_enable == true) {
		this.SaveBtn.SetFlagDim(false);
		this.IsEnableSaveBtn = true;
	} else if(flag_enable == false) {
		this.SaveBtn.SetFlagDim(true);
		this.IsEnableSaveBtn = false;
	}
}
SceneSettingsGeneral.prototype.IsChange = function(caller) {
	alert("SceneSettingsGeneral.IsChange()");
	switch(caller) {
		case "AUTO":
			if(this.IsChangeAutoStart)
				this.setSaveBtnEnable(true);
			else if(this.IsChangeAutoStart == false && this.IsChangeDisplayNotify)
				this.setSaveBtnEnable(true);
			else
				this.setSaveBtnEnable(false);
			break;
		case "DISPLAY":
			if(this.IsChangeDisplayNotify)
				this.setSaveBtnEnable(true);
			else if(this.IsChangeDisplayNotify == false && this.IsChangeAutoStart)
				this.setSaveBtnEnable(true);
			else
				this.setSaveBtnEnable(false);
			break;
	}
}
SceneSettingsGeneral.prototype.AutoStartCallBack = function(text) {
	alert("SceneSettingsGeneral.AutoStartCallBack()");
	var this_ = sf.scene.get("SettingsGeneral");
	if(this_.InitAutoStart != text) {
		this_.IsChangeAutoStart = true;
	} else {
		this_.IsChangeAutoStart = false;
	}
	this_.IsChange("AUTO");
}
SceneSettingsGeneral.prototype.DisplayNotifyCallBack = function(text) {
	alert("SceneSettingsGeneral.DisplayNotifyCallBack()");
	var this_ = sf.scene.get("SettingsGeneral");
	if(this_.InitDisplayNotify != text) {
		this_.IsChangeDisplayNotify = true;
	} else {
		this_.IsChangeDisplayNotify = false;
	}
	this_.IsChange("DISPLAY");
}
SceneSettingsGeneral.prototype.create = function() {
	alert("SceneSettingsGeneral.create()");
	this.SettingsGeneralView = new View("SettingsGeneral");
	this.SettingsGeneralBG = new View("SettingsGeneralBG");
	this.SettingsGeneralBG.CreatePopupBG(0, "SettingsGeneral_popup_BG");
	this.SettingsGeneralBG.CreateInnerBox("SettingsGeneral_popup_innerbox");
	this.SettingsGeneralBG.SetTitleTextofPopupBG(IDWS_MOIP_SKYPE_SETTING_GENERAL_SETTINGS);
	this.SettingsGeneralDim = new DimBg("SettingsGeneralDim", "SettingsGeneralBG");

	var this_ = sf.scene.get("SettingsGeneral");
	var clickCF = function(obj) {
		this_.processClickEvent(obj);
	};
	this.AutoStartLabel = new TextLayer("settingsgeneral_auto_start_label");
	this.AutoStartLabel.SetTextStyle("settingsgeneral_label_style");
	this.AutoStartLabel.SetAdjustFlag(true);
	this.DisplayNotifyLabel = new TextLayer("settingsgeneral_display_noty_label");
	this.DisplayNotifyLabel.SetTextStyle("settingsgeneral_label_style");
	this.DisplayNotifyLabel.SetAdjustFlag(true);
	var CurLangID = ResMgr.GetCurLanguage();

	if(CurLangID == ENUM_TV_LANGUAGE.ZUL || CurLangID == ENUM_TV_LANGUAGE.SWA || CurLangID == ENUM_TV_LANGUAGE.XHO) {
		this.AutoStartLabel.SetText(TV_SID_SIGN_ME_IN_WHEN_THE_TV_POWER_ON + ":");
		this.DisplayNotifyLabel.SetText(TV_SID_DISPLAY_NOTIFICATION_ONLINE_MSG + " :");
	} else {
		if(ResMgr.isReverseLanguage()) {
			this.AutoStartLabel.SetText(TV_SID_SIGN_ME_IN_WHEN_THE_TV_POWER_ON);
			this.DisplayNotifyLabel.SetText(TV_SID_DISPLAY_NOTIFICATION_ONLINE_MSG);
		} else {
			this.AutoStartLabel.SetText(TV_SID_SIGN_ME_IN_WHEN_THE_TV_POWER_ON + " :");
			this.DisplayNotifyLabel.SetText(TV_SID_DISPLAY_NOTIFICATION_ONLINE_MSG + " :");
		}
	}

	this.AutoStartBtn = new Button();
	this.AutoStartBtn.SetImageObjId("settingsgeneral_auto_start_btn", 15);
	this.AutoStartBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_IMG, g_Image.IMAGE_BASIC_BUTTON_NORMAL);
	this.AutoStartBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_FOCUS_IMG, g_Image.IMAGE_BASIC_BUTTON_FOCUS);
	this.AutoStartBtn.SetBgImage(BtnImgIndex.BTN_DIM_IMG, g_Image.IMAGE_BASIC_BUTTON_DIM);

	this.AutoStartBtn.SetTextObjId("settingsgeneral_auto_start_btn_text");
	this.AutoStartBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_NORMAL_STYLE, "popup_btn_text_normal_style");
	this.AutoStartBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_FOCUS_STYLE, "popup_btn_text_focus_style");
	this.AutoStartBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_DIM_STYLE, "popup_btn_text_dimmed_style");
	this.AutoStartBtn.SetIconObjId("settingsgeneral_auto_start_btn_arrow");
	this.AutoStartBtn.SetBgIcon(0, g_Image.IMAGE_POPUP_BTN_ARROW_DOWN);
	this.AutoStartBtn.SetOnClickCallbackFunc(clickCF);

	this.DisplayNotifyBtn = new Button();
	this.DisplayNotifyBtn.SetImageObjId("settingsgeneral_display_noty_btn", 15);
	this.DisplayNotifyBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_IMG, g_Image.IMAGE_BASIC_BUTTON_NORMAL);
	this.DisplayNotifyBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_FOCUS_IMG, g_Image.IMAGE_BASIC_BUTTON_FOCUS);
	this.DisplayNotifyBtn.SetBgImage(BtnImgIndex.BTN_DIM_IMG, g_Image.IMAGE_BASIC_BUTTON_DIM);

	this.DisplayNotifyBtn.SetTextObjId("settingsgeneral_display_noty_btn_text");
	this.DisplayNotifyBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_NORMAL_STYLE, "popup_btn_text_normal_style");
	this.DisplayNotifyBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_FOCUS_STYLE, "popup_btn_text_focus_style");
	this.DisplayNotifyBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_DIM_STYLE, "popup_btn_text_dimmed_style");
	this.DisplayNotifyBtn.SetIconObjId("settingsgeneral_display_noty_btn_arrow");
	this.DisplayNotifyBtn.SetBgIcon(0, g_Image.IMAGE_POPUP_BTN_ARROW_DOWN);
	this.DisplayNotifyBtn.SetOnClickCallbackFunc(clickCF);

	this.SaveBtn = new Button();
	this.SaveBtn.SetImageObjId("settingsgeneral_save_btn", 20);
	this.SaveBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_IMG, g_Image.IMAGE_POPUP_BTN_NORMAL);
	this.SaveBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_FOCUS_IMG, g_Image.IMAGE_POPUP_BTN_NORMALFOCUS);

	this.SaveBtn.SetTextObjId("settingsgeneral_save_btn_text");
	this.SaveBtn.SetText(SID_SAVE);
	this.SaveBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_NORMAL_STYLE, "popup_btn_text_normal_style");
	this.SaveBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_FOCUS_STYLE, "popup_btn_text_focus_style");
	this.SaveBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_DIM_STYLE, "popup_btn_text_dimmed_style");
	this.SaveBtn.SetOnClickCallbackFunc(clickCF);

	this.CancelBtn = new Button();
	this.CancelBtn.SetImageObjId("settingsgeneral_cancel_btn", 20);
	this.CancelBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_IMG, g_Image.IMAGE_POPUP_BTN_NORMAL);
	this.CancelBtn.SetBgImage(BtnImgIndex.BTN_NORMAL_FOCUS_IMG, g_Image.IMAGE_POPUP_BTN_NORMALFOCUS);

	this.CancelBtn.SetTextObjId("settingsgeneral_cancel_btn_text");
	this.CancelBtn.SetText(SID_CANCEL);
	this.CancelBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_NORMAL_STYLE, "popup_btn_text_normal_style");
	this.CancelBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_FOCUS_STYLE, "popup_btn_text_focus_style");
	this.CancelBtn.SetTextStyle(BtnTextStyleIndex.BTN_TEXT_DIM_STYLE, "popup_btn_text_dimmed_style");
	this.CancelBtn.SetOnClickCallbackFunc(clickCF);
	
	this.AutoStartBtn.SetOnMouseOverCallbackFunc(function(obj) {
		this_.processMouseOver(obj);
	});
	this.DisplayNotifyBtn.SetOnMouseOverCallbackFunc(function(obj) {
		this_.processMouseOver(obj);
	});
	this.SaveBtn.SetOnMouseOverCallbackFunc(function(obj) {
		this_.processMouseOver(obj);
	});
	this.CancelBtn.SetOnMouseOverCallbackFunc(function(obj) {
		this_.processMouseOver(obj);
	});

}